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=f3bb5d7680a71e8d77e2c815ceac9962471bb503;hb=6445920dbac192e45402c47bdd694571d3196d40;hp=9e20072c70a0d4af6a8a0f3f1b89e4b7658b16f4;hpb=c50ef1880a8afbd9943022c1b60814ebbec43fa2;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 9e20072c7..f3bb5d768 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,204 +8,160 @@ package org.opendaylight.lispflowmapping.implementation; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import java.util.List; +import java.util.Set; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; 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; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; -import org.opendaylight.controller.sal.binding.api.NotificationListener; -import org.opendaylight.controller.sal.binding.api.NotificationService; -import org.opendaylight.lispflowmapping.implementation.config.ConfigIni; -import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKey; -import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil; -import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceNoMaskKey; +import org.opendaylight.lispflowmapping.config.ConfigIni; import org.opendaylight.lispflowmapping.implementation.lisp.MapResolver; import org.opendaylight.lispflowmapping.implementation.lisp.MapServer; -import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage; -import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor; import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper; -import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; -import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter; -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.IMapRequestResultHandler; import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync; -import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServerAsync; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.AddMapping; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispflowmappingService; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRegister; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.RequestMapping; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.SendMapNotifyInputBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.SendMapReplyInputBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.SendMapRequestInputBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainerBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.Address; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4Builder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapnotifymessage.MapNotifyBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapreplymessage.MapReplyBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequestmessage.MapRequestBuilder; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.transportaddress.TransportAddress; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.transportaddress.TransportAddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; +import org.opendaylight.lispflowmapping.interfaces.lisp.ISmrNotificationListener; +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.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.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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MappingKeepAlive; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.RequestMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrReplyMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrRequestMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.map.register.cache.metadata.EidLispAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder; +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.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.yangtools.concepts.Registration; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class LispMappingService implements CommandProvider, IFlowMapping, BindingAwareConsumer, // - IMapRequestResultHandler, IMapNotifyHandler { - protected static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class); +@Singleton +@Component(service = {IFlowMapping.class, IMapRequestResultHandler.class, IMapNotifyHandler.class}, + 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 ConfigIni configIni = new ConfigIni(); - private ILispDAO lispDao = null; - private IMapResolverAsync mapResolver; - private IMapServerAsync mapServer; - private volatile boolean shouldIterateMask; - private volatile boolean shouldAuthenticate; - private volatile boolean smr = configIni.smrIsSet(); - private ThreadLocal tlsMapReply = new ThreadLocal(); - private ThreadLocal tlsMapNotify = new ThreadLocal(); - private ThreadLocal> tlsMapRequest = new ThreadLocal>(); - - private LispflowmappingService lispSB = null; - - private ConsumerContext session; - - private NotificationService notificationService; - - class LispIpv4AddressInMemoryConverter implements ILispTypeConverter { - } + private static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class); - class LispIpv6AddressInMemoryConverter implements ILispTypeConverter { - } - - class MappingServiceKeyConvertor implements ILispTypeConverter { - } + private volatile boolean smr = ConfigIni.getInstance().smrIsSet(); + private volatile String elpPolicy = ConfigIni.getInstance().getElpPolicy(); - class MappingServiceNoMaskKeyConvertor implements ILispTypeConverter { - } - - void setBindingAwareBroker(BindingAwareBroker bindingAwareBroker) { - LOG.trace("BindingAwareBroker set!"); - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - bindingAwareBroker.registerConsumer(this, bundleContext); - } + private ThreadLocal tlsMapReply = new ThreadLocal<>(); + private ThreadLocal>> tlsMapNotify = new ThreadLocal<>(); + private ThreadLocal> tlsMapRequest = new ThreadLocal<>(); - void unsetBindingAwareBroker(BindingAwareBroker bindingAwareBroker) { - LOG.debug("BindingAwareBroker was unset in LispMappingService"); - } - - public void basicInit(ILispDAO dao) { - lispDao = dao; - mapResolver = new MapResolver(dao); - mapServer = new MapServer(dao); - } - - void setLispDao(ILispDAO dao) { - LOG.trace("LispDAO set in LispMappingService"); - basicInit(dao); + private IMapResolverAsync mapResolver; + private MapServer mapServer; + + 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) { + this.mapService = mappingService; + this.lispSB = odlLispService; + this.clusterSingletonService = clusterSingletonService; + this.notificationService = notificationService; + + // initialize + listenerRegistration = notificationService.registerCompositeListener(new CompositeListener(Set.of( + new CompositeListener.Component<>(AddMapping.class, this::onAddMapping), + new CompositeListener.Component<>(GotMapNotify.class, this::onGotMapNotify), + new CompositeListener.Component<>(RequestMapping.class, this::onRequestMapping), + new CompositeListener.Component<>(GotMapReply.class, this::onGotMapReply), + 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); + mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer); + LOG.info("LISP (RFC6830) Mapping Service initialized"); } - void unsetLispDao(ILispDAO dao) { - LOG.trace("LispDAO was unset in LispMappingService"); - mapServer = null; - mapResolver = null; - lispDao = null; + public boolean shouldUseSmr() { + return this.smr; } - public void init() { - try { - registerWithOSGIConsole(); - LOG.info("LISP (RFC6830) Mapping Service init finished"); - } catch (Exception e) { - LOG.error(e.getStackTrace().toString()); + @Override + public void setShouldUseSmr(boolean shouldUseSmr) { + this.smr = shouldUseSmr; + if (mapServer != null) { + mapServer.setSubscriptionService(shouldUseSmr); } - } - - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, null); - } - - public void destroy() { - LOG.info("LISP (RFC6830) Mapping Service is destroyed!"); - mapResolver = null; - mapServer = null; - } - - public void _removeEid(final CommandInterpreter ci) { - LispAddressContainer eid = LispAFIConvertor.getIPContainer(ci.nextArgument()); - lispDao.remove(MappingServiceKeyUtil.generateMappingServiceKey(eid)); - } - - public void _dumpAll(final CommandInterpreter ci) { - ci.println("EID\tRLOCs"); - lispDao.getAll(new IRowVisitor() { - String lastKey = ""; - - public void visitRow(Object keyId, String valueKey, Object value) { - String key = keyId.getClass().getSimpleName() + "#" + keyId; - if (!lastKey.equals(key)) { - ci.println(); - ci.print(key + "\t"); - } - ci.print(valueKey + "=" + value + "\t"); - lastKey = key; - } - }); - ci.println(); - return; - } - - public void _setShouldOverwriteRlocs(final CommandInterpreter ci) { - try { - boolean shouldOverwriteRloc = Boolean.parseBoolean(ci.nextArgument()); - setOverwrite(shouldOverwriteRloc); - } catch (Exception e) { - ci.println("Bad Usage!!"); + if (mapResolver != null) { + mapResolver.setSubscriptionService(shouldUseSmr); } - - } - - public void _addDefaultPassword(final CommandInterpreter ci) { - LispAddressContainerBuilder builder = new LispAddressContainerBuilder(); - builder.setAddress((Address) (new Ipv4Builder().setIpv4Address(new Ipv4Address("0.0.0.0")).build())); - addAuthenticationKey(builder.build(), 0, "password"); + ConfigIni.getInstance().setSmr(shouldUseSmr); } - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("---LISP Mapping Service---\n"); - help.append("\t dumpAll - Dump all current EID -> RLOC mappings\n"); - help.append("\t removeEid - Remove a single EID (/32 or /128)\n"); - help.append("\t setShouldOverwriteRlocs - Set the map server's behavior regarding existing RLOCs\n"); - help.append("\t addDefaultPassword - Add \"password\" as default password for IPv4 EIDs"); - return help.toString(); + public NotificationService getNotificationService() { + return this.notificationService; } + @Override public MapReply handleMapRequest(MapRequest request) { - return handleMapRequest(request, smr); - } + if (LOG.isDebugEnabled()) { + LOG.debug("LISP: Retrieving mapping for {}", + LispAddressStringifier.getString(request.getEidItem().get(0).getEid())); + } - public MapReply handleMapRequest(MapRequest request, boolean smr) { tlsMapReply.set(null); tlsMapRequest.set(null); - mapResolver.handleMapRequest(request, smr, this); - // After this invocation we assume that the thread local is filled with - // the reply + mapResolver.handleMapRequest(request); + // After this invocation we assume that the thread local is filled with the reply if (tlsMapRequest.get() != null) { SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder(); - new MapRequestBuilder(tlsMapRequest.get().getLeft()); smrib.setMapRequest(new MapRequestBuilder(tlsMapRequest.get().getLeft()).build()); smrib.setTransportAddress(tlsMapRequest.get().getRight()); getLispSB().sendMapRequest(smrib.build()); @@ -213,151 +169,169 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin } else { return tlsMapReply.get(); } - } - public MapNotify handleMapRegister(MapRegister mapRegister) { - return handleMapRegister(mapRegister, smr); - } + @Override + public Pair> handleMapRegister(MapRegister mapRegister) { + if (LOG.isDebugEnabled()) { + LOG.debug("LISP: Adding mapping for {}", + LispAddressStringifier.getString(mapRegister.getMappingRecordItem().get(0) + .getMappingRecord().getEid())); + } - public MapNotify handleMapRegister(MapRegister mapRegister, boolean smr) { tlsMapNotify.set(null); - mapServer.handleMapRegister(mapRegister, smr, this); - // After this invocation we assume that the thread local is filled with - // the reply + mapServer.handleMapRegister(mapRegister); + // After this invocation we assume that the thread local is filled with the reply return tlsMapNotify.get(); } - public String getAuthenticationKey(LispAddressContainer address, int maskLen) { - return mapServer.getAuthenticationKey(address, maskLen); - } - - public void removeAuthenticationKey(LispAddressContainer address, int maskLen) { - mapServer.removeAuthenticationKey(address, maskLen); - } - - public void addAuthenticationKey(LispAddressContainer address, int maskLen, String key) { - mapServer.addAuthenticationKey(address, maskLen, key); - } - - public boolean shouldIterateMask() { - return this.shouldIterateMask; - } - - public boolean shouldUseSmr() { - return this.smr; + public void setShouldAuthenticate(boolean shouldAuthenticate) { + this.mapResolver.setShouldAuthenticate(shouldAuthenticate); } - public void setShouldUseSmr(boolean smr) { - this.smr = smr; + private void sendMapNotify(MapNotify mapNotify, TransportAddress address) { + SendMapNotifyInputBuilder smnib = new SendMapNotifyInputBuilder(); + smnib.setMapNotify(new MapNotifyBuilder(mapNotify).build()); + smnib.setTransportAddress(address); + getLispSB().sendMapNotify(smnib.build()); } - public void setShouldIterateMask(boolean shouldIterateMask) { - this.shouldIterateMask = shouldIterateMask; - this.mapResolver.setShouldIterateMask(shouldIterateMask); - this.mapServer.setShouldIterateMask(shouldIterateMask); + @VisibleForTesting + void onAddMapping(AddMapping mapRegisterNotification) { + Pair> result = handleMapRegister(mapRegisterNotification.getMapRegister()); + if (result != null && result.getLeft() != null) { + MapNotify mapNotify = result.getLeft(); + List rlocs = result.getRight(); + if (rlocs == null) { + TransportAddressBuilder tab = new TransportAddressBuilder(); + tab.setIpAddress(mapRegisterNotification.getTransportAddress().getIpAddress()); + tab.setPort(new PortNumber(LispMessage.PORT_NUMBER)); + sendMapNotify(mapNotify, tab.build()); + } else { + for (TransportAddress ta : rlocs) { + sendMapNotify(mapNotify, ta); + } + } + } else { + LOG.debug("Not sending Map-Notify"); + } } - public void setShouldAuthenticate(boolean shouldAuthenticate) { - this.shouldAuthenticate = shouldAuthenticate; - this.mapResolver.setShouldAuthenticate(shouldAuthenticate); - this.mapServer.setShouldAuthenticate(shouldAuthenticate); + @VisibleForTesting + void onRequestMapping(RequestMapping mapRequestNotification) { + MapReply mapReply = handleMapRequest(mapRequestNotification.getMapRequest()); + if (mapReply != null) { + SendMapReplyInputBuilder smrib = new SendMapReplyInputBuilder(); + smrib.setMapReply(new MapReplyBuilder(mapReply).build()); + smrib.setTransportAddress(mapRequestNotification.getTransportAddress()); + getLispSB().sendMapReply(smrib.build()); + } else { + LOG.debug("handleMapRequest: Got null MapReply"); + } } - public boolean shouldAuthenticate() { - return shouldAuthenticate; + @VisibleForTesting + void onGotMapReply(GotMapReply notification) { + LOG.debug("Received GotMapReply notification, ignoring"); } - public void onSessionInitialized(ConsumerContext session) { - LOG.info("Lisp Consumer session initialized!"); - notificationService = session.getSALService(NotificationService.class); - registerNotificationListener(AddMapping.class, new MapRegisterNotificationHandler()); - registerNotificationListener(RequestMapping.class, new MapRequestNotificationHandler()); - this.session = session; + @VisibleForTesting + void onGotMapNotify(GotMapNotify notification) { + LOG.debug("Received GotMapNotify notification, ignoring"); } - public void registerNotificationListener(Class notificationType, NotificationListener listener) { - notificationService.registerNotificationListener(notificationType, listener); + @VisibleForTesting + void onXtrRequestMapping(XtrRequestMapping notification) { + LOG.debug("Received XtrRequestMapping notification, ignoring"); } - private class MapRegisterNotificationHandler implements NotificationListener { - - @Override - public void onNotification(AddMapping mapRegisterNotification) { - MapNotify mapNotify = handleMapRegister(mapRegisterNotification.getMapRegister(), smr); - if (mapNotify != null) { - TransportAddressBuilder tab = new TransportAddressBuilder(); - tab.setIpAddress(mapRegisterNotification.getTransportAddress().getIpAddress()); - tab.setPort(new PortNumber(LispMessage.PORT_NUM)); - SendMapNotifyInputBuilder smnib = new SendMapNotifyInputBuilder(); - smnib.setMapNotify(new MapNotifyBuilder(mapNotify).build()); - smnib.setTransportAddress(tab.build()); - getLispSB().sendMapNotify(smnib.build()); - } else { - LOG.warn("got null map notify"); - } - - } + @VisibleForTesting + void onXtrReplyMapping(XtrReplyMapping notification) { + LOG.debug("Received XtrReplyMapping notification, ignoring"); } - private class MapRequestNotificationHandler implements NotificationListener { - - @Override - public void onNotification(RequestMapping mapRequestNotification) { - MapReply mapReply = handleMapRequest(mapRequestNotification.getMapRequest()); - if (mapReply != null) { - SendMapReplyInputBuilder smrib = new SendMapReplyInputBuilder(); - smrib.setMapReply((new MapReplyBuilder(mapReply).build())); - smrib.setTransportAddress(mapRequestNotification.getTransportAddress()); - getLispSB().sendMapReply(smrib.build()); - } else { - LOG.warn("got null map reply"); - } + @VisibleForTesting + void onMappingKeepAlive(MappingKeepAlive notification) { + final MapRegisterCacheMetadata cacheMetadata = notification.getMapRegisterCacheMetadata(); + for (EidLispAddress eidLispAddress : cacheMetadata.nonnullEidLispAddress().values()) { + final Eid eid = eidLispAddress.getEid(); + final XtrId xtrId = cacheMetadata.getXtrId(); + final Long timestamp = cacheMetadata.getTimestamp(); + LOG.debug("Update map registration for eid {} with timestamp {}", LispAddressStringifier.getString(eid), + timestamp); + mapService.refreshMappingRegistration(eid, xtrId, timestamp); } } - private LispflowmappingService getLispSB() { - if (lispSB == null) { - lispSB = session.getRpcService(LispflowmappingService.class); - } + private OdlLispSbService getLispSB() { return lispSB; } + @Override public void handleMapReply(MapReply reply) { tlsMapReply.set(reply); } - public void handleMapNotify(MapNotify notify) { - tlsMapNotify.set(notify); + @Override + public void handleMapNotify(MapNotify notify, List rlocs) { + tlsMapNotify.set(new MutablePair<>(notify, rlocs)); } - public void handleSMR(MapRequest smr, LispAddressContainer subscriber) { - LOG.debug("Sending SMR to " + subscriber.toString()); + @Override + public void handleSMR(MapRequest smrMapRequest, Rloc subscriber) { + if (LOG.isDebugEnabled()) { + LOG.debug("Sending SMR Map-Request to {} with Source-EID {} and EID Record {} (reversed)", + LispAddressStringifier.getString(subscriber), + LispAddressStringifier.getString(smrMapRequest.getSourceEid().getEid()), + LispAddressStringifier.getString(smrMapRequest.getEidItem().get(0).getEid())); + } SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder(); - smrib.setMapRequest(new MapRequestBuilder(smr).build()); - smrib.setTransportAddress(LispNotificationHelper.getTransportAddressFromContainer(subscriber)); + smrib.setMapRequest(new MapRequestBuilder(smrMapRequest).build()); + smrib.setTransportAddress(LispNotificationHelper.getTransportAddressFromRloc(subscriber)); getLispSB().sendMapRequest(smrib.build()); } @Override public void handleNonProxyMapRequest(MapRequest mapRequest, TransportAddress transportAddress) { - tlsMapRequest.set(new MutablePair(mapRequest, transportAddress)); + tlsMapRequest.set(new MutablePair<>(mapRequest, transportAddress)); } + private void destroy() { + LOG.info("LISP (RFC6830) Mapping Service is destroyed!"); + mapResolver = null; + if (mapServer != null) { + mapServer.close(); + mapServer = null; + } + } + + @Deactivate + @PreDestroy @Override - public void clean() { - lispDao.removeAll(); + public void close() throws Exception { + destroy(); + cssRegistration.close(); + clusterSingletonService.close(); + rpcRegistration.close(); + listenerRegistration.close(); } @Override - public boolean shouldOverwrite() { - return mapServer.shouldOverwrite(); + public void instantiateServiceInstance() { + mapService.setIsMaster(true); } @Override - public void setOverwrite(boolean overwrite) { - mapServer.setOverwrite(overwrite); + public ListenableFuture closeServiceInstance() { + if (mapService != null) { + mapService.setIsMaster(false); + } + return Futures.immediateFuture(null); } + @Override + public ServiceGroupIdentifier getIdentifier() { + return SERVICE_GROUP_IDENTIFIER; + } }