From patchwork Fri Jul 21 22:46:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 792362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3xDmFp4cBdz9ryk for ; Sat, 22 Jul 2017 08:50:54 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A1C02BE1; Fri, 21 Jul 2017 22:47:33 +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 4ADFEBC0 for ; Fri, 21 Jul 2017 22:47:29 +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 D7F681C0 for ; Fri, 21 Jul 2017 22:47:28 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id c23so5705810pfe.5 for ; Fri, 21 Jul 2017 15:47:28 -0700 (PDT) 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:in-reply-to :references:content-transfer-encoding; bh=6aDmeAh5COlILx8Dd1LUha9FUDKFLWIq/c+FJtnL4NE=; b=dNbdG0BchvTS+i8FOu8DhqdwC4A/yUCOYJsy3hxbRNQj4y1af7GCryULMm9NZH933u IqJiH5VXzGUDLbcDrRwvei3AM+Znb8FOFnwkeHbwVG5UrWKLQK2ZDvpI6zS82Jxvil5H mgBt7CHAsDQRbNbLci9o0YosGHTtjwcxhe7z8HjmuNzHFtSxZ9aYsgI/wcNxshyYYdnR /c2AzLpvSHqYmjtYmu2sPgIwtTP/gn8Ja+iuv5sshCDw6jKqdln3NfrLg935fuaQLIc7 GkQJb2XyD09O9EjRzQC+5IiUGnK96/uDyIdEV7s5j7n+czMzyMMhkFMKngfQL5vVqjQW x1Pw== X-Gm-Message-State: AIVw111uLxGtOs3VJ1Rd2YRGq4eJL7t7KNeZweQ9FxTBUAbQR9jqAAbY CMIR9nz+3cjnHicC X-Received: by 10.98.67.147 with SMTP id l19mr8859570pfi.198.1500677248345; Fri, 21 Jul 2017 15:47:28 -0700 (PDT) Received: from centos.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id q3sm10019886pgf.69.2017.07.21.15.47.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 15:47:27 -0700 (PDT) From: Andy Zhou To: dev@openvswitch.org Date: Fri, 21 Jul 2017 15:46:32 -0700 Message-Id: <1500677193-28512-7-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500677193-28512-1-git-send-email-azhou@ovn.org> References: <1500677193-28512-1-git-send-email-azhou@ovn.org> 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] [clone optmization v2 6/7] xlate: Refactor compose_clone() API 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 Create a new function that hides the details of netlink encoding for the translated clone action. Signed-off-by: Andy Zhou --- ofproto/ofproto-dpif-xlate.c | 76 +++++++++++++++++++------------------------- tests/ofproto-dpif.at | 7 ++++ 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index a03c27e5b860..9b7a6a4f7620 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -5245,35 +5245,39 @@ xlate_sample_action(struct xlate_ctx *ctx, tunnel_out_port, false); } -/* Use datapath 'clone' or sample to enclose the translation of 'oc'. */ +/* For datapath that does not support 'clone' action, but have a suitable + * sample action implementation for clone. The upstream Linux kernel + * version 4.11 or greater, and kernel module from OVS version 2.8 or + * greater version have suitable sample action implementations. */ static void -compose_clone_action(struct xlate_ctx *ctx, const struct ofpact_nest *oc) +compose_clone(struct xlate_ctx *ctx, struct flow *old_base_flow, + const struct ofpact_nest *oc) { - size_t clone_offset = nl_msg_start_nested(ctx->odp_actions, - OVS_ACTION_ATTR_CLONE); - do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); - nl_msg_end_non_empty_nested(ctx->odp_actions, clone_offset); -} - -/* Use datapath 'sample' action to translate clone. */ -static void -compose_clone_action_using_sample(struct xlate_ctx *ctx, - const struct ofpact_nest *oc) -{ - size_t offset = nl_msg_start_nested(ctx->odp_actions, - OVS_ACTION_ATTR_SAMPLE); - - size_t ac_offset = nl_msg_start_nested(ctx->odp_actions, - OVS_SAMPLE_ATTR_ACTIONS); - - do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); + size_t offset, ac_offset; - if (nl_msg_end_non_empty_nested(ctx->odp_actions, ac_offset)) { - nl_msg_cancel_nested(ctx->odp_actions, offset); - } else { - nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, - UINT32_MAX); /* 100% probability. */ - nl_msg_end_nested(ctx->odp_actions, offset); + if (ctx->xbridge->support.clone) { + /* Use clone action as datapath clone. */ + offset = nl_msg_start_nested(ctx->odp_actions, OVS_ACTION_ATTR_CLONE); + do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); + nl_msg_end_non_empty_nested(ctx->odp_actions, offset); + ctx->base_flow = *old_base_flow; + } else if (ctx->xbridge->support.sample_nesting > 3) { + /* Use sample action as datapath clone. */ + offset = nl_msg_start_nested(ctx->odp_actions, + OVS_ACTION_ATTR_SAMPLE); + ac_offset = nl_msg_start_nested(ctx->odp_actions, + OVS_SAMPLE_ATTR_ACTIONS); + do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); + if (nl_msg_end_non_empty_nested(ctx->odp_actions, ac_offset)) { + nl_msg_cancel_nested(ctx->odp_actions, offset); + } else { + nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, + UINT32_MAX); /* 100% probability. */ + nl_msg_end_nested(ctx->odp_actions, offset); + } + ctx->base_flow = *old_base_flow; + } else { /* Use actions. */ + do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); } } @@ -5294,27 +5298,11 @@ xlate_clone(struct xlate_ctx *ctx, const struct ofpact_nest *oc) ofpbuf_use_stub(&ctx->action_set, actset_stub, sizeof actset_stub); ofpbuf_put(&ctx->action_set, old_action_set.data, old_action_set.size); - /* Datapath clone action will make sure the pre clone packets - * are used for actions after clone. Save and restore - * ctx->base_flow to reflect this for the openflow pipeline. */ - if (ctx->xbridge->support.clone) { - struct flow old_base_flow = ctx->base_flow; - compose_clone_action(ctx, oc); - ctx->base_flow = old_base_flow; - } else if (ctx->xbridge->support.sample_nesting > 3) { - /* Avoid generate sample action if datapath - * only allow small number of nesting. Deeper nesting - * can cause the datapath to reject the generated flow. */ - struct flow old_base_flow = ctx->base_flow; - compose_clone_action_using_sample(ctx, oc); - ctx->base_flow = old_base_flow; - } else { - do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); - } + struct flow old_base = ctx->base_flow; + compose_clone(ctx, &old_base, oc); ofpbuf_uninit(&ctx->action_set); ctx->action_set = old_action_set; - ofpbuf_uninit(&ctx->stack); ctx->stack = old_stack; diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 9a08c135b9a5..ceff93014dc2 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -6792,6 +6792,13 @@ AT_CHECK([tail -1 stdout], [0], [dnl Datapath actions: sample(sample=100.0%,actions(set(ipv4(src=10.10.10.2,dst=192.168.4.4)),2)),sample(sample=100.0%,actions(set(eth(src=80:81:81:81:81:81)),set(ipv4(src=10.10.10.2,dst=192.168.5.5)),3)),4 ]) +AT_CHECK([ovs-appctl dpif/set-dp-features br0 sample_nesting 2], [0], [ignore]) +AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.10.10.2,dst=10.10.10.1,proto=1,tos=1,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout]) + +AT_CHECK([tail -1 stdout], [0], [dnl +Datapath actions: set(ipv4(src=10.10.10.2,dst=192.168.4.4)),2,set(eth(src=80:81:81:81:81:81)),set(ipv4(src=10.10.10.2,dst=192.168.5.5)),3,set(eth(src=50:54:00:00:00:09)),set(ipv4(src=10.10.10.2,dst=10.10.10.1)),4 +]) + OVS_VSWITCHD_STOP AT_CLEANUP