OFPortMap value type
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index b03c224..f40bc71 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -229,7 +229,8 @@
"OFOxmMplsLabel": OxmMapEntry("U32", "MPLS_LABEL", False),
"OFOxmMplsLabelMasked": OxmMapEntry("U32", "MPLS_LABEL", True),
"OFOxmMplsTc": OxmMapEntry("U8", "MPLS_TC", False),
- "OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True)
+ "OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True),
+ "OFOxmBsnInPortsMasked128": OxmMapEntry("OFPortMap", "BSN_IN_PORTS_MASKED_128", True)
}
# Registry of nullable properties:
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index 87ce9d6..035b11e 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -380,6 +380,10 @@
table_stats_wildcards = JType("int") \
.op(read='bb.readInt()',
write='bb.writeInt($name)')
+port_map = JType('OFPortMap') \
+ .op(read='OFPortMap.read16Bytes(bb)',
+ write='$name.write16Bytes(bb)',
+ default='OFPortMap.NONE')
port_speed = JType("PortSpeed")
@@ -417,6 +421,7 @@
'of_wc_bmap_t': flow_wildcards,
'of_oxm_t': oxm,
'of_meter_features_t': meter_features,
+ 'of_bitmap_128': port_map
}
## Map that defines exceptions from the standard loxi->java mapping scheme
@@ -470,6 +475,8 @@
'of_oxm_mpls_label_masked' : { 'value' : u32obj, 'value_mask' : u32obj },
'of_oxm_mpls_tc' : { 'value' : u8obj },
'of_oxm_mpls_tc_masked' : { 'value' : u8obj, 'value_mask' : u8obj },
+
+ 'of_oxm_bsn_in_ports_masked_128' : { 'value': port_map, 'value_mask': port_map },
'of_table_stats_entry': { 'wildcards': table_stats_wildcards },
'of_match_v1': { 'vlan_vid' : vlan_vid, 'vlan_pcp': vlan_pcp,
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 47ca9da..08a368d 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,6 +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.OFPortMap;
import org.projectfloodlight.openflow.types.OFValueType;
import org.projectfloodlight.openflow.types.TransportPort;
import org.projectfloodlight.openflow.types.U32;
@@ -170,6 +171,9 @@
new MatchField<U8>("mpls_tc", MatchFields.MPLS_TC,
new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
+ public final static MatchField<OFPortMap> BSN_IN_PORTS_MASKED_128 =
+ new MatchField<OFPortMap>("bsn_in_port_masked_128", MatchFields.BSN_IN_PORTS_MASKED_128);
+
public String getName() {
return name;
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchFields.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchFields.java
index 7deb9af..c73530b 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchFields.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/MatchFields.java
@@ -37,5 +37,6 @@
IPV6_ND_SLL,
IPV6_ND_TLL,
MPLS_LABEL,
- MPLS_TC
+ MPLS_TC,
+ BSN_IN_PORTS_MASKED_128
}
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
new file mode 100644
index 0000000..b666782
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPortMap.java
@@ -0,0 +1,117 @@
+package org.projectfloodlight.openflow.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+
+public class OFPortMap implements OFValueType<OFPortMap> {
+
+ static final int LENGTH = 16;
+
+ private final long raw1;
+ private final long raw2;
+
+ public static final OFPortMap NONE = of(0, 0);
+
+ private OFPortMap(long raw1, long raw2) {
+ this.raw1 = raw1;
+ this.raw2 = raw2;
+
+ }
+
+ public static OFPortMap of(long raw1, long raw2) {
+ if (raw1 == 0 && raw2 == 0)
+ return NONE;
+ return new OFPortMap(raw1, raw2);
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ @Override
+ public OFPortMap applyMask(OFPortMap mask) {
+ return of(this.raw1 & mask.raw1, this.raw2 & mask.raw2);
+ }
+
+ public void write16Bytes(ChannelBuffer cb) {
+ cb.writeLong(raw1);
+ cb.writeLong(raw2);
+ }
+
+ public static OFPortMap read16Bytes(ChannelBuffer cb) {
+ long raw1 = cb.readLong();
+ long raw2 = cb.readLong();
+ return of(raw1, raw2);
+ }
+
+ private static boolean isBitOn(long raw1, long raw2, int bit) {
+ if (bit < 0 || bit >= 128)
+ throw new IndexOutOfBoundsException("Port number is out of bounds");
+ long word;
+ if (bit < 64) {
+ word = raw1;
+ } else {
+ word = raw2;
+ bit -= 64;
+ }
+ return (word & ((long)1 << bit)) != 0;
+ }
+
+ public boolean isOn(OFPort port) {
+ return isBitOn(raw1, raw2, port.getPortNumber());
+ }
+
+ public static OFPortMap ofPorts(OFPort... ports) {
+ Builder builder = new Builder();
+ for (OFPort port: ports) {
+ builder.set(port);
+ }
+ return builder.build();
+ }
+
+ @Override
+ public String toString() {
+ return (String.format("%64s", Long.toBinaryString(raw2)) + String.format("%64s", Long.toBinaryString(raw1))).replaceAll(" ", "0");
+ }
+
+ public static class Builder {
+ private long raw1, raw2;
+
+ public Builder() {
+
+ }
+
+ public boolean isOn(OFPort port) {
+ return isBitOn(raw1, raw2, port.getPortNumber());
+ }
+
+ public Builder set(OFPort port) {
+ int bit = port.getPortNumber();
+ if (bit < 0 || bit >= 128)
+ throw new IndexOutOfBoundsException("Port number is out of bounds");
+ if (bit < 64) {
+ raw1 |= ((long)1 << bit);
+ } else {
+ raw2 |= ((long)1 << (bit - 64));
+ }
+ return this;
+ }
+
+ public Builder unset(OFPort port) {
+ int bit = port.getPortNumber();
+ if (bit < 0 || bit >= 128)
+ throw new IndexOutOfBoundsException("Port number is out of bounds");
+ if (bit < 64) {
+ raw1 &= ~((long)1 << bit);
+ } else {
+ raw2 &= ~((long)1 << (bit - 64));
+ }
+ return this;
+ }
+
+ public OFPortMap build() {
+ return OFPortMap.of(raw1, raw2);
+ }
+ }
+
+}
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFPortMapTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFPortMapTest.java
new file mode 100644
index 0000000..8f31c3b
--- /dev/null
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/OFPortMapTest.java
@@ -0,0 +1,54 @@
+package org.projectfloodlight.openflow.types;
+
+import static org.junit.Assert.assertArrayEquals;
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+public class OFPortMapTest extends TestCase {
+
+ @Test
+ public void testOFPortMap() {
+ Boolean[] on = new Boolean[128];
+ for (int i = 0; i < 128; i++) {
+ on[i] = false;
+ }
+
+ OFPortMap.Builder builder = new OFPortMap.Builder();
+
+ for (int i = 0; i < 128; i += 3) {
+ OFPort p = OFPort.of(i);
+ builder.set(p);
+ on[p.getPortNumber()] = true;
+ }
+
+ // Test that all ports that were added are actually on, and all other ports are off
+ OFPortMap portmap = builder.build();
+ System.out.println(portmap);
+ Boolean[] actual = new Boolean[128];
+ for (int i = 0; i < 128; i++) {
+ actual[i] = false;
+ }
+ for (int i = 0; i < 128; i++) {
+ actual[i] = portmap.isOn(OFPort.of(i));
+ }
+ assertArrayEquals(on, actual);
+
+ // Turn some ports off
+ for (int i = 0; i < 128; i += 7) {
+ on[i] = false;
+ builder.unset(OFPort.of(i));
+ }
+
+ // Test again
+ portmap = builder.build();
+ actual = new Boolean[128];
+ for (int i = 0; i < 128; i++) {
+ actual[i] = false;
+ }
+ for (int i = 0; i < 128; i++) {
+ actual[i] = portmap.isOn(OFPort.of(i));
+ }
+ assertArrayEquals(on, actual);
+ }
+}