updated mapping service
[lispflowmapping.git] / mappingservice / integrationtest / src / test / java / org / opendaylight / lispflowmapping / integrationtest / MappingServiceIntegrationTest.java
index 913a9938b88bbe9711e084a776c1c619db02f691..8c1bce1c648dfd7bf94cee3555f955ea86851aca 100644 (file)
@@ -57,7 +57,8 @@ import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
 import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispPlugin;
+import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.EidToLocatorRecord.Action;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LcafApplicationDataAddress;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LcafKeyValueAddress;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LcafListAddress;
@@ -76,7 +77,6 @@ import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.XtrRequestMapping;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecordBuilder;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord.Action;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecordBuilder;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lcafkeyvalueaddress.KeyBuilder;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lcafkeyvalueaddress.ValueBuilder;
@@ -124,8 +124,6 @@ import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import aQute.lib.osgi.Constants;
-
 @RunWith(PaxExam.class)
 public class MappingServiceIntegrationTest {
 
@@ -135,7 +133,7 @@ public class MappingServiceIntegrationTest {
     private byte[] mapRequestPacket;
     private byte[] mapRegisterPacketWithNotify;
     private byte[] mapRegisterPacketWithoutNotify;
-    private IConfigLispPlugin configLispPlugin;
+    private IConfigLispSouthboundPlugin configLispPlugin;
     String lispBindAddress = "127.0.0.1";
     String ourAddress = "127.0.0.2";
     private LispAFIAddress locatorEid;
@@ -166,7 +164,7 @@ public class MappingServiceIntegrationTest {
 
         // SRC: 127.0.0.1:58560 to 127.0.0.1:4342
         // LISP(Type = 8 - Encapsulated)
-        // IP: 192.168.136.10 -> 1.2.3.4
+        // IP: 192.168.136.10 -> 153.16.254.1
         // UDP: 56756
         // LISP(Type = 1 Map-Request
         // Record Count: 1
@@ -175,14 +173,14 @@ public class MappingServiceIntegrationTest {
         // Source EID not present
         // Nonce: 0x3d8d2acd39c8d608
         // ITR-RLOC AFI=1 Address=192.168.136.10
-        // Record 1: 1.2.3.4/32
+        // 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 " //
                 + "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 38 d4 31 00 00 ff 11 56 f3 7f 00 00 02 01 02 "
-                + "0040   03 04 dd b4 10 f6 00 24 ef 3a 10 00 00 01 3d 8d "
+                + "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 01 02 03 04"));
+                + "0060   00 01 99 10 fe 01"));
 
         // IP: 192.168.136.10 -> 128.223.156.35
         // UDP: 49289 -> 4342
@@ -323,10 +321,23 @@ public class MappingServiceIntegrationTest {
         testRecievingNonProxyOnXtrPort();
     }
 
+    @Test
+    public void testSmr() throws Exception {
+        registerQueryRegisterWithSmr();
+    }
+
     // ------------------------------- Simple Tests ---------------------------
 
     public void mapRequestSimple() throws SocketTimeoutException {
         cleanUP();
+
+        // This Map-Request is sent from a source port different from 4342
+        // We close and bind the socket on the correct port
+        if (socket != null) {
+            socket.close();
+        }
+        socket = initSocket(socket, 56756);
+
         sendPacket(mapRequestPacket);
         ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
         MapReply reply = MapReplySerializer.getInstance().deserialize(readBuf);
@@ -464,13 +475,13 @@ public class MappingServiceIntegrationTest {
     private MapReply sendMapRegisterTwiceWithDiffrentValues(LispAFIAddress eid, LispAFIAddress rloc1, LispAFIAddress rloc2)
             throws SocketTimeoutException {
         MapRegister mb = createMapRegister(eid, rloc1);
-        MapNotify mapNotify = lms.handleMapRegister(mb);
+        MapNotify mapNotify = lms.handleMapRegister(mb, false);
         MapRequest mr = createMapRequest(eid);
         MapReply mapReply = lms.handleMapRequest(mr);
         assertEquals(mb.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer(), mapReply.getEidToLocatorRecord().get(0)
                 .getLocatorRecord().get(0).getLispAddressContainer());
         mb = createMapRegister(eid, rloc2);
-        mapNotify = lms.handleMapRegister(mb);
+        mapNotify = lms.handleMapRegister(mb, false);
         assertEquals(8, mapNotify.getNonce().longValue());
         mr = createMapRequest(eid);
         sendMapRequest(mr);
@@ -500,6 +511,22 @@ public class MappingServiceIntegrationTest {
         }
     }
 
+    public void registerQueryRegisterWithSmr() throws SocketTimeoutException {
+        cleanUP();
+        lms.setShouldUseSmr(true);
+
+        sendPacket(mapRegisterPacketWithoutNotify);
+        sendPacket(mapRequestPacket);
+        mapRegisterPacketWithoutNotify[mapRegisterPacketWithoutNotify.length - 1] += 1;
+        sendPacket(mapRegisterPacketWithoutNotify);
+
+        ByteBuffer readBuf = ByteBuffer.wrap(receivePacket().getData());
+        MapRequest smr = MapRequestSerializer.getInstance().deserialize(readBuf);
+        assertTrue(smr.isSmr());
+        LispAddressContainer smrEid = smr.getEidRecord().get(0).getLispAddressContainer();
+        assertTrue(LispAFIConvertor.toContainer(asIPAfiAddress("153.16.254.1")).equals(smrEid));
+    }
+
     // --------------------- Northbound Tests ---------------------------
 
     private void northboundAddKey() throws Exception {
@@ -639,7 +666,7 @@ public class MappingServiceIntegrationTest {
         etlr.getLocatorRecord().add(record.build());
         mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
         mapRegister.getEidToLocatorRecord().add(etlr.build());
-        lms.handleMapRegister(mapRegister.build());
+        lms.handleMapRegister(mapRegister.build(), false);
 
         // Get mapping using NB interface. No IID used
         URL url = createGetMappingIPv4URL(0, eid, mask);
@@ -689,7 +716,7 @@ public class MappingServiceIntegrationTest {
         etlr.getLocatorRecord().add(record.build());
         mapRegister.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
         mapRegister.getEidToLocatorRecord().add(etlr.build());
-        lms.handleMapRegister(mapRegister.build());
+        lms.handleMapRegister(mapRegister.build(), false);
 
         // Get mapping using NB interface. No IID used
         URL url = createGetMappingSourceDestURL(address1.getAfi(), address1.getIpv4Address().getValue(), mask1, address2.getIpv4Address().getValue(),
@@ -1414,7 +1441,7 @@ public class MappingServiceIntegrationTest {
 
     public void testRecievingNonProxyOnXtrPort() throws SocketTimeoutException, SocketException, Throwable {
         cleanUP();
-        lms.shouldListenOnXtrPort(true);
+        configLispPlugin.shouldListenOnXtrPort(true);
         notificationCalled = false;
         final String eid = "10.10.10.10";
         String rloc = "127.0.0.3";
@@ -1513,7 +1540,7 @@ public class MappingServiceIntegrationTest {
         try {
             DatagramPacket packet = new DatagramPacket(bytesToSend, bytesToSend.length);
             initPacketAddress(packet, port);
-            logger.trace("Sending MapRegister to LispPlugin on socket");
+            logger.trace("Sending packet to LispPlugin on socket, port {}", port);
             socket.send(packet);
         } catch (Throwable t) {
             fail();
@@ -1605,18 +1632,20 @@ public class MappingServiceIntegrationTest {
             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
                 logger.trace("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
 
-                try {
-                    String host = element.getHeaders().get(Constants.FRAGMENT_HOST);
-                    if (host != null) {
-                        logger.warn("Bundle " + element.getSymbolicName() + " is a fragment which is part of: " + host);
-                        logger.warn("Required imports are: " + element.getHeaders().get(Constants.IMPORT_PACKAGE));
-                    } else {
-                        element.start();
-                    }
-                } catch (BundleException e) {
-                    logger.error("BundleException:", e);
-                    fail();
-                }
+                // try {
+                // String host = element.getHeaders().get("FRAGMENT-HOST");
+                // if (host != null) {
+                // logger.warn("Bundle " + element.getSymbolicName() +
+                // " is a fragment which is part of: " + host);
+                // logger.warn("Required imports are: " +
+                // element.getHeaders().get("IMPORT-PACKAGE"));
+                // } else {
+                // element.start();
+                // }
+                // } catch (BundleException e) {
+                // logger.error("BundleException:", e);
+                // fail();
+                // }
 
                 debugit = true;
 
@@ -1652,12 +1681,12 @@ public class MappingServiceIntegrationTest {
         }
 
         assertNotNull(ILispDAO.class.getName() + " service wasn't found in bundle context ", this.clusterService);
-        r = bc.getServiceReference(IConfigLispPlugin.class.getName());
+        r = bc.getServiceReference(IConfigLispSouthboundPlugin.class.getName());
         if (r != null) {
-            this.configLispPlugin = (IConfigLispPlugin) bc.getService(r);
+            this.configLispPlugin = (IConfigLispSouthboundPlugin) bc.getService(r);
         }
 
-        assertNotNull(IConfigLispPlugin.class.getName() + " service wasn't found in bundle context ", this.configLispPlugin);
+        assertNotNull(IConfigLispSouthboundPlugin.class.getName() + " service wasn't found in bundle context ", this.configLispPlugin);
         configLispPlugin.setLispAddress(lispBindAddress);
 
         // Uncomment this code to Know which services were actually loaded to
@@ -1694,7 +1723,7 @@ public class MappingServiceIntegrationTest {
     private void cleanUP() {
         after();
         lms.clean();
-        lms.shouldListenOnXtrPort(false);
+        configLispPlugin.shouldListenOnXtrPort(false);
         socket = initSocket(socket, LispMessage.PORT_NUM);
 
     }