Part of the load balancer healthcheck/svc configuration parsing was done in ovn-northd.c and part in lib/lb.c. Consolidate this in ovn-northd.c. As a side effect this will remove dependency on the 'ports' hmap in lib/lb.c. This enables future commits to optimize load balancer configuration parsing.
Signed-off-by: Dumitru Ceara <[email protected]> --- lib/lb.c | 36 +------------ lib/lb.h | 5 -- northd/ovn-northd.c | 141 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 87 insertions(+), 95 deletions(-) diff --git a/lib/lb.c b/lib/lb.c index 992286464..18dc226e9 100644 --- a/lib/lb.c +++ b/lib/lb.c @@ -101,10 +101,7 @@ static void ovn_northd_lb_vip_init(struct ovn_northd_lb_vip *lb_vip_nb, const struct ovn_lb_vip *lb_vip, const struct nbrec_load_balancer *nbrec_lb, - const char *vip_port_str, const char *backend_ips, - struct hmap *ports, - void * (*ovn_port_find)(const struct hmap *ports, - const char *name)) + const char *vip_port_str, const char *backend_ips) { lb_vip_nb->vip_port_str = xstrdup(vip_port_str); lb_vip_nb->backend_ips = xstrdup(backend_ips); @@ -133,30 +130,6 @@ void ovn_northd_lb_vip_init(struct ovn_northd_lb_vip *lb_vip_nb, } lb_vip_nb->lb_health_check = lb_health_check; - - for (size_t j = 0; j < lb_vip_nb->n_backends; j++) { - struct ovn_lb_backend *backend = &lb_vip->backends[j]; - struct ovn_northd_lb_backend *backend_nb = &lb_vip_nb->backends_nb[j]; - - struct ovn_port *op = NULL; - char *svc_mon_src_ip = NULL; - const char *s = smap_get(&nbrec_lb->ip_port_mappings, - backend->ip_str); - if (s) { - char *port_name = xstrdup(s); - char *p = strstr(port_name, ":"); - if (p) { - *p = 0; - p++; - op = ovn_port_find(ports, port_name); - svc_mon_src_ip = xstrdup(p); - } - free(port_name); - } - - backend_nb->op = op; - backend_nb->svc_mon_src_ip = svc_mon_src_ip; - } } static @@ -189,10 +162,7 @@ ovn_lb_get_hairpin_snat_ip(const struct uuid *lb_uuid, } struct ovn_northd_lb * -ovn_northd_lb_create(const struct nbrec_load_balancer *nbrec_lb, - struct hmap *ports, - void * (*ovn_port_find)(const struct hmap *ports, - const char *name)) +ovn_northd_lb_create(const struct nbrec_load_balancer *nbrec_lb) { struct ovn_northd_lb *lb = xzalloc(sizeof *lb); @@ -213,7 +183,7 @@ ovn_northd_lb_create(const struct nbrec_load_balancer *nbrec_lb, continue; } ovn_northd_lb_vip_init(lb_vip_nb, lb_vip, nbrec_lb, - node->key, node->value, ports, ovn_port_find); + node->key, node->value); n_vips++; } diff --git a/lib/lb.h b/lib/lb.h index 532cf9141..0486b3d89 100644 --- a/lib/lb.h +++ b/lib/lb.h @@ -76,10 +76,7 @@ struct ovn_northd_lb_backend { const struct sbrec_service_monitor *sbrec_monitor; }; -struct ovn_northd_lb *ovn_northd_lb_create( - const struct nbrec_load_balancer *, - struct hmap *ports, - void * (*ovn_port_find)(const struct hmap *ports, const char *name)); +struct ovn_northd_lb *ovn_northd_lb_create(const struct nbrec_load_balancer *); struct ovn_northd_lb * ovn_northd_lb_find(struct hmap *, const struct uuid *); void ovn_northd_lb_destroy(struct ovn_northd_lb *); void ovn_northd_lb_add_datapath(struct ovn_northd_lb *, diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index d872f6a3c..224ea9543 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -3279,56 +3279,72 @@ create_or_get_service_mon(struct northd_context *ctx, static void ovn_lb_svc_create(struct northd_context *ctx, struct ovn_northd_lb *lb, - struct hmap *monitor_map) + struct hmap *monitor_map, struct hmap *ports) { for (size_t i = 0; i < lb->n_vips; i++) { struct ovn_lb_vip *lb_vip = &lb->vips[i]; struct ovn_northd_lb_vip *lb_vip_nb = &lb->vips_nb[i]; - if (!lb_vip_nb->lb_health_check) { - continue; - } - for (size_t j = 0; j < lb_vip->n_backends; j++) { struct ovn_lb_backend *backend = &lb_vip->backends[j]; struct ovn_northd_lb_backend *backend_nb = &lb_vip_nb->backends_nb[j]; - if (backend_nb->op && backend_nb->svc_mon_src_ip) { - const char *protocol = lb->nlb->protocol; - if (!protocol || !protocol[0]) { - protocol = "tcp"; - } - backend_nb->health_check = true; - struct service_monitor_info *mon_info = - create_or_get_service_mon(ctx, monitor_map, - backend->ip_str, - backend_nb->op->nbsp->name, - backend->port, - protocol); - - ovs_assert(mon_info); - sbrec_service_monitor_set_options( - mon_info->sbrec_mon, &lb_vip_nb->lb_health_check->options); - struct eth_addr ea; - if (!mon_info->sbrec_mon->src_mac || - !eth_addr_from_string(mon_info->sbrec_mon->src_mac, &ea) || - !eth_addr_equals(ea, svc_monitor_mac_ea)) { - sbrec_service_monitor_set_src_mac(mon_info->sbrec_mon, - svc_monitor_mac); + struct ovn_port *op = NULL; + char *svc_mon_src_ip = NULL; + const char *s = smap_get(&lb->nlb->ip_port_mappings, + backend->ip_str); + if (s) { + char *port_name = xstrdup(s); + char *p = strstr(port_name, ":"); + if (p) { + *p = 0; + p++; + op = ovn_port_find(ports, port_name); + svc_mon_src_ip = xstrdup(p); } + free(port_name); + } - if (!mon_info->sbrec_mon->src_ip || - strcmp(mon_info->sbrec_mon->src_ip, - backend_nb->svc_mon_src_ip)) { - sbrec_service_monitor_set_src_ip( - mon_info->sbrec_mon, - backend_nb->svc_mon_src_ip); - } + backend_nb->op = op; + backend_nb->svc_mon_src_ip = svc_mon_src_ip; - backend_nb->sbrec_monitor = mon_info->sbrec_mon; - mon_info->required = true; + if (!lb_vip_nb->lb_health_check || !op || !svc_mon_src_ip) { + continue; + } + + const char *protocol = lb->nlb->protocol; + if (!protocol || !protocol[0]) { + protocol = "tcp"; + } + backend_nb->health_check = true; + struct service_monitor_info *mon_info = + create_or_get_service_mon(ctx, monitor_map, + backend->ip_str, + backend_nb->op->nbsp->name, + backend->port, + protocol); + ovs_assert(mon_info); + sbrec_service_monitor_set_options( + mon_info->sbrec_mon, &lb_vip_nb->lb_health_check->options); + struct eth_addr ea; + if (!mon_info->sbrec_mon->src_mac || + !eth_addr_from_string(mon_info->sbrec_mon->src_mac, &ea) || + !eth_addr_equals(ea, svc_monitor_mac_ea)) { + sbrec_service_monitor_set_src_mac(mon_info->sbrec_mon, + svc_monitor_mac); } + + if (!mon_info->sbrec_mon->src_ip || + strcmp(mon_info->sbrec_mon->src_ip, + backend_nb->svc_mon_src_ip)) { + sbrec_service_monitor_set_src_ip( + mon_info->sbrec_mon, + backend_nb->svc_mon_src_ip); + } + + backend_nb->sbrec_monitor = mon_info->sbrec_mon; + mon_info->required = true; } } } @@ -3393,32 +3409,17 @@ void build_lb_vip_actions(struct ovn_lb_vip *lb_vip, static void build_ovn_lbs(struct northd_context *ctx, struct hmap *datapaths, - struct hmap *ports, struct hmap *lbs) + struct hmap *lbs) { - hmap_init(lbs); - struct hmap monitor_map = HMAP_INITIALIZER(&monitor_map); + struct ovn_northd_lb *lb; - const struct sbrec_service_monitor *sbrec_mon; - SBREC_SERVICE_MONITOR_FOR_EACH (sbrec_mon, ctx->ovnsb_idl) { - uint32_t hash = sbrec_mon->port; - hash = hash_string(sbrec_mon->ip, hash); - hash = hash_string(sbrec_mon->logical_port, hash); - struct service_monitor_info *mon_info = xzalloc(sizeof *mon_info); - mon_info->sbrec_mon = sbrec_mon; - mon_info->required = false; - hmap_insert(&monitor_map, &mon_info->hmap_node, hash); - } + hmap_init(lbs); const struct nbrec_load_balancer *nbrec_lb; NBREC_LOAD_BALANCER_FOR_EACH (nbrec_lb, ctx->ovnnb_idl) { - struct ovn_northd_lb *lb = - ovn_northd_lb_create(nbrec_lb, ports, (void *)ovn_port_find); - hmap_insert(lbs, &lb->hmap_node, uuid_hash(&nbrec_lb->header_.uuid)); - } - - struct ovn_northd_lb *lb; - HMAP_FOR_EACH (lb, hmap_node, lbs) { - ovn_lb_svc_create(ctx, lb, &monitor_map); + struct ovn_northd_lb *lb_nb = ovn_northd_lb_create(nbrec_lb); + hmap_insert(lbs, &lb_nb->hmap_node, + uuid_hash(&nbrec_lb->header_.uuid)); } struct ovn_datapath *od; @@ -3510,6 +3511,29 @@ build_ovn_lbs(struct northd_context *ctx, struct hmap *datapaths, od->nbs->n_load_balancer); free(sbrec_lbs); } +} + +static void +build_ovn_lb_svcs(struct northd_context *ctx, struct hmap *ports, + struct hmap *lbs) +{ + struct hmap monitor_map = HMAP_INITIALIZER(&monitor_map); + + const struct sbrec_service_monitor *sbrec_mon; + SBREC_SERVICE_MONITOR_FOR_EACH (sbrec_mon, ctx->ovnsb_idl) { + uint32_t hash = sbrec_mon->port; + hash = hash_string(sbrec_mon->ip, hash); + hash = hash_string(sbrec_mon->logical_port, hash); + struct service_monitor_info *mon_info = xzalloc(sizeof *mon_info); + mon_info->sbrec_mon = sbrec_mon; + mon_info->required = false; + hmap_insert(&monitor_map, &mon_info->hmap_node, hash); + } + + struct ovn_northd_lb *lb; + HMAP_FOR_EACH (lb, hmap_node, lbs) { + ovn_lb_svc_create(ctx, lb, &monitor_map, ports); + } struct service_monitor_info *mon_info; HMAP_FOR_EACH_POP (mon_info, hmap_node, &monitor_map) { @@ -13322,8 +13346,9 @@ ovnnb_db_run(struct northd_context *ctx, "ignore_lsp_down", false); build_datapaths(ctx, datapaths, lr_list); + build_ovn_lbs(ctx, datapaths, &lbs); build_ports(ctx, sbrec_chassis_by_name, datapaths, ports); - build_ovn_lbs(ctx, datapaths, ports, &lbs); + build_ovn_lb_svcs(ctx, ports, &lbs); build_ipam(datapaths, ports); build_port_group_lswitches(ctx, &port_groups, ports); build_lrouter_groups(ports, lr_list); _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
