Skip to content

Commit

Permalink
odp: Add datapath clone action parser.
Browse files Browse the repository at this point in the history
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]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Feb 1, 2017
1 parent 64e6c33 commit c37f713
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
59 changes: 46 additions & 13 deletions lib/odp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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':
*
Expand Down Expand Up @@ -1560,6 +1563,29 @@ parse_conntrack_action(const char *s_, struct ofpbuf *actions)
return s - s_;
}

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)
Expand Down Expand Up @@ -1700,27 +1726,34 @@ 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);

return s[n + 1] == ')' ? n + 2 : -EINVAL;
}
}

{
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;
Expand Down
2 changes: 2 additions & 0 deletions tests/odp.at
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit c37f713

Please sign in to comment.