java_gen: separate VlanVid and OFVlanVidMatch + push version to 0.3.1
OF1.3 specifies the concept of a 'PRESENT' bit (0x1000) that gets
added to the 12 bit VlanVid to indicate presence of a tagged vlan.
While the standard is unclear, our reading is that this is only
relevant for use in match fields/oxms (not in actions).
This commit accordingly splits up VlanVid into
- a new VlanVid class (which just represents the concept of a 12-bit
VLAN tag, as specified by 802.1Q), and
- OFVlanVidMatch (which represents the concepts of an OF1.3 VlanTag
+ Presence Bit, as spec'ed in OF1.3 for matches).
As this is an API-incompatible change, the artifact version has
been pushed to 0.3.1
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatch.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatch.java
new file mode 100644
index 0000000..29d6e02
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatch.java
@@ -0,0 +1,183 @@
+package org.projectfloodlight.openflow.types;
+
+import javax.annotation.Nullable;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+
+import com.google.common.hash.PrimitiveSink;
+import com.google.common.primitives.Shorts;
+
+/** Represents an OpenFlow Vlan VID for use in Matches, as specified by the OpenFlow 1.3 spec.
+ *
+ * <b> Note: this is not just the 12-bit vlan tag. OpenFlow defines
+ * the additional mask bits 0x1000 to represent the presence of a vlan
+ * tag. This additional bit will be stripped when writing a OF1.0 value
+ * tag.
+ * </b>
+ *
+ *
+ * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
+ *
+ */
+public class OFVlanVidMatch implements OFValueType<OFVlanVidMatch> {
+
+ private static final short VALIDATION_MASK = 0x1FFF;
+ private static final short PRESENT_VAL = 0x1000;
+ private static final short VLAN_MASK = 0x0FFF;
+ private static final short NONE_VAL = 0x0000;
+ private static final short UNTAGGED_VAL_OF13 = (short) 0x0000;
+ private static final short UNTAGGED_VAL_OF10 = (short) 0xFFFF;
+ final static int LENGTH = 2;
+
+ /** presence of a VLAN tag is indicated by the presence of bit 0x1000 */
+ public static final OFVlanVidMatch PRESENT = new OFVlanVidMatch(PRESENT_VAL);
+
+ /** this value means 'not set' in OF1.0 (e.g., in a match). not used elsewhere */
+ public static final OFVlanVidMatch NONE = new OFVlanVidMatch(NONE_VAL);
+
+ /** for use with masking operations */
+ public static final OFVlanVidMatch NO_MASK = new OFVlanVidMatch((short)0xFFFF);
+ public static final OFVlanVidMatch FULL_MASK = NONE;
+
+ /** an untagged packet is specified as 0000 in OF 1.0, but 0xFFFF in OF1.0. Special case that. */
+ public static final OFVlanVidMatch UNTAGGED = new OFVlanVidMatch(NONE_VAL) {
+ @Override
+ public void write2BytesOF10(ChannelBuffer c) {
+ c.writeShort(UNTAGGED_VAL_OF10);
+ }
+ };
+
+ private final short vid;
+
+ private OFVlanVidMatch(short vid) {
+ this.vid = vid;
+ }
+
+ public static OFVlanVidMatch ofRawVid(short vid) {
+ if(vid == UNTAGGED_VAL_OF13)
+ return UNTAGGED;
+ else if(vid == PRESENT_VAL)
+ return PRESENT;
+ else if ((vid & VALIDATION_MASK) != vid)
+ throw new IllegalArgumentException(String.format("Illegal VLAN value: %x", vid));
+ return new OFVlanVidMatch(vid);
+ }
+
+ public static OFVlanVidMatch ofVlanVid(VlanVid vid) {
+ return ofVlan(vid.getVlan());
+ }
+
+
+ public static OFVlanVidMatch ofVlan(int vlan) {
+ if( (vlan & VLAN_MASK) != vlan)
+ throw new IllegalArgumentException(String.format("Illegal VLAN value: %x", vlan));
+ return ofRawVid( (short) (vlan | PRESENT_VAL));
+ }
+
+ public static OFVlanVidMatch ofVlanOF10(short of10vlan) {
+ if(of10vlan == NONE_VAL) {
+ return NONE;
+ } else if(of10vlan == UNTAGGED_VAL_OF10) {
+ return UNTAGGED;
+ } else {
+ return ofVlan(of10vlan);
+ }
+ }
+
+ /** @return whether or not this VlanId has the present (0x1000) bit set */
+ public boolean isPresentBitSet() {
+ return (vid & PRESENT_VAL) != 0;
+ }
+
+ /** @return the actual VLAN tag this vid identifies */
+ public short getVlan() {
+ return (short) (vid & VLAN_MASK);
+ }
+
+ /** @return the actual vlan tag this vid identifies as a VlanVid object, if this
+ * VlanVidMatch has the present bit set (i.e., identifies a tagged VLAN).
+ * Else, returns null.
+ */
+ @Nullable
+ public VlanVid getVlanVid() {
+ return isPresentBitSet() ? VlanVid.ofVlan((short) (vid & VLAN_MASK)) : null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof OFVlanVidMatch))
+ return false;
+ OFVlanVidMatch other = (OFVlanVidMatch)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 getRawVid() {
+ 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 void write2Bytes(ChannelBuffer c) {
+ c.writeShort(this.vid);
+ }
+
+ public void write2BytesOF10(ChannelBuffer c) {
+ c.writeShort(this.getVlan());
+ }
+
+ public static OFVlanVidMatch read2Bytes(ChannelBuffer c) throws OFParseError {
+ return OFVlanVidMatch.ofRawVid(c.readShort());
+ }
+
+ public static OFVlanVidMatch read2BytesOF10(ChannelBuffer c) throws OFParseError {
+ return OFVlanVidMatch.ofVlanOF10(c.readShort());
+ }
+
+ @Override
+ public OFVlanVidMatch applyMask(OFVlanVidMatch mask) {
+ return OFVlanVidMatch.ofRawVid((short)(this.vid & mask.vid));
+ }
+
+ @Override
+ public int compareTo(OFVlanVidMatch o) {
+ return Shorts.compare(vid, o.vid);
+ }
+ @Override
+ public void putTo(PrimitiveSink sink) {
+ sink.putShort(vid);
+ }
+}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatchWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatchWithMask.java
new file mode 100644
index 0000000..c91c28c
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFVlanVidMatchWithMask.java
@@ -0,0 +1,10 @@
+package org.projectfloodlight.openflow.types;
+
+public class OFVlanVidMatchWithMask extends Masked<OFVlanVidMatch> {
+ private OFVlanVidMatchWithMask(OFVlanVidMatch value, OFVlanVidMatch mask) {
+ super(value, mask);
+ }
+
+ /* a combination of Vlan Vid and mask that matches any tagged packet */
+ public final static OFVlanVidMatchWithMask ANY_TAGGED = new OFVlanVidMatchWithMask(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
+}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
index d370711..b63e4dc 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
@@ -6,45 +6,23 @@
import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.Shorts;
-/** Represents an OpenFlow Vlan VID, as specified by the OpenFlow 1.3 spec.
- *
- * <b> Note: this is not just the 12-bit vlan tag. OpenFlow defines
- * the additional mask bits 0x1000 to represent the presence of a vlan
- * tag. This additional bit will be stripped when writing a OF1.0 value
- * tag.
- * </b>
- *
+/** Represents an 802.1Q Vlan VID (12 bits).
*
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*
*/
public class VlanVid implements OFValueType<VlanVid> {
- private static final short VALIDATION_MASK = 0x1FFF;
- private static final short PRESENT_VAL = 0x1000;
- private static final short VLAN_MASK = 0x0FFF;
- private static final short NONE_VAL = 0x0000;
- private static final short UNTAGGED_VAL_OF13 = (short) 0x0000;
- private static final short UNTAGGED_VAL_OF10 = (short) 0xFFFF;
+ private static final short VALIDATION_MASK = 0x0FFF;
+ private static final short ZERO_VAL = 0x0000;
final static int LENGTH = 2;
- /** presence of a VLAN tag is idicated by the presence of bit 0x1000 */
- public static final VlanVid PRESENT = new VlanVid(PRESENT_VAL);
-
/** this value means 'not set' in OF1.0 (e.g., in a match). not used elsewhere */
- public static final VlanVid NONE = new VlanVid(NONE_VAL);
+ public static final VlanVid ZERO = new VlanVid(ZERO_VAL);
/** for use with masking operations */
public static final VlanVid NO_MASK = new VlanVid((short)0xFFFF);
- public static final VlanVid FULL_MASK = NONE;
-
- /** an untagged packet is specified as 0000 in OF 1.0, but 0xFFFF in OF1.0. Special case that. */
- public static final VlanVid UNTAGGED = new VlanVid(NONE_VAL) {
- @Override
- public void write2BytesOF10(ChannelBuffer c) {
- c.writeShort(UNTAGGED_VAL_OF10);
- }
- };
+ public static final VlanVid FULL_MASK = ZERO;
private final short vid;
@@ -52,40 +30,15 @@
this.vid = vid;
}
- public static VlanVid ofRawVid(short vid) {
- if(vid == UNTAGGED_VAL_OF13)
- return UNTAGGED;
- else if(vid == PRESENT_VAL)
- return PRESENT;
- else if ((vid & VALIDATION_MASK) != vid)
+ public static VlanVid ofVlan(short vid) {
+ if ((vid & VALIDATION_MASK) != vid)
throw new IllegalArgumentException(String.format("Illegal VLAN value: %x", vid));
return new VlanVid(vid);
}
- public static VlanVid ofVlan(int vlan) {
- if( (vlan & VLAN_MASK) != vlan)
- throw new IllegalArgumentException(String.format("Illegal VLAN value: %x", vlan));
- return ofRawVid( (short) (vlan | PRESENT_VAL));
- }
-
- public static VlanVid ofVlanOF10(short of10vlan) {
- if(of10vlan == NONE_VAL) {
- return NONE;
- } else if(of10vlan == UNTAGGED_VAL_OF10) {
- return UNTAGGED;
- } else {
- return ofVlan(of10vlan);
- }
- }
-
- /** @return whether or not this VlanId has the present (0x1000) bit set */
- public boolean isPresentBitSet() {
- return (vid & PRESENT_VAL) != 0;
- }
-
/** @return the actual VLAN tag this vid identifies */
public short getVlan() {
- return (short) (vid & VLAN_MASK);
+ return vid;
}
@Override
@@ -109,17 +62,11 @@
return "0x" + Integer.toHexString(vid);
}
- public short getRawVid() {
- return vid;
- }
-
-
@Override
public int getLength() {
return LENGTH;
}
-
volatile byte[] bytesCache = null;
public byte[] getBytes() {
@@ -144,22 +91,19 @@
}
public static VlanVid read2Bytes(ChannelBuffer c) throws OFParseError {
- return VlanVid.ofRawVid(c.readShort());
- }
-
- public static VlanVid read2BytesOF10(ChannelBuffer c) throws OFParseError {
- return VlanVid.ofVlanOF10(c.readShort());
+ return VlanVid.ofVlan(c.readShort());
}
@Override
public VlanVid applyMask(VlanVid mask) {
- return VlanVid.ofRawVid((short)(this.vid & mask.vid));
+ return VlanVid.ofVlan((short)(this.vid & mask.vid));
}
@Override
public int compareTo(VlanVid o) {
return Shorts.compare(vid, o.vid);
}
+
@Override
public void putTo(PrimitiveSink sink) {
sink.putShort(vid);
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVidWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVidWithMask.java
deleted file mode 100644
index cb81d31..0000000
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVidWithMask.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.projectfloodlight.openflow.types;
-
-public class VlanVidWithMask extends Masked<VlanVid> {
- private VlanVidWithMask(VlanVid value, VlanVid mask) {
- super(value, mask);
- }
-
- /* a combination of Vlan Vid and mask that matches any tagged packet */
- public final static VlanVidWithMask ANY_TAGGED = new VlanVidWithMask(VlanVid.PRESENT, VlanVid.PRESENT);
-
-}