Fix comparison between port numbers in match
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowRegistryKeyFactory.java
index c5acfa0b76b87b56f24c8a7d2dcd1847ecc8be13..a691b60ba2516d8e0e30129c00834f34b503cb22 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.openflowplugin.impl.util.MatchComparatorFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
@@ -22,27 +23,28 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M
  */
 public class FlowRegistryKeyFactory {
 
-
-    public FlowRegistryKeyFactory() {
+    private FlowRegistryKeyFactory() {
+        // Hide implicit constructor
     }
 
-    public static FlowRegistryKey create(final Flow flow) {
-        return new FlowRegistryKeyDto(flow);
+    public static FlowRegistryKey create(final short version, final Flow flow) {
+        return new FlowRegistryKeyDto(version, flow);
     }
 
     private static final class FlowRegistryKeyDto implements FlowRegistryKey {
-
         private final short tableId;
         private final int priority;
         private final BigInteger cookie;
         private final Match match;
+        private final short version;
 
-        public FlowRegistryKeyDto(final Flow flow) {
+        private FlowRegistryKeyDto(final short version, final Flow flow) {
             //TODO: mandatory flow input values (or default values) should be specified via yang model
             tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
             priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY);
-            match = flow.getMatch()==null? new MatchBuilder().build(): flow.getMatch();
+            match = MoreObjects.firstNonNull(flow.getMatch(), OFConstants.EMPTY_MATCH);
             cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
+            this.version = version;
         }
 
         @Override
@@ -60,7 +62,7 @@ public class FlowRegistryKeyFactory {
             return getPriority() == that.getPriority() &&
                     getTableId() == that.getTableId() &&
                     getCookie().equals(that.getCookie()) &&
-                    getMatch().equals(that.getMatch());
+                    MatchComparatorFactory.createMatch().areObjectsEqual(version, getMatch(), that.getMatch());
         }
 
         @Override