- System.out.println("added flow..........................");
- addedFlows.add(notification);
- }
-
- @Override
- public void onFlowRemoved(FlowRemoved notification) {
- removedFlows.add(notification);
- };
-
- @Override
- public void onFlowUpdated(FlowUpdated notification) {
- updatedFlows.add(notification);
- }
-
- }
-
- final class FlowDataListener implements DataChangeListener {
- private SalFlowService flowService;
-
- public FlowDataListener() {
-
- }
-
- @Override
- public void onDataChanged(
- DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- System.out.println("Coming in onDataChange..............");
- @SuppressWarnings("unchecked")
- Collection<DataObject> additions = (Collection<DataObject>) change.getCreatedConfigurationData();
- // we can check for getCreated, getDeleted or getUpdated from DataChange Event class
- for (DataObject dataObject : additions) {
- if (dataObject instanceof NodeFlow) {
- NodeRef nodeOne = createNodeRef("foo:node:1");
- // validating the dataObject here
- AddFlowInputBuilder input = new AddFlowInputBuilder();
- input.setNode(((NodeFlow) dataObject).getNode());
- input.setNode(nodeOne);
- // input.setPriority(((NodeFlow) dataObject).getPriority());
- //input.setMatch(((NodeFlow) dataObject).getMatch());
- //input.setFlowTable(((NodeFlow) dataObject).getFlowTable());
- //input.setCookie(((NodeFlow) dataObject).getCookie());
- //input.setAction(((NodeFlow) dataObject).getAction());
-
- @SuppressWarnings("unused")
- Future<RpcResult<java.lang.Void>> result = flowService.addFlow(input.build());
- }
- }
- }
- }
-
-
-
+ System.out.println("added flow..........................");
+ addedFlows.add(notification);
+ }
+
+ @Override
+ public void onFlowRemoved(FlowRemoved notification) {
+ removedFlows.add(notification);
+ };
+
+ @Override
+ public void onFlowUpdated(FlowUpdated notification) {
+ updatedFlows.add(notification);
+ }
+
+ @Override
+ public void onSwitchFlowRemoved(SwitchFlowRemoved notification) {
+ // TODO
+ }
+
+ @Override
+ public void onNodeErrorNotification(NodeErrorNotification notification) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onNodeExperimenterErrorNotification(
+ NodeExperimenterErrorNotification notification) {
+ // TODO Auto-generated method stub
+
+ };
+
+ }
+
+ // Commented out DataChangeListene - to be used by Stats
+
+ // final class FlowDataListener implements DataChangeListener {
+ // private SalFlowService flowService;
+ //
+ // public FlowDataListener() {
+ //
+ // }
+ //
+ // @Override
+ // public void onDataChanged(
+ // DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ // System.out.println("Coming in onDataChange..............");
+ // @SuppressWarnings("unchecked")
+ // Collection<DataObject> additions = (Collection<DataObject>)
+ // change.getCreatedConfigurationData();
+ // // we can check for getCreated, getDeleted or getUpdated from DataChange
+ // Event class
+ // for (DataObject dataObject : additions) {
+ // if (dataObject instanceof NodeFlow) {
+ // NodeRef nodeOne = createNodeRef("foo:node:1");
+ // // validating the dataObject here
+ // AddFlowInputBuilder input = new AddFlowInputBuilder();
+ // input.setNode(((NodeFlow) dataObject).getNode());
+ // input.setNode(nodeOne);
+ // // input.setPriority(((NodeFlow) dataObject).getPriority());
+ // //input.setMatch(((NodeFlow) dataObject).getMatch());
+ // //input.setFlowTable(((NodeFlow) dataObject).getFlowTable());
+ // //input.setCookie(((NodeFlow) dataObject).getCookie());
+ // //input.setAction(((NodeFlow) dataObject).getAction());
+ //
+ // @SuppressWarnings("unused")
+ // Future<RpcResult<java.lang.Void>> result =
+ // flowService.addFlow(input.build());
+ // }
+ // }
+ // }
+ // }
+
+ private static void updateLocalDatabase(NodeFlow entry, boolean add) {
+
+ updateSwViewes(entry, add);
+
+ updateNodeFlowsDB(entry, add);
+
+ }
+
+ /*
+ * Update the node mapped flows database
+ */
+ private static void updateSwViewes(NodeFlow entry, boolean add) {
+ if (add) {
+ FlowConsumerImpl.originalSwView.put((FlowKey) entry, (Flow) entry);
+ installedSwView.put((FlowKey) entry, (Flow) entry);
+ } else {
+ 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;
+ }
+
+ /*
+ * Update the node mapped flows database
+ */
+ private static void updateNodeFlowsDB(NodeFlow entry, boolean add) {
+ Node node = (Node) entry.getNode();
+
+ List<Flow> nodeIndeces = nodeFlows.get(node);
+ if (nodeIndeces == null) {
+ if (!add) {
+ return;
+ } else {
+ nodeIndeces = new ArrayList<Flow>();
+ }
+ }
+
+ if (add) {
+ nodeIndeces.add((Flow) entry);
+ } else {
+ nodeIndeces.remove(entry);
+ }
+
+ // Update cache across cluster
+ if (nodeIndeces.isEmpty()) {
+ nodeFlows.remove(node);
+ } else {
+ nodeFlows.put(node, nodeIndeces);
+ }
+ }
+