From: RYAN D. MOATS <rmo...@us.ibm.com> Persist localvif_to_ofport and tunnels structures and change physical_run to incremental processing.
Signed-off-by: RYAN D. MOATS <rmo...@us.ibm.com> --- ovn/controller/lflow.c | 3 + ovn/controller/physical.c | 99 +++++++++++++++++++++++++++++++++++--------- ovn/controller/physical.h | 2 + 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c index cd4ec9b..5c15a04 100644 --- a/ovn/controller/lflow.c +++ b/ovn/controller/lflow.c @@ -26,6 +26,7 @@ #include "ovn/lib/expr.h" #include "ovn/lib/ovn-sb-idl.h" #include "packets.h" +#include "physical.h" #include "simap.h" VLOG_DEFINE_THIS_MODULE(lflow); @@ -503,6 +504,8 @@ lflow_run(struct controller_ctx *ctx, const struct lport_index *lports, lflow_logical_flow_seqno = 0; lflow_mac_binding_seqno = 0; ovn_flow_table_clear(); + localvif_to_ofports_clear(); + tunnels_clear(); restart_flow_processing = false; } diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c index 222402e..885ac0f 100644 --- a/ovn/controller/physical.c +++ b/ovn/controller/physical.c @@ -48,6 +48,13 @@ physical_register_ovs_idl(struct ovsdb_idl *ovs_idl) ovsdb_idl_add_column(ovs_idl, &ovsrec_interface_col_external_ids); } +struct uuid *hc_uuid = NULL; // uuid to identify OF flows not associated with + // ovsdb rows. + +struct simap localvif_to_ofport = SIMAP_INITIALIZER(&localvif_to_ofport); +struct hmap tunnels = HMAP_INITIALIZER(&tunnels); +unsigned int port_binding_seqno = 0; + /* Maps from a chassis to the OpenFlow port number of the tunnel that can be * used to reach that chassis. */ struct chassis_tunnel { @@ -57,6 +64,28 @@ struct chassis_tunnel { enum chassis_tunnel_type type; }; +void +localvif_to_ofports_clear(void) +{ + simap_clear(&localvif_to_ofport); +} + +void +tunnels_clear(void) +{ + struct chassis_tunnel *tun, *next; + HMAP_FOR_EACH_SAFE (tun, next, hmap_node, &tunnels) { + hmap_remove(&tunnels, &tun->hmap_node); + free(tun); + } +} + +static void +reset_physical_seqnos(void) +{ + port_binding_seqno = 0; +} + static struct chassis_tunnel * chassis_tunnel_find(struct hmap *tunnels, const char *chassis_id) { @@ -144,17 +173,12 @@ get_localnet_port(struct hmap *local_datapaths, int64_t tunnel_key) return ld ? ld->localnet_port : NULL; } -struct uuid *hc_uuid = NULL; // uuid to identify OF flows not associated with - // ovsdb rows. - void physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, const struct ovsrec_bridge *br_int, const char *this_chassis_id, const struct simap *ct_zones, struct hmap *local_datapaths) { - struct simap localvif_to_ofport = SIMAP_INITIALIZER(&localvif_to_ofport); - struct hmap tunnels = HMAP_INITIALIZER(&tunnels); if (!hc_uuid) { hc_uuid = xmalloc(sizeof(struct uuid)); uuid_generate(hc_uuid); @@ -194,11 +218,21 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, bool is_patch = !strcmp(iface_rec->type, "patch"); if (is_patch && localnet) { /* localnet patch ports can be handled just like VIFs. */ - simap_put(&localvif_to_ofport, localnet, ofport); + struct simap_node *old = simap_find(&localvif_to_ofport, + localnet); + if (!old || old->data != ofport) { + simap_put(&localvif_to_ofport, localnet, ofport); + reset_physical_seqnos(); + } break; } else if (is_patch && logpatch) { /* Logical patch ports can be handled just like VIFs. */ - simap_put(&localvif_to_ofport, logpatch, ofport); + struct simap_node *old = simap_find(&localvif_to_ofport, + logpatch); + if (!old || old->data != ofport) { + simap_put(&localvif_to_ofport, logpatch, ofport); + reset_physical_seqnos(); + } break; } else if (chassis_id) { enum chassis_tunnel_type tunnel_type; @@ -215,18 +249,38 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, continue; } - struct chassis_tunnel *tun = xmalloc(sizeof *tun); - hmap_insert(&tunnels, &tun->hmap_node, - hash_string(chassis_id, 0)); - tun->chassis_id = chassis_id; - tun->ofport = u16_to_ofp(ofport); - tun->type = tunnel_type; + struct chassis_tunnel *old = chassis_tunnel_find(&tunnels, + chassis_id); + if (!old) { + struct chassis_tunnel *tun = xmalloc(sizeof *tun); + hmap_insert(&tunnels, &tun->hmap_node, + hash_string(chassis_id, 0)); + tun->chassis_id = chassis_id; + tun->ofport = u16_to_ofp(ofport); + tun->type = tunnel_type; + reset_physical_seqnos(); + } else { + ofp_port_t new_port = u16_to_ofp(ofport); + if (new_port != old->ofport) { + old->ofport = new_port; + reset_physical_seqnos(); + } + if (tunnel_type != old->type) { + old->type = tunnel_type; + reset_physical_seqnos(); + } + } break; } else { const char *iface_id = smap_get(&iface_rec->external_ids, "iface-id"); if (iface_id) { - simap_put(&localvif_to_ofport, iface_id, ofport); + struct simap_node *old = simap_find(&localvif_to_ofport, + iface_id); + if (!old || old->data != ofport) { + simap_put(&localvif_to_ofport, iface_id, ofport); + reset_physical_seqnos(); + } } } } @@ -243,6 +297,13 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, OVSDB_IDL_CHANGE_DELETE); unsigned int mod_seqno = sbrec_port_binding_row_get_seqno(binding, OVSDB_IDL_CHANGE_MODIFY); + unsigned int ins_seqno = sbrec_port_binding_row_get_seqno(binding, + OVSDB_IDL_CHANGE_INSERT); + + if (del_seqno <= port_binding_seqno && mod_seqno <= port_binding_seqno + && ins_seqno <= port_binding_seqno) { + continue; + } /* if the row has a del_seqno > 0, then trying to process the * row isn't going to work (as it has already been freed). @@ -250,6 +311,9 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, * ofctrl_remove_flows() to remove the flow */ if (del_seqno > 0) { ofctrl_remove_flows(&binding->header_.uuid); + if (del_seqno > port_binding_seqno) { + port_binding_seqno = del_seqno; + } continue; } @@ -758,11 +822,4 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve, hc_uuid, 0); ofpbuf_uninit(&ofpacts); - simap_destroy(&localvif_to_ofport); - struct chassis_tunnel *tun_next; - HMAP_FOR_EACH_SAFE (tun, tun_next, hmap_node, &tunnels) { - hmap_remove(&tunnels, &tun->hmap_node); - free(tun); - } - hmap_destroy(&tunnels); } diff --git a/ovn/controller/physical.h b/ovn/controller/physical.h index 1bea6bd..df6c427 100644 --- a/ovn/controller/physical.h +++ b/ovn/controller/physical.h @@ -45,5 +45,7 @@ void physical_run(struct controller_ctx *, enum mf_field_id mff_ovn_geneve, const struct ovsrec_bridge *br_int, const char *chassis_id, const struct simap *ct_zones, struct hmap *local_datapaths); +void localvif_to_ofports_clear(void); +void tunnels_clear(void); #endif /* ovn/physical.h */ -- 1.7.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev