2 * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
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
9 package org.opendaylight.lispflowmapping.serializer;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertTrue;
15 import java.nio.ByteBuffer;
16 import java.util.ArrayList;
18 import junitx.framework.ArrayAssert;
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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddressBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
39 public class MapRegisterSerializationTest extends BaseTestCase {
42 public void serialize__Fields() throws Exception {
43 MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
44 mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
45 MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
46 recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
47 recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
49 mrBuilder.getMappingRecordItem().add(
50 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
51 recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
52 mrBuilder.getMappingRecordItem().add(
53 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
55 mrBuilder.setNonce(6161616161L);
56 mrBuilder.setKeyId((short) 0x0001);
57 mrBuilder.setWantMapNotify(true);
58 mrBuilder.setProxyMapReply(true);
59 mrBuilder.setXtrSiteIdPresent(true);
60 byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d,
61 (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba,
62 (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
63 mrBuilder.setAuthenticationData(authenticationData);
64 byte[] xtrId = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
65 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
66 mrBuilder.setXtrId(xtrId);
67 byte[] siteId = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
68 mrBuilder.setSiteId(siteId);
70 ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
71 assertHexEquals((byte) 0x3a, bb.get()); // Type + MSByte of reserved
72 assertEquals(1, bb.getShort()); // Rest of reserved + want map notify
73 assertEquals(2, bb.get()); // Record Count
74 assertEquals(6161616161L, bb.getLong()); // Nonce
75 assertHexEquals((short) 0x0001, bb.getShort()); // Key ID
76 assertEquals(authenticationData.length, bb.getShort());
78 byte[] actualAuthenticationData = new byte[20];
79 bb.get(actualAuthenticationData);
80 ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
82 bb.position(bb.position() + 12); // EID in first record
83 assertEquals(0x1, bb.getInt());
85 bb.position(bb.position() + 12); // EID in second record
86 assertEquals(73, bb.getInt());
88 byte[] actualXtrId = new byte[Length.XTRID_SIZE];
90 ArrayAssert.assertEquals(xtrId, actualXtrId);
92 byte[] actualSiteId = new byte[Length.SITEID_SIZE];
94 ArrayAssert.assertEquals(siteId, actualSiteId);
96 assertEquals(bb.position(), bb.capacity());
100 public void serialize__deserialize() throws Exception {
101 MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
102 mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
103 MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
104 recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
105 recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
107 mrBuilder.getMappingRecordItem().add(
108 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
109 recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
110 mrBuilder.getMappingRecordItem().add(
111 new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
113 recordBuilder.setAction(Action.NoAction);
114 recordBuilder.setMapVersion((short) 0);
115 recordBuilder.setMaskLength((short) 0);
116 recordBuilder.setRecordTtl(0);
117 mrBuilder.setNonce(6161616161L);
118 mrBuilder.setKeyId((short) 0x0001);
119 mrBuilder.setWantMapNotify(true);
120 mrBuilder.setProxyMapReply(true);
121 byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d,
122 (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba,
123 (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
124 mrBuilder.setAuthenticationData(authenticationData);
126 MapRegister mapRegister = mrBuilder.build();
127 ArrayAssert.assertEquals(
128 MapRegisterSerializer.getInstance().serialize(mapRegister).array(),
129 MapRegisterSerializer.getInstance()
130 .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister)))
135 public void serialize__NoAuthenticationData() throws Exception {
136 MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
137 mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
138 mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
139 new MappingRecordBuilder().setRecordTtl(55)
140 .setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build()).build());
141 // mrBuilder.addEidToLocator(new EidToLocatorRecord().setPrefix(new
142 // LispIpv4Address(1)).setRecordTtl(55));
144 ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
145 bb.position(bb.position() + 14); // jump to AuthenticationDataLength
146 assertEquals(0, bb.getShort());
147 assertEquals(55, bb.getInt());
149 mrBuilder.setAuthenticationData(null);
151 bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
152 bb.position(bb.position() + 14); // jump to AuthenticationDataLength
153 assertEquals(0, bb.getShort());
154 assertEquals(55, bb.getInt());
156 mrBuilder.setAuthenticationData(new byte[0]);
158 bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
159 bb.position(bb.position() + 14); // jump to AuthenticationDataLength
160 assertEquals(0, bb.getShort());
161 assertEquals(55, bb.getInt());
165 public void serialize__NoPrefixInEidToLocator() throws Exception {
166 MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
167 mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
168 mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
169 new MappingRecordBuilder().build()).build());
170 mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
171 new MappingRecordBuilder().setEid(null).build()).build());
172 mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
173 new MappingRecordBuilder().setEid(new EidBuilder().setAddressType(NoAddressAfi.class).setAddress(
174 (Address) new NoAddressBuilder().setNoAddress(true).build()).build()).build()).build());
176 ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
177 bb.position(bb.position() + 16); // jump to first record prefix AFI
178 assertEquals(0, bb.getShort());
180 bb.position(bb.position() + 10); // jump to second record prefix AFI
181 assertEquals(0, bb.getShort());
183 bb.position(bb.position() + 10); // jump to third record prefix AFI
184 assertEquals(0, bb.getShort());
188 public void deserialize__AllFields() throws Exception {
189 // LISP(Type = 3 Map-Register, P=1, M=1
191 // Nonce: (something)
193 // AuthDataLength: 00 Data:
194 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
196 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
197 // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
199 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
201 + "00 00 00 00 00 00 00 00 00 00 00 00 " //
202 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
203 + "ff 00 00 05 00 01 c0 a8 88 0a"));
205 assertTrue(mr.isProxyMapReply());
206 assertTrue(mr.isWantMapNotify());
208 assertEquals(1, mr.getMappingRecordItem().size());
209 assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
210 assertEquals(0x0000, mr.getKeyId().shortValue());
211 byte[] expectedAuthenticationData = {};
212 ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
216 public void deserialize__serialize() throws Exception {
217 ByteBuffer bb = hexToByteBuffer("32 00 01 01 63 99 "
218 + "83 64 23 06 a8 be 00 01 00 14 b8 c2 a2 e1 dc 4a "
219 + "08 0c f6 01 b0 9d 70 5a d4 88 95 f8 73 dd 00 00 "
220 + "05 a0 01 20 10 00 00 00 40 03 00 00 02 00 00 0a "
221 + "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 "
222 + "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 "
223 + "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
224 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb);
226 assertTrue(mr.isXtrSiteIdPresent());
228 ArrayAssert.assertEquals(bb.array(), MapRegisterSerializer.getInstance().serialize(mr).array());
232 public void deserialize__MultipleRecords() throws Exception {
233 // LISP(Type = 3 Map-Register, P=1, M=1
235 // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
237 // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
240 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 "
242 + "04 " // Record count
243 + "FF BB 00 00 00 00 00 00 00 01 00 14 87 c1 33 cd " //
244 + "d1 1e bc 80 fd 3e 71 11 81 17 40 74 26 25 44 bd " //
245 + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
247 + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
248 + "00 00 00 0a 01 20 10 00 00 00 00 01 98 10 fe 01 01 64 " // Record
250 + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
251 + "00 00 00 0a 01 20 10 00 00 00 00 01 97 10 fe 01 01 64 " // Record
253 + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
254 + "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
256 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
259 assertEquals(4, mr.getMappingRecordItem().size());
260 assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
261 .getMappingRecord().getEid());
262 assertEquals(LispAddressUtil.asIpv4PrefixEid("151.16.254.1/32"), mr.getMappingRecordItem().get(2)
263 .getMappingRecord().getEid());
264 assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mr.getMappingRecordItem().get(1)
265 .getMappingRecord().getLocatorRecord().get(0).getRloc());
266 assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.13"), mr.getMappingRecordItem().get(3)
267 .getMappingRecord().getLocatorRecord().get(0).getRloc());
271 public void deserialize__Locators() throws Exception {
272 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 "
274 + "FF BB 00 00 00 00 00 00 00 01 00 14 f1 b8 ab f0 " //
275 + "66 bb 2e ef 12 70 74 46 6f 6b 8e ca bf 1e 68 40 " //
277 + "03 " // Locator Count
278 + "20 10 00 00 00 00 01 99 10 fe 01 "
280 + "01 64 1f 00 " // priorities + weights
282 + "00 01 c0 a8 88 0a " // Locator
284 + "67 00 30 34 " // priorities + weights
286 + "00 01 cc aa AA 11 " // Locator
288 + "60 11 34 A4 " // priorities + weights
290 + "00 01 c0 a8 88 0a " // Locator
293 assertEquals(1, mr.getMappingRecordItem().size());
294 MappingRecordItem eidToLocator = mr.getMappingRecordItem().get(0);
295 assertEquals(3, eidToLocator.getMappingRecord().getLocatorRecord().size());
296 LocatorRecord loc0 = eidToLocator.getMappingRecord().getLocatorRecord().get(0);
297 LocatorRecord loc1 = eidToLocator.getMappingRecord().getLocatorRecord().get(1);
298 LocatorRecord loc2 = eidToLocator.getMappingRecord().getLocatorRecord().get(2);
299 assertEquals((byte) 0x01, loc0.getPriority().byteValue());
300 assertEquals((byte) 0x67, loc1.getPriority().byteValue());
301 assertEquals((byte) 0x60, loc2.getPriority().byteValue());
303 assertEquals((byte) 0x64, loc0.getWeight().byteValue());
304 assertEquals((byte) 0x00, loc1.getWeight().byteValue());
305 assertEquals((byte) 0x11, loc2.getWeight().byteValue());
307 assertEquals((byte) 0x1F, loc0.getMulticastPriority().byteValue());
308 assertEquals((byte) 0x30, loc1.getMulticastPriority().byteValue());
309 assertEquals((byte) 0x34, loc2.getMulticastPriority().byteValue());
311 assertEquals((byte) 0x00, loc0.getMulticastWeight().byteValue());
312 assertEquals((byte) 0x34, loc1.getMulticastWeight().byteValue());
313 assertEquals((byte) 0xA4, loc2.getMulticastWeight().byteValue());
315 assertTrue(loc0.isLocalLocator());
316 assertFalse(loc1.isLocalLocator());
317 assertFalse(loc2.isLocalLocator());
319 assertFalse(loc0.isRlocProbed());
320 assertTrue(loc1.isRlocProbed());
321 assertTrue(loc2.isRlocProbed());
323 assertTrue(loc0.isRouted());
324 assertFalse(loc1.isRouted());
325 assertTrue(loc2.isRouted());
327 assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), loc0.getRloc());
328 assertEquals(LispAddressUtil.asIpv4Rloc("204.170.170.17"), loc1.getRloc());
332 public void deserialize__SomeEidToLocatorFiels() throws Exception {
333 // LISP(Type = 3 Map-Register, P=1, M=1
335 // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
337 // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
340 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 "
342 + "04 " // Record count
343 + "FF BB 00 00 00 00 00 00 00 01 00 14 b9 cd 7b 89 " //
344 + "65 c2 56 03 be dd 81 20 47 e5 c3 4f 56 02 e1 59 " //
345 + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
347 + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
348 + "00 00 00 0b 01 17 50 00 01 11 00 01 98 10 fe 01 01 64 " // Record
350 + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
351 + "00 00 00 0c 01 20 00 00 02 22 00 01 97 10 fe 01 01 64 " // Record
353 + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
354 + "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
356 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
359 assertEquals(4, mr.getMappingRecordItem().size());
361 MappingRecord record0 = mr.getMappingRecordItem().get(0).getMappingRecord();
362 MappingRecord record1 = mr.getMappingRecordItem().get(1).getMappingRecord();
363 MappingRecord record2 = mr.getMappingRecordItem().get(2).getMappingRecord();
364 MappingRecord record3 = mr.getMappingRecordItem().get(3).getMappingRecord();
366 assertEquals(10, record0.getRecordTtl().intValue());
367 assertEquals(13, record3.getRecordTtl().intValue());
369 assertEquals(32, record0.getMaskLength().intValue());
370 assertEquals(23, record1.getMaskLength().intValue());
372 assertEquals(Action.NoAction, record0.getAction());
373 assertEquals(Action.SendMapRequest, record1.getAction());
374 assertEquals(Action.NoAction, record2.getAction());
375 assertEquals(Action.NativelyForward, record3.getAction());
377 assertTrue(record0.isAuthoritative());
378 assertTrue(record1.isAuthoritative());
379 assertFalse(record2.isAuthoritative());
380 assertFalse(record3.isAuthoritative());
382 assertEquals(0x000, record0.getMapVersion().shortValue());
383 assertEquals(0x111, record1.getMapVersion().shortValue());
384 assertEquals(0x222, record2.getMapVersion().shortValue());
385 assertEquals(0x333, record3.getMapVersion().shortValue());
389 public void deserialize__IllegalAction() throws Exception {
390 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
392 + "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " //
393 + "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " //
394 + "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
395 + "ff 00 00 05 00 01 c0 a8 88 0a"));
397 assertEquals(1, mr.getMappingRecordItem().size());
398 assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
401 @Test(expected = LispSerializationException.class)
402 public void deserialize_WrongAuthenticationLength() throws Exception {
403 // LISP(Type = 3 Map-Register, P=1, M=1
405 // Nonce: (something)
407 // AuthDataLength: 20 Data:
408 // e8:f5:0b:c5:c5:f2:b0:21:27:a8:a5:68:89:ec
409 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
411 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
412 // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
414 MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
416 + "00 00 00 00 00 00 00 00 00 14 e8 f5 0b c5 c5 f2 " //
417 + "b0 21 27 a8 21 a5 68 89 ec 00 00 " //
418 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
419 + "ff 00 00 05 00 01 c0 a8 88 0a"));
423 public void deserialize__SHA1() throws Exception {
424 // LISP(Type = 3 Map-Register, P=1, M=1
426 // Nonce: (something)
428 // AuthDataLength: 20 Data:
429 // b2:dd:1a:25:c0:60:b1:46:e8:dc:6d:a6:ae:2e:92:92:a6:ca:b7:9d
430 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
432 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
433 // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
435 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
437 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
438 + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
439 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
440 + "ff 00 00 05 00 01 c0 a8 88 0a"));
442 assertTrue(mr.isProxyMapReply());
443 assertTrue(mr.isWantMapNotify());
445 assertEquals(1, mr.getMappingRecordItem().size());
446 assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
447 assertEquals(0x0001, mr.getKeyId().shortValue());
448 byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a, (byte) 0x20, (byte) 0xba, (byte) 0xd8, //
449 (byte) 0xf5, (byte) 0x40, (byte) 0xd3, (byte) 0x55, (byte) 0x6f, (byte) 0x5f, (byte) 0x6e, (byte) 0x5a, //
450 (byte) 0xb2, (byte) 0x0a, (byte) 0xbf, (byte) 0xb5 };
451 ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
455 public void deserialize__SHA256() throws Exception {
456 // LISP(Type = 3 Map-Register, P=1, M=1
458 // Nonce: (something)
460 // AuthDataLength: 32 Data:
461 // 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b
462 // 58 c4 b9 9f 06 11 23 b9 38
463 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
465 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
466 // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
468 MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
470 + "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 "
472 + "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
473 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
474 + "ff 00 00 05 00 01 c0 a8 88 0a"));
476 assertTrue(mr.isProxyMapReply());
477 assertTrue(mr.isWantMapNotify());
479 assertEquals(1, mr.getMappingRecordItem().size());
480 assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
481 assertEquals(0x0002, mr.getKeyId().shortValue());
482 byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10, (byte) 0x44, (byte) 0x0d, (byte) 0x83,
483 (byte) 0xbe, (byte) 0x4d, (byte) 0xbf, (byte) 0xfd, (byte) 0xa9, (byte) 0x8c, (byte) 0x57, (byte) 0x6d, (byte) 0x68, (byte) 0xa5,
484 (byte) 0xbf, (byte) 0x32, (byte) 0x11, (byte) 0xc9, (byte) 0x7b, (byte) 0x58, (byte) 0xc4, (byte) 0xb9, (byte) 0x9f, (byte) 0x06,
485 (byte) 0x11, (byte) 0x23, (byte) 0xb9, (byte) 0x38 };
486 ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());