Fix checkstyle
[lispflowmapping.git] / mappingservice / lisp-proto / src / test / java / org / opendaylight / lispflowmapping / serializer / MapRegisterSerializationTest.java
1 /*
2  * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.lispflowmapping.serializer;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import java.nio.ByteBuffer;
15 import java.util.ArrayList;
16 import junitx.framework.ArrayAssert;
17 import org.junit.Test;
18 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
19 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length;
20 import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
21 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
22 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
23 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
34
35 public class MapRegisterSerializationTest extends BaseTestCase {
36
37     @Test
38     public void serialize__Fields() throws Exception {
39         MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
40         mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
41         MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
42         recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
43         recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
44
45         mrBuilder.getMappingRecordItem().add(
46                 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
47         recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
48         mrBuilder.getMappingRecordItem().add(
49                 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
50
51         mrBuilder.setNonce(6161616161L);
52         mrBuilder.setKeyId((short) 0x0001);
53         mrBuilder.setWantMapNotify(true);
54         mrBuilder.setProxyMapReply(true);
55         mrBuilder.setXtrSiteIdPresent(true);
56         byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88,
57             (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64,
58             (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
59         mrBuilder.setAuthenticationData(authenticationData);
60         XtrId xtrId  = new XtrId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
61             (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
62             (byte) 0x00, (byte) 0x00, (byte) 0x01 });
63         mrBuilder.setXtrId(xtrId);
64         SiteId siteId = new SiteId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
65             (byte) 0x00, (byte) 0x00, (byte) 0x01 });
66         mrBuilder.setSiteId(siteId);
67
68         ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
69         assertHexEquals((byte) 0x3a, bb.get()); // Type + MSByte of reserved
70         assertEquals(1, bb.getShort()); // Rest of reserved + want map notify
71         assertEquals(2, bb.get()); // Record Count
72         assertEquals(6161616161L, bb.getLong()); // Nonce
73         assertHexEquals((short) 0x0001, bb.getShort()); // Key ID
74         assertEquals(authenticationData.length, bb.getShort());
75
76         byte[] actualAuthenticationData = new byte[20];
77         bb.get(actualAuthenticationData);
78         ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
79
80         bb.position(bb.position() + 12); // EID in first record
81         assertEquals(0x1, bb.getInt());
82
83         bb.position(bb.position() + 12); // EID in second record
84         assertEquals(73, bb.getInt());
85
86         byte[] actualXtrId  = new byte[Length.XTRID_SIZE];
87         bb.get(actualXtrId);
88         ArrayAssert.assertEquals(xtrId.getValue(), actualXtrId);
89
90         byte[] actualSiteId = new byte[Length.SITEID_SIZE];
91         bb.get(actualSiteId);
92         ArrayAssert.assertEquals(siteId.getValue(), actualSiteId);
93
94         assertEquals(bb.position(), bb.capacity());
95     }
96
97     @Test
98     public void serialize__deserialize() throws Exception {
99         MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
100         mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
101         MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
102         recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
103         recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
104
105         mrBuilder.getMappingRecordItem().add(
106                 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
107         recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
108         mrBuilder.getMappingRecordItem().add(
109                 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
110
111         recordBuilder.setAction(Action.NoAction);
112         recordBuilder.setMapVersion((short) 0);
113         recordBuilder.setRecordTtl(0);
114         mrBuilder.setNonce(6161616161L);
115         mrBuilder.setKeyId((short) 0x0001);
116         mrBuilder.setWantMapNotify(true);
117         mrBuilder.setProxyMapReply(true);
118         byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88,
119             (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64,
120             (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
121         mrBuilder.setAuthenticationData(authenticationData);
122
123         MapRegister mapRegister = mrBuilder.build();
124         ArrayAssert.assertEquals(
125                 MapRegisterSerializer.getInstance().serialize(mapRegister).array(),
126                 MapRegisterSerializer.getInstance()
127                         .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance()
128                                 .serialize(mapRegister), null)).array());
129     }
130
131     @Test
132     public void serialize__NoAuthenticationData() throws Exception {
133         MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
134         mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
135         mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
136                 new MappingRecordBuilder().setRecordTtl(55)
137                         .setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build()).build());
138         // mrBuilder.addEidToLocator(new EidToLocatorRecord().setPrefix(new
139         // LispIpv4Address(1)).setRecordTtl(55));
140
141         ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
142         bb.position(bb.position() + 14); // jump to AuthenticationDataLength
143         assertEquals(0, bb.getShort());
144         assertEquals(55, bb.getInt());
145
146         mrBuilder.setAuthenticationData(null);
147
148         bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
149         bb.position(bb.position() + 14); // jump to AuthenticationDataLength
150         assertEquals(0, bb.getShort());
151         assertEquals(55, bb.getInt());
152
153         mrBuilder.setAuthenticationData(new byte[0]);
154
155         bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
156         bb.position(bb.position() + 14); // jump to AuthenticationDataLength
157         assertEquals(0, bb.getShort());
158         assertEquals(55, bb.getInt());
159     }
160
161     @Test
162     public void serialize__NoPrefixInEidToLocator() throws Exception {
163         MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
164         mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
165         mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
166                 new MappingRecordBuilder().build()).build());
167         mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
168                 new MappingRecordBuilder().setEid(null).build()).build());
169         mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
170                 new MappingRecordBuilder().setEid(LispAddressUtil.getNoAddressEid()).build()).build());
171
172         ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
173         bb.position(bb.position() + 16); // jump to first record prefix AFI
174         assertEquals(0, bb.getShort());
175
176         bb.position(bb.position() + 10); // jump to second record prefix AFI
177         assertEquals(0, bb.getShort());
178
179         bb.position(bb.position() + 10); // jump to third record prefix AFI
180         assertEquals(0, bb.getShort());
181     }
182
183     @Test
184     public void deserialize__AllFields() throws Exception {
185         // LISP(Type = 3 Map-Register, P=1, M=1
186         // Record Counter: 1
187         // Nonce: (something)
188         // Key ID: 0x0000
189         // AuthDataLength: 00 Data:
190         // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
191         // No-Action
192         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
193         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
194         //
195         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
196         //
197                 + "00 00 00 00 00 00 00 00 00 00 00 00 " //
198                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
199                 + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
200
201         assertTrue(mr.isProxyMapReply());
202         assertTrue(mr.isWantMapNotify());
203
204         assertEquals(1, mr.getMappingRecordItem().size());
205         assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
206         assertEquals(0x0000, mr.getKeyId().shortValue());
207         byte[] expectedAuthenticationData = {};
208         ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
209     }
210
211     @Test
212     public void deserialize__serialize() throws Exception {
213         ByteBuffer bb = hexToByteBuffer("32 00 01 01 63 99 "
214                 + "83 64 23 06 a8 be 00 01 00 14 b8 c2 a2 e1 dc 4a "
215                 + "08 0c f6 01 b0 9d 70 5a d4 88 95 f8 73 dd 00 00 "
216                 + "05 a0 01 20 10 00 00 00 40 03 00 00 02 20 00 0a "
217                 + "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 "
218                 + "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 "
219                 + "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
220         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb, null);
221
222         assertTrue(mr.isXtrSiteIdPresent());
223
224         ArrayAssert.assertEquals(bb.array(), MapRegisterSerializer.getInstance().serialize(mr).array());
225     }
226
227     @Test
228     public void deserialize__MultipleRecords() throws Exception {
229         // LISP(Type = 3 Map-Register, P=1, M=1
230         // Record Counter: 4
231         // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
232         // 150.16.254.1
233         // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
234         // 192.168.136.13
235         //
236         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 "
237         //
238                 + "04 " // Record count
239                 + "FF BB 00 00 00 00 00 00 00 01 00 14 87 c1 33 cd " //
240                 + "d1 1e bc 80 fd 3e 71 11 81 17 40 74 26 25 44 bd " //
241                 + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
242                 // 1
243                 + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
244                 + "00 00 00 0a 01 20 10 00 00 00 00 01 98 10 fe 01 01 64 " // Record
245                 // 2
246                 + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
247                 + "00 00 00 0a 01 20 10 00 00 00 00 01 97 10 fe 01 01 64 " // Record
248                 // 3
249                 + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
250                 + "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
251                 // 4
252                 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
253         ), null);
254
255         assertEquals(4, mr.getMappingRecordItem().size());
256         assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
257                 .getMappingRecord().getEid());
258         assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("151.16.254.1/32"), mr.getMappingRecordItem().get(2)
259                 .getMappingRecord().getEid());
260         assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mr.getMappingRecordItem().get(1)
261                 .getMappingRecord().getLocatorRecord().get(0).getRloc());
262         assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.13"), mr.getMappingRecordItem().get(3)
263                 .getMappingRecord().getLocatorRecord().get(0).getRloc());
264     }
265
266     @Test
267     public void deserialize__Locators() throws Exception {
268         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 "
269         //
270                 + "FF BB 00 00 00 00 00 00 00 01 00 14 f1 b8 ab f0 " //
271                 + "66 bb 2e ef 12 70 74 46 6f 6b 8e ca bf 1e 68 40 " //
272                 + "00 00 00 0a " //
273                 + "03 " // Locator Count
274                 + "20 10 00 00 00 00 01 99 10 fe 01 "
275                 // Locator 1
276                 + "01 64 1f 00 " // priorities + weights
277                 + "00 05 " // Flags
278                 + "00 01 c0 a8 88 0a " // Locator
279                 // Locator 2
280                 + "67 00 30 34 " // priorities + weights
281                 + "00 02 " // Flags
282                 + "00 01 cc aa AA 11 " // Locator
283                 // Locator 3
284                 + "60 11 34 A4 " // priorities + weights
285                 + "00 03 " // Flags
286                 + "00 01 c0 a8 88 0a " // Locator
287         ), null);
288
289         assertEquals(1, mr.getMappingRecordItem().size());
290         MappingRecordItem eidToLocator = mr.getMappingRecordItem().get(0);
291         assertEquals(3, eidToLocator.getMappingRecord().getLocatorRecord().size());
292         LocatorRecord loc0 = eidToLocator.getMappingRecord().getLocatorRecord().get(0);
293         LocatorRecord loc1 = eidToLocator.getMappingRecord().getLocatorRecord().get(1);
294         LocatorRecord loc2 = eidToLocator.getMappingRecord().getLocatorRecord().get(2);
295         assertEquals((byte) 0x01, loc0.getPriority().byteValue());
296         assertEquals((byte) 0x67, loc1.getPriority().byteValue());
297         assertEquals((byte) 0x60, loc2.getPriority().byteValue());
298
299         assertEquals((byte) 0x64, loc0.getWeight().byteValue());
300         assertEquals((byte) 0x00, loc1.getWeight().byteValue());
301         assertEquals((byte) 0x11, loc2.getWeight().byteValue());
302
303         assertEquals((byte) 0x1F, loc0.getMulticastPriority().byteValue());
304         assertEquals((byte) 0x30, loc1.getMulticastPriority().byteValue());
305         assertEquals((byte) 0x34, loc2.getMulticastPriority().byteValue());
306
307         assertEquals((byte) 0x00, loc0.getMulticastWeight().byteValue());
308         assertEquals((byte) 0x34, loc1.getMulticastWeight().byteValue());
309         assertEquals((byte) 0xA4, loc2.getMulticastWeight().byteValue());
310
311         assertTrue(loc0.isLocalLocator());
312         assertFalse(loc1.isLocalLocator());
313         assertFalse(loc2.isLocalLocator());
314
315         assertFalse(loc0.isRlocProbed());
316         assertTrue(loc1.isRlocProbed());
317         assertTrue(loc2.isRlocProbed());
318
319         assertTrue(loc0.isRouted());
320         assertFalse(loc1.isRouted());
321         assertTrue(loc2.isRouted());
322
323         assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), loc0.getRloc());
324         assertEquals(LispAddressUtil.asIpv4Rloc("204.170.170.17"), loc1.getRloc());
325     }
326
327     @Test
328     public void deserialize__SomeEidToLocatorFiels() throws Exception {
329         // LISP(Type = 3 Map-Register, P=1, M=1
330         // Record Counter: 4
331         // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
332         // 150.16.254.1
333         // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
334         // 192.168.136.13
335         //
336         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 "
337         //
338                 + "04 " // Record count
339                 + "FF BB 00 00 00 00 00 00 00 01 00 14 b9 cd 7b 89 " //
340                 + "65 c2 56 03 be dd 81 20 47 e5 c3 4f 56 02 e1 59 " //
341                 + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
342                 // 0
343                 + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
344                 + "00 00 00 0b 01 17 50 00 01 11 00 01 98 10 fe 01 01 64 " // Record
345                 // 1
346                 + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
347                 + "00 00 00 0c 01 20 00 00 02 22 00 01 97 10 fe 01 01 64 " // Record
348                 // 2
349                 + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
350                 + "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
351                 // 3
352                 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
353         ), null);
354
355         assertEquals(4, mr.getMappingRecordItem().size());
356
357         final MappingRecord record0 = mr.getMappingRecordItem().get(0).getMappingRecord();
358         final MappingRecord record1 = mr.getMappingRecordItem().get(1).getMappingRecord();
359         final MappingRecord record2 = mr.getMappingRecordItem().get(2).getMappingRecord();
360         final MappingRecord record3 = mr.getMappingRecordItem().get(3).getMappingRecord();
361
362         assertEquals(10, record0.getRecordTtl().intValue());
363         assertEquals(13, record3.getRecordTtl().intValue());
364
365         assertEquals(32, MaskUtil.getMaskForAddress(record0.getEid().getAddress()));
366         assertEquals(23, MaskUtil.getMaskForAddress(record1.getEid().getAddress()));
367
368         assertEquals(Action.NoAction, record0.getAction());
369         assertEquals(Action.SendMapRequest, record1.getAction());
370         assertEquals(Action.NoAction, record2.getAction());
371         assertEquals(Action.NativelyForward, record3.getAction());
372
373         assertTrue(record0.isAuthoritative());
374         assertTrue(record1.isAuthoritative());
375         assertFalse(record2.isAuthoritative());
376         assertFalse(record3.isAuthoritative());
377
378         assertEquals(0x000, record0.getMapVersion().shortValue());
379         assertEquals(0x111, record1.getMapVersion().shortValue());
380         assertEquals(0x222, record2.getMapVersion().shortValue());
381         assertEquals(0x333, record3.getMapVersion().shortValue());
382     }
383
384     @Test
385     public void deserialize__IllegalAction() throws Exception {
386         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
387         //
388                 + "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " //
389                 + "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " //
390                 + "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
391                 + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
392
393         assertEquals(1, mr.getMappingRecordItem().size());
394         assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
395     }
396
397     @Test(expected = LispSerializationException.class)
398     public void deserialize_WrongAuthenticationLength() throws Exception {
399         // LISP(Type = 3 Map-Register, P=1, M=1
400         // Record Counter: 1
401         // Nonce: (something)
402         // Key ID: 0x0000
403         // AuthDataLength: 20 Data:
404         // e8:f5:0b:c5:c5:f2:b0:21:27:a8:a5:68:89:ec
405         // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
406         // No-Action
407         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
408         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
409         //
410         MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
411         //
412                 + "00 00 00 00 00 00 00 00 00 14 e8 f5 0b c5 c5 f2 " //
413                 + "b0 21 27 a8 21 a5 68 89 ec 00 00 " //
414                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
415                 + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
416     }
417
418     @Test
419     public void deserialize__SHA1() throws Exception {
420         // LISP(Type = 3 Map-Register, P=1, M=1
421         // Record Counter: 1
422         // Nonce: (something)
423         // Key ID: 0x0001
424         // AuthDataLength: 20 Data:
425         // b2:dd:1a:25:c0:60:b1:46:e8:dc:6d:a6:ae:2e:92:92:a6:ca:b7:9d
426         // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
427         // No-Action
428         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
429         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
430         //
431         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
432         //
433                 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
434                 + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
435                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
436                 + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
437
438         assertTrue(mr.isProxyMapReply());
439         assertTrue(mr.isWantMapNotify());
440
441         assertEquals(1, mr.getMappingRecordItem().size());
442         assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
443         assertEquals(0x0001, mr.getKeyId().shortValue());
444         byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a,
445             (byte) 0x20, (byte) 0xba, (byte) 0xd8, (byte) 0xf5, (byte) 0x40, (byte) 0xd3, (byte) 0x55, (byte) 0x6f,
446             (byte) 0x5f, (byte) 0x6e, (byte) 0x5a, (byte) 0xb2, (byte) 0x0a, (byte) 0xbf, (byte) 0xb5 };
447         ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
448     }
449
450     @Test
451     public void deserialize__SHA256() throws Exception {
452         // LISP(Type = 3 Map-Register, P=1, M=1
453         // Record Counter: 1
454         // Nonce: (something)
455         // Key ID: 0x0002
456         // AuthDataLength: 32 Data:
457         // 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b
458         // 58 c4 b9 9f 06 11 23 b9 38
459         // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
460         // No-Action
461         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
462         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
463         //
464         MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
465         //
466                 + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 "
467                 //
468                 + "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
469                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
470                 + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
471
472         assertTrue(mr.isProxyMapReply());
473         assertTrue(mr.isWantMapNotify());
474
475         assertEquals(1, mr.getMappingRecordItem().size());
476         assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
477         assertEquals(0x0002, mr.getKeyId().shortValue());
478         byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10,
479             (byte) 0x44, (byte) 0x0d, (byte) 0x83, (byte) 0xbe, (byte) 0x4d, (byte) 0xbf, (byte) 0xfd, (byte) 0xa9,
480             (byte) 0x8c, (byte) 0x57, (byte) 0x6d, (byte) 0x68, (byte) 0xa5, (byte) 0xbf, (byte) 0x32, (byte) 0x11,
481             (byte) 0xc9, (byte) 0x7b, (byte) 0x58, (byte) 0xc4, (byte) 0xb9, (byte) 0x9f, (byte) 0x06, (byte) 0x11,
482             (byte) 0x23, (byte) 0xb9, (byte) 0x38 };
483         ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
484     }
485 }