From patchwork Fri Feb 17 01:11:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 728971 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 3vPZkX6K5fz9s7q for ; Fri, 17 Feb 2017 12:12:20 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B0AA0BEA; Fri, 17 Feb 2017 01:11:28 +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 CEDAFB76 for ; Fri, 17 Feb 2017 01:11:25 +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 668EAA4 for ; Fri, 17 Feb 2017 01:11:25 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id v184so3360617pgv.1 for ; Thu, 16 Feb 2017 17:11:25 -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:in-reply-to :references; bh=TbtJh8XaM/Hyh66FoDkSdz2y0XKObmfb0XYXmVfVucg=; b=fb4KZvCbbLtYM3lDudySAIbiG+kzQhJ3bXMT8HTaSnWzwUY9N7eZehpGMA0QkFGgjy 0cqjk9ufBl01lGr1rK0NBpHHMj1Wu99+5k6gITvqwrRsV4Q16V98Qmv02oKRYcAGXpLL WbTY8xR0WL1R8FLO0VlIrxie06opYpJUy4B7BbbXJ8hggjHnXZ681gB+aelKD++IuNht yVJdF/QGMOJwCT6YgTJskPU0iZo5BldwMoVddMP1wRsFE9ObDWxG/IsDOTB8Enmb/70A SpLchYwsAkn78uK+LQqJS37NMqGOsQ9S3cU+lVE8yohS1sj7ycU51rmbttsC4W0m/sBt BDOg== X-Gm-Message-State: AMke39mBYcWf57DAuoQFNEz57yq6Pq1h5cb3aV4TMd2/ykviv8GTG8sdsR4QpslBy+P5nQ== X-Received: by 10.84.169.67 with SMTP id g61mr7374583plb.137.1487293884836; Thu, 16 Feb 2017 17:11:24 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id m6sm15631546pfg.126.2017.02.16.17.11.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Feb 2017 17:11:24 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Thu, 16 Feb 2017 17:11:08 -0800 Message-Id: <1487293868-21605-3-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487293868-21605-1-git-send-email-azhou@ovn.org> References: <1487293868-21605-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] [PATCH 3/3] xlate: Translate openflow clone into odp sample action. 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 datapath does not support the 'clone' action directly, generate sample action (with 100% probability) instead. Specifically, currently, there is no plan to support the 'clone' action on the Linux kernel datapath directly, so the sample action will be used to translate the openflow clone action for this datapath. Signed-off-by: Andy Zhou Acked-by: Jarno Rajahalme --- ofproto/ofproto-dpif-xlate.c | 38 ++++++++++++++++++++++++++++---------- tests/ofproto-dpif.at | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index c4ca5d2..1a5fdf8 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -4659,18 +4659,36 @@ xlate_sample_action(struct xlate_ctx *ctx, tunnel_out_port, false); } -/* Only called if the datapath supports 'OVS_ACTION_ATTR_CLONE'. - * - * Translates 'oc' within OVS_ACTION_ATTR_CLONE. */ +/* Use datapath 'clone' or sample to enclose the translation of 'oc'. */ static void compose_clone_action(struct xlate_ctx *ctx, 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); - nl_msg_end_non_empty_nested(ctx->odp_actions, clone_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); + } } static void @@ -4690,16 +4708,16 @@ 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. */ + struct flow old_base_flow = ctx->base_flow; if (ctx->xbridge->support.clone) { - /* 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. */ - struct flow old_base_flow = ctx->base_flow; compose_clone_action(ctx, oc); - ctx->base_flow = old_base_flow; } else { - do_xlate_actions(oc->actions, ofpact_nest_get_action_len(oc), ctx); + compose_clone_action_using_sample(ctx, oc); } + ctx->base_flow = old_base_flow; ofpbuf_uninit(&ctx->action_set); ctx->action_set = old_action_set; diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index e861d9f..f1415e4 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -6457,7 +6457,7 @@ AT_CHECK([ovs-appctl dpif/disable-dp-clone br0], [0], 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 +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 ]) OVS_VSWITCHD_STOP