Change enum chassis_tunnel_type from bit-field values to simple
sequential indices to simplify array-based lookups in future
optimizations.

The preference order (GENEVE > VXLAN) is preserved through numeric
comparison.

Signed-off-by: Han Zhou <[email protected]>
---
 controller/encaps.c         | 9 ++++++---
 controller/ovn-controller.h | 2 +-
 lib/ovn-util.c              | 4 ++--
 lib/ovn-util.h              | 9 +++++----
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/controller/encaps.c b/controller/encaps.c
index 8e2b8e6b82e6..3ed42534b36a 100644
--- a/controller/encaps.c
+++ b/controller/encaps.c
@@ -349,7 +349,9 @@ exit:
 }
 
 static bool
-chassis_has_type(const struct sbrec_chassis *chassis, uint32_t tun_type) {
+chassis_has_type(const struct sbrec_chassis *chassis,
+                 enum chassis_tunnel_type tun_type)
+{
     for (size_t i = 0; i < chassis->n_encaps; i++) {
         if (get_tunnel_type(chassis->encaps[i]->type) == tun_type) {
             return true;
@@ -363,10 +365,11 @@ preferred_encap(const struct sbrec_chassis *chassis_rec,
                 const struct sbrec_chassis *this_chassis)
 {
     struct sbrec_encap *best_encap = NULL;
-    uint32_t best_type = 0;
+    enum chassis_tunnel_type best_type = TUNNEL_TYPE_INVALID;
 
     for (size_t i = 0; i < chassis_rec->n_encaps; i++) {
-        uint32_t tun_type = get_tunnel_type(chassis_rec->encaps[i]->type);
+        enum chassis_tunnel_type tun_type =
+            get_tunnel_type(chassis_rec->encaps[i]->type);
         if (tun_type > best_type && chassis_has_type(this_chassis, tun_type)) {
             best_type = tun_type;
             best_encap = chassis_rec->encaps[i];
diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h
index fafd704df7a5..57d5577bc8f3 100644
--- a/controller/ovn-controller.h
+++ b/controller/ovn-controller.h
@@ -24,6 +24,6 @@ struct ovsrec_bridge_table;
 const struct ovsrec_bridge *get_bridge(const struct ovsrec_bridge_table *,
                                        const char *br_name);
 
-uint32_t get_tunnel_type(const char *name);
+enum chassis_tunnel_type get_tunnel_type(const char *name);
 
 #endif /* controller/ovn-controller.h */
diff --git a/lib/ovn-util.c b/lib/ovn-util.c
index 1b75579a8f7d..cec029e42d25 100644
--- a/lib/ovn-util.c
+++ b/lib/ovn-util.c
@@ -946,7 +946,7 @@ ovn_get_internal_version(void)
                      N_OVNACTS, OVN_INTERNAL_MINOR_VER);
 }
 
-uint32_t
+enum chassis_tunnel_type
 get_tunnel_type(const char *name)
 {
     if (!strcmp(name, "geneve")) {
@@ -955,7 +955,7 @@ get_tunnel_type(const char *name)
         return VXLAN;
     }
 
-    return 0;
+    return TUNNEL_TYPE_INVALID;
 }
 
 const struct ovsrec_bridge *
diff --git a/lib/ovn-util.h b/lib/ovn-util.h
index aa1a878bbd23..611f80f1e6f6 100644
--- a/lib/ovn-util.h
+++ b/lib/ovn-util.h
@@ -345,14 +345,15 @@ hash_add_in6_addr(uint32_t hash, const struct in6_addr 
*addr)
     return hash;
 }
 
-/* Must be a bit-field ordered from most-preferred (higher number) to
+/* Tunnel types ordered from most-preferred (higher number) to
  * least-preferred (lower number). */
 enum chassis_tunnel_type {
-    GENEVE = 1 << 1,
-    VXLAN  = 1 << 0
+    TUNNEL_TYPE_INVALID = -1,
+    VXLAN  = 0,
+    GENEVE = 1
 };
 
-uint32_t get_tunnel_type(const char *name);
+enum chassis_tunnel_type get_tunnel_type(const char *name);
 
 struct ovsrec_bridge_table;
 const struct ovsrec_bridge *get_bridge(const struct ovsrec_bridge_table *,
-- 
2.38.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to