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