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)
26 public class PushVlan extends Action {
27 private static final long serialVersionUID = 1L;
28 private int tag; // TPID - 16 bits
29 private int pcp; // PCP - 3 bits
30 private int cfi; // CFI - 1 bit (drop eligible)
31 private int vlanId; // VID - 12 bits
32 private transient int tci; // TCI = [PCP + CFI + VID] - 16 bits
33 private transient int header; // full 802.1q header [TPID + TCI] - 32 bits
35 /* Dummy constructor for JAXB */
36 @SuppressWarnings("unused")
40 public PushVlan(int tag, int pcp, int cfi, int vlanId) {
41 type = ActionType.PUSH_VLAN;
46 this.tci = createTci();
47 this.header = createHeader();
51 public PushVlan(EtherTypes tag, int pcp, int cfi, int vlanId) {
52 type = ActionType.PUSH_VLAN;
53 this.tag = tag.intValue();
57 this.tci = createTci();
58 this.header = createHeader();
63 * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
65 * @param tag An {@link EtherTypes} instance.
67 public PushVlan(EtherTypes tag) {
72 * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
74 * @param tag An ethernet type of a new VLAN tag.
76 public PushVlan(int tag) {
77 type = ActionType.PUSH_VLAN;
80 if (tag != EtherTypes.VLANTAGGED.intValue() &&
81 tag != EtherTypes.QINQ.intValue()) {
82 // pass a value which will tell fail and tell something about the
83 // original wrong value
84 checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
88 private int createTci() {
89 return (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
92 private int createHeader() {
93 return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
96 private void runChecks() {
97 checkValue(ActionType.SET_DL_TYPE, tag);
98 checkValue(ActionType.SET_VLAN_PCP, pcp);
99 checkValue(ActionType.SET_VLAN_CFI, cfi);
100 checkValue(ActionType.SET_VLAN_ID, vlanId);
103 // Run action specific check which cannot be run by parent
104 if (tag != EtherTypes.VLANTAGGED.intValue() && tag != EtherTypes.QINQ.intValue()
105 && tag != EtherTypes.OLDQINQ.intValue() && tag != EtherTypes.CISCOQINQ.intValue()) {
106 // pass a value which will tell fail and tell something about the
107 // original wrong value
108 checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
113 * Returns the VID portion of the 802.1q header this action will insert VID
118 public int getVlanId() {
123 * Returns the CFI portion of the 802.1q header this action will insert CFI
128 public int getCfi() {
133 * Returns the vlan PCP portion of the 802.1q header this action will insert
138 public int getPcp() {
143 * Returns the TPID portion of the 802.1q header this action will insert
146 public int getTag() {
151 * Returns the TCI portion of the 802.1q header this action will insert TCI
152 * = [PCP + CFI + VID] - (16 bits)
156 public int getTci() {
161 * Returns the full 802.1q header this action will insert header = [TPID +
166 @XmlElement(name = "VlanHeader")
167 public int getHeader() {
172 public boolean equals(Object obj) {
176 if (!super.equals(obj)) {
179 if (getClass() != obj.getClass()) {
182 PushVlan other = (PushVlan) obj;
183 if (cfi != other.cfi) {
186 if (pcp != other.pcp) {
189 if (tag != other.tag) {
192 if (vlanId != other.vlanId) {
199 public int hashCode() {
200 final int prime = 31;
201 int result = super.hashCode();
202 result = prime * result + cfi;
203 result = prime * result + pcp;
204 result = prime * result + tag;
205 result = prime * result + vlanId;
210 public String toString() {
211 return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi + ", vlanId = " + vlanId + "]";