They behave exactly in the same way, no need for a new (custom) data
structure.
Signed-off-by: Dumitru Ceara <[email protected]>
---
controller/lflow.c | 50 ++++++++++++++++++++---------------------------
controller/ofctrl.c | 54 ++++++++++++---------------------------------------
controller/ofctrl.h | 9 ++-------
3 files changed, 36 insertions(+), 77 deletions(-)
diff --git a/controller/lflow.c b/controller/lflow.c
index 32664b080..b5f4f1849 100644
--- a/controller/lflow.c
+++ b/controller/lflow.c
@@ -34,6 +34,7 @@
#include "lib/ovn-l7.h"
#include "lib/ovn-sb-idl.h"
#include "lib/extend-table.h"
+#include "lib/uuidset.h"
#include "packets.h"
#include "physical.h"
#include "simap.h"
@@ -383,8 +384,8 @@ lflow_handle_changed_flows(struct lflow_ctx_in *l_ctx_in,
/* Flood remove the flows for all the tracked lflows. Its possible that
* lflow_add_flows_for_datapath() may have been called before calling
* this function. */
- struct hmap flood_remove_nodes = HMAP_INITIALIZER(&flood_remove_nodes);
- struct ofctrl_flood_remove_node *ofrn;
+ struct uuidset flood_remove_nodes =
+ UUIDSET_INITIALIZER(&flood_remove_nodes);
SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow,
l_ctx_in->logical_flow_table) {
if (lflows_processed_find(l_ctx_out->lflows_processed,
@@ -394,10 +395,7 @@ lflow_handle_changed_flows(struct lflow_ctx_in *l_ctx_in,
continue;
}
VLOG_DBG("delete lflow "UUID_FMT, UUID_ARGS(&lflow->header_.uuid));
- ofrn = xmalloc(sizeof *ofrn);
- ofrn->sb_uuid = lflow->header_.uuid;
- hmap_insert(&flood_remove_nodes, &ofrn->hmap_node,
- uuid_hash(&ofrn->sb_uuid));
+ uuidset_insert(&flood_remove_nodes, &lflow->header_.uuid);
if (!sbrec_logical_flow_is_new(lflow)) {
if (lflow_cache_is_enabled(l_ctx_out->lflow_cache)) {
lflow_cache_delete(l_ctx_out->lflow_cache,
@@ -406,14 +404,16 @@ lflow_handle_changed_flows(struct lflow_ctx_in *l_ctx_in,
}
}
ofctrl_flood_remove_flows(l_ctx_out->flow_table, &flood_remove_nodes);
- HMAP_FOR_EACH (ofrn, hmap_node, &flood_remove_nodes) {
+
+ struct uuidset_node *ofrn;
+ UUIDSET_FOR_EACH (ofrn, &flood_remove_nodes) {
/* Delete entries from lflow resource reference. */
- lflow_resource_destroy_lflow(l_ctx_out->lfrr, &ofrn->sb_uuid);
+ lflow_resource_destroy_lflow(l_ctx_out->lfrr, &ofrn->uuid);
/* Delete conj_ids owned by the lflow. */
- lflow_conj_ids_free(l_ctx_out->conj_ids, &ofrn->sb_uuid);
+ lflow_conj_ids_free(l_ctx_out->conj_ids, &ofrn->uuid);
/* Reprocessing the lflow if the sb record is not deleted. */
lflow = sbrec_logical_flow_table_get_for_uuid(
- l_ctx_in->logical_flow_table, &ofrn->sb_uuid);
+ l_ctx_in->logical_flow_table, &ofrn->uuid);
if (lflow) {
VLOG_DBG("re-add lflow "UUID_FMT,
UUID_ARGS(&lflow->header_.uuid));
@@ -432,11 +432,7 @@ lflow_handle_changed_flows(struct lflow_ctx_in *l_ctx_in,
consider_logical_flow(lflow, false, l_ctx_in, l_ctx_out);
}
}
- HMAP_FOR_EACH_SAFE (ofrn, hmap_node, &flood_remove_nodes) {
- hmap_remove(&flood_remove_nodes, &ofrn->hmap_node);
- free(ofrn);
- }
- hmap_destroy(&flood_remove_nodes);
+ uuidset_destroy(&flood_remove_nodes);
return ret;
}
@@ -901,31 +897,31 @@ lflow_handle_changed_ref(enum ref_type ref_type, const
char *ref_name,
/* Re-parse the related lflows. */
/* Firstly, flood remove the flows from desired flow table. */
- struct hmap flood_remove_nodes = HMAP_INITIALIZER(&flood_remove_nodes);
+ struct uuidset flood_remove_nodes =
+ UUIDSET_INITIALIZER(&flood_remove_nodes);
LIST_FOR_EACH_SAFE (lrln_uuid, list_node, &lflows_todo) {
VLOG_DBG("Reprocess lflow "UUID_FMT" for resource type: %d,"
" name: %s.",
UUID_ARGS(&lrln_uuid->lflow_uuid),
ref_type, ref_name);
- ofctrl_flood_remove_add_node(&flood_remove_nodes,
- &lrln_uuid->lflow_uuid);
+ uuidset_insert(&flood_remove_nodes, &lrln_uuid->lflow_uuid);
free(lrln_uuid);
}
ofctrl_flood_remove_flows(l_ctx_out->flow_table, &flood_remove_nodes);
/* Secondly, for each lflow that is actually removed, reprocessing it. */
- struct ofctrl_flood_remove_node *ofrn;
- HMAP_FOR_EACH (ofrn, hmap_node, &flood_remove_nodes) {
- lflow_resource_destroy_lflow(l_ctx_out->lfrr, &ofrn->sb_uuid);
- lflow_conj_ids_free(l_ctx_out->conj_ids, &ofrn->sb_uuid);
+ struct uuidset_node *ofrn;
+ UUIDSET_FOR_EACH (ofrn, &flood_remove_nodes) {
+ lflow_resource_destroy_lflow(l_ctx_out->lfrr, &ofrn->uuid);
+ lflow_conj_ids_free(l_ctx_out->conj_ids, &ofrn->uuid);
const struct sbrec_logical_flow *lflow =
sbrec_logical_flow_table_get_for_uuid(l_ctx_in->logical_flow_table,
- &ofrn->sb_uuid);
+ &ofrn->uuid);
if (!lflow) {
VLOG_DBG("lflow "UUID_FMT" not found while reprocessing for"
" resource type: %d, name: %s.",
- UUID_ARGS(&ofrn->sb_uuid),
+ UUID_ARGS(&ofrn->uuid),
ref_type, ref_name);
continue;
}
@@ -943,11 +939,7 @@ lflow_handle_changed_ref(enum ref_type ref_type, const
char *ref_name,
consider_logical_flow(lflow, false, l_ctx_in, l_ctx_out);
}
- HMAP_FOR_EACH_SAFE (ofrn, hmap_node, &flood_remove_nodes) {
- hmap_remove(&flood_remove_nodes, &ofrn->hmap_node);
- free(ofrn);
- }
- hmap_destroy(&flood_remove_nodes);
+ uuidset_destroy(&flood_remove_nodes);
return ret;
}
diff --git a/controller/ofctrl.c b/controller/ofctrl.c
index 54b75b3ac..c77991258 100644
--- a/controller/ofctrl.c
+++ b/controller/ofctrl.c
@@ -281,7 +281,7 @@ static void ovn_flow_log(const struct ovn_flow *, const
char *action);
static void remove_flows_from_sb_to_flow(struct ovn_desired_flow_table *,
struct sb_to_flow *,
const char *log_msg,
- struct hmap *flood_remove_nodes);
+ struct uuidset *flood_remove_nodes);
/* OpenFlow connection to the switch. */
static struct rconn *swconn;
@@ -1345,32 +1345,10 @@ ofctrl_remove_flows(struct ovn_desired_flow_table
*flow_table,
ovn_extend_table_remove_desired(meters, sb_uuid);
}
-static struct ofctrl_flood_remove_node *
-flood_remove_find_node(struct hmap *flood_remove_nodes, struct uuid *sb_uuid)
-{
- struct ofctrl_flood_remove_node *ofrn;
- HMAP_FOR_EACH_WITH_HASH (ofrn, hmap_node, uuid_hash(sb_uuid),
- flood_remove_nodes) {
- if (uuid_equals(&ofrn->sb_uuid, sb_uuid)) {
- return ofrn;
- }
- }
- return NULL;
-}
-
-void
-ofctrl_flood_remove_add_node(struct hmap *flood_remove_nodes,
- const struct uuid *sb_uuid)
-{
- struct ofctrl_flood_remove_node *ofrn = xmalloc(sizeof *ofrn);
- ofrn->sb_uuid = *sb_uuid;
- hmap_insert(flood_remove_nodes, &ofrn->hmap_node, uuid_hash(sb_uuid));
-}
-
static void
flood_remove_flows_for_sb_uuid(struct ovn_desired_flow_table *flow_table,
const struct uuid *sb_uuid,
- struct hmap *flood_remove_nodes)
+ struct uuidset *flood_remove_nodes)
{
struct sb_to_flow *stf = sb_to_flow_find(&flow_table->uuid_flow_table,
sb_uuid);
@@ -1384,30 +1362,25 @@ flood_remove_flows_for_sb_uuid(struct
ovn_desired_flow_table *flow_table,
void
ofctrl_flood_remove_flows(struct ovn_desired_flow_table *flow_table,
- struct hmap *flood_remove_nodes)
+ struct uuidset *flood_remove_nodes)
{
- struct ofctrl_flood_remove_node *ofrn;
- int i, n = 0;
-
/* flood_remove_flows_for_sb_uuid() will modify the 'flood_remove_nodes'
* hash map by inserting new items, so we can't use it for iteration.
* Copying the sb_uuids into an array. */
- struct uuid *sb_uuids;
- sb_uuids = xmalloc(hmap_count(flood_remove_nodes) * sizeof *sb_uuids);
- HMAP_FOR_EACH (ofrn, hmap_node, flood_remove_nodes) {
- sb_uuids[n++] = ofrn->sb_uuid;
- }
+ struct uuid *sb_uuids = uuidset_array(flood_remove_nodes);
+ size_t n = uuidset_count(flood_remove_nodes);
- for (i = 0; i < n; i++) {
+ for (size_t i = 0; i < n; i++) {
flood_remove_flows_for_sb_uuid(flow_table, &sb_uuids[i],
flood_remove_nodes);
}
free(sb_uuids);
/* remove any related group and meter info */
- HMAP_FOR_EACH (ofrn, hmap_node, flood_remove_nodes) {
- ovn_extend_table_remove_desired(groups, &ofrn->sb_uuid);
- ovn_extend_table_remove_desired(meters, &ofrn->sb_uuid);
+ struct uuidset_node *ofrn;
+ UUIDSET_FOR_EACH (ofrn, flood_remove_nodes) {
+ ovn_extend_table_remove_desired(groups, &ofrn->uuid);
+ ovn_extend_table_remove_desired(meters, &ofrn->uuid);
}
}
@@ -1489,7 +1462,7 @@ static void
remove_flows_from_sb_to_flow(struct ovn_desired_flow_table *flow_table,
struct sb_to_flow *stf,
const char *log_msg,
- struct hmap *flood_remove_nodes)
+ struct uuidset *flood_remove_nodes)
{
/* ovn_flows that have other references and waiting to be removed. */
struct ovs_list to_be_removed = OVS_LIST_INITIALIZER(&to_be_removed);
@@ -1552,9 +1525,8 @@ remove_flows_from_sb_to_flow(struct
ovn_desired_flow_table *flow_table,
}
LIST_FOR_EACH_SAFE (f, list_node, &to_be_removed) {
LIST_FOR_EACH_SAFE (sfr, sb_list, &f->references) {
- if (!flood_remove_find_node(flood_remove_nodes, &sfr->sb_uuid)) {
- ofctrl_flood_remove_add_node(flood_remove_nodes,
- &sfr->sb_uuid);
+ if (!uuidset_find(flood_remove_nodes, &sfr->sb_uuid)) {
+ uuidset_insert(flood_remove_nodes, &sfr->sb_uuid);
flood_remove_flows_for_sb_uuid(flow_table, &sfr->sb_uuid,
flood_remove_nodes);
}
diff --git a/controller/ofctrl.h b/controller/ofctrl.h
index 330b0b6ca..71d3f5838 100644
--- a/controller/ofctrl.h
+++ b/controller/ofctrl.h
@@ -22,6 +22,7 @@
#include "openvswitch/meta-flow.h"
#include "ovsdb-idl.h"
#include "hindex.h"
+#include "lib/uuidset.h"
struct ovn_extend_table;
struct hmap;
@@ -118,14 +119,8 @@ void ofctrl_remove_flows(struct ovn_desired_flow_table *,
*
* It adds all the sb_uuids that are actually removed in the
* flood_remove_nodes. */
-struct ofctrl_flood_remove_node {
- struct hmap_node hmap_node;
- struct uuid sb_uuid;
-};
void ofctrl_flood_remove_flows(struct ovn_desired_flow_table *,
- struct hmap *flood_remove_nodes);
-void ofctrl_flood_remove_add_node(struct hmap *flood_remove_nodes,
- const struct uuid *sb_uuid);
+ struct uuidset *flood_remove_nodes);
bool ofctrl_remove_flows_for_as_ip(struct ovn_desired_flow_table *,
const struct uuid *lflow_uuid,
const struct addrset_info *,