Skip to content
Snippets Groups Projects
Commit f1d6413c authored by Andreas Wundsam's avatar Andreas Wundsam
Browse files

openflowj/Wildcards: more descriptive names

parent 8455fd5a
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment