Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame^] | 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | import org.openflow.exceptions.OFParseError; |
| 5 | |
| 6 | /** |
| 7 | * EtherType field representation. |
| 8 | * |
| 9 | * @author Yotam Harchol (yotam.harchol@bigswitch.com) |
| 10 | */ |
| 11 | public class EthType implements OFValueType { |
| 12 | static final int LENGTH = 2; |
| 13 | |
| 14 | private final int rawValue; |
| 15 | |
| 16 | static final int ETH_TYPE_VAL_IPv4 = 0x0800; // Internet Protocol version 4 (IPv4) |
| 17 | static final int ETH_TYPE_VAL_ARP = 0x0806; // Address Resolution Protocol (ARP) |
| 18 | static final int ETH_TYPE_VAL_WAKE_ON_LAN = 0x0842; // Wake-on-LAN[3] |
| 19 | static final int ETH_TYPE_VAL_TRILL = 0x22F3; // IETF TRILL Protocol |
| 20 | static final int ETH_TYPE_VAL_DECNET_IV = 0x6003; // DECnet Phase IV |
| 21 | static final int ETH_TYPE_VAL_REV_ARP = 0x8035; // Reverse Address Resolution Protocol |
| 22 | static final int ETH_TYPE_VAL_APPLE_TALK = 0x809B; // AppleTalk (Ethertalk) |
| 23 | static final int ETH_TYPE_VAL_APPLE_TALK_ARP = 0x80F3; // AppleTalk Address Resolution Protocol (AARP) |
| 24 | static final int ETH_TYPE_VAL_VLAN_FRAME = 0x8100; // VLAN-tagged frame (IEEE 802.1Q) & Shortest Path Bridging IEEE 802.1aq[4] |
| 25 | static final int ETH_TYPE_VAL_IPX_8137 = 0x8137; // IPX |
| 26 | static final int ETH_TYPE_VAL_IPX_8138 = 0x8138; // IPX |
| 27 | static final int ETH_TYPE_VAL_QNX = 0x8204; // QNX Qnet |
| 28 | static final int ETH_TYPE_VAL_IPv6 = 0x86DD; // Internet Protocol Version 6 (IPv6) |
| 29 | static final int ETH_TYPE_VAL_ETH_FLOW = 0x8808; // Ethernet flow control |
| 30 | static final int ETH_TYPE_VAL_SLOW_PROTOCOLS = 0x8809; // Slow Protocols (IEEE 802.3) |
| 31 | static final int ETH_TYPE_VAL_COBRANET = 0x8819; // CobraNet |
| 32 | static final int ETH_TYPE_VAL_MPLS_UNICAST = 0x8847; // MPLS unicast |
| 33 | static final int ETH_TYPE_VAL_MPLS_MULTICAST = 0x8848; // MPLS multicast |
| 34 | static final int ETH_TYPE_VAL_PPPoE_DISCOVERY = 0x8863; // PPPoE Discovery Stage |
| 35 | static final int ETH_TYPE_VAL_PPPoE_SESSION = 0x8864; // PPPoE Session Stage |
| 36 | static final int ETH_TYPE_VAL_JUMBO_FRAMES = 0x8870; // Jumbo Frames |
| 37 | static final int ETH_TYPE_VAL_HOMEPLUG_10 = 0x887B; // HomePlug 1.0 MME |
| 38 | static final int ETH_TYPE_VAL_EAP_OVER_LAN = 0x888E; // EAP over LAN (IEEE 802.1X) |
| 39 | static final int ETH_TYPE_VAL_PROFINET = 0x8892; // PROFINET Protocol |
| 40 | static final int ETH_TYPE_VAL_HYPERSCSI = 0x889A; // HyperSCSI (SCSI over Ethernet) |
| 41 | static final int ETH_TYPE_VAL_ATA_OVER_ETH = 0x88A2; // ATA over Ethernet |
| 42 | static final int ETH_TYPE_VAL_ETHERCAT = 0x88A4; // EtherCAT Protocol |
| 43 | static final int ETH_TYPE_VAL_BRIDGING = 0x88A8; // Provider Bridging (IEEE 802.1ad) & Shortest Path Bridging IEEE 802.1aq[5] |
| 44 | static final int ETH_TYPE_VAL_POWERLINK = 0x88AB; // Ethernet Powerlink[citation needed] |
| 45 | static final int ETH_TYPE_VAL_LLDP = 0x88CC; // Link Layer Discovery Protocol (LLDP) |
| 46 | static final int ETH_TYPE_VAL_SERCOS = 0x88CD; // SERCOS III |
| 47 | static final int ETH_TYPE_VAL_HOMEPLUG_AV = 0x88E1; // HomePlug AV MME[citation needed] |
| 48 | static final int ETH_TYPE_VAL_MRP = 0x88E3; // Media Redundancy Protocol (IEC62439-2) |
| 49 | static final int ETH_TYPE_VAL_MAC_SEC = 0x88E5; // MAC security (IEEE 802.1AE) |
| 50 | static final int ETH_TYPE_VAL_PTP = 0x88F7; // Precision Time Protocol (IEEE 1588) |
| 51 | static final int ETH_TYPE_VAL_CFM = 0x8902; // IEEE 802.1ag Connectivity Fault Management (CFM) Protocol / ITU-T Recommendation Y.1731 (OAM) |
| 52 | static final int ETH_TYPE_VAL_FCoE = 0x8906; // Fibre Channel over Ethernet (FCoE) |
| 53 | static final int ETH_TYPE_VAL_FCoE_INIT = 0x8914; // FCoE Initialization Protocol |
| 54 | static final int ETH_TYPE_VAL_RoCE = 0x8915; // RDMA over Converged Ethernet (RoCE) |
| 55 | static final int ETH_TYPE_VAL_HSR = 0x892F; // High-availability Seamless Redundancy (HSR) |
| 56 | static final int ETH_TYPE_VAL_CONF_TEST = 0x9000; // Ethernet Configuration Testing Protocol[6] |
| 57 | static final int ETH_TYPE_VAL_Q_IN_Q = 0x9100; // Q-in-Q |
| 58 | static final int ETH_TYPE_VAL_LLT = 0xCAFE; // Veritas Low Latency Transport (LLT)[7] for Veritas Cluster Server |
| 59 | |
| 60 | public static final EthType ETH_TYPE_IPv4 = new EthType(ETH_TYPE_VAL_IPv4); |
| 61 | public static final EthType ETH_TYPE_ARP = new EthType(ETH_TYPE_VAL_ARP); |
| 62 | public static final EthType ETH_TYPE_WAKE_ON_LAN = new EthType(ETH_TYPE_VAL_WAKE_ON_LAN); |
| 63 | public static final EthType ETH_TYPE_TRILL = new EthType(ETH_TYPE_VAL_TRILL); |
| 64 | public static final EthType ETH_TYPE_DECNET_IV = new EthType(ETH_TYPE_VAL_DECNET_IV); |
| 65 | public static final EthType ETH_TYPE_REV_ARP = new EthType(ETH_TYPE_VAL_REV_ARP ); |
| 66 | public static final EthType ETH_TYPE_APPLE_TALK = new EthType(ETH_TYPE_VAL_APPLE_TALK); |
| 67 | public static final EthType ETH_TYPE_APPLE_TALK_ARP = new EthType(ETH_TYPE_VAL_APPLE_TALK_ARP); |
| 68 | public static final EthType ETH_TYPE_VLAN_FRAME = new EthType(ETH_TYPE_VAL_VLAN_FRAME ); |
| 69 | public static final EthType ETH_TYPE_IPX_8137 = new EthType(ETH_TYPE_VAL_IPX_8137 ); |
| 70 | public static final EthType ETH_TYPE_IPX_8138 = new EthType(ETH_TYPE_VAL_IPX_8138 ); |
| 71 | public static final EthType ETH_TYPE_QNX = new EthType(ETH_TYPE_VAL_QNX ); |
| 72 | public static final EthType ETH_TYPE_IPv6 = new EthType(ETH_TYPE_VAL_IPv6 ); |
| 73 | public static final EthType ETH_TYPE_ETH_FLOW = new EthType(ETH_TYPE_VAL_ETH_FLOW); |
| 74 | public static final EthType ETH_TYPE_SLOW_PROTOCOLS = new EthType(ETH_TYPE_VAL_SLOW_PROTOCOLS ); |
| 75 | public static final EthType ETH_TYPE_COBRANET = new EthType(ETH_TYPE_VAL_COBRANET ); |
| 76 | public static final EthType ETH_TYPE_MPLS_UNICAST = new EthType(ETH_TYPE_VAL_MPLS_UNICAST ); |
| 77 | public static final EthType ETH_TYPE_MPLS_MULTICAST = new EthType(ETH_TYPE_VAL_MPLS_MULTICAST ); |
| 78 | public static final EthType ETH_TYPE_PPPoE_DISCOVERY = new EthType(ETH_TYPE_VAL_PPPoE_DISCOVERY); |
| 79 | public static final EthType ETH_TYPE_PPPoE_SESSION = new EthType(ETH_TYPE_VAL_PPPoE_SESSION ); |
| 80 | public static final EthType ETH_TYPE_JUMBO_FRAMES = new EthType(ETH_TYPE_VAL_JUMBO_FRAMES ); |
| 81 | public static final EthType ETH_TYPE_HOMEPLUG_10 = new EthType(ETH_TYPE_VAL_HOMEPLUG_10 ); |
| 82 | public static final EthType ETH_TYPE_EAP_OVER_LAN = new EthType(ETH_TYPE_VAL_EAP_OVER_LAN ); |
| 83 | public static final EthType ETH_TYPE_PROFINET = new EthType(ETH_TYPE_VAL_PROFINET ); |
| 84 | public static final EthType ETH_TYPE_HYPERSCSI = new EthType(ETH_TYPE_VAL_HYPERSCSI ); |
| 85 | public static final EthType ETH_TYPE_ATA_OVER_ETH = new EthType(ETH_TYPE_VAL_ATA_OVER_ETH); |
| 86 | public static final EthType ETH_TYPE_ETHERCAT = new EthType(ETH_TYPE_VAL_ETHERCAT ); |
| 87 | public static final EthType ETH_TYPE_BRIDGING = new EthType(ETH_TYPE_VAL_BRIDGING ); |
| 88 | public static final EthType ETH_TYPE_POWERLINK = new EthType(ETH_TYPE_VAL_POWERLINK ); |
| 89 | public static final EthType ETH_TYPE_LLDP = new EthType(ETH_TYPE_VAL_LLDP ); |
| 90 | public static final EthType ETH_TYPE_SERCOS = new EthType(ETH_TYPE_VAL_SERCOS ); |
| 91 | public static final EthType ETH_TYPE_HOMEPLUG_AV = new EthType(ETH_TYPE_VAL_HOMEPLUG_AV ); |
| 92 | public static final EthType ETH_TYPE_MRP = new EthType(ETH_TYPE_VAL_MRP ); |
| 93 | public static final EthType ETH_TYPE_MAC_SEC = new EthType(ETH_TYPE_VAL_MAC_SEC); |
| 94 | public static final EthType ETH_TYPE_PTP = new EthType(ETH_TYPE_VAL_PTP ); |
| 95 | public static final EthType ETH_TYPE_CFM = new EthType(ETH_TYPE_VAL_CFM ); |
| 96 | public static final EthType ETH_TYPE_FCoE = new EthType(ETH_TYPE_VAL_FCoE ); |
| 97 | public static final EthType ETH_TYPE_FCoE_INIT = new EthType(ETH_TYPE_VAL_FCoE_INIT ); |
| 98 | public static final EthType ETH_TYPE_RoCE = new EthType(ETH_TYPE_VAL_RoCE ); |
| 99 | public static final EthType ETH_TYPE_HSR = new EthType(ETH_TYPE_VAL_HSR ); |
| 100 | public static final EthType ETH_TYPE_CONF_TEST = new EthType(ETH_TYPE_VAL_CONF_TEST ); |
| 101 | public static final EthType ETH_TYPE_Q_IN_Q = new EthType(ETH_TYPE_VAL_Q_IN_Q ); |
| 102 | public static final EthType ETH_TYPE_LLT = new EthType(ETH_TYPE_VAL_LLT ); |
| 103 | |
| 104 | private EthType(int type) { |
| 105 | this.rawValue = type; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public int getLength() { |
| 110 | return LENGTH; |
| 111 | } |
| 112 | |
| 113 | volatile byte[] bytesCache = null; |
| 114 | |
| 115 | @Override |
| 116 | public byte[] getBytes() { |
| 117 | if (bytesCache == null) { |
| 118 | synchronized (this) { |
| 119 | if (bytesCache == null) { |
| 120 | bytesCache = new byte[] { |
| 121 | (byte) ((rawValue >>> 8) & 0xFF), |
| 122 | (byte) ((rawValue >>> 0) & 0xFF) |
| 123 | }; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | return bytesCache; |
| 128 | } |
| 129 | |
| 130 | public static EthType of(int type) { |
| 131 | switch (type) { |
| 132 | case ETH_TYPE_VAL_IPv4: |
| 133 | return ETH_TYPE_IPv4; |
| 134 | case ETH_TYPE_VAL_ARP: |
| 135 | return ETH_TYPE_ARP; |
| 136 | case ETH_TYPE_VAL_WAKE_ON_LAN: |
| 137 | return ETH_TYPE_WAKE_ON_LAN; |
| 138 | case ETH_TYPE_VAL_TRILL: |
| 139 | return ETH_TYPE_TRILL; |
| 140 | case ETH_TYPE_VAL_DECNET_IV: |
| 141 | return ETH_TYPE_DECNET_IV; |
| 142 | case ETH_TYPE_VAL_REV_ARP: |
| 143 | return ETH_TYPE_REV_ARP; |
| 144 | case ETH_TYPE_VAL_APPLE_TALK: |
| 145 | return ETH_TYPE_APPLE_TALK; |
| 146 | case ETH_TYPE_VAL_APPLE_TALK_ARP: |
| 147 | return ETH_TYPE_APPLE_TALK_ARP; |
| 148 | case ETH_TYPE_VAL_VLAN_FRAME: |
| 149 | return ETH_TYPE_VLAN_FRAME; |
| 150 | case ETH_TYPE_VAL_IPX_8137: |
| 151 | return ETH_TYPE_IPX_8137; |
| 152 | case ETH_TYPE_VAL_IPX_8138: |
| 153 | return ETH_TYPE_IPX_8138; |
| 154 | case ETH_TYPE_VAL_QNX: |
| 155 | return ETH_TYPE_QNX; |
| 156 | case ETH_TYPE_VAL_IPv6: |
| 157 | return ETH_TYPE_IPv6; |
| 158 | case ETH_TYPE_VAL_ETH_FLOW: |
| 159 | return ETH_TYPE_ETH_FLOW; |
| 160 | case ETH_TYPE_VAL_SLOW_PROTOCOLS: |
| 161 | return ETH_TYPE_SLOW_PROTOCOLS; |
| 162 | case ETH_TYPE_VAL_COBRANET: |
| 163 | return ETH_TYPE_COBRANET; |
| 164 | case ETH_TYPE_VAL_MPLS_UNICAST: |
| 165 | return ETH_TYPE_MPLS_UNICAST; |
| 166 | case ETH_TYPE_VAL_MPLS_MULTICAST: |
| 167 | return ETH_TYPE_MPLS_MULTICAST; |
| 168 | case ETH_TYPE_VAL_PPPoE_DISCOVERY: |
| 169 | return ETH_TYPE_PPPoE_DISCOVERY; |
| 170 | case ETH_TYPE_VAL_PPPoE_SESSION: |
| 171 | return ETH_TYPE_PPPoE_SESSION; |
| 172 | case ETH_TYPE_VAL_JUMBO_FRAMES: |
| 173 | return ETH_TYPE_JUMBO_FRAMES; |
| 174 | case ETH_TYPE_VAL_HOMEPLUG_10: |
| 175 | return ETH_TYPE_HOMEPLUG_10; |
| 176 | case ETH_TYPE_VAL_EAP_OVER_LAN: |
| 177 | return ETH_TYPE_EAP_OVER_LAN; |
| 178 | case ETH_TYPE_VAL_PROFINET: |
| 179 | return ETH_TYPE_PROFINET; |
| 180 | case ETH_TYPE_VAL_HYPERSCSI: |
| 181 | return ETH_TYPE_HYPERSCSI; |
| 182 | case ETH_TYPE_VAL_ATA_OVER_ETH: |
| 183 | return ETH_TYPE_ATA_OVER_ETH; |
| 184 | case ETH_TYPE_VAL_ETHERCAT: |
| 185 | return ETH_TYPE_ETHERCAT; |
| 186 | case ETH_TYPE_VAL_BRIDGING: |
| 187 | return ETH_TYPE_BRIDGING; |
| 188 | case ETH_TYPE_VAL_POWERLINK: |
| 189 | return ETH_TYPE_POWERLINK; |
| 190 | case ETH_TYPE_VAL_LLDP: |
| 191 | return ETH_TYPE_LLDP; |
| 192 | case ETH_TYPE_VAL_SERCOS: |
| 193 | return ETH_TYPE_SERCOS; |
| 194 | case ETH_TYPE_VAL_HOMEPLUG_AV: |
| 195 | return ETH_TYPE_HOMEPLUG_AV; |
| 196 | case ETH_TYPE_VAL_MRP: |
| 197 | return ETH_TYPE_MRP; |
| 198 | case ETH_TYPE_VAL_MAC_SEC: |
| 199 | return ETH_TYPE_MAC_SEC; |
| 200 | case ETH_TYPE_VAL_PTP: |
| 201 | return ETH_TYPE_PTP; |
| 202 | case ETH_TYPE_VAL_CFM: |
| 203 | return ETH_TYPE_CFM; |
| 204 | case ETH_TYPE_VAL_FCoE: |
| 205 | return ETH_TYPE_FCoE; |
| 206 | case ETH_TYPE_VAL_FCoE_INIT: |
| 207 | return ETH_TYPE_FCoE_INIT; |
| 208 | case ETH_TYPE_VAL_RoCE: |
| 209 | return ETH_TYPE_RoCE; |
| 210 | case ETH_TYPE_VAL_HSR: |
| 211 | return ETH_TYPE_HSR; |
| 212 | case ETH_TYPE_VAL_CONF_TEST: |
| 213 | return ETH_TYPE_CONF_TEST; |
| 214 | case ETH_TYPE_VAL_Q_IN_Q: |
| 215 | return ETH_TYPE_Q_IN_Q; |
| 216 | case ETH_TYPE_VAL_LLT: |
| 217 | return ETH_TYPE_LLT; |
| 218 | default: |
| 219 | // TODO: What's here? |
| 220 | return new EthType(type); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public boolean equals(Object obj) { |
| 226 | if (!(obj instanceof EthType)) |
| 227 | return false; |
| 228 | EthType o = (EthType)obj; |
| 229 | if (o.rawValue != this.rawValue) |
| 230 | return false; |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public int hashCode() { |
| 236 | final int prime = 37; |
| 237 | int result = 1; |
| 238 | result = prime * result + rawValue; |
| 239 | return result; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public String toString() { |
| 244 | return Integer.toHexString(rawValue); |
| 245 | } |
| 246 | |
| 247 | public static final Serializer<EthType> SERIALIZER_V10 = new SerializerV10(); |
| 248 | public static final Serializer<EthType> SERIALIZER_V11 = SERIALIZER_V10; |
| 249 | public static final Serializer<EthType> SERIALIZER_V12 = SERIALIZER_V10; |
| 250 | public static final Serializer<EthType> SERIALIZER_V13 = SERIALIZER_V10; |
| 251 | |
| 252 | private static class SerializerV10 implements OFValueType.Serializer<EthType> { |
| 253 | |
| 254 | @Override |
| 255 | public void writeTo(EthType value, ChannelBuffer c) { |
| 256 | c.writeShort(value.rawValue); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public EthType readFrom(ChannelBuffer c) throws OFParseError { |
| 261 | return EthType.of(c.readUnsignedShort()); |
| 262 | } |
| 263 | |
| 264 | } |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 265 | |
| 266 | } |