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
8 package org.opendaylight.lispflowmapping.integrationtest;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.ops4j.pax.exam.CoreOptions.composite;
15 import static org.ops4j.pax.exam.CoreOptions.maven;
16 import static org.ops4j.pax.exam.CoreOptions.options;
17 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
19 import java.io.BufferedReader;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.io.OutputStreamWriter;
24 import java.net.DatagramPacket;
25 import java.net.DatagramSocket;
26 import java.net.HttpURLConnection;
27 import java.net.InetAddress;
28 import java.net.InetSocketAddress;
29 import java.net.MalformedURLException;
30 import java.net.SocketException;
31 import java.net.SocketTimeoutException;
33 import java.net.UnknownHostException;
34 import java.nio.ByteBuffer;
35 import java.nio.charset.Charset;
36 import java.util.ArrayList;
37 import java.util.Arrays;
39 import javax.inject.Inject;
41 import org.apache.commons.codec.binary.Base64;
42 //import org.codehaus.jettison.json.JSONException;
43 //import org.codehaus.jettison.json.JSONObject;
44 //import org.codehaus.jettison.json.JSONTokener;
45 import org.junit.After;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
51 import org.opendaylight.controller.sal.binding.api.NotificationListener;
52 import org.opendaylight.lispflowmapping.implementation.LispMappingService;
53 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
54 import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
55 import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
56 import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
57 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
58 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
59 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
60 import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
61 import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
62 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.EidToLocatorRecord.Action;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafApplicationDataAddress;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafListAddress;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafSegmentAddress;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafTrafficEngineeringAddress;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispAFIAddress;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispIpv4Address;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispMacAddress;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.MapNotify;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.MapRegister;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.MapReply;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.MapRequest;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.ReencapHop;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.XtrRequestMapping;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.eidrecords.EidRecord;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.eidrecords.EidRecordBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.eidtolocatorrecords.EidToLocatorRecord;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.eidtolocatorrecords.EidToLocatorRecordBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafkeyvalueaddress.KeyBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafkeyvalueaddress.ValueBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcaflistaddress.Addresses;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcaflistaddress.AddressesBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafsegmentaddress.AddressBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafsourcedestaddress.DstAddressBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafsourcedestaddress.SrcAddressBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcaftrafficengineeringaddress.Hops;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcaftrafficengineeringaddress.HopsBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.LispAddressContainer;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.LispAddressContainerBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.LcafKeyValue;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.LcafSourceDest;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.LcafSourceDestBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddr;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddrBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddrBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddrBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddrBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddr;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddrBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.lcaftrafficengineering.LcafTrafficEngineeringAddrBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.locatorrecords.LocatorRecord;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.locatorrecords.LocatorRecordBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.mapregisternotification.MapRegisterBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.maprequest.ItrRloc;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.maprequest.ItrRlocBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.maprequest.SourceEidBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.maprequestnotification.MapRequestBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.reencaphop.Hop;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.reencaphop.HopBuilder;
114 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
115 import org.ops4j.pax.exam.Option;
116 import org.ops4j.pax.exam.junit.PaxExam;
117 import org.ops4j.pax.exam.util.Filter;
118 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
119 import org.ops4j.pax.exam.options.MavenUrlReference;
120 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
121 import org.ops4j.pax.exam.spi.reactors.PerClass;
122 import org.osgi.framework.Bundle;
123 import org.osgi.framework.BundleContext;
124 import org.osgi.framework.InvalidSyntaxException;
125 import org.osgi.framework.ServiceReference;
126 import org.slf4j.Logger;
127 import org.slf4j.LoggerFactory;
129 @RunWith(PaxExam.class)
130 @ExamReactorStrategy(PerClass.class)
131 public class MappingServiceIntegrationTest extends AbstractMdsalTestBase {
132 private static final Logger LOG = LoggerFactory.getLogger(MappingServiceIntegrationTest.class);
134 private byte[] mapRequestPacket;
135 private byte[] mapRegisterPacketWithNotify;
136 private byte[] mapRegisterPacketWithoutNotify;
137 String lispBindAddress = "127.0.0.1";
138 String ourAddress = "127.0.0.2";
139 private LispAFIAddress locatorEid;
140 private DatagramSocket socket;
141 private byte[] mapRegisterPacketWithAuthenticationAndMapNotify;
143 public static final String ODL = "org.opendaylight.controller";
144 public static final String YANG = "org.opendaylight.yangtools";
145 public static final String JERSEY = "com.sun.jersey";
146 private static final int MAX_NOTIFICATION_RETRYS = 20;
149 public String getModuleName() {
150 return "lfm-mappingservice-impl";
154 public String getInstanceName() {
155 return "lfm-mappingservice-default";
158 // This is temporary, since the properties in the pom file are not picked up
159 // .versionAsInProject() doesn't work here, and this makes version bumping difficult
161 public String getKarafDistro() {
163 .groupId("org.opendaylight.lispflowmapping")
164 .artifactId("distribution-karaf")
165 .version("1.3.0-SNAPSHOT")
171 public MavenUrlReference getFeatureRepo() {
173 .groupId("org.opendaylight.lispflowmapping")
174 .artifactId("features-lispflowmapping")
175 .classifier("features")
177 .versionAsInProject();
181 public String getFeatureName() {
182 return "odl-lispflowmapping-all";
186 public Option getLoggingOption() {
187 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
188 logConfiguration(MappingServiceIntegrationTest.class),
189 LogLevel.DEBUG.name());
190 option = composite(option, super.getLoggingOption());
195 public void testLispFlowMappingFeatureLoad() {
196 Assert.assertTrue(true);
200 public void after() {
201 if (socket != null) {
204 // if (connection != null) {
205 // connection.disconnect();
210 public void before() throws Exception {
212 locatorEid = LispAFIConvertor.asIPAfiAddress("4.3.2.1");
213 socket = initSocket(socket, LispMessage.PORT_NUM);
215 // SRC: 127.0.0.1:58560 to 127.0.0.1:4342
216 // LISP(Type = 8 - Encapsulated)
217 // IP: 192.168.136.10 -> 153.16.254.1
219 // LISP(Type = 1 Map-Request
223 // Source EID 1.2.3.4
224 // Nonce: 0x3d8d2acd39c8d608
225 // ITR-RLOC AFI=1 Address=192.168.136.10
226 // Record 1: 153.16.254.1/32
227 mapRequestPacket = extractWSUdpByteArray(new String("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " //
228 + "0010 00 58 00 00 40 00 40 11 3c 93 7f 00 00 01 7f 00 "
229 + "0020 00 01 e4 c0 10 f6 00 44 fe 57 80 00 00 00 45 00 "
230 + "0030 00 3c d4 31 00 00 ff 11 56 f3 7f 00 00 02 99 10 "
231 + "0040 fe 01 dd b4 10 f6 00 28 ef 3a 10 00 00 01 3d 8d "
232 + "0050 2a cd 39 c8 d6 08 00 01 01 02 03 04 00 01 7f 00 00 02 00 20 " //
233 + "0060 00 01 99 10 fe 01"));
235 // IP: 192.168.136.10 -> 128.223.156.35
236 // UDP: 49289 -> 4342
237 // LISP(Type = 3 Map-Register, P=1, M=1
241 // AuthDataLength: 20 Data:
242 // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:a5:68:89:ec
243 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
245 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
246 // Priority/Weight: 1/100, Multicast Priority/Weight:
250 mapRegisterPacketWithAuthenticationAndMapNotify = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
251 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
252 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
253 + "0030 00 00 00 00 00 00 00 01 00 14 0e a4 c6 d8 a4 06 "
254 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
255 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
256 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
258 // IP: 192.168.136.10 -> 128.223.156.35
259 // UDP: 49289 -> 4342
260 // LISP(Type = 3 Map-Register, P=1, M=1
263 // Key ID: 0x0000 NO AUTHENTICATION!!
264 // AuthDataLength: 00 Data:
265 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
267 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
268 // Priority/Weight: 1/100, Multicast Priority/Weight:
272 mapRegisterPacketWithNotify = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
273 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
274 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
275 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
276 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
277 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
278 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
280 // IP: 192.168.136.10 -> 128.223.156.35
281 // UDP: 49289 -> 4342
282 // LISP(Type = 3 Map-Register, P=1, M=1
285 // Key ID: 0x0000 NO AUTHENTICATION!!
286 // AuthDataLength: 00 Data:
287 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
289 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
290 // Priority/Weight: 1/100, Multicast Priority/Weight:
294 mapRegisterPacketWithoutNotify = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
295 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
296 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 00 01 00 00 "
297 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
298 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
299 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
300 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
304 private BundleContext bc;
305 private HttpURLConnection connection;
306 protected static boolean notificationCalled;
308 @Inject @Filter(timeout=60000)
309 private IFlowMapping lms;
311 @Inject @Filter(timeout=10000)
312 private IConfigLispSouthboundPlugin configLispPlugin;
315 public void testSimpleUsage() throws Exception {
317 mapRegisterWithMapNotify();
318 mapRegisterWithMapNotifyAndMapRequest();
319 registerAndQuery__MAC();
320 mapRequestMapRegisterAndMapRequest();
321 mapRegisterWithAuthenticationWithoutConfiguringAKey();
322 mapRegisterWithoutMapNotify();
326 public void testLCAFs() throws Exception {
327 //registerAndQuery__SrcDestLCAF();
328 //registerAndQuery__SrcDestLCAFOverlap();
329 //registerAndQuery__KeyValueLCAF();
330 registerAndQuery__ListLCAF();
331 registerAndQuery__ApplicationData();
332 registerAndQuery__TrafficEngineering();
333 registerAndQuery__SegmentLCAF();
337 public void testMask() throws Exception {
338 //testPasswordExactMatch(); TODO commented because it needs NB
339 //testPasswordMaskMatch(); TODO commented because it needs NB
340 eidPrefixLookupIPv4();
341 eidPrefixLookupIPv6();
345 public void testNorthbound() throws Exception {
347 northboundAddMapping();
348 northboundDeleteMapping();
349 northboundRetrieveKey();
350 northboundRetrieveMapping();
351 northboundRetrieveSourceDestKey();
352 northboundRetrieveSourceDestMapping();
356 public void testOverWriting() throws Exception {
357 //testMapRegisterDosntOverwritesOtherSubKeys(); TODO weird failure, needs debug
359 // TODO: remove, we don't support overwrite flag any longer and RLOCs are not saved as independent RLOC groups
360 // testMapRegisterOverwritesSameSubkey();
361 // testMapRegisterOverwritesNoSubkey();
362 // testMapRegisterDoesntOverwritesNoSubkey();
366 public void testTimeOuts() throws Exception {
367 mapRequestMapRegisterAndMapRequestTestTimeout();
368 //mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse(); TODO commented because it needs NB
372 // public void testNonProxy() throws Throwable {
373 // testSimpleNonProxy();
374 // testNonProxyOtherPort();
375 // testRecievingNonProxyOnXtrPort();
379 public void testSmr() throws Exception {
380 registerQueryRegisterWithSmr();
383 // ------------------------------- Simple Tests ---------------------------
385 public void mapRequestSimple() throws SocketTimeoutException {
388 // This Map-Request is sent from a source port different from 4342
389 // We close and bind the socket on the correct port
390 if (socket != null) {
393 socket = initSocket(socket, 56756);
395 sendPacket(mapRequestPacket);
396 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
397 MapReply reply = MapReplySerializer.getInstance().deserialize(readBuf);
398 assertEquals(4435248268955932168L, reply.getNonce().longValue());
402 public void mapRegisterWithMapNotify() throws SocketTimeoutException {
404 sendPacket(mapRegisterPacketWithNotify);
405 MapNotify reply = receiveMapNotify();
406 assertEquals(7, reply.getNonce().longValue());
409 public void mapRegisterWithMapNotifyAndMapRequest() throws SocketTimeoutException {
411 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
413 MapReply mapReply = registerAddressAndQuery(eid, 32);
415 assertEquals(4, mapReply.getNonce().longValue());
416 assertEquals(LispAFIConvertor.toContainer(locatorEid), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
417 .getLispAddressContainer());
421 public void registerAndQuery__MAC() throws SocketTimeoutException {
423 String macAddress = "01:02:03:04:05:06";
425 MapReply reply = registerAddressAndQuery(LispAFIConvertor.asMacAfiAddress(macAddress));
428 LispAFIAddress addressFromNetwork = LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0).getLispAddressContainer());
429 assertTrue(addressFromNetwork instanceof LispMacAddress);
430 String macAddressFromReply = ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.mac.MacAddress) addressFromNetwork).getMacAddress().getValue();
432 assertEquals(macAddress, macAddressFromReply);
435 public void mapRequestMapRegisterAndMapRequest() throws SocketTimeoutException {
437 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
438 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
439 mapRequestBuilder.setNonce((long) 4);
440 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
441 LispAFIConvertor.toContainer(new NoAddressBuilder().setAfi((short) 0).build())).build());
442 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
443 mapRequestBuilder.getEidRecord().add(
444 new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
445 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
446 mapRequestBuilder.getItrRloc().add(
447 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
448 sendMapRequest(mapRequestBuilder.build());
449 MapReply mapReply = receiveMapReply();
450 assertEquals(4, mapReply.getNonce().longValue());
451 assertEquals(0, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
452 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
453 mapRegisterbuilder.setWantMapNotify(true);
454 mapRegisterbuilder.setNonce((long) 8);
455 EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
456 etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
457 etlrBuilder.setMaskLength((short) 32);
458 etlrBuilder.setRecordTtl(254);
459 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
460 recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
461 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
462 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
463 mapRegisterbuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
464 mapRegisterbuilder.getEidToLocatorRecord().add(etlrBuilder.build());
465 sendMapRegister(mapRegisterbuilder.build());
466 MapNotify mapNotify = receiveMapNotify();
467 assertEquals(8, mapNotify.getNonce().longValue());
468 sendMapRequest(mapRequestBuilder.build());
469 mapReply = receiveMapReply();
470 assertEquals(4, mapReply.getNonce().longValue());
471 assertEquals(recordBuilder.getLispAddressContainer(), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
472 .getLispAddressContainer());
476 public void testMapRegisterDosntOverwritesOtherSubKeys() throws SocketTimeoutException {
478 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
479 LispAFIAddress rloc1Value = LispAFIConvertor.asIPAfiAddress("4.3.2.1");
480 LispAFIAddress rloc1 = LispAFIConvertor.asKeyValue("subkey1", LispAFIConvertor.toPrimitive(rloc1Value));
481 LispAFIAddress rloc2Value = LispAFIConvertor.asIPAfiAddress("4.3.2.2");
482 LispAFIAddress rloc2 = LispAFIConvertor.asKeyValue("subkey2", LispAFIConvertor.toPrimitive(rloc2Value));
483 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
484 assertEquals(2, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
485 assertEquals(LispAFIConvertor.toContainer(rloc2), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer());
486 assertEquals(LispAFIConvertor.toContainer(rloc1), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getLispAddressContainer());
489 public void testMapRegisterOverwritesSameSubkey() throws SocketTimeoutException {
491 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
492 LispAFIAddress rloc1Value = LispAFIConvertor.asIPAfiAddress("4.3.2.1");
493 LispAFIAddress rloc1 = LispAFIConvertor.asKeyValue("subkey", LispAFIConvertor.toPrimitive(rloc1Value));
494 LispAFIAddress rloc2Value = LispAFIConvertor.asIPAfiAddress("4.3.2.2");
495 LispAFIAddress rloc2 = LispAFIConvertor.asKeyValue("subkey", LispAFIConvertor.toPrimitive(rloc2Value));
496 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
497 assertEquals(1, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
498 assertEquals(LispAFIConvertor.toContainer(rloc2), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer());
501 public void testMapRegisterOverwritesNoSubkey() throws SocketTimeoutException {
503 lms.setOverwrite(true);
504 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
505 LispAFIAddress rloc1Value = LispAFIConvertor.asIPAfiAddress("4.3.2.1");
506 LispAFIAddress rloc2Value = LispAFIConvertor.asIPAfiAddress("4.3.2.2");
507 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
508 assertEquals(1, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
509 assertEquals(LispAFIConvertor.toContainer(rloc2Value), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
510 .getLispAddressContainer());
513 public void testMapRegisterDoesntOverwritesNoSubkey() throws SocketTimeoutException {
515 lms.setOverwrite(false);
516 LispAFIAddress eid = LispAFIConvertor.toAFI(LispAFIConvertor.asIPv4Address("1.2.3.4"));
517 LispAFIAddress rloc1Value = LispAFIConvertor.asIPAfiAddress("4.3.2.1");
518 LispAFIAddress rloc2Value = LispAFIConvertor.asIPAfiAddress("4.3.2.2");
519 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
520 assertEquals(1, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
521 LispAddressContainer rloc1ReturnValueContainer = mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer();
522 LispAddressContainer rloc2ReturnValueContainer = mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getLispAddressContainer();
523 assertTrue((LispAFIConvertor.toContainer(rloc1Value).equals(rloc1ReturnValueContainer) && LispAFIConvertor.toContainer(rloc2Value).equals(
524 rloc2ReturnValueContainer))
525 || (LispAFIConvertor.toContainer(rloc1Value).equals(rloc2ReturnValueContainer) && LispAFIConvertor.toContainer(rloc2Value).equals(
526 rloc1ReturnValueContainer)));
529 private MapReply sendMapRegisterTwiceWithDiffrentValues(LispAFIAddress eid, LispAFIAddress rloc1, LispAFIAddress rloc2)
530 throws SocketTimeoutException {
531 MapRegister mb = createMapRegister(eid, rloc1);
532 MapNotify mapNotify = lms.handleMapRegister(mb, false);
533 MapRequest mr = createMapRequest(eid);
534 MapReply mapReply = lms.handleMapRequest(mr);
535 assertEquals(mb.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer(), mapReply.getEidToLocatorRecord().get(0)
536 .getLocatorRecord().get(0).getLispAddressContainer());
537 mb = createMapRegister(eid, rloc2);
538 mapNotify = lms.handleMapRegister(mb, false);
539 assertEquals(8, mapNotify.getNonce().longValue());
540 mr = createMapRequest(eid);
542 mapReply = lms.handleMapRequest(mr);
546 public void mapRegisterWithAuthenticationWithoutConfiguringAKey() throws SocketTimeoutException {
548 sendPacket(mapRegisterPacketWithAuthenticationAndMapNotify);
551 // If didn't timeout then fail:
553 } catch (SocketTimeoutException ste) {
557 public void mapRegisterWithoutMapNotify() {
559 sendPacket(mapRegisterPacketWithoutNotify);
562 // If didn't timeout then fail:
564 } catch (SocketTimeoutException ste) {
568 public void registerQueryRegisterWithSmr() throws SocketTimeoutException {
570 lms.setShouldUseSmr(true);
572 sendPacket(mapRegisterPacketWithNotify);
575 sendPacket(mapRequestPacket);
578 } catch (InterruptedException e) {
579 LOG.warn("Interrupted while sleeping");
582 mapRegisterPacketWithoutNotify[mapRegisterPacketWithoutNotify.length - 1] += 1;
583 sendPacket(mapRegisterPacketWithoutNotify);
585 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
586 MapRequest smr = MapRequestSerializer.getInstance().deserialize(readBuf);
587 assertTrue(smr.isSmr());
588 LispAddressContainer sourceEid = smr.getSourceEid().getLispAddressContainer();
589 assertTrue(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("153.16.254.1")).equals(sourceEid));
590 LispAddressContainer smrEid = smr.getEidRecord().get(0).getLispAddressContainer();
591 assertTrue(LispAFIConvertor.asIPv4Address("1.2.3.4").equals(smrEid));
594 // --------------------- Northbound Tests ---------------------------
596 private void northboundAddKey() throws Exception {
598 LispIpv4Address address = LispAFIConvertor.asIPAfiAddress("1.2.3.4");
600 String pass = "asdf";
602 URL url = createPutURL("key");
603 String authKeyJSON = createAuthKeyJSON(pass, address, mask);
604 callURL("PUT", "application/json", "text/plain", authKeyJSON, url);
606 String retrievedKey = lms.getAuthenticationKey(LispAFIConvertor.toContainer(address), mask);
608 // Check stored password matches the one sent
609 assertEquals(pass, retrievedKey);
613 private void northboundRetrieveSourceDestKey() throws Exception {
615 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) LispAFIConvertor
616 .toPrimitive(LispAFIConvertor.asIPAfiAddress("10.0.0.1"));
617 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) LispAFIConvertor
618 .toPrimitive(LispAFIConvertor.asIPAfiAddress("10.0.0.2"));
621 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
622 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
623 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(address1).build()).setSrcMaskLength((short) mask1)
624 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(address2).build()).setDstMaskLength((short) mask2).build();
625 String pass = "asdf";
627 lms.addAuthenticationKey(LispAFIConvertor.toContainer(sourceDestAddress), mask1, pass);
629 // URL url = createGetKeyIPv4URL(address1, mask1);
630 URL url = createGetKeySourceDestURL(address1.getIpv4Address().getAfi(),
631 ((LispIpv4Address) LispAFIConvertor.toAFIfromPrimitive(sourceDestAddress.getSrcAddress().getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getSrcMaskLength(),
632 ((LispIpv4Address) LispAFIConvertor.toAFIfromPrimitive(sourceDestAddress.getDstAddress().getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getDstMaskLength());
633 String reply = callURL("GET", null, "application/json", null, url);
634 JSONTokener jt = new JSONTokener(reply);
635 JSONObject json = new JSONObject(jt);
637 // test that the password matches what was we expected.
638 assertEquals(pass, json.get("key"));
642 private void northboundRetrieveKey() throws Exception {
644 LispIpv4Address address = LispAFIConvertor.asIPAfiAddress("10.0.0.1");
646 String pass = "asdf";
648 lms.addAuthenticationKey(LispAFIConvertor.toContainer(address), mask, pass);
650 URL url = createGetKeyIPv4URL(address, mask);
651 String reply = callURL("GET", null, "application/json", null, url);
652 JSONTokener jt = new JSONTokener(reply);
653 JSONObject json = new JSONObject(jt);
655 // test that the password matches what was we expected.
656 assertEquals(pass, json.get("key"));
660 private String createAuthKeyJSON(String key, LispIpv4Address address, int mask) {
661 return "{\"key\" : \"" + key + "\",\"maskLength\" : " + mask + ",\"address\" : " + "{\"ipAddress\" : \""
662 + address.getIpv4Address().getValue() + "\",\"afi\" : " + address.getAfi().shortValue() + "}}";
665 private void northboundAddMapping() throws Exception {
667 String pass = "asdf";
668 LispIpv4Address eid = LispAFIConvertor.asIPAfiAddress("10.0.0.1");
670 LispIpv4Address rloc = LispAFIConvertor.asIPAfiAddress("20.0.0.2");
672 // NB add mapping always checks the key
673 lms.addAuthenticationKey(LispAFIConvertor.toContainer(eid), mask, pass);
675 URL url = createPutURL("mapping");
676 String mapRegisterJSON = createMapRegisterJSON(pass, eid, mask, rloc);
677 callURL("PUT", "application/json", "text/plain", mapRegisterJSON, url);
679 // Retrieve the RLOC from the database
680 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
681 mapRequestBuilder.setPitr(false);
682 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
683 mapRequestBuilder.getEidRecord().add(
684 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
685 MapReply mapReply = lms.handleMapRequest(mapRequestBuilder.build());
687 LispIpv4Address retrievedRloc = (LispIpv4Address) LispAFIConvertor.toAFI(
688 mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer());
690 assertEquals(rloc.getIpv4Address().getValue(), retrievedRloc.getIpv4Address().getValue());
694 private String createMapRegisterJSON(String key, LispIpv4Address eid, int mask, LispIpv4Address rloc) {
695 String jsonString = "{ " + "\"key\" : \"" + key + "\"," + "\"mapregister\" : " + "{ " + "\"proxyMapReply\" : false, "
696 + "\"eidToLocatorRecords\" : " + "[ " + "{ " + "\"authoritative\" : true," + "\"prefixGeneric\" : " + "{ " + "\"ipAddress\" : \""
697 + eid.getIpv4Address().getValue() + "\"," + "\"afi\" : " + eid.getAfi().shortValue() + "}," + "\"mapVersion\" : 0,"
698 + "\"maskLength\" : " + mask + ", " + "\"action\" : \"NoAction\"," + "\"locators\" : " + "[ " + "{ " + "\"multicastPriority\" : 1,"
699 + "\"locatorGeneric\" : " + "{ " + "\"ipAddress\" : \"" + rloc.getIpv4Address().getValue() + "\"," + "\"afi\" : "
700 + rloc.getAfi().shortValue() + "}, " + "\"routed\" : true," + "\"multicastWeight\" : 50," + "\"rlocProbed\" : false, "
701 + "\"localLocator\" : false, " + "\"priority\" : 1, " + "\"weight\" : 50 " + "} " + "], " + "\"recordTtl\" : 100" + "} " + "], "
702 + "\"nonce\" : 3," + "\"keyId\" : 0 " + "} " + "}";
707 private void northboundRetrieveMapping() throws Exception {
709 LispIpv4Address eid = LispAFIConvertor.asIPAfiAddress("10.0.0.1");
711 LispIpv4Address rloc = LispAFIConvertor.asIPAfiAddress("20.0.0.2");
712 // Insert mapping in the database
713 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
714 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
715 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
716 etlr.setMaskLength((short) mask);
717 etlr.setRecordTtl(254);
718 etlr.setAuthoritative(false);
719 etlr.setAction(Action.NoAction);
720 LocatorRecordBuilder record = new LocatorRecordBuilder();
721 record.setLispAddressContainer(LispAFIConvertor.toContainer(rloc));
722 record.setRouted(true);
723 record.setRlocProbed(false);
724 record.setLocalLocator(false);
725 record.setPriority((short) 1);
726 record.setWeight((short) 50);
727 record.setMulticastPriority((short) 1);
728 record.setMulticastWeight((short) 1);
729 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
730 etlr.getLocatorRecord().add(record.build());
731 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
732 mapRegister.getEidToLocatorRecord().add(etlr.build());
733 lms.handleMapRegister(mapRegister.build(), false);
735 // Get mapping using NB interface. No IID used
736 URL url = createGetMappingIPv4URL(0, eid, mask);
737 String reply = callURL("GET", null, "application/json", null, url);
738 JSONTokener jt = new JSONTokener(reply);
739 JSONObject json = new JSONObject(jt);
741 // With just one locator, locators is not a JSONArray
742 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric").getString("ipAddress");
744 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
748 private void northboundDeleteMapping() throws Exception {
750 LispIpv4Address eid = LispAFIConvertor.asIPAfiAddress("10.0.0.1");
752 LispIpv4Address rloc = LispAFIConvertor.asIPAfiAddress("20.0.0.2");
753 // Insert mapping in the database
754 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
755 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
756 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
757 etlr.setMaskLength((short) mask);
758 etlr.setRecordTtl(254);
759 etlr.setAuthoritative(false);
760 etlr.setAction(Action.NoAction);
761 LocatorRecordBuilder record = new LocatorRecordBuilder();
762 record.setLispAddressContainer(LispAFIConvertor.toContainer(rloc));
763 record.setRouted(true);
764 record.setRlocProbed(false);
765 record.setLocalLocator(false);
766 record.setPriority((short) 1);
767 record.setWeight((short) 50);
768 record.setMulticastPriority((short) 1);
769 record.setMulticastWeight((short) 1);
770 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
771 etlr.getLocatorRecord().add(record.build());
772 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
773 mapRegister.getEidToLocatorRecord().add(etlr.build());
774 lms.handleMapRegister(mapRegister.build(), false);
776 // Delete mapping using NB interface. No IID used
777 URL url = createDeleteMappingIPv4URL(0, eid, mask);
778 String reply = callURL("DELETE", null, "application/json", null, url);
780 // Get mapping using NB interface. No IID used
781 url = createGetMappingIPv4URL(0, eid, mask);
782 reply = callURL("GET", null, "application/json", null, url);
783 JSONTokener jt = new JSONTokener(reply);
784 JSONObject json = new JSONObject(jt);
786 // With just one locator, locators is not a JSONArray
787 assertEquals(json.getJSONArray("locators").length(), 0);
790 private void northboundRetrieveSourceDestMapping() throws Exception {
792 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) LispAFIConvertor
793 .toPrimitive(LispAFIConvertor.asIPAfiAddress("10.0.0.1"));
794 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) LispAFIConvertor
795 .toPrimitive(LispAFIConvertor.asIPAfiAddress("10.0.0.2"));
798 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
799 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
800 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(address1).build()).setSrcMaskLength((short) mask1)
801 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(address2).build()).setDstMaskLength((short) mask2).build();
802 LispIpv4Address rloc = LispAFIConvertor.asIPAfiAddress("20.0.0.2");
804 // Insert mapping in the database
805 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
806 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
807 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(sourceDestAddress));
808 etlr.setMaskLength((short) mask1);
809 etlr.setRecordTtl(254);
810 etlr.setAuthoritative(false);
811 etlr.setAction(Action.NoAction);
812 LocatorRecordBuilder record = new LocatorRecordBuilder();
813 record.setLispAddressContainer(LispAFIConvertor.toContainer(rloc));
814 record.setRouted(true);
815 record.setRlocProbed(false);
816 record.setLocalLocator(false);
817 record.setPriority((short) 1);
818 record.setWeight((short) 50);
819 record.setMulticastPriority((short) 1);
820 record.setMulticastWeight((short) 1);
821 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
822 etlr.getLocatorRecord().add(record.build());
823 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
824 mapRegister.getEidToLocatorRecord().add(etlr.build());
825 lms.handleMapRegister(mapRegister.build(), false);
827 // Get mapping using NB interface. No IID used
828 URL url = createGetMappingSourceDestURL(address1.getIpv4Address().getAfi(),
829 address1.getIpv4Address().getIpv4Address().getValue(),
831 address2.getIpv4Address().getIpv4Address().getValue(),
833 String reply = callURL("GET", null, "application/json", null, url);
834 JSONTokener jt = new JSONTokener(reply);
835 JSONObject json = new JSONObject(jt);
837 // With just one locator, locators is not a JSONArray
838 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric").getString("ipAddress");
840 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
844 private URL createGetKeyIPv4URL(LispIpv4Address address, int mask) throws MalformedURLException {
845 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d", "key", address.getAfi().shortValue(),
846 address.getIpv4Address().getValue(), mask);
847 URL url = new URL(restUrl);
851 private URL createGetKeySourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask) throws MalformedURLException {
852 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d", "key", afi, srcAddress, srcMask,
853 dstAddress, dstMask);
854 URL url = new URL(restUrl);
858 private URL createGetMappingSourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask) throws MalformedURLException {
859 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d", "mapping", afi, srcAddress,
860 srcMask, dstAddress, dstMask);
861 URL url = new URL(restUrl);
865 private URL createGetMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
866 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping", iid, address.getAfi()
867 .shortValue(), address.getIpv4Address().getValue(), mask);
868 URL url = new URL(restUrl);
872 private URL createDeleteMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
873 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping", iid, address.getAfi()
874 .shortValue(), address.getIpv4Address().getValue(), mask);
875 URL url = new URL(restUrl);
879 private URL createPutURL(String resource) throws MalformedURLException {
881 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s", resource);
883 URL url = new URL(restUrl);
887 private String createAuthenticationString() {
888 String authString = "admin:admin";
889 byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
890 String authStringEnc = new String(authEncBytes);
891 return authStringEnc;
894 private String callURL(String method, String content, String accept, String body, URL url) throws IOException, JSONException {
895 String authStringEnc = createAuthenticationString();
896 connection = (HttpURLConnection) url.openConnection();
897 connection.setRequestMethod(method);
898 connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
899 if (content != null) {
900 connection.setRequestProperty("Content-Type", content);
902 if (accept != null) {
903 connection.setRequestProperty("Accept", accept);
906 // now add the request body
907 connection.setDoOutput(true);
908 OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
912 connection.connect();
914 // getting the result, first check response code
915 Integer httpResponseCode = connection.getResponseCode();
917 if (httpResponseCode > 299) {
918 LOG.trace("HTTP Address: " + url);
919 LOG.trace("HTTP Response Code: " + httpResponseCode);
923 InputStream is = connection.getInputStream();
924 BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
925 StringBuilder sb = new StringBuilder();
927 while ((cp = rd.read()) != -1) {
928 sb.append((char) cp);
931 connection.disconnect();
932 return (sb.toString());
935 // timePeriod - in ms
936 public void assertNoPacketReceived(int timePeriod) {
938 receivePacket(timePeriod);
939 // If didn't timeout then fail:
941 } catch (SocketTimeoutException ste) {
945 // ------------------------------- Mask Tests ---------------------------
947 public void eidPrefixLookupIPv4() throws SocketTimeoutException {
949 runPrefixTest(LispAFIConvertor.asIPAfiAddress("1.2.3.4"), 16, LispAFIConvertor.asIPAfiAddress("1.2.3.2"),
950 LispAFIConvertor.asIPAfiAddress("1.1.1.1"), (byte) 32);
953 public void eidPrefixLookupIPv6() throws SocketTimeoutException {
955 runPrefixTest(LispAFIConvertor.asIPv6AfiAddress("1:2:3:4:5:6:7:8"), 64, LispAFIConvertor.asIPv6AfiAddress("1:2:3:4:5:1:2:3"),
956 LispAFIConvertor.asIPv6AfiAddress("1:2:3:1:2:3:1:2"), 128);
959 private void runPrefixTest(LispAFIAddress registerEID, int registerdMask, LispAFIAddress matchedAddress, LispAFIAddress unMatchedAddress, int mask)
960 throws SocketTimeoutException {
962 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
963 mapRegister.setWantMapNotify(true);
964 mapRegister.setNonce((long) 8);
965 mapRegister.setWantMapNotify(true);
966 mapRegister.setKeyId((short) 0);
967 mapRegister.setAuthenticationData(new byte[0]);
968 mapRegister.setNonce((long) 8);
969 mapRegister.setProxyMapReply(false);
970 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
971 etlr.setRecordTtl(254);
972 etlr.setAction(Action.NoAction);
973 etlr.setAuthoritative(false);
974 etlr.setMapVersion((short) 0);
975 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(registerEID));
976 etlr.setMaskLength((short) registerdMask);
977 etlr.setRecordTtl(254);
978 LocatorRecordBuilder record = new LocatorRecordBuilder();
979 record.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
980 record.setLocalLocator(false);
981 record.setRlocProbed(false);
982 record.setRouted(true);
983 record.setMulticastPriority((short) 0);
984 record.setMulticastWeight((short) 0);
985 record.setPriority((short) 0);
986 record.setWeight((short) 0);
987 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
988 etlr.getLocatorRecord().add(record.build());
989 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
990 mapRegister.getEidToLocatorRecord().add(etlr.build());
991 sendMapRegister(mapRegister.build());
992 MapNotify mapNotify = receiveMapNotify();
993 assertEquals(8, mapNotify.getNonce().longValue());
994 MapRequestBuilder mapRequest = new MapRequestBuilder();
995 mapRequest.setNonce((long) 4);
996 mapRequest.setSourceEid(new SourceEidBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
997 mapRequest.setEidRecord(new ArrayList<EidRecord>());
998 mapRequest.setAuthoritative(false);
999 mapRequest.setMapDataPresent(false);
1000 mapRequest.setPitr(false);
1001 mapRequest.setProbe(false);
1002 mapRequest.setSmr(false);
1003 mapRequest.setSmrInvoked(false);
1004 mapRequest.getEidRecord().add(
1005 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(LispAFIConvertor.toContainer(matchedAddress)).build());
1006 mapRequest.setItrRloc(new ArrayList<ItrRloc>());
1007 mapRequest.getItrRloc().add(
1008 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1009 sendMapRequest(mapRequest.build());
1010 MapReply mapReply = receiveMapReply();
1011 assertEquals(4, mapReply.getNonce().longValue());
1012 assertEquals(record.getLispAddressContainer(), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer());
1013 mapRequest.setEidRecord(new ArrayList<EidRecord>());
1014 mapRequest.getEidRecord().add(
1015 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(LispAFIConvertor.toContainer(unMatchedAddress)).build());
1016 sendMapRequest(mapRequest.build());
1017 mapReply = receiveMapReply();
1018 assertEquals(0, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
1021 // This registers an IP with a MapRegister, then adds a password via the
1022 // northbound REST API
1023 // and checks that the password works
1024 public void testPasswordExactMatch() throws Exception {
1026 String ipString = "10.0.0.1";
1027 LispIpv4Address address = LispAFIConvertor.asIPAfiAddress(ipString);
1029 String pass = "pass";
1031 URL url = createPutURL("key");
1033 String jsonAuthData = createAuthKeyJSON(pass, address, mask);
1035 LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
1036 LOG.trace("Address: " + address);
1038 byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232, (byte) 31, (byte) 249, (byte) 87,
1039 (byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53, (byte) 196, (byte) 62 };
1041 byte[] zeros = new byte[20];
1043 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1045 // build a MapRegister
1046 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1047 mapRegister.setWantMapNotify(true);
1048 mapRegister.setNonce((long) 8);
1049 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1050 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(address));
1051 etlr.setMaskLength((short) mask);
1052 etlr.setRecordTtl(254);
1053 LocatorRecordBuilder record = new LocatorRecordBuilder();
1054 record.setLispAddressContainer(LispAFIConvertor.toContainer(locatorEid));
1055 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1056 etlr.getLocatorRecord().add(record.build());
1057 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1058 mapRegister.getEidToLocatorRecord().add(etlr.build());
1060 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1061 mapRegister.setAuthenticationData(zeros);
1063 sendMapRegister(mapRegister.build());
1064 assertNoPacketReceived(3000);
1066 mapRegister.setAuthenticationData(expectedSha);
1068 sendMapRegister(mapRegister.build());
1070 assertMapNotifyRecieved();
1073 public void testPasswordMaskMatch() throws Exception {
1075 LispIpv4Address addressInRange = LispAFIConvertor.asIPAfiAddress("10.20.30.40");
1076 LispIpv4Address addressOutOfRange = LispAFIConvertor.asIPAfiAddress("20.40.30.40");
1077 LispIpv4Address range = LispAFIConvertor.asIPAfiAddress("10.20.30.0");
1080 String pass = "pass";
1082 URL url = createPutURL("key");
1083 String jsonAuthData = createAuthKeyJSON(pass, range, 8);
1085 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1086 // build a MapRegister
1087 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1089 mapRegister.setWantMapNotify(true);
1090 mapRegister.setNonce((long) 8);
1091 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1092 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(addressInRange));
1093 etlr.setMaskLength((short) mask);
1094 etlr.setRecordTtl(254);
1095 LocatorRecordBuilder record = new LocatorRecordBuilder();
1096 record.setLispAddressContainer(LispAFIConvertor.toContainer(locatorEid));
1097 record.setLispAddressContainer(LispAFIConvertor.toContainer(locatorEid));
1098 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1099 etlr.getLocatorRecord().add(record.build());
1100 mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1101 mapRegister.getEidToLocatorRecord().add(etlr.build());
1103 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1105 .setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4, -67, -113, 104, -110, -71 });
1107 sendMapRegister(mapRegister.build());
1109 assertMapNotifyRecieved();
1111 etlr.setLispAddressContainer(LispAFIConvertor.toContainer(addressOutOfRange));
1113 .setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123, -71, -14, -99, 67, -23, -73 });
1115 sendMapRegister(mapRegister.build());
1116 assertNoPacketReceived(3000);
1119 private MapReply registerAddressAndQuery(LispAFIAddress eid) throws SocketTimeoutException {
1120 return registerAddressAndQuery(eid, -1);
1123 // takes an address, packs it in a MapRegister and sends it
1124 private void registerAddress(LispAddressContainer eid, int maskLength) throws SocketTimeoutException {
1125 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1126 mapRegisterBuilder.setWantMapNotify(true);
1127 mapRegisterBuilder.setKeyId((short) 0);
1128 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1129 mapRegisterBuilder.setNonce((long) 8);
1130 mapRegisterBuilder.setProxyMapReply(false);
1131 EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
1132 etlrBuilder.setLispAddressContainer(eid);
1133 if (maskLength != -1) {
1134 etlrBuilder.setMaskLength((short) maskLength);
1136 etlrBuilder.setMaskLength((short) 0);
1138 etlrBuilder.setRecordTtl(254);
1139 etlrBuilder.setAction(Action.NoAction);
1140 etlrBuilder.setAuthoritative(false);
1141 etlrBuilder.setMapVersion((short) 0);
1142 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1143 recordBuilder.setLocalLocator(false);
1144 recordBuilder.setRlocProbed(false);
1145 recordBuilder.setRouted(true);
1146 recordBuilder.setMulticastPriority((short) 0);
1147 recordBuilder.setMulticastWeight((short) 0);
1148 recordBuilder.setPriority((short) 0);
1149 recordBuilder.setWeight((short) 0);
1150 recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(locatorEid));
1151 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1152 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1153 mapRegisterBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1154 mapRegisterBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
1155 sendMapRegister(mapRegisterBuilder.build());
1156 MapNotify mapNotify = receiveMapNotify();
1157 assertEquals(8, mapNotify.getNonce().longValue());
1160 private MapReply queryForAddress(LispAddressContainer eid, String srcEid) throws SocketTimeoutException {
1161 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1162 mapRequestBuilder.setNonce((long) 4);
1163 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
1164 mapRequestBuilder.getEidRecord().add(
1165 new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(eid).build());
1166 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1167 if (srcEid != null) {
1168 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(LispAFIConvertor.
1169 toContainer(LispAFIConvertor.asIPAfiAddress(srcEid))).build());
1171 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(LispAFIConvertor.
1172 toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1174 mapRequestBuilder.getItrRloc().add(
1175 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1176 mapRequestBuilder.setAuthoritative(false);
1177 mapRequestBuilder.setMapDataPresent(false);
1178 mapRequestBuilder.setPitr(false);
1179 mapRequestBuilder.setProbe(false);
1180 mapRequestBuilder.setSmr(false);
1181 mapRequestBuilder.setSmrInvoked(false);
1182 sendMapRequest(mapRequestBuilder.build());
1183 return receiveMapReply();
1186 // takes an address, packs it in a MapRegister, sends it, returns the
1188 private MapReply registerAddressAndQuery(LispAFIAddress eid, int maskLength) throws SocketTimeoutException {
1189 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1190 mapRegisterBuilder.setWantMapNotify(true);
1191 mapRegisterBuilder.setKeyId((short) 0);
1192 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1193 mapRegisterBuilder.setNonce((long) 8);
1194 mapRegisterBuilder.setProxyMapReply(false);
1195 EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
1196 etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
1197 if (maskLength != -1) {
1198 etlrBuilder.setMaskLength((short) maskLength);
1200 etlrBuilder.setMaskLength((short) 0);
1202 etlrBuilder.setRecordTtl(254);
1203 etlrBuilder.setAction(Action.NoAction);
1204 etlrBuilder.setAuthoritative(false);
1205 etlrBuilder.setMapVersion((short) 0);
1206 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1207 recordBuilder.setLocalLocator(false);
1208 recordBuilder.setRlocProbed(false);
1209 recordBuilder.setRouted(true);
1210 recordBuilder.setMulticastPriority((short) 0);
1211 recordBuilder.setMulticastWeight((short) 0);
1212 recordBuilder.setPriority((short) 0);
1213 recordBuilder.setWeight((short) 0);
1214 recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(locatorEid));
1215 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1216 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1217 mapRegisterBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1218 mapRegisterBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
1219 sendMapRegister(mapRegisterBuilder.build());
1220 MapNotify mapNotify = receiveMapNotify();
1221 assertEquals(8, mapNotify.getNonce().longValue());
1222 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1223 mapRequestBuilder.setNonce((long) 4);
1224 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
1225 mapRequestBuilder.getEidRecord().add(
1226 new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
1227 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1228 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress)))
1230 mapRequestBuilder.getItrRloc().add(
1231 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1232 mapRequestBuilder.setAuthoritative(false);
1233 mapRequestBuilder.setMapDataPresent(false);
1234 mapRequestBuilder.setPitr(false);
1235 mapRequestBuilder.setProbe(false);
1236 mapRequestBuilder.setSmr(false);
1237 mapRequestBuilder.setSmrInvoked(false);
1238 sendMapRequest(mapRequestBuilder.build());
1239 return receiveMapReply();
1242 // ------------------------------- LCAF Tests ---------------------------
1245 public void registerAndQuery__SrcDestLCAF() throws SocketTimeoutException {
1247 String ipString = "10.20.30.200";
1248 String macString = "01:02:03:04:05:06";
1249 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend1 = LispAFIConvertor.asPrimitiveIPv4AfiPrefix(ipString, 32);
1250 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Mac addrToSend2 = LispAFIConvertor.asPrimitiveMacAfiAddress(macString);
1251 LcafSourceDestAddrBuilder builder = new LcafSourceDestAddrBuilder();
1252 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
1253 builder.setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
1254 builder.setSrcMaskLength((short) 32);
1255 builder.setDstMaskLength((short) 0);
1256 builder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(addrToSend1).build());
1257 builder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress(addrToSend2).build());
1259 MapReply reply = registerAddressAndQuery(builder.build());
1261 LispAddressContainer fromNetwork = reply.getEidToLocatorRecord().get(0).getLispAddressContainer();
1262 assertTrue(fromNetwork.getAddress() instanceof LcafSourceDest);
1263 LcafSourceDest sourceDestFromNetwork = (LcafSourceDest) fromNetwork.getAddress();
1265 LispAFIAddress receivedAddr1 = LispAFIConvertor.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getSrcAddress().getPrimitiveAddress());
1266 LispAFIAddress receivedAddr2 = LispAFIConvertor.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getDstAddress().getPrimitiveAddress());
1268 assertTrue(receivedAddr1 instanceof LispIpv4Address);
1269 assertTrue(receivedAddr2 instanceof LispMacAddress);
1271 LispIpv4Address receivedIP = (LispIpv4Address) receivedAddr1;
1272 LispMacAddress receivedMAC = (LispMacAddress) receivedAddr2;
1274 assertEquals(ipString, receivedIP.getIpv4Address().getValue());
1275 assertEquals(macString, receivedMAC.getMacAddress().getValue());
1279 public void registerAndQuery__SrcDestLCAFOverlap() throws SocketTimeoutException {
1281 String ipString1 = "10.10.10.0";
1282 String ipString2 = "20.20.20.0";
1283 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend1 = LispAFIConvertor.asPrimitiveIPv4AfiPrefix(ipString1, 24);
1284 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend2 = LispAFIConvertor.asPrimitiveIPv4AfiPrefix(ipString2, 24);
1285 LcafSourceDestAddrBuilder builder = new LcafSourceDestAddrBuilder();
1286 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
1287 builder.setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
1288 builder.setSrcMaskLength((short) 24);
1289 builder.setDstMaskLength((short) 24);
1290 builder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(addrToSend1).build());
1291 builder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress(addrToSend2).build());
1293 LispAddressContainer srcDst = LispAFIConvertor.toContainer(builder.build());
1294 registerAddress(LispAFIConvertor.asIPv4Prefix(ipString2, 24), 24);
1295 registerAddress(srcDst, -1);
1298 MapReply reply = queryForAddress(srcDst, null);
1300 LispAddressContainer fromNetwork = reply.getEidToLocatorRecord().get(0).getLispAddressContainer();
1301 assertTrue(fromNetwork.getAddress() instanceof LcafSourceDest);
1302 LcafSourceDest sourceDestFromNetwork = (LcafSourceDest) fromNetwork.getAddress();
1304 LispAFIAddress receivedAddr1 = LispAFIConvertor.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getSrcAddress().getPrimitiveAddress());
1305 LispAFIAddress receivedAddr2 = LispAFIConvertor.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getDstAddress().getPrimitiveAddress());
1307 assertTrue(receivedAddr1 instanceof LispIpv4Address);
1308 assertTrue(receivedAddr2 instanceof LispIpv4Address);
1310 LispIpv4Address receivedIP1 = (LispIpv4Address) receivedAddr1;
1311 LispIpv4Address receivedIP2 = (LispIpv4Address) receivedAddr2;
1313 assertEquals(ipString1, receivedIP1.getIpv4Address().getValue());
1314 assertEquals(ipString2, receivedIP2.getIpv4Address().getValue());
1316 // srcEid/dstEid match
1317 reply = queryForAddress(LispAFIConvertor.asIPv4Address("20.20.20.1"), "10.10.10.1");
1318 fromNetwork = reply.getEidToLocatorRecord().get(0).getLispAddressContainer();
1319 assertTrue(fromNetwork.getAddress() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.Ipv4);
1321 Ipv4Address ipAddr2 = ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.Ipv4) fromNetwork.getAddress()).getIpv4Address();
1322 assertEquals(ipString2, ipAddr2.getIpv4Address().getValue());
1324 // dstEid match only
1325 reply = queryForAddress(LispAFIConvertor.asIPv4Address("20.20.20.1"), "1.2.3.4");
1326 fromNetwork = reply.getEidToLocatorRecord().get(0).getLispAddressContainer();
1327 assertTrue(fromNetwork.getAddress() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.Ipv4);
1329 ipAddr2 = ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.Ipv4) fromNetwork.getAddress()).getIpv4Address();
1330 assertEquals(ipString2, ipAddr2.getIpv4Address().getValue());
1334 public void registerAndQuery__KeyValueLCAF() throws SocketTimeoutException {
1336 String ipString = "10.20.30.200";
1337 String macString = "01:02:03:04:05:06";
1338 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend1 = LispAFIConvertor.asPrimitiveIPAfiAddress(ipString);
1339 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Mac addrToSend2 = LispAFIConvertor.asPrimitiveMacAfiAddress(macString);
1340 LcafKeyValueAddressAddrBuilder builder = new LcafKeyValueAddressAddrBuilder();
1341 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
1342 builder.setLcafType((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode());
1343 builder.setKey(new KeyBuilder().setPrimitiveAddress(addrToSend1).build());
1344 builder.setValue(new ValueBuilder().setPrimitiveAddress(addrToSend2).build());
1346 MapReply reply = registerAddressAndQuery(builder.build());
1348 LispAddressContainer fromNetwork = reply.getEidToLocatorRecord().get(0).getLispAddressContainer();
1349 assertTrue(fromNetwork.getAddress() instanceof LcafKeyValue);
1350 LcafKeyValue keyValueFromNetwork = (LcafKeyValue) fromNetwork.getAddress();
1352 LispAFIAddress receivedAddr1 = LispAFIConvertor.toAFIfromPrimitive(keyValueFromNetwork.getLcafKeyValueAddressAddr().getKey().getPrimitiveAddress());
1353 LispAFIAddress receivedAddr2 = LispAFIConvertor.toAFIfromPrimitive(keyValueFromNetwork.getLcafKeyValueAddressAddr().getValue().getPrimitiveAddress());
1355 assertTrue(receivedAddr1 instanceof LispIpv4Address);
1356 assertTrue(receivedAddr2 instanceof LispMacAddress);
1358 LispIpv4Address receivedIP = (LispIpv4Address) receivedAddr1;
1359 LispMacAddress receivedMAC = (LispMacAddress) receivedAddr2;
1361 assertEquals(ipString, receivedIP.getIpv4Address().getValue());
1362 assertEquals(macString, receivedMAC.getMacAddress().getValue());
1365 public void registerAndQuery__ListLCAF() throws SocketTimeoutException {
1367 String macString = "01:02:03:04:05:06";
1368 String ipString = "10.20.255.30";
1369 LcafListAddrBuilder listbuilder = new LcafListAddrBuilder();
1370 listbuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.LIST.getLispCode());
1371 listbuilder.setAddresses(new ArrayList<Addresses>());
1372 listbuilder.getAddresses().add(new AddressesBuilder().setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress(ipString))).build());
1373 listbuilder.getAddresses().add(new AddressesBuilder().setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asMacAfiAddress(macString))).build());
1375 MapReply reply = registerAddressAndQuery(listbuilder.build());
1377 LispAFIAddress receivedAddress = LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0).getLispAddressContainer());
1379 assertTrue(receivedAddress instanceof LcafListAddress);
1381 LcafListAddress listAddrFromNetwork = (LcafListAddress) receivedAddress;
1382 LispAFIAddress receivedAddr1 = LispAFIConvertor.toAFIfromPrimitive(listAddrFromNetwork.getAddresses().get(0).getPrimitiveAddress());
1383 LispAFIAddress receivedAddr2 = LispAFIConvertor.toAFIfromPrimitive(listAddrFromNetwork.getAddresses().get(1).getPrimitiveAddress());
1385 assertTrue(receivedAddr1 instanceof LispIpv4Address);
1386 assertTrue(receivedAddr2 instanceof LispMacAddress);
1388 assertEquals(macString, ((LispMacAddress) receivedAddr2).getMacAddress().getValue());
1389 assertEquals(ipString, ((LispIpv4Address) receivedAddr1).getIpv4Address().getValue());
1392 public void registerAndQuery__SegmentLCAF() throws SocketTimeoutException {
1394 String ipString = "10.20.255.30";
1396 LcafSegmentAddrBuilder builder = new LcafSegmentAddrBuilder();
1397 builder.setInstanceId((long) instanceId);
1398 builder.setIidMaskLength((short) 32);
1399 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
1400 builder.setAddress(new AddressBuilder().setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress(ipString))).build());
1402 MapReply reply = registerAddressAndQuery(builder.build());
1404 LispAFIAddress receivedAddress = LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0).getLispAddressContainer());
1405 assertTrue(receivedAddress instanceof LcafSegmentAddress);
1407 LcafSegmentAddress segmentfromNetwork = (LcafSegmentAddress) receivedAddress;
1408 LispAFIAddress addrFromSegment = LispAFIConvertor.toAFIfromPrimitive(segmentfromNetwork.getAddress().getPrimitiveAddress());
1409 assertTrue(addrFromSegment instanceof LispIpv4Address);
1410 assertEquals(ipString, ((LispIpv4Address) addrFromSegment).getIpv4Address().getValue());
1412 assertEquals(instanceId, segmentfromNetwork.getInstanceId().intValue());
1415 public void registerAndQuery__TrafficEngineering() throws SocketTimeoutException {
1417 String macString = "01:02:03:04:05:06";
1418 String ipString = "10.20.255.30";
1419 HopBuilder hopBuilder = new HopBuilder();
1420 hopBuilder.setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress(ipString)));
1421 Hop hop1 = hopBuilder.build();
1422 hopBuilder.setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asMacAfiAddress(macString)));
1423 Hop hop2 = hopBuilder.build();
1424 HopsBuilder hb = new HopsBuilder();
1427 hb.setRLOCProbe(false);
1429 HopsBuilder hb2 = new HopsBuilder();
1431 hb2.setLookup(false);
1432 hb2.setRLOCProbe(true);
1433 hb2.setStrict(false);
1434 Hops hops1 = hb.build();
1435 Hops hops2 = hb2.build();
1436 LcafTrafficEngineeringAddrBuilder trafficBuilder = new LcafTrafficEngineeringAddrBuilder();
1437 trafficBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType(
1438 (short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode());
1439 trafficBuilder.setHops(new ArrayList<Hops>());
1440 trafficBuilder.getHops().add(hb.build());
1441 trafficBuilder.getHops().add(hb2.build());
1443 MapReply reply = registerAddressAndQuery(trafficBuilder.build());
1445 assertTrue(LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0).getLispAddressContainer()) instanceof LcafTrafficEngineeringAddress);
1447 LcafTrafficEngineeringAddress receivedAddress = (LcafTrafficEngineeringAddress) LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0)
1448 .getLispAddressContainer());
1450 ReencapHop receivedHop1 = receivedAddress.getHops().get(0);
1451 ReencapHop receivedHop2 = receivedAddress.getHops().get(1);
1453 assertEquals(true, hops1.isLookup());
1454 assertEquals(false, hops1.isRLOCProbe());
1455 assertEquals(true, hops1.isStrict());
1457 assertEquals(false, hops2.isLookup());
1458 assertEquals(true, hops2.isRLOCProbe());
1459 assertEquals(false, hops2.isStrict());
1461 assertTrue(receivedHop1.getHop().getPrimitiveAddress() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4);
1462 assertTrue(receivedHop2.getHop().getPrimitiveAddress() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Mac);
1464 assertEquals(ipString, ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) receivedHop1.getHop().getPrimitiveAddress()).getIpv4Address().getIpv4Address().getValue());
1465 assertEquals(macString, ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Mac) receivedHop2.getHop().getPrimitiveAddress()).getMacAddress().getMacAddress().getValue());
1468 public void registerAndQuery__ApplicationData() throws SocketTimeoutException {
1470 String ipString = "1.2.3.4";
1473 int localPortLow = 3;
1474 int localPortHigh = 4;
1475 int remotePortLow = 4;
1476 int remotePortHigh = 5;
1478 LcafApplicationDataAddrBuilder builder = new LcafApplicationDataAddrBuilder();
1479 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode());
1480 builder.setIpTos(ipTOs);
1481 builder.setProtocol(protocol);
1482 builder.setLocalPortLow(new PortNumber(localPortLow));
1483 builder.setLocalPortHigh(new PortNumber(localPortHigh));
1484 builder.setRemotePortLow(new PortNumber(remotePortLow));
1485 builder.setRemotePortHigh(new PortNumber(remotePortHigh));
1486 builder.setAddress(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafapplicationdataaddress.AddressBuilder()
1487 .setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress(ipString))).build());
1489 LcafApplicationDataAddress addressToSend = builder.build();
1491 MapReply reply = registerAddressAndQuery(addressToSend);
1493 LispAFIAddress receivedAddress = LispAFIConvertor.toAFI(reply.getEidToLocatorRecord().get(0).getLispAddressContainer());
1495 assertTrue(receivedAddress instanceof LcafApplicationDataAddress);
1497 LcafApplicationDataAddress receivedApplicationDataAddress = (LcafApplicationDataAddress) receivedAddress;
1498 assertEquals(protocol, receivedApplicationDataAddress.getProtocol().intValue());
1499 assertEquals(ipTOs, receivedApplicationDataAddress.getIpTos().intValue());
1500 assertEquals(localPortLow, receivedApplicationDataAddress.getLocalPortLow().getValue().intValue());
1501 assertEquals(localPortHigh, receivedApplicationDataAddress.getLocalPortHigh().getValue().intValue());
1502 assertEquals(remotePortLow, receivedApplicationDataAddress.getRemotePortLow().getValue().intValue());
1503 assertEquals(remotePortHigh, receivedApplicationDataAddress.getRemotePortHigh().getValue().intValue());
1505 LispIpv4Address ipAddressReceived = (LispIpv4Address) LispAFIConvertor.toAFIfromPrimitive(receivedApplicationDataAddress.getAddress().getPrimitiveAddress());
1506 assertEquals(ipString, ipAddressReceived.getIpv4Address().getValue());
1509 // ------------------- TimeOut Tests -----------
1511 public void mapRequestMapRegisterAndMapRequestTestTimeout() throws SocketTimeoutException {
1513 LispIpv4Address eid = LispAFIConvertor.asIPAfiAddress("1.2.3.4");
1514 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1515 mapRequestBuilder.setNonce((long) 4);
1516 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
1517 LispAFIConvertor.toContainer(new NoAddressBuilder().setAfi((short) 0).build())).build());
1518 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
1519 mapRequestBuilder.getEidRecord().add(
1520 new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
1521 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1522 mapRequestBuilder.getItrRloc().add(
1523 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1524 sendMapRequest(mapRequestBuilder.build());
1525 MapReply mapReply = receiveMapReply();
1526 assertEquals(4, mapReply.getNonce().longValue());
1527 assertEquals(0, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
1528 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
1529 mapRegisterbuilder.setWantMapNotify(true);
1530 mapRegisterbuilder.setNonce((long) 8);
1531 EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
1532 etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
1533 etlrBuilder.setMaskLength((short) 32);
1534 etlrBuilder.setRecordTtl(254);
1535 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1536 recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
1537 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1538 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1539 mapRegisterbuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1540 mapRegisterbuilder.getEidToLocatorRecord().add(etlrBuilder.build());
1541 sendMapRegister(mapRegisterbuilder.build());
1542 MapNotify mapNotify = receiveMapNotify();
1543 assertEquals(8, mapNotify.getNonce().longValue());
1544 sendMapRequest(mapRequestBuilder.build());
1545 mapReply = receiveMapReply();
1546 assertEquals(4, mapReply.getNonce().longValue());
1547 assertEquals(recordBuilder.getLispAddressContainer(), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
1548 .getLispAddressContainer());
1549 causeEntryToBeCleaned();
1550 sendMapRequest(mapRequestBuilder.build());
1551 mapReply = receiveMapReply();
1552 assertEquals(0, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size());
1555 public void mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse() throws Exception {
1557 LispIpv4Address eid = LispAFIConvertor.asIPAfiAddress("1.2.3.4");
1558 MapRequest mapRequest = createMapRequest(eid);
1560 testTTLBeforeRegister(mapRequest);
1562 registerForTTL(eid);
1564 testTTLAfterRegister(mapRequest);
1566 causeEntryToBeCleaned();
1567 testTTLAfterClean(mapRequest);
1569 //northboundAddKey();
1570 //testTTLAfterAutherize(mapRequest);
1574 private void testTTLAfterClean(MapRequest mapRequest) throws SocketTimeoutException {
1576 sendMapRequest(mapRequest);
1577 mapReply = receiveMapReply();
1578 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
1581 private void causeEntryToBeCleaned() {
1582 // TODO for the time being, to keep master and stable/lithium in sync, we need to remove the forceful
1583 // expiration of DAO entries. Once we're past this, we'll have to expose methods to setTimeUnit(TimeUnit)
1584 // and cleanOld() (expired) entries in IFlowMapping (and perhaps ILispDAO) and use them here.
1588 private void testTTLAfterRegister(MapRequest mapRequest) throws SocketTimeoutException {
1590 sendMapRequest(mapRequest);
1591 mapReply = receiveMapReply();
1592 assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
1593 .getLispAddressContainer());
1594 assertCorrectMapReplyTTLAndAction(mapReply, 254, Action.NoAction);
1597 private void registerForTTL(LispIpv4Address eid) throws SocketTimeoutException {
1598 MapRegister mapRegister = createMapRegister(eid);
1599 sendMapRegister(mapRegister);
1600 assertMapNotifyRecieved();
1603 private void testTTLBeforeRegister(MapRequest mapRequest) throws SocketTimeoutException {
1605 sendMapRequest(mapRequest);
1606 mapReply = receiveMapReply();
1607 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
1610 private void testTTLAfterAutherize(MapRequest mapRequest) throws SocketTimeoutException {
1612 sendMapRequest(mapRequest);
1613 mapReply = receiveMapReply();
1614 assertCorrectMapReplyTTLAndAction(mapReply, 1, Action.NativelyForward);
1617 private void assertCorrectMapReplyTTLAndAction(MapReply mapReply, int expectedTTL, Action expectedAction) {
1618 assertEquals(expectedTTL, mapReply.getEidToLocatorRecord().get(0).getRecordTtl().intValue());
1619 assertEquals(expectedAction, mapReply.getEidToLocatorRecord().get(0).getAction());
1622 private MapRegister createMapRegister(LispAFIAddress eid, LispAFIAddress rloc) {
1623 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
1624 mapRegisterbuilder.setWantMapNotify(true);
1625 mapRegisterbuilder.setNonce((long) 8);
1626 mapRegisterbuilder.setKeyId((short) 0);
1627 EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
1628 etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
1629 etlrBuilder.setMaskLength((short) 24);
1630 etlrBuilder.setRecordTtl(254);
1631 etlrBuilder.setAuthoritative(false);
1632 etlrBuilder.setAction(Action.NoAction);
1633 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1634 recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(rloc));
1635 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1636 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1637 mapRegisterbuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
1638 mapRegisterbuilder.getEidToLocatorRecord().add(etlrBuilder.build());
1639 MapRegister mapRegister = mapRegisterbuilder.build();
1643 private MapRegister createMapRegister(LispIpv4Address eid) {
1644 return createMapRegister(eid, LispAFIConvertor.asIPAfiAddress("4.3.2.1"));
1647 private MapRequest createMapRequest(LispAFIAddress eid) {
1648 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1649 mapRequestBuilder.setNonce((long) 4);
1650 mapRequestBuilder.setPitr(false);
1651 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
1652 LispAFIConvertor.toContainer(new NoAddressBuilder().setAfi((short) 0).build())).build());
1653 mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
1654 mapRequestBuilder.getEidRecord().add(
1655 new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
1656 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1657 mapRequestBuilder.getItrRloc().add(
1658 new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ourAddress))).build());
1659 MapRequest mr = mapRequestBuilder.build();
1663 public void testSimpleNonProxy() throws SocketTimeoutException, SocketException {
1665 String rloc = "127.0.0.3";
1666 int port = LispMessage.PORT_NUM;
1667 LispAFIAddress ipRloc = LispAFIConvertor.asIPAfiAddress(rloc);
1668 sendProxyMapRequest(rloc, port, ipRloc);
1672 public void testNonProxyOtherPort() throws SocketTimeoutException, SocketException {
1674 String rloc = "127.0.0.3";
1676 LcafApplicationDataAddr adLcaf = new LcafApplicationDataAddrBuilder()
1677 .setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
1678 .setLcafType((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode())
1680 new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafapplicationdataaddress.AddressBuilder().setPrimitiveAddress(
1681 LispAFIConvertor.asPrimitiveIPAfiAddress(rloc)).build()).setLocalPortLow(new PortNumber(port)).build();
1682 LOG.info("testNonProxyOtherPort:" + adLcaf.toString());
1683 sendProxyMapRequest(rloc, port, adLcaf);
1687 public void testRecievingNonProxyOnXtrPort() throws SocketTimeoutException, SocketException, Throwable {
1689 configLispPlugin.shouldListenOnXtrPort(true);
1690 notificationCalled = false;
1691 final String eid = "10.10.10.10";
1692 String rloc = "127.0.0.3";
1693 int port = LispMessage.XTR_PORT_NUM;
1694 LcafApplicationDataAddr adLcaf = new LcafApplicationDataAddrBuilder()
1695 .setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
1696 .setLcafType((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode())
1698 new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lcafapplicationdataaddress.AddressBuilder().setPrimitiveAddress(
1699 LispAFIConvertor.asPrimitiveIPAfiAddress(rloc)).build()).setLocalPortLow(new PortNumber(port)).build();
1700 final MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
1701 ((LispMappingService) lms).registerNotificationListener(XtrRequestMapping.class, new NotificationListener<XtrRequestMapping>() {
1704 public void onNotification(XtrRequestMapping notification) {
1705 assertEquals(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.lispaddresscontainer.address.Ipv4) mapRequest.getEidRecord().get(0).getLispAddressContainer().getAddress()).getIpv4Address().getIpv4Address().getValue(),
1707 notificationCalled = true;
1708 LOG.warn("notification arrived");
1711 sendMapRequest(mapRequest, port);
1712 for (int i = 0; i < MAX_NOTIFICATION_RETRYS; i++) {
1713 if (notificationCalled) {
1716 LOG.warn("notification hasn't arrived, sleeping...");
1721 fail("Notification hasn't arrived");
1725 private void sendProxyMapRequest(String rloc, int port, LispAFIAddress adLcaf) throws SocketTimeoutException, SocketException {
1726 String eid = "10.1.0.1";
1727 MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
1728 sendMapRequest(mapRequest);
1729 DatagramSocket nonProxySocket = new DatagramSocket(new InetSocketAddress(rloc, port));
1730 MapRequest recievedMapRequest = receiveMapRequest(nonProxySocket);
1731 assertEquals(mapRequest.getNonce(), recievedMapRequest.getNonce());
1732 assertEquals(mapRequest.getSourceEid(), recievedMapRequest.getSourceEid());
1733 assertEquals(mapRequest.getItrRloc(), recievedMapRequest.getItrRloc());
1734 assertEquals(mapRequest.getEidRecord(), recievedMapRequest.getEidRecord());
1735 nonProxySocket.close();
1738 private MapRequest createNonProxyMapRequest(String eid, LispAFIAddress adLcaf) throws SocketTimeoutException {
1739 MapRegister mr = createMapRegister(LispAFIConvertor.asIPAfiAddress(eid));
1740 LocatorRecord record = new LocatorRecordBuilder(mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)).setLispAddressContainer(
1741 LispAFIConvertor.toContainer(adLcaf)).build();
1742 mr.getEidToLocatorRecord().get(0).getLocatorRecord().set(0, record);
1743 sendMapRegister(mr);
1744 assertMapNotifyRecieved();
1745 MapRequest mapRequest = createMapRequest(LispAFIConvertor.asIPAfiAddress(eid));
1746 MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
1747 builder.setPitr(true);
1748 mapRequest = builder.build();
1752 private void assertMapNotifyRecieved() throws SocketTimeoutException {
1756 private MapReply receiveMapReply() throws SocketTimeoutException {
1757 return MapReplySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
1760 private MapRequest receiveMapRequest(DatagramSocket datagramSocket) throws SocketTimeoutException {
1761 return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket(datagramSocket, 30000).getData()));
1764 private MapNotify receiveMapNotify() throws SocketTimeoutException {
1765 return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
1768 private void sendMapRequest(MapRequest mapRequest) {
1769 sendMapRequest(mapRequest, LispMessage.PORT_NUM);
1772 private void sendMapRequest(MapRequest mapRequest, int port) {
1773 sendPacket(MapRequestSerializer.getInstance().serialize(mapRequest).array(), port);
1776 private void sendMapRegister(MapRegister mapRegister) {
1777 sendPacket(MapRegisterSerializer.getInstance().serialize(mapRegister).array());
1780 private void sendPacket(byte[] bytesToSend) {
1781 sendPacket(bytesToSend, LispMessage.PORT_NUM);
1784 private void sendPacket(byte[] bytesToSend, int port) {
1786 DatagramPacket packet = new DatagramPacket(bytesToSend, bytesToSend.length);
1787 initPacketAddress(packet, port);
1788 LOG.trace("Sending packet to LispPlugin on socket, port {}", port);
1789 socket.send(packet);
1790 } catch (Throwable t) {
1795 private DatagramPacket receivePacket() throws SocketTimeoutException {
1796 return receivePacket(6000);
1799 private DatagramPacket receivePacket(int timeout) throws SocketTimeoutException {
1800 return receivePacket(socket, timeout);
1803 private DatagramPacket receivePacket(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException {
1805 byte[] buffer = new byte[4096];
1806 DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
1807 LOG.trace("Waiting for packet from socket...");
1808 receivedSocket.setSoTimeout(timeout);
1809 receivedSocket.receive(receivePacket);
1810 LOG.trace("Recieved packet from socket!");
1811 return receivePacket;
1812 } catch (SocketTimeoutException ste) {
1814 } catch (Throwable t) {
1820 private void initPacketAddress(DatagramPacket packet, int port) throws UnknownHostException {
1821 packet.setAddress(InetAddress.getByName(lispBindAddress));
1822 packet.setPort(port);
1825 private DatagramSocket initSocket(DatagramSocket socket, int port) {
1827 socket = new DatagramSocket(new InetSocketAddress(ourAddress, port));
1828 } catch (SocketException e) {
1829 e.printStackTrace();
1835 private byte[] extractWSUdpByteArray(String wiresharkHex) {
1836 final int HEADER_LEN = 42;
1837 byte[] res = new byte[1000];
1838 String[] split = wiresharkHex.split(" ");
1840 for (String cur : split) {
1842 if (cur.length() == 2) {
1844 if (counter > HEADER_LEN) {
1845 res[counter - HEADER_LEN - 1] = (byte) Integer.parseInt(cur, 16);
1850 return Arrays.copyOf(res, counter - HEADER_LEN);
1853 private String stateToString(int state) {
1857 case Bundle.INSTALLED:
1859 case Bundle.RESOLVED:
1861 case Bundle.UNINSTALLED:
1862 return "UNINSTALLED";
1864 return "Not CONVERTED";
1868 @SuppressWarnings({ "rawtypes", "unchecked" })
1869 private void areWeReady() throws InvalidSyntaxException {
1872 } catch (InterruptedException e) {
1876 boolean debugit = false;
1877 Bundle b[] = bc.getBundles();
1878 for (Bundle element : b) {
1879 int state = element.getState();
1880 LOG.trace("Bundle[" + element.getBundleId() + "]:" + element.getSymbolicName() + ",v" + element.getVersion() + ", state:"
1881 + stateToString(state));
1882 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
1883 LOG.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
1886 // String host = element.getHeaders().get("FRAGMENT-HOST");
1887 // if (host != null) {
1888 // LOG.warn("Bundle " + element.getSymbolicName() +
1889 // " is a fragment which is part of: " + host);
1890 // LOG.warn("Required imports are: " +
1891 // element.getHeaders().get("IMPORT-PACKAGE"));
1895 // } catch (BundleException e) {
1896 // LOG.error("BundleException:", e);
1905 LOG.warn(("Do some debugging because some bundle is unresolved"));
1907 // assertNotNull(broker);
1909 ServiceReference r = null;
1910 configLispPlugin.setLispAddress(lispBindAddress);
1912 // Uncomment this code to Know which services were actually loaded to
1916 for (ServiceReference sr : bc.getAllServiceReferences(null, null)) {
1917 LOG.info(sr.getBundle().getSymbolicName());
1918 LOG.info(sr.toString());
1924 } catch (InterruptedException e) {
1928 private void cleanUP() {
1931 configLispPlugin.shouldListenOnXtrPort(false);
1932 socket = initSocket(socket, LispMessage.PORT_NUM);