This is my suggestion as a way to make the use of extend-table code simpler and more transparent. This is intended to be squashed into the previous commit.
Signed-off-by: Ben Pfaff <[email protected]> --- ovn/controller/ofctrl.c | 47 ++++++++++++++++++++--------------------------- ovn/lib/extend-table.c | 18 +----------------- ovn/lib/extend-table.h | 17 +++++++++++------ 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/ovn/controller/ofctrl.c b/ovn/controller/ofctrl.c index 94ee69c1c3ed..c81c40c6e646 100644 --- a/ovn/controller/ofctrl.c +++ b/ovn/controller/ofctrl.c @@ -69,7 +69,6 @@ static char *ovn_flow_to_string(const struct ovn_flow *); static void ovn_flow_log(const struct ovn_flow *, const char *action); static void ovn_flow_destroy(struct ovn_flow *); -static void add_group(uint32_t table_id, struct ds *ds, struct ovs_list *msgs); static void delete_group(uint32_t table_id, struct ovs_list *msgs); /* OpenFlow connection to the switch. */ @@ -162,7 +161,6 @@ ofctrl_init(struct ovn_extend_table *group_table) ovs_list_init(&flow_updates); ovn_init_symtab(&symtab); groups = group_table; - groups->create = add_group; groups->remove = delete_group; } @@ -767,30 +765,6 @@ add_group_mod(const struct ofputil_group_mod *gm, struct ovs_list *msgs) } static void -add_group(uint32_t table_id, struct ds *ds, struct ovs_list *msgs) { - /* Create and install new group. */ - struct ofputil_group_mod gm; - enum ofputil_protocol usable_protocols; - char *error; - struct ds group_string = DS_EMPTY_INITIALIZER; - ds_put_format(&group_string, "group_id=%"PRIu32",%s", - table_id, ds_cstr(ds)); - - error = parse_ofp_group_mod_str(&gm, OFPGC11_ADD, ds_cstr(&group_string), - NULL, &usable_protocols); - if (!error) { - add_group_mod(&gm, msgs); - } else { - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); - VLOG_ERR_RL(&rl, "new group %s %s", error, - ds_cstr(&group_string)); - free(error); - } - ds_destroy(&group_string); - ofputil_uninit_group_mod(&gm); -} - -static void delete_group(uint32_t table_id, struct ovs_list *msgs) { /* Delete the group. */ struct ofputil_group_mod gm; @@ -878,7 +852,26 @@ ofctrl_put(struct hmap *flow_table, struct shash *pending_ct_zones, } } - ovn_extend_table_install_desired(groups, &msgs); + struct ovn_extend_table_info *desired; + EXTEND_TABLE_FOR_EACH_UNINSTALLED (desired, groups) { + char *group_string = xasprintf("group_id=%"PRIu32",%s", + desired->table_id, + ds_cstr(&desired->info)); + + struct ofputil_group_mod gm; + enum ofputil_protocol usable_protocols; + char *error = parse_ofp_group_mod_str(&gm, OFPGC11_ADD, group_string, + NULL, &usable_protocols); + if (!error) { + add_group_mod(&gm, &msgs); + } else { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_ERR_RL(&rl, "new group %s %s", error, group_string); + free(error); + } + free(group_string); + ofputil_uninit_group_mod(&gm); + } /* Iterate through all of the installed flows. If any of them are no * longer desired, delete them; if any of them should have different diff --git a/ovn/lib/extend-table.c b/ovn/lib/extend-table.c index dfd1a9413cfc..26391b6bd264 100644 --- a/ovn/lib/extend-table.c +++ b/ovn/lib/extend-table.c @@ -53,7 +53,7 @@ void ovn_extend_table_destroy(struct ovn_extend_table *table) /* Finds and returns a group_info in 'existing' whose key is identical * to 'target''s key, or NULL if there is none. */ -static struct ovn_extend_table_info * +struct ovn_extend_table_info * ovn_extend_table_lookup(struct hmap *exisiting, const struct ovn_extend_table_info *target) { @@ -88,22 +88,6 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) } void -ovn_extend_table_install_desired(struct ovn_extend_table *table, - struct ovs_list *msgs) -{ - struct ovn_extend_table_info *desired; - - /* Iterate through all the desired tables. If there are new ones, - * add them to the switch. */ - HMAP_FOR_EACH (desired, hmap_node, &table->desired) { - if (!ovn_extend_table_lookup(&table->existing, desired)) { - /* Create and install new group. */ - table->create(desired->table_id, &desired->info, msgs); - } - } -} - -void ovn_extend_table_remove_existing(struct ovn_extend_table *table, struct ovs_list *msgs) { diff --git a/ovn/lib/extend-table.h b/ovn/lib/extend-table.h index ededba59dc01..67ac5d77436e 100644 --- a/ovn/lib/extend-table.h +++ b/ovn/lib/extend-table.h @@ -33,9 +33,6 @@ struct ovn_extend_table { struct hmap desired; struct hmap existing; - /* Used to create a form entity through the openflow channel. */ - void (*create)(uint32_t, struct ds *, struct ovs_list *); - /* Used to remove a form entity through the openflow channel. */ void (*remove)(uint32_t, struct ovs_list *); }; @@ -52,12 +49,12 @@ void ovn_extend_table_init(struct ovn_extend_table *table); void ovn_extend_table_destroy(struct ovn_extend_table *table); -void ovn_extend_table_install_desired(struct ovn_extend_table *table, - struct ovs_list *msgs); - void ovn_extend_table_remove_existing(struct ovn_extend_table *table, struct ovs_list *msgs); +struct ovn_extend_table_info *ovn_extend_table_lookup( + struct hmap *, const struct ovn_extend_table_info *); + /* Move the contents of desired to existing. */ void ovn_extend_table_move(struct ovn_extend_table *table); @@ -66,4 +63,12 @@ void ovn_extend_table_clear(struct ovn_extend_table *table, bool existing); uint32_t ovn_extend_table_assign_id(struct ovn_extend_table *table, struct ds *ds); +/* Iterates 'DESIRED' through all of the 'ovn_extend_table_info's in + * 'TABLE'->desired that are not in 'TABLE'->existing. (The loop body + * presumably adds those */ +#define EXTEND_TABLE_FOR_EACH_UNINSTALLED(DESIRED, TABLE) \ + HMAP_FOR_EACH (DESIRED, hmap_node, &(TABLE)->desired) \ + if (!ovn_extend_table_lookup(&(TABLE)->existing, DESIRED)) + + #endif /* ovn/lib/extend-table.h */ -- 2.10.2 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
