From patchwork Tue Oct 19 10:13:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1543149 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=ocxaR5dn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.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 4HYV331yTZz9sPf for ; Tue, 19 Oct 2021 21:14:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 018F24080F; Tue, 19 Oct 2021 10:14:20 +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 XiiJgXmMqA4W; Tue, 19 Oct 2021 10:14:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id CB33240765; Tue, 19 Oct 2021 10:14:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F1E78C0030; Tue, 19 Oct 2021 10:14:06 +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 677C6C000F for ; Tue, 19 Oct 2021 10:13:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 6F2DD4025D for ; Tue, 19 Oct 2021 10:13:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=canonical.com 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 B-7lSizQ5R6z for ; Tue, 19 Oct 2021 10:13:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by smtp2.osuosl.org (Postfix) with ESMTPS id 8B6BD401C0 for ; Tue, 19 Oct 2021 10:13:55 +0000 (UTC) Received: from frode-threadripper.. (1.general.frode.uk.vpn [10.172.193.250]) (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-1.canonical.com (Postfix) with ESMTPSA id 0120041C9A for ; Tue, 19 Oct 2021 10:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634638433; bh=6yfBy4GYaJiPo5YgBvIWiQN5vyEytFQt+cAAm0/i6y8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ocxaR5dn8w9wSW7bYrJ1g9D8edzx851+5yCNhhhNDMP1zIZQY3uMdTMivSZ+82CZK s8VR4fm9vmbVBNFIZhLd6qcyLYUfp/fbGy4ijrNyse12wZF+WD/C3gsg+/cQ28zvPm UYMTgM54ENAYUOv1fQgX8wQaCkRrNnQB2+64a9Qyv400gOqeMKzmT7YRrWkCt1xruE wIg2WUm9+VO78UybwnwLO4iKjJQ1HV53QyttY1dXeJzht0JHFo7G/QrNomgeWTcxOx 034Lzxk7Fm3bylq3v6wQXzGVtTiGlKTlP6pbPt9lLZdeY2AwlYW0j6KtOw6YCbdGkW 7lMRzAvIblUKg== From: Frode Nordahl To: dev@openvswitch.org Date: Tue, 19 Oct 2021 12:13:44 +0200 Message-Id: <20211019101348.3833652-9-frode.nordahl@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211019101348.3833652-1-frode.nordahl@canonical.com> References: <20211019101348.3833652-1-frode.nordahl@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v7 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 -------------------------- lib/ovn-util.c | 27 +++++++++++++++++++++++++++ lib/ovn-util.h | 18 +++++++++++++++++- 4 files changed, 47 insertions(+), 35 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 a1382a67b..c015f936c 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/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 */