2 * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.action;
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElement;
14 import javax.xml.bind.annotation.XmlRootElement;
16 import org.opendaylight.controller.sal.utils.EtherTypes;
19 * Insert a 802.1q (outermost) header action Execute it multiple times to
22 * 802.1q = [TPID(16) + TCI(16)] TCI = [PCP(3) + CFI(1) + VID(12)]
25 @XmlAccessorType(XmlAccessType.NONE)
27 public class PushVlan extends Action {
28 private static final long serialVersionUID = 1L;
29 private int tag; // TPID - 16 bits
30 private int pcp; // PCP - 3 bits
31 private int cfi; // CFI - 1 bit (drop eligible)
32 private int vlanId; // VID - 12 bits
33 private transient int tci; // TCI = [PCP + CFI + VID] - 16 bits
34 private transient int header; // full 802.1q header [TPID + TCI] - 32 bits
36 /* Dummy constructor for JAXB */
37 @SuppressWarnings("unused")
41 public PushVlan(int tag, int pcp, int cfi, int vlanId) {
42 type = ActionType.PUSH_VLAN;
47 this.tci = createTci();
48 this.header = createHeader();
52 public PushVlan(EtherTypes tag, int pcp, int cfi, int vlanId) {
53 type = ActionType.PUSH_VLAN;
54 this.tag = tag.intValue();
58 this.tci = createTci();
59 this.header = createHeader();
64 * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
66 * @param tag An {@link EtherTypes} instance.
68 public PushVlan(EtherTypes tag) {
73 * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
75 * @param tag An ethernet type of a new VLAN tag.
77 public PushVlan(int tag) {
78 type = ActionType.PUSH_VLAN;
81 if (tag != EtherTypes.VLANTAGGED.intValue() &&
82 tag != EtherTypes.QINQ.intValue()) {
83 // pass a value which will tell fail and tell something about the
84 // original wrong value
85 checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
89 private int createTci() {
90 return (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
93 private int createHeader() {
94 return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
97 private void runChecks() {
98 checkValue(ActionType.SET_DL_TYPE, tag);
99 checkValue(ActionType.SET_VLAN_PCP, pcp);
100 checkValue(ActionType.SET_VLAN_CFI, cfi);
101 checkValue(ActionType.SET_VLAN_ID, vlanId);
104 // Run action specific check which cannot be run by parent
105 if (tag != EtherTypes.VLANTAGGED.intValue() && tag != EtherTypes.QINQ.intValue()
106 && tag != EtherTypes.OLDQINQ.intValue() && tag != EtherTypes.CISCOQINQ.intValue()) {
107 // pass a value which will tell fail and tell something about the
108 // original wrong value
109 checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
114 * Returns the VID portion of the 802.1q header this action will insert VID
119 public int getVlanId() {
124 * Returns the CFI portion of the 802.1q header this action will insert CFI
129 public int getCfi() {
134 * Returns the vlan PCP portion of the 802.1q header this action will insert
139 public int getPcp() {
144 * Returns the TPID portion of the 802.1q header this action will insert
147 public int getTag() {
152 * Returns the TCI portion of the 802.1q header this action will insert TCI
153 * = [PCP + CFI + VID] - (16 bits)
157 public int getTci() {
162 * Returns the full 802.1q header this action will insert header = [TPID +
167 @XmlElement(name = "VlanHeader")
168 public int getHeader() {
173 public boolean equals(Object obj) {
177 if (!super.equals(obj)) {
180 if (getClass() != obj.getClass()) {
183 PushVlan other = (PushVlan) obj;
184 if (cfi != other.cfi) {
187 if (pcp != other.pcp) {
190 if (tag != other.tag) {
193 if (vlanId != other.vlanId) {
200 public int hashCode() {
201 final int prime = 31;
202 int result = super.hashCode();
203 result = prime * result + cfi;
204 result = prime * result + pcp;
205 result = prime * result + tag;
206 result = prime * result + vlanId;
211 public String toString() {
212 return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi + ", vlanId = " + vlanId + "]";