Fixes to port map
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index f2983af..f30ab1b 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -230,8 +230,8 @@
"OFOxmMplsLabelMasked": OxmMapEntry("U32", "MPLS_LABEL", True),
"OFOxmMplsTc": OxmMapEntry("U8", "MPLS_TC", False),
"OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True),
- "OFOxmBsnInPorts128": OxmMapEntry("OFPortBitmap", "BSN_IN_PORTS_128", False),
- "OFOxmBsnInPorts128Masked": OxmMapEntry("OFPortBitmap", "BSN_IN_PORTS_128", True)
+ "OFOxmBsnInPorts128": OxmMapEntry("OFBitMask128", "BSN_IN_PORTS_128", False),
+ "OFOxmBsnInPorts128Masked": OxmMapEntry("OFBitMask128", "BSN_IN_PORTS_128", True)
}
# Registry of nullable properties:
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index 16e9183..82510d2 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -380,10 +380,10 @@
table_stats_wildcards = JType("int") \
.op(read='bb.readInt()',
write='bb.writeInt($name)')
-port_bitmap = JType('OFPortBitmap') \
- .op(read='OFPortBitmap.read16Bytes(bb)',
+port_bitmap = JType('OFBitMask128') \
+ .op(read='OFBitMask128.read16Bytes(bb)',
write='$name.write16Bytes(bb)',
- default='OFPortBitmap.NONE')
+ default='OFBitMask128.NONE')
table_id = JType("TableId") \
.op(read='TableId.readByte(bb)',
write='$name.writeByte(bb)',
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchField.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchField.java
index 3eaaa95..5df7012 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchField.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchField.java
@@ -13,7 +13,7 @@
import org.projectfloodlight.openflow.types.MacAddress;
import org.projectfloodlight.openflow.types.OFMetadata;
import org.projectfloodlight.openflow.types.OFPort;
-import org.projectfloodlight.openflow.types.OFPortBitmap;
+import org.projectfloodlight.openflow.types.OFBitMask128;
import org.projectfloodlight.openflow.types.OFValueType;
import org.projectfloodlight.openflow.types.TransportPort;
import org.projectfloodlight.openflow.types.U32;
@@ -171,8 +171,8 @@
new MatchField<U8>("mpls_tc", MatchFields.MPLS_TC,
new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
- public final static MatchField<OFPortBitmap> BSN_IN_PORTS_128 =
- new MatchField<OFPortBitmap>("bsn_in_port_masked_128", MatchFields.BSN_IN_PORTS_128);
+ public final static MatchField<OFBitMask128> BSN_IN_PORTS_128 =
+ new MatchField<OFBitMask128>("bsn_in_port_masked_128", MatchFields.BSN_IN_PORTS_128);
public String getName() {
return name;
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortBitmap.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
similarity index 64%
rename from java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortBitmap.java
rename to java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
index ecf9bc5..2827a72 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortBitmap.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
@@ -2,27 +2,27 @@
import org.jboss.netty.buffer.ChannelBuffer;
-public class OFPortBitmap implements OFValueType<OFPortBitmap> {
+public class OFBitMask128 implements OFValueType<OFBitMask128> {
static final int LENGTH = 16;
private final long raw1; // MSBs (ports 64-127)
private final long raw2; // LSBs (ports 0-63)
- public static final OFPortBitmap ALL = new OFPortBitmap(-1, -1);
- public static final OFPortBitmap NONE = new OFPortBitmap(0, 0);
+ public static final OFBitMask128 ALL = new OFBitMask128(-1, -1);
+ public static final OFBitMask128 NONE = new OFBitMask128(0, 0);
- private OFPortBitmap(long raw1, long raw2) {
+ private OFBitMask128(long raw1, long raw2) {
this.raw1 = raw1;
this.raw2 = raw2;
}
- static OFPortBitmap of(long raw1, long raw2) {
+ static OFBitMask128 of(long raw1, long raw2) {
if (raw1 == -1 && raw2 == -1)
return ALL;
if (raw1 == 0 && raw2 == 0)
return NONE;
- return new OFPortBitmap(raw1, raw2);
+ return new OFBitMask128(raw1, raw2);
}
@Override
@@ -31,15 +31,15 @@
}
@Override
- public OFPortBitmap applyMask(OFPortBitmap mask) {
+ public OFBitMask128 applyMask(OFBitMask128 mask) {
return of(this.raw1 & mask.raw1, this.raw2 & mask.raw2);
}
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof OFPortBitmap))
+ if (!(obj instanceof OFBitMask128))
return false;
- OFPortBitmap other = (OFPortBitmap)obj;
+ OFBitMask128 other = (OFBitMask128)obj;
return (other.raw1 == this.raw1 && other.raw2 == this.raw2);
}
@@ -50,7 +50,7 @@
protected static boolean isBitOn(long raw1, long raw2, int bit) {
if (bit < 0 || bit >= 128)
- throw new IndexOutOfBoundsException("Port number is out of bounds");
+ throw new IndexOutOfBoundsException();
long word;
if (bit < 64) {
word = raw2; // ports 0-63
@@ -61,20 +61,19 @@
return (word & ((long)1 << bit)) != 0;
}
-
public void write16Bytes(ChannelBuffer cb) {
cb.writeLong(raw1);
cb.writeLong(raw2);
}
- public static OFPortBitmap read16Bytes(ChannelBuffer cb) {
+ public static OFBitMask128 read16Bytes(ChannelBuffer cb) {
long raw1 = cb.readLong();
long raw2 = cb.readLong();
return of(raw1, raw2);
}
- public boolean isOn(OFPort port) {
- return isBitOn(raw1, raw2, port.getPortNumber());
+ public boolean isOn(int bit) {
+ return isBitOn(raw1, raw2, bit);
}
@Override
@@ -82,4 +81,12 @@
return (String.format("%64s", Long.toBinaryString(raw2)) + String.format("%64s", Long.toBinaryString(raw1))).replaceAll(" ", "0");
}
+ @Override
+ public int compareTo(OFBitMask128 o) {
+ long c = this.raw1 - o.raw1;
+ if (c != 0)
+ return Long.signum(c);
+ return Long.signum(this.raw2 - o.raw2);
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortMap.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortMap.java
index 0454d39..8ec056e 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortMap.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortMap.java
@@ -1,14 +1,14 @@
package org.projectfloodlight.openflow.types;
-public class OFPortMap extends Masked<OFPortBitmap> {
+public class OFPortMap extends Masked<OFBitMask128> {
- private OFPortMap(OFPortBitmap mask) {
- super(OFPortBitmap.NONE, mask);
+ private OFPortMap(OFBitMask128 mask) {
+ super(OFBitMask128.NONE, mask);
}
public boolean isOn(OFPort port) {
- return this.mask.isOn(port);
+ return !(this.mask.isOn(port.getPortNumber()));
}
public static OFPortMap ofPorts(OFPort... ports) {
@@ -33,19 +33,19 @@
}
public static class Builder {
- private long raw1, raw2;
+ private long raw1 = -1, raw2 = -1;
public Builder() {
}
public boolean isOn(OFPort port) {
- return OFPortBitmap.isBitOn(raw1, raw2, port.getPortNumber());
+ return !(OFBitMask128.isBitOn(raw1, raw2, port.getPortNumber()));
}
- public Builder set(OFPort port) {
+ public Builder unset(OFPort port) {
int bit = port.getPortNumber();
- if (bit < 0 || bit >= 128)
+ if (bit < 0 || bit >= 127) // MAX PORT IS 127
throw new IndexOutOfBoundsException("Port number is out of bounds");
if (bit < 64) {
raw2 |= ((long)1 << bit);
@@ -55,9 +55,9 @@
return this;
}
- public Builder unset(OFPort port) {
+ public Builder set(OFPort port) {
int bit = port.getPortNumber();
- if (bit < 0 || bit >= 128)
+ if (bit < 0 || bit >= 127)
throw new IndexOutOfBoundsException("Port number is out of bounds");
if (bit < 64) {
raw2 &= ~((long)1 << bit);
@@ -68,7 +68,7 @@
}
public OFPortMap build() {
- return new OFPortMap(OFPortBitmap.of(raw1, raw2));
+ return new OFPortMap(OFBitMask128.of(raw1, raw2));
}
}
diff --git a/test_data/of13/oxm_bsn_in_ports_masked_128.data b/test_data/of13/oxm_bsn_in_ports_masked_128.data
index 8d5ec31..9ef5245 100644
--- a/test_data/of13/oxm_bsn_in_ports_masked_128.data
+++ b/test_data/of13/oxm_bsn_in_ports_masked_128.data
@@ -4,10 +4,10 @@
20 # length
00 00 00 00 00 00 00 00 # value
00 00 00 00 00 00 00 00 # ...
-80 00 00 01 00 00 00 00 # mask
-00 00 00 00 00 02 00 01 # ...
+ff ff ff fe ff ff ff ff # mask - Only ports 0, 17, 96 are selected (and thus are zero)
+ff ff ff ff ff fd ff fe # ...
-- python
-ofp.oxm.bsn_in_ports_128_masked(set(), set([0, 17, 96, 127]))
+ofp.oxm.bsn_in_ports_128_masked(set(), set(range(0,128)) - set((0, 17,96)))
-- c
obj = of_oxm_bsn_in_ports_128_masked_new(OF_VERSION_1_3);
{
@@ -15,10 +15,10 @@
of_oxm_bsn_in_ports_128_masked_value_set(obj, bmap);
}
{
- of_bitmap_128_t bmap = { 0x8000000100000000, 0x00000000020001 };
+ of_bitmap_128_t bmap = { 0xfffffffeffffffff , 0xfffffffffffdfffe };
of_oxm_bsn_in_ports_128_masked_value_mask_set(obj, bmap);
}
-- java
-OFPortMap portmap = OFPortMap.ofPorts(OFPort.of(0), OFPort.of(17), OFPort.of(96), OFPort.of(127));
+OFPortMap portmap = OFPortMap.ofPorts(OFPort.of(0), OFPort.of(17), OFPort.of(96));
builder.setValue(portmap.getValue());
builder.setMask(portmap.getMask());