Updated Java types according to new design
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
index b6e8317..cc191ab 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
@@ -2,18 +2,15 @@
import org.openflow.types.EthType;
import org.openflow.types.IPv4;
-import org.openflow.types.IPv4WithMask;
import org.openflow.types.IPv6;
-import org.openflow.types.IPv6WithMask;
import org.openflow.types.IpProtocol;
import org.openflow.types.MacAddress;
-import org.openflow.types.MacAddressWithMask;
+import org.openflow.types.Masked;
import org.openflow.types.OFPort;
import org.openflow.types.U16;
import org.openflow.types.U8;
import org.openflow.types.VlanPcp;
import org.openflow.types.VlanVid;
-import org.openflow.types.VlanVidWithMask.VlanVidWithMask;
public class MatchField<F, M> {
private final String name;
@@ -36,18 +33,20 @@
public final static MatchField<OFPort, NoMatch> METADATA =
new MatchField<OFPort, NoMatch>("metadata");
- public final static MatchField<MacAddress, MacAddressWithMask> ETH_DST =
- new MatchField<MacAddress, MacAddressWithMask>("eth_dst");
- public final static MatchField<MacAddress, MacAddressWithMask> ETH_SRC =
- new MatchField<MacAddress, MacAddressWithMask>("eth_src", 1);
+ public final static MatchField<MacAddress, Masked<MacAddress>> ETH_DST =
+ new MatchField<MacAddress, Masked<MacAddress>>("eth_dst");
+ public final static MatchField<MacAddress, Masked<MacAddress>> ETH_SRC =
+ new MatchField<MacAddress, Masked<MacAddress>>("eth_src", 1);
public final static MatchField<EthType, NoMatch> ETH_TYPE =
new MatchField<EthType, NoMatch>("eth_type");
- public final static MatchField<VlanVid, VlanVidWithMask> VLAN_VID =
- new MatchField<VlanVid, VlanVidWithMask>("vlan_vid");
+
+ public final static MatchField<VlanVid, Masked<VlanVid>> VLAN_VID =
+ new MatchField<VlanVid, Masked<VlanVid>>("vlan_vid");
public final static MatchField<VlanPcp, NoMatch> VLAN_PCP =
new MatchField<VlanPcp, NoMatch>("vlan_pcp");
-
+
+
public final static MatchField<NoMatch, NoMatch> IP_DSCP =
new MatchField<NoMatch, NoMatch>("ip_dscp");
public final static MatchField<NoMatch, NoMatch> IP_ECN =
@@ -55,10 +54,10 @@
public final static MatchField<IpProtocol, NoMatch> IP_PROTO =
new MatchField<IpProtocol, NoMatch>("ip_proto");
- public final static MatchField<IPv4, IPv4WithMask> IPV4_SRC =
- new MatchField<IPv4, IPv4WithMask>("ipv4_src");
- public final static MatchField<IPv4, IPv4WithMask> IPV4_DST =
- new MatchField<IPv4, IPv4WithMask>("ipv4_dst");
+ public final static MatchField<IPv4, Masked<IPv4>> IPV4_SRC =
+ new MatchField<IPv4, Masked<IPv4>>("ipv4_src");
+ public final static MatchField<IPv4, Masked<IPv4>> IPV4_DST =
+ new MatchField<IPv4, Masked<IPv4>>("ipv4_dst");
public final static MatchField<U16, NoMatch> TCP_SRC = new MatchField<U16, NoMatch>(
"tcp_src");
@@ -82,22 +81,23 @@
public final static MatchField<U16, NoMatch> ARP_OP = new MatchField<U16, NoMatch>(
"arp_op");
- public final static MatchField<IPv4, IPv4WithMask> ARP_SPA =
- new MatchField<IPv4, IPv4WithMask>("arp_spa");
- public final static MatchField<IPv4, IPv4WithMask> ARP_TPA =
- new MatchField<IPv4, IPv4WithMask>("arp_tpa");
- public final static MatchField<MacAddress, MacAddressWithMask> ARP_SHA =
- new MatchField<MacAddress, MacAddressWithMask>("arp_sha");
- public final static MatchField<MacAddress, MacAddressWithMask> ARP_THA =
- new MatchField<MacAddress, MacAddressWithMask>("arp_tha");
+ public final static MatchField<IPv4, Masked<IPv4>> ARP_SPA =
+ new MatchField<IPv4, Masked<IPv4>>("arp_spa");
+ public final static MatchField<IPv4, Masked<IPv4>> ARP_TPA =
+ new MatchField<IPv4, Masked<IPv4>>("arp_tpa");
+ public final static MatchField<MacAddress, Masked<MacAddress>> ARP_SHA =
+ new MatchField<MacAddress, Masked<MacAddress>>("arp_sha");
+ public final static MatchField<MacAddress, Masked<MacAddress>> ARP_THA =
+ new MatchField<MacAddress, Masked<MacAddress>>("arp_tha");
- public final static MatchField<IPv6, IPv6WithMask> IPV6_SRC =
- new MatchField<IPv6, IPv6WithMask>("ipv6_src");
- public final static MatchField<IPv6, IPv6WithMask> IPV6_DST =
- new MatchField<IPv6, IPv6WithMask>("ipv6_dst");
+ public final static MatchField<IPv6, Masked<IPv6>> IPV6_SRC =
+ new MatchField<IPv6, Masked<IPv6>>("ipv6_src");
+ public final static MatchField<IPv6, Masked<IPv6>> IPV6_DST =
+ new MatchField<IPv6, Masked<IPv6>>("ipv6_dst");
- public final static MatchField<U8, IPv6WithMask> IPV6_FLABEL =
- new MatchField<U8, IPv6WithMask>("ipv6_flabel");
+ // FIXME: Wrong masked type?
+ public final static MatchField<U8, Masked<IPv6>> IPV6_FLABEL =
+ new MatchField<U8, Masked<IPv6>>("ipv6_flabel");
public String getName() {
return name;
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java b/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
index d319e57..b86a38f 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
@@ -1,5 +1,266 @@
package org.openflow.types;
-public class EthType {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+
+/**
+ * EtherType field representation.
+ *
+ * @author Yotam Harchol (yotam.harchol@bigswitch.com)
+ */
+public class EthType implements OFValueType {
+ static final int LENGTH = 2;
+
+ private final int rawValue;
+
+ static final int ETH_TYPE_VAL_IPv4 = 0x0800; // Internet Protocol version 4 (IPv4)
+ static final int ETH_TYPE_VAL_ARP = 0x0806; // Address Resolution Protocol (ARP)
+ static final int ETH_TYPE_VAL_WAKE_ON_LAN = 0x0842; // Wake-on-LAN[3]
+ static final int ETH_TYPE_VAL_TRILL = 0x22F3; // IETF TRILL Protocol
+ static final int ETH_TYPE_VAL_DECNET_IV = 0x6003; // DECnet Phase IV
+ static final int ETH_TYPE_VAL_REV_ARP = 0x8035; // Reverse Address Resolution Protocol
+ static final int ETH_TYPE_VAL_APPLE_TALK = 0x809B; // AppleTalk (Ethertalk)
+ static final int ETH_TYPE_VAL_APPLE_TALK_ARP = 0x80F3; // AppleTalk Address Resolution Protocol (AARP)
+ static final int ETH_TYPE_VAL_VLAN_FRAME = 0x8100; // VLAN-tagged frame (IEEE 802.1Q) & Shortest Path Bridging IEEE 802.1aq[4]
+ static final int ETH_TYPE_VAL_IPX_8137 = 0x8137; // IPX
+ static final int ETH_TYPE_VAL_IPX_8138 = 0x8138; // IPX
+ static final int ETH_TYPE_VAL_QNX = 0x8204; // QNX Qnet
+ static final int ETH_TYPE_VAL_IPv6 = 0x86DD; // Internet Protocol Version 6 (IPv6)
+ static final int ETH_TYPE_VAL_ETH_FLOW = 0x8808; // Ethernet flow control
+ static final int ETH_TYPE_VAL_SLOW_PROTOCOLS = 0x8809; // Slow Protocols (IEEE 802.3)
+ static final int ETH_TYPE_VAL_COBRANET = 0x8819; // CobraNet
+ static final int ETH_TYPE_VAL_MPLS_UNICAST = 0x8847; // MPLS unicast
+ static final int ETH_TYPE_VAL_MPLS_MULTICAST = 0x8848; // MPLS multicast
+ static final int ETH_TYPE_VAL_PPPoE_DISCOVERY = 0x8863; // PPPoE Discovery Stage
+ static final int ETH_TYPE_VAL_PPPoE_SESSION = 0x8864; // PPPoE Session Stage
+ static final int ETH_TYPE_VAL_JUMBO_FRAMES = 0x8870; // Jumbo Frames
+ static final int ETH_TYPE_VAL_HOMEPLUG_10 = 0x887B; // HomePlug 1.0 MME
+ static final int ETH_TYPE_VAL_EAP_OVER_LAN = 0x888E; // EAP over LAN (IEEE 802.1X)
+ static final int ETH_TYPE_VAL_PROFINET = 0x8892; // PROFINET Protocol
+ static final int ETH_TYPE_VAL_HYPERSCSI = 0x889A; // HyperSCSI (SCSI over Ethernet)
+ static final int ETH_TYPE_VAL_ATA_OVER_ETH = 0x88A2; // ATA over Ethernet
+ static final int ETH_TYPE_VAL_ETHERCAT = 0x88A4; // EtherCAT Protocol
+ static final int ETH_TYPE_VAL_BRIDGING = 0x88A8; // Provider Bridging (IEEE 802.1ad) & Shortest Path Bridging IEEE 802.1aq[5]
+ static final int ETH_TYPE_VAL_POWERLINK = 0x88AB; // Ethernet Powerlink[citation needed]
+ static final int ETH_TYPE_VAL_LLDP = 0x88CC; // Link Layer Discovery Protocol (LLDP)
+ static final int ETH_TYPE_VAL_SERCOS = 0x88CD; // SERCOS III
+ static final int ETH_TYPE_VAL_HOMEPLUG_AV = 0x88E1; // HomePlug AV MME[citation needed]
+ static final int ETH_TYPE_VAL_MRP = 0x88E3; // Media Redundancy Protocol (IEC62439-2)
+ static final int ETH_TYPE_VAL_MAC_SEC = 0x88E5; // MAC security (IEEE 802.1AE)
+ static final int ETH_TYPE_VAL_PTP = 0x88F7; // Precision Time Protocol (IEEE 1588)
+ static final int ETH_TYPE_VAL_CFM = 0x8902; // IEEE 802.1ag Connectivity Fault Management (CFM) Protocol / ITU-T Recommendation Y.1731 (OAM)
+ static final int ETH_TYPE_VAL_FCoE = 0x8906; // Fibre Channel over Ethernet (FCoE)
+ static final int ETH_TYPE_VAL_FCoE_INIT = 0x8914; // FCoE Initialization Protocol
+ static final int ETH_TYPE_VAL_RoCE = 0x8915; // RDMA over Converged Ethernet (RoCE)
+ static final int ETH_TYPE_VAL_HSR = 0x892F; // High-availability Seamless Redundancy (HSR)
+ static final int ETH_TYPE_VAL_CONF_TEST = 0x9000; // Ethernet Configuration Testing Protocol[6]
+ static final int ETH_TYPE_VAL_Q_IN_Q = 0x9100; // Q-in-Q
+ static final int ETH_TYPE_VAL_LLT = 0xCAFE; // Veritas Low Latency Transport (LLT)[7] for Veritas Cluster Server
+
+ public static final EthType ETH_TYPE_IPv4 = new EthType(ETH_TYPE_VAL_IPv4);
+ public static final EthType ETH_TYPE_ARP = new EthType(ETH_TYPE_VAL_ARP);
+ public static final EthType ETH_TYPE_WAKE_ON_LAN = new EthType(ETH_TYPE_VAL_WAKE_ON_LAN);
+ public static final EthType ETH_TYPE_TRILL = new EthType(ETH_TYPE_VAL_TRILL);
+ public static final EthType ETH_TYPE_DECNET_IV = new EthType(ETH_TYPE_VAL_DECNET_IV);
+ public static final EthType ETH_TYPE_REV_ARP = new EthType(ETH_TYPE_VAL_REV_ARP );
+ public static final EthType ETH_TYPE_APPLE_TALK = new EthType(ETH_TYPE_VAL_APPLE_TALK);
+ public static final EthType ETH_TYPE_APPLE_TALK_ARP = new EthType(ETH_TYPE_VAL_APPLE_TALK_ARP);
+ public static final EthType ETH_TYPE_VLAN_FRAME = new EthType(ETH_TYPE_VAL_VLAN_FRAME );
+ public static final EthType ETH_TYPE_IPX_8137 = new EthType(ETH_TYPE_VAL_IPX_8137 );
+ public static final EthType ETH_TYPE_IPX_8138 = new EthType(ETH_TYPE_VAL_IPX_8138 );
+ public static final EthType ETH_TYPE_QNX = new EthType(ETH_TYPE_VAL_QNX );
+ public static final EthType ETH_TYPE_IPv6 = new EthType(ETH_TYPE_VAL_IPv6 );
+ public static final EthType ETH_TYPE_ETH_FLOW = new EthType(ETH_TYPE_VAL_ETH_FLOW);
+ public static final EthType ETH_TYPE_SLOW_PROTOCOLS = new EthType(ETH_TYPE_VAL_SLOW_PROTOCOLS );
+ public static final EthType ETH_TYPE_COBRANET = new EthType(ETH_TYPE_VAL_COBRANET );
+ public static final EthType ETH_TYPE_MPLS_UNICAST = new EthType(ETH_TYPE_VAL_MPLS_UNICAST );
+ public static final EthType ETH_TYPE_MPLS_MULTICAST = new EthType(ETH_TYPE_VAL_MPLS_MULTICAST );
+ public static final EthType ETH_TYPE_PPPoE_DISCOVERY = new EthType(ETH_TYPE_VAL_PPPoE_DISCOVERY);
+ public static final EthType ETH_TYPE_PPPoE_SESSION = new EthType(ETH_TYPE_VAL_PPPoE_SESSION );
+ public static final EthType ETH_TYPE_JUMBO_FRAMES = new EthType(ETH_TYPE_VAL_JUMBO_FRAMES );
+ public static final EthType ETH_TYPE_HOMEPLUG_10 = new EthType(ETH_TYPE_VAL_HOMEPLUG_10 );
+ public static final EthType ETH_TYPE_EAP_OVER_LAN = new EthType(ETH_TYPE_VAL_EAP_OVER_LAN );
+ public static final EthType ETH_TYPE_PROFINET = new EthType(ETH_TYPE_VAL_PROFINET );
+ public static final EthType ETH_TYPE_HYPERSCSI = new EthType(ETH_TYPE_VAL_HYPERSCSI );
+ public static final EthType ETH_TYPE_ATA_OVER_ETH = new EthType(ETH_TYPE_VAL_ATA_OVER_ETH);
+ public static final EthType ETH_TYPE_ETHERCAT = new EthType(ETH_TYPE_VAL_ETHERCAT );
+ public static final EthType ETH_TYPE_BRIDGING = new EthType(ETH_TYPE_VAL_BRIDGING );
+ public static final EthType ETH_TYPE_POWERLINK = new EthType(ETH_TYPE_VAL_POWERLINK );
+ public static final EthType ETH_TYPE_LLDP = new EthType(ETH_TYPE_VAL_LLDP );
+ public static final EthType ETH_TYPE_SERCOS = new EthType(ETH_TYPE_VAL_SERCOS );
+ public static final EthType ETH_TYPE_HOMEPLUG_AV = new EthType(ETH_TYPE_VAL_HOMEPLUG_AV );
+ public static final EthType ETH_TYPE_MRP = new EthType(ETH_TYPE_VAL_MRP );
+ public static final EthType ETH_TYPE_MAC_SEC = new EthType(ETH_TYPE_VAL_MAC_SEC);
+ public static final EthType ETH_TYPE_PTP = new EthType(ETH_TYPE_VAL_PTP );
+ public static final EthType ETH_TYPE_CFM = new EthType(ETH_TYPE_VAL_CFM );
+ public static final EthType ETH_TYPE_FCoE = new EthType(ETH_TYPE_VAL_FCoE );
+ public static final EthType ETH_TYPE_FCoE_INIT = new EthType(ETH_TYPE_VAL_FCoE_INIT );
+ public static final EthType ETH_TYPE_RoCE = new EthType(ETH_TYPE_VAL_RoCE );
+ public static final EthType ETH_TYPE_HSR = new EthType(ETH_TYPE_VAL_HSR );
+ public static final EthType ETH_TYPE_CONF_TEST = new EthType(ETH_TYPE_VAL_CONF_TEST );
+ public static final EthType ETH_TYPE_Q_IN_Q = new EthType(ETH_TYPE_VAL_Q_IN_Q );
+ public static final EthType ETH_TYPE_LLT = new EthType(ETH_TYPE_VAL_LLT );
+
+ private EthType(int type) {
+ this.rawValue = type;
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache = null;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache = new byte[] {
+ (byte) ((rawValue >>> 8) & 0xFF),
+ (byte) ((rawValue >>> 0) & 0xFF)
+ };
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ public static EthType of(int type) {
+ switch (type) {
+ case ETH_TYPE_VAL_IPv4:
+ return ETH_TYPE_IPv4;
+ case ETH_TYPE_VAL_ARP:
+ return ETH_TYPE_ARP;
+ case ETH_TYPE_VAL_WAKE_ON_LAN:
+ return ETH_TYPE_WAKE_ON_LAN;
+ case ETH_TYPE_VAL_TRILL:
+ return ETH_TYPE_TRILL;
+ case ETH_TYPE_VAL_DECNET_IV:
+ return ETH_TYPE_DECNET_IV;
+ case ETH_TYPE_VAL_REV_ARP:
+ return ETH_TYPE_REV_ARP;
+ case ETH_TYPE_VAL_APPLE_TALK:
+ return ETH_TYPE_APPLE_TALK;
+ case ETH_TYPE_VAL_APPLE_TALK_ARP:
+ return ETH_TYPE_APPLE_TALK_ARP;
+ case ETH_TYPE_VAL_VLAN_FRAME:
+ return ETH_TYPE_VLAN_FRAME;
+ case ETH_TYPE_VAL_IPX_8137:
+ return ETH_TYPE_IPX_8137;
+ case ETH_TYPE_VAL_IPX_8138:
+ return ETH_TYPE_IPX_8138;
+ case ETH_TYPE_VAL_QNX:
+ return ETH_TYPE_QNX;
+ case ETH_TYPE_VAL_IPv6:
+ return ETH_TYPE_IPv6;
+ case ETH_TYPE_VAL_ETH_FLOW:
+ return ETH_TYPE_ETH_FLOW;
+ case ETH_TYPE_VAL_SLOW_PROTOCOLS:
+ return ETH_TYPE_SLOW_PROTOCOLS;
+ case ETH_TYPE_VAL_COBRANET:
+ return ETH_TYPE_COBRANET;
+ case ETH_TYPE_VAL_MPLS_UNICAST:
+ return ETH_TYPE_MPLS_UNICAST;
+ case ETH_TYPE_VAL_MPLS_MULTICAST:
+ return ETH_TYPE_MPLS_MULTICAST;
+ case ETH_TYPE_VAL_PPPoE_DISCOVERY:
+ return ETH_TYPE_PPPoE_DISCOVERY;
+ case ETH_TYPE_VAL_PPPoE_SESSION:
+ return ETH_TYPE_PPPoE_SESSION;
+ case ETH_TYPE_VAL_JUMBO_FRAMES:
+ return ETH_TYPE_JUMBO_FRAMES;
+ case ETH_TYPE_VAL_HOMEPLUG_10:
+ return ETH_TYPE_HOMEPLUG_10;
+ case ETH_TYPE_VAL_EAP_OVER_LAN:
+ return ETH_TYPE_EAP_OVER_LAN;
+ case ETH_TYPE_VAL_PROFINET:
+ return ETH_TYPE_PROFINET;
+ case ETH_TYPE_VAL_HYPERSCSI:
+ return ETH_TYPE_HYPERSCSI;
+ case ETH_TYPE_VAL_ATA_OVER_ETH:
+ return ETH_TYPE_ATA_OVER_ETH;
+ case ETH_TYPE_VAL_ETHERCAT:
+ return ETH_TYPE_ETHERCAT;
+ case ETH_TYPE_VAL_BRIDGING:
+ return ETH_TYPE_BRIDGING;
+ case ETH_TYPE_VAL_POWERLINK:
+ return ETH_TYPE_POWERLINK;
+ case ETH_TYPE_VAL_LLDP:
+ return ETH_TYPE_LLDP;
+ case ETH_TYPE_VAL_SERCOS:
+ return ETH_TYPE_SERCOS;
+ case ETH_TYPE_VAL_HOMEPLUG_AV:
+ return ETH_TYPE_HOMEPLUG_AV;
+ case ETH_TYPE_VAL_MRP:
+ return ETH_TYPE_MRP;
+ case ETH_TYPE_VAL_MAC_SEC:
+ return ETH_TYPE_MAC_SEC;
+ case ETH_TYPE_VAL_PTP:
+ return ETH_TYPE_PTP;
+ case ETH_TYPE_VAL_CFM:
+ return ETH_TYPE_CFM;
+ case ETH_TYPE_VAL_FCoE:
+ return ETH_TYPE_FCoE;
+ case ETH_TYPE_VAL_FCoE_INIT:
+ return ETH_TYPE_FCoE_INIT;
+ case ETH_TYPE_VAL_RoCE:
+ return ETH_TYPE_RoCE;
+ case ETH_TYPE_VAL_HSR:
+ return ETH_TYPE_HSR;
+ case ETH_TYPE_VAL_CONF_TEST:
+ return ETH_TYPE_CONF_TEST;
+ case ETH_TYPE_VAL_Q_IN_Q:
+ return ETH_TYPE_Q_IN_Q;
+ case ETH_TYPE_VAL_LLT:
+ return ETH_TYPE_LLT;
+ default:
+ // TODO: What's here?
+ return new EthType(type);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof EthType))
+ return false;
+ EthType o = (EthType)obj;
+ if (o.rawValue != this.rawValue)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 37;
+ int result = 1;
+ result = prime * result + rawValue;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toHexString(rawValue);
+ }
+
+ public static final Serializer<EthType> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<EthType> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<EthType> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<EthType> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<EthType> {
+
+ @Override
+ public void writeTo(EthType value, ChannelBuffer c) {
+ c.writeShort(value.rawValue);
+ }
+
+ @Override
+ public EthType readFrom(ChannelBuffer c) throws OFParseError {
+ return EthType.of(c.readUnsignedShort());
+ }
+
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
index 0583d6f..c05a7e3 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
@@ -1,14 +1,15 @@
package org.openflow.types;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFObject;
+import org.openflow.exceptions.OFParseError;
+
/**
* Wrapper around an IPv4 address
*
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
-public class IPv4 implements OFObject {
+public class IPv4 implements OFValueType {
static final int LENGTH = 4;
private final int rawValue;
@@ -55,6 +56,61 @@
}
return IPv4.of(raw);
}
+
+ public static OFValueType ofPossiblyMasked(final String string) {
+ int start = 0;
+ int shift = 24;
+ int slashPos;
+
+ String ip = string;
+ int maskBits = 0;
+ if ((slashPos = string.indexOf('/')) != -1) {
+ ip = string.substring(0, slashPos);
+ try {
+ String suffix = string.substring(slashPos + 1);
+ if (suffix.length() == 0)
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+ maskBits = Integer.parseInt(suffix);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+ }
+ if (maskBits < 0 || maskBits > 32) {
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+ }
+ }
+
+ int raw = 0;
+ while (shift >= 0) {
+ int end = ip.indexOf('.', start);
+ if (end == start || !((shift > 0) ^ (end < 0)))
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+
+ String substr =
+ end > 0 ? ip.substring(start, end) : ip.substring(start);
+ int val;
+ try {
+ val = Integer.parseInt(substr);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+ }
+ if (val < 0 || val > 255)
+ throw new IllegalArgumentException("IP Address not well formed: " + string);
+
+ raw |= val << shift;
+
+ shift -= 8;
+ start = end + 1;
+ }
+
+ if (maskBits == 0) {
+ // No mask
+ return IPv4.of(raw);
+ } else {
+ // With mask
+ int mask = (-1) << (32 - maskBits);
+ return Masked.<IPv4>of(IPv4.of(raw), IPv4.of(mask));
+ }
+ }
public int getInt() {
return rawValue;
@@ -82,15 +138,6 @@
return LENGTH;
}
- public static IPv4 readFrom(final ChannelBuffer bb) {
- return IPv4.of(bb.readInt());
- }
-
- @Override
- public void writeTo(final ChannelBuffer bb) {
- bb.writeInt(rawValue);
- }
-
@Override
public String toString() {
StringBuilder res = new StringBuilder();
@@ -122,5 +169,23 @@
return false;
return true;
}
+
+ public static final Serializer<IPv4> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<IPv4> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<IPv4> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<IPv4> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<IPv4> {
+ @Override
+ public void writeTo(IPv4 value, ChannelBuffer c) {
+ c.writeInt(value.rawValue);
+ }
+
+ @Override
+ public IPv4 readFrom(ChannelBuffer c) throws OFParseError {
+ return IPv4.of(c.readInt());
+ }
+
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java
deleted file mode 100644
index ec777c0..0000000
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.openflow.types;
-
-public class IPv4WithMask {
-
-}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
index 19002d9..ff5e9ed 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
@@ -4,7 +4,6 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-import org.openflow.protocol.OFObject;
/**
* IPv6 address object. Instance controlled, immutable. Internal representation:
@@ -12,7 +11,7 @@
*
* @author Andreas Wundsam <andreas.wundsam@teleteach.de>
*/
-public class IPv6 implements OFObject {
+public class IPv6 implements OFValueType {
static final int LENGTH = 16;
private final long raw1;
private final long raw2;
@@ -159,16 +158,6 @@
return LENGTH;
}
- public static IPv6 readFrom(final ChannelBuffer bb) throws OFParseError {
- return IPv6.of(bb.readLong(), bb.readLong());
- }
-
- @Override
- public void writeTo(final ChannelBuffer bb) {
- bb.writeLong(raw1);
- bb.writeLong(raw2);
- }
-
@Override
public String toString() {
return toString(true, false);
@@ -280,5 +269,25 @@
return false;
return true;
}
+
+ public static final Serializer<IPv6> SERIALIZER_V12 = new SerializerV12();
+ public static final Serializer<IPv6> SERIALIZER_V13 = SERIALIZER_V12;
+
+ private static class SerializerV12 implements OFValueType.Serializer<IPv6> {
+
+ @Override
+ public void writeTo(IPv6 value, ChannelBuffer c) {
+ c.writeLong(value.raw1);
+ c.writeLong(value.raw2);
+ }
+
+ @Override
+ public IPv6 readFrom(ChannelBuffer c) throws OFParseError {
+ return IPv6.of(c.readLong(), c.readLong());
+ }
+
+ }
+
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java
deleted file mode 100644
index 0fb3281..0000000
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.openflow.types;
-
-public class IPv6WithMask {
-
-}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java b/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
index a295cb2..fc28370 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
@@ -1,5 +1,662 @@
package org.openflow.types;
-public class IpProtocol {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+
+/**
+ * IP-Protocol field representation
+ *
+ * @author Yotam Harchol (yotam.harchol@bigswitch.com)
+ */
+public class IpProtocol implements OFValueType {
+
+ static final short MAX_PROTO = 0xFF;
+ static final int LENGTH = 1;
+
+ private final short proto;
+
+ static final short IP_PROTO_NUM_HOPOPT = 0x00;
+ static final short IP_PROTO_NUM_ICMP = 0x01;
+ static final short IP_PROTO_NUM_IGMP = 0x02;
+ static final short IP_PROTO_NUM_GGP = 0x03;
+ static final short IP_PROTO_NUM_IPv4 = 0x04;
+ static final short IP_PROTO_NUM_ST = 0x05;
+ static final short IP_PROTO_NUM_TCP = 0x06;
+ static final short IP_PROTO_NUM_CBT = 0x07;
+ static final short IP_PROTO_NUM_EGP = 0x08;
+ static final short IP_PROTO_NUM_IGP = 0x09;
+ static final short IP_PROTO_NUM_BBN_RCC_MON = 0x0A;
+ static final short IP_PROTO_NUM_NVP_II = 0x0B;
+ static final short IP_PROTO_NUM_PUP = 0x0C;
+ static final short IP_PROTO_NUM_ARGUS = 0x0D;
+ static final short IP_PROTO_NUM_EMCON = 0x0E;
+ static final short IP_PROTO_NUM_XNET = 0x0F;
+ static final short IP_PROTO_NUM_CHAOS = 0x10;
+ static final short IP_PROTO_NUM_UDP = 0x11;
+ static final short IP_PROTO_NUM_MUX = 0x12;
+ static final short IP_PROTO_NUM_DCN_MEAS = 0x13;
+ static final short IP_PROTO_NUM_HMP = 0x14;
+ static final short IP_PROTO_NUM_PRM = 0x15;
+ static final short IP_PROTO_NUM_XNS_IDP = 0x16;
+ static final short IP_PROTO_NUM_TRUNK_1 = 0x17;
+ static final short IP_PROTO_NUM_TRUNK_2 = 0x18;
+ static final short IP_PROTO_NUM_LEAF_1 = 0x19;
+ static final short IP_PROTO_NUM_LEAF_2 = 0x1A;
+ static final short IP_PROTO_NUM_RDP = 0x1B;
+ static final short IP_PROTO_NUM_IRTP = 0x1C;
+ static final short IP_PROTO_NUM_ISO_TP4 = 0x1D;
+ static final short IP_PROTO_NUM_NETBLT = 0x1E;
+ static final short IP_PROTO_NUM_MFE_NSP = 0x1F;
+ static final short IP_PROTO_NUM_MERIT_INP = 0x20;
+ static final short IP_PROTO_NUM_DCCP = 0x21;
+ static final short IP_PROTO_NUM_3PC = 0x22;
+ static final short IP_PROTO_NUM_IDPR = 0x23;
+ static final short IP_PROTO_NUM_XTP = 0x24;
+ static final short IP_PROTO_NUM_DDP = 0x25;
+ static final short IP_PROTO_NUM_IDPR_CMTP = 0x26;
+ static final short IP_PROTO_NUM_TP_PP = 0x27;
+ static final short IP_PROTO_NUM_IL = 0x28;
+ static final short IP_PROTO_NUM_IPv6 = 0x29;
+ static final short IP_PROTO_NUM_SDRP = 0x2A;
+ static final short IP_PROTO_NUM_IPv6_ROUTE = 0x2B;
+ static final short IP_PROTO_NUM_IPv6_FRAG = 0x2C;
+ static final short IP_PROTO_NUM_IDRP = 0x2D;
+ static final short IP_PROTO_NUM_RSVP = 0x2E;
+ static final short IP_PROTO_NUM_GRE = 0x2F;
+ static final short IP_PROTO_NUM_MHRP = 0x30;
+ static final short IP_PROTO_NUM_BNA = 0x31;
+ static final short IP_PROTO_NUM_ESP = 0x32;
+ static final short IP_PROTO_NUM_AH = 0x33;
+ static final short IP_PROTO_NUM_I_NLSP = 0x34;
+ static final short IP_PROTO_NUM_SWIPE = 0x35;
+ static final short IP_PROTO_NUM_NARP = 0x36;
+ static final short IP_PROTO_NUM_MOBILE = 0x37;
+ static final short IP_PROTO_NUM_TLSP = 0x38;
+ static final short IP_PROTO_NUM_SKIP = 0x39;
+ static final short IP_PROTO_NUM_IPv6_ICMP = 0x3A;
+ static final short IP_PROTO_NUM_IPv6_NO_NXT = 0x3B;
+ static final short IP_PROTO_NUM_IPv6_OPTS = 0x3C;
+ static final short IP_PROTO_NUM_HOST_INTERNAL = 0x3D;
+ static final short IP_PROTO_NUM_CFTP = 0x3E;
+ static final short IP_PROTO_NUM_LOCAL_NET = 0x3F;
+ static final short IP_PROTO_NUM_SAT_EXPAK = 0x40;
+ static final short IP_PROTO_NUM_KRYPTOLAN = 0x41;
+ static final short IP_PROTO_NUM_RVD = 0x42;
+ static final short IP_PROTO_NUM_IPPC = 0x43;
+ static final short IP_PROTO_NUM_DIST_FS = 0x44;
+ static final short IP_PROTO_NUM_SAT_MON = 0x45;
+ static final short IP_PROTO_NUM_VISA = 0x46;
+ static final short IP_PROTO_NUM_IPCV = 0x47;
+ static final short IP_PROTO_NUM_CPNX = 0x48;
+ static final short IP_PROTO_NUM_CPHB = 0x49;
+ static final short IP_PROTO_NUM_WSN = 0x4A;
+ static final short IP_PROTO_NUM_PVP = 0x4B;
+ static final short IP_PROTO_NUM_BR_SAT_MON = 0x4C;
+ static final short IP_PROTO_NUM_SUN_ND = 0x4D;
+ static final short IP_PROTO_NUM_WB_MON = 0x4E;
+ static final short IP_PROTO_NUM_WB_EXPAK = 0x4F;
+ static final short IP_PROTO_NUM_ISO_IP = 0x50;
+ static final short IP_PROTO_NUM_VMTP = 0x51;
+ static final short IP_PROTO_NUM_SECURE_VMTP = 0x52;
+ static final short IP_PROTO_NUM_VINES = 0x53;
+ static final short IP_PROTO_NUM_TTP_IPTM = 0x54;
+ static final short IP_PROTO_NUM_NSFNET_IGP = 0x55;
+ static final short IP_PROTO_NUM_DGP = 0x56;
+ static final short IP_PROTO_NUM_TCF = 0x57;
+ static final short IP_PROTO_NUM_EIGRP = 0x58;
+ static final short IP_PROTO_NUM_OSPF = 0x59;
+ static final short IP_PROTO_NUM_Sprite_RPC = 0x5A;
+ static final short IP_PROTO_NUM_LARP = 0x5B;
+ static final short IP_PROTO_NUM_MTP = 0x5C;
+ static final short IP_PROTO_NUM_AX_25 = 0x5D;
+ static final short IP_PROTO_NUM_IPIP = 0x5E;
+ static final short IP_PROTO_NUM_MICP = 0x5F;
+ static final short IP_PROTO_NUM_SCC_SP = 0x60;
+ static final short IP_PROTO_NUM_ETHERIP = 0x61;
+ static final short IP_PROTO_NUM_ENCAP = 0x62;
+ static final short IP_PROTO_NUM_PRIVATE_ENCRYPT = 0x63;
+ static final short IP_PROTO_NUM_GMTP = 0x64;
+ static final short IP_PROTO_NUM_IFMP = 0x65;
+ static final short IP_PROTO_NUM_PNNI = 0x66;
+ static final short IP_PROTO_NUM_PIM = 0x67;
+ static final short IP_PROTO_NUM_ARIS = 0x68;
+ static final short IP_PROTO_NUM_SCPS = 0x69;
+ static final short IP_PROTO_NUM_QNX = 0x6A;
+ static final short IP_PROTO_NUM_A_N = 0x6B;
+ static final short IP_PROTO_NUM_IP_COMP = 0x6C;
+ static final short IP_PROTO_NUM_SNP = 0x6D;
+ static final short IP_PROTO_NUM_COMPAQ_PEER = 0x6E;
+ static final short IP_PROTO_NUM_IPX_IN_IP = 0x6F;
+ static final short IP_PROTO_NUM_VRRP = 0x70;
+ static final short IP_PROTO_NUM_PGM = 0x71;
+ static final short IP_PROTO_NUM_ZERO_HOP = 0x72;
+ static final short IP_PROTO_NUM_L2TP = 0x73;
+ static final short IP_PROTO_NUM_DDX = 0x74;
+ static final short IP_PROTO_NUM_IATP = 0x75;
+ static final short IP_PROTO_NUM_STP = 0x76;
+ static final short IP_PROTO_NUM_SRP = 0x77;
+ static final short IP_PROTO_NUM_UTI = 0x78;
+ static final short IP_PROTO_NUM_SMP = 0x79;
+ static final short IP_PROTO_NUM_SM = 0x7A;
+ static final short IP_PROTO_NUM_PTP = 0x7B;
+ static final short IP_PROTO_NUM_IS_IS_OVER_IPv4 = 0x7C;
+ static final short IP_PROTO_NUM_FIRE = 0x7D;
+ static final short IP_PROTO_NUM_CRTP = 0x7E;
+ static final short IP_PROTO_NUM_CRUDP = 0x7F;
+ static final short IP_PROTO_NUM_SSCOPMCE = 0x80;
+ static final short IP_PROTO_NUM_IPLT = 0x81;
+ static final short IP_PROTO_NUM_SPS = 0x82;
+ static final short IP_PROTO_NUM_PIPE = 0x83;
+ static final short IP_PROTO_NUM_SCTP = 0x84;
+ static final short IP_PROTO_NUM_FC = 0x85;
+ static final short IP_PROTO_NUM_RSVP_E2E_IGNORE = 0x86;
+ static final short IP_PROTO_NUM_MOBILITY_HEADER = 0x87;
+ static final short IP_PROTO_NUM_UDP_LITE = 0x88;
+ static final short IP_PROTO_NUM_MPLS_IN_IP = 0x89;
+ static final short IP_PROTO_NUM_MANET = 0x8A;
+ static final short IP_PROTO_NUM_HIP = 0x8B;
+ static final short IP_PROTO_NUM_SHIM6 = 0x8C;
+
+ public static final IpProtocol IP_PROTO_HOPOPT = new IpProtocol(IP_PROTO_NUM_HOPOPT);
+ public static final IpProtocol IP_PROTO_ICMP = new IpProtocol(IP_PROTO_NUM_ICMP);
+ public static final IpProtocol IP_PROTO_IGMP = new IpProtocol(IP_PROTO_NUM_IGMP);
+ public static final IpProtocol IP_PROTO_GGP = new IpProtocol(IP_PROTO_NUM_GGP);
+ public static final IpProtocol IP_PROTO_IPv4 = new IpProtocol(IP_PROTO_NUM_IPv4);
+ public static final IpProtocol IP_PROTO_ST = new IpProtocol(IP_PROTO_NUM_ST);
+ public static final IpProtocol IP_PROTO_TCP = new IpProtocol(IP_PROTO_NUM_TCP);
+ public static final IpProtocol IP_PROTO_CBT = new IpProtocol(IP_PROTO_NUM_CBT);
+ public static final IpProtocol IP_PROTO_EGP = new IpProtocol(IP_PROTO_NUM_EGP);
+ public static final IpProtocol IP_PROTO_IGP = new IpProtocol(IP_PROTO_NUM_IGP);
+ public static final IpProtocol IP_PROTO_BBN_RCC_MON = new IpProtocol(IP_PROTO_NUM_BBN_RCC_MON);
+ public static final IpProtocol IP_PROTO_NVP_II = new IpProtocol(IP_PROTO_NUM_NVP_II);
+ public static final IpProtocol IP_PROTO_PUP = new IpProtocol(IP_PROTO_NUM_PUP);
+ public static final IpProtocol IP_PROTO_ARGUS = new IpProtocol(IP_PROTO_NUM_ARGUS);
+ public static final IpProtocol IP_PROTO_EMCON = new IpProtocol(IP_PROTO_NUM_EMCON);
+ public static final IpProtocol IP_PROTO_XNET = new IpProtocol(IP_PROTO_NUM_XNET);
+ public static final IpProtocol IP_PROTO_CHAOS = new IpProtocol(IP_PROTO_NUM_CHAOS);
+ public static final IpProtocol IP_PROTO_UDP = new IpProtocol(IP_PROTO_NUM_UDP);
+ public static final IpProtocol IP_PROTO_MUX = new IpProtocol(IP_PROTO_NUM_MUX);
+ public static final IpProtocol IP_PROTO_DCN_MEAS = new IpProtocol(IP_PROTO_NUM_DCN_MEAS);
+ public static final IpProtocol IP_PROTO_HMP = new IpProtocol(IP_PROTO_NUM_HMP);
+ public static final IpProtocol IP_PROTO_PRM = new IpProtocol(IP_PROTO_NUM_PRM);
+ public static final IpProtocol IP_PROTO_XNS_IDP = new IpProtocol(IP_PROTO_NUM_XNS_IDP);
+ public static final IpProtocol IP_PROTO_TRUNK_1 = new IpProtocol(IP_PROTO_NUM_TRUNK_1);
+ public static final IpProtocol IP_PROTO_TRUNK_2 = new IpProtocol(IP_PROTO_NUM_TRUNK_2);
+ public static final IpProtocol IP_PROTO_LEAF_1 = new IpProtocol(IP_PROTO_NUM_LEAF_1);
+ public static final IpProtocol IP_PROTO_LEAF_2 = new IpProtocol(IP_PROTO_NUM_LEAF_2);
+ public static final IpProtocol IP_PROTO_RDP = new IpProtocol(IP_PROTO_NUM_RDP);
+ public static final IpProtocol IP_PROTO_IRTP = new IpProtocol(IP_PROTO_NUM_IRTP);
+ public static final IpProtocol IP_PROTO_ISO_TP4 = new IpProtocol(IP_PROTO_NUM_ISO_TP4);
+ public static final IpProtocol IP_PROTO_NETBLT = new IpProtocol(IP_PROTO_NUM_NETBLT);
+ public static final IpProtocol IP_PROTO_MFE_NSP = new IpProtocol(IP_PROTO_NUM_MFE_NSP);
+ public static final IpProtocol IP_PROTO_MERIT_INP = new IpProtocol(IP_PROTO_NUM_MERIT_INP);
+ public static final IpProtocol IP_PROTO_DCCP = new IpProtocol(IP_PROTO_NUM_DCCP);
+ public static final IpProtocol IP_PROTO_3PC = new IpProtocol(IP_PROTO_NUM_3PC);
+ public static final IpProtocol IP_PROTO_IDPR = new IpProtocol(IP_PROTO_NUM_IDPR);
+ public static final IpProtocol IP_PROTO_XTP = new IpProtocol(IP_PROTO_NUM_XTP);
+ public static final IpProtocol IP_PROTO_DDP = new IpProtocol(IP_PROTO_NUM_DDP);
+ public static final IpProtocol IP_PROTO_IDPR_CMTP = new IpProtocol(IP_PROTO_NUM_IDPR_CMTP);
+ public static final IpProtocol IP_PROTO_TP_PP = new IpProtocol(IP_PROTO_NUM_TP_PP);
+ public static final IpProtocol IP_PROTO_IL = new IpProtocol(IP_PROTO_NUM_IL);
+ public static final IpProtocol IP_PROTO_IPv6 = new IpProtocol(IP_PROTO_NUM_IPv6);
+ public static final IpProtocol IP_PROTO_SDRP = new IpProtocol(IP_PROTO_NUM_SDRP);
+ public static final IpProtocol IP_PROTO_IPv6_ROUTE = new IpProtocol(IP_PROTO_NUM_IPv6_ROUTE);
+ public static final IpProtocol IP_PROTO_IPv6_FRAG = new IpProtocol(IP_PROTO_NUM_IPv6_FRAG);
+ public static final IpProtocol IP_PROTO_IDRP = new IpProtocol(IP_PROTO_NUM_IDRP);
+ public static final IpProtocol IP_PROTO_RSVP = new IpProtocol(IP_PROTO_NUM_RSVP);
+ public static final IpProtocol IP_PROTO_GRE = new IpProtocol(IP_PROTO_NUM_GRE);
+ public static final IpProtocol IP_PROTO_MHRP = new IpProtocol(IP_PROTO_NUM_MHRP);
+ public static final IpProtocol IP_PROTO_BNA = new IpProtocol(IP_PROTO_NUM_BNA);
+ public static final IpProtocol IP_PROTO_ESP = new IpProtocol(IP_PROTO_NUM_ESP);
+ public static final IpProtocol IP_PROTO_AH = new IpProtocol(IP_PROTO_NUM_AH);
+ public static final IpProtocol IP_PROTO_I_NLSP = new IpProtocol(IP_PROTO_NUM_I_NLSP);
+ public static final IpProtocol IP_PROTO_SWIPE = new IpProtocol(IP_PROTO_NUM_SWIPE);
+ public static final IpProtocol IP_PROTO_NARP = new IpProtocol(IP_PROTO_NUM_NARP);
+ public static final IpProtocol IP_PROTO_MOBILE = new IpProtocol(IP_PROTO_NUM_MOBILE);
+ public static final IpProtocol IP_PROTO_TLSP = new IpProtocol(IP_PROTO_NUM_TLSP);
+ public static final IpProtocol IP_PROTO_SKIP = new IpProtocol(IP_PROTO_NUM_SKIP);
+ public static final IpProtocol IP_PROTO_IPv6_ICMP = new IpProtocol(IP_PROTO_NUM_IPv6_ICMP);
+ public static final IpProtocol IP_PROTO_IPv6_NO_NXT = new IpProtocol(IP_PROTO_NUM_IPv6_NO_NXT);
+ public static final IpProtocol IP_PROTO_IPv6_OPTS = new IpProtocol(IP_PROTO_NUM_IPv6_OPTS);
+ public static final IpProtocol IP_PROTO_HOST_INTERNAL = new IpProtocol(IP_PROTO_NUM_HOST_INTERNAL);
+ public static final IpProtocol IP_PROTO_CFTP = new IpProtocol(IP_PROTO_NUM_CFTP);
+ public static final IpProtocol IP_PROTO_LOCAL_NET = new IpProtocol(IP_PROTO_NUM_LOCAL_NET);
+ public static final IpProtocol IP_PROTO_SAT_EXPAK = new IpProtocol(IP_PROTO_NUM_SAT_EXPAK);
+ public static final IpProtocol IP_PROTO_KRYPTOLAN = new IpProtocol(IP_PROTO_NUM_KRYPTOLAN);
+ public static final IpProtocol IP_PROTO_RVD = new IpProtocol(IP_PROTO_NUM_RVD);
+ public static final IpProtocol IP_PROTO_IPPC = new IpProtocol(IP_PROTO_NUM_IPPC);
+ public static final IpProtocol IP_PROTO_DIST_FS = new IpProtocol(IP_PROTO_NUM_DIST_FS);
+ public static final IpProtocol IP_PROTO_SAT_MON = new IpProtocol(IP_PROTO_NUM_SAT_MON);
+ public static final IpProtocol IP_PROTO_VISA = new IpProtocol(IP_PROTO_NUM_VISA);
+ public static final IpProtocol IP_PROTO_IPCV = new IpProtocol(IP_PROTO_NUM_IPCV);
+ public static final IpProtocol IP_PROTO_CPNX = new IpProtocol(IP_PROTO_NUM_CPNX);
+ public static final IpProtocol IP_PROTO_CPHB = new IpProtocol(IP_PROTO_NUM_CPHB);
+ public static final IpProtocol IP_PROTO_WSN = new IpProtocol(IP_PROTO_NUM_WSN);
+ public static final IpProtocol IP_PROTO_PVP = new IpProtocol(IP_PROTO_NUM_PVP);
+ public static final IpProtocol IP_PROTO_BR_SAT_MON = new IpProtocol(IP_PROTO_NUM_BR_SAT_MON);
+ public static final IpProtocol IP_PROTO_SUN_ND = new IpProtocol(IP_PROTO_NUM_SUN_ND);
+ public static final IpProtocol IP_PROTO_WB_MON = new IpProtocol(IP_PROTO_NUM_WB_MON);
+ public static final IpProtocol IP_PROTO_WB_EXPAK = new IpProtocol(IP_PROTO_NUM_WB_EXPAK);
+ public static final IpProtocol IP_PROTO_ISO_IP = new IpProtocol(IP_PROTO_NUM_ISO_IP);
+ public static final IpProtocol IP_PROTO_VMTP = new IpProtocol(IP_PROTO_NUM_VMTP);
+ public static final IpProtocol IP_PROTO_SECURE_VMTP = new IpProtocol(IP_PROTO_NUM_SECURE_VMTP);
+ public static final IpProtocol IP_PROTO_VINES = new IpProtocol(IP_PROTO_NUM_VINES);
+ public static final IpProtocol IP_PROTO_TTP_IPTM = new IpProtocol(IP_PROTO_NUM_TTP_IPTM);
+ public static final IpProtocol IP_PROTO_NSFNET_IGP = new IpProtocol(IP_PROTO_NUM_NSFNET_IGP);
+ public static final IpProtocol IP_PROTO_DGP = new IpProtocol(IP_PROTO_NUM_DGP);
+ public static final IpProtocol IP_PROTO_TCF = new IpProtocol(IP_PROTO_NUM_TCF);
+ public static final IpProtocol IP_PROTO_EIGRP = new IpProtocol(IP_PROTO_NUM_EIGRP);
+ public static final IpProtocol IP_PROTO_OSPF = new IpProtocol(IP_PROTO_NUM_OSPF);
+ public static final IpProtocol IP_PROTO_Sprite_RPC = new IpProtocol(IP_PROTO_NUM_Sprite_RPC);
+ public static final IpProtocol IP_PROTO_LARP = new IpProtocol(IP_PROTO_NUM_LARP);
+ public static final IpProtocol IP_PROTO_MTP = new IpProtocol(IP_PROTO_NUM_MTP);
+ public static final IpProtocol IP_PROTO_AX_25 = new IpProtocol(IP_PROTO_NUM_AX_25);
+ public static final IpProtocol IP_PROTO_IPIP = new IpProtocol(IP_PROTO_NUM_IPIP);
+ public static final IpProtocol IP_PROTO_MICP = new IpProtocol(IP_PROTO_NUM_MICP);
+ public static final IpProtocol IP_PROTO_SCC_SP = new IpProtocol(IP_PROTO_NUM_SCC_SP);
+ public static final IpProtocol IP_PROTO_ETHERIP = new IpProtocol(IP_PROTO_NUM_ETHERIP);
+ public static final IpProtocol IP_PROTO_ENCAP = new IpProtocol(IP_PROTO_NUM_ENCAP);
+ public static final IpProtocol IP_PROTO_PRIVATE_ENCRYPT = new IpProtocol(IP_PROTO_NUM_PRIVATE_ENCRYPT);
+ public static final IpProtocol IP_PROTO_GMTP = new IpProtocol(IP_PROTO_NUM_GMTP);
+ public static final IpProtocol IP_PROTO_IFMP = new IpProtocol(IP_PROTO_NUM_IFMP);
+ public static final IpProtocol IP_PROTO_PNNI = new IpProtocol(IP_PROTO_NUM_PNNI);
+ public static final IpProtocol IP_PROTO_PIM = new IpProtocol(IP_PROTO_NUM_PIM);
+ public static final IpProtocol IP_PROTO_ARIS = new IpProtocol(IP_PROTO_NUM_ARIS);
+ public static final IpProtocol IP_PROTO_SCPS = new IpProtocol(IP_PROTO_NUM_SCPS);
+ public static final IpProtocol IP_PROTO_QNX = new IpProtocol(IP_PROTO_NUM_QNX);
+ public static final IpProtocol IP_PROTO_A_N = new IpProtocol(IP_PROTO_NUM_A_N);
+ public static final IpProtocol IP_PROTO_IP_COMP = new IpProtocol(IP_PROTO_NUM_IP_COMP);
+ public static final IpProtocol IP_PROTO_SNP = new IpProtocol(IP_PROTO_NUM_SNP);
+ public static final IpProtocol IP_PROTO_COMPAQ_PEER = new IpProtocol(IP_PROTO_NUM_COMPAQ_PEER);
+ public static final IpProtocol IP_PROTO_IPX_IN_IP = new IpProtocol(IP_PROTO_NUM_IPX_IN_IP);
+ public static final IpProtocol IP_PROTO_VRRP = new IpProtocol(IP_PROTO_NUM_VRRP);
+ public static final IpProtocol IP_PROTO_PGM = new IpProtocol(IP_PROTO_NUM_PGM);
+ public static final IpProtocol IP_PROTO_ZERO_HOP = new IpProtocol(IP_PROTO_NUM_ZERO_HOP);
+ public static final IpProtocol IP_PROTO_L2TP = new IpProtocol(IP_PROTO_NUM_L2TP);
+ public static final IpProtocol IP_PROTO_DDX = new IpProtocol(IP_PROTO_NUM_DDX);
+ public static final IpProtocol IP_PROTO_IATP = new IpProtocol(IP_PROTO_NUM_IATP);
+ public static final IpProtocol IP_PROTO_STP = new IpProtocol(IP_PROTO_NUM_STP);
+ public static final IpProtocol IP_PROTO_SRP = new IpProtocol(IP_PROTO_NUM_SRP);
+ public static final IpProtocol IP_PROTO_UTI = new IpProtocol(IP_PROTO_NUM_UTI);
+ public static final IpProtocol IP_PROTO_SMP = new IpProtocol(IP_PROTO_NUM_SMP);
+ public static final IpProtocol IP_PROTO_SM = new IpProtocol(IP_PROTO_NUM_SM);
+ public static final IpProtocol IP_PROTO_PTP = new IpProtocol(IP_PROTO_NUM_PTP);
+ public static final IpProtocol IP_PROTO_IS_IS_OVER_IPv4 = new IpProtocol(IP_PROTO_NUM_IS_IS_OVER_IPv4);
+ public static final IpProtocol IP_PROTO_FIRE = new IpProtocol(IP_PROTO_NUM_FIRE);
+ public static final IpProtocol IP_PROTO_CRTP = new IpProtocol(IP_PROTO_NUM_CRTP);
+ public static final IpProtocol IP_PROTO_CRUDP = new IpProtocol(IP_PROTO_NUM_CRUDP);
+ public static final IpProtocol IP_PROTO_SSCOPMCE = new IpProtocol(IP_PROTO_NUM_SSCOPMCE);
+ public static final IpProtocol IP_PROTO_IPLT = new IpProtocol(IP_PROTO_NUM_IPLT);
+ public static final IpProtocol IP_PROTO_SPS = new IpProtocol(IP_PROTO_NUM_SPS);
+ public static final IpProtocol IP_PROTO_PIPE = new IpProtocol(IP_PROTO_NUM_PIPE);
+ public static final IpProtocol IP_PROTO_SCTP = new IpProtocol(IP_PROTO_NUM_SCTP);
+ public static final IpProtocol IP_PROTO_FC = new IpProtocol(IP_PROTO_NUM_FC);
+ public static final IpProtocol IP_PROTO_RSVP_E2E_IGNORE = new IpProtocol(IP_PROTO_NUM_RSVP_E2E_IGNORE);
+ public static final IpProtocol IP_PROTO_MOBILITY_HEADER = new IpProtocol(IP_PROTO_NUM_MOBILITY_HEADER);
+ public static final IpProtocol IP_PROTO_UDP_LITE = new IpProtocol(IP_PROTO_NUM_UDP_LITE);
+ public static final IpProtocol IP_PROTO_MPLS_IN_IP = new IpProtocol(IP_PROTO_NUM_MPLS_IN_IP);
+ public static final IpProtocol IP_PROTO_MANET = new IpProtocol(IP_PROTO_NUM_MANET);
+ public static final IpProtocol IP_PROTO_HIP = new IpProtocol(IP_PROTO_NUM_HIP);
+ public static final IpProtocol IP_PROTO_SHIM6 = new IpProtocol(IP_PROTO_NUM_SHIM6);
+
+ private IpProtocol(short version) {
+ this.proto = version;
+ }
+
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache = null;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache = new byte[] { (byte)proto };
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ public static IpProtocol of(short proto) {
+ switch (proto) {
+ case IP_PROTO_NUM_HOPOPT:
+ return IP_PROTO_HOPOPT;
+ case IP_PROTO_NUM_ICMP:
+ return IP_PROTO_ICMP;
+ case IP_PROTO_NUM_IGMP:
+ return IP_PROTO_IGMP;
+ case IP_PROTO_NUM_GGP:
+ return IP_PROTO_GGP;
+ case IP_PROTO_NUM_IPv4:
+ return IP_PROTO_IPv4;
+ case IP_PROTO_NUM_ST:
+ return IP_PROTO_ST;
+ case IP_PROTO_NUM_TCP:
+ return IP_PROTO_TCP;
+ case IP_PROTO_NUM_CBT:
+ return IP_PROTO_CBT;
+ case IP_PROTO_NUM_EGP:
+ return IP_PROTO_EGP;
+ case IP_PROTO_NUM_IGP:
+ return IP_PROTO_IGP;
+ case IP_PROTO_NUM_BBN_RCC_MON:
+ return IP_PROTO_BBN_RCC_MON;
+ case IP_PROTO_NUM_NVP_II:
+ return IP_PROTO_NVP_II;
+ case IP_PROTO_NUM_PUP:
+ return IP_PROTO_PUP;
+ case IP_PROTO_NUM_ARGUS:
+ return IP_PROTO_ARGUS;
+ case IP_PROTO_NUM_EMCON:
+ return IP_PROTO_EMCON;
+ case IP_PROTO_NUM_XNET:
+ return IP_PROTO_XNET;
+ case IP_PROTO_NUM_CHAOS:
+ return IP_PROTO_CHAOS;
+ case IP_PROTO_NUM_UDP:
+ return IP_PROTO_UDP;
+ case IP_PROTO_NUM_MUX:
+ return IP_PROTO_MUX;
+ case IP_PROTO_NUM_DCN_MEAS:
+ return IP_PROTO_DCN_MEAS;
+ case IP_PROTO_NUM_HMP:
+ return IP_PROTO_HMP;
+ case IP_PROTO_NUM_PRM:
+ return IP_PROTO_PRM;
+ case IP_PROTO_NUM_XNS_IDP:
+ return IP_PROTO_XNS_IDP;
+ case IP_PROTO_NUM_TRUNK_1:
+ return IP_PROTO_TRUNK_1;
+ case IP_PROTO_NUM_TRUNK_2:
+ return IP_PROTO_TRUNK_2;
+ case IP_PROTO_NUM_LEAF_1:
+ return IP_PROTO_LEAF_1;
+ case IP_PROTO_NUM_LEAF_2:
+ return IP_PROTO_LEAF_2;
+ case IP_PROTO_NUM_RDP:
+ return IP_PROTO_RDP;
+ case IP_PROTO_NUM_IRTP:
+ return IP_PROTO_IRTP;
+ case IP_PROTO_NUM_ISO_TP4:
+ return IP_PROTO_ISO_TP4;
+ case IP_PROTO_NUM_NETBLT:
+ return IP_PROTO_NETBLT;
+ case IP_PROTO_NUM_MFE_NSP:
+ return IP_PROTO_MFE_NSP;
+ case IP_PROTO_NUM_MERIT_INP:
+ return IP_PROTO_MERIT_INP;
+ case IP_PROTO_NUM_DCCP:
+ return IP_PROTO_DCCP;
+ case IP_PROTO_NUM_3PC:
+ return IP_PROTO_3PC;
+ case IP_PROTO_NUM_IDPR:
+ return IP_PROTO_IDPR;
+ case IP_PROTO_NUM_XTP:
+ return IP_PROTO_XTP;
+ case IP_PROTO_NUM_DDP:
+ return IP_PROTO_DDP;
+ case IP_PROTO_NUM_IDPR_CMTP:
+ return IP_PROTO_IDPR_CMTP;
+ case IP_PROTO_NUM_TP_PP:
+ return IP_PROTO_TP_PP;
+ case IP_PROTO_NUM_IL:
+ return IP_PROTO_IL;
+ case IP_PROTO_NUM_IPv6:
+ return IP_PROTO_IPv6;
+ case IP_PROTO_NUM_SDRP:
+ return IP_PROTO_SDRP;
+ case IP_PROTO_NUM_IPv6_ROUTE:
+ return IP_PROTO_IPv6_ROUTE;
+ case IP_PROTO_NUM_IPv6_FRAG:
+ return IP_PROTO_IPv6_FRAG;
+ case IP_PROTO_NUM_IDRP:
+ return IP_PROTO_IDRP;
+ case IP_PROTO_NUM_RSVP:
+ return IP_PROTO_RSVP;
+ case IP_PROTO_NUM_GRE:
+ return IP_PROTO_GRE;
+ case IP_PROTO_NUM_MHRP:
+ return IP_PROTO_MHRP;
+ case IP_PROTO_NUM_BNA:
+ return IP_PROTO_BNA;
+ case IP_PROTO_NUM_ESP:
+ return IP_PROTO_ESP;
+ case IP_PROTO_NUM_AH:
+ return IP_PROTO_AH;
+ case IP_PROTO_NUM_I_NLSP:
+ return IP_PROTO_I_NLSP;
+ case IP_PROTO_NUM_SWIPE:
+ return IP_PROTO_SWIPE;
+ case IP_PROTO_NUM_NARP:
+ return IP_PROTO_NARP;
+ case IP_PROTO_NUM_MOBILE:
+ return IP_PROTO_MOBILE;
+ case IP_PROTO_NUM_TLSP:
+ return IP_PROTO_TLSP;
+ case IP_PROTO_NUM_SKIP:
+ return IP_PROTO_SKIP;
+ case IP_PROTO_NUM_IPv6_ICMP:
+ return IP_PROTO_IPv6_ICMP;
+ case IP_PROTO_NUM_IPv6_NO_NXT:
+ return IP_PROTO_IPv6_NO_NXT;
+ case IP_PROTO_NUM_IPv6_OPTS:
+ return IP_PROTO_IPv6_OPTS;
+ case IP_PROTO_NUM_HOST_INTERNAL:
+ return IP_PROTO_HOST_INTERNAL;
+ case IP_PROTO_NUM_CFTP:
+ return IP_PROTO_CFTP;
+ case IP_PROTO_NUM_LOCAL_NET:
+ return IP_PROTO_LOCAL_NET;
+ case IP_PROTO_NUM_SAT_EXPAK:
+ return IP_PROTO_SAT_EXPAK;
+ case IP_PROTO_NUM_KRYPTOLAN:
+ return IP_PROTO_KRYPTOLAN;
+ case IP_PROTO_NUM_RVD:
+ return IP_PROTO_RVD;
+ case IP_PROTO_NUM_IPPC:
+ return IP_PROTO_IPPC;
+ case IP_PROTO_NUM_DIST_FS:
+ return IP_PROTO_DIST_FS;
+ case IP_PROTO_NUM_SAT_MON:
+ return IP_PROTO_SAT_MON;
+ case IP_PROTO_NUM_VISA:
+ return IP_PROTO_VISA;
+ case IP_PROTO_NUM_IPCV:
+ return IP_PROTO_IPCV;
+ case IP_PROTO_NUM_CPNX:
+ return IP_PROTO_CPNX;
+ case IP_PROTO_NUM_CPHB:
+ return IP_PROTO_CPHB;
+ case IP_PROTO_NUM_WSN:
+ return IP_PROTO_WSN;
+ case IP_PROTO_NUM_PVP:
+ return IP_PROTO_PVP;
+ case IP_PROTO_NUM_BR_SAT_MON:
+ return IP_PROTO_BR_SAT_MON;
+ case IP_PROTO_NUM_SUN_ND:
+ return IP_PROTO_SUN_ND;
+ case IP_PROTO_NUM_WB_MON:
+ return IP_PROTO_WB_MON;
+ case IP_PROTO_NUM_WB_EXPAK:
+ return IP_PROTO_WB_EXPAK;
+ case IP_PROTO_NUM_ISO_IP:
+ return IP_PROTO_ISO_IP;
+ case IP_PROTO_NUM_VMTP:
+ return IP_PROTO_VMTP;
+ case IP_PROTO_NUM_SECURE_VMTP:
+ return IP_PROTO_SECURE_VMTP;
+ case IP_PROTO_NUM_VINES:
+ return IP_PROTO_VINES;
+ case IP_PROTO_NUM_TTP_IPTM:
+ return IP_PROTO_TTP_IPTM;
+ case IP_PROTO_NUM_NSFNET_IGP:
+ return IP_PROTO_NSFNET_IGP;
+ case IP_PROTO_NUM_DGP:
+ return IP_PROTO_DGP;
+ case IP_PROTO_NUM_TCF:
+ return IP_PROTO_TCF;
+ case IP_PROTO_NUM_EIGRP:
+ return IP_PROTO_EIGRP;
+ case IP_PROTO_NUM_OSPF:
+ return IP_PROTO_OSPF;
+ case IP_PROTO_NUM_Sprite_RPC:
+ return IP_PROTO_Sprite_RPC;
+ case IP_PROTO_NUM_LARP:
+ return IP_PROTO_LARP;
+ case IP_PROTO_NUM_MTP:
+ return IP_PROTO_MTP;
+ case IP_PROTO_NUM_AX_25:
+ return IP_PROTO_AX_25;
+ case IP_PROTO_NUM_IPIP:
+ return IP_PROTO_IPIP;
+ case IP_PROTO_NUM_MICP:
+ return IP_PROTO_MICP;
+ case IP_PROTO_NUM_SCC_SP:
+ return IP_PROTO_SCC_SP;
+ case IP_PROTO_NUM_ETHERIP:
+ return IP_PROTO_ETHERIP;
+ case IP_PROTO_NUM_ENCAP:
+ return IP_PROTO_ENCAP;
+ case IP_PROTO_NUM_PRIVATE_ENCRYPT:
+ return IP_PROTO_PRIVATE_ENCRYPT;
+ case IP_PROTO_NUM_GMTP:
+ return IP_PROTO_GMTP;
+ case IP_PROTO_NUM_IFMP:
+ return IP_PROTO_IFMP;
+ case IP_PROTO_NUM_PNNI:
+ return IP_PROTO_PNNI;
+ case IP_PROTO_NUM_PIM:
+ return IP_PROTO_PIM;
+ case IP_PROTO_NUM_ARIS:
+ return IP_PROTO_ARIS;
+ case IP_PROTO_NUM_SCPS:
+ return IP_PROTO_SCPS;
+ case IP_PROTO_NUM_QNX:
+ return IP_PROTO_QNX;
+ case IP_PROTO_NUM_A_N:
+ return IP_PROTO_A_N;
+ case IP_PROTO_NUM_IP_COMP:
+ return IP_PROTO_IP_COMP;
+ case IP_PROTO_NUM_SNP:
+ return IP_PROTO_SNP;
+ case IP_PROTO_NUM_COMPAQ_PEER:
+ return IP_PROTO_COMPAQ_PEER;
+ case IP_PROTO_NUM_IPX_IN_IP:
+ return IP_PROTO_IPX_IN_IP;
+ case IP_PROTO_NUM_VRRP:
+ return IP_PROTO_VRRP;
+ case IP_PROTO_NUM_PGM:
+ return IP_PROTO_PGM;
+ case IP_PROTO_NUM_ZERO_HOP:
+ return IP_PROTO_ZERO_HOP;
+ case IP_PROTO_NUM_L2TP:
+ return IP_PROTO_L2TP;
+ case IP_PROTO_NUM_DDX:
+ return IP_PROTO_DDX;
+ case IP_PROTO_NUM_IATP:
+ return IP_PROTO_IATP;
+ case IP_PROTO_NUM_STP:
+ return IP_PROTO_STP;
+ case IP_PROTO_NUM_SRP:
+ return IP_PROTO_SRP;
+ case IP_PROTO_NUM_UTI:
+ return IP_PROTO_UTI;
+ case IP_PROTO_NUM_SMP:
+ return IP_PROTO_SMP;
+ case IP_PROTO_NUM_SM:
+ return IP_PROTO_SM;
+ case IP_PROTO_NUM_PTP:
+ return IP_PROTO_PTP;
+ case IP_PROTO_NUM_IS_IS_OVER_IPv4:
+ return IP_PROTO_IS_IS_OVER_IPv4;
+ case IP_PROTO_NUM_FIRE:
+ return IP_PROTO_FIRE;
+ case IP_PROTO_NUM_CRTP:
+ return IP_PROTO_CRTP;
+ case IP_PROTO_NUM_CRUDP:
+ return IP_PROTO_CRUDP;
+ case IP_PROTO_NUM_SSCOPMCE:
+ return IP_PROTO_SSCOPMCE;
+ case IP_PROTO_NUM_IPLT:
+ return IP_PROTO_IPLT;
+ case IP_PROTO_NUM_SPS:
+ return IP_PROTO_SPS;
+ case IP_PROTO_NUM_PIPE:
+ return IP_PROTO_PIPE;
+ case IP_PROTO_NUM_SCTP:
+ return IP_PROTO_SCTP;
+ case IP_PROTO_NUM_FC:
+ return IP_PROTO_FC;
+ case IP_PROTO_NUM_RSVP_E2E_IGNORE:
+ return IP_PROTO_RSVP_E2E_IGNORE;
+ case IP_PROTO_NUM_MOBILITY_HEADER:
+ return IP_PROTO_MOBILITY_HEADER;
+ case IP_PROTO_NUM_UDP_LITE:
+ return IP_PROTO_UDP_LITE;
+ case IP_PROTO_NUM_MPLS_IN_IP:
+ return IP_PROTO_MPLS_IN_IP;
+ case IP_PROTO_NUM_MANET:
+ return IP_PROTO_MANET;
+ case IP_PROTO_NUM_HIP:
+ return IP_PROTO_HIP;
+ case IP_PROTO_NUM_SHIM6:
+ return IP_PROTO_SHIM6;
+ default:
+ if (proto >= MAX_PROTO) {
+ throw new IllegalArgumentException("Illegal IP protocol number: "
+ + proto);
+ } else {
+ return new IpProtocol(proto);
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof IpProtocol))
+ return false;
+ IpProtocol o = (IpProtocol)obj;
+ if (o.proto != this.proto)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 37;
+ int result = 1;
+ result = prime * result + proto;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toHexString(proto);
+ }
+
+ public static final Serializer<IpProtocol> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<IpProtocol> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<IpProtocol> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<IpProtocol> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<IpProtocol> {
+
+ @Override
+ public void writeTo(IpProtocol value, ChannelBuffer c) {
+ c.writeByte(value.proto);
+ }
+
+ @Override
+ public IpProtocol readFrom(ChannelBuffer c) throws OFParseError {
+ return IpProtocol.of((short)(c.readUnsignedByte() & 0x00FF));
+ }
+
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java b/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
index 8806bb3..ec15f74 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
@@ -2,7 +2,6 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-import org.openflow.protocol.OFObject;
import org.openflow.util.HexString;
/**
@@ -11,7 +10,7 @@
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
-public class MacAddress implements OFObject {
+public class MacAddress implements OFValueType {
static final int MacAddrLen = 6;
private final long rawValue;
@@ -77,17 +76,6 @@
return MacAddrLen;
}
- public static MacAddress readFrom(final ChannelBuffer bb) throws OFParseError {
- long raw = bb.readUnsignedInt() << 16 | bb.readUnsignedShort();
- return MacAddress.of(raw);
- }
-
- @Override
- public void writeTo(final ChannelBuffer bb) {
- bb.writeInt((int) (rawValue >> 16));
- bb.writeShort((int) rawValue & 0xFFFF);
- }
-
@Override
public String toString() {
return HexString.toHexString(rawValue, 6);
@@ -119,4 +107,29 @@
return rawValue;
}
+ public static final Serializer<MacAddress> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<MacAddress> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<MacAddress> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<MacAddress> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<MacAddress> {
+
+ @Override
+ public void writeTo(MacAddress value, ChannelBuffer c) {
+ c.writeInt((int) (value.rawValue >> 16));
+ c.writeShort((int) value.rawValue & 0xFFFF);
+ }
+
+ @Override
+ public MacAddress readFrom(ChannelBuffer c) throws OFParseError {
+ long raw = c.readUnsignedInt() << 16 | c.readUnsignedShort();
+ return MacAddress.of(raw);
+ }
+
+
+ }
+
+
+
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddressWithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/MacAddressWithMask.java
deleted file mode 100644
index ffa5fa7..0000000
--- a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddressWithMask.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.openflow.types;
-
-public class MacAddressWithMask {
-
-}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java b/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
index 98a8e0b..de6b604 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
@@ -1,5 +1,97 @@
package org.openflow.types;
-public class Masked<T> {
+
+public class Masked<T extends OFValueType> implements OFValueType {
+ private T value;
+ private T mask;
+
+ private Masked(T value, T mask) {
+ this.value = value;
+ this.mask = mask;
+ }
+
+ public T getValue() {
+ return value;
+ }
+
+ public T getMask() {
+ return mask;
+ }
+
+ @Override
+ public int getLength() {
+ return this.value.getLength() + this.mask.getLength();
+ }
+
+ volatile byte[] bytesCache = null;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized(this) {
+ if (bytesCache == null) {
+ byte[] bytesValue = this.value.getBytes();
+ byte[] bytesMask = this.mask.getBytes();
+ bytesCache = new byte[bytesValue.length + bytesMask.length];
+ System.arraycopy(bytesValue, 0, bytesCache, 0, bytesValue.length);
+ System.arraycopy(bytesMask, 0, bytesCache, bytesValue.length, bytesMask.length);
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ public static <T extends OFValueType> Masked<T> of(T value, T mask) {
+ return new Masked<T>(value, mask);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Masked<?>))
+ return false;
+ Masked<?> mobj = (Masked<?>)obj;
+ return this.value.equals(mobj.value) && this.mask.equals(mobj.mask);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 59;
+ int result = 1;
+ result = prime * result + this.value.hashCode();
+ result = prime * result + this.mask.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (value.getClass() == IPv4.class) {
+ // TODO: How to output the mask when not in CIDR notation?
+ StringBuilder res = new StringBuilder();
+ res.append(((IPv4)value).toString());
+
+ int maskint = ((IPv4)mask).getInt();
+ if (Integer.bitCount((~maskint) + 1) == 1) {
+ // CIDR notation
+ res.append('/');
+ res.append(Integer.bitCount(maskint));
+ } else {
+ // Arbitrary mask not in CIDR notation
+ // TODO: HERE?
+ }
+
+ return res.toString();
+ } else if (value.getClass() == IPv6.class) {
+ // TODO: Return IPv6 string
+ StringBuilder sb = new StringBuilder();
+ sb.append(value.toString()).append('/').append(mask.toString());
+ return sb.toString();
+ } else {
+ // General representation: value/mask
+ StringBuilder sb = new StringBuilder();
+ sb.append(value.toString()).append('/').append(mask.toString());
+ return sb.toString();
+ }
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
index 0853fea..9d87b8f 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
@@ -1,5 +1,8 @@
package org.openflow.types;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+
/**
* A wrapper around the OpenFlow physical port description. The interfaces to
* this object are version agnostic.
@@ -7,6 +10,81 @@
* @author capveg
*/
-public class OFPhysicalPort {
+public class OFPhysicalPort implements OFValueType {
+
+ static final int LENGTH = 4;
+
+ private final int port;
+
+ private OFPhysicalPort(int port) {
+ this.port = port;
+ }
+
+ public static OFPhysicalPort of(int port) {
+ return new OFPhysicalPort(port);
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache = new byte[] { (byte)(port & 0xFF),
+ (byte)((port >>> 8) & 0xFF),
+ (byte)((port >>> 16) & 0xFF),
+ (byte)((port >>> 24) & 0xFF)};
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof OFPhysicalPort))
+ return false;
+ OFPhysicalPort other = (OFPhysicalPort)obj;
+ if (other.port != this.port)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 59;
+ int result = 1;
+ result = prime * result + port;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toHexString(port);
+ }
+
+ public static final Serializer<OFPhysicalPort> SERIALIZER_V11 = new SerializerV11();
+ public static final Serializer<OFPhysicalPort> SERIALIZER_V12 = SERIALIZER_V11;
+ public static final Serializer<OFPhysicalPort> SERIALIZER_V13 = SERIALIZER_V11;
+
+ private static class SerializerV11 implements OFValueType.Serializer<OFPhysicalPort> {
+
+ @Override
+ public void writeTo(OFPhysicalPort value, ChannelBuffer c) {
+ c.writeInt(value.port);
+ }
+
+ @Override
+ public OFPhysicalPort readFrom(ChannelBuffer c) throws OFParseError {
+ return OFPhysicalPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
+ }
+
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
index 4156f1f..22b347d 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
@@ -1,6 +1,8 @@
package org.openflow.types;
+import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.annotations.Immutable;
+import org.openflow.exceptions.OFParseError;
/**
* Abstraction of an logical / OpenFlow switch port (ofp_port_no) in OpenFlow.
@@ -13,7 +15,9 @@
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
@Immutable
-public class OFPort {
+public class OFPort implements OFValueType {
+ static final int LENGTH = 4;
+
// private int constants (OF1.1+) to avoid duplication in the code
// should not have to use these outside this class
private static final int OFPP_ANY_INT = 0xFFffFFff;
@@ -488,4 +492,76 @@
}
}
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache = new byte[] { (byte)(portNumber & 0xFF),
+ (byte)((portNumber >>> 8) & 0xFF),
+ (byte)((portNumber >>> 16) & 0xFF),
+ (byte)((portNumber >>> 24) & 0xFF) };
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof OFPort))
+ return false;
+ OFPort other = (OFPort)obj;
+ if (other.portNumber != this.portNumber)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 53;
+ int result = 1;
+ result = prime * result + portNumber;
+ return result;
+ }
+
+ public static final Serializer<OFPort> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<OFPort> SERIALIZER_V11 = new SerializerV11();
+ public static final Serializer<OFPort> SERIALIZER_V12 = SERIALIZER_V11;
+ public static final Serializer<OFPort> SERIALIZER_V13 = SERIALIZER_V11;
+
+ private static class SerializerV10 implements OFValueType.Serializer<OFPort> {
+
+ @Override
+ public void writeTo(OFPort value, ChannelBuffer c) {
+ c.writeShort(value.portNumber);
+ }
+
+ @Override
+ public OFPort readFrom(ChannelBuffer c) throws OFParseError {
+ return OFPort.of((c.readUnsignedShort() & 0x0FFFF));
+ }
+
+ }
+
+ private static class SerializerV11 implements OFValueType.Serializer<OFPort> {
+
+ @Override
+ public void writeTo(OFPort value, ChannelBuffer c) {
+ c.writeInt(value.portNumber);
+ }
+
+ @Override
+ public OFPort readFrom(ChannelBuffer c) throws OFParseError {
+ return OFPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
+ }
+
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java
new file mode 100644
index 0000000..01e7012
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java
@@ -0,0 +1,18 @@
+package org.openflow.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+
+
+
+public interface OFValueType {
+
+ public int getLength();
+ public byte[] getBytes();
+
+ public interface Serializer<T extends OFValueType> {
+ public void writeTo(T value, ChannelBuffer c);
+ public T readFrom(ChannelBuffer c) throws OFParseError;
+ }
+
+}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java
new file mode 100644
index 0000000..86ed53e
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java
@@ -0,0 +1,92 @@
+package org.openflow.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+
+/**
+ * Represents L4 (Transport Layer) port (TCP, UDP, etc.)
+ *
+ * @author Yotam Harchol (yotam.harchol@bigswitch.com)
+ */
+public class TransportPort implements OFValueType {
+
+ static final int LENGTH = 2;
+ static final int MAX_PORT = 0xFFFF;
+ static final int MIN_PORT = 0;
+
+ private final int port;
+
+ private TransportPort(int port) {
+ this.port = port;
+ }
+
+ public static TransportPort of(int port) {
+ if (port < MIN_PORT || port > MAX_PORT) {
+ throw new IllegalArgumentException("Illegal transport layer port number: " + port);
+ }
+ return new TransportPort(port);
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache;
+
+ @Override
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache = new byte[] { (byte)(port & 0xFF),
+ (byte)((port >>> 8) & 0xFF)};
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof TransportPort))
+ return false;
+ TransportPort other = (TransportPort)obj;
+ if (other.port != this.port)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 59;
+ int result = 1;
+ result = prime * result + port;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(port);
+ }
+
+ public static final Serializer<TransportPort> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<TransportPort> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<TransportPort> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<TransportPort> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<TransportPort> {
+
+ @Override
+ public void writeTo(TransportPort value, ChannelBuffer c) {
+ c.writeShort(value.port);
+ }
+
+ @Override
+ public TransportPort readFrom(ChannelBuffer c) throws OFParseError {
+ return TransportPort.of((c.readUnsignedShort() & 0x0FFFF));
+ }
+
+ }
+
+}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java b/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
index bda2dc1..0a7b7c5 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
@@ -1,5 +1,86 @@
package org.openflow.types;
-public class VlanPcp {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+public class VlanPcp implements OFValueType {
+
+ private static final byte VALIDATION_MASK = 0x07;
+ static final int LENGTH = 1;
+
+ private final byte pcp;
+
+ private VlanPcp(byte pcp) {
+ this.pcp = pcp;
+ }
+
+ public static VlanPcp of(byte pcp) {
+ if ((pcp & VALIDATION_MASK) != pcp)
+ throw new IllegalArgumentException("Illegal VLAN PCP value: " + pcp);
+ return new VlanPcp(pcp);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof VlanPcp))
+ return false;
+ VlanPcp other = (VlanPcp)obj;
+ if (other.pcp != this.pcp)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int prime = 20173;
+ return this.pcp * prime;
+ }
+
+ @Override
+ public String toString() {
+ return "0x" + Integer.toHexString(pcp);
+ }
+
+ public byte getValue() {
+ return pcp;
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ volatile byte[] bytesCache = null;
+
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache =
+ new byte[] { pcp };
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ public static final Serializer<VlanPcp> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<VlanPcp> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<VlanPcp> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<VlanPcp> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<VlanPcp> {
+
+ @Override
+ public void writeTo(VlanPcp value, ChannelBuffer c) {
+ c.writeShort(value.pcp);
+ }
+
+ @Override
+ public VlanPcp readFrom(ChannelBuffer c) throws OFParseError {
+ return VlanPcp.of((byte)(c.readUnsignedByte() & 0xFF));
+ }
+
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java b/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
index 0f9eaf7..11c733d 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
@@ -1,5 +1,88 @@
package org.openflow.types;
-public class VlanVid {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+public class VlanVid implements OFValueType {
+
+ private static final short VALIDATION_MASK = 0x0FFF;
+ final static int LENGTH = 2;
+
+ private final short vid;
+
+ private VlanVid(short vid) {
+ this.vid = vid;
+ }
+
+ public static VlanVid of(short vid) {
+ if ((vid & VALIDATION_MASK) != vid)
+ throw new IllegalArgumentException("Illegal VLAN VID value: " + vid);
+ return new VlanVid(vid);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof VlanVid))
+ return false;
+ VlanVid other = (VlanVid)obj;
+ if (other.vid != this.vid)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int prime = 13873;
+ return this.vid * prime;
+ }
+
+ @Override
+ public String toString() {
+ return "0x" + Integer.toHexString(vid);
+ }
+
+ public short getValue() {
+ return vid;
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+
+ volatile byte[] bytesCache = null;
+
+ public byte[] getBytes() {
+ if (bytesCache == null) {
+ synchronized (this) {
+ if (bytesCache == null) {
+ bytesCache =
+ new byte[] { (byte) ((vid >>> 8) & 0xFF),
+ (byte) ((vid >>> 0) & 0xFF) };
+ }
+ }
+ }
+ return bytesCache;
+ }
+
+ public static final Serializer<VlanVid> SERIALIZER_V10 = new SerializerV10();
+ public static final Serializer<VlanVid> SERIALIZER_V11 = SERIALIZER_V10;
+ public static final Serializer<VlanVid> SERIALIZER_V12 = SERIALIZER_V10;
+ public static final Serializer<VlanVid> SERIALIZER_V13 = SERIALIZER_V10;
+
+ private static class SerializerV10 implements OFValueType.Serializer<VlanVid> {
+
+ @Override
+ public void writeTo(VlanVid value, ChannelBuffer c) {
+ c.writeShort(value.vid);
+ }
+
+ @Override
+ public VlanVid readFrom(ChannelBuffer c) throws OFParseError {
+ return VlanVid.of(c.readShort());
+ }
+
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVidWithMask/VlanVidWithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/VlanVidWithMask/VlanVidWithMask.java
deleted file mode 100644
index 610b11c..0000000
--- a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVidWithMask/VlanVidWithMask.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.openflow.types.VlanVidWithMask;
-
-public class VlanVidWithMask {
-
-}