From f1d6413c5b89cc58854315a7cff415c5c1945d3f Mon Sep 17 00:00:00 2001
From: Andreas Wundsam <andreas.wundsam@bigswitch.com>
Date: Mon, 12 Nov 2012 14:57:58 -0800
Subject: [PATCH] openflowj/Wildcards: more descriptive names

---
 .../java/org/openflow/protocol/Wildcards.java | 18 ++++---
 .../org/openflow/protocol/WildcardsTest.java  | 50 +++++++++----------
 2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/openflow/protocol/Wildcards.java b/src/main/java/org/openflow/protocol/Wildcards.java
index d8ee83b43..2b411224e 100644
--- a/src/main/java/org/openflow/protocol/Wildcards.java
+++ b/src/main/java/org/openflow/protocol/Wildcards.java
@@ -39,15 +39,19 @@ import com.google.common.base.Joiner;
  */
 public class Wildcards {
 
-    public final static Wildcards ALL = new Wildcards(
-            OFMatch.OFPFW_ALL_SANITIZED);
-    public final static Wildcards NONE = new Wildcards(0);
+    public final static Wildcards FULL = new Wildcards(OFMatch.OFPFW_ALL_SANITIZED);
+
+    public final static Wildcards EXACT = new Wildcards(0);
 
     // floodlight common case: matches on inport + l2
     public final static int INT_INPORT_L2_MATCH = 0x3820e0;
     public final static Wildcards INPORT_L2_MATCH = new Wildcards(
             INT_INPORT_L2_MATCH);
 
+    /**
+     * enum type for the binary flags that can be set in the wildcards field of
+     * an OFMatch. Replaces the unwieldy c-ish int constants in OFMatch.
+     */
     public static enum Flag {
         IN_PORT(OFMatch.OFPFW_IN_PORT),  /* Switch input port. */
         DL_VLAN(OFMatch.OFPFW_DL_VLAN), /* VLAN id. */
@@ -85,10 +89,10 @@ public class Wildcards {
     public static Wildcards of(int flags) {
         switch(flags) {
             case 0x0000:
-                return NONE;
+                return EXACT;
             case OFMatch.OFPFW_ALL:
             case OFMatch.OFPFW_ALL_SANITIZED:
-                return ALL;
+                return FULL;
             case INT_INPORT_L2_MATCH:
                 return INPORT_L2_MATCH;
             default:
@@ -371,12 +375,12 @@ public class Wildcards {
      * is this a wildcard set that has all flags set + and full (/0) nw_src and
      * nw_dst wildcarding ?
      */
-    public boolean isAll() {
+    public boolean isFull() {
         return flags == OFMatch.OFPFW_ALL || flags == OFMatch.OFPFW_ALL_SANITIZED;
     }
 
     /** is this a wildcard of an exact match */
-    public boolean isNone() {
+    public boolean isExact() {
         return flags == 0;
     }
 
diff --git a/src/test/java/org/openflow/protocol/WildcardsTest.java b/src/test/java/org/openflow/protocol/WildcardsTest.java
index 802805764..8c28647f9 100644
--- a/src/test/java/org/openflow/protocol/WildcardsTest.java
+++ b/src/test/java/org/openflow/protocol/WildcardsTest.java
@@ -25,63 +25,63 @@ public class WildcardsTest {
     public void testAllSanitize() {
         Wildcards w = Wildcards.of(OFMatch.OFPFW_ALL);
         assertEquals(OFMatch.OFPFW_ALL_SANITIZED, w.getInt());
-        assertTrue(w.isAll());
-        assertFalse(w.isNone());
+        assertTrue(w.isFull());
+        assertFalse(w.isExact());
     }
 
     @Test
     public void testAll() {
-        Wildcards all = Wildcards.ALL;
-        assertTrue(all.isAll());
-        assertFalse(all.isNone());
+        Wildcards all = Wildcards.FULL;
+        assertTrue(all.isFull());
+        assertFalse(all.isExact());
         assertEquals(0, all.getNwDstMask());
         assertEquals(0, all.getNwSrcMask());
 
         // unsetting flags from NONE is a no-op
         Wildcards stillAll = all.set(Flag.IN_PORT);
-        assertTrue(stillAll.isAll());
+        assertTrue(stillAll.isFull());
         assertEquals(all, stillAll);
 
         // so is setting a >= 32 netmask
 
         stillAll = all.setNwSrcMask(0);
-        assertTrue(stillAll.isAll());
+        assertTrue(stillAll.isFull());
         assertEquals(all, stillAll);
 
         stillAll = all.setNwDstMask(0);
-        assertTrue(stillAll.isAll());
+        assertTrue(stillAll.isFull());
         assertEquals(all, stillAll);
     }
 
     @Test
     public void testNone() {
-        Wildcards none = Wildcards.NONE;
-        assertTrue(none.isNone());
+        Wildcards none = Wildcards.EXACT;
+        assertTrue(none.isExact());
         assertEquals(32, none.getNwDstMask());
         assertEquals(32, none.getNwSrcMask());
 
         // unsetting flags from NONE is a no-op
         Wildcards stillNone = none.unset(Flag.IN_PORT);
-        assertTrue(stillNone.isNone());
+        assertTrue(stillNone.isExact());
         assertEquals(none, stillNone);
 
         // so is setting a >= 32 netmask
         stillNone = none.setNwSrcMask(32);
-        assertTrue(stillNone.isNone());
+        assertTrue(stillNone.isExact());
         assertEquals(none, stillNone);
 
         stillNone = none.setNwDstMask(32);
-        assertTrue(stillNone.isNone());
+        assertTrue(stillNone.isExact());
         assertEquals(none, stillNone);
     }
 
     @Test
     public void testSetOneFlag() {
-        Wildcards none = Wildcards.NONE;
-        assertTrue(none.isNone());
+        Wildcards none = Wildcards.EXACT;
+        assertTrue(none.isExact());
         assertFalse(none.hasFlag(Flag.DL_SRC));
         Wildcards one = none.set(Flag.DL_SRC);
-        assertFalse(one.isNone());
+        assertFalse(one.isExact());
         assertTrue(one.hasFlag(Flag.DL_SRC));
         assertEquals(OFMatch.OFPFW_DL_SRC, one.getInt());
         assertEquals(EnumSet.of(Flag.DL_SRC), one.getFlags());
@@ -89,11 +89,11 @@ public class WildcardsTest {
 
     @Test
     public void testSetTwoFlags() {
-        Wildcards none = Wildcards.NONE;
+        Wildcards none = Wildcards.EXACT;
 
         // set two flags
         Wildcards two = none.set(Flag.DL_SRC, Flag.DL_DST);
-        assertFalse(two.isNone());
+        assertFalse(two.isExact());
         assertTrue(two.hasFlag(Flag.DL_SRC));
         assertTrue(two.hasFlag(Flag.DL_DST));
         assertEquals(OFMatch.OFPFW_DL_SRC | OFMatch.OFPFW_DL_DST, two.getInt());
@@ -101,7 +101,7 @@ public class WildcardsTest {
 
         // unset dl_dst
         Wildcards gone = two.unset(Flag.DL_DST);
-        assertFalse(gone.isNone());
+        assertFalse(gone.isExact());
         assertTrue(gone.hasFlag(Flag.DL_SRC));
         assertFalse(gone.hasFlag(Flag.DL_DST));
         assertEquals(OFMatch.OFPFW_DL_SRC, gone.getInt());
@@ -110,12 +110,12 @@ public class WildcardsTest {
 
     @Test
     public void testSetNwSrc() {
-        Wildcards none = Wildcards.NONE;
+        Wildcards none = Wildcards.EXACT;
         assertEquals(32, none.getNwSrcMask());
 
         // unsetting flags from NONE is a no-op
         Wildcards nwSet = none.setNwSrcMask(8);
-        assertFalse(nwSet.isNone());
+        assertFalse(nwSet.isExact());
         assertEquals(EnumSet.noneOf(Flag.class), nwSet.getFlags());
         assertEquals(8, nwSet.getNwSrcMask());
         assertEquals((32 - 8) << OFMatch.OFPFW_NW_SRC_SHIFT, nwSet.getInt());
@@ -123,12 +123,12 @@ public class WildcardsTest {
 
     @Test
     public void testSetNwDst() {
-        Wildcards none = Wildcards.NONE;
+        Wildcards none = Wildcards.EXACT;
         assertEquals(32, none.getNwDstMask());
 
         // unsetting flags from NONE is a no-op
         Wildcards nwSet = none.setNwDstMask(8);
-        assertFalse(nwSet.isNone());
+        assertFalse(nwSet.isExact());
         assertEquals(EnumSet.noneOf(Flag.class), nwSet.getFlags());
         assertEquals(8, nwSet.getNwDstMask());
         assertEquals((32 - 8) << OFMatch.OFPFW_NW_DST_SHIFT, nwSet.getInt());
@@ -136,14 +136,14 @@ public class WildcardsTest {
 
     @Test
     public void testToString() {
-        String s = Wildcards.ALL.toString();
+        String s = Wildcards.FULL.toString();
         assertNotNull(s);
         assertTrue(s.length() > 0);
     }
 
     @Test
     public void testInvert() {
-        assertEquals(Wildcards.ALL, Wildcards.NONE.inverted());
+        assertEquals(Wildcards.FULL, Wildcards.EXACT.inverted());
 
         Wildcards some = Wildcards.of(Flag.DL_VLAN, Flag.DL_VLAN_PCP);
         Wildcards inv = some.inverted();
-- 
GitLab