diff mbox

[ovs-dev] odp: Add datapath clone action parser.

Message ID 1485923042-21558-1-git-send-email-azhou@ovn.org
State Superseded
Headers show

Commit Message

Andy Zhou Feb. 1, 2017, 4:24 a.m. UTC
When adding userspace datapath clone action, the corresponding odp
actions parser and unit tests were missing. This patch adds them.

Reported-by: Ben Pfaff <blp@ovn.org>
Signed-off-by: Andy Zhou <azhou@ovn.org>

---
Note: back port to branch-2.7
---
 lib/odp-util.c | 56 +++++++++++++++++++++++++++++++++++++++++++-------------
 tests/odp.at   |  2 ++
 2 files changed, 45 insertions(+), 13 deletions(-)

Comments

Ben Pfaff Feb. 1, 2017, 5:45 p.m. UTC | #1
On Tue, Jan 31, 2017 at 08:24:02PM -0800, Andy Zhou wrote:
> When adding userspace datapath clone action, the corresponding odp
> actions parser and unit tests were missing. This patch adds them.
> 
> Reported-by: Ben Pfaff <blp@ovn.org>
> Signed-off-by: Andy Zhou <azhou@ovn.org>
> 
> ---
> Note: back port to branch-2.7

Thanks!

Probably, it would be good to be more tolerant of white space.  When I
add a space before the closing ) in a clone action, I get an error:

    blp@sigabrt:~/nicira/ovs/_build(130)$ echo 'clone(1,2 )' | tests/ovstest test-odp parse-actions
    odp_actions_from_string: error
    blp@sigabrt:~/nicira/ovs/_build(0)$ 

Thanks,

Ben.
Andy Zhou Feb. 1, 2017, 9:37 p.m. UTC | #2
On Wed, Feb 1, 2017 at 9:45 AM, Ben Pfaff <blp@ovn.org> wrote:
> On Tue, Jan 31, 2017 at 08:24:02PM -0800, Andy Zhou wrote:
>> When adding userspace datapath clone action, the corresponding odp
>> actions parser and unit tests were missing. This patch adds them.
>>
>> Reported-by: Ben Pfaff <blp@ovn.org>
>> Signed-off-by: Andy Zhou <azhou@ovn.org>
>>
>> ---
>> Note: back port to branch-2.7
>
> Thanks!
>
> Probably, it would be good to be more tolerant of white space.  When I
> add a space before the closing ) in a clone action, I get an error:
>
>     blp@sigabrt:~/nicira/ovs/_build(130)$ echo 'clone(1,2 )' | tests/ovstest test-odp parse-actions
>     odp_actions_from_string: error
>     blp@sigabrt:~/nicira/ovs/_build(0)$
>
> Thanks,
>
> Ben.
Yes, It is worth while improvement to have. I just posted v2.  Thanks Ben.
diff mbox

Patch

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 430793b..e12acf7 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,26 @@  find_end:
 }
 
 static int
+parse_action_list(const char *s, const struct simap *port_names,
+                  struct ofpbuf *actions)
+{
+    int n = 0;
+
+    while (s[n] != ')') {
+        int retval = 0;
+
+        n += strspn(s + n, delimiters);
+        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 +1723,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 +1736,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`