/**
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- * <p/>
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
package org.opendaylight.openflowplugin.applications.frm.impl;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+
+import com.google.common.util.concurrent.CheckedFuture;
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.RpcConsumerRegistry;
import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesCommiter;
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.table.types.rev131026.table.features.TableFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final SalFlowService salFlowService;
private final SalGroupService salGroupService;
private final SalMeterService salMeterService;
+ private final SalTableService salTableService;
private ForwardingRulesCommiter<Flow> flowListener;
private ForwardingRulesCommiter<Group> groupListener;
private ForwardingRulesCommiter<Meter> meterListener;
+ private ForwardingRulesCommiter<TableFeatures> tableListener;
private FlowNodeReconciliation nodeListener;
+ private final ForwardingRulesManagerConfig forwardingRulesManagerConfig;
+ private final EntityOwnershipService entityOwnershipService;
+
public ForwardingRulesManagerImpl(final DataBroker dataBroker,
- final RpcConsumerRegistry rpcRegistry) {
+ final RpcConsumerRegistry rpcRegistry,
+ final ForwardingRulesManagerConfig config,
+ final EntityOwnershipService eos) {
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");
Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !");
"RPC SalGroupService not found.");
this.salMeterService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalMeterService.class),
"RPC SalMeterService not found.");
+ this.salTableService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalTableService.class),
+ "RPC SalTableService not found.");
}
@Override
public void start() {
+
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);
LOG.info("ForwardingRulesManager has started successfully.");
+
}
@Override
this.meterListener.close();
this.meterListener = null;
}
+ if (this.tableListener != null) {
+ this.tableListener.close();
+ this.tableListener = null;
+ }
if (this.nodeListener != null) {
this.nodeListener.close();
this.nodeListener = null;
return activeNodes.contains(ident);
}
+ @Override
+ public boolean checkNodeInOperationalDataStore(InstanceIdentifier<FlowCapableNode> ident) {
+ boolean result = false;
+ InstanceIdentifier<Node> nodeIid = ident.firstIdentifierOf(Node.class);
+ final ReadOnlyTransaction transaction = dataService.newReadOnlyTransaction();
+ Optional<Node> optionalDataObject;
+ CheckedFuture<Optional<Node>, ReadFailedException> future = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid);
+ try {
+ optionalDataObject = future.checkedGet();
+ if (optionalDataObject.isPresent()) {
+ result = true;
+ } else {
+ LOG.debug("{}: Failed to read {}",
+ Thread.currentThread().getStackTrace()[1], nodeIid);
+ }
+ } catch (ReadFailedException e) {
+ LOG.warn("Failed to read {} ", nodeIid, e);
+ }
+ transaction.close();
+
+ return result;
+ }
+
@Override
public void registrateNewNode(InstanceIdentifier<FlowCapableNode> ident) {
if (!activeNodes.contains(ident)) {
return salMeterService;
}
+ @Override
+ public SalTableService getSalTableService() {
+ return salTableService;
+ }
+
@Override
public ForwardingRulesCommiter<Flow> getFlowCommiter() {
return flowListener;
return meterListener;
}
+ @Override
+ public ForwardingRulesCommiter<TableFeatures> getTableFeaturesCommiter() {
+ return tableListener;
+ }
+
@Override
public FlowNodeReconciliation getFlowNodeReconciliation() {
return nodeListener;
}
+
+ @Override
+ public ForwardingRulesManagerConfig getConfiguration() {
+ return forwardingRulesManagerConfig;
+ }
+
+ @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;
+ }
}