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