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