[ovs-dev] [PATCH ovn v13 6/7] Add an util function get_unique_lport_key() for generating unique lport key.

numans at ovn.org numans at ovn.org
Fri Jun 19 11:10:41 UTC 2020


From: Numan Siddique <numans at ovn.org>

Suggested-by: Dumitru Ceara <dceara at redhat.com>
Acked-by: Han Zhou <hzhou at ovn.org>
Signed-off-by: Numan Siddique <numans at ovn.org>
---
 controller/binding.c | 8 ++++----
 controller/lflow.c   | 8 ++++----
 lib/ovn-util.h       | 8 ++++++++
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/controller/binding.c b/controller/binding.c
index 58e0bf59f..9dbbb34df 100644
--- a/controller/binding.c
+++ b/controller/binding.c
@@ -521,8 +521,8 @@ update_local_lport_ids(struct binding_ctx_out *b_ctx,
                        const struct sbrec_port_binding *pb)
 {
     char buf[16];
-    snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64,
-             pb->datapath->tunnel_key, pb->tunnel_key);
+    get_unique_lport_key(pb->datapath->tunnel_key, pb->tunnel_key,
+                         buf, sizeof(buf));
     if (sset_add(b_ctx->local_lport_ids, buf) != NULL) {
         b_ctx->local_lport_ids_changed = true;
 
@@ -541,8 +541,8 @@ remove_local_lport_ids(struct binding_ctx_out *b_ctx,
                        const struct sbrec_port_binding *pb)
 {
     char buf[16];
-    snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64,
-             pb->datapath->tunnel_key, pb->tunnel_key);
+    get_unique_lport_key(pb->datapath->tunnel_key, pb->tunnel_key,
+                         buf, sizeof(buf));
     if (sset_find_and_delete(b_ctx->local_lport_ids, buf)) {
         b_ctx->local_lport_ids_changed = true;
 
diff --git a/controller/lflow.c b/controller/lflow.c
index c76ba4e92..15f1a6acb 100644
--- a/controller/lflow.c
+++ b/controller/lflow.c
@@ -130,7 +130,7 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name)
     /* Store the port_name to lflow reference. */
     int64_t dp_id = pb->datapath->tunnel_key;
     char buf[16];
-    snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, dp_id, pb->tunnel_key);
+    get_unique_lport_key(dp_id, pb->tunnel_key, buf, sizeof(buf));
     lflow_resource_add(c_aux->lfrr, REF_TYPE_PORTBINDING, buf,
                        &c_aux->lflow->header_.uuid);
 
@@ -664,7 +664,7 @@ consider_logical_flow(const struct sbrec_logical_flow *lflow,
             if (port_id) {
                 int64_t dp_id = lflow->logical_datapath->tunnel_key;
                 char buf[16];
-                snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, dp_id, port_id);
+                get_unique_lport_key(dp_id, port_id, buf, sizeof(buf));
                 lflow_resource_add(l_ctx_out->lfrr, REF_TYPE_PORTBINDING, buf,
                                    &lflow->header_.uuid);
                 if (!sset_contains(l_ctx_in->local_lport_ids, buf)) {
@@ -928,8 +928,8 @@ lflow_handle_flows_for_lport(const struct sbrec_port_binding *pb,
     bool changed;
     int64_t dp_id = pb->datapath->tunnel_key;
     char pb_ref_name[16];
-    snprintf(pb_ref_name, sizeof(pb_ref_name), "%"PRId64"_%"PRId64,
-             dp_id, pb->tunnel_key);
+    get_unique_lport_key(dp_id, pb->tunnel_key, pb_ref_name,
+                         sizeof(pb_ref_name));
 
     return lflow_handle_changed_ref(REF_TYPE_PORTBINDING, pb_ref_name,
                                     l_ctx_in, l_ctx_out, &changed);
diff --git a/lib/ovn-util.h b/lib/ovn-util.h
index e13cf4d78..eba2948ff 100644
--- a/lib/ovn-util.h
+++ b/lib/ovn-util.h
@@ -114,6 +114,14 @@ bool ovn_tnlid_in_use(const struct hmap *set, uint32_t tnlid);
 uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min,
                             uint32_t max, uint32_t *hint);
 
+static inline void
+get_unique_lport_key(uint64_t dp_tunnel_key, uint64_t lport_tunnel_key,
+                     char *buf, size_t buf_size)
+{
+    snprintf(buf, buf_size, "%"PRId64"_%"PRId64, dp_tunnel_key,
+             lport_tunnel_key);
+}
+
 char *ovn_chassis_redirect_name(const char *port_name);
 void ovn_set_pidfile(const char *name);
 
-- 
2.26.2



More information about the dev mailing list