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