From patchwork Tue Sep 28 12:56:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1533880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=A1wEB1xb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJfft38dpz9t0T for ; Tue, 28 Sep 2021 22:57:26 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7D8F2407F1; Tue, 28 Sep 2021 12:57:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tvq_d_EGFlT5; Tue, 28 Sep 2021 12:57:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id ED72A40752; Tue, 28 Sep 2021 12:57:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 68A3DC0033; Tue, 28 Sep 2021 12:57:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A994C0023 for ; Tue, 28 Sep 2021 12:57:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 11529403B1 for ; Tue, 28 Sep 2021 12:57:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EM9XzC2oLyGS for ; Tue, 28 Sep 2021 12:57:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by smtp4.osuosl.org (Postfix) with ESMTPS id 49ED1403A7 for ; Tue, 28 Sep 2021 12:57:00 +0000 (UTC) Received: from frode-threadripper.. (ti0189a330-1161.bb.online.no [88.88.219.141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 42D9040DEE; Tue, 28 Sep 2021 12:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632833818; bh=v6A/7jmscQGjrr1aNmYjpeJjCacQ3uwe6o9O8fIAj8w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A1wEB1xbMvbc2OQPmWsZ8KpGJJvJqfQYTNRt79C2bT16GisnVCW1ZDfnnzJov3geI AOaE1uB1pt2GbiywZF3DLbe8sJKrTPY43yo5W57jJ42bopdsQwjpdbWivF0HDyrPAu ZEw3AtqLstWxt80M+E/qPjYgp12zhDXt+/t5zW1l5wBXLmM8sc5dvy1JN7m768reBG RJ+Viih7R9DA6Pa2P8scKumcoYdvsO87sFveHLmOgr7vi47o2/vUL7SFnLXH2jFPwT bTKj6lQotga1dSqGHhWHaPAwu8YCaBBFvZp0XB6klX/xIMlmSFPayIW5zVNKAfsSdI sVW/1BL6YJogQ== From: Frode Nordahl To: dev@openvswitch.org Date: Tue, 28 Sep 2021 14:56:49 +0200 Message-Id: <20210928125653.7329-9-frode.nordahl@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210928125653.7329-1-frode.nordahl@canonical.com> References: <20210928125653.7329-1-frode.nordahl@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn v5 08/12] ovn-controller: Move shared functions to ovn-util 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" The `get_tunnel_type` (and associated enum) and `get_bridge` functions are used in modules other than the `ovn-controller` module. Since the `ovn-controller` module also has the `main` function this organization makes it hard or impossible to unit test. Signed-off-by: Frode Nordahl --- controller/local_data.h | 11 +++-------- controller/ovn-controller.c | 26 -------------------------- controller/ovn-controller.h | 5 ----- lib/ovn-util.c | 27 +++++++++++++++++++++++++++ lib/ovn-util.h | 18 +++++++++++++++++- 5 files changed, 47 insertions(+), 40 deletions(-) diff --git a/controller/local_data.h b/controller/local_data.h index f6317e9ca..c790bc722 100644 --- a/controller/local_data.h +++ b/controller/local_data.h @@ -21,6 +21,9 @@ #include "lib/smap.h" #include "lib/simap.h" +/* OVN includes. */ +#include "lib/ovn-util.h" + struct sbrec_datapath_binding; struct sbrec_port_binding; struct sbrec_chassis; @@ -120,14 +123,6 @@ void tracked_datapath_lport_add(const struct sbrec_port_binding *, struct hmap *tracked_datapaths); void tracked_datapaths_destroy(struct hmap *tracked_datapaths); -/* Must be a bit-field ordered from most-preferred (higher number) to - * least-preferred (lower number). */ -enum chassis_tunnel_type { - GENEVE = 1 << 2, - STT = 1 << 1, - VXLAN = 1 << 0 -}; - /* Maps from a chassis to the OpenFlow port number of the tunnel that can be * used to reach that chassis. */ struct chassis_tunnel { diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index b0e4174aa..8e35188c6 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -140,32 +140,6 @@ struct pending_pkt { /* Registered ofctrl seqno type for nb_cfg propagation. */ static size_t ofctrl_seq_type_nb_cfg; -uint32_t -get_tunnel_type(const char *name) -{ - if (!strcmp(name, "geneve")) { - return GENEVE; - } else if (!strcmp(name, "stt")) { - return STT; - } else if (!strcmp(name, "vxlan")) { - return VXLAN; - } - - return 0; -} - -const struct ovsrec_bridge * -get_bridge(const struct ovsrec_bridge_table *bridge_table, const char *br_name) -{ - const struct ovsrec_bridge *br; - OVSREC_BRIDGE_TABLE_FOR_EACH (br, bridge_table) { - if (!strcmp(br->name, br_name)) { - return br; - } - } - return NULL; -} - static unsigned int update_sb_monitors(struct ovsdb_idl *ovnsb_idl, const struct sbrec_chassis *chassis, diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h index 78a53312f..827b7442d 100644 --- a/controller/ovn-controller.h +++ b/controller/ovn-controller.h @@ -40,13 +40,8 @@ struct ct_zone_pending_entry { enum ct_zone_pending_state state; }; -const struct ovsrec_bridge *get_bridge(const struct ovsrec_bridge_table *, - const char *br_name); - struct sbrec_encap *preferred_encap(const struct sbrec_chassis *); -uint32_t get_tunnel_type(const char *name); - struct pb_ld_binding { const struct sbrec_port_binding *pb; const struct local_datapath *ld; diff --git a/lib/ovn-util.c b/lib/ovn-util.c index 683ca37d9..19e3c2343 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -23,6 +23,7 @@ #include "include/ovn/actions.h" #include "openvswitch/ofp-parse.h" #include "openvswitch/vlog.h" +#include "lib/vswitch-idl.h" #include "ovn-dirs.h" #include "ovn-nb-idl.h" #include "ovn-sb-idl.h" @@ -791,3 +792,29 @@ ddlog_err(const char *msg) VLOG_ERR("%s", msg); } #endif + +uint32_t +get_tunnel_type(const char *name) +{ + if (!strcmp(name, "geneve")) { + return GENEVE; + } else if (!strcmp(name, "stt")) { + return STT; + } else if (!strcmp(name, "vxlan")) { + return VXLAN; + } + + return 0; +} + +const struct ovsrec_bridge * +get_bridge(const struct ovsrec_bridge_table *bridge_table, const char *br_name) +{ + const struct ovsrec_bridge *br; + OVSREC_BRIDGE_TABLE_FOR_EACH (br, bridge_table) { + if (!strcmp(br->name, br_name)) { + return br; + } + } + return NULL; +} diff --git a/lib/ovn-util.h b/lib/ovn-util.h index b0bc70a16..2fa92e069 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -285,4 +285,20 @@ void ddlog_warn(const char *msg); void ddlog_err(const char *msg); #endif -#endif + +/* Must be a bit-field ordered from most-preferred (higher number) to + * least-preferred (lower number). */ +enum chassis_tunnel_type { + GENEVE = 1 << 2, + STT = 1 << 1, + VXLAN = 1 << 0 +}; + +uint32_t get_tunnel_type(const char *name); + +struct ovsrec_bridge_table; +const struct ovsrec_bridge *get_bridge(const struct ovsrec_bridge_table *, + const char *br_name); + + +#endif /* OVN_UTIL_H */