package org.opendaylight.openflowplugin.applications.frm.impl;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.CheckedFuture;
import java.util.Collections;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesCommiter;
import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig;
* Manager and middle point for whole module.
* It contains ActiveNodeHolder and provide all RPC services.
*
- * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- *
- * Created: Aug 25, 2014
*/
public class ForwardingRulesManagerImpl implements ForwardingRulesManager {
private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesManagerImpl.class);
- public static final int STARTUP_LOOP_TICK = 500;
- public static final int STARTUP_LOOP_MAX_RETRIES = 8;
+ static final int STARTUP_LOOP_TICK = 500;
+ static final int STARTUP_LOOP_MAX_RETRIES = 8;
private final AtomicLong txNum = new AtomicLong();
private final Object lockObj = new Object();
private final ForwardingRulesManagerConfig forwardingRulesManagerConfig;
private FlowNodeConnectorInventoryTranslatorImpl flowNodeConnectorInventoryTranslatorImpl;
- private final EntityOwnershipService entityOwnershipService;
+ private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
+ private final NotificationProviderService notificationService;
+ private DeviceMastershipManager deviceMastershipManager;
public ForwardingRulesManagerImpl(final DataBroker dataBroker,
final RpcConsumerRegistry rpcRegistry,
final ForwardingRulesManagerConfig config,
- final EntityOwnershipService eos) {
+ final ClusterSingletonServiceProvider clusterSingletonService,
+ final NotificationProviderService notificationService) {
this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
this.forwardingRulesManagerConfig = Preconditions.checkNotNull(config, "Configuration for FRM cannot be null");
- this.entityOwnershipService = Preconditions.checkNotNull(eos, "EntityOwnership service can not be null");
+ this.clusterSingletonServiceProvider = Preconditions.checkNotNull(clusterSingletonService,
+ "ClusterSingletonService provider can not be null");
+ this.notificationService = Preconditions.checkNotNull(notificationService, "Notification publisher service is" +
+ " not available");
Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !");
@Override
public void start() {
-
+ this.deviceMastershipManager = new DeviceMastershipManager(clusterSingletonServiceProvider,
+ notificationService);
this.flowListener = new FlowForwarder(this, dataService);
-
this.groupListener = new GroupForwarder(this, dataService);
this.meterListener = new MeterForwarder(this, dataService);
-
this.tableListener = new TableForwarder(this, dataService);
this.nodeListener = new FlowNodeReconciliationImpl(this, dataService);
- flowNodeConnectorInventoryTranslatorImpl =
- new FlowNodeConnectorInventoryTranslatorImpl(this,dataService);
+ flowNodeConnectorInventoryTranslatorImpl =
+ new FlowNodeConnectorInventoryTranslatorImpl(this,dataService);
LOG.info("ForwardingRulesManager has started successfully.");
-
}
@Override
this.nodeListener.close();
this.nodeListener = null;
}
+ if (deviceMastershipManager != null) {
+ deviceMastershipManager.close();
+ }
}
@Override
Sets.newHashSet(activeNodes);
set.add(ident);
activeNodes = Collections.unmodifiableSet(set);
+ deviceMastershipManager.onDeviceConnected(ident.firstKeyOf(Node.class).getId());
}
}
}
Sets.newHashSet(activeNodes);
set.remove(ident);
activeNodes = Collections.unmodifiableSet(set);
+ deviceMastershipManager.onDeviceDisconnected(ident.firstKeyOf(Node.class).getId());
}
}
}
@Override
public boolean isNodeOwner(InstanceIdentifier<FlowCapableNode> ident) {
- NodeId nodeId = ident.firstKeyOf(Node.class).getId();
- Entity entity = new Entity("openflow", nodeId.getValue());
- Optional<EntityOwnershipState> eState = this.entityOwnershipService.getOwnershipState(entity);
- if(eState.isPresent()) {
- return eState.get().isOwner();
- }
- return false;
+ return Objects.nonNull(ident) && deviceMastershipManager.isDeviceMastered(ident.firstKeyOf(Node.class).getId());
}
+
+ @VisibleForTesting
+ public void setDeviceMastershipManager(final DeviceMastershipManager deviceMastershipManager) {
+ this.deviceMastershipManager = deviceMastershipManager;
+ }
+
}