Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / packet / IEEE8021Q.java
1 /*
2  * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.sal.packet;
10
11 import java.util.HashMap;
12 import java.util.LinkedHashMap;
13 import java.util.Map;
14
15 import org.apache.commons.lang3.tuple.ImmutablePair;
16 import org.apache.commons.lang3.tuple.Pair;
17 import org.opendaylight.controller.sal.match.Match;
18 import org.opendaylight.controller.sal.match.MatchType;
19
20 /**
21  * Class that represents the IEEE 802.1Q objects
22  */
23 @Deprecated
24 public class IEEE8021Q extends Packet {
25     private static final String PCP = "PriorityCodePoint";
26     private static final String CFI = "CanonicalFormatIndicator";
27     private static final String VID = "VlanIdentifier";
28     private static final String ETHT = "EtherType";
29
30     private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
31         private static final long serialVersionUID = 1L;
32         {
33             put(PCP, new ImmutablePair<Integer, Integer>(0, 3));
34             put(CFI, new ImmutablePair<Integer, Integer>(3, 1));
35             put(VID, new ImmutablePair<Integer, Integer>(4, 12));
36             put(ETHT, new ImmutablePair<Integer, Integer>(16, 16));
37         }
38     };
39     private final Map<String, byte[]> fieldValues;
40
41     /**
42      * Default constructor that creates and sets the HashMap
43      */
44     public IEEE8021Q() {
45         super();
46         fieldValues = new HashMap<String, byte[]>();
47         hdrFieldCoordMap = fieldCoordinates;
48         hdrFieldsMap = fieldValues;
49     }
50
51     /**
52      * Constructor that sets the access level for the packet and creates and
53      * sets the HashMap
54      */
55     public IEEE8021Q(boolean writeAccess) {
56         super(writeAccess);
57         fieldValues = new HashMap<String, byte[]>();
58         hdrFieldCoordMap = fieldCoordinates;
59         hdrFieldsMap = fieldValues;
60     }
61
62     @Override
63     /**
64      * Store the value read from data stream in hdrFieldMap
65      */
66     public void setHeaderField(String headerField, byte[] readValue) {
67         if (headerField.equals(ETHT)) {
68             payloadClass = Ethernet.etherTypeClassMap.get(BitBufferHelper.getShort(readValue));
69         }
70         hdrFieldsMap.put(headerField, readValue);
71     }
72
73     /**
74      * Gets the priority code point(PCP) stored
75      *
76      * @return byte - the PCP
77      */
78     public byte getPcp() {
79         return BitBufferHelper.getByte(fieldValues.get(PCP));
80     }
81
82     /**
83      * Gets the canonical format indicator(CFI) stored
84      *
85      * @return byte - the CFI
86      */
87     public byte getCfi() {
88         return BitBufferHelper.getByte(fieldValues.get(CFI));
89     }
90
91     /**
92      * Gets the VLAN identifier(VID) stored
93      *
94      * @return short - the VID
95      */
96     public short getVid() {
97         return BitBufferHelper.getShort(fieldValues.get(VID));
98     }
99
100     /**
101      * Gets the etherType stored
102      *
103      * @return short - the etherType
104      */
105     public short getEtherType() {
106         return BitBufferHelper.getShort(fieldValues.get(ETHT));
107     }
108
109     /**
110      * Sets the priority code point(PCP) for the current IEEE 802.1Q object
111      * instance
112      *
113      * @param byte - the PCP to set
114      */
115     public IEEE8021Q setPcp(byte pcp) {
116         byte[] priorityCodePoint = BitBufferHelper.toByteArray(pcp);
117         fieldValues.put(PCP, priorityCodePoint);
118         return this;
119     }
120
121     /**
122      * Sets the canonical format indicator(CFI) for the current IEEE 802.1Q
123      * object instance
124      *
125      * @param byte - the CFI to set
126      */
127     public IEEE8021Q setCfi(byte cfi) {
128         byte[] canonicalFormatIndicator = BitBufferHelper.toByteArray(cfi);
129         fieldValues.put(CFI, canonicalFormatIndicator);
130         return this;
131     }
132
133     /**
134      * Sets the VLAN identifier(VID) for the current IEEE 802.1Q instance
135      *
136      * @param short - the VID to set
137      */
138     public IEEE8021Q setVid(short vid) {
139         byte[] vlanIdentifier = BitBufferHelper.toByteArray(vid);
140         fieldValues.put(VID, vlanIdentifier);
141         return this;
142     }
143
144     /**
145      * Sets the etherType for the current IEEE 802.1Q object instance
146      *
147      * @param short - the etherType to set
148      */
149     public IEEE8021Q setEtherType(short etherType) {
150         byte[] ethType = BitBufferHelper.toByteArray(etherType);
151         fieldValues.put(ETHT, ethType);
152         return this;
153     }
154
155     @Override
156     public void populateMatch(Match match) {
157         match.setField(MatchType.DL_VLAN, this.getVid());
158         match.setField(MatchType.DL_VLAN_PR, this.getPcp());
159         match.setField(MatchType.DL_TYPE, this.getEtherType());
160     }
161
162     /**
163      * Gets the header size in bits
164      * @return The .1Q header size in bits
165      */
166     @Override
167     public int getHeaderSize() {
168         return 32;
169     }
170
171 }