Commit 37de65a7 authored by Aaron Conole's avatar Aaron Conole Committed by Jakub Kicinski

selftests: openvswitch: Refactor actions parsing.

Until recently, the ovs-dpctl utility was used with a limited actions set
and didn't need to have support for multiple similar actions.  However,
when adding support for tunnels, it will be important to support multiple
set() actions in a single flow.  When printing these actions, the existing
code will be unable to print all of the sets - it will only print the
first.

Refactor this code to be easier to read and support multiple actions of the
same type in an action list.
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Tested-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarAaron Conole <aconole@redhat.com>
Link: https://patch.msgid.link/20240625172245.233874-3-aconole@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f94ecbc9
...@@ -439,32 +439,30 @@ class ovsactions(nla): ...@@ -439,32 +439,30 @@ class ovsactions(nla):
def dpstr(self, more=False): def dpstr(self, more=False):
print_str = "" print_str = ""
for field in self.nla_map: for field in self["attrs"]:
if field[1] == "none" or self.get_attr(field[0]) is None: if field[1] == "none" or self.get_attr(field[0]) is None:
continue continue
if print_str != "": if print_str != "":
print_str += "," print_str += ","
if field[1] == "uint32": if field[0] == "OVS_ACTION_ATTR_OUTPUT":
if field[0] == "OVS_ACTION_ATTR_OUTPUT": print_str += "%d" % int(self.get_attr(field[0]))
print_str += "%d" % int(self.get_attr(field[0])) elif field[0] == "OVS_ACTION_ATTR_RECIRC":
elif field[0] == "OVS_ACTION_ATTR_RECIRC": print_str += "recirc(0x%x)" % int(self.get_attr(field[0]))
print_str += "recirc(0x%x)" % int(self.get_attr(field[0])) elif field[0] == "OVS_ACTION_ATTR_TRUNC":
elif field[0] == "OVS_ACTION_ATTR_TRUNC": print_str += "trunc(%d)" % int(self.get_attr(field[0]))
print_str += "trunc(%d)" % int(self.get_attr(field[0])) elif field[0] == "OVS_ACTION_ATTR_DROP":
elif field[0] == "OVS_ACTION_ATTR_DROP": print_str += "drop(%d)" % int(self.get_attr(field[0]))
print_str += "drop(%d)" % int(self.get_attr(field[0])) elif field[0] == "OVS_ACTION_ATTR_CT_CLEAR":
elif field[1] == "flag": print_str += "ct_clear"
if field[0] == "OVS_ACTION_ATTR_CT_CLEAR": elif field[0] == "OVS_ACTION_ATTR_POP_VLAN":
print_str += "ct_clear" print_str += "pop_vlan"
elif field[0] == "OVS_ACTION_ATTR_POP_VLAN": elif field[0] == "OVS_ACTION_ATTR_POP_ETH":
print_str += "pop_vlan" print_str += "pop_eth"
elif field[0] == "OVS_ACTION_ATTR_POP_ETH": elif field[0] == "OVS_ACTION_ATTR_POP_NSH":
print_str += "pop_eth" print_str += "pop_nsh"
elif field[0] == "OVS_ACTION_ATTR_POP_NSH": elif field[0] == "OVS_ACTION_ATTR_POP_MPLS":
print_str += "pop_nsh" print_str += "pop_mpls"
elif field[0] == "OVS_ACTION_ATTR_POP_MPLS":
print_str += "pop_mpls"
else: else:
datum = self.get_attr(field[0]) datum = self.get_attr(field[0])
if field[0] == "OVS_ACTION_ATTR_CLONE": if field[0] == "OVS_ACTION_ATTR_CLONE":
...@@ -472,7 +470,10 @@ class ovsactions(nla): ...@@ -472,7 +470,10 @@ class ovsactions(nla):
print_str += datum.dpstr(more) print_str += datum.dpstr(more)
print_str += ")" print_str += ")"
else: else:
print_str += datum.dpstr(more) try:
print_str += datum.dpstr(more)
except:
print_str += "{ATTR: %s not decoded}" % field[0]
return print_str return print_str
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment