Added code for cluster aware behaviour to LfmMappingServiceSb.
Change-Id: I06e89cf08fe531e1e53eab08b9f8d5204ba2603f
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
<groupId>${project.groupId}</groupId>
<artifactId>mappingservice.api</artifactId>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mappingservice.clustering</artifactId>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mappingservice.inmemorydb</artifactId>
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.lispflowmapping.clustering.ClusterNodeModulSwitcherImpl;
+import org.opendaylight.lispflowmapping.clustering.api.ClusterNodeModuleSwitcher;
import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
import org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCloseable {
+public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCloseable, ClusterNodeModuleSwitcher {
protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundPlugin.class);
private static Object startLock = new Object();
+ private final ClusterNodeModulSwitcherImpl clusterNodeModulSwitcher;
private LispSouthboundHandler lispSouthboundHandler;
private LispXtrSouthboundHandler lispXtrSouthboundHandler;
private NotificationPublishService notificationPublishService;
public LispSouthboundPlugin(final DataBroker dataBroker,
final NotificationPublishService notificationPublishService,
- final LispSbConfig lispSbConfig) {
+ final LispSbConfig lispSbConfig, final EntityOwnershipService entityOwnershipService) {
this.dataBroker = dataBroker;
this.notificationPublishService = notificationPublishService;
this.bindingAddress = lispSbConfig.getBindAddress();
this.mapRegisterCacheEnabled = lispSbConfig.isMapRegisterCache();
+ clusterNodeModulSwitcher = new ClusterNodeModulSwitcherImpl(entityOwnershipService);
+ clusterNodeModulSwitcher.setModule(this);
}
public void init() {
LOG.info("LISP (RFC6830) Southbound Plugin is up!");
}
+ clusterNodeModulSwitcher.switchModuleByEntityOwnership();
}
private void start() {
lispSouthboundHandler.close();
unloadActions();
}
+
+ @Override
+ public void stopModule() {
+ if (lispSouthboundHandler != null) {
+ lispSouthboundHandler.setNotificationProvider(null);
+ lispSouthboundHandler.setIsReadFromChannelEnabled(false);
+ }
+ if (lispXtrSouthboundHandler != null) {
+ lispXtrSouthboundHandler.setNotificationProvider(null);
+ }
+ }
+
+ @Override
+ public void startModule() {
+ if (lispSouthboundHandler != null) {
+ lispSouthboundHandler.setNotificationProvider(notificationPublishService);
+ lispSouthboundHandler.restoreDaoFromDatastore();
+ lispSouthboundHandler.setIsReadFromChannelEnabled(true);
+ }
+ if (lispXtrSouthboundHandler != null) {
+ lispXtrSouthboundHandler.setNotificationProvider(notificationPublishService);
+ }
+ }
}
private SimpleMapCache smc;
private AuthenticationKeyDataListener authenticationKeyDataListener;
private DataStoreBackEnd dsbe;
+ private boolean isReadFromChannelEnabled = true;
public LispSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
this.lispSbPlugin = lispSbPlugin;
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
- msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+ if (isReadFromChannelEnabled) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
+ msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+ }
+ handlePacket(msg);
}
- handlePacket(msg);
}
@Override
this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
dsbe = new DataStoreBackEnd(dataBroker);
}
+
+ public void setIsReadFromChannelEnabled(boolean isReadFromChannelEnabled) {
+ this.isReadFromChannelEnabled = isReadFromChannelEnabled;
+ }
}
odl:type="pingpong" />
<reference id="notificationPublishService"
interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService" />
+ <reference id="entityOwnershipService"
+ interface="org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService" />
<odl:clustered-app-config id="lispSbConfig"
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.lisp.sb.config.rev150517.LispSbConfig">
<argument ref="dataBroker" />
<argument ref="notificationPublishService" />
<argument ref="lispSbConfig" />
+ <argument ref="entityOwnershipService" />
</bean>
<service ref="lispSouthboundPlugin"
interface="org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin"
</bean>
<odl:rpc-implementation ref="sbRpcHandler" />
-</blueprint>
\ No newline at end of file
+</blueprint>
import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
lispSouthboundPlugin = new LispSouthboundPlugin(
Mockito.mock(DataBroker.class),
Mockito.mock(NotificationPublishService.class),
- config);
+ config,
+ Mockito.mock(EntityOwnershipService.class));
channel = PowerMockito.mock(NioDatagramChannel.class);
xtrChannel = PowerMockito.mock(NioDatagramChannel.class);
injectChannel();