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.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_A;
15 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_A_SB;
16 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_B;
17 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_B_SB;
18 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C;
19 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_RLOC_10;
20 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_SB;
21 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_WP_100_1_SB;
22 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_WP_50_2_SB;
23 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D4;
24 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D5;
25 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_DELETE_SB;
26 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_WP_100_1_SB;
27 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_WP_50_2_SB;
28 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_E_SB;
29 import static org.ops4j.pax.exam.CoreOptions.composite;
30 import static org.ops4j.pax.exam.CoreOptions.maven;
31 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
33 import java.io.IOException;
34 import java.net.DatagramPacket;
35 import java.net.DatagramSocket;
36 import java.net.InetAddress;
37 import java.net.InetSocketAddress;
38 import java.net.SocketException;
39 import java.net.SocketTimeoutException;
40 import java.net.UnknownHostException;
41 import java.nio.ByteBuffer;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.List;
46 import javax.inject.Inject;
48 //import org.codehaus.jettison.json.JSONException;
49 //import org.codehaus.jettison.json.JSONObject;
50 //import org.codehaus.jettison.json.JSONTokener;
51 import org.junit.After;
52 import org.junit.Assert;
53 import org.junit.Before;
54 import org.junit.Test;
55 import org.junit.runner.RunWith;
56 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
57 import org.opendaylight.lispflowmapping.implementation.LispMappingService;
58 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
59 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
60 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
61 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
62 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
63 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
64 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
65 import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
66 import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
67 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MappingKeepAlive;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.OdlLispProtoListener;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.RequestMapping;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrReplyMapping;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrRequestMapping;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
100 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
101 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
102 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
103 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
104 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
105 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
106 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
107 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
108 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
109 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
110 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
111 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
112 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
113 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
114 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData;
115 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath;
116 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
117 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
118 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
119 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
120 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
121 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiListBuilder;
122 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.application.data.ApplicationDataBuilder;
123 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.ExplicitLocatorPathBuilder;
124 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
125 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop.LrsBits;
126 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.HopBuilder;
127 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
128 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
129 import org.ops4j.pax.exam.Option;
130 import org.ops4j.pax.exam.junit.PaxExam;
131 import org.ops4j.pax.exam.util.Filter;
132 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
133 import org.ops4j.pax.exam.options.MavenUrlReference;
134 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
135 import org.ops4j.pax.exam.spi.reactors.PerClass;
136 import org.osgi.framework.Bundle;
137 import org.osgi.framework.BundleContext;
138 import org.osgi.framework.InvalidSyntaxException;
139 import org.slf4j.Logger;
140 import org.slf4j.LoggerFactory;
142 @RunWith(PaxExam.class)
143 @ExamReactorStrategy(PerClass.class)
144 public class MappingServiceIntegrationTest extends AbstractMdsalTestBase {
145 private static final Logger LOG = LoggerFactory.getLogger(MappingServiceIntegrationTest.class);
148 * Defines how many attempt to create instance of DatagramSocket will be done before giving up.
150 private static final int NUM_OF_ATTEMPTS_TO_CREATE_SOCKET = 2;
152 private byte[] mapRequestPacket;
153 private byte[] mapRegisterPacketWithNotify;
154 private byte[] mapRegisterPacketWithoutNotify;
155 String lispBindAddress = "127.0.0.1";
156 static final String ourAddress = "127.0.0.2";
157 private Rloc locatorEid;
158 private DatagramSocket socket;
159 private byte[] mapRegisterPacketWithAuthenticationAndMapNotify;
161 public static final String ODL = "org.opendaylight.controller";
162 public static final String YANG = "org.opendaylight.yangtools";
163 private static final int MAX_NOTIFICATION_RETRYS = 20;
164 private static final MappingAuthkey NULL_AUTH_KEY = new MappingAuthkeyBuilder().setKeyType(0).build();
166 // This is temporary, since the properties in the pom file are not picked up
168 public String getKarafDistro() {
170 .groupId("org.opendaylight.lispflowmapping")
171 .artifactId("distribution-karaf")
172 .versionAsInProject()
178 public MavenUrlReference getFeatureRepo() {
180 .groupId("org.opendaylight.lispflowmapping")
181 .artifactId("features-lispflowmapping")
182 .classifier("features")
184 .versionAsInProject();
188 public String getFeatureName() {
189 return "odl-lispflowmapping-msmr";
193 public Option getLoggingOption() {
194 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
195 "log4j.logger.org.opendaylight.lispflowmapping",
196 LogLevel.DEBUG.name());
197 option = composite(option, super.getLoggingOption());
202 public void testLispFlowMappingFeatureLoad() {
203 Assert.assertTrue(true);
207 public void after() {
208 if (socket != null) {
211 // if (connection != null) {
212 // connection.disconnect();
217 public void before() throws Exception {
219 mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_FIRST);
220 mapService.setMappingOverwrite(true);
222 locatorEid = LispAddressUtil.asIpv4Rloc("4.3.2.1");
223 socket = initSocket(socket, LispMessage.PORT_NUM);
225 // SRC: 127.0.0.1:58560 to 127.0.0.1:4342
226 // LISP(Type = 8 - Encapsulated)
227 // IP: 192.168.136.10 -> 153.16.254.1
229 // LISP(Type = 1 Map-Request
233 // Source EID 1.2.3.4
234 // Nonce: 0x3d8d2acd39c8d608
235 // ITR-RLOC AFI=1 Address=192.168.136.10
236 // Record 1: 153.16.254.1/32
237 mapRequestPacket = extractWSUdpByteArray(new String("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " //
238 + "0010 00 58 00 00 40 00 40 11 3c 93 7f 00 00 01 7f 00 "
239 + "0020 00 01 e4 c0 10 f6 00 44 fe 57 80 00 00 00 45 00 "
240 + "0030 00 3c d4 31 00 00 ff 11 56 f3 7f 00 00 02 99 10 "
241 + "0040 fe 01 dd b4 10 f6 00 28 ef 3a 10 00 00 01 3d 8d "
242 + "0050 2a cd 39 c8 d6 08 00 01 01 02 03 04 00 01 7f 00 00 02 00 20 " //
243 + "0060 00 01 99 10 fe 01"));
245 // IP: 192.168.136.10 -> 128.223.156.35
246 // UDP: 49289 -> 4342
247 // LISP(Type = 3 Map-Register, P=1, M=1
251 // AuthDataLength: 20 Data:
252 // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:a5:68:89:ec
253 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
255 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
256 // Priority/Weight: 1/100, Multicast Priority/Weight:
260 mapRegisterPacketWithAuthenticationAndMapNotify = extractWSUdpByteArray(new String(
261 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
262 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
263 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
264 + "0030 00 00 00 00 00 00 00 01 00 14 0e a4 c6 d8 a4 06 "
265 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
266 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
267 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
269 // IP: 192.168.136.10 -> 128.223.156.35
270 // UDP: 49289 -> 4342
271 // LISP(Type = 3 Map-Register, P=1, M=1
274 // Key ID: 0x0000 NO AUTHENTICATION!!
275 // AuthDataLength: 00 Data:
276 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
278 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
279 // Priority/Weight: 1/100, Multicast Priority/Weight:
283 mapRegisterPacketWithNotify = extractWSUdpByteArray(new String(
284 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
285 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
286 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
287 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
288 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
289 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
290 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
292 // IP: 192.168.136.10 -> 128.223.156.35
293 // UDP: 49289 -> 4342
294 // LISP(Type = 3 Map-Register, P=1, M=1
297 // Key ID: 0x0000 NO AUTHENTICATION!!
298 // AuthDataLength: 00 Data:
299 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
301 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
302 // Priority/Weight: 1/100, Multicast Priority/Weight:
306 mapRegisterPacketWithoutNotify = extractWSUdpByteArray(new String(
307 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
308 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
309 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 00 01 00 00 "
310 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
311 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
312 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
313 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
317 private BundleContext bc;
318 //private HttpURLConnection connection;
319 protected static boolean notificationCalled;
321 @Inject @Filter(timeout=60000)
322 private IFlowMapping lms;
324 @Inject @Filter(timeout=60000)
325 private IMappingService mapService;
327 @Inject @Filter(timeout=10000)
328 private IConfigLispSouthboundPlugin configLispPlugin;
331 public void testSimpleUsage() throws Exception {
333 mapRegisterWithMapNotify();
334 mapRegisterWithMapNotifyAndMapRequest();
335 registerAndQuery__MAC();
336 mapRequestMapRegisterAndMapRequest();
337 mapRegisterWithAuthenticationWithoutConfiguringAKey();
338 mapRegisterWithoutMapNotify();
342 public void testLCAFs() throws Exception {
343 registerAndQuery__SrcDestLCAF();
344 registerAndQuery__SrcDestLCAFOverlap();
345 registerAndQuery__KeyValueLCAF();
346 //registerAndQuery__ListLCAF();
347 //registerAndQuery__ApplicationData();
348 //registerAndQuery__TrafficEngineering();
349 //registerAndQuery__SegmentLCAF();
353 public void testMask() throws Exception {
354 //testPasswordExactMatch(); TODO commented because it needs NB
355 //testPasswordMaskMatch(); TODO commented because it needs NB
356 eidPrefixLookupIPv4();
357 eidPrefixLookupIPv6();
361 public void testNorthbound() throws Exception {
363 northboundAddMapping();
364 northboundDeleteMapping();
365 northboundRetrieveKey();
366 northboundRetrieveMapping();
367 northboundRetrieveSourceDestKey();
368 northboundRetrieveSourceDestMapping();
372 public void testOverWriting() throws Exception {
373 //testMapRegisterDosntOverwritesOtherSubKeys(); TODO weird failure, needs debug
375 // TODO: remove, we don't support overwrite flag any longer and RLOCs are not saved as independent RLOC groups
376 // testMapRegisterOverwritesSameSubkey();
377 // testMapRegisterOverwritesNoSubkey();
378 // testMapRegisterDoesntOverwritesNoSubkey();
382 public void testTimeOuts() throws Exception {
383 mapRequestMapRegisterAndMapRequestTestTimeout();
384 //mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse(); TODO commented because it needs NB
388 // public void testNonProxy() throws Throwable {
389 // testSimpleNonProxy();
390 // testNonProxyOtherPort();
391 // testRecievingNonProxyOnXtrPort();
395 public void testSmr() throws Exception {
396 registerQueryRegisterWithSmr();
400 public void testMultiSite() throws Exception {
401 testMultiSiteScenarioA();
402 testMultiSiteScenarioB();
408 public void testMultiSiteScenarioA() throws IOException {
411 final MultiSiteScenario multiSiteScenario = new MultiSiteScenario(mapService, lms);
412 multiSiteScenario.setCommonAuthentication();
415 final SocketReader socketReader = SocketReader.startReadingInStandaloneThread(socket);
418 multiSiteScenario.storeSouthboundMappings(false, SITE_A, SITE_B, SITE_C, SITE_D4, SITE_D5);
419 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C);
420 multiSiteScenario.storeNorthMappingNegative(SITE_C, Action.Drop);
422 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
423 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
424 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
427 //following action should trigger generatting of SMR messages:
430 multiSiteScenario.storeNorthMappingSrcDst(SITE_A, SITE_C);
432 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1));
433 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_C, 4);
434 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
435 multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4);
438 // following action should trigger generatting of SMR messages:
443 multiSiteScenario.deleteNorthMappingNegative(SITE_C);
445 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1), SITE_A
448 multiSiteScenario.assertPingWorks(SITE_D4, 5, SITE_C, 4);
451 // following action should trigger generatting of SMR messages:
453 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C_RLOC_10);
455 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D4.getHost(5));
456 //way of testing ping - get RLOC for mapping src-dst and compare it with awaited value doesn't test
457 //that ping won't be successfull
458 multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4);
461 // following action should trigger generatting of SMR messages:
464 multiSiteScenario.storeNorthMappingNegative(SITE_C, Action.Drop);
466 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D4.getHost(5), SITE_B.getHost(5));
467 multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4);
470 multiSiteScenario.assertPingFails(SITE_D5, 5, SITE_C, 3);
473 multiSiteScenario.deleteNorthMapingSrcDst(SITE_A, SITE_C);
475 // following action should trigger generatting of SMR messages:
479 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
482 // following action should trigger generatting of SMR messages:
486 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C);
488 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
491 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
492 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
493 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
496 // following action should trigger generatting of SMR messages:
501 multiSiteScenario.deleteNorthMapingSrcDst(SITE_B, SITE_C);
503 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
506 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
507 multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4);
508 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
511 // following action should trigger generatting of SMR messages:
516 multiSiteScenario.deleteNorthMappingNegative(SITE_C);
518 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
521 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
522 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
523 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_C, 4);
525 socketReader.stopReading();
532 public void testMultiSiteScenarioB() throws IOException {
535 final MultiSiteScenario multiSiteScenario = new MultiSiteScenario(mapService, lms);
536 multiSiteScenario.setCommonAuthentication();
539 final SocketReader socketReader = SocketReader.startReadingInStandaloneThread(socket);
541 mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB);
542 mapService.setMappingOverwrite(false);
545 multiSiteScenario.storeSouthboundMappings(true, SITE_A_SB, SITE_B_SB, SITE_C_WP_100_1_SB, SITE_D_WP_100_1_SB,
547 multiSiteScenario.storeNorthMappingIpPrefix(SITE_A_SB);
548 multiSiteScenario.storeNorthMappingIpPrefix(SITE_B_SB);
549 multiSiteScenario.storeNorthMappingIpPrefix(SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
551 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
552 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
555 // following action should trigger generatting of SMR messages:
558 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
560 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
562 // following action should trigger generatting of SMR messages:
565 multiSiteScenario.storeNorthMappingNegative(SITE_C_SB, Action.Drop);
567 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
569 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
570 multiSiteScenario.assertPingFails(SITE_B_SB, 5, SITE_C_SB, 4);
574 // following action should trigger generatting of SMR messages:
577 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB);
579 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
580 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4);
583 multiSiteScenario.storeNorthMappingSrcDst(SITE_B_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
585 // following action should trigger generatting of SMR messages:
588 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
589 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
592 multiSiteScenario.deleteSouthboundMappings(SITE_D_DELETE_SB);
594 // following action should trigger generatting of SMR messages:
597 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
599 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4);
602 multiSiteScenario.deleteNorthMapingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB);
604 // following action should trigger generatting of SMR messages:
607 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
609 multiSiteScenario.deleteNorthMapingSrcDst(SITE_B_SB, SITE_C_WP_50_2_SB);
611 multiSiteScenario.assertPingFails(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4);
613 socketReader.stopReading();
617 // ------------------------------- Simple Tests ---------------------------
619 public void mapRequestSimple() throws SocketTimeoutException {
622 // This Map-Request is sent from a source port different from 4342
623 // We close and bind the socket on the correct port
624 if (socket != null) {
627 socket = initSocket(socket, 56756);
629 sendPacket(mapRequestPacket);
630 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
631 MapReply reply = MapReplySerializer.getInstance().deserialize(readBuf);
632 assertEquals(4435248268955932168L, reply.getNonce().longValue());
636 public void mapRegisterWithMapNotify() throws SocketTimeoutException {
638 mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
641 sendPacket(mapRegisterPacketWithNotify);
642 MapNotify reply = receiveMapNotify();
643 assertEquals(7, reply.getNonce().longValue());
646 public void mapRegisterWithMapNotifyAndMapRequest() throws SocketTimeoutException {
648 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
650 MapReply mapReply = registerAddressAndQuery(eid);
652 assertEquals(4, mapReply.getNonce().longValue());
653 assertEquals(locatorEid, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
658 public void registerAndQuery__MAC() throws SocketTimeoutException {
660 String macAddress = "01:02:03:04:05:06";
662 MapReply reply = registerAddressAndQuery(LispAddressUtil.asMacEid(macAddress));
665 Eid addressFromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
666 assertEquals(MacAfi.class, addressFromNetwork.getAddressType());
667 String macAddressFromReply = ((Mac) addressFromNetwork.getAddress()).getMac().getValue();
669 assertEquals(macAddress, macAddressFromReply);
672 public void mapRequestMapRegisterAndMapRequest() throws SocketTimeoutException {
674 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
675 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
678 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
679 mapRequestBuilder.setNonce((long) 4);
680 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
681 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
682 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
683 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
684 mapRequestBuilder.getItrRloc().add(
685 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
686 sendMapRequest(mapRequestBuilder.build());
687 MapReply mapReply = receiveMapReply();
688 assertEquals(4, mapReply.getNonce().longValue());
689 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
690 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
691 mapRegisterbuilder.setWantMapNotify(true);
692 mapRegisterbuilder.setNonce((long) 8);
693 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
694 etlrBuilder.setEid(eid);
695 etlrBuilder.setRecordTtl(254);
696 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
697 recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
698 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
699 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
700 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
701 mapRegisterbuilder.getMappingRecordItem().add(
702 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
703 sendMapRegister(mapRegisterbuilder.build());
704 MapNotify mapNotify = receiveMapNotify();
705 assertEquals(8, mapNotify.getNonce().longValue());
707 sendMapRequest(mapRequestBuilder.build());
708 mapReply = receiveMapReply();
709 assertEquals(4, mapReply.getNonce().longValue());
710 assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord()
711 .getLocatorRecord().get(0).getRloc());
715 public void testMapRegisterDosntOverwritesOtherSubKeys() throws SocketTimeoutException {
717 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
718 SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
719 Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
720 SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
721 Rloc rloc2 = LispAddressUtil.asKeyValueAddress("subkey2", rloc2Value);
722 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
723 assertEquals(2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
724 assertEquals(rloc2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
726 assertEquals(rloc1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1)
730 public void testMapRegisterOverwritesSameSubkey() throws SocketTimeoutException {
732 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
733 SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
734 Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
735 SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
736 Rloc rloc2 = LispAddressUtil.asKeyValueAddress("subkey2", rloc2Value);
737 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
738 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
739 assertEquals(rloc2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
743 public void testMapRegisterOverwritesNoSubkey() throws SocketTimeoutException {
745 mapService.setMappingOverwrite(true);
746 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
747 Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
748 Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
749 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
750 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
751 assertEquals(rloc2Value, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
755 public void testMapRegisterDoesntOverwritesNoSubkey() throws SocketTimeoutException {
757 mapService.setMappingOverwrite(false);
758 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
759 Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
760 Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
761 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
762 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
763 Rloc rloc1ReturnValueContainer = mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
765 Rloc rloc2ReturnValueContainer = mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
767 assertTrue((rloc1Value.equals(rloc1ReturnValueContainer) && rloc2Value.equals(rloc2ReturnValueContainer))
768 || (rloc1Value.equals(rloc2ReturnValueContainer) && rloc2Value.equals(rloc1ReturnValueContainer)));
771 private MapReply sendMapRegisterTwiceWithDiffrentValues(Eid eid, Rloc rloc1, Rloc rloc2)
772 throws SocketTimeoutException {
773 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
775 MapRegister mb = createMapRegister(eid, rloc1);
776 MapNotify mapNotify = lms.handleMapRegister(mb).getLeft();
777 MapRequest mr = createMapRequest(eid);
778 MapReply mapReply = lms.handleMapRequest(mr);
779 assertEquals(mb.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc(),
780 mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc());
781 mb = createMapRegister(eid, rloc2);
782 mapNotify = lms.handleMapRegister(mb).getLeft();
783 assertEquals(8, mapNotify.getNonce().longValue());
784 mr = createMapRequest(eid);
786 mapReply = lms.handleMapRequest(mr);
790 public void mapRegisterWithAuthenticationWithoutConfiguringAKey() throws SocketTimeoutException {
792 sendPacket(mapRegisterPacketWithAuthenticationAndMapNotify);
795 // If didn't timeout then fail:
797 } catch (SocketTimeoutException ste) {
801 public void mapRegisterWithoutMapNotify() {
803 sendPacket(mapRegisterPacketWithoutNotify);
806 // If didn't timeout then fail:
808 } catch (SocketTimeoutException ste) {
812 public void registerQueryRegisterWithSmr() throws SocketTimeoutException {
814 lms.setShouldUseSmr(true);
815 mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
818 sendPacket(mapRegisterPacketWithNotify);
822 sendPacket(mapRequestPacket);
825 mapRegisterPacketWithoutNotify[mapRegisterPacketWithoutNotify.length - 1] += 1;
826 sendPacket(mapRegisterPacketWithoutNotify);
828 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
829 MapRequest smr = MapRequestSerializer.getInstance().deserialize(readBuf, null);
830 assertTrue(smr.isSmr());
831 Eid sourceEid = smr.getSourceEid().getEid();
832 assertTrue(LispAddressUtil.asIpv4Eid("153.16.254.1").equals(sourceEid));
833 Eid smrEid = smr.getEidItem().get(0).getEid();
834 assertTrue(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32").equals(smrEid));
837 // --------------------- Northbound Tests ---------------------------
839 private void northboundAddKey() throws Exception {
841 LispIpv4Address address = LispAddressUtil.asIPAfiAddress("1.2.3.4");
843 String pass = "asdf";
845 URL url = createPutURL("key");
846 String authKeyJSON = createAuthKeyJSON(pass, address, mask);
847 callURL("PUT", "application/json", "text/plain", authKeyJSON, url);
849 String retrievedKey = lms.getAuthenticationKey(LispAddressUtil.toContainer(address), mask);
851 // Check stored password matches the one sent
852 assertEquals(pass, retrievedKey);
856 private void northboundRetrieveSourceDestKey() throws Exception {
858 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
859 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
860 .primitiveaddress.Ipv4) LispAddressUtil
861 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.1"));
862 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
863 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
864 .primitiveaddress.Ipv4) LispAddressUtil
865 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.2"));
868 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(
869 AddressFamilyNumberEnum.LCAF.getIanaCode())
870 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
871 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(address1).build())
872 .setSrcMaskLength((short) mask1)
873 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(address2).build())
874 .setDstMaskLength((short) mask2).build();
875 String pass = "asdf";
877 lms.addAuthenticationKey(LispAddressUtil.toContainer(sourceDestAddress), mask1, pass);
879 // URL url = createGetKeyIPv4URL(address1, mask1);
880 URL url = createGetKeySourceDestURL(address1.getIpv4Address().getAfi(),
881 ((LispIpv4Address) LispAddressUtil.toAFIfromPrimitive(sourceDestAddress.getSrcAddress()
882 .getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getSrcMaskLength(),
883 ((LispIpv4Address) LispAddressUtil.toAFIfromPrimitive(sourceDestAddress.getDstAddress()
884 .getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getDstMaskLength());
885 String reply = callURL("GET", null, "application/json", null, url);
886 JSONTokener jt = new JSONTokener(reply);
887 JSONObject json = new JSONObject(jt);
889 // test that the password matches what was we expected.
890 assertEquals(pass, json.get("key"));
894 private void northboundRetrieveKey() throws Exception {
896 LispIpv4Address address = LispAddressUtil.asIPAfiAddress("10.0.0.1");
898 String pass = "asdf";
900 lms.addAuthenticationKey(LispAddressUtil.toContainer(address), mask, pass);
902 URL url = createGetKeyIPv4URL(address, mask);
903 String reply = callURL("GET", null, "application/json", null, url);
904 JSONTokener jt = new JSONTokener(reply);
905 JSONObject json = new JSONObject(jt);
907 // test that the password matches what was we expected.
908 assertEquals(pass, json.get("key"));
912 private String createAuthKeyJSON(String key, LispIpv4Address address, int mask) {
913 return "{\"key\" : \"" + key + "\",\"maskLength\" : " + mask + ",\"address\" : " + "{\"ipAddress\" : \""
914 + address.getIpv4Address().getValue() + "\",\"afi\" : " + address.getAfi().shortValue() + "}}";
917 private void northboundAddMapping() throws Exception {
919 String pass = "asdf";
920 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
922 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
924 // NB add mapping always checks the key
925 lms.addAuthenticationKey(LispAddressUtil.toContainer(eid), mask, pass);
927 URL url = createPutURL("mapping");
928 String mapRegisterJSON = createMapRegisterJSON(pass, eid, mask, rloc);
929 callURL("PUT", "application/json", "text/plain", mapRegisterJSON, url);
931 // Retrieve the RLOC from the database
932 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
933 mapRequestBuilder.setPitr(false);
934 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
935 mapRequestBuilder.getEidItem().add(
936 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(
937 LispAddressUtil.toContainer(eid)).build());
938 MapReply mapReply = lms.handleMapRequest(mapRequestBuilder.build());
940 LispIpv4Address retrievedRloc = (LispIpv4Address) LispAddressUtil.toAFI(
941 mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
942 .getLispAddressContainer());
944 assertEquals(rloc.getIpv4Address().getValue(), retrievedRloc.getIpv4Address().getValue());
948 private String createMapRegisterJSON(String key, LispIpv4Address eid, int mask, LispIpv4Address rloc) {
949 String jsonString = "{ " + "\"key\" : \"" + key + "\"," + "\"mapregister\" : " + "{ "
950 + "\"proxyMapReply\" : false, "
951 + "\"eidToLocatorRecords\" : " + "[ " + "{ " + "\"authoritative\" : true," + "\"prefixGeneric\" : "
952 + "{ " + "\"ipAddress\" : \""
953 + eid.getIpv4Address().getValue() + "\"," + "\"afi\" : " + eid.getAfi().shortValue() + "},"
954 + "\"mapVersion\" : 0,"
955 + "\"maskLength\" : " + mask + ", " + "\"action\" : \"NoAction\"," + "\"locators\" : " + "[ " + "{ "
956 + "\"multicastPriority\" : 1,"
957 + "\"locatorGeneric\" : " + "{ " + "\"ipAddress\" : \"" + rloc.getIpv4Address().getValue() + "\","
959 + rloc.getAfi().shortValue() + "}, " + "\"routed\" : true," + "\"multicastWeight\" : 50,"
960 + "\"rlocProbed\" : false, "
961 + "\"localLocator\" : false, " + "\"priority\" : 1, " + "\"weight\" : 50 " + "} " + "], "
962 + "\"recordTtl\" : 100" + "} " + "], "
963 + "\"nonce\" : 3," + "\"keyId\" : 0 " + "} " + "}";
968 private void northboundRetrieveMapping() throws Exception {
970 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
972 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
973 // Insert mapping in the database
974 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
975 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
976 etlr.setLispAddressContainer(LispAddressUtil.toContainer(eid));
977 etlr.setMaskLength((short) mask);
978 etlr.setRecordTtl(254);
979 etlr.setAuthoritative(false);
980 etlr.setAction(Action.NoAction);
981 LocatorRecordBuilder record = new LocatorRecordBuilder();
982 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
983 record.setRouted(true);
984 record.setRlocProbed(false);
985 record.setLocalLocator(false);
986 record.setPriority((short) 1);
987 record.setWeight((short) 50);
988 record.setMulticastPriority((short) 1);
989 record.setMulticastWeight((short) 1);
990 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
991 etlr.getLocatorRecord().add(record.build());
992 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
993 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
994 lms.handleMapRegister(mapRegister.build());
996 // Get mapping using NB interface. No IID used
997 URL url = createGetMappingIPv4URL(0, eid, mask);
998 String reply = callURL("GET", null, "application/json", null, url);
999 JSONTokener jt = new JSONTokener(reply);
1000 JSONObject json = new JSONObject(jt);
1002 // With just one locator, locators is not a JSONArray
1003 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric")
1004 .getString("ipAddress");
1006 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
1010 private void northboundDeleteMapping() throws Exception {
1012 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
1014 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1015 // Insert mapping in the database
1016 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1017 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1018 etlr.setLispAddressContainer(LispAddressUtil.toContainer(eid));
1019 etlr.setMaskLength((short) mask);
1020 etlr.setRecordTtl(254);
1021 etlr.setAuthoritative(false);
1022 etlr.setAction(Action.NoAction);
1023 LocatorRecordBuilder record = new LocatorRecordBuilder();
1024 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
1025 record.setRouted(true);
1026 record.setRlocProbed(false);
1027 record.setLocalLocator(false);
1028 record.setPriority((short) 1);
1029 record.setWeight((short) 50);
1030 record.setMulticastPriority((short) 1);
1031 record.setMulticastWeight((short) 1);
1032 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1033 etlr.getLocatorRecord().add(record.build());
1034 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1035 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1036 lms.handleMapRegister(mapRegister.build());
1038 // Delete mapping using NB interface. No IID used
1039 URL url = createDeleteMappingIPv4URL(0, eid, mask);
1040 String reply = callURL("DELETE", null, "application/json", null, url);
1042 // Get mapping using NB interface. No IID used
1043 url = createGetMappingIPv4URL(0, eid, mask);
1044 reply = callURL("GET", null, "application/json", null, url);
1045 JSONTokener jt = new JSONTokener(reply);
1046 JSONObject json = new JSONObject(jt);
1048 // With just one locator, locators is not a JSONArray
1049 assertEquals(json.getJSONArray("locators").length(), 0);
1052 private void northboundRetrieveSourceDestMapping() throws Exception {
1054 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1055 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1056 .primitiveaddress.Ipv4) LispAddressUtil
1057 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.1"));
1058 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1059 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1060 .primitiveaddress.Ipv4) LispAddressUtil
1061 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.2"));
1064 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(
1065 AddressFamilyNumberEnum.LCAF.getIanaCode())
1066 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
1067 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(
1068 address1).build()).setSrcMaskLength((short) mask1)
1069 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(
1070 address2).build()).setDstMaskLength((short) mask2).build();
1071 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1073 // Insert mapping in the database
1074 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1075 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1076 etlr.setLispAddressContainer(LispAddressUtil.toContainer(sourceDestAddress));
1077 etlr.setMaskLength((short) mask1);
1078 etlr.setRecordTtl(254);
1079 etlr.setAuthoritative(false);
1080 etlr.setAction(Action.NoAction);
1081 LocatorRecordBuilder record = new LocatorRecordBuilder();
1082 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
1083 record.setRouted(true);
1084 record.setRlocProbed(false);
1085 record.setLocalLocator(false);
1086 record.setPriority((short) 1);
1087 record.setWeight((short) 50);
1088 record.setMulticastPriority((short) 1);
1089 record.setMulticastWeight((short) 1);
1090 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1091 etlr.getLocatorRecord().add(record.build());
1092 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1093 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1094 lms.handleMapRegister(mapRegister.build());
1096 // Get mapping using NB interface. No IID used
1097 URL url = createGetMappingSourceDestURL(address1.getIpv4Address().getAfi(),
1098 address1.getIpv4Address().getIpv4Address().getValue(),
1100 address2.getIpv4Address().getIpv4Address().getValue(),
1102 String reply = callURL("GET", null, "application/json", null, url);
1103 JSONTokener jt = new JSONTokener(reply);
1104 JSONObject json = new JSONObject(jt);
1106 // With just one locator, locators is not a JSONArray
1107 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric")
1108 .getString("ipAddress");
1110 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
1114 private URL createGetKeyIPv4URL(LispIpv4Address address, int mask) throws MalformedURLException {
1115 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d", "key",
1116 address.getAfi().shortValue(),
1117 address.getIpv4Address().getValue(), mask);
1118 URL url = new URL(restUrl);
1122 private URL createGetKeySourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask)
1123 throws MalformedURLException {
1124 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d",
1125 "key", afi, srcAddress, srcMask,
1126 dstAddress, dstMask);
1127 URL url = new URL(restUrl);
1131 private URL createGetMappingSourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask)
1132 throws MalformedURLException {
1133 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d",
1134 "mapping", afi, srcAddress,
1135 srcMask, dstAddress, dstMask);
1136 URL url = new URL(restUrl);
1140 private URL createGetMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
1141 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping",
1142 iid, address.getAfi()
1143 .shortValue(), address.getIpv4Address().getValue(), mask);
1144 URL url = new URL(restUrl);
1148 private URL createDeleteMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
1149 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping",
1150 iid, address.getAfi()
1151 .shortValue(), address.getIpv4Address().getValue(), mask);
1152 URL url = new URL(restUrl);
1156 private URL createPutURL(String resource) throws MalformedURLException {
1158 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s", resource);
1160 URL url = new URL(restUrl);
1164 private String createAuthenticationString() {
1165 String authString = "admin:admin";
1166 byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
1167 String authStringEnc = new String(authEncBytes);
1168 return authStringEnc;
1171 private String callURL(String method, String content, String accept, String body, URL url) throws IOException,
1173 String authStringEnc = createAuthenticationString();
1174 connection = (HttpURLConnection) url.openConnection();
1175 connection.setRequestMethod(method);
1176 connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
1177 if (content != null) {
1178 connection.setRequestProperty("Content-Type", content);
1180 if (accept != null) {
1181 connection.setRequestProperty("Accept", accept);
1184 // now add the request body
1185 connection.setDoOutput(true);
1186 OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
1190 connection.connect();
1192 // getting the result, first check response code
1193 Integer httpResponseCode = connection.getResponseCode();
1195 if (httpResponseCode > 299) {
1196 LOG.trace("HTTP Address: " + url);
1197 LOG.trace("HTTP Response Code: " + httpResponseCode);
1201 InputStream is = connection.getInputStream();
1202 BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
1203 StringBuilder sb = new StringBuilder();
1205 while ((cp = rd.read()) != -1) {
1206 sb.append((char) cp);
1209 connection.disconnect();
1210 return (sb.toString());
1213 // timePeriod - in ms
1214 public void assertNoPacketReceived(int timePeriod) {
1216 receivePacket(timePeriod);
1217 // If didn't timeout then fail:
1219 } catch (SocketTimeoutException ste) {
1223 // ------------------------------- Mask Tests ---------------------------
1225 public void eidPrefixLookupIPv4() throws SocketTimeoutException {
1227 runPrefixTest(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/16"),
1228 LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.2/32"),
1229 LispAddressUtil.asIpv4PrefixBinaryEid("1.1.1.1/32"));
1232 public void eidPrefixLookupIPv6() throws SocketTimeoutException {
1234 runPrefixTest(LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:6:7:8/64"),
1235 LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:1:2:3/128"),
1236 LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:1:2:3:1:2/128"));
1239 private void runPrefixTest(Eid registerEID, Eid matchedAddress, Eid unMatchedAddress)
1240 throws SocketTimeoutException {
1241 mapService.addAuthenticationKey(registerEID, NULL_AUTH_KEY);
1244 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1245 mapRegister.setWantMapNotify(true);
1246 mapRegister.setNonce((long) 8);
1247 mapRegister.setWantMapNotify(true);
1248 mapRegister.setKeyId((short) 0);
1249 mapRegister.setAuthenticationData(new byte[0]);
1250 mapRegister.setNonce((long) 8);
1251 mapRegister.setProxyMapReply(false);
1252 MappingRecordBuilder etlr = new MappingRecordBuilder();
1253 etlr.setRecordTtl(254);
1254 etlr.setAction(Action.NoAction);
1255 etlr.setAuthoritative(false);
1256 etlr.setMapVersion((short) 0);
1257 etlr.setEid(registerEID);
1258 etlr.setRecordTtl(254);
1259 LocatorRecordBuilder record = new LocatorRecordBuilder();
1260 record.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
1261 record.setLocalLocator(false);
1262 record.setRlocProbed(false);
1263 record.setRouted(true);
1264 record.setMulticastPriority((short) 0);
1265 record.setMulticastWeight((short) 0);
1266 record.setPriority((short) 0);
1267 record.setWeight((short) 0);
1268 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1269 etlr.getLocatorRecord().add(record.build());
1270 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1271 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1272 sendMapRegister(mapRegister.build());
1273 MapNotify mapNotify = receiveMapNotify();
1274 assertEquals(8, mapNotify.getNonce().longValue());
1276 MapRequestBuilder mapRequest = new MapRequestBuilder();
1277 mapRequest.setNonce((long) 4);
1278 mapRequest.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
1279 mapRequest.setEidItem(new ArrayList<EidItem>());
1280 mapRequest.setAuthoritative(false);
1281 mapRequest.setMapDataPresent(false);
1282 mapRequest.setPitr(false);
1283 mapRequest.setProbe(false);
1284 mapRequest.setSmr(false);
1285 mapRequest.setSmrInvoked(false);
1286 mapRequest.getEidItem().add(new EidItemBuilder().setEid(matchedAddress).build());
1287 mapRequest.setItrRloc(new ArrayList<ItrRloc>());
1288 mapRequest.getItrRloc().add(
1289 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1290 sendMapRequest(mapRequest.build());
1291 MapReply mapReply = receiveMapReply();
1292 assertEquals(4, mapReply.getNonce().longValue());
1293 assertEquals(record.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
1295 mapRequest.setEidItem(new ArrayList<EidItem>());
1296 mapRequest.getEidItem().add(new EidItemBuilder().setEid(unMatchedAddress).build());
1297 sendMapRequest(mapRequest.build());
1298 mapReply = receiveMapReply();
1299 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1302 // This registers an IP with a MapRegister, then adds a password via the
1303 // northbound REST API
1304 // and checks that the password works
1305 public void testPasswordExactMatch() throws Exception {
1307 String ipString = "10.0.0.1";
1308 LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
1310 String pass = "pass";
1312 URL url = createPutURL("key");
1314 String jsonAuthData = createAuthKeyJSON(pass, address, mask);
1316 LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
1317 LOG.trace("Address: " + address);
1319 byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
1320 (byte) 31, (byte) 249, (byte) 87,
1321 (byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
1322 (byte) 196, (byte) 62 };
1324 byte[] zeros = new byte[20];
1326 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1328 // build a MapRegister
1329 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1330 mapRegister.setWantMapNotify(true);
1331 mapRegister.setNonce((long) 8);
1332 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1333 etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
1334 etlr.setMaskLength((short) mask);
1335 etlr.setRecordTtl(254);
1336 LocatorRecordBuilder record = new LocatorRecordBuilder();
1337 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1338 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1339 etlr.getLocatorRecord().add(record.build());
1340 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1341 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1343 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1344 mapRegister.setAuthenticationData(zeros);
1346 sendMapRegister(mapRegister.build());
1347 assertNoPacketReceived(3000);
1349 mapRegister.setAuthenticationData(expectedSha);
1351 sendMapRegister(mapRegister.build());
1353 assertMapNotifyReceived();
1356 public void testPasswordMaskMatch() throws Exception {
1358 LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
1359 LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
1360 LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");
1363 String pass = "pass";
1365 URL url = createPutURL("key");
1366 String jsonAuthData = createAuthKeyJSON(pass, range, 8);
1368 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1369 // build a MapRegister
1370 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1372 mapRegister.setWantMapNotify(true);
1373 mapRegister.setNonce((long) 8);
1374 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1375 etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
1376 etlr.setMaskLength((short) mask);
1377 etlr.setRecordTtl(254);
1378 LocatorRecordBuilder record = new LocatorRecordBuilder();
1379 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1380 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1381 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1382 etlr.getLocatorRecord().add(record.build());
1383 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1384 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1386 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1388 .setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
1389 -67, -113, 104, -110, -71 });
1391 sendMapRegister(mapRegister.build());
1393 assertMapNotifyReceived();
1395 etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
1397 .setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
1398 -71, -14, -99, 67, -23, -73 });
1400 sendMapRegister(mapRegister.build());
1401 assertNoPacketReceived(3000);
1404 // takes an address, packs it in a MapRegister and sends it
1405 private void registerAddress(Eid eid) throws SocketTimeoutException {
1406 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1408 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1409 mapRegisterBuilder.setWantMapNotify(true);
1410 mapRegisterBuilder.setKeyId((short) 0);
1411 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1412 mapRegisterBuilder.setNonce((long) 8);
1413 mapRegisterBuilder.setProxyMapReply(false);
1414 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1415 etlrBuilder.setEid(eid);
1416 etlrBuilder.setRecordTtl(254);
1417 etlrBuilder.setAction(Action.NoAction);
1418 etlrBuilder.setAuthoritative(false);
1419 etlrBuilder.setMapVersion((short) 0);
1420 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1421 recordBuilder.setLocalLocator(false);
1422 recordBuilder.setRlocProbed(false);
1423 recordBuilder.setRouted(true);
1424 recordBuilder.setMulticastPriority((short) 0);
1425 recordBuilder.setMulticastWeight((short) 0);
1426 recordBuilder.setPriority((short) 0);
1427 recordBuilder.setWeight((short) 0);
1428 recordBuilder.setRloc(locatorEid);
1429 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1430 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1431 mapRegisterBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1432 mapRegisterBuilder.getMappingRecordItem().add(
1433 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
1434 sendMapRegister(mapRegisterBuilder.build());
1435 MapNotify mapNotify = receiveMapNotify();
1436 assertEquals(8, mapNotify.getNonce().longValue());
1439 private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
1440 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1441 mapRequestBuilder.setNonce((long) 4);
1442 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1443 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1444 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1445 if (srcEid != null) {
1446 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
1448 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress))
1451 mapRequestBuilder.getItrRloc().add(
1452 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1453 mapRequestBuilder.setAuthoritative(false);
1454 mapRequestBuilder.setMapDataPresent(false);
1455 mapRequestBuilder.setPitr(false);
1456 mapRequestBuilder.setProbe(false);
1457 mapRequestBuilder.setSmr(false);
1458 mapRequestBuilder.setSmrInvoked(false);
1459 sendMapRequest(mapRequestBuilder.build());
1460 return receiveMapReply();
1463 // takes an address, packs it in a MapRegister, sends it, returns the
1465 private MapReply registerAddressAndQuery(Eid eid) throws SocketTimeoutException {
1466 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1468 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1469 mapRegisterBuilder.setWantMapNotify(true);
1470 mapRegisterBuilder.setKeyId((short) 0);
1471 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1472 mapRegisterBuilder.setNonce((long) 8);
1473 mapRegisterBuilder.setProxyMapReply(false);
1474 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1475 etlrBuilder.setEid(eid);
1476 etlrBuilder.setRecordTtl(254);
1477 etlrBuilder.setAction(Action.NoAction);
1478 etlrBuilder.setAuthoritative(false);
1479 etlrBuilder.setMapVersion((short) 0);
1480 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1481 recordBuilder.setLocalLocator(false);
1482 recordBuilder.setRlocProbed(false);
1483 recordBuilder.setRouted(true);
1484 recordBuilder.setMulticastPriority((short) 0);
1485 recordBuilder.setMulticastWeight((short) 0);
1486 recordBuilder.setPriority((short) 0);
1487 recordBuilder.setWeight((short) 0);
1488 recordBuilder.setRloc(locatorEid);
1489 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1490 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1491 mapRegisterBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1492 mapRegisterBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
1493 etlrBuilder.build()).build());
1494 sendMapRegister(mapRegisterBuilder.build());
1495 MapNotify mapNotify = receiveMapNotify();
1496 assertEquals(8, mapNotify.getNonce().longValue());
1497 // wait for the notifications to propagate
1499 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1500 mapRequestBuilder.setNonce((long) 4);
1501 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1502 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1503 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1504 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
1505 mapRequestBuilder.getItrRloc().add(
1506 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1507 mapRequestBuilder.setAuthoritative(false);
1508 mapRequestBuilder.setMapDataPresent(false);
1509 mapRequestBuilder.setPitr(false);
1510 mapRequestBuilder.setProbe(false);
1511 mapRequestBuilder.setSmr(false);
1512 mapRequestBuilder.setSmrInvoked(false);
1513 sendMapRequest(mapRequestBuilder.build());
1514 return receiveMapReply();
1517 // ------------------------------- LCAF Tests ---------------------------
1519 public void registerAndQuery__SrcDestLCAF() throws SocketTimeoutException {
1521 String ipPrefix = "10.20.30.200/32";
1522 String macString = "01:02:03:04:05:06";
1524 SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
1525 builder.setSource(new SimpleAddress(new IpPrefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1526 .ietf.inet.types.rev130715.Ipv4Prefix(ipPrefix))));
1527 builder.setDest(new SimpleAddress(new MacAddress(macString)));
1529 EidBuilder eb = new EidBuilder();
1530 eb.setAddressType(SourceDestKeyLcaf.class);
1531 eb.setVirtualNetworkId(null);
1532 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1533 .lisp.address.address.SourceDestKeyBuilder().setSourceDestKey(builder.build()).build());
1535 MapReply reply = registerAddressAndQuery(eb.build());
1537 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1538 assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
1539 SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
1541 SimpleAddress receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
1542 SimpleAddress receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
1544 assertNotNull(receivedAddr1.getIpPrefix().getIpv4Prefix());
1545 assertNotNull(receivedAddr2.getMacAddress());
1547 IpPrefix receivedIP = receivedAddr1.getIpPrefix();
1548 MacAddress receivedMAC = receivedAddr2.getMacAddress();
1550 assertEquals(ipPrefix, receivedIP.getIpv4Prefix().getValue());
1551 assertEquals(macString, receivedMAC.getValue());
1554 public void registerAndQuery__SrcDestLCAFOverlap() throws SocketTimeoutException {
1556 String ipString1 = "10.10.10.0";
1557 String ipString2 = "20.20.20.0";
1558 String ipPrefix1 = ipString1 + "/24";
1559 String ipPrefix2 = ipString2 + "/24";
1561 Eid srcDst = LispAddressUtil.asSrcDstEid(ipString1, ipString2, 24, 24, 0);
1562 registerAddress(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2));
1563 registerAddress(srcDst);
1566 MapReply reply = queryForAddress(srcDst, null);
1568 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1569 assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
1570 SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
1572 IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource().getIpPrefix();
1573 IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest().getIpPrefix();
1575 assertNotNull(receivedAddr1.getIpv4Prefix());
1576 assertNotNull(receivedAddr2.getIpv4Prefix());
1578 assertEquals(ipPrefix1, receivedAddr1.getIpv4Prefix().getValue());
1579 assertEquals(ipPrefix2, receivedAddr2.getIpv4Prefix().getValue());
1581 // srcEid/dstEid match
1582 reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "10.10.10.1");
1583 fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1584 assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
1586 assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
1588 // dstEid match only
1589 reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "1.2.3.4");
1590 fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1591 assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
1593 assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
1596 public void registerAndQuery__KeyValueLCAF() throws SocketTimeoutException {
1598 String ipString = "10.20.30.200";
1599 String macString = "01:02:03:04:05:06";
1600 SimpleAddress addrToSend1 = new SimpleAddress(new IpAddress(new Ipv4Address(ipString)));
1601 SimpleAddress addrToSend2 = new SimpleAddress(new MacAddress(macString));
1602 Eid kv = LispAddressUtil.asKeyValueAddressEid(addrToSend1, addrToSend2);
1604 MapReply reply = registerAddressAndQuery(kv);
1606 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1607 assertEquals(KeyValueAddressLcaf.class, fromNetwork.getAddressType());
1608 KeyValueAddress keyValueFromNetwork = (KeyValueAddress) fromNetwork.getAddress();
1610 SimpleAddress receivedAddr1 = keyValueFromNetwork.getKeyValueAddress().getKey();
1611 SimpleAddress receivedAddr2 = keyValueFromNetwork.getKeyValueAddress().getValue();
1613 assertNotNull(receivedAddr1.getIpAddress().getIpv4Address());
1614 assertNotNull(receivedAddr2.getMacAddress());
1616 Ipv4Address receivedIP = receivedAddr1.getIpAddress().getIpv4Address();
1617 MacAddress receivedMAC = receivedAddr2.getMacAddress();
1619 assertEquals(ipString, receivedIP.getValue());
1620 assertEquals(macString, receivedMAC.getValue());
1623 public void registerAndQuery__ListLCAF() throws SocketTimeoutException {
1625 String macString = "01:02:03:04:05:06";
1626 String ipString = "10.20.255.30";
1627 List<SimpleAddress> addresses = new ArrayList<SimpleAddress>();
1628 addresses.add(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
1629 addresses.add(new SimpleAddress(new MacAddress(macString)));
1630 AfiListBuilder listbuilder = new AfiListBuilder();
1631 listbuilder.setAddressList(addresses);
1633 EidBuilder eb = new EidBuilder();
1634 eb.setAddressType(AfiListLcaf.class);
1635 eb.setVirtualNetworkId(null);
1636 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1637 .lisp.address.address.AfiListBuilder().setAfiList(listbuilder.build()).build());
1639 MapReply reply = registerAddressAndQuery(eb.build());
1641 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1643 assertEquals(AfiListLcaf.class, receivedAddress.getAddressType());
1645 AfiList listAddrFromNetwork = (AfiList) receivedAddress.getAddress();
1646 SimpleAddress receivedAddr1 = (SimpleAddress) listAddrFromNetwork.getAfiList().getAddressList().get(0);
1647 SimpleAddress receivedAddr2 = (SimpleAddress) listAddrFromNetwork.getAfiList().getAddressList().get(1);
1649 assertNotNull(receivedAddr1.getIpAddress().getIpv4Address());
1650 assertNotNull(receivedAddr2.getMacAddress());
1652 assertEquals(macString, receivedAddr2.getMacAddress().getValue());
1653 assertEquals(ipString, receivedAddr1.getIpAddress().getIpv4Address().getValue());
1656 public void registerAndQuery__SegmentLCAF() throws SocketTimeoutException {
1658 String ipString = "10.20.255.30";
1661 EidBuilder eb = new EidBuilder();
1662 eb.setAddressType(Ipv4PrefixAfi.class);
1663 eb.setVirtualNetworkId(new InstanceIdType((long) instanceId));
1664 eb.setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns
1665 .yang.ietf.inet.types.rev130715.Ipv4Prefix(ipString)).build());
1667 MapReply reply = registerAddressAndQuery(eb.build());
1669 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1670 assertEquals(Ipv4PrefixAfi.class, receivedAddress.getAddressType());
1672 assertEquals(ipString, ((Ipv4Prefix) receivedAddress.getAddress()).getIpv4Prefix().getValue());
1674 assertEquals(instanceId, receivedAddress.getVirtualNetworkId().getValue().intValue());
1677 public void registerAndQuery__TrafficEngineering() throws SocketTimeoutException {
1679 String macString = "01:02:03:04:05:06";
1680 String ipString = "10.20.255.30";
1681 HopBuilder hopBuilder = new HopBuilder();
1682 hopBuilder.setAddress(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
1683 hopBuilder.setLrsBits(new LrsBits(true, false, true));
1684 Hop hop1 = hopBuilder.build();
1685 hopBuilder.setAddress(new SimpleAddress(new MacAddress(macString)));
1686 hopBuilder.setLrsBits(new LrsBits(false, true, false));
1687 Hop hop2 = hopBuilder.build();
1688 ExplicitLocatorPathBuilder elpBuilder = new ExplicitLocatorPathBuilder();
1689 elpBuilder.setHop(new ArrayList<Hop>());
1690 elpBuilder.getHop().add(hop1);
1691 elpBuilder.getHop().add(hop2);
1693 EidBuilder eb = new EidBuilder();
1694 eb.setAddressType(ExplicitLocatorPathLcaf.class);
1695 eb.setVirtualNetworkId(null);
1696 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1697 .lisp.address.address.ExplicitLocatorPathBuilder().setExplicitLocatorPath(elpBuilder.build()).build());
1699 MapReply reply = registerAddressAndQuery(eb.build());
1701 assertEquals(ExplicitLocatorPathLcaf.class, reply.getMappingRecordItem().get(0).getMappingRecord().getEid()
1704 ExplicitLocatorPath receivedAddress = (ExplicitLocatorPath) reply.getMappingRecordItem().get(0)
1705 .getMappingRecord().getEid().getAddress();
1707 Hop receivedHop1 = (Hop) receivedAddress.getExplicitLocatorPath().getHop().get(0);
1708 Hop receivedHop2 = (Hop) receivedAddress.getExplicitLocatorPath().getHop().get(1);
1710 assertEquals(true, receivedHop1.getLrsBits().isLookup());
1711 assertEquals(false, receivedHop1.getLrsBits().isRlocProbe());
1712 assertEquals(true, receivedHop1.getLrsBits().isStrict());
1714 assertEquals(false, receivedHop2.getLrsBits().isLookup());
1715 assertEquals(true, receivedHop2.getLrsBits().isRlocProbe());
1716 assertEquals(false, receivedHop2.getLrsBits().isStrict());
1718 assertNotNull(receivedHop1.getAddress().getIpAddress().getIpv4Address());
1719 assertNotNull(receivedHop2.getAddress().getMacAddress());
1721 assertEquals(ipString, receivedHop1.getAddress().getIpAddress().getIpv4Address().getValue());
1722 assertEquals(macString, receivedHop2.getAddress().getMacAddress().getValue());
1725 public void registerAndQuery__ApplicationData() throws SocketTimeoutException {
1727 String ipString = "1.2.3.4";
1730 int localPortLow = 3;
1731 int localPortHigh = 4;
1732 int remotePortLow = 4;
1733 int remotePortHigh = 5;
1735 ApplicationDataBuilder builder = new ApplicationDataBuilder();
1736 builder.setIpTos(ipTOs);
1737 builder.setProtocol(protocol);
1738 builder.setLocalPortLow(new PortNumber(localPortLow));
1739 builder.setLocalPortHigh(new PortNumber(localPortHigh));
1740 builder.setRemotePortLow(new PortNumber(remotePortLow));
1741 builder.setRemotePortHigh(new PortNumber(remotePortHigh));
1742 builder.setAddress(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
1744 EidBuilder eb = new EidBuilder();
1745 eb.setAddressType(ApplicationDataLcaf.class);
1746 eb.setVirtualNetworkId(null);
1747 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1748 .lisp.address.address.ApplicationDataBuilder().setApplicationData(builder.build()).build());
1749 Eid addressToSend = eb.build();
1751 MapReply reply = registerAddressAndQuery(addressToSend);
1753 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1755 assertEquals(ApplicationDataLcaf.class, receivedAddress.getAddressType());
1757 ApplicationData receivedApplicationDataAddress = (ApplicationData) receivedAddress.getAddress();
1758 assertEquals(protocol, receivedApplicationDataAddress.getApplicationData().getProtocol().intValue());
1759 assertEquals(ipTOs, receivedApplicationDataAddress.getApplicationData().getIpTos().intValue());
1760 assertEquals(localPortLow, receivedApplicationDataAddress.getApplicationData().getLocalPortLow().getValue()
1762 assertEquals(localPortHigh, receivedApplicationDataAddress.getApplicationData().getLocalPortHigh().getValue()
1764 assertEquals(remotePortLow, receivedApplicationDataAddress.getApplicationData().getRemotePortLow().getValue()
1766 assertEquals(remotePortHigh, receivedApplicationDataAddress.getApplicationData().getRemotePortHigh().getValue()
1769 SimpleAddress ipAddressReceived = receivedApplicationDataAddress.getApplicationData().getAddress();
1770 assertEquals(ipString, ipAddressReceived.getIpAddress().getIpv4Address().getValue());
1773 // ------------------- TimeOut Tests -----------
1775 public void mapRequestMapRegisterAndMapRequestTestTimeout() throws SocketTimeoutException {
1777 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1778 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1780 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1781 mapRequestBuilder.setNonce((long) 4);
1782 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
1783 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1784 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1785 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1786 mapRequestBuilder.getItrRloc().add(
1787 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1789 sendMapRequest(mapRequestBuilder.build());
1790 MapReply mapReply = receiveMapReply();
1791 assertEquals(4, mapReply.getNonce().longValue());
1792 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1794 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
1795 mapRegisterbuilder.setWantMapNotify(true);
1796 mapRegisterbuilder.setNonce((long) 8);
1798 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1799 etlrBuilder.setEid(eid);
1800 etlrBuilder.setRecordTtl(254);
1802 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1803 recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
1804 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1805 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1806 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1807 mapRegisterbuilder.getMappingRecordItem().add(
1808 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
1810 sendMapRegister(mapRegisterbuilder.build());
1811 MapNotify mapNotify = receiveMapNotify();
1812 assertEquals(8, mapNotify.getNonce().longValue());
1815 sendMapRequest(mapRequestBuilder.build());
1816 mapReply = receiveMapReply();
1817 assertEquals(4, mapReply.getNonce().longValue());
1818 assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord()
1819 .getLocatorRecord().get(0).getRloc());
1821 causeEntryToBeCleaned();
1822 sendMapRequest(mapRequestBuilder.build());
1823 mapReply = receiveMapReply();
1824 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1827 public void mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse() throws Exception {
1829 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1830 MapRequest mapRequest = createMapRequest(eid);
1832 testTTLBeforeRegister(mapRequest);
1834 registerForTTL(eid);
1836 testTTLAfterRegister(mapRequest);
1838 causeEntryToBeCleaned();
1839 testTTLAfterClean(mapRequest);
1841 //northboundAddKey();
1842 //testTTLAfterAutherize(mapRequest);
1846 private void testTTLAfterClean(MapRequest mapRequest) throws SocketTimeoutException {
1848 sendMapRequest(mapRequest);
1849 mapReply = receiveMapReply();
1850 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
1853 private void causeEntryToBeCleaned() {
1854 // TODO XXX for the time being, to keep master and stable/lithium in sync, we need to remove the forceful
1855 // expiration of DAO entries. Once we're past this, we'll have to expose methods to setTimeUnit(TimeUnit)
1856 // and cleanOld() (expired) entries in IFlowMapping (and perhaps ILispDAO) and use them here.
1857 mapService.cleanCachedMappings();
1860 private void testTTLAfterRegister(MapRequest mapRequest) throws SocketTimeoutException {
1862 sendMapRequest(mapRequest);
1863 mapReply = receiveMapReply();
1864 assertEquals(LispAddressUtil.asIpv4Rloc("4.3.2.1"), mapReply.getMappingRecordItem().get(0).getMappingRecord()
1865 .getLocatorRecord().get(0).getRloc());
1866 assertCorrectMapReplyTTLAndAction(mapReply, 254, Action.NoAction);
1869 private void registerForTTL(Eid eid) throws SocketTimeoutException {
1870 MapRegister mapRegister = createMapRegister(eid);
1871 sendMapRegister(mapRegister);
1872 assertMapNotifyReceived();
1875 private void testTTLBeforeRegister(MapRequest mapRequest) throws SocketTimeoutException {
1877 sendMapRequest(mapRequest);
1878 mapReply = receiveMapReply();
1879 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
1882 private void testTTLAfterAutherize(MapRequest mapRequest) throws SocketTimeoutException {
1884 sendMapRequest(mapRequest);
1885 mapReply = receiveMapReply();
1886 assertCorrectMapReplyTTLAndAction(mapReply, 1, Action.NativelyForward);
1889 private void assertCorrectMapReplyTTLAndAction(MapReply mapReply, int expectedTTL, Action expectedAction) {
1890 assertEquals(expectedTTL, mapReply.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().intValue());
1891 assertEquals(expectedAction, mapReply.getMappingRecordItem().get(0).getMappingRecord().getAction());
1894 private MapRegister createMapRegister(Eid eid, Rloc rloc) {
1895 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
1896 mapRegisterbuilder.setWantMapNotify(true);
1897 mapRegisterbuilder.setNonce((long) 8);
1898 mapRegisterbuilder.setKeyId((short) 0);
1899 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1900 etlrBuilder.setEid(eid);
1901 etlrBuilder.setRecordTtl(254);
1902 etlrBuilder.setAuthoritative(false);
1903 etlrBuilder.setAction(Action.NoAction);
1904 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1905 recordBuilder.setRloc(rloc);
1906 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1907 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1908 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1909 mapRegisterbuilder.getMappingRecordItem().add(
1910 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
1911 MapRegister mapRegister = mapRegisterbuilder.build();
1915 private MapRegister createMapRegister(Eid eid) {
1916 return createMapRegister(eid, LispAddressUtil.asIpv4Rloc("4.3.2.1"));
1919 private MapRequest createMapRequest(Eid eid) {
1920 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1921 mapRequestBuilder.setNonce((long) 4);
1922 mapRequestBuilder.setPitr(false);
1923 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
1924 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1925 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1926 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1927 mapRequestBuilder.getItrRloc().add(
1928 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1929 MapRequest mr = mapRequestBuilder.build();
1933 public void testSimpleNonProxy() throws SocketTimeoutException, SocketException {
1935 String rloc = "127.0.0.3";
1936 int port = LispMessage.PORT_NUM;
1937 Rloc ipRloc = LispAddressUtil.asIpv4Rloc(rloc);
1938 sendProxyMapRequest(rloc, port, ipRloc);
1942 public void testNonProxyOtherPort() throws SocketTimeoutException, SocketException {
1944 String rloc = "127.0.0.3";
1947 RlocBuilder rb = new RlocBuilder();
1948 rb.setAddressType(ApplicationDataLcaf.class);
1949 rb.setVirtualNetworkId(null);
1950 rb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1951 .lisp.address.address.ApplicationDataBuilder()
1952 .setApplicationData(new ApplicationDataBuilder().setAddress(new SimpleAddress(new IpAddress(
1953 new Ipv4Address(rloc)))).setLocalPortLow(new PortNumber(port)).build()).build());
1954 Rloc adLcaf = rb.build();
1956 LOG.info("testNonProxyOtherPort:" + LispAddressStringifier.getString(adLcaf));
1957 sendProxyMapRequest(rloc, port, adLcaf);
1961 private class XtrRequestMappingListener implements OdlLispProtoListener {
1964 public void onGotMapReply(GotMapReply notification) {
1968 public void onAddMapping(AddMapping notification) {
1972 public void onXtrReplyMapping(XtrReplyMapping notification) {
1976 public void onRequestMapping(RequestMapping notification) {
1980 public void onGotMapNotify(GotMapNotify notification) {
1984 public void onXtrRequestMapping(XtrRequestMapping notification) {
1988 public void onMappingKeepAlive(MappingKeepAlive notification) {
1993 public void testRecievingNonProxyOnXtrPort() throws SocketTimeoutException, SocketException, Throwable {
1995 configLispPlugin.shouldListenOnXtrPort(true);
1996 notificationCalled = false;
1997 final String eid = "10.10.10.10/32";
1998 String rloc = "127.0.0.3";
1999 int port = LispMessage.XTR_PORT_NUM;
2001 RlocBuilder rb = new RlocBuilder();
2002 rb.setAddressType(ApplicationDataLcaf.class);
2003 rb.setVirtualNetworkId(null);
2004 rb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
2005 .lisp.address.address.ApplicationDataBuilder()
2006 .setApplicationData(new ApplicationDataBuilder().setAddress(new SimpleAddress(new IpAddress(
2007 new Ipv4Address(rloc)))).setLocalPortLow(new PortNumber(port)).build()).build());
2008 Rloc adLcaf = rb.build();
2010 final MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
2011 ((LispMappingService) lms).getNotificationService().registerNotificationListener(
2012 new XtrRequestMappingListener() {
2015 public void onXtrRequestMapping(XtrRequestMapping notification) {
2016 assertEquals(((Ipv4Prefix) mapRequest.getEidItem().get(0).getEid().getAddress())
2017 .getIpv4Prefix().getValue(), eid);
2018 notificationCalled = true;
2019 LOG.warn("notification arrived");
2022 sendMapRequest(mapRequest, port);
2023 for (int i = 0; i < MAX_NOTIFICATION_RETRYS; i++) {
2024 if (notificationCalled) {
2027 LOG.warn("notification hasn't arrived, sleeping...");
2032 fail("Notification hasn't arrived");
2036 private void sendProxyMapRequest(String rloc, int port, Rloc adLcaf) throws SocketTimeoutException,
2038 String eid = "10.1.0.1/32";
2039 MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
2040 sendMapRequest(mapRequest);
2041 DatagramSocket nonProxySocket = new DatagramSocket(new InetSocketAddress(rloc, port));
2042 MapRequest receivedMapRequest = receiveMapRequest(nonProxySocket);
2043 assertEquals(mapRequest.getNonce(), receivedMapRequest.getNonce());
2044 assertEquals(mapRequest.getSourceEid(), receivedMapRequest.getSourceEid());
2045 assertEquals(mapRequest.getItrRloc(), receivedMapRequest.getItrRloc());
2046 assertEquals(mapRequest.getEidItem(), receivedMapRequest.getEidItem());
2047 nonProxySocket.close();
2050 private MapRequest createNonProxyMapRequest(String eid, Rloc adLcaf) throws SocketTimeoutException {
2051 MapRegister mr = createMapRegister(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
2052 LocatorRecord record = new LocatorRecordBuilder(mr.getMappingRecordItem().get(0).getMappingRecord()
2053 .getLocatorRecord().get(0)).setRloc(adLcaf).build();
2054 mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().set(0, record);
2055 sendMapRegister(mr);
2056 assertMapNotifyReceived();
2057 MapRequest mapRequest = createMapRequest(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
2058 MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
2059 builder.setPitr(true);
2060 mapRequest = builder.build();
2064 private void assertMapNotifyReceived() throws SocketTimeoutException {
2068 private MapReply receiveMapReply() throws SocketTimeoutException {
2069 return MapReplySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
2072 private MapRequest receiveMapRequest(DatagramSocket datagramSocket) throws SocketTimeoutException {
2073 return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket(
2074 datagramSocket, 30000).getData()), null);
2077 private MapNotify receiveMapNotify() throws SocketTimeoutException {
2078 return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
2081 private void sendMapRequest(MapRequest mapRequest) {
2082 sendMapRequest(mapRequest, LispMessage.PORT_NUM);
2085 private void sendMapRequest(MapRequest mapRequest, int port) {
2086 sendPacket(MapRequestSerializer.getInstance().serialize(mapRequest).array(), port);
2089 private void sendMapRegister(MapRegister mapRegister) {
2090 sendPacket(MapRegisterSerializer.getInstance().serialize(mapRegister).array());
2093 private void sendPacket(byte[] bytesToSend) {
2094 sendPacket(bytesToSend, LispMessage.PORT_NUM);
2097 private void sendPacket(byte[] bytesToSend, int port) {
2099 DatagramPacket packet = new DatagramPacket(bytesToSend, bytesToSend.length);
2100 initPacketAddress(packet, port);
2101 LOG.trace("Sending packet to LispPlugin on socket, port {}", port);
2102 socket.send(packet);
2103 } catch (Throwable t) {
2108 private DatagramPacket receivePacket() throws SocketTimeoutException {
2109 return receivePacket(6000);
2112 private DatagramPacket receivePacket(int timeout) throws SocketTimeoutException {
2113 return receivePacket(socket, timeout);
2116 private DatagramPacket receivePacket(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException {
2118 byte[] buffer = new byte[4096];
2119 DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
2120 LOG.trace("Waiting for packet from socket...");
2121 receivedSocket.setSoTimeout(timeout);
2122 receivedSocket.receive(receivePacket);
2123 LOG.trace("Received packet from socket!");
2124 return receivePacket;
2125 } catch (SocketTimeoutException ste) {
2127 } catch (Throwable t) {
2133 private void sleepForSeconds(int seconds) {
2135 Thread.sleep(seconds*1000);
2136 } catch (InterruptedException e) {
2137 LOG.warn("Interrupted while sleeping", e);
2141 private void initPacketAddress(DatagramPacket packet, int port) throws UnknownHostException {
2142 packet.setAddress(InetAddress.getByName(lispBindAddress));
2143 packet.setPort(port);
2146 private DatagramSocket initSocket(DatagramSocket socket, int port) {
2147 for (int i=0; i < NUM_OF_ATTEMPTS_TO_CREATE_SOCKET; i++) {
2149 return new DatagramSocket(new InetSocketAddress(ourAddress, port));
2150 } catch (SocketException e) {
2151 LOG.error("Can't initialize socket for {}", ourAddress, e);
2158 private byte[] extractWSUdpByteArray(String wiresharkHex) {
2159 final int HEADER_LEN = 42;
2160 byte[] res = new byte[1000];
2161 String[] split = wiresharkHex.split(" ");
2163 for (String cur : split) {
2165 if (cur.length() == 2) {
2167 if (counter > HEADER_LEN) {
2168 res[counter - HEADER_LEN - 1] = (byte) Integer.parseInt(cur, 16);
2173 return Arrays.copyOf(res, counter - HEADER_LEN);
2176 private String stateToString(int state) {
2180 case Bundle.INSTALLED:
2182 case Bundle.RESOLVED:
2184 case Bundle.UNINSTALLED:
2185 return "UNINSTALLED";
2187 return "Not CONVERTED";
2191 private void areWeReady() throws InvalidSyntaxException {
2195 boolean debugit = false;
2196 Bundle b[] = bc.getBundles();
2197 for (Bundle element : b) {
2198 int state = element.getState();
2199 LOG.trace("Bundle[" + element.getBundleId() + "]:" + element.getSymbolicName() + ",v"
2200 + element.getVersion() + ", state:" + stateToString(state));
2201 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
2202 LOG.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
2205 // String host = element.getHeaders().get("FRAGMENT-HOST");
2206 // if (host != null) {
2207 // LOG.warn("Bundle " + element.getSymbolicName() +
2208 // " is a fragment which is part of: " + host);
2209 // LOG.warn("Required imports are: " +
2210 // element.getHeaders().get("IMPORT-PACKAGE"));
2214 // } catch (BundleException e) {
2215 // LOG.error("BundleException:", e);
2224 LOG.warn(("Do some debugging because some bundle is unresolved"));
2226 // assertNotNull(broker);
2228 configLispPlugin.setLispAddress(lispBindAddress);
2230 // Uncomment this code to Know which services were actually loaded to
2234 for (ServiceReference sr : bc.getAllServiceReferences(null, null)) {
2235 LOG.info(sr.getBundle().getSymbolicName());
2236 LOG.info(sr.toString());
2243 private void cleanUP() {
2245 mapService.cleanCachedMappings();
2246 configLispPlugin.shouldListenOnXtrPort(false);
2247 socket = initSocket(socket, LispMessage.PORT_NUM);
2251 private void restartSocket() {
2253 socket = initSocket(socket, LispMessage.PORT_NUM);