Revert "Merge "Bug 6235 - Cookie compare in FlowRegistryKeyFactory""
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowRegistryKeyFactory.java
index 08f128e5b5d298705a1c3cd7d9b3ca1970897cec..1a9948a2bd1137036ce9af73f678550595784c57 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 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;
 
 /**
  * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
@@ -25,7 +26,7 @@ public class FlowRegistryKeyFactory {
     public FlowRegistryKeyFactory() {
     }
 
-    public static FlowRegistryKey create(Flow flow) {
+    public static FlowRegistryKey create(final Flow flow) {
         return new FlowRegistryKeyDto(flow);
     }
 
@@ -37,29 +38,33 @@ public class FlowRegistryKeyFactory {
         private final Match match;
 
         public FlowRegistryKeyDto(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 = Preconditions.checkNotNull(flow.getPriority(), "flow priority must not be null");
-            match = Preconditions.checkNotNull(flow.getMatch(), "Match value must not be null");
+            priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY);
+            match = flow.getMatch()==null? new MatchBuilder().build(): flow.getMatch();
             cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
         }
 
         @Override
         public boolean equals(final Object o) {
-            if (this == o) return true;
-            if (o == null || getClass() != o.getClass()) return false;
+            if (this == o) {
+                return true;
+            }
 
-            final FlowRegistryKeyDto that = (FlowRegistryKeyDto) o;
+            if (o == null || !(o instanceof FlowRegistryKey)) {
+                return false;
+            }
 
-            if (priority != that.priority) return false;
-            if (tableId != that.tableId) return false;
-            if (!match.equals(that.match)) return false;
+            final FlowRegistryKey that = (FlowRegistryKey) o;
 
-            return true;
+            return getPriority() == that.getPriority() &&
+                    getTableId() == that.getTableId() &&
+                    getMatch().equals(that.getMatch());
         }
 
         @Override
         public int hashCode() {
-            int result = (int) tableId;
+            int result = tableId;
             result = 31 * result + priority;
             result = 31 * result + match.hashCode();
             return result;
@@ -79,5 +84,10 @@ public class FlowRegistryKeyFactory {
         public BigInteger getCookie() {
             return cookie;
         }
+
+        @Override
+        public Match getMatch() {
+            return match;
+        }
     }
 }