2 * Copyright (c) 2014, 2017 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.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_A;
16 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_A_SB;
17 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_B;
18 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_B_SB;
19 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C;
20 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_RLOC_10;
21 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_SB;
22 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_WP_100_1_SB;
23 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_C_WP_50_2_SB;
24 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D4;
25 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D5;
26 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_DELETE_SB;
27 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_WP_100_1_SB;
28 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_D_WP_50_2_SB;
29 import static org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.SITE_E_SB;
30 import static org.ops4j.pax.exam.CoreOptions.composite;
31 import static org.ops4j.pax.exam.CoreOptions.maven;
32 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
34 import com.google.common.collect.Lists;
35 import com.google.common.collect.Sets;
36 import java.io.IOException;
37 import java.net.DatagramPacket;
38 import java.net.DatagramSocket;
39 import java.net.InetAddress;
40 import java.net.InetSocketAddress;
41 import java.net.SocketException;
42 import java.net.SocketTimeoutException;
43 import java.net.UnknownHostException;
44 import java.nio.ByteBuffer;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.List;
49 import javax.inject.Inject;
50 import org.junit.After;
51 import org.junit.Assert;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
55 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
56 import org.opendaylight.lispflowmapping.config.ConfigIni;
57 import org.opendaylight.lispflowmapping.implementation.LispMappingService;
58 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
59 import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber;
60 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
61 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
62 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
63 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
64 import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
65 import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
66 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
67 import org.opendaylight.lispflowmapping.lisp.type.MappingData;
68 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
69 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
70 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
71 import org.opendaylight.lispflowmapping.lisp.util.MappingRecordUtil;
72 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
73 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
74 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
75 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
76 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
77 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
78 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
79 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
81 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
82 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
86 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
87 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
88 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData;
89 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath;
90 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
91 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
92 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
93 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
94 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
95 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiListBuilder;
96 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.application.data.ApplicationDataBuilder;
97 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.ExplicitLocatorPathBuilder;
98 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;
99 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;
100 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;
101 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
102 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MappingKeepAlive;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.OdlLispProtoListener;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.RequestMapping;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrReplyMapping;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrRequestMapping;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
142 import org.ops4j.pax.exam.Option;
143 import org.ops4j.pax.exam.junit.PaxExam;
144 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
145 import org.ops4j.pax.exam.options.MavenUrlReference;
146 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
147 import org.ops4j.pax.exam.spi.reactors.PerClass;
148 import org.ops4j.pax.exam.util.Filter;
149 import org.osgi.framework.Bundle;
150 import org.osgi.framework.BundleContext;
151 import org.osgi.framework.InvalidSyntaxException;
152 import org.slf4j.Logger;
153 import org.slf4j.LoggerFactory;
155 @RunWith(PaxExam.class)
156 @ExamReactorStrategy(PerClass.class)
157 public class MappingServiceIntegrationTest extends AbstractMdsalTestBase {
158 private static final Logger LOG = LoggerFactory.getLogger(MappingServiceIntegrationTest.class);
161 * Defines how many attempt to create instance of DatagramSocket will be done before giving up.
163 private static final int NUM_OF_ATTEMPTS_TO_CREATE_SOCKET = 2;
165 private byte[] mapRequestPacket;
166 private byte[] mapRegisterPacketWithNotify;
167 private byte[] mapRegisterPacketWithoutNotify;
168 String lispBindAddress = "127.0.0.1";
169 static final String ourAddress = "127.0.0.2";
170 private Rloc locatorEid;
171 private DatagramSocket socket;
172 private byte[] mapRegisterPacketWithAuthenticationAndMapNotify;
174 public static final String ODL = "org.opendaylight.controller";
175 public static final String YANG = "org.opendaylight.yangtools";
176 private static final int MULTI_SITE_SLEEP_TIME = 2;
177 private static final int MAX_NOTIFICATION_RETRYS = 20;
178 private static final MappingAuthkey NULL_AUTH_KEY = new MappingAuthkeyBuilder().setKeyType(0).build();
180 // This is temporary, since the properties in the pom file are not picked up
182 public String getKarafDistro() {
184 .groupId("org.opendaylight.lispflowmapping")
185 .artifactId("lispflowmapping-karaf")
186 .versionAsInProject()
192 public MavenUrlReference getFeatureRepo() {
194 .groupId("org.opendaylight.lispflowmapping")
195 .artifactId("features-lispflowmapping")
196 .classifier("features")
198 .versionAsInProject();
202 public String getFeatureName() {
203 return "odl-lispflowmapping-msmr";
207 public Option getLoggingOption() {
208 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
209 "log4j.logger.org.opendaylight.lispflowmapping",
210 LogLevel.TRACE.name());
211 option = composite(option, super.getLoggingOption());
216 public void testLispFlowMappingFeatureLoad() {
217 Assert.assertTrue(true);
221 public void after() {
222 if (socket != null) {
225 // reset mapping record validity to default value
226 ConfigIni.getInstance().setRegistrationValiditySb(200000L);
230 public void before() throws Exception {
232 mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_FIRST);
233 mapService.setMappingMerge(false);
234 ConfigIni.getInstance().setSmrRetryCount(1);
236 locatorEid = LispAddressUtil.asIpv4Rloc("4.3.2.1");
237 socket = initSocket(socket, LispMessage.PORT_NUM);
239 // SRC: 127.0.0.1:58560 to 127.0.0.1:4342
240 // LISP(Type = 8 - Encapsulated)
241 // IP: 192.168.136.10 -> 153.16.254.1
243 // LISP(Type = 1 Map-Request
247 // Source EID 1.2.3.4
248 // Nonce: 0x3d8d2acd39c8d608
249 // ITR-RLOC AFI=1 Address=192.168.136.10
250 // Record 1: 153.16.254.1/32
251 mapRequestPacket = extractWSUdpByteArray(new String("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " //
252 + "0010 00 58 00 00 40 00 40 11 3c 93 7f 00 00 01 7f 00 "
253 + "0020 00 01 e4 c0 10 f6 00 44 fe 57 80 00 00 00 45 00 "
254 + "0030 00 3c d4 31 00 00 ff 11 56 f3 7f 00 00 02 99 10 "
255 + "0040 fe 01 dd b4 10 f6 00 28 ef 3a 10 00 00 01 3d 8d "
256 + "0050 2a cd 39 c8 d6 08 00 01 01 02 03 04 00 01 7f 00 00 02 00 20 " //
257 + "0060 00 01 99 10 fe 01"));
259 // IP: 192.168.136.10 -> 128.223.156.35
260 // UDP: 49289 -> 4342
261 // LISP(Type = 3 Map-Register, P=1, M=1
265 // AuthDataLength: 20 Data:
266 // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:a5:68:89:ec
267 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
269 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
270 // Priority/Weight: 1/100, Multicast Priority/Weight:
274 mapRegisterPacketWithAuthenticationAndMapNotify = extractWSUdpByteArray(new String(
275 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
276 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
277 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
278 + "0030 00 00 00 00 00 00 00 01 00 14 0e a4 c6 d8 a4 06 "
279 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
280 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
281 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
283 // IP: 192.168.136.10 -> 128.223.156.35
284 // UDP: 49289 -> 4342
285 // LISP(Type = 3 Map-Register, P=1, M=1
288 // Key ID: 0x0000 NO AUTHENTICATION!!
289 // AuthDataLength: 00 Data:
290 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
292 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
293 // Priority/Weight: 1/100, Multicast Priority/Weight:
297 mapRegisterPacketWithNotify = extractWSUdpByteArray(new String(
298 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
299 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
300 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
301 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
302 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
303 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
304 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
306 // IP: 192.168.136.10 -> 128.223.156.35
307 // UDP: 49289 -> 4342
308 // LISP(Type = 3 Map-Register, P=1, M=1
311 // Key ID: 0x0000 NO AUTHENTICATION!!
312 // AuthDataLength: 00 Data:
313 // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
315 // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
316 // Priority/Weight: 1/100, Multicast Priority/Weight:
320 mapRegisterPacketWithoutNotify = extractWSUdpByteArray(new String(
321 "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
322 + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
323 + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 00 01 00 00 "
324 + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 "
325 + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
326 + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
327 + "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
331 private BundleContext bc;
332 //private HttpURLConnection connection;
333 protected static boolean notificationCalled;
335 @Inject @Filter(timeout=60000)
336 private IFlowMapping lms;
338 @Inject @Filter(timeout=60000)
339 private IMappingService mapService;
341 @Inject @Filter(timeout=10000)
342 private IConfigLispSouthboundPlugin configLispPlugin;
345 public void testSimpleUsage() throws Exception {
347 mapRegisterWithMapNotify();
348 mapRegisterWithMapNotifyAndMapRequest();
349 registerAndQuery__MAC();
350 mapRequestMapRegisterAndMapRequest();
351 mapRegisterWithAuthenticationWithoutConfiguringAKey();
352 mapRegisterWithoutMapNotify();
356 public void testLCAFs() throws Exception {
357 registerAndQuery__SrcDestLCAF();
358 registerAndQuery__SrcDestLCAFOverlap();
359 registerAndQuery__KeyValueLCAF();
360 //registerAndQuery__ListLCAF();
361 //registerAndQuery__ApplicationData();
362 //registerAndQuery__TrafficEngineering();
363 //registerAndQuery__SegmentLCAF();
367 public void testMask() throws Exception {
368 //testPasswordExactMatch(); TODO commented because it needs NB
369 //testPasswordMaskMatch(); TODO commented because it needs NB
370 eidPrefixLookupIPv4();
371 eidPrefixLookupIPv6();
375 public void testNorthbound() throws Exception {
377 northboundAddMapping();
378 northboundDeleteMapping();
379 northboundRetrieveKey();
380 northboundRetrieveMapping();
381 northboundRetrieveSourceDestKey();
382 northboundRetrieveSourceDestMapping();
386 public void testOverWriting() throws Exception {
387 //testMapRegisterDosntOverwritesOtherSubKeys(); TODO weird failure, needs debug
389 // TODO: remove, we don't support overwrite flag any longer and RLOCs are not saved as independent RLOC groups
390 // testMapRegisterOverwritesSameSubkey();
391 // testMapRegisterOverwritesNoSubkey();
392 // testMapRegisterDoesntOverwritesNoSubkey();
396 public void testTimeOuts() throws Exception {
397 timedOutMappingRecord();
398 mapRequestMapRegisterAndMapRequestTestTimeout();
399 //mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse(); TODO commented because it needs NB
403 // public void testNonProxy() throws Throwable {
404 // testSimpleNonProxy();
405 // testNonProxyOtherPort();
406 // testRecievingNonProxyOnXtrPort();
410 public void testSmr() throws Exception {
411 registerQueryRegisterWithSmr();
416 public void testMultiSite() throws Exception {
417 testMultiSiteScenarioA();
418 testMultiSiteScenarioB();
422 public void testNbAndSbNegativePrefix() throws UnknownHostException {
424 testGapIntersection();
427 testMultipleMappings();
431 public void testExplicitSbNegativePrefixes() {
432 // https://bugs.opendaylight.org/show_bug.cgi?id=8679
433 testNegativePrefix();
435 // https://bugs.opendaylight.org/show_bug.cgi?id=9023
436 testPositiveMappingRemoval();
439 private void testRepeatedSmr() throws SocketTimeoutException, UnknownHostException {
441 long timeout = ConfigIni.getInstance().getSmrTimeout();
442 ConfigIni.getInstance().setSmrRetryCount(5);
444 final InstanceIdType iid = new InstanceIdType(1L);
445 final Eid eid1 = LispAddressUtil.asIpv4Eid("1.1.1.1", 1L);
446 final Eid subscriberEid = LispAddressUtil.asIpv4Eid("2.2.2.2", 1L);
447 final int expectedSmrs1 = 2;
448 final int expectedSmrs2 = 3;
451 final Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iid);
452 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
454 /* add subscribers */
455 final String subscriberSrcRloc1 = "127.0.0.3";
456 final String subscriberSrcRloc2 = "127.0.0.4";
457 final Set<Subscriber> subscriberSet1 = Sets.newHashSet(newSubscriber(subscriberEid, subscriberSrcRloc1),
458 newSubscriber(subscriberEid, subscriberSrcRloc2));
459 mapService.addData(MappingOrigin.Southbound, eid1, SubKeys.SUBSCRIBERS, subscriberSet1);
461 final SocketReader reader1 = startSocketReader(subscriberSrcRloc1, 15000);
462 final SocketReader reader2 = startSocketReader(subscriberSrcRloc2, 15000);
466 final MappingRecord mapping1 = new MappingRecordBuilder()
467 .setEid(eid1).setTimestamp(System.currentTimeMillis()).setRecordTtl(1440).build();
468 mapService.addMapping(MappingOrigin.Northbound, eid1, null, new MappingData(mapping1));
470 sleepForMilliseconds((timeout * expectedSmrs1) - (timeout / 2));
471 final List<MapRequest> requests1 = processSmrPackets(reader1, subscriberSrcRloc1, expectedSmrs1);
472 final MapReply mapReply1 = lms.handleMapRequest(
473 new MapRequestBuilder(requests1.get(0))
474 .setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build())
475 .setItrRloc(Lists.newArrayList(new ItrRlocBuilder()
476 .setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc1)).build()))
477 .setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build()))
479 .setSmr(false).build());
481 // sleep to get 1 extra smr request
482 sleepForMilliseconds(timeout * 1);
483 final List<MapRequest> requests2 = processSmrPackets(reader2, subscriberSrcRloc2, expectedSmrs2);
484 final MapReply mapReply2 = lms.handleMapRequest(
485 new MapRequestBuilder(requests2.get(0))
486 .setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build())
487 .setItrRloc(Lists.newArrayList(new ItrRlocBuilder()
488 .setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc2)).build()))
489 .setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build()))
491 .setSmr(false).build());
494 assertEquals(expectedSmrs1, requests1.size());
495 assertEquals(expectedSmrs2, requests2.size());
496 assertEquals((long) mapReply1.getNonce(), (long) requests1.get(0).getNonce());
497 assertEquals((long) mapReply2.getNonce(), (long) requests2.get(0).getNonce());
498 assertNextBufferEmpty(reader1);
499 assertNextBufferEmpty(reader2);
501 reader1.stopReading();
502 reader2.stopReading();
505 private SocketReader startSocketReader(String address, int timeout) {
506 DatagramSocket receivingSocket = null;
509 receivingSocket = new DatagramSocket(new InetSocketAddress(address, LispMessage.PORT_NUM));
510 } catch (SocketException e) {
511 LOG.error("Can't initialize socket for {}", address, e);
513 return SocketReader.startReadingInStandaloneThread(receivingSocket, timeout);
516 private List<MapRequest> processSmrPackets(SocketReader reader, String address, int expectedSmrs) {
517 InetAddress inetAddress = null;
519 inetAddress = InetAddress.getByName(address);
520 } catch (UnknownHostException e) {
521 LOG.error("Unknown address {}.", address, e);
524 final List<MapRequest> requests = Lists.newArrayList();
525 byte[][] buffers = reader.getBuffers(expectedSmrs);
526 for (byte[] buf : buffers) {
527 MapRequest request = MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(buf), inetAddress);
528 requests.add(request);
533 private void assertNextBufferEmpty(SocketReader socketReader) {
534 assertTrue(MultiSiteScenario.areBuffersEmpty(socketReader.getBuffers(1)));
537 private static Subscriber newSubscriber(Eid srcEid, String srcRlocIp) {
538 final int timeout = 5;
539 final Rloc srcRloc = LispAddressUtil.asIpv4Rloc(srcRlocIp);
540 return new Subscriber(srcRloc, srcEid, timeout);
543 private void testMultipleMappings() throws UnknownHostException {
544 final InstanceIdType iid = new InstanceIdType(1L);
545 final String prefix1 = "1.1.127.10/32"; // prefix from the intersection of NB and SB gaps
546 final String prefix2 = "1.1.200.255/32"; // prefix with existing mapping in NB
547 final String prefix3 = "1.3.255.255/32";
549 final MapRequest mapRequest = new MapRequestBuilder().setSmrInvoked(false).setEidItem(Lists.newArrayList(
550 new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixBinaryEid(prefix1, iid))
552 new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixBinaryEid(prefix2, iid))
554 new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixBinaryEid(prefix3, iid))
557 final MapReply mapReply = lms.handleMapRequest(mapRequest);
560 final String resultPrefix1 = "1.1.64.0";
561 final Address resultNegMapping1 = new Ipv4PrefixBinaryBuilder()
562 .setIpv4AddressBinary(new Ipv4AddressBinary(InetAddress.getByName(resultPrefix1).getAddress()))
563 .setIpv4MaskLength((short) 18).build();
565 final String resultPrefix2 = "1.1.128.0";
566 final Address resultMapping2 = new Ipv4PrefixBinaryBuilder()
567 .setIpv4AddressBinary(new Ipv4AddressBinary(InetAddress.getByName(resultPrefix2).getAddress()))
568 .setIpv4MaskLength((short) 17).build();
570 final String resultPrefix3 = "1.3.0.0";
571 final Address resultNegMapping3 = new Ipv4PrefixBinaryBuilder()
572 .setIpv4AddressBinary(new Ipv4AddressBinary(InetAddress.getByName(resultPrefix3).getAddress()))
573 .setIpv4MaskLength((short) 16).build();
575 assertEquals(resultNegMapping1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getEid()
577 assertEquals(resultMapping2, mapReply.getMappingRecordItem().get(1).getMappingRecord().getEid()
579 assertEquals(resultNegMapping3, mapReply.getMappingRecordItem().get(2).getMappingRecord().getEid()
584 * Tests a negative mapping from an intersection of gaps in northbound and southbound.
586 private void testGapIntersection() throws UnknownHostException {
587 // request an Eid from a gap between mappings
588 final MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "1.1.127.10/32"));
590 // expected negative mapping
591 final Address resultNegMapping = new Ipv4PrefixBinaryBuilder()
592 .setIpv4AddressBinary(new Ipv4AddressBinary(InetAddress.getByName("1.1.64.0").getAddress()))
593 .setIpv4MaskLength((short) 18).build();
594 assertEquals(resultNegMapping, mapReply.getMappingRecordItem().get(0).getMappingRecord().getEid()
598 private void testNegativePrefix() {
599 // First, we test with one mapping in NB and one mapping in SB
602 insertNBMappings(1L, "192.0.2.0/24");
603 insertSBMappings(1L, "10.0.0.0/32");
608 MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "11.1.1.1/32"));
609 Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "11.0.0.0/8");
610 assertEquals(expectedNegativePrefix, mapReply.getMappingRecordItem().get(0).getMappingRecord().getEid());
611 assertTrue(MappingRecordUtil.isNegativeMapping(mapReply.getMappingRecordItem().get(0).getMappingRecord()));
613 // Second, we test with two mappings in NB only
616 insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16");
621 mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32"));
622 expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16");
623 MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
624 assertEquals(expectedNegativePrefix, mr.getEid());
625 assertTrue(MappingRecordUtil.isNegativeMapping(mr));
628 private void testPositiveMappingRemoval() {
631 insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16");
632 insertSBMappings(1L, "192.168.32.0/19");
634 MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32"));
635 Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/19");
636 MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
637 assertEquals(expectedNegativePrefix, mr.getEid());
638 assertTrue(MappingRecordUtil.isNegativeMapping(mr));
640 mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.64.1/32"));
641 expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.64.0/18");
642 mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
643 assertEquals(expectedNegativePrefix, mr.getEid());
644 assertTrue(MappingRecordUtil.isNegativeMapping(mr));
646 mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.128.1/32"));
647 expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.128.0/17");
648 mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
649 assertEquals(expectedNegativePrefix, mr.getEid());
650 assertTrue(MappingRecordUtil.isNegativeMapping(mr));
652 printMapCacheState();
654 mapService.removeMapping(MappingOrigin.Southbound, LispAddressUtil.asIpv4PrefixBinaryEid(
655 1L, "192.168.32.0/19"));
657 printMapCacheState();
659 mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.32.1/32"));
660 expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16");
661 mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
662 assertEquals(expectedNegativePrefix, mr.getEid());
663 assertTrue(MappingRecordUtil.isNegativeMapping(mr));
665 printMapCacheState();
668 private void insertMappings() {
670 mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB);
672 insertNBMappings(1L, "1.2.0.0/16", "1.1.128.0/17");
673 insertSBMappings(1L, "1.1.32.0/19", "1.0.0.0/8");
679 private void insertNBMappings(long iid, String ... prefixes) {
680 LOG.debug("Adding Northbound mappings for prefixes: {}", prefixes);
681 final InstanceIdType iiType = new InstanceIdType(iid);
682 for (String prefix : prefixes) {
683 MappingRecord record = newMappingRecord(prefix, iiType);
684 mapService.addMapping(MappingOrigin.Northbound, record.getEid(), null, new MappingData(record));
686 sleepForMilliseconds(25);
687 printMapCacheState();
690 private void insertSBMappings(long iid, String ... prefixes) {
691 LOG.debug("Adding Southbound mappings for prefixes: {}", prefixes);
692 final InstanceIdType iiType = new InstanceIdType(iid);
693 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iiType);
694 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
696 for (String prefix : prefixes) {
697 MappingRecord record = newMappingRecord(prefix, iiType);
698 mapService.addMapping(MappingOrigin.Southbound, record.getEid(), null,
699 new MappingData(record, System.currentTimeMillis()));
701 printMapCacheState();
704 private void printMapCacheState() {
705 LOG.debug("Map-cache state:\n{}", mapService.prettyPrintMappings());
709 * Creates a new MappingRecord object.
711 * @param prefix The Eid prefix
713 * @return new MappingRecord object
715 private MappingRecord newMappingRecord(String prefix, InstanceIdType iid) {
716 final Eid prefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(prefix, iid);
717 return new MappingRecordBuilder()
718 .setEid(prefixBinary)
719 .setLocatorRecord(Lists.newArrayList(new LocatorRecordBuilder()
720 .setRloc(LispAddressUtil.asIpv4Rloc("2.2.2.2"))
721 .setLocatorId("loc_id")
723 .setPriority((short) 1)
724 .setWeight((short) 1).build()))
725 .setTimestamp(System.currentTimeMillis())
726 .setRecordTtl(1440).build();
729 private MapRequest newMapRequest(long iid, String prefix) {
730 final InstanceIdType iidt = new InstanceIdType(iid);
731 return new MapRequestBuilder()
732 .setSmrInvoked(false)
733 .setEidItem(Lists.newArrayList(
734 new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixBinaryEid(prefix, iidt)).build()))
741 public void testMultiSiteScenarioA() throws IOException {
743 ConfigIni.getInstance().setSmrRetryCount(1);
744 ConfigIni.getInstance().setSmrTimeout(30000L);
746 final MultiSiteScenario multiSiteScenario = new MultiSiteScenario(mapService, lms);
747 multiSiteScenario.setCommonAuthentication();
750 final SocketReader socketReader = SocketReader.startReadingInStandaloneThread(socket);
753 multiSiteScenario.storeSouthboundMappings(false, SITE_A, SITE_B, SITE_C, SITE_D4, SITE_D5);
754 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C);
755 multiSiteScenario.storeNorthMappingNegative(SITE_C, Action.Drop);
756 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
757 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
758 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
759 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
762 //following action should trigger generating of SMR messages:
765 multiSiteScenario.storeNorthMappingSrcDst(SITE_A, SITE_C);
766 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
767 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1));
768 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_C, 4);
769 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
770 multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4);
773 // following action should trigger generating of SMR messages:
778 multiSiteScenario.deleteNorthMappingNegative(SITE_C);
779 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
780 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1), SITE_A
783 multiSiteScenario.assertPingWorks(SITE_D4, 5, SITE_C, 4);
786 // following action should trigger generating of SMR messages:
791 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C_RLOC_10);
792 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
793 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1),
794 SITE_A.getHost(5), SITE_D4.getHost(5));
795 //way of testing ping - get RLOC for mapping src-dst and compare it with awaited value doesn't test
796 //that ping won't be successfull
797 multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4);
800 // following action should trigger generating of SMR messages:
805 multiSiteScenario.storeNorthMappingNegative(SITE_C, Action.Drop);
806 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
807 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1),
808 SITE_A.getHost(5), SITE_D4.getHost(5));
809 multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4);
812 multiSiteScenario.assertPingFails(SITE_D5, 5, SITE_C, 3);
815 // following action should trigger generating of SMR messages:
821 multiSiteScenario.deleteNorthMapingSrcDst(SITE_A, SITE_C);
822 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
823 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
824 SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5));
826 // following action should trigger generating of SMR messages:
832 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C);
833 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
834 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
835 SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5));
837 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
838 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
839 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
842 // following action should trigger generating of SMR messages:
848 multiSiteScenario.deleteNorthMapingSrcDst(SITE_B, SITE_C);
849 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
850 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
851 SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5));
852 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
853 multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4);
854 multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4);
857 // following action should trigger generating of SMR messages:
863 multiSiteScenario.deleteNorthMappingNegative(SITE_C);
864 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
865 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5),
866 SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5));
867 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4);
868 multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4);
869 multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_C, 4);
871 socketReader.stopReading();
878 public void testMultiSiteScenarioB() throws IOException {
881 final MultiSiteScenario multiSiteScenario = new MultiSiteScenario(mapService, lms);
882 multiSiteScenario.setCommonAuthentication();
885 final SocketReader socketReader = SocketReader.startReadingInStandaloneThread(socket);
887 mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB);
888 mapService.setMappingMerge(true);
891 multiSiteScenario.storeSouthboundMappings(true, SITE_A_SB, SITE_B_SB, SITE_C_WP_100_1_SB, SITE_D_WP_100_1_SB,
893 multiSiteScenario.storeNorthMappingIpPrefix(SITE_A_SB);
894 multiSiteScenario.storeNorthMappingIpPrefix(SITE_B_SB);
895 multiSiteScenario.storeNorthMappingIpPrefix(SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
896 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
897 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
898 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
901 // following action should trigger generating of SMR messages:
904 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
905 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
906 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
908 // following action should trigger generating of SMR messages:
911 multiSiteScenario.storeNorthMappingNegative(SITE_C_SB, Action.Drop);
912 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
913 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
915 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
916 multiSiteScenario.assertPingFails(SITE_B_SB, 5, SITE_C_SB, 4);
920 // following action should trigger generating of SMR messages:
923 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB);
924 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
925 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
926 multiSiteScenario.assertPingWorks(SITE_A_SB, 5, SITE_C_WP_50_2_SB, 4);
929 multiSiteScenario.storeNorthMappingSrcDst(SITE_B_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB);
930 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
931 // following action should trigger generating of SMR messages:
934 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
935 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB);
938 multiSiteScenario.deleteSouthboundMappings(SITE_D_DELETE_SB);
939 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
940 // following action should trigger generating of SMR messages:
943 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
945 multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4);
948 multiSiteScenario.deleteNorthMapingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB);
949 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
950 // following action should trigger generating of SMR messages:
953 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5));
955 multiSiteScenario.deleteNorthMapingSrcDst(SITE_B_SB, SITE_C_WP_50_2_SB);
956 sleepForSeconds(MULTI_SITE_SLEEP_TIME);
957 multiSiteScenario.assertPingFails(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4);
959 socketReader.stopReading();
963 // ------------------------------- Simple Tests ---------------------------
965 public void mapRequestSimple() throws SocketTimeoutException {
968 // This Map-Request is sent from a source port different from 4342
969 // We close and bind the socket on the correct port
970 if (socket != null) {
973 socket = initSocket(socket, 56756);
975 sendPacket(mapRequestPacket);
976 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
977 MapReply reply = MapReplySerializer.getInstance().deserialize(readBuf);
978 assertEquals(4435248268955932168L, reply.getNonce().longValue());
982 public void mapRegisterWithMapNotify() throws SocketTimeoutException {
984 mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
987 sendPacket(mapRegisterPacketWithNotify);
988 MapNotify reply = receiveMapNotify();
989 assertEquals(7, reply.getNonce().longValue());
992 public void mapRegisterWithMapNotifyAndMapRequest() throws SocketTimeoutException {
994 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
996 MapReply mapReply = registerAddressAndQuery(eid);
998 assertEquals(4, mapReply.getNonce().longValue());
999 assertEquals(locatorEid, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
1004 public void registerAndQuery__MAC() throws SocketTimeoutException {
1006 String macAddress = "01:02:03:04:05:06";
1008 MapReply reply = registerAddressAndQuery(LispAddressUtil.asMacEid(macAddress));
1011 Eid addressFromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1012 assertEquals(MacAfi.class, addressFromNetwork.getAddressType());
1013 String macAddressFromReply = ((Mac) addressFromNetwork.getAddress()).getMac().getValue();
1015 assertEquals(macAddress, macAddressFromReply);
1018 public void mapRequestMapRegisterAndMapRequest() throws SocketTimeoutException {
1020 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1021 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1024 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1025 mapRequestBuilder.setNonce((long) 4);
1026 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
1027 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1028 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1029 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1030 mapRequestBuilder.getItrRloc().add(
1031 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1032 sendMapRequest(mapRequestBuilder.build());
1033 MapReply mapReply = receiveMapReply();
1034 assertEquals(4, mapReply.getNonce().longValue());
1035 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1036 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
1037 mapRegisterbuilder.setWantMapNotify(true);
1038 mapRegisterbuilder.setNonce((long) 8);
1039 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1040 etlrBuilder.setEid(eid);
1041 etlrBuilder.setRecordTtl(254);
1042 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1043 recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
1044 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1045 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1046 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1047 mapRegisterbuilder.getMappingRecordItem().add(
1048 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
1049 sendMapRegister(mapRegisterbuilder.build());
1050 MapNotify mapNotify = receiveMapNotify();
1051 assertEquals(8, mapNotify.getNonce().longValue());
1053 sendMapRequest(mapRequestBuilder.build());
1054 mapReply = receiveMapReply();
1055 assertEquals(4, mapReply.getNonce().longValue());
1056 assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord()
1057 .getLocatorRecord().get(0).getRloc());
1061 public void testMapRegisterDosntOverwritesOtherSubKeys() throws SocketTimeoutException {
1063 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1064 SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
1065 Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
1066 SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
1067 Rloc rloc2 = LispAddressUtil.asKeyValueAddress("subkey2", rloc2Value);
1068 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
1069 assertEquals(2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1070 assertEquals(rloc2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
1072 assertEquals(rloc1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1)
1076 public void testMapRegisterOverwritesSameSubkey() throws SocketTimeoutException {
1078 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1079 SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
1080 Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
1081 SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
1082 Rloc rloc2 = LispAddressUtil.asKeyValueAddress("subkey2", rloc2Value);
1083 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1, rloc2);
1084 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1085 assertEquals(rloc2, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
1089 public void testMapRegisterOverwritesNoSubkey() throws SocketTimeoutException {
1091 mapService.setMappingMerge(false);
1092 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1093 Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
1094 Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
1095 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
1096 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1097 assertEquals(rloc2Value, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
1101 public void testMapRegisterDoesntOverwritesNoSubkey() throws SocketTimeoutException {
1103 mapService.setMappingMerge(true);
1104 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
1105 Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
1106 Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
1107 MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
1108 assertEquals(1, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1109 Rloc rloc1ReturnValueContainer = mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
1111 Rloc rloc2ReturnValueContainer = mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
1113 assertTrue((rloc1Value.equals(rloc1ReturnValueContainer) && rloc2Value.equals(rloc2ReturnValueContainer))
1114 || (rloc1Value.equals(rloc2ReturnValueContainer) && rloc2Value.equals(rloc1ReturnValueContainer)));
1117 private MapReply sendMapRegisterTwiceWithDiffrentValues(Eid eid, Rloc rloc1, Rloc rloc2)
1118 throws SocketTimeoutException {
1119 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1121 MapRegister mb = createMapRegister(eid, rloc1);
1122 MapNotify mapNotify = lms.handleMapRegister(mb).getLeft();
1123 MapRequest mr = createMapRequest(eid);
1124 MapReply mapReply = lms.handleMapRequest(mr);
1125 assertEquals(mb.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc(),
1126 mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc());
1127 mb = createMapRegister(eid, rloc2);
1128 mapNotify = lms.handleMapRegister(mb).getLeft();
1129 assertEquals(8, mapNotify.getNonce().longValue());
1130 mr = createMapRequest(eid);
1132 mapReply = lms.handleMapRequest(mr);
1136 public void mapRegisterWithAuthenticationWithoutConfiguringAKey() throws SocketTimeoutException {
1138 sendPacket(mapRegisterPacketWithAuthenticationAndMapNotify);
1140 receivePacket(3000);
1141 // If didn't timeout then fail:
1143 } catch (SocketTimeoutException ste) {
1147 public void mapRegisterWithoutMapNotify() {
1149 sendPacket(mapRegisterPacketWithoutNotify);
1151 receivePacket(3000);
1152 // If didn't timeout then fail:
1154 } catch (SocketTimeoutException ste) {
1158 public void registerQueryRegisterWithSmr() throws SocketTimeoutException {
1160 lms.setShouldUseSmr(true);
1161 mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
1164 sendPacket(mapRegisterPacketWithNotify);
1168 sendPacket(mapRequestPacket);
1171 mapRegisterPacketWithoutNotify[mapRegisterPacketWithoutNotify.length - 1] += 1;
1172 sendPacket(mapRegisterPacketWithoutNotify);
1174 ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
1175 MapRequest smr = MapRequestSerializer.getInstance().deserialize(readBuf, null);
1176 assertTrue(smr.isSmr());
1177 Eid sourceEid = smr.getSourceEid().getEid();
1178 assertTrue(LispAddressUtil.asIpv4Eid("153.16.254.1").equals(sourceEid));
1179 Eid smrEid = smr.getEidItem().get(0).getEid();
1180 assertTrue(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32").equals(smrEid));
1183 // --------------------- Northbound Tests ---------------------------
1185 private void northboundAddKey() throws Exception {
1187 LispIpv4Address address = LispAddressUtil.asIPAfiAddress("1.2.3.4");
1189 String pass = "asdf";
1191 URL url = createPutURL("key");
1192 String authKeyJSON = createAuthKeyJSON(pass, address, mask);
1193 callURL("PUT", "application/json", "text/plain", authKeyJSON, url);
1195 String retrievedKey = lms.getAuthenticationKey(LispAddressUtil.toContainer(address), mask);
1197 // Check stored password matches the one sent
1198 assertEquals(pass, retrievedKey);
1202 private void northboundRetrieveSourceDestKey() throws Exception {
1204 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1205 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1206 .primitiveaddress.Ipv4) LispAddressUtil
1207 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.1"));
1208 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1209 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1210 .primitiveaddress.Ipv4) LispAddressUtil
1211 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.2"));
1214 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(
1215 AddressFamilyNumberEnum.LCAF.getIanaCode())
1216 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
1217 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(address1).build())
1218 .setSrcMaskLength((short) mask1)
1219 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(address2).build())
1220 .setDstMaskLength((short) mask2).build();
1221 String pass = "asdf";
1223 lms.addAuthenticationKey(LispAddressUtil.toContainer(sourceDestAddress), mask1, pass);
1225 // URL url = createGetKeyIPv4URL(address1, mask1);
1226 URL url = createGetKeySourceDestURL(address1.getIpv4Address().getAfi(),
1227 ((LispIpv4Address) LispAddressUtil.toAFIfromPrimitive(sourceDestAddress.getSrcAddress()
1228 .getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getSrcMaskLength(),
1229 ((LispIpv4Address) LispAddressUtil.toAFIfromPrimitive(sourceDestAddress.getDstAddress()
1230 .getPrimitiveAddress())).getIpv4Address().getValue(), sourceDestAddress.getDstMaskLength());
1231 String reply = callURL("GET", null, "application/json", null, url);
1232 JSONTokener jt = new JSONTokener(reply);
1233 JSONObject json = new JSONObject(jt);
1235 // test that the password matches what was we expected.
1236 assertEquals(pass, json.get("key"));
1240 private void northboundRetrieveKey() throws Exception {
1242 LispIpv4Address address = LispAddressUtil.asIPAfiAddress("10.0.0.1");
1244 String pass = "asdf";
1246 lms.addAuthenticationKey(LispAddressUtil.toContainer(address), mask, pass);
1248 URL url = createGetKeyIPv4URL(address, mask);
1249 String reply = callURL("GET", null, "application/json", null, url);
1250 JSONTokener jt = new JSONTokener(reply);
1251 JSONObject json = new JSONObject(jt);
1253 // test that the password matches what was we expected.
1254 assertEquals(pass, json.get("key"));
1258 private String createAuthKeyJSON(String key, LispIpv4Address address, int mask) {
1259 return "{\"key\" : \"" + key + "\",\"maskLength\" : " + mask + ",\"address\" : " + "{\"ipAddress\" : \""
1260 + address.getIpv4Address().getValue() + "\",\"afi\" : " + address.getAfi().shortValue() + "}}";
1263 private void northboundAddMapping() throws Exception {
1265 String pass = "asdf";
1266 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
1268 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1270 // NB add mapping always checks the key
1271 lms.addAuthenticationKey(LispAddressUtil.toContainer(eid), mask, pass);
1273 URL url = createPutURL("mapping");
1274 String mapRegisterJSON = createMapRegisterJSON(pass, eid, mask, rloc);
1275 callURL("PUT", "application/json", "text/plain", mapRegisterJSON, url);
1277 // Retrieve the RLOC from the database
1278 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1279 mapRequestBuilder.setPitr(false);
1280 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1281 mapRequestBuilder.getEidItem().add(
1282 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(
1283 LispAddressUtil.toContainer(eid)).build());
1284 MapReply mapReply = lms.handleMapRequest(mapRequestBuilder.build());
1286 LispIpv4Address retrievedRloc = (LispIpv4Address) LispAddressUtil.toAFI(
1287 mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0)
1288 .getLispAddressContainer());
1290 assertEquals(rloc.getIpv4Address().getValue(), retrievedRloc.getIpv4Address().getValue());
1294 private String createMapRegisterJSON(String key, LispIpv4Address eid, int mask, LispIpv4Address rloc) {
1295 String jsonString = "{ " + "\"key\" : \"" + key + "\"," + "\"mapregister\" : " + "{ "
1296 + "\"proxyMapReply\" : false, "
1297 + "\"eidToLocatorRecords\" : " + "[ " + "{ " + "\"authoritative\" : true," + "\"prefixGeneric\" : "
1298 + "{ " + "\"ipAddress\" : \""
1299 + eid.getIpv4Address().getValue() + "\"," + "\"afi\" : " + eid.getAfi().shortValue() + "},"
1300 + "\"mapVersion\" : 0,"
1301 + "\"maskLength\" : " + mask + ", " + "\"action\" : \"NoAction\"," + "\"locators\" : " + "[ " + "{ "
1302 + "\"multicastPriority\" : 1,"
1303 + "\"locatorGeneric\" : " + "{ " + "\"ipAddress\" : \"" + rloc.getIpv4Address().getValue() + "\","
1305 + rloc.getAfi().shortValue() + "}, " + "\"routed\" : true," + "\"multicastWeight\" : 50,"
1306 + "\"rlocProbed\" : false, "
1307 + "\"localLocator\" : false, " + "\"priority\" : 1, " + "\"weight\" : 50 " + "} " + "], "
1308 + "\"recordTtl\" : 100" + "} " + "], "
1309 + "\"nonce\" : 3," + "\"keyId\" : 0 " + "} " + "}";
1314 private void northboundRetrieveMapping() throws Exception {
1316 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
1318 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1319 // Insert mapping in the database
1320 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1321 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1322 etlr.setLispAddressContainer(LispAddressUtil.toContainer(eid));
1323 etlr.setMaskLength((short) mask);
1324 etlr.setRecordTtl(254);
1325 etlr.setAuthoritative(false);
1326 etlr.setAction(Action.NoAction);
1327 LocatorRecordBuilder record = new LocatorRecordBuilder();
1328 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
1329 record.setRouted(true);
1330 record.setRlocProbed(false);
1331 record.setLocalLocator(false);
1332 record.setPriority((short) 1);
1333 record.setWeight((short) 50);
1334 record.setMulticastPriority((short) 1);
1335 record.setMulticastWeight((short) 1);
1336 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1337 etlr.getLocatorRecord().add(record.build());
1338 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1339 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1340 lms.handleMapRegister(mapRegister.build());
1342 // Get mapping using NB interface. No IID used
1343 URL url = createGetMappingIPv4URL(0, eid, mask);
1344 String reply = callURL("GET", null, "application/json", null, url);
1345 JSONTokener jt = new JSONTokener(reply);
1346 JSONObject json = new JSONObject(jt);
1348 // With just one locator, locators is not a JSONArray
1349 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric")
1350 .getString("ipAddress");
1352 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
1356 private void northboundDeleteMapping() throws Exception {
1358 LispIpv4Address eid = LispAddressUtil.asIPAfiAddress("10.0.0.1");
1360 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1361 // Insert mapping in the database
1362 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1363 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1364 etlr.setLispAddressContainer(LispAddressUtil.toContainer(eid));
1365 etlr.setMaskLength((short) mask);
1366 etlr.setRecordTtl(254);
1367 etlr.setAuthoritative(false);
1368 etlr.setAction(Action.NoAction);
1369 LocatorRecordBuilder record = new LocatorRecordBuilder();
1370 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
1371 record.setRouted(true);
1372 record.setRlocProbed(false);
1373 record.setLocalLocator(false);
1374 record.setPriority((short) 1);
1375 record.setWeight((short) 50);
1376 record.setMulticastPriority((short) 1);
1377 record.setMulticastWeight((short) 1);
1378 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1379 etlr.getLocatorRecord().add(record.build());
1380 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1381 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1382 lms.handleMapRegister(mapRegister.build());
1384 // Delete mapping using NB interface. No IID used
1385 URL url = createDeleteMappingIPv4URL(0, eid, mask);
1386 String reply = callURL("DELETE", null, "application/json", null, url);
1388 // Get mapping using NB interface. No IID used
1389 url = createGetMappingIPv4URL(0, eid, mask);
1390 reply = callURL("GET", null, "application/json", null, url);
1391 JSONTokener jt = new JSONTokener(reply);
1392 JSONObject json = new JSONObject(jt);
1394 // With just one locator, locators is not a JSONArray
1395 assertEquals(json.getJSONArray("locators").length(), 0);
1398 private void northboundRetrieveSourceDestMapping() throws Exception {
1400 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1401 address1 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1402 .primitiveaddress.Ipv4) LispAddressUtil
1403 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.1"));
1404 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4
1405 address2 = (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress
1406 .primitiveaddress.Ipv4) LispAddressUtil
1407 .toPrimitive(LispAddressUtil.asIPAfiAddress("10.0.0.2"));
1410 LcafSourceDestAddr sourceDestAddress = new LcafSourceDestAddrBuilder().setAfi(
1411 AddressFamilyNumberEnum.LCAF.getIanaCode())
1412 .setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode())
1413 .setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(
1414 address1).build()).setSrcMaskLength((short) mask1)
1415 .setDstAddress(new DstAddressBuilder().setPrimitiveAddress(
1416 address2).build()).setDstMaskLength((short) mask2).build();
1417 LispIpv4Address rloc = LispAddressUtil.asIPAfiAddress("20.0.0.2");
1419 // Insert mapping in the database
1420 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1421 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1422 etlr.setLispAddressContainer(LispAddressUtil.toContainer(sourceDestAddress));
1423 etlr.setMaskLength((short) mask1);
1424 etlr.setRecordTtl(254);
1425 etlr.setAuthoritative(false);
1426 etlr.setAction(Action.NoAction);
1427 LocatorRecordBuilder record = new LocatorRecordBuilder();
1428 record.setLispAddressContainer(LispAddressUtil.toContainer(rloc));
1429 record.setRouted(true);
1430 record.setRlocProbed(false);
1431 record.setLocalLocator(false);
1432 record.setPriority((short) 1);
1433 record.setWeight((short) 50);
1434 record.setMulticastPriority((short) 1);
1435 record.setMulticastWeight((short) 1);
1436 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1437 etlr.getLocatorRecord().add(record.build());
1438 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1439 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1440 lms.handleMapRegister(mapRegister.build());
1442 // Get mapping using NB interface. No IID used
1443 URL url = createGetMappingSourceDestURL(address1.getIpv4Address().getAfi(),
1444 address1.getIpv4Address().getIpv4Address().getValue(),
1446 address2.getIpv4Address().getIpv4Address().getValue(),
1448 String reply = callURL("GET", null, "application/json", null, url);
1449 JSONTokener jt = new JSONTokener(reply);
1450 JSONObject json = new JSONObject(jt);
1452 // With just one locator, locators is not a JSONArray
1453 String rlocRetrieved = json.getJSONArray("locators").getJSONObject(0).getJSONObject("locatorGeneric")
1454 .getString("ipAddress");
1456 assertEquals(rloc.getIpv4Address().getValue(), rlocRetrieved);
1460 private URL createGetKeyIPv4URL(LispIpv4Address address, int mask) throws MalformedURLException {
1461 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d", "key",
1462 address.getAfi().shortValue(),
1463 address.getIpv4Address().getValue(), mask);
1464 URL url = new URL(restUrl);
1468 private URL createGetKeySourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask)
1469 throws MalformedURLException {
1470 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d",
1471 "key", afi, srcAddress, srcMask,
1472 dstAddress, dstMask);
1473 URL url = new URL(restUrl);
1477 private URL createGetMappingSourceDestURL(int afi, String srcAddress, int srcMask, String dstAddress, int dstMask)
1478 throws MalformedURLException {
1479 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/0/%d/%s/%d/%s/%d",
1480 "mapping", afi, srcAddress,
1481 srcMask, dstAddress, dstMask);
1482 URL url = new URL(restUrl);
1486 private URL createGetMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
1487 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping",
1488 iid, address.getAfi()
1489 .shortValue(), address.getIpv4Address().getValue(), mask);
1490 URL url = new URL(restUrl);
1494 private URL createDeleteMappingIPv4URL(int iid, LispIpv4Address address, int mask) throws MalformedURLException {
1495 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s/%d/%d/%s/%d", "mapping",
1496 iid, address.getAfi()
1497 .shortValue(), address.getIpv4Address().getValue(), mask);
1498 URL url = new URL(restUrl);
1502 private URL createPutURL(String resource) throws MalformedURLException {
1504 String restUrl = String.format("http://localhost:8080/lispflowmapping/nb/v2/default/%s", resource);
1506 URL url = new URL(restUrl);
1510 private String createAuthenticationString() {
1511 String authString = "admin:admin";
1512 byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
1513 String authStringEnc = new String(authEncBytes);
1514 return authStringEnc;
1517 private String callURL(String method, String content, String accept, String body, URL url) throws IOException,
1519 String authStringEnc = createAuthenticationString();
1520 connection = (HttpURLConnection) url.openConnection();
1521 connection.setRequestMethod(method);
1522 connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
1523 if (content != null) {
1524 connection.setRequestProperty("Content-Type", content);
1526 if (accept != null) {
1527 connection.setRequestProperty("Accept", accept);
1530 // now add the request body
1531 connection.setDoOutput(true);
1532 OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
1536 connection.connect();
1538 // getting the result, first check response code
1539 Integer httpResponseCode = connection.getResponseCode();
1541 if (httpResponseCode > 299) {
1542 LOG.trace("HTTP Address: " + url);
1543 LOG.trace("HTTP Response Code: " + httpResponseCode);
1547 InputStream is = connection.getInputStream();
1548 BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
1549 StringBuilder sb = new StringBuilder();
1551 while ((cp = rd.read()) != -1) {
1552 sb.append((char) cp);
1555 connection.disconnect();
1556 return (sb.toString());
1559 // timePeriod - in ms
1560 public void assertNoPacketReceived(int timePeriod) {
1562 receivePacket(timePeriod);
1563 // If didn't timeout then fail:
1565 } catch (SocketTimeoutException ste) {
1569 // ------------------------------- Mask Tests ---------------------------
1571 public void eidPrefixLookupIPv4() throws SocketTimeoutException {
1573 runPrefixTest(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/16"),
1574 LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.2/32"),
1575 LispAddressUtil.asIpv4PrefixBinaryEid("1.1.1.1/32"));
1578 public void eidPrefixLookupIPv6() throws SocketTimeoutException {
1580 runPrefixTest(LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:6:7:8/64"),
1581 LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:1:2:3/128"),
1582 LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:1:2:3:1:2/128"));
1585 private void runPrefixTest(Eid registerEID, Eid matchedAddress, Eid unMatchedAddress)
1586 throws SocketTimeoutException {
1587 mapService.addAuthenticationKey(registerEID, NULL_AUTH_KEY);
1590 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1591 mapRegister.setWantMapNotify(true);
1592 mapRegister.setNonce((long) 8);
1593 mapRegister.setWantMapNotify(true);
1594 mapRegister.setKeyId((short) 0);
1595 mapRegister.setAuthenticationData(new byte[0]);
1596 mapRegister.setNonce((long) 8);
1597 mapRegister.setProxyMapReply(false);
1598 MappingRecordBuilder etlr = new MappingRecordBuilder();
1599 etlr.setRecordTtl(254);
1600 etlr.setAction(Action.NoAction);
1601 etlr.setAuthoritative(false);
1602 etlr.setMapVersion((short) 0);
1603 etlr.setEid(registerEID);
1604 etlr.setRecordTtl(254);
1605 LocatorRecordBuilder record = new LocatorRecordBuilder();
1606 record.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
1607 record.setLocalLocator(false);
1608 record.setRlocProbed(false);
1609 record.setRouted(true);
1610 record.setMulticastPriority((short) 0);
1611 record.setMulticastWeight((short) 0);
1612 record.setPriority((short) 0);
1613 record.setWeight((short) 0);
1614 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1615 etlr.getLocatorRecord().add(record.build());
1616 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1617 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1618 sendMapRegister(mapRegister.build());
1619 MapNotify mapNotify = receiveMapNotify();
1620 assertEquals(8, mapNotify.getNonce().longValue());
1622 MapRequestBuilder mapRequest = new MapRequestBuilder();
1623 mapRequest.setNonce((long) 4);
1624 mapRequest.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
1625 mapRequest.setEidItem(new ArrayList<EidItem>());
1626 mapRequest.setAuthoritative(false);
1627 mapRequest.setMapDataPresent(false);
1628 mapRequest.setPitr(false);
1629 mapRequest.setProbe(false);
1630 mapRequest.setSmr(false);
1631 mapRequest.setSmrInvoked(false);
1632 mapRequest.getEidItem().add(new EidItemBuilder().setEid(matchedAddress).build());
1633 mapRequest.setItrRloc(new ArrayList<ItrRloc>());
1634 mapRequest.getItrRloc().add(
1635 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1636 sendMapRequest(mapRequest.build());
1637 MapReply mapReply = receiveMapReply();
1638 assertEquals(4, mapReply.getNonce().longValue());
1639 assertEquals(record.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord()
1641 mapRequest.setEidItem(new ArrayList<EidItem>());
1642 mapRequest.getEidItem().add(new EidItemBuilder().setEid(unMatchedAddress).build());
1643 sendMapRequest(mapRequest.build());
1644 mapReply = receiveMapReply();
1645 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
1648 // This registers an IP with a MapRegister, then adds a password via the
1649 // northbound REST API
1650 // and checks that the password works
1651 public void testPasswordExactMatch() throws Exception {
1653 String ipString = "10.0.0.1";
1654 LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
1656 String pass = "pass";
1658 URL url = createPutURL("key");
1660 String jsonAuthData = createAuthKeyJSON(pass, address, mask);
1662 LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
1663 LOG.trace("Address: " + address);
1665 byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
1666 (byte) 31, (byte) 249, (byte) 87,
1667 (byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
1668 (byte) 196, (byte) 62 };
1670 byte[] zeros = new byte[20];
1672 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1674 // build a MapRegister
1675 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1676 mapRegister.setWantMapNotify(true);
1677 mapRegister.setNonce((long) 8);
1678 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1679 etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
1680 etlr.setMaskLength((short) mask);
1681 etlr.setRecordTtl(254);
1682 LocatorRecordBuilder record = new LocatorRecordBuilder();
1683 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1684 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1685 etlr.getLocatorRecord().add(record.build());
1686 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1687 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1689 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1690 mapRegister.setAuthenticationData(zeros);
1692 sendMapRegister(mapRegister.build());
1693 assertNoPacketReceived(3000);
1695 mapRegister.setAuthenticationData(expectedSha);
1697 sendMapRegister(mapRegister.build());
1699 assertMapNotifyReceived();
1702 public void testPasswordMaskMatch() throws Exception {
1704 LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
1705 LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
1706 LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");
1709 String pass = "pass";
1711 URL url = createPutURL("key");
1712 String jsonAuthData = createAuthKeyJSON(pass, range, 8);
1714 callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
1715 // build a MapRegister
1716 MapRegisterBuilder mapRegister = new MapRegisterBuilder();
1718 mapRegister.setWantMapNotify(true);
1719 mapRegister.setNonce((long) 8);
1720 EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
1721 etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
1722 etlr.setMaskLength((short) mask);
1723 etlr.setRecordTtl(254);
1724 LocatorRecordBuilder record = new LocatorRecordBuilder();
1725 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1726 record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
1727 etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
1728 etlr.getLocatorRecord().add(record.build());
1729 mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1730 mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
1732 mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
1734 .setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
1735 -67, -113, 104, -110, -71 });
1737 sendMapRegister(mapRegister.build());
1739 assertMapNotifyReceived();
1741 etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
1743 .setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
1744 -71, -14, -99, 67, -23, -73 });
1746 sendMapRegister(mapRegister.build());
1747 assertNoPacketReceived(3000);
1750 // takes an address, packs it in a MapRegister and sends it
1751 private void registerAddress(Eid eid) throws SocketTimeoutException {
1752 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1754 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1755 mapRegisterBuilder.setWantMapNotify(true);
1756 mapRegisterBuilder.setKeyId((short) 0);
1757 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1758 mapRegisterBuilder.setNonce((long) 8);
1759 mapRegisterBuilder.setProxyMapReply(false);
1760 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1761 etlrBuilder.setEid(eid);
1762 etlrBuilder.setRecordTtl(254);
1763 etlrBuilder.setAction(Action.NoAction);
1764 etlrBuilder.setAuthoritative(false);
1765 etlrBuilder.setMapVersion((short) 0);
1766 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1767 recordBuilder.setLocalLocator(false);
1768 recordBuilder.setRlocProbed(false);
1769 recordBuilder.setRouted(true);
1770 recordBuilder.setMulticastPriority((short) 0);
1771 recordBuilder.setMulticastWeight((short) 0);
1772 recordBuilder.setPriority((short) 0);
1773 recordBuilder.setWeight((short) 0);
1774 recordBuilder.setRloc(locatorEid);
1775 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1776 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1777 mapRegisterBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1778 mapRegisterBuilder.getMappingRecordItem().add(
1779 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
1780 sendMapRegister(mapRegisterBuilder.build());
1781 MapNotify mapNotify = receiveMapNotify();
1782 assertEquals(8, mapNotify.getNonce().longValue());
1785 private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
1786 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1787 mapRequestBuilder.setNonce((long) 4);
1788 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1789 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1790 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1791 if (srcEid != null) {
1792 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
1794 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress))
1797 mapRequestBuilder.getItrRloc().add(
1798 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1799 mapRequestBuilder.setAuthoritative(false);
1800 mapRequestBuilder.setMapDataPresent(false);
1801 mapRequestBuilder.setPitr(false);
1802 mapRequestBuilder.setProbe(false);
1803 mapRequestBuilder.setSmr(false);
1804 mapRequestBuilder.setSmrInvoked(false);
1805 sendMapRequest(mapRequestBuilder.build());
1806 return receiveMapReply();
1809 // takes an address, packs it in a MapRegister, sends it, returns the
1811 private MapReply registerAddressAndQuery(Eid eid) throws SocketTimeoutException {
1812 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
1814 MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder();
1815 mapRegisterBuilder.setWantMapNotify(true);
1816 mapRegisterBuilder.setKeyId((short) 0);
1817 mapRegisterBuilder.setAuthenticationData(new byte[0]);
1818 mapRegisterBuilder.setNonce((long) 8);
1819 mapRegisterBuilder.setProxyMapReply(false);
1820 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
1821 etlrBuilder.setEid(eid);
1822 etlrBuilder.setRecordTtl(254);
1823 etlrBuilder.setAction(Action.NoAction);
1824 etlrBuilder.setAuthoritative(false);
1825 etlrBuilder.setMapVersion((short) 0);
1826 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
1827 recordBuilder.setLocalLocator(false);
1828 recordBuilder.setRlocProbed(false);
1829 recordBuilder.setRouted(true);
1830 recordBuilder.setMulticastPriority((short) 0);
1831 recordBuilder.setMulticastWeight((short) 0);
1832 recordBuilder.setPriority((short) 0);
1833 recordBuilder.setWeight((short) 0);
1834 recordBuilder.setRloc(locatorEid);
1835 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
1836 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
1837 mapRegisterBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
1838 mapRegisterBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
1839 etlrBuilder.build()).build());
1840 sendMapRegister(mapRegisterBuilder.build());
1841 MapNotify mapNotify = receiveMapNotify();
1842 assertEquals(8, mapNotify.getNonce().longValue());
1843 // wait for the notifications to propagate
1845 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
1846 mapRequestBuilder.setNonce((long) 4);
1847 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
1848 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
1849 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
1850 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
1851 mapRequestBuilder.getItrRloc().add(
1852 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
1853 mapRequestBuilder.setAuthoritative(false);
1854 mapRequestBuilder.setMapDataPresent(false);
1855 mapRequestBuilder.setPitr(false);
1856 mapRequestBuilder.setProbe(false);
1857 mapRequestBuilder.setSmr(false);
1858 mapRequestBuilder.setSmrInvoked(false);
1859 sendMapRequest(mapRequestBuilder.build());
1860 return receiveMapReply();
1863 // ------------------------------- LCAF Tests ---------------------------
1865 public void registerAndQuery__SrcDestLCAF() throws SocketTimeoutException {
1867 String ipPrefix = "10.20.30.200/32";
1868 String macString = "01:02:03:04:05:06";
1870 SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
1871 builder.setSource(new SimpleAddress(new IpPrefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1872 .ietf.inet.types.rev130715.Ipv4Prefix(ipPrefix))));
1873 builder.setDest(new SimpleAddress(new MacAddress(macString)));
1875 EidBuilder eb = new EidBuilder();
1876 eb.setAddressType(SourceDestKeyLcaf.class);
1877 eb.setVirtualNetworkId(null);
1878 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1879 .lisp.address.address.SourceDestKeyBuilder().setSourceDestKey(builder.build()).build());
1881 MapReply reply = registerAddressAndQuery(eb.build());
1883 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1884 assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
1885 SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
1887 SimpleAddress receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
1888 SimpleAddress receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
1890 assertNotNull(receivedAddr1.getIpPrefix().getIpv4Prefix());
1891 assertNotNull(receivedAddr2.getMacAddress());
1893 IpPrefix receivedIP = receivedAddr1.getIpPrefix();
1894 MacAddress receivedMAC = receivedAddr2.getMacAddress();
1896 assertEquals(ipPrefix, receivedIP.getIpv4Prefix().getValue());
1897 assertEquals(macString, receivedMAC.getValue());
1900 public void registerAndQuery__SrcDestLCAFOverlap() throws SocketTimeoutException {
1902 String ipString1 = "10.10.10.0";
1903 String ipString2 = "20.20.20.0";
1904 String ipPrefix1 = ipString1 + "/24";
1905 String ipPrefix2 = ipString2 + "/24";
1907 Eid srcDst = LispAddressUtil.asSrcDstEid(ipString1, ipString2, 24, 24, 0);
1908 registerAddress(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2));
1909 registerAddress(srcDst);
1912 MapReply reply = queryForAddress(srcDst, null);
1914 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1915 assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
1916 SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
1918 IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource().getIpPrefix();
1919 IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest().getIpPrefix();
1921 assertNotNull(receivedAddr1.getIpv4Prefix());
1922 assertNotNull(receivedAddr2.getIpv4Prefix());
1924 assertEquals(ipPrefix1, receivedAddr1.getIpv4Prefix().getValue());
1925 assertEquals(ipPrefix2, receivedAddr2.getIpv4Prefix().getValue());
1927 // srcEid/dstEid match
1928 reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "10.10.10.1");
1929 fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1930 assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
1932 assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
1934 // dstEid match only
1935 reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "1.2.3.4");
1936 fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1937 assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
1939 assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
1942 public void registerAndQuery__KeyValueLCAF() throws SocketTimeoutException {
1944 String ipString = "10.20.30.200";
1945 String macString = "01:02:03:04:05:06";
1946 SimpleAddress addrToSend1 = new SimpleAddress(new IpAddress(new Ipv4Address(ipString)));
1947 SimpleAddress addrToSend2 = new SimpleAddress(new MacAddress(macString));
1948 Eid kv = LispAddressUtil.asKeyValueAddressEid(addrToSend1, addrToSend2);
1950 MapReply reply = registerAddressAndQuery(kv);
1952 Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1953 assertEquals(KeyValueAddressLcaf.class, fromNetwork.getAddressType());
1954 KeyValueAddress keyValueFromNetwork = (KeyValueAddress) fromNetwork.getAddress();
1956 SimpleAddress receivedAddr1 = keyValueFromNetwork.getKeyValueAddress().getKey();
1957 SimpleAddress receivedAddr2 = keyValueFromNetwork.getKeyValueAddress().getValue();
1959 assertNotNull(receivedAddr1.getIpAddress().getIpv4Address());
1960 assertNotNull(receivedAddr2.getMacAddress());
1962 Ipv4Address receivedIP = receivedAddr1.getIpAddress().getIpv4Address();
1963 MacAddress receivedMAC = receivedAddr2.getMacAddress();
1965 assertEquals(ipString, receivedIP.getValue());
1966 assertEquals(macString, receivedMAC.getValue());
1969 public void registerAndQuery__ListLCAF() throws SocketTimeoutException {
1971 String macString = "01:02:03:04:05:06";
1972 String ipString = "10.20.255.30";
1973 List<SimpleAddress> addresses = new ArrayList<SimpleAddress>();
1974 addresses.add(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
1975 addresses.add(new SimpleAddress(new MacAddress(macString)));
1976 AfiListBuilder listbuilder = new AfiListBuilder();
1977 listbuilder.setAddressList(addresses);
1979 EidBuilder eb = new EidBuilder();
1980 eb.setAddressType(AfiListLcaf.class);
1981 eb.setVirtualNetworkId(null);
1982 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
1983 .lisp.address.address.AfiListBuilder().setAfiList(listbuilder.build()).build());
1985 MapReply reply = registerAddressAndQuery(eb.build());
1987 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
1989 assertEquals(AfiListLcaf.class, receivedAddress.getAddressType());
1991 AfiList listAddrFromNetwork = (AfiList) receivedAddress.getAddress();
1992 SimpleAddress receivedAddr1 = (SimpleAddress) listAddrFromNetwork.getAfiList().getAddressList().get(0);
1993 SimpleAddress receivedAddr2 = (SimpleAddress) listAddrFromNetwork.getAfiList().getAddressList().get(1);
1995 assertNotNull(receivedAddr1.getIpAddress().getIpv4Address());
1996 assertNotNull(receivedAddr2.getMacAddress());
1998 assertEquals(macString, receivedAddr2.getMacAddress().getValue());
1999 assertEquals(ipString, receivedAddr1.getIpAddress().getIpv4Address().getValue());
2002 public void registerAndQuery__SegmentLCAF() throws SocketTimeoutException {
2004 String ipString = "10.20.255.30";
2007 EidBuilder eb = new EidBuilder();
2008 eb.setAddressType(Ipv4PrefixAfi.class);
2009 eb.setVirtualNetworkId(new InstanceIdType((long) instanceId));
2010 eb.setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns
2011 .yang.ietf.inet.types.rev130715.Ipv4Prefix(ipString)).build());
2013 MapReply reply = registerAddressAndQuery(eb.build());
2015 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
2016 assertEquals(Ipv4PrefixAfi.class, receivedAddress.getAddressType());
2018 assertEquals(ipString, ((Ipv4Prefix) receivedAddress.getAddress()).getIpv4Prefix().getValue());
2020 assertEquals(instanceId, receivedAddress.getVirtualNetworkId().getValue().intValue());
2023 public void registerAndQuery__TrafficEngineering() throws SocketTimeoutException {
2025 String macString = "01:02:03:04:05:06";
2026 String ipString = "10.20.255.30";
2027 HopBuilder hopBuilder = new HopBuilder();
2028 hopBuilder.setAddress(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
2029 hopBuilder.setLrsBits(new LrsBits(true, false, true));
2030 Hop hop1 = hopBuilder.build();
2031 hopBuilder.setAddress(new SimpleAddress(new MacAddress(macString)));
2032 hopBuilder.setLrsBits(new LrsBits(false, true, false));
2033 Hop hop2 = hopBuilder.build();
2034 ExplicitLocatorPathBuilder elpBuilder = new ExplicitLocatorPathBuilder();
2035 elpBuilder.setHop(new ArrayList<Hop>());
2036 elpBuilder.getHop().add(hop1);
2037 elpBuilder.getHop().add(hop2);
2039 EidBuilder eb = new EidBuilder();
2040 eb.setAddressType(ExplicitLocatorPathLcaf.class);
2041 eb.setVirtualNetworkId(null);
2042 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
2043 .lisp.address.address.ExplicitLocatorPathBuilder().setExplicitLocatorPath(elpBuilder.build()).build());
2045 MapReply reply = registerAddressAndQuery(eb.build());
2047 assertEquals(ExplicitLocatorPathLcaf.class, reply.getMappingRecordItem().get(0).getMappingRecord().getEid()
2050 ExplicitLocatorPath receivedAddress = (ExplicitLocatorPath) reply.getMappingRecordItem().get(0)
2051 .getMappingRecord().getEid().getAddress();
2053 Hop receivedHop1 = (Hop) receivedAddress.getExplicitLocatorPath().getHop().get(0);
2054 Hop receivedHop2 = (Hop) receivedAddress.getExplicitLocatorPath().getHop().get(1);
2056 assertEquals(true, receivedHop1.getLrsBits().isLookup());
2057 assertEquals(false, receivedHop1.getLrsBits().isRlocProbe());
2058 assertEquals(true, receivedHop1.getLrsBits().isStrict());
2060 assertEquals(false, receivedHop2.getLrsBits().isLookup());
2061 assertEquals(true, receivedHop2.getLrsBits().isRlocProbe());
2062 assertEquals(false, receivedHop2.getLrsBits().isStrict());
2064 assertNotNull(receivedHop1.getAddress().getIpAddress().getIpv4Address());
2065 assertNotNull(receivedHop2.getAddress().getMacAddress());
2067 assertEquals(ipString, receivedHop1.getAddress().getIpAddress().getIpv4Address().getValue());
2068 assertEquals(macString, receivedHop2.getAddress().getMacAddress().getValue());
2071 public void registerAndQuery__ApplicationData() throws SocketTimeoutException {
2073 String ipString = "1.2.3.4";
2076 int localPortLow = 3;
2077 int localPortHigh = 4;
2078 int remotePortLow = 4;
2079 int remotePortHigh = 5;
2081 ApplicationDataBuilder builder = new ApplicationDataBuilder();
2082 builder.setIpTos(ipTOs);
2083 builder.setProtocol(protocol);
2084 builder.setLocalPortLow(new PortNumber(localPortLow));
2085 builder.setLocalPortHigh(new PortNumber(localPortHigh));
2086 builder.setRemotePortLow(new PortNumber(remotePortLow));
2087 builder.setRemotePortHigh(new PortNumber(remotePortHigh));
2088 builder.setAddress(new SimpleAddress(new IpAddress(new Ipv4Address(ipString))));
2090 EidBuilder eb = new EidBuilder();
2091 eb.setAddressType(ApplicationDataLcaf.class);
2092 eb.setVirtualNetworkId(null);
2093 eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
2094 .lisp.address.address.ApplicationDataBuilder().setApplicationData(builder.build()).build());
2095 Eid addressToSend = eb.build();
2097 MapReply reply = registerAddressAndQuery(addressToSend);
2099 Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
2101 assertEquals(ApplicationDataLcaf.class, receivedAddress.getAddressType());
2103 ApplicationData receivedApplicationDataAddress = (ApplicationData) receivedAddress.getAddress();
2104 assertEquals(protocol, receivedApplicationDataAddress.getApplicationData().getProtocol().intValue());
2105 assertEquals(ipTOs, receivedApplicationDataAddress.getApplicationData().getIpTos().intValue());
2106 assertEquals(localPortLow, receivedApplicationDataAddress.getApplicationData().getLocalPortLow().getValue()
2108 assertEquals(localPortHigh, receivedApplicationDataAddress.getApplicationData().getLocalPortHigh().getValue()
2110 assertEquals(remotePortLow, receivedApplicationDataAddress.getApplicationData().getRemotePortLow().getValue()
2112 assertEquals(remotePortHigh, receivedApplicationDataAddress.getApplicationData().getRemotePortHigh().getValue()
2115 SimpleAddress ipAddressReceived = receivedApplicationDataAddress.getApplicationData().getAddress();
2116 assertEquals(ipString, ipAddressReceived.getIpAddress().getIpv4Address().getValue());
2119 // ------------------- TimeOut Tests -----------
2121 public void mapRequestMapRegisterAndMapRequestTestTimeout() throws SocketTimeoutException {
2123 ConfigIni.getInstance().setSmrRetryCount(0);
2124 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
2125 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
2127 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
2128 mapRequestBuilder.setNonce((long) 4);
2129 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
2130 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
2131 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
2132 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
2133 mapRequestBuilder.getItrRloc().add(
2134 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
2136 sendMapRequest(mapRequestBuilder.build());
2137 MapReply mapReply = receiveMapReply();
2138 assertEquals(4, mapReply.getNonce().longValue());
2139 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
2141 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
2142 mapRegisterbuilder.setWantMapNotify(true);
2143 mapRegisterbuilder.setNonce((long) 8);
2145 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
2146 etlrBuilder.setEid(eid);
2147 etlrBuilder.setRecordTtl(254);
2149 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
2150 recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1"));
2151 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
2152 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
2153 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
2154 mapRegisterbuilder.getMappingRecordItem().add(
2155 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
2157 sendMapRegister(mapRegisterbuilder.build());
2158 MapNotify mapNotify = receiveMapNotify();
2159 assertEquals(8, mapNotify.getNonce().longValue());
2162 sendMapRequest(mapRequestBuilder.build());
2163 mapReply = receiveMapReply();
2164 assertEquals(4, mapReply.getNonce().longValue());
2165 assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord()
2166 .getLocatorRecord().get(0).getRloc());
2168 causeEntryToBeCleaned();
2169 sendMapRequest(mapRequestBuilder.build());
2170 mapReply = receiveMapReply();
2171 assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size());
2174 public void mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse() throws Exception {
2176 Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
2177 MapRequest mapRequest = createMapRequest(eid);
2179 testTTLBeforeRegister(mapRequest);
2181 registerForTTL(eid);
2183 testTTLAfterRegister(mapRequest);
2185 causeEntryToBeCleaned();
2186 testTTLAfterClean(mapRequest);
2188 //northboundAddKey();
2189 //testTTLAfterAutherize(mapRequest);
2193 private void timedOutMappingRecord() {
2195 mapService.setMappingMerge(true);
2196 // mapping expires after 1 second
2197 ConfigIni.getInstance().setRegistrationValiditySb(1000L);
2199 final Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32", new InstanceIdType(10L));
2200 final XtrId xtrId = new XtrId(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
2201 final SiteId siteId = new SiteId(new byte[]{1, 2, 3, 4, 5, 6, 7, 8});
2203 final LocatorRecord locatorRecord = new LocatorRecordBuilder()
2204 .setRloc(LispAddressUtil.asIpv4Rloc("1.1.1.1")).setLocatorId("locator-id").build();
2205 final MappingRecord mappingRecord = new MappingRecordBuilder()
2210 .setAction(Action.NoAction)
2211 .setAuthoritative(true)
2212 .setLocatorRecord(Lists.newArrayList()).build();
2213 mappingRecord.getLocatorRecord().add(locatorRecord);
2215 mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
2216 mapService.addMapping(MappingOrigin.Southbound, eid, siteId,
2217 new MappingData(mappingRecord, System.currentTimeMillis()));
2220 MappingRecord resultRecord = (MappingRecord) mapService.getMapping(MappingOrigin.Southbound, eid);
2221 assertNull(resultRecord);
2224 private void testTTLAfterClean(MapRequest mapRequest) throws SocketTimeoutException {
2226 sendMapRequest(mapRequest);
2227 mapReply = receiveMapReply();
2228 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
2231 private void causeEntryToBeCleaned() {
2232 // TODO XXX for the time being, to keep master and stable/lithium in sync, we need to remove the forceful
2233 // expiration of DAO entries. Once we're past this, we'll have to expose methods to setTimeUnit(TimeUnit)
2234 // and cleanOld() (expired) entries in IFlowMapping (and perhaps ILispDAO) and use them here.
2235 mapService.cleanCachedMappings();
2238 private void testTTLAfterRegister(MapRequest mapRequest) throws SocketTimeoutException {
2240 sendMapRequest(mapRequest);
2241 mapReply = receiveMapReply();
2242 assertEquals(LispAddressUtil.asIpv4Rloc("4.3.2.1"), mapReply.getMappingRecordItem().get(0).getMappingRecord()
2243 .getLocatorRecord().get(0).getRloc());
2244 assertCorrectMapReplyTTLAndAction(mapReply, 254, Action.NoAction);
2247 private void registerForTTL(Eid eid) throws SocketTimeoutException {
2248 MapRegister mapRegister = createMapRegister(eid);
2249 sendMapRegister(mapRegister);
2250 assertMapNotifyReceived();
2253 private void testTTLBeforeRegister(MapRequest mapRequest) throws SocketTimeoutException {
2255 sendMapRequest(mapRequest);
2256 mapReply = receiveMapReply();
2257 assertCorrectMapReplyTTLAndAction(mapReply, 15, Action.NativelyForward);
2260 private void testTTLAfterAutherize(MapRequest mapRequest) throws SocketTimeoutException {
2262 sendMapRequest(mapRequest);
2263 mapReply = receiveMapReply();
2264 assertCorrectMapReplyTTLAndAction(mapReply, 1, Action.NativelyForward);
2267 private void assertCorrectMapReplyTTLAndAction(MapReply mapReply, int expectedTTL, Action expectedAction) {
2268 assertEquals(expectedTTL, mapReply.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().intValue());
2269 assertEquals(expectedAction, mapReply.getMappingRecordItem().get(0).getMappingRecord().getAction());
2272 private MapRegister createMapRegister(Eid eid, Rloc rloc) {
2273 MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder();
2274 mapRegisterbuilder.setWantMapNotify(true);
2275 mapRegisterbuilder.setNonce((long) 8);
2276 mapRegisterbuilder.setKeyId((short) 0);
2277 MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
2278 etlrBuilder.setEid(eid);
2279 etlrBuilder.setRecordTtl(254);
2280 etlrBuilder.setAuthoritative(false);
2281 etlrBuilder.setAction(Action.NoAction);
2282 LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder();
2283 recordBuilder.setRloc(rloc);
2284 etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
2285 etlrBuilder.getLocatorRecord().add(recordBuilder.build());
2286 mapRegisterbuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
2287 mapRegisterbuilder.getMappingRecordItem().add(
2288 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
2289 MapRegister mapRegister = mapRegisterbuilder.build();
2293 private MapRegister createMapRegister(Eid eid) {
2294 return createMapRegister(eid, LispAddressUtil.asIpv4Rloc("4.3.2.1"));
2297 private MapRequest createMapRequest(Eid eid) {
2298 MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
2299 mapRequestBuilder.setNonce((long) 4);
2300 mapRequestBuilder.setPitr(false);
2301 mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build());
2302 mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
2303 mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
2304 mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
2305 mapRequestBuilder.getItrRloc().add(
2306 new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
2307 MapRequest mr = mapRequestBuilder.build();
2311 public void testSimpleNonProxy() throws SocketTimeoutException, SocketException {
2313 String rloc = "127.0.0.3";
2314 int port = LispMessage.PORT_NUM;
2315 Rloc ipRloc = LispAddressUtil.asIpv4Rloc(rloc);
2316 sendProxyMapRequest(rloc, port, ipRloc);
2320 public void testNonProxyOtherPort() throws SocketTimeoutException, SocketException {
2322 String rloc = "127.0.0.3";
2325 RlocBuilder rb = new RlocBuilder();
2326 rb.setAddressType(ApplicationDataLcaf.class);
2327 rb.setVirtualNetworkId(null);
2328 rb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
2329 .lisp.address.address.ApplicationDataBuilder()
2330 .setApplicationData(new ApplicationDataBuilder().setAddress(new SimpleAddress(new IpAddress(
2331 new Ipv4Address(rloc)))).setLocalPortLow(new PortNumber(port)).build()).build());
2332 Rloc adLcaf = rb.build();
2334 LOG.info("testNonProxyOtherPort:" + LispAddressStringifier.getString(adLcaf));
2335 sendProxyMapRequest(rloc, port, adLcaf);
2339 private class XtrRequestMappingListener implements OdlLispProtoListener {
2342 public void onGotMapReply(GotMapReply notification) {
2346 public void onAddMapping(AddMapping notification) {
2350 public void onXtrReplyMapping(XtrReplyMapping notification) {
2354 public void onRequestMapping(RequestMapping notification) {
2358 public void onGotMapNotify(GotMapNotify notification) {
2362 public void onXtrRequestMapping(XtrRequestMapping notification) {
2366 public void onMappingKeepAlive(MappingKeepAlive notification) {
2371 public void testRecievingNonProxyOnXtrPort() throws SocketTimeoutException, SocketException, Throwable {
2373 configLispPlugin.shouldListenOnXtrPort(true);
2374 notificationCalled = false;
2375 final String eid = "10.10.10.10/32";
2376 String rloc = "127.0.0.3";
2377 int port = LispMessage.XTR_PORT_NUM;
2379 RlocBuilder rb = new RlocBuilder();
2380 rb.setAddressType(ApplicationDataLcaf.class);
2381 rb.setVirtualNetworkId(null);
2382 rb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
2383 .lisp.address.address.ApplicationDataBuilder()
2384 .setApplicationData(new ApplicationDataBuilder().setAddress(new SimpleAddress(new IpAddress(
2385 new Ipv4Address(rloc)))).setLocalPortLow(new PortNumber(port)).build()).build());
2386 Rloc adLcaf = rb.build();
2388 final MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
2389 ((LispMappingService) lms).getNotificationService().registerNotificationListener(
2390 new XtrRequestMappingListener() {
2393 public void onXtrRequestMapping(XtrRequestMapping notification) {
2394 assertEquals(((Ipv4Prefix) mapRequest.getEidItem().get(0).getEid().getAddress())
2395 .getIpv4Prefix().getValue(), eid);
2396 notificationCalled = true;
2397 LOG.warn("notification arrived");
2400 sendMapRequest(mapRequest, port);
2401 for (int i = 0; i < MAX_NOTIFICATION_RETRYS; i++) {
2402 if (notificationCalled) {
2405 LOG.warn("notification hasn't arrived, sleeping...");
2410 fail("Notification hasn't arrived");
2414 private void sendProxyMapRequest(String rloc, int port, Rloc adLcaf) throws SocketTimeoutException,
2416 String eid = "10.1.0.1/32";
2417 MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf);
2418 sendMapRequest(mapRequest);
2419 DatagramSocket nonProxySocket = new DatagramSocket(new InetSocketAddress(rloc, port));
2420 MapRequest receivedMapRequest = receiveMapRequest(nonProxySocket);
2421 assertEquals(mapRequest.getNonce(), receivedMapRequest.getNonce());
2422 assertEquals(mapRequest.getSourceEid(), receivedMapRequest.getSourceEid());
2423 assertEquals(mapRequest.getItrRloc(), receivedMapRequest.getItrRloc());
2424 assertEquals(mapRequest.getEidItem(), receivedMapRequest.getEidItem());
2425 nonProxySocket.close();
2428 private MapRequest createNonProxyMapRequest(String eid, Rloc adLcaf) throws SocketTimeoutException {
2429 MapRegister mr = createMapRegister(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
2430 LocatorRecord record = new LocatorRecordBuilder(mr.getMappingRecordItem().get(0).getMappingRecord()
2431 .getLocatorRecord().get(0)).setRloc(adLcaf).build();
2432 mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().set(0, record);
2433 sendMapRegister(mr);
2434 assertMapNotifyReceived();
2435 MapRequest mapRequest = createMapRequest(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
2436 MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
2437 builder.setPitr(true);
2438 mapRequest = builder.build();
2442 private void assertMapNotifyReceived() throws SocketTimeoutException {
2446 private MapReply receiveMapReply() throws SocketTimeoutException {
2447 return receiveMapReply(socket, 1000);
2450 private MapRequest receiveMapRequest(DatagramSocket datagramSocket) throws SocketTimeoutException {
2451 return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket(
2452 datagramSocket, 30000).getData()), null);
2455 private MapNotify receiveMapNotify() throws SocketTimeoutException {
2456 return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
2459 private void sendMapRequest(MapRequest mapRequest) {
2460 sendMapRequest(mapRequest, LispMessage.PORT_NUM);
2463 private void sendMapRequest(MapRequest mapRequest, int port) {
2464 sendPacket(MapRequestSerializer.getInstance().serialize(mapRequest).array(), port);
2467 private void sendMapRegister(MapRegister mapRegister) {
2468 sendPacket(MapRegisterSerializer.getInstance().serialize(mapRegister).array());
2471 private void sendPacket(byte[] bytesToSend) {
2472 sendPacket(bytesToSend, LispMessage.PORT_NUM);
2475 private void sendPacket(byte[] bytesToSend, int port) {
2477 DatagramPacket packet = new DatagramPacket(bytesToSend, bytesToSend.length);
2478 initPacketAddress(packet, port);
2479 LOG.trace("Sending packet to LispPlugin on socket, port {}", port);
2480 socket.send(packet);
2481 } catch (Throwable t) {
2486 private DatagramPacket receivePacket() throws SocketTimeoutException {
2487 return receivePacket(6000);
2490 private DatagramPacket receivePacket(int timeout) throws SocketTimeoutException {
2491 return receivePacket(socket, timeout);
2494 private DatagramPacket receivePacket(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException {
2496 byte[] buffer = new byte[4096];
2497 DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
2498 LOG.trace("Waiting for packet from socket...");
2499 receivedSocket.setSoTimeout(timeout);
2500 receivedSocket.receive(receivePacket);
2501 LOG.trace("Received packet from socket!");
2502 return receivePacket;
2503 } catch (SocketTimeoutException ste) {
2505 } catch (Throwable t) {
2511 private MapReply receiveMapReply(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException {
2512 DatagramPacket packet;
2515 packet = receivePacket(receivedSocket, timeout);
2516 final ByteBuffer buff = ByteBuffer.wrap(packet.getData());
2517 final int type = ByteUtil.getUnsignedByte(buff, LispMessage.Pos.TYPE) >> 4;
2518 final Object lispType = MessageType.forValue(type);
2520 if (lispType == MessageType.MapReply) {
2521 return MapReplySerializer.getInstance().deserialize(buff);
2524 } catch (SocketTimeoutException ste) {
2529 private void sleepForSeconds(int seconds) {
2531 Thread.sleep(seconds*1000);
2532 } catch (InterruptedException e) {
2533 LOG.warn("Interrupted while sleeping", e);
2537 private void sleepForMilliseconds(long milliseconds) {
2539 Thread.sleep(milliseconds);
2540 } catch (InterruptedException e) {
2541 LOG.warn("Interrupted while sleeping", e);
2545 private void initPacketAddress(DatagramPacket packet, int port) throws UnknownHostException {
2546 packet.setAddress(InetAddress.getByName(lispBindAddress));
2547 packet.setPort(port);
2550 private DatagramSocket initSocket(DatagramSocket socket, int port) {
2551 for (int i=0; i < NUM_OF_ATTEMPTS_TO_CREATE_SOCKET; i++) {
2553 LOG.debug("Binding socket on {}:{}", ourAddress, port);
2554 return new DatagramSocket(new InetSocketAddress(ourAddress, port));
2555 } catch (SocketException e) {
2556 LOG.error("Can't initialize socket for {}:{}", ourAddress, port, e);
2563 private byte[] extractWSUdpByteArray(String wiresharkHex) {
2564 final int HEADER_LEN = 42;
2565 byte[] res = new byte[1000];
2566 String[] split = wiresharkHex.split(" ");
2568 for (String cur : split) {
2570 if (cur.length() == 2) {
2572 if (counter > HEADER_LEN) {
2573 res[counter - HEADER_LEN - 1] = (byte) Integer.parseInt(cur, 16);
2578 return Arrays.copyOf(res, counter - HEADER_LEN);
2581 private String stateToString(int state) {
2585 case Bundle.INSTALLED:
2587 case Bundle.RESOLVED:
2589 case Bundle.UNINSTALLED:
2590 return "UNINSTALLED";
2592 return "Not CONVERTED";
2596 private void areWeReady() throws InvalidSyntaxException {
2600 boolean debugit = false;
2601 Bundle b[] = bc.getBundles();
2602 for (Bundle element : b) {
2603 int state = element.getState();
2604 LOG.trace("Bundle[" + element.getBundleId() + "]:" + element.getSymbolicName() + ",v"
2605 + element.getVersion() + ", state:" + stateToString(state));
2606 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
2607 LOG.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
2610 // String host = element.getHeaders().get("FRAGMENT-HOST");
2611 // if (host != null) {
2612 // LOG.warn("Bundle " + element.getSymbolicName() +
2613 // " is a fragment which is part of: " + host);
2614 // LOG.warn("Required imports are: " +
2615 // element.getHeaders().get("IMPORT-PACKAGE"));
2619 // } catch (BundleException e) {
2620 // LOG.error("BundleException:", e);
2629 LOG.warn(("Do some debugging because some bundle is unresolved"));
2631 // assertNotNull(broker);
2633 configLispPlugin.setLispAddress(lispBindAddress);
2635 // Uncomment this code to Know which services were actually loaded to
2639 for (ServiceReference sr : bc.getAllServiceReferences(null, null)) {
2640 LOG.info(sr.getBundle().getSymbolicName());
2641 LOG.info(sr.toString());
2648 private void cleanUP() {
2650 mapService.cleanCachedMappings();
2651 configLispPlugin.shouldListenOnXtrPort(false);
2652 socket = initSocket(socket, LispMessage.PORT_NUM);
2656 private void restartSocket() {
2658 socket = initSocket(socket, LispMessage.PORT_NUM);