From patchwork Fri Sep 17 10:12:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1529315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org 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=JMQivPa4; dkim-atps=neutral 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=) 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 4H9qWt281yz9sR4 for ; Fri, 17 Sep 2021 20:12:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E9A2740496; Fri, 17 Sep 2021 10:12:36 +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 o0xwBHI9Usjh; Fri, 17 Sep 2021 10:12:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 91F8F400AF; Fri, 17 Sep 2021 10:12:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 63899C000F; Fri, 17 Sep 2021 10:12:34 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1199DC000D for ; Fri, 17 Sep 2021 10:12:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 07A3483F82 for ; Fri, 17 Sep 2021 10:12:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id whOYWGhN1cUj for ; Fri, 17 Sep 2021 10:12:32 +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 smtp1.osuosl.org (Postfix) with ESMTPS id BD28B83E8F for ; Fri, 17 Sep 2021 10:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631873551; 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; bh=Sk4LU5aVdiZC1Uwh0GlnKCmtlZ6SI/QZzzwpEcVbpos=; b=JMQivPa43IcOQrO7dVcENnsrg1kQW9NUOPe8p2w15XfGWH+sVRZVZ5WYx4MEmozZk/NLhT 0oTvthk2LMuVVVPR/U2nmija//6MIeFIofJltdIv4qZ8oTpnZpg9WYVDORAvMbONStfcM6 YCmYvoy55WIokLEN5TNCQ5g1/GsU2z4= 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-255-p4s-t6PLMv-yFtkNGBiMLg-1; Fri, 17 Sep 2021 06:12:29 -0400 X-MC-Unique: p4s-t6PLMv-yFtkNGBiMLg-1 Received: by mail-ed1-f72.google.com with SMTP id h24-20020a50cdd8000000b003d8005fe2f8so4447093edj.6 for ; Fri, 17 Sep 2021 03:12:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Sk4LU5aVdiZC1Uwh0GlnKCmtlZ6SI/QZzzwpEcVbpos=; b=Nh3++TkV4XD9Fjh45dgJ0q0ZFqSqJf6sRGmOxEVsu8PRMLhyjf4jAUkDOOYhLfTrvi Hq85FWFrmoep+huEjuVLLL8lSQYT7JnChLRzgvQmjcVJjfUU7fznrDlq53ZYqIX6IN7g g4/oMsiGGW7sP+VfJWLuofgKmOZvkdODzltyyyVCCg4gkgOEYLB9DYOGtjcuLsb5Qd0t Q77bWC83ejEXV1QOC+Ih3sQ+oEdcHiHcHUt0bZXCOi8zuVEXN/kSToaaYjtv96/HP38P Wt8p5r7WZtSC4A5HU6wnQ18isYkS4YHyeSczyy3lxXWKA4MIY5QEgTfbA3NojY2pxffL yVEA== X-Gm-Message-State: AOAM532D0Wu+H3ibbosgFeaCgV2bnbYBV3JWPakF75NWTTxwSwHSkCuD x46zQx7DDQdEn83XydiSmsH0tCAFCtbt7qw2WBg0cDa0AE5U32vMC/EOOlc3amKoEkNM3DAdM3b kLgRDKqoboZtI3AVmlQATJZ5PozwSM751h/pg6BEyUQ1/ORj/M0w34Bl5UpuIhnByTj4VdNVvq+ ol75R3 X-Received: by 2002:a50:9d85:: with SMTP id w5mr6691520ede.268.1631873548315; Fri, 17 Sep 2021 03:12:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd4pykroR5YQE7lEj4ENyeaaS6rpx/Kx/8e1WouKLCnei5qjXi5BXtrPieoT6I3Y4EfUXUAQ== X-Received: by 2002:a50:9d85:: with SMTP id w5mr6691490ede.268.1631873548039; Fri, 17 Sep 2021 03:12:28 -0700 (PDT) Received: from lore-desk.redhat.com (net-130-25-199-50.cust.vodafonedsl.it. [130.25.199.50]) by smtp.gmail.com with ESMTPSA id s18sm2124681ejc.52.2021.09.17.03.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 03:12:27 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Fri, 17 Sep 2021 12:12:22 +0200 Message-Id: <93952575174f6b204e70766ac1124e0defdefa80.1631873201.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.31.1 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 v5 ovn] controller: add datapath meter capability check 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" Dump datapath meter capabilities before configuring meters in ovn-controller Signed-off-by: Lorenzo Bianconi Acked-by: Mark D. Gray --- Changes since v4: - move rconn setup in ovs_feature_support_update and rename it in ovs_feature_support_run - drop ovs_feature_support_init() - rename ovs_feature_support_deinit in ovs_feature_support_destroy Changes since v3: - add missing rconn_run_wait() and rconn_recv_wait() at the end of swconn for loop - cosmetics Changes since v2: - move meter capability logic in lib/features.c Changes since v1: - move rconn in ovn-controller to avoid concurrency issues --- controller/ovn-controller.c | 7 +-- include/ovn/features.h | 6 ++- lib/actions.c | 3 ++ lib/automake.mk | 1 + lib/features.c | 95 ++++++++++++++++++++++++++++++++++++- lib/test-ovn-features.c | 6 +-- tests/ovn.at | 4 +- 7 files changed, 112 insertions(+), 10 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 0031a1035..3347396f8 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -3569,9 +3569,9 @@ main(int argc, char *argv[]) * 'br_int_dp' is valid only if an OVS transaction is possible. */ if (ovs_idl_txn - && ovs_feature_support_update(br_int_dp - ? &br_int_dp->capabilities - : NULL)) { + && ovs_feature_support_run(br_int_dp ? + &br_int_dp->capabilities : NULL, + br_int ? br_int->name : NULL)) { VLOG_INFO("OVS feature set changed, force recompute."); engine_set_force_recompute(true); } @@ -3898,6 +3898,7 @@ loop_done: ovsdb_idl_loop_destroy(&ovs_idl_loop); ovsdb_idl_loop_destroy(&ovnsb_idl_loop); + ovs_feature_support_destroy(); free(ovs_remote); service_stop(); diff --git a/include/ovn/features.h b/include/ovn/features.h index c35d59b14..d12a8eb0d 100644 --- a/include/ovn/features.h +++ b/include/ovn/features.h @@ -28,13 +28,17 @@ */ enum ovs_feature_support_bits { OVS_CT_ZERO_SNAT_SUPPORT_BIT, + OVS_DP_METER_SUPPORT_BIT, }; enum ovs_feature_value { OVS_CT_ZERO_SNAT_SUPPORT = (1 << OVS_CT_ZERO_SNAT_SUPPORT_BIT), + OVS_DP_METER_SUPPORT = (1 << OVS_DP_METER_SUPPORT_BIT), }; +void ovs_feature_support_destroy(void); bool ovs_feature_is_supported(enum ovs_feature_value feature); -bool ovs_feature_support_update(const struct smap *ovs_capabilities); +bool ovs_feature_support_run(const struct smap *ovs_capabilities, + const char *br_name); #endif diff --git a/lib/actions.c b/lib/actions.c index c572e88ae..7cf6be308 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -87,6 +87,9 @@ encode_start_controller_op(enum action_opcode opcode, bool pause, oc->max_len = UINT16_MAX; oc->reason = OFPR_ACTION; oc->pause = pause; + if (!ovs_feature_is_supported(OVS_DP_METER_SUPPORT)) { + meter_id = NX_CTLR_NO_METER; + } oc->meter_id = meter_id; struct action_header ah = { .opcode = htonl(opcode) }; diff --git a/lib/automake.mk b/lib/automake.mk index ddfe33948..9f9f447d5 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -2,6 +2,7 @@ lib_LTLIBRARIES += lib/libovn.la lib_libovn_la_LDFLAGS = \ $(OVS_LTINFO) \ -Wl,--version-script=$(top_builddir)/lib/libovn.sym \ + $(OVS_LIBDIR)/libopenvswitch.la \ $(AM_LDFLAGS) lib_libovn_la_SOURCES = \ lib/acl-log.c \ diff --git a/lib/features.c b/lib/features.c index fddf4c450..3ec2d26af 100644 --- a/lib/features.c +++ b/lib/features.c @@ -18,7 +18,14 @@ #include #include "lib/util.h" +#include "lib/dirs.h" +#include "socket-util.h" +#include "lib/vswitch-idl.h" #include "openvswitch/vlog.h" +#include "openvswitch/ofpbuf.h" +#include "openvswitch/rconn.h" +#include "openvswitch/ofp-msgs.h" +#include "openvswitch/ofp-meter.h" #include "ovn/features.h" VLOG_DEFINE_THIS_MODULE(features); @@ -40,11 +47,15 @@ static uint32_t supported_ovs_features; static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5); +/* ovs-vswitchd connection. */ +static struct rconn *swconn; + static bool ovs_feature_is_valid(enum ovs_feature_value feature) { switch (feature) { case OVS_CT_ZERO_SNAT_SUPPORT: + case OVS_DP_METER_SUPPORT: return true; default: return false; @@ -58,9 +69,87 @@ ovs_feature_is_supported(enum ovs_feature_value feature) return supported_ovs_features & feature; } +static void +ovs_feature_rconn_setup(const char *br_name) +{ + if (!swconn) { + swconn = rconn_create(5, 0, DSCP_DEFAULT, 1 << OFP15_VERSION); + } + + if (swconn && !rconn_is_connected(swconn)) { + char *target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), br_name); + if (strcmp(target, rconn_get_target(swconn))) { + VLOG_INFO("%s: connecting to switch", target); + rconn_connect(swconn, target, target); + } + free(target); + } +} + +static bool +ovs_feature_get_openflow_cap(const char *br_name) +{ + if (!br_name) { + return false; + } + + ovs_feature_rconn_setup(br_name); + + rconn_run(swconn); + if (!rconn_is_connected(swconn)) { + return false; + } + + bool ret = false; + /* dump datapath meter capabilities. */ + struct ofpbuf *msg = ofpraw_alloc(OFPRAW_OFPST13_METER_FEATURES_REQUEST, + rconn_get_version(swconn), 0); + rconn_send(swconn, msg, NULL); + for (int i = 0; i < 50; i++) { + msg = rconn_recv(swconn); + if (!msg) { + break; + } + + const struct ofp_header *oh = msg->data; + enum ofptype type; + ofptype_decode(&type, oh); + + if (type == OFPTYPE_METER_FEATURES_STATS_REPLY) { + struct ofputil_meter_features mf; + ofputil_decode_meter_features(oh, &mf); + + bool old_state = supported_ovs_features & OVS_DP_METER_SUPPORT; + bool new_state = mf.max_meters > 0; + + if (old_state != new_state) { + ret = true; + if (new_state) { + supported_ovs_features |= OVS_DP_METER_SUPPORT; + } else { + supported_ovs_features &= ~OVS_DP_METER_SUPPORT; + } + } + } + ofpbuf_delete(msg); + } + rconn_run_wait(swconn); + rconn_recv_wait(swconn); + + return ret; +} + +void +ovs_feature_support_destroy(void) +{ + rconn_destroy(swconn); + swconn = NULL; +} + /* Returns 'true' if the set of tracked OVS features has been updated. */ bool -ovs_feature_support_update(const struct smap *ovs_capabilities) +ovs_feature_support_run(const struct smap *ovs_capabilities, + const char *br_name) { static struct smap empty_caps = SMAP_INITIALIZER(&empty_caps); bool updated = false; @@ -69,6 +158,10 @@ ovs_feature_support_update(const struct smap *ovs_capabilities) ovs_capabilities = &empty_caps; } + if (ovs_feature_get_openflow_cap(br_name)) { + updated = true; + } + for (size_t i = 0; i < ARRAY_SIZE(all_ovs_features); i++) { enum ovs_feature_value value = all_ovs_features[i].value; const char *name = all_ovs_features[i].name; diff --git a/lib/test-ovn-features.c b/lib/test-ovn-features.c index deb97581e..aabc547e6 100644 --- a/lib/test-ovn-features.c +++ b/lib/test-ovn-features.c @@ -26,15 +26,15 @@ test_ovn_features(struct ovs_cmdl_context *ctx OVS_UNUSED) struct smap features = SMAP_INITIALIZER(&features); smap_add(&features, "ct_zero_snat", "false"); - ovs_assert(!ovs_feature_support_update(&features)); + ovs_assert(!ovs_feature_support_run(&features, NULL)); ovs_assert(!ovs_feature_is_supported(OVS_CT_ZERO_SNAT_SUPPORT)); smap_replace(&features, "ct_zero_snat", "true"); - ovs_assert(ovs_feature_support_update(&features)); + ovs_assert(ovs_feature_support_run(&features, NULL)); ovs_assert(ovs_feature_is_supported(OVS_CT_ZERO_SNAT_SUPPORT)); smap_add(&features, "unknown_feature", "true"); - ovs_assert(!ovs_feature_support_update(&features)); + ovs_assert(!ovs_feature_support_run(&features, NULL)); smap_destroy(&features); } diff --git a/tests/ovn.at b/tests/ovn.at index 30625ec37..9e55c0d57 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -1529,9 +1529,9 @@ log(verdict=allow, severity=warning); log(name="test1", verdict=drop, severity=info); encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06.74.65.73.74.31) log(verdict=drop, severity=info, meter="meter1"); - encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06,meter_id=4) + encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06) log(name="test1", verdict=drop, severity=info, meter="meter1"); - encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06.74.65.73.74.31,meter_id=4) + encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06.74.65.73.74.31) log(verdict=drop); formats as log(verdict=drop, severity=info); encodes as controller(userdata=00.00.00.07.00.00.00.00.01.06)