When adding userspace datapath clone action, the corresponding odp actions parser and unit tests were missing. This patch adds them.
Reported-by: Ben Pfaff <[email protected]> Signed-off-by: Andy Zhou <[email protected]> --- v1->v2: Be more tolerate of white spaces. Tested with: $ echo 'clone(1,2 )' |../tests/ovstest test-odp parse-actions clone(1,2) --- lib/odp-util.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------------- tests/odp.at | 2 ++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/odp-util.c b/lib/odp-util.c index 430793b..4106738 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -89,6 +89,9 @@ static void format_u128(struct ds *ds, const ovs_u128 *value, const ovs_u128 *mask, bool verbose); static int scan_u128(const char *s, ovs_u128 *value, ovs_u128 *mask); +static int parse_odp_action(const char *s, const struct simap *port_names, + struct ofpbuf *actions); + /* Returns one the following for the action with the given OVS_ACTION_ATTR_* * 'type': * @@ -1561,6 +1564,29 @@ find_end: } static int +parse_action_list(const char *s, const struct simap *port_names, + struct ofpbuf *actions) +{ + int n = 0; + + for (;;) { + int retval; + + n += strspn(s + n, delimiters); + if (s[n] == ')') { + break; + } + retval = parse_odp_action(s + n, port_names, actions); + if (retval < 0) { + return retval; + } + n += retval; + } + + return n; +} + +static int parse_odp_action(const char *s, const struct simap *port_names, struct ofpbuf *actions) { @@ -1700,20 +1726,11 @@ parse_odp_action(const char *s, const struct simap *port_names, actions_ofs = nl_msg_start_nested(actions, OVS_SAMPLE_ATTR_ACTIONS); - for (;;) { - int retval; - - n += strspn(s + n, delimiters); - if (s[n] == ')') { - break; - } + int retval = parse_action_list(s + n, port_names, actions); + if (retval < 0) + return retval; - retval = parse_odp_action(s + n, port_names, actions); - if (retval < 0) { - return retval; - } - n += retval; - } + n += retval; nl_msg_end_nested(actions, actions_ofs); nl_msg_end_nested(actions, sample_ofs); @@ -1722,6 +1739,22 @@ parse_odp_action(const char *s, const struct simap *port_names, } { + if (!strncmp(s, "clone(", 6)) { + size_t actions_ofs; + int n = 6; + + actions_ofs = nl_msg_start_nested(actions, OVS_ACTION_ATTR_CLONE); + int retval = parse_action_list(s + n, port_names, actions); + if (retval < 0) { + return retval; + } + n += retval; + nl_msg_end_nested(actions, actions_ofs); + return n + 1; + } + } + + { uint32_t port; int n; diff --git a/tests/odp.at b/tests/odp.at index 019897c..db1e827 100644 --- a/tests/odp.at +++ b/tests/odp.at @@ -333,6 +333,8 @@ ct(commit,nat(src=fe80::20c:29ff:fe88:1-fe80::20c:29ff:fe88:a18b,random)) ct(commit,nat(src=[[fe80::20c:29ff:fe88:1]]-[[fe80::20c:29ff:fe88:a18b]]:255-4096,random)) ct(commit,helper=ftp,nat(src=10.1.1.240-10.1.1.255)) trunc(100) +clone(1) +clone(clone(push_vlan(vid=12,pcp=0),2),1) ]) AT_CHECK_UNQUOTED([ovstest test-odp parse-actions < actions.txt], [0], [`cat actions.txt` -- 1.8.3.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
