From patchwork Thu Apr 29 17:04:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1471790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GlCafHHK; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FWMLM4Zytz9t0G for ; Fri, 30 Apr 2021 03:04:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 7AE0A4199B; Thu, 29 Apr 2021 17:04:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iWDsF7vQ3uQW; Thu, 29 Apr 2021 17:04:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id 972844199D; Thu, 29 Apr 2021 17:04:39 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6880EC000E; Thu, 29 Apr 2021 17:04:39 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4A992C0001 for ; Thu, 29 Apr 2021 17:04:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id EE06B4199B for ; Thu, 29 Apr 2021 17:04:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9CSoy-qIpAzB for ; Thu, 29 Apr 2021 17:04:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id B9B1841994 for ; Thu, 29 Apr 2021 17:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619715874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ln8nJITa0zj+ZxwRc9Gih5W10I7CwnfOl4cKgOM8Jak=; b=GlCafHHKsIlNhJNgjiGjBuX3vglI+L40Hj6TW7Wlq+scRSUVJfkCvWe5PjC1lIUGTzJsRG PQu/+ZAvmWa72S4botJR6uun/xSR1WmNZUNIcbfpXiF91YJtTP4D0i+aV3k8rzv2ZO/K6b vRFb59QOmgmDtGNRWM25fcmwek2s5w4= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-E3gfK3kmP62CGvCRo-O8HA-1; Thu, 29 Apr 2021 13:04:32 -0400 X-MC-Unique: E3gfK3kmP62CGvCRo-O8HA-1 Received: by mail-ed1-f72.google.com with SMTP id w14-20020aa7da4e0000b02903834aeed684so27314608eds.13 for ; Thu, 29 Apr 2021 10:04:32 -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:mime-version:content-transfer-encoding; bh=Ln8nJITa0zj+ZxwRc9Gih5W10I7CwnfOl4cKgOM8Jak=; b=PE5TEI1wL/I5lK6lLOqrlOBbvQM3YPT8PMiBPZDUQrCmlmQpj/uVk4V1MxH74QoHrx xk5HckRVuQdPwBg7dlMeGLgYLLLT8xGG43A/2Q852HziMbeo4Qk1CMtrJ4cdTw9eQxHj 38zwHaN8Z3Oy64L7jMMSrC+NgiVSRrGzwypy30aePqW28eJh1uaG+MApMztISmaIMdVV sZucJrPe6/Nr8PoLE72HQwRNomW3DRPMQ5w/nsfNCQ/XJTDI5RLeqbLI5etz4dzlbT6R 57rzez48XJdZHzNdSy9IJXKXSfcprqgkf1snCaMQqD9114ZFMDHxQWk7Nys23NryG041 rfhg== X-Gm-Message-State: AOAM531KrHmAIxNwLnT7VueRCnnP2KHtK359bM0w09Bs5N1ays1KcedQ CgoY02vK/2qRG4audNS5fFb5Csj9+WoMJg770F9ov9yZVB1RNCX2GM4gQ92VkPogvq2kS+1jakV SFCz/oBI2P7PzMwt2M7XbNoQb3krVtYlYUoW/8evH6BoOvydhKXs59BHJzSsqHPtKJ/3U9v242l U= X-Received: by 2002:aa7:cb43:: with SMTP id w3mr638052edt.287.1619715871129; Thu, 29 Apr 2021 10:04:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGz/RNIvo/sUJWQbAcMQStAvsBU9UzDSLIz39PQAq1ChXhQPiWwcyxtuwIpZkvdPjQglWlXw== X-Received: by 2002:aa7:cb43:: with SMTP id w3mr638017edt.287.1619715870888; Thu, 29 Apr 2021 10:04:30 -0700 (PDT) Received: from lore-desk.redhat.com ([151.66.28.185]) by smtp.gmail.com with ESMTPSA id re26sm299250ejb.3.2021.04.29.10.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Apr 2021 10:04:30 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Thu, 29 Apr 2021 19:04:17 +0200 Message-Id: <075a2b9054edd352dd17ec34b45c32a643b7fb20.1619715319.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com Subject: [ovs-dev] [PATCH ovn 4/5] ovn-northd: Extend metering to Controller-Events X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Dumitru Ceara Co-authored-by: Lorenzo Bianconi Signed-off-by: Lorenzo Bianconi Signed-off-by: Dumitru Ceara --- include/ovn/actions.h | 1 - lib/actions.c | 50 ++++++++----------------------------------- northd/ovn-northd.c | 18 ++++++++-------- tests/ovn.at | 4 ++-- 4 files changed, 20 insertions(+), 53 deletions(-) diff --git a/include/ovn/actions.h b/include/ovn/actions.h index ab03df12c..b2f2f57c6 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -393,7 +393,6 @@ struct ovnact_controller_event { int event_type; /* controller event type */ struct ovnact_gen_option *options; size_t n_options; - char *meter; }; /* OVNACT_BIND_VPORT. */ diff --git a/lib/actions.c b/lib/actions.c index 155b4a45a..f0291afef 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -1613,9 +1613,6 @@ 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, ", "); @@ -1790,24 +1787,11 @@ encode_event_empty_lb_backends_opts(struct ofpbuf *ofpacts, static void encode_TRIGGER_EVENT(const struct ovnact_controller_event *event, - const struct ovnact_encode_params *ep OVS_UNUSED, + const struct ovnact_encode_params *ep, 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, - meter_id, ofpacts); + size_t oc_offset = encode_start_controller_op(ACTION_OPCODE_EVENT, false, + ep->ctrl_meter_id, ofpacts); ovs_be32 ofs = htonl(event->event_type); ofpbuf_put(ofpacts, &ofs, sizeof ofs); @@ -2341,27 +2325,12 @@ parse_trigger_event(struct action_context *ctx, sizeof *event->options); } - 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)); - } + 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; } @@ -2382,7 +2351,6 @@ static void ovnact_controller_event_free(struct ovnact_controller_event *event) { free_gen_options(event->options, event->n_options); - free(event->meter); } static void diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 93b431f4c..a3eb8f646 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -5083,11 +5083,7 @@ build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows, bool ipv4 = IN6_IS_ADDR_V4MAPPED(&lb_vip->vip); struct ds match = DS_EMPTY_INITIALIZER; - char *meter = "", *action; - - if (meter_groups && shash_find(meter_groups, "event-elb")) { - meter = "event-elb"; - } + char *action; ds_put_format(&match, "ip%s.dst == %s && %s", ipv4 ? "4": "6", lb_vip->vip_str, lb->protocol); @@ -5101,14 +5097,18 @@ build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows, } action = xasprintf("trigger_event(event = \"%s\", " - "meter = \"%s\", vip = \"%s\", " + "vip = \"%s\", " "protocol = \"%s\", " "load_balancer = \"" UUID_FMT "\");", event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS), - meter, vip, lb->protocol, + vip, lb->protocol, UUID_ARGS(&lb->header_.uuid)); - ovn_lflow_add_with_hint(lflows, od, pl, 130, ds_cstr(&match), action, - &lb->header_); + + const struct nbrec_copp *copp = (od->nbr ? od->nbr->copp : od->nbs->copp); + ovn_lflow_add_with_hint__(lflows, od, pl, 130, ds_cstr(&match), action, + copp_meter_get(COPP_EVENT_ELB, copp, + meter_groups), + &lb->header_); ds_destroy(&match); if (lb_vip->vip_port) { free(vip); diff --git a/tests/ovn.at b/tests/ovn.at index ae1b472e4..aff520f3a 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -1661,8 +1661,7 @@ trigger_event(event = "empty_lb_backends", vip = "10.0.0.1:80", protocol = "tcp" encodes as controller(userdata=00.00.00.0f.00.00.00.00.00.00.00.00.00.01.00.0b.31.30.2e.30.2e.30.2e.31.3a.38.30.00.02.00.03.74.63.70.00.03.00.24.31.32.33.34.35.36.37.38.2d.61.62.63.64.2d.39.38.37.36.2d.66.65.64.63.2d.31.31.31.31.39.66.38.65.37.64.36.63) trigger_event(event = "empty_lb_backends", meter="event-elb" vip = "10.0.0.1:80", protocol = "tcp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c"); - formats as trigger_event(event = "empty_lb_backends", meter = "event-elb", vip = "10.0.0.1:80", protocol = "tcp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c"); - encodes as controller(userdata=00.00.00.0f.00.00.00.00.00.00.00.00.00.01.00.0b.31.30.2e.30.2e.30.2e.31.3a.38.30.00.02.00.03.74.63.70.00.03.00.24.31.32.33.34.35.36.37.38.2d.61.62.63.64.2d.39.38.37.36.2d.66.65.64.63.2d.31.31.31.31.39.66.38.65.37.64.36.63,meter_id=5) + Syntax error at `meter' expecting empty_lb_backends option name. # Testing invalid vip results in extra error messages from socket-util.c trigger_event(event = "empty_lb_backends", vip = "10.0.0.1:80", protocol = "aarp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c"); @@ -17629,6 +17628,7 @@ ovn-nbctl ls-lb-add sw0 lb2 uuid_lb2=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb2) ovn-nbctl --wait=hv meter-add event-elb drop 100 pktps 10 +ovn-nbctl --wait=hv ls-copp-add sw0 event-elb event-elb OVN_POPULATE_ARP wait_for_ports_up