Merge "Enable AD-SAL application to configure OF 1.3 PUSH_VLAN action."
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / action / PushVlan.java
index d50851ae49705df37bf61c5f143c3cdc7d87051d..a1b50edd5116fcc8a451d86ae2dff61d5f2b643e 100644 (file)
@@ -1,6 +1,5 @@
-
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 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,
@@ -14,24 +13,18 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.utils.EtherTypes;
 
 /**
- * Insert a 802.1q (outermost) header action
- * Execute it multiple times to achieve QinQ
- *
- * 802.1q = [TPID(16) + TCI(16)]
- *                     TCI = [PCP(3) + CFI(1) + VID(12)]
- *
- *
+ * Insert a 802.1q (outermost) header action Execute it multiple times to
+ * achieve QinQ
  *
+ * 802.1q = [TPID(16) + TCI(16)] TCI = [PCP(3) + CFI(1) + VID(12)]
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-
 public class PushVlan extends Action {
+    private static final long serialVersionUID = 1L;
     private int tag; // TPID - 16 bits
     private int pcp; // PCP - 3 bits
     private int cfi; // CFI - 1 bit (drop eligible)
@@ -40,7 +33,8 @@ public class PushVlan extends Action {
     private transient int header; // full 802.1q header [TPID + TCI] - 32 bits
 
     /* Dummy constructor for JAXB */
-    private PushVlan () {
+    @SuppressWarnings("unused")
+    private PushVlan() {
     }
 
     public PushVlan(int tag, int pcp, int cfi, int vlanId) {
@@ -65,13 +59,38 @@ public class PushVlan extends Action {
         runChecks();
     }
 
+    /**
+     * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
+     *
+     * @param tag  An {@link EtherTypes} instance.
+     */
+    public PushVlan(EtherTypes tag) {
+        this(tag.intValue());
+    }
+
+    /**
+     * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
+     *
+     * @param tag  An ethernet type of a new VLAN tag.
+     */
+    public PushVlan(int tag) {
+        type = ActionType.PUSH_VLAN;
+        this.tag = tag;
+
+        if (tag != EtherTypes.VLANTAGGED.intValue() &&
+            tag != EtherTypes.QINQ.intValue()) {
+            // pass a value which will tell fail and tell something about the
+            // original wrong value
+            checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
+        }
+    }
+
     private int createTci() {
         return (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
     }
 
     private int createHeader() {
-        return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12
-                | (vlanId & 0xfff);
+        return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
     }
 
     private void runChecks() {
@@ -82,18 +101,18 @@ public class PushVlan extends Action {
         checkValue(tci);
 
         // Run action specific check which cannot be run by parent
-        if (tag != EtherTypes.VLANTAGGED.intValue()
-                && tag != EtherTypes.QINQ.intValue()
-                && tag != EtherTypes.OLDQINQ.intValue()
-                && tag != EtherTypes.CISCOQINQ.intValue()) {
-            // pass a value which will tell fail and tell something about the original wrong value
+        if (tag != EtherTypes.VLANTAGGED.intValue() && tag != EtherTypes.QINQ.intValue()
+                && tag != EtherTypes.OLDQINQ.intValue() && tag != EtherTypes.CISCOQINQ.intValue()) {
+            // pass a value which will tell fail and tell something about the
+            // original wrong value
             checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
         }
     }
 
     /**
-     * Returns the VID portion of the 802.1q header this action will insert
-     * VID - (12 bits)
+     * Returns the VID portion of the 802.1q header this action will insert VID
+     * - (12 bits)
+     *
      * @return byte[]
      */
     public int getVlanId() {
@@ -101,8 +120,9 @@ public class PushVlan extends Action {
     }
 
     /**
-     * Returns the CFI portion of the 802.1q header this action will insert
-     * CFI - (1 bit)
+     * Returns the CFI portion of the 802.1q header this action will insert CFI
+     * - (1 bit)
+     *
      * @return
      */
     public int getCfi() {
@@ -112,6 +132,7 @@ public class PushVlan extends Action {
     /**
      * Returns the vlan PCP portion of the 802.1q header this action will insert
      * PCP - (3 bits)
+     *
      * @return byte[]
      */
     public int getPcp() {
@@ -127,8 +148,9 @@ public class PushVlan extends Action {
     }
 
     /**
-     * Returns the TCI portion of the 802.1q header this action will insert
-     * TCI = [PCP + CFI + VID] - (16 bits)
+     * Returns the TCI portion of the 802.1q header this action will insert TCI
+     * = [PCP + CFI + VID] - (16 bits)
+     *
      * @return
      */
     public int getTci() {
@@ -136,30 +158,57 @@ public class PushVlan extends Action {
     }
 
     /**
-     * Returns the full 802.1q header this action will insert
-     * header = [TPID + TIC] (32 bits)
+     * Returns the full 802.1q header this action will insert header = [TPID +
+     * TIC] (32 bits)
      *
      * @return int
      */
-    @XmlElement(name="VlanHeader")
+    @XmlElement(name = "VlanHeader")
     public int getHeader() {
         return header;
     }
 
     @Override
-    public boolean equals(Object other) {
-        return EqualsBuilder.reflectionEquals(this, other);
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        PushVlan other = (PushVlan) obj;
+        if (cfi != other.cfi) {
+            return false;
+        }
+        if (pcp != other.pcp) {
+            return false;
+        }
+        if (tag != other.tag) {
+            return false;
+        }
+        if (vlanId != other.vlanId) {
+            return false;
+        }
+        return true;
     }
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + cfi;
+        result = prime * result + pcp;
+        result = prime * result + tag;
+        result = prime * result + vlanId;
+        return result;
     }
 
     @Override
     public String toString() {
-        return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi
-                + ", vlanId = " + vlanId + "]";
+        return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi + ", vlanId = " + vlanId + "]";
     }
 
 }