From patchwork Wed Feb 1 21:36:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 722686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vDGfs2hlPz9sDB for ; Thu, 2 Feb 2017 08:36:53 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D9801B5F; Wed, 1 Feb 2017 21:36:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 8AAEBB5A for ; Wed, 1 Feb 2017 21:36:50 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 07CE5FF for ; Wed, 1 Feb 2017 21:36:48 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id e4so32589501pfg.0 for ; Wed, 01 Feb 2017 13:36:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mk3rXHBQ64RaNt11QuHmkZmcT8HWno6KhUdUqgDuTeg=; b=FvC3ePzP96zAyhEuYyGcKZdAjzgP5/2tMdvfa1Lyvj/c7H+loqhk3tqGiBdqyWNHn0 D5R0YtxwTT8dbOAbn25NlnazgPs/S2ABMQaurr/G8x7lrnoKGBeKLtYrFAVicYE41HoL +C/5Yv+CRIrOonlJG2R6WJW7Ett9yamzr2ajZr/uhtR9BTQOL14OmAiUJN744Uzeigix qK0YBvS5xj2kB1AV9voNA9819/juioNtHEz/LlXfpWy0uAYZoykFz51R6Kcr5YnHNDI+ YCDIcRyw7zJgSZE78lt4O7ioC5bQPAZl8oZOTrygdYsI/FReZ8IiJA+8OZbs0gHPq4Nc QjJg== X-Gm-Message-State: AIkVDXJN3+fV3vh9c+gYxoPIFDJpiOegP+wIi94O1hVJPais72/gAQvm0P9CZRWEWbYcnQ== X-Received: by 10.99.114.91 with SMTP id c27mr6415841pgn.163.1485985008491; Wed, 01 Feb 2017 13:36:48 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id c204sm52030845pfb.51.2017.02.01.13.36.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Feb 2017 13:36:47 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Wed, 1 Feb 2017 13:36:33 -0800 Message-Id: <1485984993-22577-1-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [v2] odp: Add datapath clone action parser. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When adding userspace datapath clone action, the corresponding odp actions parser and unit tests were missing. This patch adds them. Reported-by: Ben Pfaff Signed-off-by: Andy Zhou Acked-by: Ben Pfaff --- 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`