X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=mappingservice%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Flispflowmapping%2Fimplementation%2FLispMappingService.java;h=9e7bbd5de73b74b3a0a213ab62b36dd18f4c0aa6;hb=1af4913ccb1fbe8db5079c7b11911a0363e87798;hp=b870dc43ca9cf7e2e2b275c15aec03ac717dcd6e;hpb=ddc54dbce094b9bd986cba19c4cf75b0786ee361;p=lispflowmapping.git diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java index b870dc43c..9e7bbd5de 100644 --- a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java @@ -8,26 +8,28 @@ package org.opendaylight.lispflowmapping.implementation; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import java.util.List; - import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; import org.opendaylight.controller.md.sal.binding.api.NotificationService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.lispflowmapping.implementation.config.ConfigIni; import org.opendaylight.lispflowmapping.implementation.lisp.MapResolver; import org.opendaylight.lispflowmapping.implementation.lisp.MapServer; import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper; -import org.opendaylight.lispflowmapping.lisp.type.LispMessage; import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping; import org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler; 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.interfaces.mappingservice.IMappingService; +import org.opendaylight.lispflowmapping.lisp.type.LispMessage; import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier; +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.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; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply; @@ -53,16 +55,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLi 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.SendMapReplyInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class LispMappingService implements IFlowMapping, BindingAwareProvider, IMapRequestResultHandler, - IMapNotifyHandler, OdlLispProtoListener, AutoCloseable { - protected static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class); +public class LispMappingService implements IFlowMapping, IMapRequestResultHandler, + IMapNotifyHandler, OdlLispProtoListener, AutoCloseable, ClusterSingletonService { + public static final String LISPFLOWMAPPING_ENTITY_NAME = "lispflowmapping"; + public static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create( + LISPFLOWMAPPING_ENTITY_NAME); - private volatile boolean shouldAuthenticate = true; + + protected static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class); + private final ClusterSingletonServiceProvider clusterSingletonService; private volatile boolean smr = ConfigIni.getInstance().smrIsSet(); private volatile String elpPolicy = ConfigIni.getInstance().getElpPolicy(); @@ -73,30 +78,22 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I private ThreadLocal> tlsMapRequest = new ThreadLocal>(); - private OdlLispSbService lispSB = null; + private final OdlLispSbService lispSB; private IMapResolverAsync mapResolver; private IMapServerAsync mapServer; - private IMappingService mapService; - private NotificationService notificationService; - private BindingAwareBroker broker; - private ProviderContext session; - - public LispMappingService() { - LOG.debug("LispMappingService Module constructed!"); - } - - public void setBindingAwareBroker(BindingAwareBroker broker) { - this.broker = broker; - } + private final IMappingService mapService; + private final NotificationService notificationService; - public void setNotificationService(NotificationService ns) { - this.notificationService = ns; - } + public LispMappingService(final NotificationService notificationService, + final IMappingService mappingService, + final OdlLispSbService odlLispService, final ClusterSingletonServiceProvider clusterSingletonService) { - public void setMappingService(IMappingService ms) { - LOG.trace("MappingService set in LispMappingService"); - this.mapService = ms; + this.notificationService = notificationService; + this.mapService = mappingService; + this.lispSB = odlLispService; + this.clusterSingletonService = clusterSingletonService; + LOG.debug("LispMappingService Module constructed!"); } public boolean shouldUseSmr() { @@ -119,22 +116,15 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I } public void initialize() { - broker.registerProvider(this); - notificationService.registerNotificationListener(this); mapResolver = new MapResolver(mapService, smr, elpPolicy, this); - mapServer = new MapServer(mapService, shouldAuthenticate, smr, this, notificationService); + mapServer = new MapServer(mapService, smr, this, notificationService); + this.clusterSingletonService.registerClusterSingletonService(this); + LOG.info("LISP (RFC6830) Mapping Service init finished"); } public void basicInit() { mapResolver = new MapResolver(mapService, smr, elpPolicy, this); - mapServer = new MapServer(mapService, shouldAuthenticate, smr, this, notificationService); - } - - @Override - public void onSessionInitiated(ProviderContext session) { - LOG.info("Lisp Consumer session initialized!"); - this.session = session; - LOG.info("LISP (RFC6830) Mapping Service init finished"); + mapServer = new MapServer(mapService, smr, this, notificationService); } public MapReply handleMapRequest(MapRequest request) { @@ -172,13 +162,7 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I } public void setShouldAuthenticate(boolean shouldAuthenticate) { - this.shouldAuthenticate = shouldAuthenticate; this.mapResolver.setShouldAuthenticate(shouldAuthenticate); - this.mapServer.setShouldAuthenticate(shouldAuthenticate); - } - - public boolean shouldAuthenticate() { - return shouldAuthenticate; } private void sendMapNotify(MapNotify mapNotify, TransportAddress address) { @@ -193,7 +177,7 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I Pair> result = handleMapRegister(mapRegisterNotification.getMapRegister()); if (result != null && result.getLeft() != null) { MapNotify mapNotify = result.getLeft(); - List rlocs = result.getRight(); + List rlocs = result.getRight(); if (rlocs == null) { TransportAddressBuilder tab = new TransportAddressBuilder(); tab.setIpAddress(mapRegisterNotification.getTransportAddress().getIpAddress()); @@ -218,7 +202,7 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I smrib.setTransportAddress(mapRequestNotification.getTransportAddress()); getLispSB().sendMapReply(smrib.build()); } else { - LOG.warn("got null map reply"); + LOG.debug("handleMapRequest: Got null MapReply"); } } @@ -255,9 +239,6 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I } private OdlLispSbService getLispSB() { - if (lispSB == null) { - lispSB = session.getRpcService(OdlLispSbService.class); - } return lispSB; } @@ -300,5 +281,24 @@ public class LispMappingService implements IFlowMapping, BindingAwareProvider, I @Override public void close() throws Exception { destroy(); + clusterSingletonService.close(); + } + + @Override + public void instantiateServiceInstance() { + mapServer.setIsMaster(true); + } + + @Override + public ListenableFuture closeServiceInstance() { + if (mapServer != null) { + mapServer.setIsMaster(false); + } + return Futures.immediateFuture(null); + } + + @Override + public ServiceGroupIdentifier getIdentifier() { + return SERVICE_GROUP_IDENTIFIER; } }