OFVlanVidMatch: enable correct conversion of VlanVid.NO_MASK
Also fixed consistency of null value handling with VlanVid.
+ added unit test
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
index 0fae3e6..0a35926 100644
--- 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
@@ -74,7 +74,14 @@
}
public static OFVlanVidMatch ofVlanVid(VlanVid vid) {
- return ofVlan(vid.getVlan());
+ if(vid == null)
+ return UNTAGGED;
+ else if(VlanVid.NO_MASK.equals(vid))
+ // NO_MASK is a special value in that it doesn't fit in the
+ // allowed value space (0x1FFF) of this type. Do a manual conversion
+ return NO_MASK;
+ else
+ return ofVlan(vid.getVlan());
}
@@ -110,7 +117,12 @@
*/
@Nullable
public VlanVid getVlanVid() {
- return isPresentBitSet() ? VlanVid.ofVlan((short) (vid & VLAN_MASK)) : null;
+ if(this.equals(NO_MASK))
+ return VlanVid.NO_MASK;
+ else if(isPresentBitSet())
+ return VlanVid.ofVlan((short) (vid & VLAN_MASK));
+ else
+ return null;
}
@Override
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFVlanVidMatchTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFVlanVidMatchTest.java
new file mode 100644
index 0000000..ce6e7a2
--- /dev/null
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFVlanVidMatchTest.java
@@ -0,0 +1,44 @@
+package org.projectfloodlight.openflow.types;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+
+public class OFVlanVidMatchTest {
+ @Test
+ public void testofVlanVid() {
+ assertThat(
+ (int) OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(1)).getRawVid(),
+ equalTo(0x1001));
+ assertThat(
+ (int) OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(0xFFF)).getRawVid(),
+ equalTo(0x1FFF));
+ assertThat(OFVlanVidMatch.ofVlanVid(null), equalTo(OFVlanVidMatch.UNTAGGED));
+ assertThat(OFVlanVidMatch.ofVlanVid(VlanVid.NO_MASK),
+ equalTo(OFVlanVidMatch.NO_MASK));
+ // a fully masked VlanVid means "PRESENT" in OFVlanVid
+ // (because a VlanVid always specifies a Vlan)
+ assertThat(OFVlanVidMatch.ofVlanVid(VlanVid.FULL_MASK),
+ equalTo(OFVlanVidMatch.PRESENT));
+ }
+ @Test
+ public void testtoVlanVid() {
+ assertThat(
+ OFVlanVidMatch.ofRawVid((short)0x1001).getVlanVid(),
+ equalTo(VlanVid.ofVlan(1)));
+ assertThat(
+ OFVlanVidMatch.ofRawVid((short)0x1FFF).getVlanVid(),
+ equalTo(VlanVid.ofVlan(0xFFF)));
+ assertThat(OFVlanVidMatch.UNTAGGED.getVlanVid(), CoreMatchers.nullValue());
+ assertThat(
+ OFVlanVidMatch.NO_MASK.getVlanVid(),
+ equalTo(VlanVid.NO_MASK));
+ assertThat(
+ OFVlanVidMatch.PRESENT.getVlanVid(),
+ equalTo(VlanVid.FULL_MASK));
+ }
+
+
+}