import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private ListenerRegistration<SessionListener> sessionListenerRegistration;
+ private OfEntityManager entManager;
+
public SalRegistrationManager() {
swFeaturesUtil = SwitchFeaturesUtil.getInstance();
}
this.rpcProviderRegistry = rpcProviderRegistry;
}
+ public void setOfEntityManager(OfEntityManager entManager) {
+ this.entManager = entManager;
+ }
+
public void init() {
LOG.debug("init..");
sessionListenerRegistration = getSessionManager().registerSessionListener(this);
InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
NodeRef nodeRef = new NodeRef(identifier);
NodeId nodeId = nodeIdFromDatapathId(datapathId);
- ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
- CompositeObjectRegistration<ModelDrivenSwitch> registration =
- ofSwitch.register(rpcProviderRegistry);
- context.setProviderRegistration(registration);
-
- LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId);
+ ModelDrivenSwitch ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier,context);
NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
nodeAdded(ofSwitch, features, nodeRef),
context.getFeatures().getVersion());
- context.getNotificationEnqueuer().enqueueNotification(wrappedNotification);
+
+ reqOpenflowEntityOwnership(ofSwitch, context, wrappedNotification, rpcProviderRegistry);
+ }
+
+ @Override
+ public void setRole (SessionContext context) {
+ entManager.setSlaveRole(context);
}
@Override
BigInteger datapathId = features.getDatapathId();
InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
NodeRef nodeRef = new NodeRef(identifier);
+ NodeId nodeId = nodeIdFromDatapathId(datapathId);
+ unregOpenflowEntityOwnership(nodeId);
NodeRemoved nodeRemoved = nodeRemoved(nodeRef);
CompositeObjectRegistration<ModelDrivenSwitch> registration = context.getProviderRegistration();
@Override
public void close() {
- LOG.debug("close");
dataService = null;
rpcProviderRegistry = null;
publishService = null;
sessionListenerRegistration.close();
}
}
+
+ private void reqOpenflowEntityOwnership(ModelDrivenSwitch ofSwitch,
+ SessionContext context,
+ NotificationQueueWrapper wrappedNotification,
+ RpcProviderRegistry rpcProviderRegistry) {
+ context.setValid(true);
+ entManager.requestOpenflowEntityOwnership(ofSwitch, context, wrappedNotification, rpcProviderRegistry);
+ }
+
+ private void unregOpenflowEntityOwnership(NodeId nodeId) {
+ entManager.unregisterEntityOwnershipRequest(nodeId);
+ }
+
}