- 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);
+ }
+
+ }
+
+ // 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((Flow) entry);
+ installedSwView.remove((FlowKey) entry);
+
+ }
+ }
+
+ /*
+ * 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((Flow) entry);
+ }
+
+ // Update cache across cluster
+ if (nodeIndeces.isEmpty()) {
+ nodeFlows.remove(node);
+ } else {
+ nodeFlows.put(node, nodeIndeces);
+ }
+ }
+