Merge branch 'release-1.0.X' into develop
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / LispMappingService.java
index 0eec064d494f436750f2bd0c9526bb03473b7d16..99d2f17d8d4a1d2f798a52ec85b664b8b1e79cf0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -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;
 
@@ -89,7 +92,7 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     }
 
     void setBindingAwareBroker(BindingAwareBroker bindingAwareBroker) {
-        logger.debug("BindingAwareBroker set!");
+        logger.trace("BindingAwareBroker set!");
         BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
         bindingAwareBroker.registerConsumer(this, bundleContext);
     }
@@ -105,20 +108,20 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     }
 
     void setLispDao(ILispDAO dao) {
-        logger.debug("LispDAO set in LispMappingService");
+        logger.trace("LispDAO set in LispMappingService");
         basicInit(dao);
-        logger.debug("Registering LispIpv4Address");
+        logger.trace("Registering LispIpv4Address");
         lispDao.register(LispIpv4AddressInMemoryConverter.class);
-        logger.debug("Registering LispIpv6Address");
+        logger.trace("Registering LispIpv6Address");
         lispDao.register(LispIpv6AddressInMemoryConverter.class);
-        logger.debug("Registering MappingServiceKey");
+        logger.trace("Registering MappingServiceKey");
         lispDao.register(MappingServiceKeyConvertor.class);
-        logger.debug("Registering MappingServiceNoMaskKey");
+        logger.trace("Registering MappingServiceNoMaskKey");
         lispDao.register(MappingServiceNoMaskKeyConvertor.class);
     }
 
     void unsetLispDao(ILispDAO dao) {
-        logger.debug("LispDAO was unset in LispMappingService");
+        logger.trace("LispDAO was unset in LispMappingService");
         mapServer = null;
         mapResolver = null;
         lispDao = null;
@@ -139,7 +142,7 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     }
 
     public void destroy() {
-        logger.debug("LISP (RFC6830) Mapping Service is destroyed!");
+        logger.info("LISP (RFC6830) Mapping Service is destroyed!");
         mapResolver = null;
         mapServer = 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();
+        }
 
     }
 
@@ -235,7 +244,7 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin
     }
 
     public void onSessionInitialized(ConsumerContext session) {
-        logger.debug("Lisp Consumer session initialized!");
+        logger.info("Lisp Consumer session initialized!");
         NotificationService notificationService = session.getSALService(NotificationService.class);
         // notificationService.registerNotificationListener(LispNotification.class,
         // this);
@@ -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));
+    }
+
 }