Fixed a bug that failed specifying the value 0 on VLAN ID field for a match condition...
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / match / Match.java
index 2ead8cdbc4b7e645b6d6a0a6d0ae8039c08923f2..9bab8391986df5a82dfc6b3aeeab51155eb84f88 100644 (file)
@@ -38,8 +38,8 @@ import org.opendaylight.controller.sal.utils.NetUtils;
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class Match implements Cloneable, Serializable {
-       private static final long serialVersionUID = 1L;
-       private static final Map<MatchType, MatchType> reversableMatches;
+        private static final long serialVersionUID = 1L;
+        private static final Map<MatchType, MatchType> reversableMatches;
     static {
         Map<MatchType, MatchType> map = new HashMap<MatchType, MatchType>();
         map.put(MatchType.DL_SRC, MatchType.DL_DST);
@@ -67,9 +67,9 @@ public class Match implements Cloneable, Serializable {
      * Generic setter for frame/packet/message's header fields against which to match
      * Note: For MAC addresses, please pass the cloned value to this function
      *
-     * @param type             packet's header field type
-     * @param value    field's value to assign to the match
-     * @param mask             field's bitmask to apply to the match (has to be of the same class type of value)
+     * @param type      packet's header field type
+     * @param value     field's value to assign to the match
+     * @param mask      field's bitmask to apply to the match (has to be of the same class type of value)
      */
     public void setField(MatchType type, Object value, Object mask) {
         MatchField field = new MatchField(type, value, mask);
@@ -83,8 +83,8 @@ public class Match implements Cloneable, Serializable {
      * Generic setter for frame/packet/message's header fields against which to match
      * Note: For MAC addresses, please pass the cloned value to this function
      *
-     * @param type             packet's header field type
-     * @param value    field's value to assign to the match
+     * @param type      packet's header field type
+     * @param value     field's value to assign to the match
      */
     public void setField(MatchType type, Object value) {
         MatchField field = new MatchField(type, value);
@@ -117,7 +117,7 @@ public class Match implements Cloneable, Serializable {
     /**
      * Generic getter for fields against which the match is programmed
      *
-     * @param type     frame/packet/message's header field type
+     * @param type  frame/packet/message's header field type
      * @return
      */
     public MatchField getField(MatchType type) {
@@ -137,7 +137,7 @@ public class Match implements Cloneable, Serializable {
     /**
      * Returns the list of MatchType fields the match is set for
      *
-     * @return List of individual MatchType fields. 
+     * @return List of individual MatchType fields.
      */
     public List<MatchType> getMatchesList() {
         return new ArrayList<MatchType>(fields.keySet());
@@ -146,13 +146,13 @@ public class Match implements Cloneable, Serializable {
     /**
      * Returns the list of MatchFields the match is set for
      *
-     * @return List of individual MatchField values. 
+     * @return List of individual MatchField values.
      */
     @XmlElement(name="matchField")
     public List<MatchField> getMatchFields() {
-       return new ArrayList<MatchField>(fields.values());
+        return new ArrayList<MatchField>(fields.values());
     }
-    
+
     /**
      * Returns whether this match is for an IPv6 flow
      */
@@ -202,6 +202,7 @@ public class Match implements Cloneable, Serializable {
         Match cloned = null;
         try {
             cloned = (Match) super.clone();
+            cloned.matches = matches;
             cloned.fields = new HashMap<MatchType, MatchField>();
             for (Entry<MatchType, MatchField> entry : this.fields.entrySet()) {
                 cloned.fields.put(entry.getKey(), entry.getValue().clone());
@@ -225,13 +226,14 @@ public class Match implements Cloneable, Serializable {
         Match reverse = this.clone();
 
         // Flip symmetric fields
-        for (Map.Entry<MatchType, MatchType> entry : Match.reversableMatches
-                .entrySet()) {
+        for (Map.Entry<MatchType, MatchType> entry : Match.reversableMatches.entrySet()) {
             MatchType from = entry.getKey();
             MatchType to = entry.getValue();
             if (this.isPresent(from)) {
-                reverse.setField(to, this.getField(from).getValue(), this
-                        .getField(from).getMask());
+                reverse.setField(to, this.getField(from).getValue(), this.getField(from).getMask());
+                if (!this.isPresent(to)) {
+                    reverse.clearField(from);
+                }
             }
         }
 
@@ -344,20 +346,26 @@ public class Match implements Cloneable, Serializable {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         Match other = (Match) obj;
         if (fields == null) {
-            if (other.fields != null)
+            if (other.fields != null) {
                 return false;
-        } else if (!fields.equals(other.fields))
+            }
+        } else if (!fields.equals(other.fields)) {
             return false;
-        if (matches != other.matches)
+        }
+        if (matches != other.matches) {
             return false;
+        }
         return true;
     }