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