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