Skip to content

Commit

Permalink
python: Include aliases in ofp_fields.py.
Browse files Browse the repository at this point in the history
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]>
Acked-by: Mike Pattrick <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
amorenoz authored and Simon Horman committed Jan 18, 2024
1 parent 2892622 commit d15b3d0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions build-aux/gen_ofp_field_decoders
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,42 @@ def main():
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", []):
aliases[nxm[1]] = field.get("name")

code = """
# This file is auto-generated. Do not edit!
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)


Expand Down

0 comments on commit d15b3d0

Please sign in to comment.