enums: support partial groups in enums that have other semantics *sigh*
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index 9fab422..13a0d09 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -130,6 +130,12 @@
"OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True)
}
+ MaskedEnumGroup = namedtuple("MaskedEnumGroup", ("name", "mask", "members"))
+
+ masked_enum_groups = defaultdict(lambda: (),
+ OFPortState= (MaskedEnumGroup("stp_flags", mask="STP_MASK", members=set(("STP_LISTEN", "STP_LEARN", "STP_FORWARD", "STP_BLOCK"))), )
+ )
+
class OFEnumPropertyMetadata(namedtuple("OFEnumPropertyMetadata", ("name", "type", "value"))):
@property
def variable_name(self):
@@ -1003,8 +1009,6 @@
entry_name_version_value_map = OrderedDefaultDict(lambda: OrderedDict())
for version, ir_enum in version_enum_map.items():
for ir_entry in ir_enum.entries:
- if "virtual" in ir_entry.params:
- continue
entry_name_version_value_map[ir_entry.name][version] = ir_entry.value
self.entries = [ JavaEnumEntry(self, name, version_value_map)
@@ -1078,3 +1082,14 @@
def all_values(self, versions, not_present=None):
return [ self.values[version] if version in self.values else not_present for version in versions ]
+
+ @property
+ @memoize
+ def masked_enum_group(self):
+ group = find(lambda g: self.name in g.members, model.masked_enum_groups[self.enum.name])
+ return group
+
+ @property
+ @memoize
+ def is_mask(self):
+ return any(self.name == g.mask for g in model.masked_enum_groups[self.enum.name])
diff --git a/java_gen/templates/const_set_serializer.java b/java_gen/templates/const_set_serializer.java
index ad0adb1..4fcff22 100644
--- a/java_gen/templates/const_set_serializer.java
+++ b/java_gen/templates/const_set_serializer.java
@@ -46,9 +46,9 @@
public class ${class_name} {
//:: wire_type = enum.wire_type(version)
//:: int_wire_type = enum.wire_type(version).pub_type
- //:: entries = sorted([ (entry, entry.value(version)) for entry in enum.entries if entry.has_value(version) ], lambda (_,va), (_2,vb): va.__cmp__(vb))
+ //:: entries = [entry for entry in enum.entries if entry.has_value(version) ]
- //:: for entry, _ in entries:
+ //:: for entry in entries:
public final static ${int_wire_type} ${entry.name}_VAL = ${entry.format_value(version)};
//:: #endfor
@@ -67,9 +67,21 @@
public static Set<${enum.name}> ofWireValue(${int_wire_type} val) {
EnumSet<${enum.name}> set = EnumSet.noneOf(${enum.name}.class);
- //:: for entry, _ in entries:
+ //:: last_group = None
+ //:: for entry in entries:
+ //:: if entry.is_mask:
+ //:: continue
+ //:: #endif
+ //:: group = entry.masked_enum_group
+ //:: if group:
+ ${"else " if group == last_group else "" }if((val & ${group.mask}_VAL) == ${entry.name}_VAL)
+ set.add(${enum.name}.${entry.name});
+ //:: last_group = group
+ //:: else:
if((val & ${entry.name}_VAL) != 0)
set.add(${enum.name}.${entry.name});
+ //:: last_group = None
+ //:: #endif
//:: #endfor
return Collections.unmodifiableSet(set);
}
@@ -79,7 +91,10 @@
for(${enum.name} e: set) {
switch(e) {
- //:: for entry, _ in entries:
+ //:: for entry in entries:
+ //:: if entry.is_mask:
+ //:: continue
+ //:: #endif
case ${entry.name}:
wireValue |= ${entry.name}_VAL;
break;
diff --git a/openflow_input/standard-1.0 b/openflow_input/standard-1.0
index 4a73261..806a6a9 100644
--- a/openflow_input/standard-1.0
+++ b/openflow_input/standard-1.0
@@ -97,8 +97,8 @@
};
enum ofp_port_state(wire_type=uint32_t, bitmask=True) {
- OFPPS_STP_LISTEN = 0,
OFPPS_LINK_DOWN = 1,
+ OFPPS_STP_LISTEN = 0,
OFPPS_STP_LEARN = 0x100,
OFPPS_STP_FORWARD = 0x200,
OFPPS_STP_BLOCK = 0x300,