3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.action;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
17 import org.apache.commons.lang3.builder.EqualsBuilder;
18 import org.apache.commons.lang3.builder.HashCodeBuilder;
19 import org.opendaylight.controller.sal.utils.EtherTypes;
22 * Insert a 802.1q (outermost) header action
23 * Execute it multiple times to achieve QinQ
25 * 802.1q = [TPID(16) + TCI(16)]
26 * TCI = [PCP(3) + CFI(1) + VID(12)]
32 @XmlAccessorType(XmlAccessType.NONE)
34 public class PushVlan extends Action {
35 private int tag; // TPID - 16 bits
36 private int pcp; // PCP - 3 bits
37 private int cfi; // CFI - 1 bit (drop eligible)
38 private int vlanId; // VID - 12 bits
39 private transient int tci; // TCI = [PCP + CFI + VID] - 16 bits
40 private transient int header; // full 802.1q header [TPID + TCI] - 32 bits
42 /* Dummy constructor for JAXB */
46 public PushVlan(int tag, int pcp, int cfi, int vlanId) {
47 type = ActionType.PUSH_VLAN;
52 this.tci = createTci();
53 this.header = createHeader();
57 public PushVlan(EtherTypes tag, int pcp, int cfi, int vlanId) {
58 type = ActionType.PUSH_VLAN;
59 this.tag = tag.intValue();
63 this.tci = createTci();
64 this.header = createHeader();
68 private int createTci() {
69 return (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
72 private int createHeader() {
73 return (tag & 0xffff) << 16 | (pcp & 0x7) << 13 | (cfi & 0x1) << 12
77 private void runChecks() {
78 checkValue(ActionType.SET_DL_TYPE, tag);
79 checkValue(ActionType.SET_VLAN_PCP, pcp);
80 checkValue(ActionType.SET_VLAN_CFI, cfi);
81 checkValue(ActionType.SET_VLAN_ID, vlanId);
84 // Run action specific check which cannot be run by parent
85 if (tag != EtherTypes.VLANTAGGED.intValue()
86 && tag != EtherTypes.QINQ.intValue()
87 && tag != EtherTypes.OLDQINQ.intValue()
88 && tag != EtherTypes.CISCOQINQ.intValue()) {
89 // pass a value which will tell fail and tell something about the original wrong value
90 checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
95 * Returns the VID portion of the 802.1q header this action will insert
99 public int getVlanId() {
104 * Returns the CFI portion of the 802.1q header this action will insert
108 public int getCfi() {
113 * Returns the vlan PCP portion of the 802.1q header this action will insert
117 public int getPcp() {
122 * Returns the TPID portion of the 802.1q header this action will insert
125 public int getTag() {
130 * Returns the TCI portion of the 802.1q header this action will insert
131 * TCI = [PCP + CFI + VID] - (16 bits)
134 public int getTci() {
139 * Returns the full 802.1q header this action will insert
140 * header = [TPID + TIC] (32 bits)
144 @XmlElement(name="VlanHeader")
145 public int getHeader() {
150 public boolean equals(Object other) {
151 return EqualsBuilder.reflectionEquals(this, other);
155 public int hashCode() {
156 return HashCodeBuilder.reflectionHashCode(this);
160 public String toString() {
161 return type + "[tag = " + tag + ", pcp = " + pcp + ", cfi = " + cfi
162 + ", vlanId = " + vlanId + "]";