X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=integrationtest%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Flispflowmapping%2Fintegrationtest%2FMappingServiceIntegrationTest.java;h=2c1c8d8069d523b15fa7719d339d7cd58a164610;hb=refs%2Fchanges%2F25%2F62925%2F6;hp=70394d73dc23a68fcaa108623b2c397513966318;hpb=9fd133aa7fd59627960e8941b329901fcf4a494d;p=lispflowmapping.git diff --git a/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java b/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java index 70394d73d..2c1c8d806 100644 --- a/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java +++ b/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java @@ -33,9 +33,7 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfi import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.common.net.InetAddresses; import java.io.IOException; -import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -60,15 +58,14 @@ import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys; import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber; import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping; import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService; -import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer; import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer; import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer; import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer; import org.opendaylight.lispflowmapping.lisp.type.LispMessage; import org.opendaylight.lispflowmapping.lisp.type.MappingData; -import org.opendaylight.lispflowmapping.lisp.util.ByteUtil; import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier; import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil; +import org.opendaylight.lispflowmapping.lisp.util.MappingRecordUtil; import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; @@ -102,7 +99,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi; -import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4BinaryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify; @@ -115,8 +111,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.Ma import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.OdlLispProtoListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.RequestMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrReplyMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrRequestMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid; @@ -158,11 +152,6 @@ import org.slf4j.LoggerFactory; public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { private static final Logger LOG = LoggerFactory.getLogger(MappingServiceIntegrationTest.class); - /** - * Defines how many attempt to create instance of DatagramSocket will be done before giving up. - */ - private static final int NUM_OF_ATTEMPTS_TO_CREATE_SOCKET = 2; - private byte[] mapRequestPacket; private byte[] mapRegisterPacketWithNotify; private byte[] mapRegisterPacketWithoutNotify; @@ -174,7 +163,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { public static final String ODL = "org.opendaylight.controller"; public static final String YANG = "org.opendaylight.yangtools"; - private static final int MULTI_SITE_SLEEP_TIME = 1; + private static final int MULTI_SITE_SLEEP_TIME = 2; private static final int MAX_NOTIFICATION_RETRYS = 20; private static final MappingAuthkey NULL_AUTH_KEY = new MappingAuthkeyBuilder().setKeyType(0).build(); @@ -193,7 +182,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { public MavenUrlReference getFeatureRepo() { return maven() .groupId("org.opendaylight.lispflowmapping") - .artifactId("features4-lispflowmapping") + .artifactId("features-lispflowmapping") .classifier("features") .type("xml") .versionAsInProject(); @@ -208,7 +197,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { public Option getLoggingOption() { Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG, "log4j.logger.org.opendaylight.lispflowmapping", - LogLevel.DEBUG.name()); + LogLevel.TRACE.name()); option = composite(option, super.getLoggingOption()); return option; } @@ -234,8 +223,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { mapService.setMappingMerge(false); ConfigIni.getInstance().setSmrRetryCount(1); - locatorEid = LispAddressUtil.asIpv4Rloc("4.3.2.1"); - socket = initSocket(socket, LispMessage.PORT_NUM); + socket = MappingServiceIntegrationTestUtil.initSocket(LispMessage.PORT_NUM); // SRC: 127.0.0.1:58560 to 127.0.0.1:4342 // LISP(Type = 8 - Encapsulated) @@ -249,13 +237,13 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { // Nonce: 0x3d8d2acd39c8d608 // ITR-RLOC AFI=1 Address=192.168.136.10 // Record 1: 153.16.254.1/32 - mapRequestPacket = extractWSUdpByteArray(new String("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " // + mapRequestPacket = extractWSUdpByteArray("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " + "0010 00 58 00 00 40 00 40 11 3c 93 7f 00 00 01 7f 00 " + "0020 00 01 e4 c0 10 f6 00 44 fe 57 80 00 00 00 45 00 " + "0030 00 3c d4 31 00 00 ff 11 56 f3 7f 00 00 02 99 10 " + "0040 fe 01 dd b4 10 f6 00 28 ef 3a 10 00 00 01 3d 8d " - + "0050 2a cd 39 c8 d6 08 00 01 01 02 03 04 00 01 7f 00 00 02 00 20 " // - + "0060 00 01 99 10 fe 01")); + + "0050 2a cd 39 c8 d6 08 00 01 01 02 03 04 00 01 7f 00 00 02 00 20 " + + "0060 00 01 99 10 fe 01"); // IP: 192.168.136.10 -> 128.223.156.35 // UDP: 49289 -> 4342 @@ -272,14 +260,14 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { // 255/0 // - mapRegisterPacketWithAuthenticationAndMapNotify = extractWSUdpByteArray(new String( - "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " // + mapRegisterPacketWithAuthenticationAndMapNotify = extractWSUdpByteArray( + "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df " + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 " + "0030 00 00 00 00 00 00 00 01 00 14 0e a4 c6 d8 a4 06 " + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 " - + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // - + "0060 ff 00 00 05 00 01 c0 a8 88 0a")); + + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " + + "0060 ff 00 00 05 00 01 c0 a8 88 0a"); // IP: 192.168.136.10 -> 128.223.156.35 // UDP: 49289 -> 4342 @@ -295,14 +283,14 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { // 255/0 // - mapRegisterPacketWithNotify = extractWSUdpByteArray(new String( - "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " // + mapRegisterPacketWithNotify = extractWSUdpByteArray( + "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df " + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 " + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 " + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 " - + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // - + "0060 ff 00 00 05 00 01 c0 a8 88 0a")); + + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " + + "0060 ff 00 00 05 00 01 c0 a8 88 0a"); // IP: 192.168.136.10 -> 128.223.156.35 // UDP: 49289 -> 4342 @@ -318,14 +306,14 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { // 255/0 // - mapRegisterPacketWithoutNotify = extractWSUdpByteArray(new String( - "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " // + mapRegisterPacketWithoutNotify = extractWSUdpByteArray( + "0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " + "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df " + "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 00 01 00 00 " + "0030 00 00 00 00 00 07 00 00 00 14 0e a4 c6 d8 a4 06 " + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 " - + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // - + "0060 ff 00 00 05 00 01 c0 a8 88 0a")); + + "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " + + "0060 ff 00 00 05 00 01 c0 a8 88 0a"); } @Inject @@ -410,7 +398,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { @Test public void testSmr() throws Exception { registerQueryRegisterWithSmr(); - testRepeatedSmr(); + //testRepeatedSmr(); } @Test @@ -420,7 +408,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { } @Test - public void testNegativePrefix_gapIntersection() throws UnknownHostException { + public void testNbAndSbNegativePrefix() throws UnknownHostException { insertMappings(); testGapIntersection(); @@ -428,6 +416,18 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { testMultipleMappings(); } + @Test + public void testExplicitSbNegativePrefixes() { + // https://bugs.opendaylight.org/show_bug.cgi?id=8679 + testNegativePrefix(); + + // https://bugs.opendaylight.org/show_bug.cgi?id=9023 + testPositiveMappingRemoval(); + + // https://bugs.opendaylight.org/show_bug.cgi?id=9037 + testPositivePrefixOverlappingNegativePrefix(); + } + private void testRepeatedSmr() throws SocketTimeoutException, UnknownHostException { cleanUP(); long timeout = ConfigIni.getInstance().getSmrTimeout(); @@ -435,6 +435,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { final InstanceIdType iid = new InstanceIdType(1L); final Eid eid1 = LispAddressUtil.asIpv4Eid("1.1.1.1", 1L); + final Eid subscriberEid = LispAddressUtil.asIpv4Eid("2.2.2.2", 1L); final int expectedSmrs1 = 2; final int expectedSmrs2 = 3; @@ -445,8 +446,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { /* add subscribers */ final String subscriberSrcRloc1 = "127.0.0.3"; final String subscriberSrcRloc2 = "127.0.0.4"; - final Set subscriberSet1 = Sets.newHashSet(newSubscriber(eid1, subscriberSrcRloc1), - newSubscriber(eid1, subscriberSrcRloc2)); + final Set subscriberSet1 = Sets.newHashSet(newSubscriber(subscriberEid, subscriberSrcRloc1), + newSubscriber(subscriberEid, subscriberSrcRloc2)); mapService.addData(MappingOrigin.Southbound, eid1, SubKeys.SUBSCRIBERS, subscriberSet1); final SocketReader reader1 = startSocketReader(subscriberSrcRloc1, 15000); @@ -462,6 +463,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { final List requests1 = processSmrPackets(reader1, subscriberSrcRloc1, expectedSmrs1); final MapReply mapReply1 = lms.handleMapRequest( new MapRequestBuilder(requests1.get(0)) + .setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build()) .setItrRloc(Lists.newArrayList(new ItrRlocBuilder() .setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc1)).build())) .setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build())) @@ -473,6 +475,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { final List requests2 = processSmrPackets(reader2, subscriberSrcRloc2, expectedSmrs2); final MapReply mapReply2 = lms.handleMapRequest( new MapRequestBuilder(requests2.get(0)) + .setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build()) .setItrRloc(Lists.newArrayList(new ItrRlocBuilder() .setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc2)).build())) .setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build())) @@ -513,8 +516,11 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { final List requests = Lists.newArrayList(); byte[][] buffers = reader.getBuffers(expectedSmrs); for (byte[] buf : buffers) { - MapRequest request = MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(buf), inetAddress); - requests.add(request); + ByteBuffer packet = ByteBuffer.wrap(buf); + if (MappingServiceIntegrationTestUtil.checkType(packet, MessageType.MapRequest)) { + MapRequest request = MapRequestSerializer.getInstance().deserialize(packet, inetAddress); + requests.add(request); + } } return requests; } @@ -524,11 +530,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { } private static Subscriber newSubscriber(Eid srcEid, String srcRlocIp) { - final byte[] addressBinary = InetAddresses.forString(srcRlocIp).getAddress(); final int timeout = 5; - final Rloc srcRloc = new RlocBuilder().setAddress(new Ipv4BinaryBuilder() - .setIpv4Binary(new Ipv4AddressBinary(addressBinary)).build()).build(); - + final Rloc srcRloc = LispAddressUtil.asIpv4Rloc(srcRlocIp); return new Subscriber(srcRloc, srcEid, timeout); } @@ -576,14 +579,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { * Tests a negative mapping from an intersection of gaps in northbound and southbound. */ private void testGapIntersection() throws UnknownHostException { - final InstanceIdType iid = new InstanceIdType(1L); - // request an Eid from a gap between mappings - final MapRequest mapRequest = new MapRequestBuilder().setSmrInvoked(false).setEidItem(Lists.newArrayList( - new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixBinaryEid("1.1.127.10/32", iid)) - .build())) - .build(); - final MapReply mapReply = lms.handleMapRequest(mapRequest); + final MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "1.1.127.10/32")); // expected negative mapping final Address resultNegMapping = new Ipv4PrefixBinaryBuilder() @@ -593,55 +590,144 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { .getAddress()); } + private void testNegativePrefix() { + // First, we test with one mapping in NB and one mapping in SB + cleanUP(); + + insertNBMappings(1L, "192.0.2.0/24"); + insertSBMappings(1L, "10.0.0.0/32"); + + restartSocket(); + sleepForSeconds(2); + + MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "11.1.1.1/32")); + Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "11.0.0.0/8"); + assertEquals(expectedNegativePrefix, mapReply.getMappingRecordItem().get(0).getMappingRecord().getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mapReply.getMappingRecordItem().get(0).getMappingRecord())); + + // Second, we test with two mappings in NB only + cleanUP(); + + insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16"); + + restartSocket(); + sleepForSeconds(2); + + mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32")); + expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16"); + MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + } + + private void testPositiveMappingRemoval() { + cleanUP(); + + insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16"); + insertSBMappings(1L, "192.168.32.0/19"); + + MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32")); + Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/19"); + MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + + mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.64.1/32")); + expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.64.0/18"); + mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + + mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.128.1/32")); + expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.128.0/17"); + mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + + printMapCacheState(); + + mapService.removeMapping(MappingOrigin.Southbound, LispAddressUtil.asIpv4PrefixBinaryEid( + 1L, "192.168.32.0/19")); + + printMapCacheState(); + + mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.32.1/32")); + expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16"); + mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + + printMapCacheState(); + } + + private void testPositivePrefixOverlappingNegativePrefix() { + cleanUP(); + + insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16"); + + MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32")); + Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16"); + MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + + insertNBMappings(1L, "192.168.1.0/24"); + + mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32")); + expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/24"); + mr = mapReply.getMappingRecordItem().get(0).getMappingRecord(); + assertEquals(expectedNegativePrefix, mr.getEid()); + assertTrue(MappingRecordUtil.isNegativeMapping(mr)); + } + private void insertMappings() { cleanUP(); mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB); - final InstanceIdType iid = new InstanceIdType(1L); - final String prefixNbLeft = "1.2.0.0/16"; - final String prefixNbRight = "1.1.128.0/17"; - final String prefixSbLeft = "1.1.32.0/19"; - final String prefixSbRight = "1.0.0.0/8"; + insertNBMappings(1L, "1.2.0.0/16", "1.1.128.0/17"); + insertSBMappings(1L, "1.1.32.0/19", "1.0.0.0/8"); - final MappingRecord mapRecordNbLeft = newMappingRecord(prefixNbLeft, iid); - final MappingRecord mapRecordNbRight = newMappingRecord(prefixNbRight, iid); - final MappingRecord mapRecordSbLeft = newMappingRecord(prefixSbLeft, iid); - final MappingRecord mapRecordSbRight = newMappingRecord(prefixSbRight, iid); + restartSocket(); + sleepForSeconds(2); + } - /* set auth */ - final Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iid); + private void insertNBMappings(long iid, String ... prefixes) { + LOG.debug("Adding Northbound mappings for prefixes: {}", prefixes); + final InstanceIdType iiType = new InstanceIdType(iid); + for (String prefix : prefixes) { + MappingRecord record = newMappingRecord(prefix, iiType); + mapService.addMapping(MappingOrigin.Northbound, record.getEid(), null, new MappingData(record)); + } + sleepForMilliseconds(25); + printMapCacheState(); + } + + private void insertSBMappings(long iid, String ... prefixes) { + LOG.debug("Adding Southbound mappings for prefixes: {}", prefixes); + final InstanceIdType iiType = new InstanceIdType(iid); + Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iiType); mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); - mapService.addMapping(MappingOrigin.Northbound, mapRecordNbLeft.getEid(), null, - new MappingData(mapRecordNbLeft)); - mapService.addMapping(MappingOrigin.Northbound, mapRecordNbRight.getEid(), null, - new MappingData(mapRecordNbRight)); - mapService.addMapping(MappingOrigin.Southbound, mapRecordSbLeft.getEid(), null, - new MappingData(mapRecordSbLeft, System.currentTimeMillis())); - mapService.addMapping(MappingOrigin.Southbound, mapRecordSbRight.getEid(), null, - new MappingData(mapRecordSbRight, System.currentTimeMillis())); + for (String prefix : prefixes) { + MappingRecord record = newMappingRecord(prefix, iiType); + mapService.addMapping(MappingOrigin.Southbound, record.getEid(), null, + new MappingData(record, System.currentTimeMillis())); + } + printMapCacheState(); + } - restartSocket(); - sleepForSeconds(2); + private void printMapCacheState() { + LOG.debug("Map-cache state:\n{}", mapService.prettyPrintMappings()); } - /** - * Creates a new MappingRecord object. - * - * @param prefix The Eid prefix - * @param iid VNI - * @return new MappingRecord object - */ private MappingRecord newMappingRecord(String prefix, InstanceIdType iid) { final Eid prefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(prefix, iid); - return new MappingRecordBuilder() - .setEid(prefixBinary) - .setLocatorRecord(Lists.newArrayList(new LocatorRecordBuilder() - .setRloc(LispAddressUtil.asIpv4Rloc("2.2.2.2")) - .setLocatorId("loc_id") - .setPriority((short) 1).build())) - .setTimestamp(System.currentTimeMillis()) - .setRecordTtl(1440).build(); + return MappingServiceIntegrationTestUtil.getDefaultMappingRecordBuilder(prefixBinary).build(); + } + + private MapRequest newMapRequest(long iid, String prefix) { + final Eid prefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(prefix, new InstanceIdType(iid)); + return MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(prefixBinary).build(); } /** @@ -668,7 +754,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4); //TEST CASE 2 - //following action should trigger generatting of SMR messages: + //following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.1/32 multiSiteScenario.storeNorthMappingSrcDst(SITE_A, SITE_C); @@ -679,7 +765,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4); //TEST CASE 3 - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.1/32 // 3) 192.0.1.5/32 @@ -692,76 +778,87 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { multiSiteScenario.assertPingWorks(SITE_D4, 5, SITE_C, 4); //TEST CASE 4 - // following action should trigger generatting of SMR messages: - // 1) 192.0.4.5/32 + // following action should trigger generating of SMR messages: + // 1) 192.0.2.5/32 + // 2) 192.0.1.1/32 + // 3) 192.0.1.5/32 + // 4) 192.0.4.5/32 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C_RLOC_10); sleepForSeconds(MULTI_SITE_SLEEP_TIME); - multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D4.getHost(5)); + multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1), + SITE_A.getHost(5), SITE_D4.getHost(5)); //way of testing ping - get RLOC for mapping src-dst and compare it with awaited value doesn't test //that ping won't be successfull multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4); //TEST CASE 5 - // following action should trigger generatting of SMR messages: - // 1) 192.0.4.5/32 - // 2) 192.0.2.5/32 + // following action should trigger generating of SMR messages: + // 1) 192.0.2.5/32 + // 2) 192.0.1.1/32 + // 3) 192.0.1.5/32 + // 4) 192.0.4.5/32 multiSiteScenario.storeNorthMappingNegative(SITE_C, Action.Drop); sleepForSeconds(MULTI_SITE_SLEEP_TIME); - multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D4.getHost(5), SITE_B.getHost(5)); + multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B.getHost(5), SITE_A.getHost(1), + SITE_A.getHost(5), SITE_D4.getHost(5)); multiSiteScenario.assertPingFails(SITE_D4, 5, SITE_C, 4); //TEST CASE 6 multiSiteScenario.assertPingFails(SITE_D5, 5, SITE_C, 3); //TEST CASE 7 - multiSiteScenario.deleteNorthMapingSrcDst(SITE_A, SITE_C); - sleepForSeconds(MULTI_SITE_SLEEP_TIME); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.4.5/32 // 2) 192.0.2.5/32 // 3) 192.0.5.5/32 + // 4) 192.0.1.5/32 + // 5) 192.0.1.1/32 + multiSiteScenario.deleteNorthMapingSrcDst(SITE_A, SITE_C); + sleepForSeconds(MULTI_SITE_SLEEP_TIME); multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5), - SITE_B.getHost(5)); + SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5)); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.4.5/32 // 2) 192.0.2.5/32 // 3) 192.0.5.5/32 + // 4) 192.0.1.5/32 + // 5) 192.0.1.1/32 multiSiteScenario.storeNorthMappingSrcDst(SITE_B, SITE_C); sleepForSeconds(MULTI_SITE_SLEEP_TIME); multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5), - SITE_B.getHost(5)); + SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5)); multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4); multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4); multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4); //TEST CASE 8 - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.4.5/32 // 2) 192.0.2.5/32 // 3) 192.0.5.5/32 - // 4) 192.0.1.1/32 + // 4) 192.0.1.5/32 + // 5) 192.0.1.1/32 multiSiteScenario.deleteNorthMapingSrcDst(SITE_B, SITE_C); sleepForSeconds(MULTI_SITE_SLEEP_TIME); multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5), - SITE_B.getHost(5), - SITE_A.getHost(1)); + SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5)); multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4); multiSiteScenario.assertPingFails(SITE_B, 5, SITE_C, 4); multiSiteScenario.assertPingFails(SITE_A, 1, SITE_C, 4); //TEST CASE 9 - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.4.5/32 // 2) 192.0.2.5/32 // 3) 192.0.5.5/32 - // 4) 192.0.1.1/32 + // 4) 192.0.1.5/32 + // 5) 192.0.1.1/32 multiSiteScenario.deleteNorthMappingNegative(SITE_C); sleepForSeconds(MULTI_SITE_SLEEP_TIME); multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_D5.getHost(5), SITE_D4.getHost(5), - SITE_B.getHost(5), - SITE_A.getHost(1)); + SITE_B.getHost(5), SITE_A.getHost(1), SITE_A.getHost(5)); multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_B, 4); multiSiteScenario.assertPingWorks(SITE_B, 5, SITE_C, 4); multiSiteScenario.assertPingWorks(SITE_A, 5, SITE_C, 4); @@ -796,14 +893,14 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { multiSiteScenario.assertPingWorks(SITE_B_SB, 5, SITE_C_WP_50_2_SB, 4, SITE_D_WP_50_2_SB); //TEST CASE 2 - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB); sleepForSeconds(MULTI_SITE_SLEEP_TIME); multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5)); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.storeNorthMappingNegative(SITE_C_SB, Action.Drop); @@ -815,7 +912,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { //TEST CASE 3 - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.storeNorthMappingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB); @@ -826,7 +923,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { //TEST CASE 4 multiSiteScenario.storeNorthMappingSrcDst(SITE_B_SB, SITE_C_WP_50_2_SB, SITE_D_WP_50_2_SB); sleepForSeconds(MULTI_SITE_SLEEP_TIME); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5)); @@ -835,7 +932,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { //TEST CASE 5 multiSiteScenario.deleteSouthboundMappings(SITE_D_DELETE_SB); sleepForSeconds(MULTI_SITE_SLEEP_TIME); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5)); @@ -845,7 +942,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { //TEST CASE 6 multiSiteScenario.deleteNorthMapingSrcDst(SITE_A_SB, SITE_C_WP_50_2_SB); sleepForSeconds(MULTI_SITE_SLEEP_TIME); - // following action should trigger generatting of SMR messages: + // following action should trigger generating of SMR messages: // 1) 192.0.2.5/32 // 2) 192.0.1.5/32 multiSiteScenario.checkSMR(socketReader, SITE_C.getEidPrefix(), SITE_B_SB.getHost(5), SITE_A_SB.getHost(5)); @@ -868,10 +965,10 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { if (socket != null) { socket.close(); } - socket = initSocket(socket, 56756); + socket = MappingServiceIntegrationTestUtil.initSocket(56756); sendPacket(mapRequestPacket); - ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData()); + ByteBuffer readBuf = receivePacket(); MapReply reply = MapReplySerializer.getInstance().deserialize(readBuf); assertEquals(4435248268955932168L, reply.getNonce().longValue()); @@ -894,8 +991,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { MapReply mapReply = registerAddressAndQuery(eid); assertEquals(4, mapReply.getNonce().longValue()); - assertEquals(locatorEid, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0) - .getRloc()); + assertEquals(MappingServiceIntegrationTestUtil.DEFAULT_IPV4_RLOC, + mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc()); } @@ -919,40 +1016,21 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); sleepForSeconds(1); - MapRequestBuilder mapRequestBuilder = new MapRequestBuilder(); - mapRequestBuilder.setNonce((long) 4); - mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build()); - mapRequestBuilder.setEidItem(new ArrayList()); - mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build()); - mapRequestBuilder.setItrRloc(new ArrayList()); - mapRequestBuilder.getItrRloc().add( - new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build()); - sendMapRequest(mapRequestBuilder.build()); + MapRequest mapRequest = MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build(); + sendMapRequest(mapRequest); MapReply mapReply = receiveMapReply(); assertEquals(4, mapReply.getNonce().longValue()); assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size()); - MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder(); - mapRegisterbuilder.setWantMapNotify(true); - mapRegisterbuilder.setNonce((long) 8); - MappingRecordBuilder etlrBuilder = new MappingRecordBuilder(); - etlrBuilder.setEid(eid); - etlrBuilder.setRecordTtl(254); - LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder(); - recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1")); - etlrBuilder.setLocatorRecord(new ArrayList()); - etlrBuilder.getLocatorRecord().add(recordBuilder.build()); - mapRegisterbuilder.setMappingRecordItem(new ArrayList()); - mapRegisterbuilder.getMappingRecordItem().add( - new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build()); - sendMapRegister(mapRegisterbuilder.build()); + MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build(); + sendMapRegister(mapRegister); MapNotify mapNotify = receiveMapNotify(); assertEquals(8, mapNotify.getNonce().longValue()); sleepForSeconds(1); - sendMapRequest(mapRequestBuilder.build()); + sendMapRequest(mapRequest); mapReply = receiveMapReply(); assertEquals(4, mapReply.getNonce().longValue()); - assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord() - .getLocatorRecord().get(0).getRloc()); + assertEquals(MappingServiceIntegrationTestUtil.DEFAULT_IPV4_RLOC, + mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc()); } @@ -1069,8 +1147,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { mapRegisterPacketWithoutNotify[mapRegisterPacketWithoutNotify.length - 1] += 1; sendPacket(mapRegisterPacketWithoutNotify); - ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData()); - MapRequest smr = MapRequestSerializer.getInstance().deserialize(readBuf, null); + MapRequest smr = receiveMapRequest(); assertTrue(smr.isSmr()); Eid sourceEid = smr.getSourceEid().getEid(); assertTrue(LispAddressUtil.asIpv4Eid("153.16.254.1").equals(sourceEid)); @@ -1649,33 +1726,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { private void registerAddress(Eid eid) throws SocketTimeoutException { mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); sleepForSeconds(1); - MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder(); - mapRegisterBuilder.setWantMapNotify(true); - mapRegisterBuilder.setKeyId((short) 0); - mapRegisterBuilder.setAuthenticationData(new byte[0]); - mapRegisterBuilder.setNonce((long) 8); - mapRegisterBuilder.setProxyMapReply(false); - MappingRecordBuilder etlrBuilder = new MappingRecordBuilder(); - etlrBuilder.setEid(eid); - etlrBuilder.setRecordTtl(254); - etlrBuilder.setAction(Action.NoAction); - etlrBuilder.setAuthoritative(false); - etlrBuilder.setMapVersion((short) 0); - LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder(); - recordBuilder.setLocalLocator(false); - recordBuilder.setRlocProbed(false); - recordBuilder.setRouted(true); - recordBuilder.setMulticastPriority((short) 0); - recordBuilder.setMulticastWeight((short) 0); - recordBuilder.setPriority((short) 0); - recordBuilder.setWeight((short) 0); - recordBuilder.setRloc(locatorEid); - etlrBuilder.setLocatorRecord(new ArrayList()); - etlrBuilder.getLocatorRecord().add(recordBuilder.build()); - mapRegisterBuilder.setMappingRecordItem(new ArrayList()); - mapRegisterBuilder.getMappingRecordItem().add( - new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build()); - sendMapRegister(mapRegisterBuilder.build()); + MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build(); + sendMapRegister(mapRegister); MapNotify mapNotify = receiveMapNotify(); assertEquals(8, mapNotify.getNonce().longValue()); } @@ -1709,52 +1761,16 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { private MapReply registerAddressAndQuery(Eid eid) throws SocketTimeoutException { mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); sleepForSeconds(1); - MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder(); - mapRegisterBuilder.setWantMapNotify(true); - mapRegisterBuilder.setKeyId((short) 0); - mapRegisterBuilder.setAuthenticationData(new byte[0]); - mapRegisterBuilder.setNonce((long) 8); - mapRegisterBuilder.setProxyMapReply(false); - MappingRecordBuilder etlrBuilder = new MappingRecordBuilder(); - etlrBuilder.setEid(eid); - etlrBuilder.setRecordTtl(254); - etlrBuilder.setAction(Action.NoAction); - etlrBuilder.setAuthoritative(false); - etlrBuilder.setMapVersion((short) 0); - LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder(); - recordBuilder.setLocalLocator(false); - recordBuilder.setRlocProbed(false); - recordBuilder.setRouted(true); - recordBuilder.setMulticastPriority((short) 0); - recordBuilder.setMulticastWeight((short) 0); - recordBuilder.setPriority((short) 0); - recordBuilder.setWeight((short) 0); - recordBuilder.setRloc(locatorEid); - etlrBuilder.setLocatorRecord(new ArrayList()); - etlrBuilder.getLocatorRecord().add(recordBuilder.build()); - mapRegisterBuilder.setMappingRecordItem(new ArrayList()); - mapRegisterBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord( - etlrBuilder.build()).build()); - sendMapRegister(mapRegisterBuilder.build()); + MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build(); + LOG.trace("Sending Map-Register via socket: {}", mapRegister); + sendMapRegister(mapRegister); MapNotify mapNotify = receiveMapNotify(); + LOG.trace("Received Map-Notify via socket: {}", mapNotify); assertEquals(8, mapNotify.getNonce().longValue()); // wait for the notifications to propagate sleepForSeconds(1); - MapRequestBuilder mapRequestBuilder = new MapRequestBuilder(); - mapRequestBuilder.setNonce((long) 4); - mapRequestBuilder.setEidItem(new ArrayList()); - mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build()); - mapRequestBuilder.setItrRloc(new ArrayList()); - mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build()); - mapRequestBuilder.getItrRloc().add( - new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build()); - mapRequestBuilder.setAuthoritative(false); - mapRequestBuilder.setMapDataPresent(false); - mapRequestBuilder.setPitr(false); - mapRequestBuilder.setProbe(false); - mapRequestBuilder.setSmr(false); - mapRequestBuilder.setSmrInvoked(false); - sendMapRequest(mapRequestBuilder.build()); + MapRequest mapRequest = MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build(); + sendMapRequest(mapRequest); return receiveMapReply(); } @@ -2022,49 +2038,27 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"); mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); sleepForSeconds(1); - MapRequestBuilder mapRequestBuilder = new MapRequestBuilder(); - mapRequestBuilder.setNonce((long) 4); - mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build()); - mapRequestBuilder.setEidItem(new ArrayList()); - mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build()); - mapRequestBuilder.setItrRloc(new ArrayList()); - mapRequestBuilder.getItrRloc().add( - new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build()); - sendMapRequest(mapRequestBuilder.build()); + MapRequest mapRequest = MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build(); + sendMapRequest(mapRequest); MapReply mapReply = receiveMapReply(); assertEquals(4, mapReply.getNonce().longValue()); assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size()); - MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder(); - mapRegisterbuilder.setWantMapNotify(true); - mapRegisterbuilder.setNonce((long) 8); - - MappingRecordBuilder etlrBuilder = new MappingRecordBuilder(); - etlrBuilder.setEid(eid); - etlrBuilder.setRecordTtl(254); - - LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder(); - recordBuilder.setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1")); - etlrBuilder.setLocatorRecord(new ArrayList()); - etlrBuilder.getLocatorRecord().add(recordBuilder.build()); - mapRegisterbuilder.setMappingRecordItem(new ArrayList()); - mapRegisterbuilder.getMappingRecordItem().add( - new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build()); - - sendMapRegister(mapRegisterbuilder.build()); + MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build(); + sendMapRegister(mapRegister); MapNotify mapNotify = receiveMapNotify(); assertEquals(8, mapNotify.getNonce().longValue()); sleepForSeconds(1); - sendMapRequest(mapRequestBuilder.build()); + sendMapRequest(mapRequest); mapReply = receiveMapReply(); assertEquals(4, mapReply.getNonce().longValue()); - assertEquals(recordBuilder.getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord() - .getLocatorRecord().get(0).getRloc()); + assertEquals(MappingServiceIntegrationTestUtil.DEFAULT_IPV4_RLOC, + mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc()); causeEntryToBeCleaned(); - sendMapRequest(mapRequestBuilder.build()); + sendMapRequest(mapRequest); mapReply = receiveMapReply(); assertEquals(0, mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().size()); } @@ -2095,23 +2089,11 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { ConfigIni.getInstance().setRegistrationValiditySb(1000L); final Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32", new InstanceIdType(10L)); - final XtrId xtrId = new XtrId(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); - final SiteId siteId = new SiteId(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}); - - final LocatorRecord locatorRecord = new LocatorRecordBuilder() - .setRloc(LispAddressUtil.asIpv4Rloc("1.1.1.1")).setLocatorId("locator-id").build(); - final MappingRecord mappingRecord = new MappingRecordBuilder() - .setEid(eid) - .setSiteId(siteId) - .setRecordTtl(1000) - .setXtrId(xtrId) - .setAction(Action.NoAction) - .setAuthoritative(true) - .setLocatorRecord(Lists.newArrayList()).build(); - mappingRecord.getLocatorRecord().add(locatorRecord); + final MappingRecord mappingRecord = MappingServiceIntegrationTestUtil.getDefaultMappingRecordBuilder(eid) + .setRecordTtl(1000).build(); mapService.addAuthenticationKey(eid, NULL_AUTH_KEY); - mapService.addMapping(MappingOrigin.Southbound, eid, siteId, + mapService.addMapping(MappingOrigin.Southbound, eid, MappingServiceIntegrationTestUtil.DEFAULT_SITE_ID, new MappingData(mappingRecord, System.currentTimeMillis())); sleepForSeconds(2); @@ -2168,42 +2150,15 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { } private MapRegister createMapRegister(Eid eid, Rloc rloc) { - MapRegisterBuilder mapRegisterbuilder = new MapRegisterBuilder(); - mapRegisterbuilder.setWantMapNotify(true); - mapRegisterbuilder.setNonce((long) 8); - mapRegisterbuilder.setKeyId((short) 0); - MappingRecordBuilder etlrBuilder = new MappingRecordBuilder(); - etlrBuilder.setEid(eid); - etlrBuilder.setRecordTtl(254); - etlrBuilder.setAuthoritative(false); - etlrBuilder.setAction(Action.NoAction); - LocatorRecordBuilder recordBuilder = new LocatorRecordBuilder(); - recordBuilder.setRloc(rloc); - etlrBuilder.setLocatorRecord(new ArrayList()); - etlrBuilder.getLocatorRecord().add(recordBuilder.build()); - mapRegisterbuilder.setMappingRecordItem(new ArrayList()); - mapRegisterbuilder.getMappingRecordItem().add( - new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build()); - MapRegister mapRegister = mapRegisterbuilder.build(); - return mapRegister; + return MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid, rloc).build(); } private MapRegister createMapRegister(Eid eid) { - return createMapRegister(eid, LispAddressUtil.asIpv4Rloc("4.3.2.1")); + return MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build(); } private MapRequest createMapRequest(Eid eid) { - MapRequestBuilder mapRequestBuilder = new MapRequestBuilder(); - mapRequestBuilder.setNonce((long) 4); - mapRequestBuilder.setPitr(false); - mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.getNoAddressEid()).build()); - mapRequestBuilder.setEidItem(new ArrayList()); - mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build()); - mapRequestBuilder.setItrRloc(new ArrayList()); - mapRequestBuilder.getItrRloc().add( - new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build()); - MapRequest mr = mapRequestBuilder.build(); - return mr; + return MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build(); } public void testSimpleNonProxy() throws SocketTimeoutException, SocketException { @@ -2315,7 +2270,7 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf); sendMapRequest(mapRequest); DatagramSocket nonProxySocket = new DatagramSocket(new InetSocketAddress(rloc, port)); - MapRequest receivedMapRequest = receiveMapRequest(nonProxySocket); + MapRequest receivedMapRequest = MappingServiceIntegrationTestUtil.receiveMapRequest(nonProxySocket); assertEquals(mapRequest.getNonce(), receivedMapRequest.getNonce()); assertEquals(mapRequest.getSourceEid(), receivedMapRequest.getSourceEid()); assertEquals(mapRequest.getItrRloc(), receivedMapRequest.getItrRloc()); @@ -2337,23 +2292,6 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { return mapRequest; } - private void assertMapNotifyReceived() throws SocketTimeoutException { - receiveMapNotify(); - } - - private MapReply receiveMapReply() throws SocketTimeoutException { - return receiveMapReply(socket, 1000); - } - - private MapRequest receiveMapRequest(DatagramSocket datagramSocket) throws SocketTimeoutException { - return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket( - datagramSocket, 30000).getData()), null); - } - - private MapNotify receiveMapNotify() throws SocketTimeoutException { - return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData())); - } - private void sendMapRequest(MapRequest mapRequest) { sendMapRequest(mapRequest, LispMessage.PORT_NUM); } @@ -2371,57 +2309,30 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { } private void sendPacket(byte[] bytesToSend, int port) { - try { - DatagramPacket packet = new DatagramPacket(bytesToSend, bytesToSend.length); - initPacketAddress(packet, port); - LOG.trace("Sending packet to LispPlugin on socket, port {}", port); - socket.send(packet); - } catch (Throwable t) { - fail(); - } + MappingServiceIntegrationTestUtil.sendPacket(socket, bytesToSend, port); } - private DatagramPacket receivePacket() throws SocketTimeoutException { - return receivePacket(6000); + private ByteBuffer receivePacket() throws SocketTimeoutException { + return MappingServiceIntegrationTestUtil.receivePacket(socket); } + + private ByteBuffer receivePacket(int timeout) throws SocketTimeoutException { + return MappingServiceIntegrationTestUtil.receivePacket(socket, timeout); } - private DatagramPacket receivePacket(int timeout) throws SocketTimeoutException { - return receivePacket(socket, timeout); + private void assertMapNotifyReceived() throws SocketTimeoutException { + MappingServiceIntegrationTestUtil.receiveMapNotify(socket); } - private DatagramPacket receivePacket(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException { - try { - byte[] buffer = new byte[4096]; - DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length); - LOG.trace("Waiting for packet from socket..."); - receivedSocket.setSoTimeout(timeout); - receivedSocket.receive(receivePacket); - LOG.trace("Received packet from socket!"); - return receivePacket; - } catch (SocketTimeoutException ste) { - throw ste; - } catch (Throwable t) { - fail(); - return null; - } + private MapRequest receiveMapRequest() throws SocketTimeoutException { + return MappingServiceIntegrationTestUtil.receiveMapRequest(socket); } - private MapReply receiveMapReply(DatagramSocket receivedSocket, int timeout) throws SocketTimeoutException { - DatagramPacket packet; - try { - while (true) { - packet = receivePacket(receivedSocket, timeout); - final ByteBuffer buff = ByteBuffer.wrap(packet.getData()); - final int type = ByteUtil.getUnsignedByte(buff, LispMessage.Pos.TYPE) >> 4; - final Object lispType = MessageType.forValue(type); - - if (lispType == MessageType.MapReply) { - return MapReplySerializer.getInstance().deserialize(buff); - } - } - } catch (SocketTimeoutException ste) { - throw ste; - } + private MapReply receiveMapReply() throws SocketTimeoutException { + return MappingServiceIntegrationTestUtil.receiveMapReply(socket); + } + + private MapNotify receiveMapNotify() throws SocketTimeoutException { + return MappingServiceIntegrationTestUtil.receiveMapNotify(socket); } private void sleepForSeconds(int seconds) { @@ -2440,24 +2351,6 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { } } - private void initPacketAddress(DatagramPacket packet, int port) throws UnknownHostException { - packet.setAddress(InetAddress.getByName(lispBindAddress)); - packet.setPort(port); - } - - private DatagramSocket initSocket(DatagramSocket socket, int port) { - for (int i=0; i < NUM_OF_ATTEMPTS_TO_CREATE_SOCKET; i++) { - try { - LOG.debug("Binding socket on {}:{}", ourAddress, port); - return new DatagramSocket(new InetSocketAddress(ourAddress, port)); - } catch (SocketException e) { - LOG.error("Can't initialize socket for {}:{}", ourAddress, port, e); - } - } - fail(); - return null; - } - private byte[] extractWSUdpByteArray(String wiresharkHex) { final int HEADER_LEN = 42; byte[] res = new byte[1000]; @@ -2547,13 +2440,13 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase { after(); mapService.cleanCachedMappings(); configLispPlugin.shouldListenOnXtrPort(false); - socket = initSocket(socket, LispMessage.PORT_NUM); + socket = MappingServiceIntegrationTestUtil.initSocket(LispMessage.PORT_NUM); } private void restartSocket() { after(); - socket = initSocket(socket, LispMessage.PORT_NUM); + socket = MappingServiceIntegrationTestUtil.initSocket(LispMessage.PORT_NUM); } }