From patchwork Fri Apr 14 19:46:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 750950 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 3w4StN3B54z9s7F for ; Sat, 15 Apr 2017 05:50:04 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7AFE1C5D; Fri, 14 Apr 2017 19:46:59 +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 10DA8C40 for ; Fri, 14 Apr 2017 19:46:56 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9184C168 for ; Fri, 14 Apr 2017 19:46:55 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id i5so16354848pfc.3 for ; Fri, 14 Apr 2017 12:46:55 -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=qL5aKTju3s5dlmk5lYkA+6UjOMjSgs23gX77QIRKUvw=; b=EFjSsuzf/ZjxR7Z73XpOb2gyyreyRjDwY2JVKYVcidMVdFZRepmXeCcXpxVHEjf1LY 8teaD+yqb+O04NF91iBwKeA80JC+MeyZLgjTq7PYA3FH98oH71SYR14j37nCoBo96et7 9kCxexkxgIxlzECSmVfK5uT27VwjQghgCq6eEOqqbLpO0unVt9ndF+w9HFPQZN+x0K/j trp0y46CB7MbTGI/gwzCtBA/3n56u+KuZLsN3CP/+zlM6DGlnaPZyrl1vTAT424lWnVk sbuiVRquFp6Bm5YCtyJfXHYgpx/4U011iIdtG7m8WITJ9HzpBrI2nK0mo3r2gMtZd47P 4lQw== X-Gm-Message-State: AN3rC/6l+hU7M8YwTpLga2EUiRbYo6GS8vUIiw4zHl8TfiD7R6sJAJNv xVNGW0zpqRIVlA== X-Received: by 10.98.78.195 with SMTP id c186mr2639484pfb.155.1492199215105; Fri, 14 Apr 2017 12:46:55 -0700 (PDT) Received: from centos.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id p68sm4661584pfp.104.2017.04.14.12.46.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Apr 2017 12:46:54 -0700 (PDT) From: Andy Zhou To: dev@openvswitch.org Date: Fri, 14 Apr 2017 12:46:22 -0700 Message-Id: <1492199182-4479-6-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1492199182-4479-1-git-send-email-azhou@ovn.org> References: <1492199182-4479-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] [action upcall meters 5/5] ofproto: Meter slowpath action when action upcall meters are configured 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 If a slow path action is a controller action, meter it when the controller meter is configured. For other kinds of slow path actions, meter it when the slowpath meter is configured. Note, this patch only considers the meters configuration of the packet's input bridge, which may not be the same bridge that the action is generated. Signed-off-by: Andy Zhou --- ofproto/ofproto-dpif-upcall.c | 34 +++++++++++++++++++++++++++++++--- ofproto/ofproto-dpif-xlate.c | 12 ++++++------ tests/ofproto-dpif.at | 31 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 3b28f9a22939..37f345b235b1 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -1018,7 +1018,8 @@ classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata) static void compose_slow_path(struct udpif *udpif, struct xlate_out *xout, const struct flow *flow, odp_port_t odp_in_port, - struct ofpbuf *buf) + struct ofpbuf *buf, uint32_t slowpath_meter_id, + uint32_t controller_meter_id) { union user_action_cookie cookie; odp_port_t port; @@ -1032,8 +1033,28 @@ compose_slow_path(struct udpif *udpif, struct xlate_out *xout, ? ODPP_NONE : odp_in_port; pid = dpif_port_get_pid(udpif->dpif, port, flow_hash_5tuple(flow, 0)); + + size_t offset; + size_t ac_offset; + uint32_t meter_id = xout->slow & SLOW_CONTROLLER ? controller_meter_id + : slowpath_meter_id; + + if (meter_id != UINT32_MAX) { + /* If slowpath meter is configured, generate clone(meter, userspace) + * action. */ + offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SAMPLE); + nl_msg_put_u32(buf, OVS_SAMPLE_ATTR_PROBABILITY, UINT32_MAX); + ac_offset = nl_msg_start_nested(buf, OVS_SAMPLE_ATTR_ACTIONS); + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id); + } + odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, ODPP_NONE, false, buf); + + if (meter_id != UINT32_MAX) { + nl_msg_end_nested(buf, ac_offset); + nl_msg_end_nested(buf, offset); + } } /* If there is no error, the upcall must be destroyed with upcall_uninit() @@ -1136,10 +1157,12 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall, ofpbuf_use_const(&upcall->put_actions, odp_actions->data, odp_actions->size); } else { + uint32_t smid= upcall->ofproto->up.slowpath_meter_id; + uint32_t cmid = upcall->ofproto->up.controller_meter_id; /* upcall->put_actions already initialized by upcall_receive(). */ compose_slow_path(udpif, &upcall->xout, upcall->flow, upcall->flow->in_port.odp_port, - &upcall->put_actions); + &upcall->put_actions, smid, cmid); } /* This function is also called for slow-pathed flows. As we are only @@ -1956,9 +1979,14 @@ revalidate_ukey__(struct udpif *udpif, const struct udpif_key *ukey, } if (xoutp->slow) { + struct ofproto_dpif *ofproto; + ofproto = xlate_lookup_ofproto(udpif->backer, &ctx.flow, NULL); + uint32_t smid= ofproto->up.slowpath_meter_id; + uint32_t cmid= ofproto->up.controller_meter_id; + ofpbuf_clear(odp_actions); compose_slow_path(udpif, xoutp, &ctx.flow, ctx.flow.in_port.odp_port, - odp_actions); + odp_actions, smid, cmid); } if (odp_flow_key_to_mask(ukey->mask, ukey->mask_len, &dp_mask, &ctx.flow) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 52e0d3f1b0bb..416012ab6930 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2849,8 +2849,13 @@ compose_sample_action(struct xlate_ctx *ctx, return 0; } + /* If the slow path meter is configured by the controller, + * Insert a meter action before the user space action. */ + struct ofproto *ofproto = &ctx->xin->ofproto->up; + uint32_t meter_id = ofproto->slowpath_meter_id; + /* No need to generate sample action for 100% sampling rate. */ - bool is_sample = probability < UINT32_MAX; + bool is_sample = probability < UINT32_MAX || meter_id != UINT32_MAX; size_t sample_offset, actions_offset; if (is_sample) { sample_offset = nl_msg_start_nested(ctx->odp_actions, @@ -2861,11 +2866,6 @@ compose_sample_action(struct xlate_ctx *ctx, OVS_SAMPLE_ATTR_ACTIONS); } - /* If the slow path meter is configured by the controller, - * Insert a meter action before the user space action. */ - struct ofproto *ofproto = &ctx->xin->ofproto->up; - uint32_t meter_id = ofproto->slowpath_meter_id; - if (meter_id != UINT32_MAX) { nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_METER, meter_id); } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 3c3037b16548..8b097adec940 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -1658,6 +1658,37 @@ NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x1234 ]) +AT_CHECK([ovs-appctl revalidator/purge]) +AT_CHECK([ovs-ofctl monitor br0 65534 invalid_ttl -P nxt_packet_in --detach --no-chdir --pidfile 2> ofctl_monitor.log]) + +dnl Add a controller meter. +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=controller pktps stats bands=type=drop rate=1']) + +dnl Advance time by 1 second. +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore]) + +for i in `seq 1 8`; do + AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x4321)']) +done + +AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/.*\(packets:\)/\1/' | sed 's/used:[[0-9]].[[0-9]]*s/used:0.001s/'], [0], [dnl +flow-dump from non-dpdk interfaces: +packets:7, bytes:98, used:0.001s, actions:sample(sample=100.0%,actions(meter(0),userspace(pid=0,slow_path(controller)))) +]) + +AT_CHECK([ovs-appctl time/warp 1], [0], [ignore]) +OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit]) + +dnl Out of 8 packets we sent, one executes the controller action via +dnl miss upcall. Another one got passed the rate limiter. +dnl The rest of packets are blocked by the rate limiter. +AT_CHECK([cat ofctl_monitor.log], [0], [dnl +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered) +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321 +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered) +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321 +]) + OVS_VSWITCHD_STOP AT_CLEANUP