blob: 7031a0dd8c28778f33f9831f3aa16c0ce6b7e651 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4
Andreas Wundsam85c961f2013-09-29 21:22:12 -07005import com.google.common.primitives.UnsignedInts;
6
Yotam Harcholf3f11152013-09-05 16:47:16 -07007
8/**
9 * EtherType field representation.
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -070010 *
Yotam Harcholf3f11152013-09-05 16:47:16 -070011 * @author Yotam Harchol (yotam.harchol@bigswitch.com)
12 */
13public class EthType implements OFValueType<EthType> {
14 static final int LENGTH = 2;
15
16 private final int rawValue;
17
Andreas Wundsamb70b0442013-09-23 14:44:43 -070018 static final int VAL_IPv4 = 0x0800; // Internet Protocol version 4 (IPv4)
19 static final int VAL_ARP = 0x0806; // Address Resolution Protocol (ARP)
20 static final int VAL_WAKE_ON_LAN = 0x0842; // Wake-on-LAN[3]
21 static final int VAL_TRILL = 0x22F3; // IETF TRILL Protocol
22 static final int VAL_DECNET_IV = 0x6003; // DECnet Phase IV
23 static final int VAL_REV_ARP = 0x8035; // Reverse Address Resolution Protocol
24 static final int VAL_APPLE_TALK = 0x809B; // AppleTalk (Ethertalk)
25 static final int VAL_APPLE_TALK_ARP = 0x80F3; // AppleTalk Address Resolution Protocol (AARP)
26 static final int VAL_VLAN_FRAME = 0x8100; // VLAN-tagged frame (IEEE 802.1Q) & Shortest Path Bridging IEEE 802.1aq[4]
27 static final int VAL_IPX_8137 = 0x8137; // IPX
28 static final int VAL_IPX_8138 = 0x8138; // IPX
29 static final int VAL_QNX = 0x8204; // QNX Qnet
30 static final int VAL_IPv6 = 0x86DD; // Internet Protocol Version 6 (IPv6)
31 static final int VAL_ETH_FLOW = 0x8808; // Ethernet flow control
32 static final int VAL_SLOW_PROTOCOLS = 0x8809; // Slow Protocols (IEEE 802.3)
33 static final int VAL_COBRANET = 0x8819; // CobraNet
34 static final int VAL_MPLS_UNICAST = 0x8847; // MPLS unicast
35 static final int VAL_MPLS_MULTICAST = 0x8848; // MPLS multicast
36 static final int VAL_PPPoE_DISCOVERY = 0x8863; // PPPoE Discovery Stage
37 static final int VAL_PPPoE_SESSION = 0x8864; // PPPoE Session Stage
38 static final int VAL_JUMBO_FRAMES = 0x8870; // Jumbo Frames
39 static final int VAL_HOMEPLUG_10 = 0x887B; // HomePlug 1.0 MME
40 static final int VAL_EAP_OVER_LAN = 0x888E; // EAP over LAN (IEEE 802.1X)
41 static final int VAL_PROFINET = 0x8892; // PROFINET Protocol
42 static final int VAL_HYPERSCSI = 0x889A; // HyperSCSI (SCSI over Ethernet)
43 static final int VAL_ATA_OVER_ETH = 0x88A2; // ATA over Ethernet
44 static final int VAL_ETHERCAT = 0x88A4; // EtherCAT Protocol
45 static final int VAL_BRIDGING = 0x88A8; // Provider Bridging (IEEE 802.1ad) & Shortest Path Bridging IEEE 802.1aq[5]
46 static final int VAL_POWERLINK = 0x88AB; // Ethernet Powerlink[citation needed]
47 static final int VAL_LLDP = 0x88CC; // Link Layer Discovery Protocol (LLDP)
48 static final int VAL_SERCOS = 0x88CD; // SERCOS III
49 static final int VAL_HOMEPLUG_AV = 0x88E1; // HomePlug AV MME[citation needed]
50 static final int VAL_MRP = 0x88E3; // Media Redundancy Protocol (IEC62439-2)
51 static final int VAL_MAC_SEC = 0x88E5; // MAC security (IEEE 802.1AE)
52 static final int VAL_PTP = 0x88F7; // Precision Time Protocol (IEEE 1588)
53 static final int VAL_CFM = 0x8902; // IEEE 802.1ag Connectivity Fault Management (CFM) Protocol / ITU-T Recommendation Y.1731 (OAM)
54 static final int VAL_FCoE = 0x8906; // Fibre Channel over Ethernet (FCoE)
55 static final int VAL_FCoE_INIT = 0x8914; // FCoE Initialization Protocol
56 static final int VAL_RoCE = 0x8915; // RDMA over Converged Ethernet (RoCE)
57 static final int VAL_HSR = 0x892F; // High-availability Seamless Redundancy (HSR)
58 static final int VAL_CONF_TEST = 0x9000; // Ethernet Configuration Testing Protocol[6]
59 static final int VAL_Q_IN_Q = 0x9100; // Q-in-Q
60 static final int VAL_LLT = 0xCAFE; // Veritas Low Latency Transport (LLT)[7] for Veritas Cluster Server
Yotam Harcholf3f11152013-09-05 16:47:16 -070061
Andreas Wundsamb70b0442013-09-23 14:44:43 -070062 public static final EthType IPv4 = new EthType(VAL_IPv4);
63 public static final EthType ARP = new EthType(VAL_ARP);
64 public static final EthType WAKE_ON_LAN = new EthType(VAL_WAKE_ON_LAN);
65 public static final EthType TRILL = new EthType(VAL_TRILL);
66 public static final EthType DECNET_IV = new EthType(VAL_DECNET_IV);
67 public static final EthType REV_ARP = new EthType(VAL_REV_ARP );
68 public static final EthType APPLE_TALK = new EthType(VAL_APPLE_TALK);
69 public static final EthType APPLE_TALK_ARP = new EthType(VAL_APPLE_TALK_ARP);
70 public static final EthType VLAN_FRAME = new EthType(VAL_VLAN_FRAME );
71 public static final EthType IPX_8137 = new EthType(VAL_IPX_8137 );
72 public static final EthType IPX_8138 = new EthType(VAL_IPX_8138 );
73 public static final EthType QNX = new EthType(VAL_QNX );
74 public static final EthType IPv6 = new EthType(VAL_IPv6 );
75 public static final EthType ETH_FLOW = new EthType(VAL_ETH_FLOW);
76 public static final EthType SLOW_PROTOCOLS = new EthType(VAL_SLOW_PROTOCOLS );
77 public static final EthType COBRANET = new EthType(VAL_COBRANET );
78 public static final EthType MPLS_UNICAST = new EthType(VAL_MPLS_UNICAST );
79 public static final EthType MPLS_MULTICAST = new EthType(VAL_MPLS_MULTICAST );
80 public static final EthType PPPoE_DISCOVERY = new EthType(VAL_PPPoE_DISCOVERY);
81 public static final EthType PPPoE_SESSION = new EthType(VAL_PPPoE_SESSION );
82 public static final EthType JUMBO_FRAMES = new EthType(VAL_JUMBO_FRAMES );
83 public static final EthType HOMEPLUG_10 = new EthType(VAL_HOMEPLUG_10 );
84 public static final EthType EAP_OVER_LAN = new EthType(VAL_EAP_OVER_LAN );
85 public static final EthType PROFINET = new EthType(VAL_PROFINET );
86 public static final EthType HYPERSCSI = new EthType(VAL_HYPERSCSI );
87 public static final EthType ATA_OVER_ETH = new EthType(VAL_ATA_OVER_ETH);
88 public static final EthType ETHERCAT = new EthType(VAL_ETHERCAT );
89 public static final EthType BRIDGING = new EthType(VAL_BRIDGING );
90 public static final EthType POWERLINK = new EthType(VAL_POWERLINK );
91 public static final EthType LLDP = new EthType(VAL_LLDP );
92 public static final EthType SERCOS = new EthType(VAL_SERCOS );
93 public static final EthType HOMEPLUG_AV = new EthType(VAL_HOMEPLUG_AV );
94 public static final EthType MRP = new EthType(VAL_MRP );
95 public static final EthType MAC_SEC = new EthType(VAL_MAC_SEC);
96 public static final EthType PTP = new EthType(VAL_PTP );
97 public static final EthType CFM = new EthType(VAL_CFM );
98 public static final EthType FCoE = new EthType(VAL_FCoE );
99 public static final EthType FCoE_INIT = new EthType(VAL_FCoE_INIT );
100 public static final EthType RoCE = new EthType(VAL_RoCE );
101 public static final EthType HSR = new EthType(VAL_HSR );
102 public static final EthType CONF_TEST = new EthType(VAL_CONF_TEST );
103 public static final EthType Q_IN_Q = new EthType(VAL_Q_IN_Q );
104 public static final EthType LLT = new EthType(VAL_LLT );
105
106
107 private static final int NONE_VAL = 0x0;
108 public static final EthType NONE = new EthType(NONE_VAL);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700109
110 public static final EthType NO_MASK = new EthType(0xFFFFFFFF);
111 public static final EthType FULL_MASK = new EthType(0x00000000);
112
113 private EthType(int type) {
114 this.rawValue = type;
115 }
116
117 @Override
118 public int getLength() {
119 return LENGTH;
120 }
121
122 public static EthType of(int type) {
123 switch (type) {
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700124 case NONE_VAL:
125 return NONE;
126 case VAL_IPv4:
127 return IPv4;
128 case VAL_ARP:
129 return ARP;
130 case VAL_WAKE_ON_LAN:
131 return WAKE_ON_LAN;
132 case VAL_TRILL:
133 return TRILL;
134 case VAL_DECNET_IV:
135 return DECNET_IV;
136 case VAL_REV_ARP:
137 return REV_ARP;
138 case VAL_APPLE_TALK:
139 return APPLE_TALK;
140 case VAL_APPLE_TALK_ARP:
141 return APPLE_TALK_ARP;
142 case VAL_VLAN_FRAME:
143 return VLAN_FRAME;
144 case VAL_IPX_8137:
145 return IPX_8137;
146 case VAL_IPX_8138:
147 return IPX_8138;
148 case VAL_QNX:
149 return QNX;
150 case VAL_IPv6:
151 return IPv6;
152 case VAL_ETH_FLOW:
153 return ETH_FLOW;
154 case VAL_SLOW_PROTOCOLS:
155 return SLOW_PROTOCOLS;
156 case VAL_COBRANET:
157 return COBRANET;
158 case VAL_MPLS_UNICAST:
159 return MPLS_UNICAST;
160 case VAL_MPLS_MULTICAST:
161 return MPLS_MULTICAST;
162 case VAL_PPPoE_DISCOVERY:
163 return PPPoE_DISCOVERY;
164 case VAL_PPPoE_SESSION:
165 return PPPoE_SESSION;
166 case VAL_JUMBO_FRAMES:
167 return JUMBO_FRAMES;
168 case VAL_HOMEPLUG_10:
169 return HOMEPLUG_10;
170 case VAL_EAP_OVER_LAN:
171 return EAP_OVER_LAN;
172 case VAL_PROFINET:
173 return PROFINET;
174 case VAL_HYPERSCSI:
175 return HYPERSCSI;
176 case VAL_ATA_OVER_ETH:
177 return ATA_OVER_ETH;
178 case VAL_ETHERCAT:
179 return ETHERCAT;
180 case VAL_BRIDGING:
181 return BRIDGING;
182 case VAL_POWERLINK:
183 return POWERLINK;
184 case VAL_LLDP:
185 return LLDP;
186 case VAL_SERCOS:
187 return SERCOS;
188 case VAL_HOMEPLUG_AV:
189 return HOMEPLUG_AV;
190 case VAL_MRP:
191 return MRP;
192 case VAL_MAC_SEC:
193 return MAC_SEC;
194 case VAL_PTP:
195 return PTP;
196 case VAL_CFM:
197 return CFM;
198 case VAL_FCoE:
199 return FCoE;
200 case VAL_FCoE_INIT:
201 return FCoE_INIT;
202 case VAL_RoCE:
203 return RoCE;
204 case VAL_HSR:
205 return HSR;
206 case VAL_CONF_TEST:
207 return CONF_TEST;
208 case VAL_Q_IN_Q:
209 return Q_IN_Q;
210 case VAL_LLT:
211 return LLT;
Yotam Harcholf3f11152013-09-05 16:47:16 -0700212 default:
213 // TODO: What's here?
214 return new EthType(type);
215 }
216 }
217
218 @Override
Yotam Harcholf3f11152013-09-05 16:47:16 -0700219 public String toString() {
220 return Integer.toHexString(rawValue);
221 }
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700222
Yotam Harcholf3f11152013-09-05 16:47:16 -0700223 public void write2Bytes(ChannelBuffer c) {
224 c.writeShort(this.rawValue);
225 }
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700226
Yotam Harcholf3f11152013-09-05 16:47:16 -0700227 public static EthType read2Bytes(ChannelBuffer c) {
228 return EthType.of(c.readUnsignedShort());
229 }
230
231 @Override
232 public EthType applyMask(EthType mask) {
233 return EthType.of(this.rawValue & mask.rawValue);
234 }
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700235
Yotam Harcholf3f11152013-09-05 16:47:16 -0700236 public int getValue() {
237 return rawValue;
238 }
239
Andreas Wundsam85c961f2013-09-29 21:22:12 -0700240 @Override
241 public boolean equals(Object obj) {
242 if (!(obj instanceof EthType))
243 return false;
244 EthType o = (EthType)obj;
245 if (o.rawValue != this.rawValue)
246 return false;
247 return true;
248 }
249
250 @Override
251 public int hashCode() {
252 final int prime = 37;
253 int result = 1;
254 result = prime * result + rawValue;
255 return result;
256 }
257
258 @Override
259 public int compareTo(EthType o) {
260 return UnsignedInts.compare(rawValue, o.rawValue);
261 }
262
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700263
Yotam Harcholf3f11152013-09-05 16:47:16 -0700264}