Merge "Bug 6110: Fixed bugs in statistics manager due to race condition." into stable...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowRegistryKeyFactory.java
index aac1c3c465927236216a6c65fa9b06767c27a6de..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;
@@ -21,12 +22,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M
  * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
  */
 public class 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 {
@@ -34,14 +36,15 @@ public class FlowRegistryKeyFactory {
         private final int priority;
         private final BigInteger cookie;
         private final Match match;
-        private static final Match EMPTY_MATCH = new MatchBuilder().build();
+        private final short version;
 
-        private 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 ? EMPTY_MATCH : flow.getMatch();
+            match = MoreObjects.firstNonNull(flow.getMatch(), OFConstants.EMPTY_MATCH);
             cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
+            this.version = version;
         }
 
         @Override
@@ -58,13 +61,15 @@ public class FlowRegistryKeyFactory {
 
             return getPriority() == that.getPriority() &&
                     getTableId() == that.getTableId() &&
-                    getMatch().equals(that.getMatch());
+                    getCookie().equals(that.getCookie()) &&
+                    MatchComparatorFactory.createMatch().areObjectsEqual(version, getMatch(), that.getMatch());
         }
 
         @Override
         public int hashCode() {
             int result = tableId;
             result = 31 * result + priority;
+            result = 31 * result + cookie.hashCode();
             result = 31 * result + match.hashCode();
             return result;
         }