From patchwork Thu Nov 5 07:42:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1394768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CRb8f1thqz9sTD for ; Thu, 5 Nov 2020 18:42:41 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 3EF8D228D1; Thu, 5 Nov 2020 07:42:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DOhb7Xq6+q+7; Thu, 5 Nov 2020 07:42:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 487F72050D; Thu, 5 Nov 2020 07:42:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C3C3C0893; Thu, 5 Nov 2020 07:42:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 21F60C0889 for ; Thu, 5 Nov 2020 07:42:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id EFBFA20767 for ; Thu, 5 Nov 2020 07:42:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JRYBzfaSArif for ; Thu, 5 Nov 2020 07:42:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by silver.osuosl.org (Postfix) with ESMTPS id 32E632050D for ; Thu, 5 Nov 2020 07:42:31 +0000 (UTC) X-Originating-IP: 115.99.213.209 Received: from nusiddiq.home.org.home.org (unknown [115.99.213.209]) (Authenticated sender: numans@ovn.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id CBAB2FF806; Thu, 5 Nov 2020 07:42:23 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Thu, 5 Nov 2020 13:12:14 +0530 Message-Id: <20201105074214.3793878-1-numans@ovn.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201105074146.3793721-1-numans@ovn.org> References: <20201105074146.3793721-1-numans@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn v3 1/7] Add new table Load_Balancer in Southbound database. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique This patch adds a new table 'Load_Balancer' in SB DB and syncs the Load_Balancer table rows from NB DB to SB DB. An upcoming patch will make use of this table for handling the load balancer hairpin traffic. Signed-off-by: Numan Siddique --- northd/ovn-northd.c | 146 ++++++++++++++++++++++++++++++++++++++++++ ovn-sb.ovsschema | 27 +++++++- ovn-sb.xml | 45 +++++++++++++ tests/ovn-northd.at | 87 +++++++++++++++++++++++++ utilities/ovn-sbctl.c | 3 + 5 files changed, 306 insertions(+), 2 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 684c2bd478..6bbe93befb 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -11872,6 +11872,141 @@ sync_dns_entries(struct northd_context *ctx, struct hmap *datapaths) } hmap_destroy(&dns_map); } + +/* + * struct 'sync_lb_info' is used to sync the load balancer records between + * OVN Northbound db and Southbound db. + */ +struct sync_lb_info { + struct hmap_node hmap_node; + const struct nbrec_load_balancer *nlb; /* LB record in the NB db. */ + const struct sbrec_load_balancer *slb; /* LB record in the SB db. */ + + /* Datapaths to which the LB entry is associated with it. */ + const struct sbrec_datapath_binding **sbs; + size_t n_sbs; +}; + +static struct sync_lb_info * +sync_lb_info_find(struct hmap *sync_lb_map, struct uuid *uuid) +{ + struct sync_lb_info *lb_info; + size_t hash = uuid_hash(uuid); + HMAP_FOR_EACH_WITH_HASH (lb_info, hmap_node, hash, sync_lb_map) { + if (uuid_equals(&lb_info->nlb->header_.uuid, uuid)) { + return lb_info; + } + } + + return NULL; +} + +static void +sync_lb_entries(struct northd_context *ctx, struct hmap *datapaths) +{ + struct hmap lb_map = HMAP_INITIALIZER(&lb_map); + struct ovn_datapath *od; + + /* Build a local hmap of lbs from the NB db. */ + HMAP_FOR_EACH (od, key_node, datapaths) { + if (!od->nbs || !od->nbs->n_load_balancer) { + continue; + } + + for (size_t i = 0; i < od->nbs->n_load_balancer; i++) { + struct sync_lb_info *lb_info = + sync_lb_info_find( + &lb_map, &od->nbs->load_balancer[i]->header_.uuid); + + if (!lb_info) { + size_t hash = uuid_hash( + &od->nbs->load_balancer[i]->header_.uuid); + lb_info = xzalloc(sizeof *lb_info);; + lb_info->nlb = od->nbs->load_balancer[i]; + hmap_insert(&lb_map, &lb_info->hmap_node, hash); + } + + lb_info->n_sbs++; + lb_info->sbs = xrealloc(lb_info->sbs, + lb_info->n_sbs * sizeof *lb_info->sbs); + lb_info->sbs[lb_info->n_sbs - 1] = od->sb; + } + } + + /* Delete any stale SB load balancer rows. */ + const struct sbrec_load_balancer *sbrec_lb, *next; + SBREC_LOAD_BALANCER_FOR_EACH_SAFE (sbrec_lb, next, ctx->ovnsb_idl) { + const char *nb_lb_uuid = smap_get(&sbrec_lb->external_ids, "lb_id"); + struct uuid lb_uuid; + if (!nb_lb_uuid || !uuid_from_string(&lb_uuid, nb_lb_uuid)) { + sbrec_load_balancer_delete(sbrec_lb); + continue; + } + + struct sync_lb_info *lb_info = sync_lb_info_find(&lb_map, &lb_uuid); + if (lb_info) { + lb_info->slb = sbrec_lb; + } else { + sbrec_load_balancer_delete(sbrec_lb); + } + } + + /* Create SB Load balancer records if not present and sync + * the SB load balancer columns. */ + struct sync_lb_info *lb_info; + HMAP_FOR_EACH (lb_info, hmap_node, &lb_map) { + if (!lb_info->slb) { + sbrec_lb = sbrec_load_balancer_insert(ctx->ovnsb_txn); + lb_info->slb = sbrec_lb; + char *lb_id = xasprintf( + UUID_FMT, UUID_ARGS(&lb_info->nlb->header_.uuid)); + const struct smap external_ids = + SMAP_CONST1(&external_ids, "lb_id", lb_id); + sbrec_load_balancer_set_external_ids(sbrec_lb, &external_ids); + free(lb_id); + } + + /* Set the datapaths and other columns. If nothing has changed, then + * this will be a no-op. + */ + sbrec_load_balancer_set_datapaths( + lb_info->slb, + (struct sbrec_datapath_binding **)lb_info->sbs, + lb_info->n_sbs); + + sbrec_load_balancer_set_name(lb_info->slb, lb_info->nlb->name); + sbrec_load_balancer_set_vips(lb_info->slb, &lb_info->nlb->vips); + sbrec_load_balancer_set_protocol(lb_info->slb, lb_info->nlb->protocol); + } + + /* Set the list of associated load balanacers to a logical switch + * datapath binding in the SB DB. */ + HMAP_FOR_EACH (od, key_node, datapaths) { + if (!od->nbs || !od->nbs->n_load_balancer) { + continue; + } + + const struct sbrec_load_balancer **lbs = + xmalloc(od->nbs->n_load_balancer * sizeof *lbs); + for (size_t i = 0; i < od->nbs->n_load_balancer; i++) { + lb_info = sync_lb_info_find( + &lb_map, &od->nbs->load_balancer[i]->header_.uuid); + ovs_assert(lb_info); + lbs[i] = lb_info->slb; + } + + sbrec_datapath_binding_set_load_balancers( + od->sb, (struct sbrec_load_balancer **)lbs, + od->nbs->n_load_balancer); + free(lbs); + } + + HMAP_FOR_EACH_POP (lb_info, hmap_node, &lb_map) { + free(lb_info->sbs); + free(lb_info); + } + hmap_destroy(&lb_map); +} static void destroy_datapaths_and_ports(struct hmap *datapaths, struct hmap *ports, @@ -12243,6 +12378,7 @@ ovnnb_db_run(struct northd_context *ctx, sync_port_groups(ctx, &port_groups); sync_meters(ctx); sync_dns_entries(ctx, datapaths); + sync_lb_entries(ctx, datapaths); destroy_ovn_lbs(&lbs); hmap_destroy(&lbs); @@ -13003,6 +13139,8 @@ main(int argc, char *argv[]) ovsdb_idl_add_table(ovnsb_idl_loop.idl, &sbrec_table_datapath_binding); add_column_noalert(ovnsb_idl_loop.idl, &sbrec_datapath_binding_col_tunnel_key); + add_column_noalert(ovnsb_idl_loop.idl, + &sbrec_datapath_binding_col_load_balancers); add_column_noalert(ovnsb_idl_loop.idl, &sbrec_datapath_binding_col_external_ids); @@ -13170,6 +13308,14 @@ main(int argc, char *argv[]) add_column_noalert(ovnsb_idl_loop.idl, &sbrec_service_monitor_col_external_ids); + ovsdb_idl_add_table(ovnsb_idl_loop.idl, &sbrec_table_load_balancer); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_load_balancer_col_datapaths); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_load_balancer_col_name); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_load_balancer_col_vips); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_load_balancer_col_protocol); + add_column_noalert(ovnsb_idl_loop.idl, + &sbrec_load_balancer_col_external_ids); + struct ovsdb_idl_index *sbrec_chassis_by_name = chassis_index_create(ovnsb_idl_loop.idl); diff --git a/ovn-sb.ovsschema b/ovn-sb.ovsschema index d1c506a22c..7db6c6a4dd 100644 --- a/ovn-sb.ovsschema +++ b/ovn-sb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Southbound", - "version": "2.10.0", - "cksum": "2548342632 22615", + "version": "2.11.0", + "cksum": "1470439925 23814", "tables": { "SB_Global": { "columns": { @@ -152,6 +152,11 @@ "type": {"key": {"type": "integer", "minInteger": 1, "maxInteger": 16777215}}}, + "load_balancers": {"type": {"key": {"type": "uuid", + "refTable": "Load_Balancer", + "refType": "weak"}, + "min": 0, + "max": "unlimited"}}, "external_ids": { "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"}}}, @@ -447,6 +452,24 @@ "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"}}}, "indexes": [["logical_port", "ip", "port", "protocol"]], + "isRoot": true}, + "Load_Balancer": { + "columns": { + "name": {"type": "string"}, + "vips": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}, + "protocol": { + "type": {"key": {"type": "string", + "enum": ["set", ["tcp", "udp", "sctp"]]}, + "min": 0, "max": 1}}, + "datapaths": { + "type": {"key": {"type": "uuid", + "refTable": "Datapath_Binding"}, + "min": 1, "max": "unlimited"}}, + "external_ids": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}}, "isRoot": true} } } diff --git a/ovn-sb.xml b/ovn-sb.xml index b1480f2186..bdd41c1f97 100644 --- a/ovn-sb.xml +++ b/ovn-sb.xml @@ -2497,6 +2497,12 @@ tcp.flags = RST; constructed for each supported encapsulation. + +

+ Load balancers associated with the datapath. +

+
+

Each row in is associated with some @@ -4126,4 +4132,43 @@ tcp.flags = RST; + + +

+ Each row represents a load balancer. +

+ + + A name for the load balancer. This name has no special meaning or + purpose other than to provide convenience for human interaction with + the ovn-nb database. + + + + A map of virtual IP addresses (and an optional port number with + : as a separator) associated with this load balancer and + their corresponding endpoint IP addresses (and optional port numbers + with : as separators) separated by commas. + + + +

+ Valid protocols are tcp, udp, or + sctp. This column is useful when a port number is + provided as part of the vips column. If this column is + empty and a port number is provided as part of vips + column, OVN assumes the protocol to be tcp. +

+
+ + + Datapaths to which this load balancer applies to. + + + + + See External IDs at the beginning of this document. + + +
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index 0bf20c1a70..872e88c9a4 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -1911,4 +1911,91 @@ AT_CHECK( [ovn-nbctl --wait=sb set logical-switch-port lsp01 options:requested-tnl-key=2]) get_tunnel_keys AT_CHECK([test $lsp02 = 3 && test $ls1 = 123]) + +AT_CLEANUP + +AT_SETUP([ovn -- NB to SB load balancer sync]) +ovn_start + +check ovn-nbctl --wait=hv lb-add lb0 10.0.0.10:80 10.0.0.4:8080 +check_row_count nb:load_balancer 1 + +echo +echo "__file__:__line__: Check that there are no SB load balancer rows." +check_row_count sb:load_balancer 0 + +check ovn-nbctl ls-add sw0 +check ovn-nbctl --wait=hv ls-lb-add sw0 lb0 +sw0_sb_uuid=$(fetch_column datapath_binding _uuid external_ids:name=sw0) + +echo +echo "__file__:__line__: Check that there are is SB load balancer row for lb0." +check_row_count sb:load_balancer 1 +check_column "10.0.0.10:80=10.0.0.4:8080 tcp" sb:load_balancer vips,protocol name=lb0 + +lb0_uuid=$(fetch_column sb:load_balancer _uuid name=lb0) + +echo +echo "__file__:__line__: Check that SB lb0 has sw0 in datapaths column." + +check_column "$sw0_sb_uuid" sb:load_balancer datapaths name=lb0 +check_column "$lb0_uuid" sb:datapath_binding load_balancers external_ids:name=sw0 + +check ovn-nbctl --wait=sb set load_balancer . vips:"10.0.0.20\:90"="20.0.0.4:8080,30.0.0.4:8080" + +echo +echo "__file__:__line__: Check that SB lb0 has vips and protocol columns are set properly." + +check_column "10.0.0.10:80=10.0.0.4:8080 10.0.0.20:90=20.0.0.4:8080,30.0.0.4:8080 tcp" \ +sb:load_balancer vips,protocol name=lb0 + +check ovn-nbctl lr-add lr0 +check ovn-nbctl --wait=sb lr-lb-add lr0 lb0 + +echo +echo "__file__:__line__: Check that SB lb0 has only sw0 in datapaths column." +check_column "$sw0_sb_uuid" sb:load_balancer datapaths name=lb0 + +check ovn-nbctl ls-add sw1 +check ovn-nbctl --wait=sb ls-lb-add sw1 lb0 +sw1_sb_uuid=$(fetch_column datapath_binding _uuid external_ids:name=sw1) + +echo +echo "__file__:__line__: Check that SB lb0 has sw0 and sw1 in datapaths column." +check_column "$sw0_sb_uuid $sw1_sb_uuid" sb:load_balancer datapaths name=lb0 +check_column "$lb0_uuid" sb:datapath_binding load_balancers external_ids:name=sw1 + +check ovn-nbctl --wait=sb lb-add lb1 10.0.0.30:80 20.0.0.50:8080 udp +check_row_count sb:load_balancer 1 + +check ovn-nbctl --wait=sb lr-lb-add lr0 lb1 +check_row_count sb:load_balancer 1 + +echo +echo "__file__:__line__: Associate lb1 to sw1 and check that lb1 is created in SB DB." + +check ovn-nbctl --wait=sb ls-lb-add sw1 lb1 +check_row_count sb:load_balancer 2 + +echo +echo "__file__:__line__: Check that SB lb1 has vips and protocol columns are set properly." +check_column "10.0.0.30:80=20.0.0.50:8080 udp" sb:load_balancer vips,protocol name=lb1 + +lb1_uuid=$(fetch_column sb:load_balancer _uuid name=lb1) + +echo +echo "__file__:__line__: Check that SB lb1 has sw1 in datapaths column." + +check_column "$sw1_sb_uuid" sb:load_balancer datapaths name=lb1 + +echo +echo "__file__:__line__: check that datapath sw1 has lb0 and lb1 set in the load_balancers column." +check_column "$lb0_uuid $lb1_uuid" sb:datapath_binding load_balancers external_ids:name=sw1 + +echo +echo "__file__:__line__: Delete load balancer lb1 an check that datapath sw1's load_balancers are updated accordingly." + +ovn-nbctl --wait=sb lb-del lb1 +check_column "$lb0_uuid" sb:datapath_binding load_balancers external_ids:name=sw1 + AT_CLEANUP diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c index 85e448ec04..00c112c7e5 100644 --- a/utilities/ovn-sbctl.c +++ b/utilities/ovn-sbctl.c @@ -1441,6 +1441,9 @@ static const struct ctl_table_class tables[SBREC_N_TABLES] = { [SBREC_TABLE_GATEWAY_CHASSIS].row_ids[0] = {&sbrec_gateway_chassis_col_name, NULL, NULL}, + + [SBREC_TABLE_LOAD_BALANCER].row_ids[0] + = {&sbrec_load_balancer_col_name, NULL, NULL}, };