On 10/24/22 17:55, Mike Pattrick wrote:
On Mon, Oct 17, 2022 at 9:18 AM Adrian Moreno <[email protected]> wrote:
We currently auto-generate a dictionary of field names and decoders.
However, sometimes fields can be specified by their cannonical NXM or
OXM names.
Modify gen_ofp_field_decoders to also generate a dictionary of aliases
so it's easy to map OXM/NXM names to their fields and decoding
information.
Signed-off-by: Adrian Moreno <[email protected]>
---
build-aux/gen_ofp_field_decoders | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/build-aux/gen_ofp_field_decoders b/build-aux/gen_ofp_field_decoders
index 96f99e860..9f7bdaa83 100755
--- a/build-aux/gen_ofp_field_decoders
+++ b/build-aux/gen_ofp_field_decoders
@@ -22,12 +22,16 @@ def main():
fields = extract_fields.extract_ofp_fields(args.metaflow)
field_decoders = {}
+ aliases = {}
for field in fields:
decoder = get_decoder(field)
field_decoders[field.get("name")] = decoder
if field.get("extra_name"):
field_decoders[field.get("extra_name")] = decoder
+ for nxm in field.get("OXM"):
I believe that field will be a dictionary here, if "OXM" is not
present in the dictionary then .get() without a second parameter will
return None and result in an exception. If OXM is not an optional
parameter then this could be changed to "for nxm in field["OXM"]",
else, if it is optional, then "field.get("OXM", [])" should be used.
Hi Mike, you're right, None is not iterable. "OXM" is a mandatory field in this
case so I'll change it to 'for nxm in field["OXM"]'.
+ aliases[nxm[1]] = field.get("name")
+
code = """
# This file is auto-generated. Do not edit!
@@ -35,14 +39,25 @@ from ovs.flow import decoders
field_decoders = {{
{decoders}
+}}
+
+field_aliases = {{
+{aliases}
}}""".format(
decoders="\n".join(
[
" '{name}': {decoder},".format(name=name, decoder=decoder)
for name, decoder in field_decoders.items()
]
+ ),
+ aliases="\n".join(
+ [
+ " '{alias}': '{name}',".format(name=name, alias=alias)
+ for alias, name in aliases.items()
+ ]
)
)
+
print(code)
--
2.37.3
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev
--
Adrián Moreno
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev