started non proxy CXTMAP-66: #close 80/4080/4
authorDavid Goldberg <david.goldberg@contextream.com>
Thu, 2 Jan 2014 19:12:07 +0000 (21:12 +0200)
committerDavid Goldberg <david.goldberg@contextream.com>
Fri, 3 Jan 2014 18:47:28 +0000 (20:47 +0200)
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
Change-Id: I186f4e85426d12e1f1ed5a39e045b1bdd23dccc1
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IMapRequestResultHandler.java [moved from mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IMapReplyHandler.java with 69% similarity]
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IMapResolverAsync.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/sbplugin/ILispSouthboundPlugin.java
mappingservice/implementation/pom.xml
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/LispNotificationHelper.java
mappingservice/integrationtest/pom.xml
mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/yangmodel/.gitignore

similarity index 69%
rename from mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IMapReplyHandler.java
rename to mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IMapRequestResultHandler.java
index 48c4b547b8841713cdc2654d27a4d0c6bcea033c..5c8b7f8d28e4aadb3ffd771eb6d4c33ecd5b5c7a 100644 (file)
@@ -7,11 +7,16 @@
  */
 package org.opendaylight.lispflowmapping.interfaces.lisp;
 
+import java.net.InetAddress;
+
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
 
 /**
  * An interface for dealing with a map reply message.
  */
-public interface IMapReplyHandler {
+public interface IMapRequestResultHandler {
     public void handleMapReply(MapReply mapReply);
+
+    public void handleNonProxyMapRequest(MapRequest mapRequest, InetAddress targetAddress);
 }
index 95cae25b6131cb93dbda95e49d55481aa42340c3..6fff6dfdae107f8d89abfd10de9396306aeda6c9 100644 (file)
@@ -13,5 +13,5 @@ import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
  * The async map resolver interface for dealing with async map request calls.
  */
 public interface IMapResolverAsync extends IGeneralMapResolver {
-    public void handleMapRequest(MapRequest request, IMapReplyHandler callback);
+    public void handleMapRequest(MapRequest request, IMapRequestResultHandler callback);
 }
index d71ffb68a33d9597219ff156e79f49419acc6103..8f3a5208c668ae6eb8a209c49c0bcb75118f8377 100644 (file)
@@ -12,6 +12,7 @@ import java.util.concurrent.Future;
 
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
@@ -38,4 +39,13 @@ public interface ILispSouthboundPlugin extends RpcService {
      */
     Future<RpcResult<java.lang.Void>> handleMapReply(MapReply mapReply, InetAddress targetAddress);
 
+    /**
+     * Handle a non proxy map request by sending it to the correct xTR.
+     * 
+     * @param mapRequest
+     * @param targetAddress
+     * @return
+     */
+    Future<RpcResult<java.lang.Void>> handleMapRequest(MapRequest mapRequest, InetAddress targetAddress);
+
 }
\ No newline at end of file
index bbb9aff3984f0b697d1c09eaeea34e366a320167..33e53ffd39bd5b27ee41782ceaf39bc2b026248b 100644 (file)
@@ -60,6 +60,7 @@
                                                        org.opendaylight.controller.sal.core,
                                                        org.apache.felix.dm,
                                                        org.apache.commons.lang3,
+                                                       org.apache.commons.lang3.tuple,
                                                        org.apache.commons.lang3.builder,
                                                        org.osgi.service.component,
                                                        org.slf4j,
index 1367810e7f65e043baacb0cda6a746838bdcd511..5befc148690cdf7d0e6e92c126939f47f4c14211 100644 (file)
@@ -11,6 +11,8 @@ package org.opendaylight.lispflowmapping.implementation;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
@@ -31,7 +33,7 @@ import org.opendaylight.lispflowmapping.interfaces.dao.IQueryAll;
 import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IMapReplyHandler;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServerAsync;
 import org.opendaylight.lispflowmapping.type.sbplugin.ILispSouthboundPlugin;
@@ -55,7 +57,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.net.InetAddresses;
 
 public class LispMappingService implements CommandProvider, IFlowMapping, BindingAwareConsumer, //
-        IMapReplyHandler, IMapNotifyHandler {
+        IMapRequestResultHandler, IMapNotifyHandler {
     protected static final Logger logger = LoggerFactory.getLogger(LispMappingService.class);
 
     private ILispDAO lispDao = null;
@@ -65,6 +67,7 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     private volatile boolean shouldAuthenticate;
     private ThreadLocal<MapReply> tlsMapReply = new ThreadLocal<MapReply>();
     private ThreadLocal<MapNotify> tlsMapNotify = new ThreadLocal<MapNotify>();
+    private ThreadLocal<Pair<MapRequest, InetAddress>> tlsMapRequest = new ThreadLocal<Pair<MapRequest, InetAddress>>();
 
     private ILispSouthboundPlugin lispSB = null;
 
@@ -187,10 +190,16 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
 
     public MapReply handleMapRequest(MapRequest request) {
         tlsMapReply.set(null);
+        tlsMapRequest.set(null);
         mapResolver.handleMapRequest(request, this);
         // After this invocation we assume that the thread local is filled with
         // the reply
-        return tlsMapReply.get();
+        if (tlsMapRequest.get() != null) {
+            getLispSB().handleMapRequest(tlsMapRequest.get().getLeft(), tlsMapRequest.get().getRight());
+            return null;
+        } else {
+            return tlsMapReply.get();
+        }
 
     }
 
@@ -280,4 +289,10 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     public void handleMapNotify(MapNotify notify) {
         tlsMapNotify.set(notify);
     }
+
+    @Override
+    public void handleNonProxyMapRequest(MapRequest mapRequest, InetAddress targetAddress) {
+        tlsMapRequest.set(new MutablePair<MapRequest, InetAddress>(mapRequest, targetAddress));
+    }
+
 }
index 603675740b1429086042d7357bf4b0092acd29d5..3f298707b859e8830d1c5075658e299d7828ad2a 100644 (file)
@@ -12,12 +12,13 @@ import java.util.ArrayList;
 import java.util.Map;
 
 import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil;
+import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper;
 import org.opendaylight.lispflowmapping.implementation.util.MaskUtil;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOC;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IMapReplyHandler;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord;
@@ -49,9 +50,22 @@ public class MapResolver implements IMapResolverAsync {
         this.shouldIterateMask = iterateMask;
     }
 
-    public void handleMapRequest(MapRequest request, IMapReplyHandler callback) {
+    public void handleMapRequest(MapRequest request, IMapRequestResultHandler callback) {
         if (dao == null) {
             logger.warn("handleMapRequest called while dao is uninitialized");
+            return;
+        }
+        if (request.isPitr()) {
+            if (request.getEidRecord().size() > 0) {
+                EidRecord eid = request.getEidRecord().get(0);
+                Map<String, ?> locators = getLocators(eid);
+                MappingServiceValue value = (MappingServiceValue) locators.get("value");
+                if (value.getRlocs() != null && value.getRlocs().size() > 0) {
+                    callback.handleNonProxyMapRequest(request,
+                            LispNotificationHelper.getInetAddressFromContainer(value.getRlocs().get(0).getRecord().getLispAddressContainer()));
+                }
+            }
+
         } else {
             MapReplyBuilder builder = new MapReplyBuilder();
             builder.setEchoNonceEnabled(false);
@@ -68,11 +82,7 @@ public class MapResolver implements IMapResolverAsync {
                 recordBuilder.setMaskLength(eid.getMask());
                 recordBuilder.setLispAddressContainer(eid.getLispAddressContainer());
                 recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
-                IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
-                Map<String, ?> locators = dao.get(key);
-                if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
-                    locators = findMaskLocators(key);
-                }
+                Map<String, ?> locators = getLocators(eid);
                 if (locators != null) {
                     MappingServiceValue value = (MappingServiceValue) locators.get("value");
 
@@ -94,6 +104,15 @@ public class MapResolver implements IMapResolverAsync {
         }
     }
 
+    private Map<String, ?> getLocators(EidRecord eid) {
+        IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
+        Map<String, ?> locators = dao.get(key);
+        if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
+            locators = findMaskLocators(key);
+        }
+        return locators;
+    }
+
     private Map<String, ?> findMaskLocators(IMappingServiceKey key) {
         int mask = key.getMask();
         while (mask > 0) {
index 9772303a530e5df8bc1ecba41f63783fc43dcd1e..0e5cb2f8b8647f8ee20705193d3f1cc6308dc175 100644 (file)
@@ -4,6 +4,8 @@ import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapregisternotification.MapRegister;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapregisternotification.MapRegisterBuilder;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequestnotification.MapRequest;
@@ -39,21 +41,31 @@ public class LispNotificationHelper {
     }
 
     public static InetAddress getInetAddressFromIpAddress(IpAddress ipAddress) {
-        InetAddress address = InetAddress.getLoopbackAddress();
-        if (ipAddress == null) {
-            return address;
-        }
-        if (ipAddress.getIpv4Address() != null) {
-            try {
-                address = Inet4Address.getByName(ipAddress.getIpv4Address().getValue());
-            } catch (UnknownHostException e) {
-            }
-        } else if (ipAddress.getIpv6Address() != null) {
-            try {
-                address = Inet4Address.getByName(ipAddress.getIpv6Address().getValue());
-            } catch (UnknownHostException e) {
+        InetAddress address = null;
+        if (ipAddress != null) {
+            if (ipAddress.getIpv4Address() != null) {
+                address = getAddressByName(ipAddress.getIpv4Address().getValue());
+            } else if (ipAddress.getIpv6Address() != null) {
+                address = getAddressByName(ipAddress.getIpv6Address().getValue());
             }
         }
+        if (address == null) {
+            address = InetAddress.getLoopbackAddress();
+        }
         return address;
     }
+
+    public static InetAddress getInetAddressFromContainer(LispAddressContainer container) {
+        Ipv4Address ipAddress = ((Ipv4) LispAFIConvertor.toAFI(container)).getIpv4Address();
+        return getAddressByName(ipAddress.getValue());
+    }
+
+    public static InetAddress getAddressByName(String IPAddress) {
+        try {
+            InetAddress address = InetAddress.getByName(IPAddress);
+            return address;
+        } catch (UnknownHostException e) {
+            return null;
+        }
+    }
 }
index 1e1234d2edcdf69bef7dfe06da4fd5c8125b08ea..3e2ea98104044c3fefc73021ce119879529f3455 100644 (file)
                        <artifactId>jersey-client</artifactId>
                        <version>${jersey.version}</version>
                </dependency>
+               <dependency>
+        <groupId>com.sun.jersey</groupId>
+        <artifactId>jersey-json</artifactId>
+        <version>${jersey.version}</version>
+      </dependency>
                <dependency>
                        <groupId>org.opendaylight.yangtools.thirdparty</groupId>
                        <artifactId>xtend-lib-osgi</artifactId>
index 465832522a41aa3a7eadbd5b9324eb7f05b4ab7c..48ed4cfa5c7c44712b2d201dc48fb89ce189445c 100644 (file)
@@ -397,8 +397,7 @@ public class MappingServiceIntegrationTest {
                 mavenBundle(JERSEY, "jersey-client").versionAsInProject(),
                 mavenBundle(JERSEY, "jersey-server").versionAsInProject().startLevel(2),
                 mavenBundle(JERSEY, "jersey-core").versionAsInProject().startLevel(2),
-                // mavenBundle(JERSEY,
-                // "jersey-json").versionAsInProject().startLevel(2),
+                mavenBundle(JERSEY, "jersey-json").versionAsInProject().startLevel(2),
                 mavenBundle("com.fasterxml.jackson.core", "jackson-annotations").versionAsInProject(),//
                 mavenBundle("com.fasterxml.jackson.core", "jackson-core").versionAsInProject(),//
                 mavenBundle("com.fasterxml.jackson.core", "jackson-databind").versionAsInProject(),//
@@ -690,6 +689,7 @@ public class MappingServiceIntegrationTest {
 
         // Retrieve the RLOC from the database
         MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
+        mapRequestBuilder.setPitr(false);
         mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
         mapRequestBuilder.getEidRecord().add(
                 new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
@@ -1420,10 +1420,38 @@ public class MappingServiceIntegrationTest {
         return mr;
     }
 
+    @Test
+    public void nonProxyTest() throws SocketTimeoutException, SocketException {
+        String eid = "10.0.0.1";
+        String rloc = "127.0.0.3";
+        MapRegister mr = createMapRegister(LispAFIConvertor.asIPAfiAddress(eid));
+        LocatorRecord record = new LocatorRecordBuilder(mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)).setLispAddressContainer(
+                LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(rloc))).build();
+        mr.getEidToLocatorRecord().get(0).getLocatorRecord().set(0, record);
+        sendMapRegister(mr);
+        receiveMapNotify();
+        MapRequest mapRequest = createMapRequest(LispAFIConvertor.asIPAfiAddress(eid));
+        MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
+        builder.setPitr(true);
+        mapRequest = builder.build();
+        sendMapRequest(mapRequest);
+        socket = new DatagramSocket(new InetSocketAddress(rloc, LispMessage.PORT_NUM));
+        MapRequest recievedMapRequest = receiveMapRequest();
+        assertEquals(mapRequest.getNonce(), recievedMapRequest.getNonce());
+        assertEquals(mapRequest.getSourceEid(), recievedMapRequest.getSourceEid());
+        assertEquals(mapRequest.getItrRloc(), recievedMapRequest.getItrRloc());
+        assertEquals(mapRequest.getEidRecord(), recievedMapRequest.getEidRecord());
+
+    }
+
     private MapReply receiveMapReply() throws SocketTimeoutException {
         return MapReplySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
     }
 
+    private MapRequest receiveMapRequest() throws SocketTimeoutException {
+        return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
+    }
+
     private MapNotify receiveMapNotify() throws SocketTimeoutException {
         return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
     }
index e37e2ff0eff80e8f38a8f29e6e40dba584625ff1..f4c8760170ff0dc4b53585b24f20f2df3f2b5360 100644 (file)
@@ -25,11 +25,13 @@ import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage;
 import org.opendaylight.lispflowmapping.implementation.serializer.MapNotifySerializer;
 import org.opendaylight.lispflowmapping.implementation.serializer.MapReplySerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRequestSerializer;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundService;
 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispPlugin;
 import org.opendaylight.lispflowmapping.type.sbplugin.ILispSouthboundPlugin;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -45,6 +47,7 @@ public class LispSouthboundPlugin extends AbstractBindingAwareProvider implement
     private volatile DatagramSocket socket = null;
     private final String MAP_NOTIFY = "MapNotify";
     private final String MAP_REPlY = "MapReply";
+    private final String MAP_REQUEST = "MapRequest";
     private volatile String bindingAddress = null;
     private volatile boolean stillRunning = false;
     private volatile boolean alreadyInit = false;
@@ -211,6 +214,17 @@ public class LispSouthboundPlugin extends AbstractBindingAwareProvider implement
         return null;
     }
 
+    public Future<RpcResult<Void>> handleMapRequest(MapRequest mapRequest, InetAddress address) {
+        logger.trace("handleMapRequest called!!");
+        if (mapRequest != null) {
+            ByteBuffer outBuffer = MapRequestSerializer.getInstance().serialize(mapRequest);
+            handleSerializedLispBuffer(address, outBuffer, MAP_REQUEST);
+        } else {
+            logger.debug("MapRequest was null");
+        }
+        return null;
+    }
+
     public void setLispAddress(String address) {
         synchronized (startLock) {
             if (bindingAddress != null && bindingAddress.equals(address)) {
index a26e08ff5fc72ab1976a950f9f4e983f806eb2f7..a670d1c7beb24dcfe39d5d329930e3e3b93ddd42 100644 (file)
@@ -1,2 +1,3 @@
 /target
 /META-INF
+/target