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 <frode.nord...@canonical.com>
---
 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 */
-- 
2.32.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to