Bump upstreams
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / LispMappingService.java
index f3bb5d7680a71e8d77e2c815ceac9962471bb503..aeaa3f4d12beae6b19317168643ef5f2ac8e565a 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.lispflowmapping.implementation;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -32,10 +31,10 @@ import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
-import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.mdsal.binding.api.RpcService;
+import org.opendaylight.mdsal.singleton.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.api.ServiceGroupIdentifier;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 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;
@@ -58,9 +57,11 @@ 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.rloc.container.Rloc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLispSbService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotify;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.osgi.service.component.annotations.Activate;
@@ -75,40 +76,38 @@ import org.slf4j.LoggerFactory;
         immediate = true, property = "type=default")
 public class LispMappingService implements IFlowMapping, IMapRequestResultHandler,
         IMapNotifyHandler, AutoCloseable, ClusterSingletonService {
-    private static final String LISPFLOWMAPPING_ENTITY_NAME = "lispflowmapping";
-    private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create(
-            LISPFLOWMAPPING_ENTITY_NAME);
+    private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER =
+        new ServiceGroupIdentifier("lispflowmapping");
 
     private static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class);
 
     private volatile boolean smr = ConfigIni.getInstance().smrIsSet();
     private volatile String elpPolicy = ConfigIni.getInstance().getElpPolicy();
 
+    // These are non-final for testing
     private ThreadLocal<MapReply> tlsMapReply = new ThreadLocal<>();
     private ThreadLocal<Pair<MapNotify, List<TransportAddress>>> tlsMapNotify = new ThreadLocal<>();
     private ThreadLocal<Pair<MapRequest, TransportAddress>> tlsMapRequest = new ThreadLocal<>();
-
     private IMapResolverAsync mapResolver;
     private MapServer mapServer;
+    private SendMapRequest sendMapRequest;
+    private SendMapReply sendMapReply;
+    private SendMapNotify sendMapNotify;
 
     private final IMappingService mapService;
-    private final OdlLispSbService lispSB;
-    private final ClusterSingletonServiceProvider clusterSingletonService;
     private final NotificationService notificationService;
-    private final Registration rpcRegistration;
     private final Registration listenerRegistration;
     private final Registration cssRegistration;
 
     @Inject
     @Activate
     public LispMappingService(@Reference final IMappingService mappingService,
-            @Reference final OdlLispSbService odlLispService,
             @Reference final ClusterSingletonServiceProvider clusterSingletonService,
-            @Reference final RpcProviderService rpcProviderService,
-            @Reference final NotificationService notificationService) {
+            @Reference final RpcService rpcService, @Reference final NotificationService notificationService) {
         this.mapService = mappingService;
-        this.lispSB = odlLispService;
-        this.clusterSingletonService = clusterSingletonService;
+        sendMapRequest = rpcService.getRpc(SendMapRequest.class);
+        sendMapReply = rpcService.getRpc(SendMapReply.class);
+        sendMapNotify = rpcService.getRpc(SendMapNotify.class);
         this.notificationService = notificationService;
 
         // initialize
@@ -120,8 +119,6 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
                 new CompositeListener.Component<>(XtrRequestMapping.class, this::onXtrRequestMapping),
                 new CompositeListener.Component<>(XtrReplyMapping.class, this::onXtrReplyMapping),
                 new CompositeListener.Component<>(MappingKeepAlive.class, this::onMappingKeepAlive))));
-        rpcRegistration = rpcProviderService.registerRpcImplementation(OdlLispSbService.class, lispSB);
-
         mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
         mapServer = new MapServer(mapService, smr, this, notificationService);
         cssRegistration = clusterSingletonService.registerClusterSingletonService(this);
@@ -164,7 +161,7 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
             SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder();
             smrib.setMapRequest(new MapRequestBuilder(tlsMapRequest.get().getLeft()).build());
             smrib.setTransportAddress(tlsMapRequest.get().getRight());
-            getLispSB().sendMapRequest(smrib.build());
+            sendMapRequest.invoke(smrib.build());
             return null;
         } else {
             return tlsMapReply.get();
@@ -193,7 +190,7 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         SendMapNotifyInputBuilder smnib = new SendMapNotifyInputBuilder();
         smnib.setMapNotify(new MapNotifyBuilder(mapNotify).build());
         smnib.setTransportAddress(address);
-        getLispSB().sendMapNotify(smnib.build());
+        sendMapNotify.invoke(smnib.build());
     }
 
     @VisibleForTesting
@@ -224,7 +221,7 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
             SendMapReplyInputBuilder smrib = new SendMapReplyInputBuilder();
             smrib.setMapReply(new MapReplyBuilder(mapReply).build());
             smrib.setTransportAddress(mapRequestNotification.getTransportAddress());
-            getLispSB().sendMapReply(smrib.build());
+            sendMapReply.invoke(smrib.build());
         } else {
             LOG.debug("handleMapRequest: Got null MapReply");
         }
@@ -263,10 +260,6 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         }
     }
 
-    private OdlLispSbService getLispSB() {
-        return lispSB;
-    }
-
     @Override
     public void handleMapReply(MapReply reply) {
         tlsMapReply.set(reply);
@@ -288,8 +281,7 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder();
         smrib.setMapRequest(new MapRequestBuilder(smrMapRequest).build());
         smrib.setTransportAddress(LispNotificationHelper.getTransportAddressFromRloc(subscriber));
-        getLispSB().sendMapRequest(smrib.build());
-
+        sendMapRequest.invoke(smrib.build());
     }
 
     @Override
@@ -312,8 +304,6 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
     public void close() throws Exception {
         destroy();
         cssRegistration.close();
-        clusterSingletonService.close();
-        rpcRegistration.close();
         listenerRegistration.close();
     }