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