summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2017-05-05 12:54:43 +0000
committerBen Pfaff <blp@ovn.org>2017-05-05 08:52:34 -0700
commit45b18dc3d84e9e83c656963586bab082e57fa2a0 (patch)
treecdc3cc92e5505eb2e34c85453d6341b69ec84a94
parentc841e96ae669485e1fd30edffbaa1f1326c63338 (diff)
downloadopenvswitch-45b18dc3d84e9e83c656963586bab082e57fa2a0.tar.gz
physical: Simplify updating localvif_to_ofport map in physical_run()
These two loops were updating 'localvif_to_ports' to be the same as 'new_localvif_to_ports' and setting physical_map_changed if there had been any differences. This is more work than necessary, so this commit simplifies it. Signed-off-by: Ben Pfaff <blp@ovn.org>
-rw-r--r--ovn/controller/physical.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
index 0f1aa63ab..457fc4541 100644
--- a/ovn/controller/physical.c
+++ b/ovn/controller/physical.c
@@ -753,6 +753,17 @@ consider_mc_group(enum mf_field_id mff_ovn_geneve,
sset_destroy(&remote_chassis);
}
+/* Replaces 'old' by 'new' (destroying 'new'). Returns true if 'old' and 'new'
+ * contained different data, false if they were the same. */
+static bool
+update_ofports(struct simap *old, struct simap *new)
+{
+ bool changed = !simap_equal(old, new);
+ simap_swap(old, new);
+ simap_destroy(new);
+ return changed;
+}
+
void
physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve,
const struct ovsrec_bridge *br_int,
@@ -864,26 +875,8 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve,
}
/* Capture changed or removed openflow ports. */
- struct simap_node *vif_name, *vif_name_next;
- SIMAP_FOR_EACH_SAFE (vif_name, vif_name_next, &localvif_to_ofport) {
- int newport;
- if ((newport = simap_get(&new_localvif_to_ofport, vif_name->name))) {
- if (newport != simap_get(&localvif_to_ofport, vif_name->name)) {
- simap_put(&localvif_to_ofport, vif_name->name, newport);
- physical_map_changed = true;
- }
- } else {
- simap_find_and_delete(&localvif_to_ofport, vif_name->name);
- physical_map_changed = true;
- }
- }
- SIMAP_FOR_EACH (vif_name, &new_localvif_to_ofport) {
- if (!simap_get(&localvif_to_ofport, vif_name->name)) {
- simap_put(&localvif_to_ofport, vif_name->name,
- simap_get(&new_localvif_to_ofport, vif_name->name));
- physical_map_changed = true;
- }
- }
+ physical_map_changed |= update_ofports(&localvif_to_ofport,
+ &new_localvif_to_ofport);
if (physical_map_changed) {
/* Reprocess logical flow table immediately. */
poll_immediate_wake();
@@ -1041,6 +1034,5 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve,
ofpbuf_uninit(&ofpacts);
- simap_destroy(&new_localvif_to_ofport);
simap_destroy(&new_tunnel_to_ofport);
}