import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class FlowConsumerImpl {
+public class FlowConsumerImpl implements IForwardingRulesManager {
protected static final Logger logger = LoggerFactory.getLogger(FlowConsumerImpl.class);
- private FlowEventListener flowEventListener = new FlowEventListener();
+ private final FlowEventListener flowEventListener = new FlowEventListener();
private Registration<NotificationListener> listener1Reg;
private SalFlowService flowService;
// private FlowDataListener listener;
// updating the staticflow cache
Integer ordinal = staticFlowsOrdinal.get(0);
staticFlowsOrdinal.put(0, ++ordinal);
- staticFlows.put(ordinal, (Flow) dataObject);
+ staticFlows.put(ordinal, dataObject);
// We send flow to the sounthbound plugin
flowService.addFlow(input.build());
updateLocalDatabase((NodeFlow) dataObject, false);
}
+ /**
+ * Update flow to the southbound plugin and our internal database
+ *
+ * @param path
+ * @param dataObject
+ */
+ private void updateFlow(InstanceIdentifier<?> path, Flow dataObject) {
+
+ UpdateFlowInputBuilder input = new UpdateFlowInputBuilder();
+ UpdatedFlowBuilder updatedflowbuilder = new UpdatedFlowBuilder();
+ updatedflowbuilder.fieldsFrom(dataObject);
+ input.setUpdatedFlow(updatedflowbuilder.build());
+
+ // updating the staticflow cache
+ Integer ordinal = staticFlowsOrdinal.get(0);
+ staticFlowsOrdinal.put(0, ++ordinal);
+ staticFlows.put(ordinal, dataObject);
+
+ // We send flow to the sounthbound plugin
+ flowService.updateFlow(input.build());
+ updateLocalDatabase((NodeFlow) dataObject, true);
+ }
+
@SuppressWarnings("unchecked")
private void commitToPlugin(internalTransaction transaction) {
for (Entry<InstanceIdentifier<?>, Flow> entry : transaction.additions.entrySet()) {
for (@SuppressWarnings("unused")
Entry<InstanceIdentifier<?>, Flow> entry : transaction.updates.entrySet()) {
System.out.println("Coming update cc in FlowDatacommitHandler");
- // updateFlow(entry.getKey(),entry.getValue());
+ updateFlow(entry.getKey(), entry.getValue());
}
for (Entry<InstanceIdentifier<?>, Flow> entry : transaction.removals.entrySet()) {
logger.error(error);
return;
}
- if (originalSwView.containsKey((FlowKey) entry)) {
+ if (originalSwView.containsKey(entry)) {
logger.warn("Operation Rejected: A flow with same match and priority exists on the target node");
logger.trace("Aborting to install {}", entry);
continue;
public void onFlowUpdated(FlowUpdated notification) {
updatedFlows.add(notification);
}
-
+
@Override
public void onSwitchFlowRemoved(SwitchFlowRemoved notification) {
- //TODO
+ // TODO
+ }
+
+ @Override
+ public void onNodeErrorNotification(NodeErrorNotification notification) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onNodeExperimenterErrorNotification(
+ NodeExperimenterErrorNotification notification) {
+ // TODO Auto-generated method stub
+
};
}
FlowConsumerImpl.originalSwView.put((FlowKey) entry, (Flow) entry);
installedSwView.put((FlowKey) entry, (Flow) entry);
} else {
- originalSwView.remove((Flow) entry);
- installedSwView.remove((FlowKey) entry);
+ originalSwView.remove(entry);
+ installedSwView.remove(entry);
+
+ }
+ }
+ @Override
+ public List<DataObject> get() {
+
+ List<DataObject> orderedList = new ArrayList<DataObject>();
+ ConcurrentMap<Integer, Flow> flowMap = staticFlows;
+ int maxKey = staticFlowsOrdinal.get(0).intValue();
+ for (int i = 0; i <= maxKey; i++) {
+ Flow entry = flowMap.get(i);
+ if (entry != null) {
+ orderedList.add(entry);
+ }
+ }
+ return orderedList;
+ }
+
+ @Override
+ public DataObject getWithName(String name, org.opendaylight.controller.sal.core.Node n) {
+ if (this instanceof FlowConsumerImpl) {
+ for (ConcurrentMap.Entry<Integer, Flow> flowEntry : staticFlows.entrySet()) {
+ Flow flow = flowEntry.getValue();
+ if (flow.getNode().equals(n) && flow.getFlowName().equals(name)) {
+
+ return flowEntry.getValue();
+ }
+ }
}
+ return null;
}
/*
if (add) {
nodeIndeces.add((Flow) entry);
} else {
- nodeIndeces.remove((Flow) entry);
+ nodeIndeces.remove(entry);
}
// Update cache across cluster