From patchwork Thu Aug 1 12:16:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1140449 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 45zqKv01Rtz9sDQ for ; Thu, 1 Aug 2019 22:26:58 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6393DB0C2; Thu, 1 Aug 2019 12:26:19 +0000 (UTC) X-Original-To: ovs-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 71EEDB0B9 for ; Thu, 1 Aug 2019 12:16:18 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C7AFE821 for ; Thu, 1 Aug 2019 12:16:17 +0000 (UTC) Received: by mail-wr1-f45.google.com with SMTP id c2so70124526wrm.8 for ; Thu, 01 Aug 2019 05:16:17 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3HR1VyO6uHQi3bQFVUBgYNqJjbB5vH20lhzVmgdaMwU=; b=XT7GnIHIBLY5GQcTCEStssNsvfRklAZ9wP6xo7cFqixSL3txjmmMKG4320DicTr389 dcYPJl4/P2KXohrRV5R2CnXrgjfebg4KJCza7b/T4511pU3q8UcXhNK06JAOq9sCfTbL lzdWVca8fY3DUvzuFIuKNz8TNT4NxgFHAgAzjPPXFayGVmZT6upjVUP2hmJp44e+mtob rel8789swxB+UFUiYxA1ZUb0bKlDZNzfjGpKjhGFbAyH1U4jFdPw46u2/g+lR3oUPt28 XRzkAsDVXnPs8OKxM7gvn1u1WE36U8hIDCU3k32FqKXTsfx6uYTlHHmQ/k1sC85QCpKq OD3Q== X-Gm-Message-State: APjAAAVeqf3ZEJ0jJoAz83nP1S8kz34vSavzBjzg4omXpDXFk2T0JrRB Xy2QA2uAmTSkQW+2eTKvYc9IGUZT+ns= X-Google-Smtp-Source: APXvYqw/Mk20X8FUe3M+aVIov1yhxtb/KXe7K8DuHSqYYTX8SGLTWGg0aIRn9mF6LfmABdfRcLmafg== X-Received: by 2002:a5d:69c4:: with SMTP id s4mr110627762wrw.163.1564661776073; Thu, 01 Aug 2019 05:16:16 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id j33sm153579764wre.42.2019.08.01.05.16.15 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 05:16:15 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Thu, 1 Aug 2019 14:16:05 +0200 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 ovn 1/2] add meter support to trigger_event 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Introduce meter support to trigger_event action in order to not overload pinctrl thread under heavy load Signed-off-by: Lorenzo Bianconi --- include/ovn/actions.h | 1 + lib/actions.c | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/include/ovn/actions.h b/include/ovn/actions.h index 63d3907d8..1f2ac2eb2 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -326,6 +326,7 @@ struct ovnact_controller_event { int event_type; /* controller event type */ struct ovnact_gen_option *options; size_t n_options; + char *meter; }; /* Internal use by the helpers below. */ diff --git a/lib/actions.c b/lib/actions.c index 4eacc44ed..2e321d82e 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -1273,6 +1273,9 @@ format_TRIGGER_EVENT(const struct ovnact_controller_event *event, { ds_put_format(s, "trigger_event(event = \"%s\"", event_to_string(event->event_type)); + if (event->meter) { + ds_put_format(s, ", meter = \"%s\"", event->meter); + } for (const struct ovnact_gen_option *o = event->options; o < &event->options[event->n_options]; o++) { ds_put_cstr(s, ", "); @@ -1420,10 +1423,21 @@ encode_TRIGGER_EVENT(const struct ovnact_controller_event *event, const struct ovnact_encode_params *ep OVS_UNUSED, struct ofpbuf *ofpacts) { + uint32_t meter_id = NX_CTLR_NO_METER; size_t oc_offset; + if (event->meter) { + meter_id = ovn_extend_table_assign_id(ep->meter_table, event->meter, + ep->lflow_uuid); + if (meter_id == EXT_TABLE_ID_INVALID) { + VLOG_WARN("Unable to assign id for trigger meter: %s", + event->meter); + return; + } + } + oc_offset = encode_start_controller_op(ACTION_OPCODE_EVENT, false, - NX_CTLR_NO_METER, ofpacts); + meter_id, ofpacts); ovs_be32 ofs = htonl(event->event_type); ofpbuf_put(ofpacts, &ofs, sizeof ofs); @@ -1738,11 +1752,27 @@ parse_trigger_event(struct action_context *ctx, sizeof *event->options); } - struct ovnact_gen_option *o = &event->options[event->n_options++]; - memset(o, 0, sizeof *o); - parse_gen_opt(ctx, o, - &ctx->pp->controller_event_opts->event_opts[event_type], - event_to_string(event_type)); + if (lexer_match_id(ctx->lexer, "meter")) { + if (!lexer_force_match(ctx->lexer, LEX_T_EQUALS)) { + return; + } + /* If multiple meters are given, use the most recent. */ + if (ctx->lexer->token.type == LEX_T_STRING && + strlen(ctx->lexer->token.s)) { + free(event->meter); + event->meter = xstrdup(ctx->lexer->token.s); + } else if (ctx->lexer->token.type != LEX_T_STRING) { + lexer_syntax_error(ctx->lexer, "expecting string"); + return; + } + lexer_get(ctx->lexer); + } else { + struct ovnact_gen_option *o = &event->options[event->n_options++]; + memset(o, 0, sizeof *o); + parse_gen_opt(ctx, o, + &ctx->pp->controller_event_opts->event_opts[event_type], + event_to_string(event_type)); + } if (ctx->lexer->error) { return; } From patchwork Thu Aug 1 12:16:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1140452 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 45zqLc67l3z9s00 for ; Thu, 1 Aug 2019 22:27:36 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3036FB0CE; Thu, 1 Aug 2019 12:26:20 +0000 (UTC) X-Original-To: ovs-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 689C9B0B9 for ; Thu, 1 Aug 2019 12:16:20 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8D49382B for ; Thu, 1 Aug 2019 12:16:19 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id f17so62961268wme.2 for ; Thu, 01 Aug 2019 05:16:19 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nhs7dOwqnwO2SgLPcbXwDEJh8x+/dXE1+o2tjdLOpwU=; b=joRpNDwpCCUABY2w82zLyyOV4NAzbIaQHlaKh7DzqM7sMm8u2x27wPTmaL4ccwtVcQ g4ZLYRDDl7K2rFhgmnu4sjAc8vyiJF2vyHbG3Z9u7hlEymccnxVBw0DawjELSogDh0jP tq2+R/3wDybXUeg84zMlX9oyKDJpj+syF5UtSyUxIrc91JNzbZFwp0iB0gGlGEznTQxb 1g7efnbq8vqqV8tym50QzfnM/s5TUDrgE1yq00g9eRmtcelBLxKn01GBuawBtduEoC4Z YHtlc+IGQrxCNC4IkxE2t1fboeYGhI3GQVaDngGWWUsrSfppirSN0nakNUdSkwmrUoRx RvCA== X-Gm-Message-State: APjAAAVqceNRy9Q8r4V0+u9eD2MI6g4PdItwhjFE/hO6maWbUl1XtDH1 VqkD5NMa5htjxeaz7WJiOKMUv3WfNXM= X-Google-Smtp-Source: APXvYqzXhe282LBfzge+qo79lGcbToDQdOXM8n90UijPAKfAEx6fXcFel9or4eciQJpCRbh0G8d8iQ== X-Received: by 2002:a1c:d10c:: with SMTP id i12mr116423488wmg.152.1564661777759; Thu, 01 Aug 2019 05:16:17 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id j33sm153579764wre.42.2019.08.01.05.16.16 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 05:16:17 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Thu, 1 Aug 2019 14:16:06 +0200 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 ovn 2/2] northd: add rate limiting support for SB controller events 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Introduce the capability to associate a meter to each controller event type in order to not overload the pinctrl thread under heavy load. Each event type relies on a meter with a defined name: - empty_lb_backends: event-elb Signed-off-by: Lorenzo Bianconi --- northd/ovn-northd.c | 44 +++++++++++++++++++++++++++++++++++--------- ovn-nb.xml | 8 ++++++++ tests/ovn.at | 1 + 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index dabd422b5..e9c561265 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -3879,7 +3879,8 @@ ls_has_dns_records(const struct nbrec_logical_switch *nbs) } static void -build_pre_lb(struct ovn_datapath *od, struct hmap *lflows) +build_pre_lb(struct ovn_datapath *od, struct hmap *lflows, + struct shash *meter_groups) { /* Do not send ND packets to conntrack */ ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 110, @@ -3917,7 +3918,11 @@ build_pre_lb(struct ovn_datapath *od, struct hmap *lflows) if (controller_event_en && !node->value[0]) { struct ds match = DS_EMPTY_INITIALIZER; - char *action; + char *meter = "", *action; + + if (shash_find(meter_groups, "event-elb")) { + meter = "event-elb"; + } if (addr_family == AF_INET) { ds_put_format(&match, "ip4.dst == %s && %s", @@ -3931,10 +3936,11 @@ build_pre_lb(struct ovn_datapath *od, struct hmap *lflows) port); } action = xasprintf("trigger_event(event = \"%s\", " - "vip = \"%s\", protocol = \"%s\", " + "meter = \"%s\", vip = \"%s\", " + "protocol = \"%s\", " "load_balancer = \"" UUID_FMT "\");", event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS), - node->key, lb->protocol, + meter, node->key, lb->protocol, UUID_ARGS(&lb->header_.uuid)); ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 120, ds_cstr(&match), action); @@ -4761,7 +4767,8 @@ build_lrouter_groups(struct hmap *ports, struct ovs_list *lr_list) static void build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, struct hmap *port_groups, struct hmap *lflows, - struct hmap *mcgroups, struct hmap *igmp_groups) + struct hmap *mcgroups, struct hmap *igmp_groups, + struct shash *meter_groups) { /* This flow table structure is documented in ovn-northd(8), so please * update ovn-northd.8.xml if you change anything. */ @@ -4778,7 +4785,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, } build_pre_acls(od, lflows); - build_pre_lb(od, lflows); + build_pre_lb(od, lflows, meter_groups); build_pre_stateful(od, lflows); build_acls(od, lflows, port_groups); build_qos(od, lflows); @@ -7886,12 +7893,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, static void build_lflows(struct northd_context *ctx, struct hmap *datapaths, struct hmap *ports, struct hmap *port_groups, - struct hmap *mcgroups, struct hmap *igmp_groups) + struct hmap *mcgroups, struct hmap *igmp_groups, + struct shash *meter_groups) { struct hmap lflows = HMAP_INITIALIZER(&lflows); build_lswitch_flows(datapaths, ports, port_groups, &lflows, mcgroups, - igmp_groups); + igmp_groups, meter_groups); build_lrouter_flows(datapaths, ports, &lflows); /* Push changes to the Logical_Flow table to database. */ @@ -8504,6 +8512,16 @@ build_mcast_groups(struct northd_context *ctx, } } +static void +build_meter_groups(struct northd_context *ctx, + struct shash *meter_groups) +{ + const struct nbrec_meter *nb_meter; + NBREC_METER_FOR_EACH (nb_meter, ctx->ovnnb_idl) { + shash_add(meter_groups, nb_meter->name, nb_meter); + } +} + static void ovnnb_db_run(struct northd_context *ctx, struct ovsdb_idl_index *sbrec_chassis_by_name, @@ -8517,6 +8535,7 @@ ovnnb_db_run(struct northd_context *ctx, struct hmap port_groups; struct hmap mcast_groups; struct hmap igmp_groups; + struct shash meter_groups = SHASH_INITIALIZER(&meter_groups); build_datapaths(ctx, datapaths, lr_list); build_ports(ctx, sbrec_chassis_by_name, datapaths, ports); @@ -8525,8 +8544,9 @@ ovnnb_db_run(struct northd_context *ctx, build_lrouter_groups(ports, lr_list); build_ip_mcast(ctx, datapaths); build_mcast_groups(ctx, datapaths, ports, &mcast_groups, &igmp_groups); + build_meter_groups(ctx, &meter_groups); build_lflows(ctx, datapaths, ports, &port_groups, &mcast_groups, - &igmp_groups); + &igmp_groups, &meter_groups); sync_address_sets(ctx); sync_port_groups(ctx); @@ -8547,6 +8567,12 @@ ovnnb_db_run(struct northd_context *ctx, hmap_destroy(&mcast_groups); hmap_destroy(&port_groups); + struct shash_node *node, *next; + SHASH_FOR_EACH_SAFE (node, next, &meter_groups) { + shash_delete(&meter_groups, node); + } + shash_destroy(&meter_groups); + /* Sync ipsec configuration. * Copy nb_cfg from northbound to southbound database. * Also set up to update sb_cfg once our southbound transaction commits. */ diff --git a/ovn-nb.xml b/ovn-nb.xml index 57b6edbf8..53f267ab6 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -117,6 +117,14 @@ table. The intention is for a CMS to see the events and take some sort of action. Please see the table in SBDB. + It is possible to associate a meter to each controller event type + in order to not overload the pinctrl thread under heavy load. + Each event type relies on a meter with a defined name: + +
    +
  • empty_lb_backends: event-elb
  • +
+ diff --git a/tests/ovn.at b/tests/ovn.at index 23159c876..8ff8cff0d 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -14399,6 +14399,7 @@ ovn-nbctl --wait=hv set NB_Global . options:controller_event=true ovn-nbctl lb-add lb0 192.168.1.100:80 "" ovn-nbctl ls-lb-add sw0 lb0 uuid_lb=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb0) +ovn-nbctl --wait=hv meter-add event-elb drop 100 pktps 10 OVN_POPULATE_ARP ovn-nbctl --timeout=3 --wait=hv sync