From patchwork Wed Feb 1 04:24:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 722344 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 3vCqlV25q7z9ryv for ; Wed, 1 Feb 2017 15:24:22 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BB857BC7; Wed, 1 Feb 2017 04:24:19 +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 5FA7CB50 for ; Wed, 1 Feb 2017 04:24:18 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7689ACF for ; Wed, 1 Feb 2017 04:24:17 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id 3so15169249pgj.1 for ; Tue, 31 Jan 2017 20:24:17 -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=atn5Tf/RkYQNibuZfjfHfiMP7No4rEBhmQrAH5k6BVE=; b=laZnuK2Kmyf/gXxe8e5WyxBDmivTOXcjYAquVUUR6m5F0sl7n7Zh8iiFPD7vb476QK xE67sSAxIP3rt/0+Da6JQHkg9nuWFUDaozict8AUIcsDjRrMu5adCXiFucdxZBLyh8Dd x68qyv6LAoRtnM68Xia/WYUCEHjl+DKHCObGlWbTBIW3xl5Wa3YdD3KNriRFZ/wWAqh1 LgiI1WhjB/6KSFstgSaSWL/zBxupuMGqWHTZBD8RSQfL7aez42cZVFr3cvDpE8FzIu4Y PPyuXR2w3QUWxtgFYN3FPfS9axSMRRKKMMNORJqg1PhWtOzOh6UA5F4DrAzLVn8WU+wN vjIg== X-Gm-Message-State: AIkVDXKAVst43/8HtVqeJNJfUOnNADLlHELFh8w3XsjKcFPdUIg+w+nwFG4Zovpag92DBQ== X-Received: by 10.99.109.143 with SMTP id i137mr1123234pgc.11.1485923056855; Tue, 31 Jan 2017 20:24:16 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id o12sm44870290pfg.15.2017.01.31.20.24.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jan 2017 20:24:16 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Tue, 31 Jan 2017 20:24:02 -0800 Message-Id: <1485923042-21558-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] [PATCH] 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 --- Note: back port to branch-2.7 --- lib/odp-util.c | 56 +++++++++++++++++++++++++++++++++++++++++++------------- tests/odp.at | 2 ++ 2 files changed, 45 insertions(+), 13 deletions(-) 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`