Bug 6524 FlowDescriptor instead of SwitchFlowId in FRS 62/44662/3
authorAndrej Leitner <andrej.leitner@pantheon.tech>
Wed, 24 Aug 2016 14:10:27 +0000 (16:10 +0200)
committerAndrej Leitner <andrej.leitner@pantheon.sk>
Thu, 25 Aug 2016 13:26:12 +0000 (13:26 +0000)
Change-Id: Ibb02c310be27f02c7543e157d2f5e7ca7cc430a8
Signed-off-by: Andrej Leitner <andrej.leitner@pantheon.tech>
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FlowCapableNodeLookups.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FlowDescriptor.java [new file with mode: 0644]
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/ReconcileUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SwitchFlowId.java [deleted file]

index cd92bb083e3f6771e32fe6fc84edb0ac68c6f62a..5d040fa4471e0f11e51ca08049ed4ed083028bef 100644 (file)
@@ -52,8 +52,8 @@ public final class FlowCapableNodeLookups {
     }
 
     @Nonnull
-    public static Map<SwitchFlowId, Flow> wrapFlowsToMap(@Nullable final List<Flow> flows) {
-        final Map<SwitchFlowId, Flow> flowMap;
+    public static Map<FlowDescriptor, Flow> wrapFlowsToMap(@Nullable final List<Flow> flows) {
+        final Map<FlowDescriptor, Flow> flowMap;
 
         if (flows == null) {
             flowMap = Collections.emptyMap();
@@ -61,15 +61,15 @@ public final class FlowCapableNodeLookups {
             LOG.trace("flows found: {}", flows.size());
             flowMap = new HashMap<>();
             for (Flow flow : flows) {
-                flowMap.put(new SwitchFlowId(flow), flow);
+                flowMap.put(new FlowDescriptor(flow), flow);
             }
         }
 
         return flowMap;
     }
 
-    public static Flow flowMapLookupExisting(Flow flow, Map<SwitchFlowId, Flow> flowConfigMap) {
-        return flowConfigMap.get(new SwitchFlowId(flow));
+    public static Flow flowMapLookupExisting(Flow flow, Map<FlowDescriptor, Flow> flowConfigMap) {
+        return flowConfigMap.get(new FlowDescriptor(flow));
     }
 
     @Nonnull
diff --git a/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FlowDescriptor.java b/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FlowDescriptor.java
new file mode 100644 (file)
index 0000000..676cd92
--- /dev/null
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.frsync.util;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+
+/**
+ * Identifier of {@link Flow} in datastore using combination of flow-id and table-id from datastore datapath.
+ */
+public class FlowDescriptor {
+
+    private final FlowId flowId;
+    private final Short tableId;
+
+    public FlowDescriptor(Flow flow) {
+        this.flowId = flow.getId();
+        this.tableId = flow.getTableId();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        FlowDescriptor that = (FlowDescriptor) o;
+        if (flowId != null ? !flowId.equals(that.flowId) : that.flowId != null) {
+            return false;
+        }
+        return tableId != null ? tableId.equals(that.tableId) : that.tableId == null;
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = flowId != null ? flowId.hashCode() : 0;
+        result = 31 * result + (tableId != null ? tableId.hashCode() : 0);
+        return result;
+    }
+
+}
index a910c01957e0dc8ec57d817d3f9a7a7da105dbcb..85f04d438d6f1162e4d8c7f5e7118a51bc247626 100644 (file)
@@ -269,8 +269,8 @@ public final class ReconcileUtil {
      * @return list of safe synchronization steps
      */
     public static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
-                                                     final Map<SwitchFlowId, Flow> flowOperationalMap,
-                                                     final boolean gatherUpdates) {
+                                                            final Map<FlowDescriptor, Flow> flowOperationalMap,
+                                                            final boolean gatherUpdates) {
         final ItemSyncBox<Flow> flowsSyncBox = new ItemSyncBox<>();
         // loop configured flows and check if already present on device
         for (final Flow flow : flowsConfigured) {
@@ -310,7 +310,7 @@ public final class ReconcileUtil {
             // lookup table (on device)
             final Table tableOperational = tableOperationalMap.get(tableConfigured.getId());
             // wrap existing (on device) flows in current table into map
-            final Map<SwitchFlowId, Flow> flowOperationalMap = FlowCapableNodeLookups.wrapFlowsToMap(
+            final Map<FlowDescriptor, Flow> flowOperationalMap = FlowCapableNodeLookups.wrapFlowsToMap(
                     tableOperational != null
                             ? tableOperational.getFlow()
                             : null);
diff --git a/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SwitchFlowId.java b/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SwitchFlowId.java
deleted file mode 100644 (file)
index 8ccc9b2..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright (c) 2016 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.frsync.util;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-
-/**
- * Identifier of {@link Flow} on device. Switch does not know about flow-id but,
- * it uses combination of these unique fields: table-id, priority, match.
- */
-public class SwitchFlowId {
-
-    private final Short tableId;
-
-    private final Integer priority;
-
-    private final Match match;
-
-    public SwitchFlowId(Flow flow) {
-        this.tableId = flow.getTableId();
-        this.priority = flow.getPriority();
-        this.match = flow.getMatch();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        SwitchFlowId that = (SwitchFlowId) o;
-
-        if (tableId != null ? !tableId.equals(that.tableId) : that.tableId != null) {
-            return false;
-        }
-        if (priority != null ? !priority.equals(that.priority) : that.priority != null) {
-            return false;
-        }
-        return match != null ? match.equals(that.match) : that.match == null;
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((match == null) ? 0 : match.hashCode());
-        result = prime * result + ((priority == null) ? 0 : priority.hashCode());
-        result = prime * result + ((tableId == null) ? 0 : tableId.hashCode());
-        return result;
-    }
-
-}