Introduce TableId value type
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index 53c37cf..7da6f6a 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -380,7 +380,10 @@
table_stats_wildcards = JType("int") \
.op(read='bb.readInt()',
write='bb.writeInt($name)')
-
+table_id = JType("TableId") \
+ .op(read='TableId.readByte(bb)',
+ write='$name.writeByte(bb)',
+ default='TableId.ALL')
port_speed = JType("PortSpeed")
error_type = JType("OFErrorType")
@@ -538,6 +541,8 @@
return JType("OFActionType", 'short') \
.op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)\
.op(read="OFActionTypeSerializerVer$version.readFrom(bb)", write="OFActionTypeSerializerVer$version.writeTo(bb, $name)", pub_type=True)
+ elif field_name == "table_id" and c_type == "uint8_t":
+ return table_id
elif field_name == "version" and c_type == "uint8_t":
return JType("OFVersion", 'byte') \
.op(read='bb.readByte()', write='bb.writeByte($name)')
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java
new file mode 100644
index 0000000..6353698
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java
@@ -0,0 +1,86 @@
+package org.projectfloodlight.openflow.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+
+public class TableId implements OFValueType<TableId> {
+
+ final static int LENGTH = 1;
+
+ private static final short VALIDATION_MASK = 0x00FF;
+
+ private static final short ALL_VAL = 0x00FF;
+ private static final short NONE_VAL = 0x0000;
+ public static final TableId NONE = new TableId(NONE_VAL);
+ public static final TableId ALL = new TableId(ALL_VAL);
+
+ private final short id;
+
+ private TableId(short id) {
+ this.id = id;
+ }
+
+ public static TableId of(short id) {
+ switch(id) {
+ case NONE_VAL:
+ return NONE;
+ case ALL_VAL:
+ return ALL;
+ default:
+ if ((id & VALIDATION_MASK) != id)
+ throw new IllegalArgumentException("Illegal Table id value: " + id);
+ return new TableId(id);
+ }
+ }
+
+ public static TableId of(int id) {
+ if((id & VALIDATION_MASK) != id)
+ throw new IllegalArgumentException("Illegal Table id value: "+id);
+ return of((short) id);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof TableId))
+ return false;
+ TableId other = (TableId)obj;
+ if (other.id != this.id)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int prime = 13873;
+ return this.id * prime;
+ }
+
+ @Override
+ public String toString() {
+ return "0x" + Integer.toHexString(id);
+ }
+
+ public short getValue() {
+ return id;
+ }
+
+ @Override
+ public int getLength() {
+ return LENGTH;
+ }
+
+ public void writeByte(ChannelBuffer c) {
+ c.writeByte(this.id);
+ }
+
+ public static TableId readByte(ChannelBuffer c) throws OFParseError {
+ return TableId.of(c.readUnsignedByte());
+ }
+
+ @Override
+ public TableId applyMask(TableId mask) {
+ return TableId.of((short)(this.id & mask.id));
+ }
+
+
+}
diff --git a/test_data/of10/flow_stats_entry.data b/test_data/of10/flow_stats_entry.data
index 3422064..b9a8dc1 100644
--- a/test_data/of10/flow_stats_entry.data
+++ b/test_data/of10/flow_stats_entry.data
@@ -110,7 +110,7 @@
of_flow_stats_entry_table_id_set(obj, 3);
-- java
builder
- .setTableId((short) 3)
+ .setTableId(TableId.of(3))
.setMatch(
factory.buildMatch()
.setExact(MatchField.IN_PORT, OFPort.of(3))
diff --git a/test_data/of13/flow_add.data b/test_data/of13/flow_add.data
index f86f4ae..854c908 100644
--- a/test_data/of13/flow_add.data
+++ b/test_data/of13/flow_add.data
@@ -76,7 +76,7 @@
builder.setXid(0x12345678)
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setCookieMask(U64.parseHex("FF00FF00FF00FF00"))
- .setTableId((byte) 3)
+ .setTableId(TableId.of(3))
.setIdleTimeout(5)
.setHardTimeout(10)
.setPriority(6000)
@@ -96,7 +96,7 @@
)
.setInstructions(
ImmutableList.<OFInstruction>of(
- factory.instructions().gotoTable((short)4),
- factory.instructions().gotoTable((short)7)
+ factory.instructions().gotoTable(TableId.of(4)),
+ factory.instructions().gotoTable(TableId.of(7))
)
);
diff --git a/test_data/of13/flow_delete.data b/test_data/of13/flow_delete.data
index 6dee43b..497103f 100644
--- a/test_data/of13/flow_delete.data
+++ b/test_data/of13/flow_delete.data
@@ -76,7 +76,7 @@
builder.setXid(0x12345678)
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setCookieMask(U64.parseHex("FF00FF00FF00FF00"))
- .setTableId((byte) 3)
+ .setTableId(TableId.of(3))
.setIdleTimeout(5)
.setHardTimeout(10)
.setPriority(6000)
@@ -96,7 +96,7 @@
)
.setInstructions(
ImmutableList.<OFInstruction>of(
- factory.instructions().gotoTable((short)4),
- factory.instructions().gotoTable((short)7)
+ factory.instructions().gotoTable(TableId.of(4)),
+ factory.instructions().gotoTable(TableId.of(7))
)
);
diff --git a/test_data/of13/flow_delete_strict.data b/test_data/of13/flow_delete_strict.data
index 5da11a2..83d212c 100644
--- a/test_data/of13/flow_delete_strict.data
+++ b/test_data/of13/flow_delete_strict.data
@@ -76,7 +76,7 @@
builder.setXid(0x12345678)
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setCookieMask(U64.parseHex("FF00FF00FF00FF00"))
- .setTableId((byte) 3)
+ .setTableId(TableId.of(3))
.setIdleTimeout(5)
.setHardTimeout(10)
.setPriority(6000)
@@ -96,7 +96,7 @@
)
.setInstructions(
ImmutableList.<OFInstruction>of(
- factory.instructions().gotoTable((short)4),
- factory.instructions().gotoTable((short)7)
+ factory.instructions().gotoTable(TableId.of(4)),
+ factory.instructions().gotoTable(TableId.of(7))
)
);
diff --git a/test_data/of13/flow_modify.data b/test_data/of13/flow_modify.data
index 7f7f7a6..9b8834d 100644
--- a/test_data/of13/flow_modify.data
+++ b/test_data/of13/flow_modify.data
@@ -76,7 +76,7 @@
builder.setXid(0x12345678)
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setCookieMask(U64.parseHex("FF00FF00FF00FF00"))
- .setTableId((byte) 3)
+ .setTableId(TableId.of(3))
.setIdleTimeout(5)
.setHardTimeout(10)
.setPriority(6000)
@@ -96,7 +96,7 @@
)
.setInstructions(
ImmutableList.<OFInstruction>of(
- factory.instructions().gotoTable((short)4),
- factory.instructions().gotoTable((short)7)
+ factory.instructions().gotoTable(TableId.of(4)),
+ factory.instructions().gotoTable(TableId.of(7))
)
);
diff --git a/test_data/of13/flow_modify_strict.data b/test_data/of13/flow_modify_strict.data
index f288d5f..250adb9 100644
--- a/test_data/of13/flow_modify_strict.data
+++ b/test_data/of13/flow_modify_strict.data
@@ -76,7 +76,7 @@
builder.setXid(0x12345678)
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setCookieMask(U64.parseHex("FF00FF00FF00FF00"))
- .setTableId((byte) 3)
+ .setTableId(TableId.of(3))
.setIdleTimeout(5)
.setHardTimeout(10)
.setPriority(6000)
@@ -96,7 +96,7 @@
)
.setInstructions(
ImmutableList.<OFInstruction>of(
- factory.instructions().gotoTable((short)4),
- factory.instructions().gotoTable((short)7)
+ factory.instructions().gotoTable(TableId.of(4)),
+ factory.instructions().gotoTable(TableId.of(7))
)
);
diff --git a/test_data/of13/packet_in.data b/test_data/of13/packet_in.data
index b32bbee..ca7006f 100644
--- a/test_data/of13/packet_in.data
+++ b/test_data/of13/packet_in.data
@@ -36,7 +36,7 @@
.setBufferId(OFBufferId.of(100))
.setTotalLen(17000)
.setReason(OFPacketInReason.ACTION)
- .setTableId((byte) 20)
+ .setTableId(TableId.of(20))
.setCookie(U64.parseHex("FEDCBA9876543210"))
.setMatch(
factory.buildMatchV3()