From patchwork Sat May 13 00:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Tt0VVSz20KD for ; Sat, 13 May 2023 10:04:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 32E8383FEE; Sat, 13 May 2023 00:04:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 32E8383FEE X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sQDJj4af8S_H; Sat, 13 May 2023 00:04:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 7068983FC4; Sat, 13 May 2023 00:04:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7068983FC4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3CE3CC008E; Sat, 13 May 2023 00:04:27 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id F3349C0036 for ; Sat, 13 May 2023 00:04:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id C0EE660D89 for ; Sat, 13 May 2023 00:04:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org C0EE660D89 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nCY3jp2Cp4BK for ; Sat, 13 May 2023 00:04:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3265F60B31 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3265F60B31 for ; Sat, 13 May 2023 00:04:22 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id BE6DB1C0003; Sat, 13 May 2023 00:04:20 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:43 -0700 Message-Id: <20230513000356.2475960-2-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 01/14] northd: Remove bfd_connections from northd_data. 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" bfd_connections isn't related to the I-P engine node "northd". So move it from the northd_data to a local variable of en_lflow_run(). Signed-off-by: Han Zhou --- northd/en-lflow.c | 9 ++++++--- northd/northd.c | 2 -- northd/northd.h | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/northd/en-lflow.c b/northd/en-lflow.c index c1951c8c8c20..bed7bb001e20 100644 --- a/northd/en-lflow.c +++ b/northd/en-lflow.c @@ -38,6 +38,8 @@ void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) struct northd_data *northd_data = engine_get_input_data("northd", node); + struct hmap bfd_connections = HMAP_INITIALIZER(&bfd_connections); + lflow_input.nbrec_bfd_table = EN_OVSDB_GET(engine_get_input("NB_bfd", node)); lflow_input.sbrec_bfd_table = @@ -61,7 +63,7 @@ void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) lflow_input.port_groups = &northd_data->port_groups; lflow_input.meter_groups = &northd_data->meter_groups; lflow_input.lbs = &northd_data->lbs; - lflow_input.bfd_connections = &northd_data->bfd_connections; + lflow_input.bfd_connections = &bfd_connections; lflow_input.features = &northd_data->features; lflow_input.ovn_internal_version_changed = northd_data->ovn_internal_version_changed; @@ -70,11 +72,12 @@ void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) build_bfd_table(eng_ctx->ovnsb_idl_txn, lflow_input.nbrec_bfd_table, lflow_input.sbrec_bfd_table, - &northd_data->bfd_connections, + &bfd_connections, &northd_data->lr_ports); build_lflows(&lflow_input, eng_ctx->ovnsb_idl_txn); bfd_cleanup_connections(lflow_input.nbrec_bfd_table, - &northd_data->bfd_connections); + &bfd_connections); + hmap_destroy(&bfd_connections); stopwatch_stop(BUILD_LFLOWS_STOPWATCH_NAME, time_msec()); engine_set_node_state(node, EN_UPDATED); diff --git a/northd/northd.c b/northd/northd.c index 25df0957eaa2..fdd8a21138ef 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -16473,7 +16473,6 @@ northd_init(struct northd_data *data) shash_init(&data->meter_groups); hmap_init(&data->lbs); hmap_init(&data->lb_groups); - hmap_init(&data->bfd_connections); ovs_list_init(&data->lr_list); data->features = (struct chassis_features) { .ct_no_masked_label = true, @@ -16504,7 +16503,6 @@ northd_destroy(struct northd_data *data) } hmap_destroy(&data->port_groups); - hmap_destroy(&data->bfd_connections); struct shash_node *node; SHASH_FOR_EACH_SAFE (node, &data->meter_groups) { diff --git a/northd/northd.h b/northd/northd.h index a503f4a6675a..385c8adce4ea 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -94,7 +94,6 @@ struct northd_data { struct shash meter_groups; struct hmap lbs; struct hmap lb_groups; - struct hmap bfd_connections; struct ovs_list lr_list; bool ovn_internal_version_changed; struct chassis_features features; From patchwork Sat May 13 00:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Tx4Mp9z20KD for ; Sat, 13 May 2023 10:04:37 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 903A342E18; Sat, 13 May 2023 00:04:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 903A342E18 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ivTNGNw1Pg9Y; Sat, 13 May 2023 00:04:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id D74FD42E1F; Sat, 13 May 2023 00:04:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org D74FD42E1F Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D1008C0092; Sat, 13 May 2023 00:04:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id D2FAAC002A for ; Sat, 13 May 2023 00:04:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id AE8FF60B31 for ; Sat, 13 May 2023 00:04:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org AE8FF60B31 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aeb4ZmPsZ9NJ for ; Sat, 13 May 2023 00:04:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7C7E360C16 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7C7E360C16 for ; Sat, 13 May 2023 00:04:24 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 1BE961C0002; Sat, 13 May 2023 00:04:21 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:44 -0700 Message-Id: <20230513000356.2475960-3-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 02/14] northd: Enable persistence of logical flows between engine runs. 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" This patch ensures logical flows remain persistent between engine runs, given there are no changes. In case of any change, it will deconstruct and reconstruct the hmap during recompute. This functionality is needed for future incremental processing, particularly when logical flows need to be removed. Signed-off-by: Han Zhou --- northd/en-lflow.c | 16 ++++++++++---- northd/northd.c | 55 +++++++++++++++++++++++++++++++---------------- northd/northd.h | 13 +++++++++-- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/northd/en-lflow.c b/northd/en-lflow.c index bed7bb001e20..081ec7c353ed 100644 --- a/northd/en-lflow.c +++ b/northd/en-lflow.c @@ -30,7 +30,7 @@ VLOG_DEFINE_THIS_MODULE(en_lflow); -void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) +void en_lflow_run(struct engine_node *node, void *data) { const struct engine_context *eng_ctx = engine_get_context(); @@ -68,13 +68,17 @@ void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) lflow_input.ovn_internal_version_changed = northd_data->ovn_internal_version_changed; + struct lflow_data *lflow_data = data; + lflow_data_destroy(lflow_data); + lflow_data_init(lflow_data); + stopwatch_start(BUILD_LFLOWS_STOPWATCH_NAME, time_msec()); build_bfd_table(eng_ctx->ovnsb_idl_txn, lflow_input.nbrec_bfd_table, lflow_input.sbrec_bfd_table, &bfd_connections, &northd_data->lr_ports); - build_lflows(&lflow_input, eng_ctx->ovnsb_idl_txn); + build_lflows(eng_ctx->ovnsb_idl_txn, &lflow_input, &lflow_data->lflows); bfd_cleanup_connections(lflow_input.nbrec_bfd_table, &bfd_connections); hmap_destroy(&bfd_connections); @@ -82,12 +86,16 @@ void en_lflow_run(struct engine_node *node, void *data OVS_UNUSED) engine_set_node_state(node, EN_UPDATED); } + void *en_lflow_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg OVS_UNUSED) { - return NULL; + struct lflow_data *data = xmalloc(sizeof *data); + lflow_data_init(data); + return data; } -void en_lflow_cleanup(void *data OVS_UNUSED) +void en_lflow_cleanup(void *data) { + lflow_data_destroy(data); } diff --git a/northd/northd.c b/northd/northd.c index fdd8a21138ef..3214b86fc589 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -15202,6 +15202,22 @@ ovn_sb_set_lflow_logical_dp_group( static ssize_t max_seen_lflow_size = 128; +void +lflow_data_init(struct lflow_data *data) +{ + fast_hmap_size_for(&data->lflows, max_seen_lflow_size); +} + +void +lflow_data_destroy(struct lflow_data *data) +{ + struct ovn_lflow *lflow; + HMAP_FOR_EACH_SAFE (lflow, hmap_node, &data->lflows) { + ovn_lflow_destroy(&data->lflows, lflow); + } + hmap_destroy(&data->lflows); +} + void run_update_worker_pool(int n_threads) { /* If number of threads has been updated (or initially set), @@ -15231,10 +15247,10 @@ build_mcast_groups(const struct sbrec_igmp_group_table *sbrec_igmp_group_table, /* Updates the Logical_Flow and Multicast_Group tables in the OVN_SB database, * constructing their contents based on the OVN_NB database. */ -void build_lflows(struct lflow_input *input_data, - struct ovsdb_idl_txn *ovnsb_txn) +void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, + struct lflow_input *input_data, + struct hmap *lflows) { - struct hmap lflows; struct hmap mcast_groups; struct hmap igmp_groups; @@ -15244,13 +15260,11 @@ void build_lflows(struct lflow_input *input_data, input_data->ls_ports, input_data->lr_ports, &mcast_groups, &igmp_groups); - fast_hmap_size_for(&lflows, max_seen_lflow_size); - build_lswitch_and_lrouter_flows(input_data->ls_datapaths, input_data->lr_datapaths, input_data->ls_ports, input_data->lr_ports, - input_data->port_groups, &lflows, + input_data->port_groups, lflows, &mcast_groups, &igmp_groups, input_data->meter_groups, input_data->lbs, input_data->bfd_connections, @@ -15263,10 +15277,10 @@ void build_lflows(struct lflow_input *input_data, /* Parallel build may result in a suboptimal hash. Resize the * hash to a correct size before doing lookups */ - hmap_expand(&lflows); + hmap_expand(lflows); - if (hmap_count(&lflows) > max_seen_lflow_size) { - max_seen_lflow_size = hmap_count(&lflows); + if (hmap_count(lflows) > max_seen_lflow_size) { + max_seen_lflow_size = hmap_count(lflows); } stopwatch_start(LFLOWS_DP_GROUPS_STOPWATCH_NAME, time_msec()); @@ -15284,7 +15298,7 @@ void build_lflows(struct lflow_input *input_data, fast_hmap_size_for(&single_dp_lflows, max_seen_lflow_size); struct ovn_lflow *lflow; - HMAP_FOR_EACH_SAFE (lflow, hmap_node, &lflows) { + HMAP_FOR_EACH_SAFE (lflow, hmap_node, lflows) { struct ovn_dp_group *dpg; uint32_t hash, n_ods; @@ -15317,7 +15331,7 @@ void build_lflows(struct lflow_input *input_data, /* Logical flow should be re-hashed to allow lookups. */ hash = hmap_node_hash(&lflow->hmap_node); /* Remove from lflows. */ - hmap_remove(&lflows, &lflow->hmap_node); + hmap_remove(lflows, &lflow->hmap_node); hash = ovn_logical_flow_hash_datapath(&lflow->od->sb->header_.uuid, hash); /* Add to single_dp_lflows. */ @@ -15338,13 +15352,14 @@ void build_lflows(struct lflow_input *input_data, /* Merge multiple and single dp hashes. */ - fast_hmap_merge(&lflows, &single_dp_lflows); + fast_hmap_merge(lflows, &single_dp_lflows); hmap_destroy(&single_dp_lflows); stopwatch_stop(LFLOWS_DP_GROUPS_STOPWATCH_NAME, time_msec()); stopwatch_start(LFLOWS_TO_SB_STOPWATCH_NAME, time_msec()); + struct hmap lflows_temp = HMAP_INITIALIZER(&lflows_temp); /* Push changes to the Logical_Flow table to database. */ const struct sbrec_logical_flow *sbflow; SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_SAFE (sbflow, @@ -15387,7 +15402,7 @@ void build_lflows(struct lflow_input *input_data, = !strcmp(sbflow->pipeline, "ingress") ? P_IN : P_OUT; lflow = ovn_lflow_find( - &lflows, dp_group ? NULL : logical_datapath_od, + lflows, dp_group ? NULL : logical_datapath_od, ovn_stage_build(ovn_datapath_get_type(logical_datapath_od), pipeline, sbflow->table_id), sbflow->priority, sbflow->match, sbflow->actions, @@ -15482,13 +15497,15 @@ void build_lflows(struct lflow_input *input_data, } /* This lflow updated. Not needed anymore. */ - ovn_lflow_destroy(&lflows, lflow); + hmap_remove(lflows, &lflow->hmap_node); + hmap_insert(&lflows_temp, &lflow->hmap_node, + hmap_node_hash(&lflow->hmap_node)); } else { sbrec_logical_flow_delete(sbflow); } } - HMAP_FOR_EACH_SAFE (lflow, hmap_node, &lflows) { + HMAP_FOR_EACH_SAFE (lflow, hmap_node, lflows) { const char *pipeline = ovn_stage_get_pipeline_name(lflow->stage); uint8_t table = ovn_stage_get_table(lflow->stage); @@ -15543,10 +15560,12 @@ void build_lflows(struct lflow_input *input_data, } sbrec_logical_flow_set_external_ids(sbflow, &ids); smap_destroy(&ids); - - ovn_lflow_destroy(&lflows, lflow); + hmap_remove(lflows, &lflow->hmap_node); + hmap_insert(&lflows_temp, &lflow->hmap_node, + hmap_node_hash(&lflow->hmap_node)); } - hmap_destroy(&lflows); + hmap_swap(lflows, &lflows_temp); + hmap_destroy(&lflows_temp); stopwatch_stop(LFLOWS_TO_SB_STOPWATCH_NAME, time_msec()); struct ovn_dp_group *dpg; diff --git a/northd/northd.h b/northd/northd.h index 385c8adce4ea..dc630b488410 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -99,6 +99,13 @@ struct northd_data { struct chassis_features features; }; +struct lflow_data { + struct hmap lflows; +}; + +void lflow_data_init(struct lflow_data *); +void lflow_data_destroy(struct lflow_data *); + struct lflow_input { /* Northbound table references */ const struct nbrec_bfd_table *nbrec_bfd_table; @@ -294,8 +301,10 @@ void northd_destroy(struct northd_data *data); void northd_init(struct northd_data *data); void northd_indices_create(struct northd_data *data, struct ovsdb_idl *ovnsb_idl); -void build_lflows(struct lflow_input *input_data, - struct ovsdb_idl_txn *ovnsb_txn); +void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, + struct lflow_input *input_data, + struct hmap *lflows); + void build_bfd_table(struct ovsdb_idl_txn *ovnsb_txn, const struct nbrec_bfd_table *, const struct sbrec_bfd_table *, From patchwork Sat May 13 00:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5V051T5z20dF for ; Sat, 13 May 2023 10:04:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id CF16042E1F; Sat, 13 May 2023 00:04:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CF16042E1F X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4JnUPDsY5lzD; Sat, 13 May 2023 00:04:33 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 444DC4299A; Sat, 13 May 2023 00:04:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 444DC4299A Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 97FCEC0096; Sat, 13 May 2023 00:04:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01941C002A for ; Sat, 13 May 2023 00:04:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9D84440573 for ; Sat, 13 May 2023 00:04:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 9D84440573 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Cw5nbhkNA968 for ; Sat, 13 May 2023 00:04:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org D5B9D400C4 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp2.osuosl.org (Postfix) with ESMTPS id D5B9D400C4 for ; Sat, 13 May 2023 00:04:25 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 91D3B1C0004; Sat, 13 May 2023 00:04:23 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:45 -0700 Message-Id: <20230513000356.2475960-4-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 03/14] inc-proc-eng.h: Refactor I-P engine node macros. 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" Refactor so that ENGINE_NODE_WITH_CLEAR_TRACK_DATA_IS_VALID can be used outside of functions. Signed-off-by: Han Zhou --- lib/inc-proc-eng.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/inc-proc-eng.h b/lib/inc-proc-eng.h index 5f515f1eaf50..c7e45e73972e 100644 --- a/lib/inc-proc-eng.h +++ b/lib/inc-proc-eng.h @@ -387,7 +387,7 @@ void engine_ovsdb_node_add_index(struct engine_node *, const char *name, struct ovsdb_idl_index *); /* Macro to define an engine node. */ -#define ENGINE_NODE_DEF(NAME, NAME_STR) \ +#define ENGINE_NODE_DEF(NAME, NAME_STR, CLEAR_TRACKED_DATA, IS_VALID) \ struct engine_node en_##NAME = { \ .name = NAME_STR, \ .data = NULL, \ @@ -395,21 +395,20 @@ void engine_ovsdb_node_add_index(struct engine_node *, const char *name, .init = en_##NAME##_init, \ .run = en_##NAME##_run, \ .cleanup = en_##NAME##_cleanup, \ - .is_valid = NULL, \ - .clear_tracked_data = NULL, \ + .is_valid = IS_VALID, \ + .clear_tracked_data = CLEAR_TRACKED_DATA, \ }; -#define ENGINE_NODE_WITH_CLEAR_TRACK_DATA_IS_VALID(NAME, NAME_STR) \ - ENGINE_NODE(NAME, NAME_STR) \ - en_##NAME.clear_tracked_data = en_##NAME##_clear_tracked_data; \ - en_##NAME.is_valid = en_##NAME##_is_valid; - #define ENGINE_NODE(NAME, NAME_STR) \ - ENGINE_NODE_DEF(NAME, NAME_STR) + ENGINE_NODE_DEF(NAME, NAME_STR, NULL, NULL) #define ENGINE_NODE_WITH_CLEAR_TRACK_DATA(NAME, NAME_STR) \ - ENGINE_NODE(NAME, NAME_STR) \ - en_##NAME.clear_tracked_data = en_##NAME##_clear_tracked_data; + ENGINE_NODE_DEF(NAME, NAME_STR, en_##NAME##_clear_tracked_data, NULL) + +#define ENGINE_NODE_WITH_CLEAR_TRACK_DATA_IS_VALID(NAME, NAME_STR) \ + ENGINE_NODE_DEF(NAME, NAME_STR, \ + en_##NAME##_clear_tracked_data, \ + en_##NAME##_is_valid) /* Macro to define member functions of an engine node which represents * a table of OVSDB */ From patchwork Sat May 13 00:03:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5V03ydVz20KD for ; Sat, 13 May 2023 10:04:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id ED76F42E3B; Sat, 13 May 2023 00:04:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org ED76F42E3B X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hQ4jvaFFRvNV; Sat, 13 May 2023 00:04:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0B71742BC4; Sat, 13 May 2023 00:04:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0B71742BC4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7CEC8C008E; Sat, 13 May 2023 00:04:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3C555C0091 for ; Sat, 13 May 2023 00:04:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 09BBC83F87 for ; Sat, 13 May 2023 00:04:28 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 09BBC83F87 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9kUrv6w5167w for ; Sat, 13 May 2023 00:04:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 38AF983F7E Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.osuosl.org (Postfix) with ESMTPS id 38AF983F7E for ; Sat, 13 May 2023 00:04:27 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id DF5EE1C0003; Sat, 13 May 2023 00:04:24 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:46 -0700 Message-Id: <20230513000356.2475960-5-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 04/14] ovn.at: Fix test case: delete mac bindings. 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" MAC_Binding table is to store neighbour cache for logical router datapaths to resolve unknown IP addresses to MAC. The datapath field is always logical router and the logical_port feild is always logical router port. The test case used logical switch and logical switch ports by mistake. Correct it to use logical router and logical router ports. Signed-off-by: Han Zhou --- tests/ovn.at | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index 2ba7c7ce52c0..ed5b10589194 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -9265,23 +9265,21 @@ sim_add hv1 as hv1 ovs-vsctl -- add-br br-phys ovn_attach n1 br-phys 192.168.0.1 -# Create logical switch ls0 -ovn-nbctl ls-add ls0 -# Create ports lp0, lp1 in ls0 -ovn-nbctl lsp-add ls0 lp0 -ovn-nbctl lsp-add ls0 lp1 -ovn-nbctl lsp-set-addresses lp0 "f0:00:00:00:00:01 192.168.0.1" -ovn-nbctl lsp-set-addresses lp1 "f0:00:00:00:00:02 192.168.0.2" +# Create logical router lr0 +ovn-nbctl lr-add lr0 +# Create ports lrp0, lrp1 in lr0 +ovn-nbctl lrp-add lr0 lrp0 f0:00:00:00:00:01 192.168.0.1/24 +ovn-nbctl lrp-add lr0 lrp1 f0:00:00:00:00:02 192.168.1.1/24 dp_uuid=$(fetch_column Datapath_Binding _uuid) -ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lp0 mac="mac1" -ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lp1 mac="mac2" +ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lrp0 mac="mac1" +ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lrp1 mac="mac2" ovn-sbctl find MAC_Binding -# Delete port lp0 and check that its MAC_Binding is deleted. -ovn-nbctl lsp-del lp0 +# Delete port lrp0 and check that its MAC_Binding is deleted. +ovn-nbctl lrp-del lrp0 ovn-sbctl find MAC_Binding -wait_row_count MAC_Binding 0 logical_port=lp0 -# Delete logical switch ls0 and check that its MAC_Binding is deleted. -ovn-nbctl ls-del ls0 +wait_row_count MAC_Binding 0 logical_port=lrp0 +# Delete logical switch lr0 and check that its MAC_Binding is deleted. +ovn-nbctl lr-del lr0 ovn-sbctl find MAC_Binding wait_row_count MAC_Binding 0 From patchwork Sat May 13 00:03:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5V21NNBz20KD for ; Sat, 13 May 2023 10:04:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id F08D1702C7; Sat, 13 May 2023 00:04:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org F08D1702C7 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id siaKjwSCyOU4; Sat, 13 May 2023 00:04:37 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 6DC6C60F0F; Sat, 13 May 2023 00:04:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6DC6C60F0F Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5F33AC0090; Sat, 13 May 2023 00:04:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6BD4DC009E for ; Sat, 13 May 2023 00:04:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4035060EA6 for ; Sat, 13 May 2023 00:04:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4035060EA6 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aoUorVin-EI3 for ; Sat, 13 May 2023 00:04:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A353A60F19 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp3.osuosl.org (Postfix) with ESMTPS id A353A60F19 for ; Sat, 13 May 2023 00:04:28 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 3677C1C0005; Sat, 13 May 2023 00:04:25 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:47 -0700 Message-Id: <20230513000356.2475960-6-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 05/14] northd: Avoid triggering unnecesary recompute for nb_global changes. 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" For changes such as nb_cfg related columns, don't trigger recompute. Signed-off-by: Han Zhou --- northd/en-northd.c | 26 ++++++++++++++++++++++++++ northd/en-northd.h | 1 + northd/inc-proc-northd.c | 3 ++- tests/ovn-northd.at | 6 +++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/northd/en-northd.c b/northd/en-northd.c index e8f3a844af71..a3dc37e198e3 100644 --- a/northd/en-northd.c +++ b/northd/en-northd.c @@ -20,6 +20,7 @@ #include "en-northd.h" #include "lib/inc-proc-eng.h" +#include "lib/ovn-nb-idl.h" #include "openvswitch/list.h" /* TODO This is needed for ovn-parallel-hmap.h. * lib/ovn-parallel-hmap.h should be updated * to include this dependency itself */ @@ -122,6 +123,31 @@ void en_northd_run(struct engine_node *node, void *data) engine_set_node_state(node, EN_UPDATED); } + +bool +northd_nb_nb_global_handler(struct engine_node *node, + void *data OVS_UNUSED) +{ + const struct nbrec_nb_global_table *nb_global_table + = EN_OVSDB_GET(engine_get_input("NB_nb_global", node)); + + const struct nbrec_nb_global *nb = + nbrec_nb_global_table_first(nb_global_table); + + if (!nb) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); + VLOG_WARN_RL(&rl, "NB_Global is updated but has no record."); + return false; + } + + /* We care about the 'options' and 'ipsec' columns only. */ + if (nbrec_nb_global_is_updated(nb, NBREC_NB_GLOBAL_COL_OPTIONS) || + nbrec_nb_global_is_updated(nb, NBREC_NB_GLOBAL_COL_IPSEC)) { + return false; + } + return true; +} + void *en_northd_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg OVS_UNUSED) { diff --git a/northd/en-northd.h b/northd/en-northd.h index 0e7f76245e69..8d8343b459a6 100644 --- a/northd/en-northd.h +++ b/northd/en-northd.h @@ -13,5 +13,6 @@ void en_northd_run(struct engine_node *node OVS_UNUSED, void *data OVS_UNUSED); void *en_northd_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg); void en_northd_cleanup(void *data); +bool northd_nb_nb_global_handler(struct engine_node *, void *data OVS_UNUSED); #endif /* EN_NORTHD_H */ diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index d54aa19c7749..863c9323c444 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -141,7 +141,8 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, { /* Define relationships between nodes where first argument is dependent * on the second argument */ - engine_add_input(&en_northd, &en_nb_nb_global, NULL); + engine_add_input(&en_northd, &en_nb_nb_global, + northd_nb_nb_global_handler); engine_add_input(&en_northd, &en_nb_logical_switch, NULL); engine_add_input(&en_northd, &en_nb_port_group, NULL); engine_add_input(&en_northd, &en_nb_load_balancer, NULL); diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index 047b8b6ad914..58098fa91c06 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -8657,11 +8657,11 @@ wait_column '20.0.0.4' Address_Set addresses name=pg1_ip4 recompute_stat=$(as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats sync_to_sb_addr_set recompute) AT_CHECK([test $recompute_stat -ge 1]) -# Any change to northd engine node should result in full recompute of sync_to_sb_addr_set node. +# No change, no recompute check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=sb sync -recompute_stat=$(as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats sync_to_sb_addr_set recompute) -AT_CHECK([test $recompute_stat -ge 1]) +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats sync_to_sb_addr_set recompute], [0], [0 +]) AT_CLEANUP ]) From patchwork Sat May 13 00:03:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5V715hCz20KD for ; Sat, 13 May 2023 10:04:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5530442EC3; Sat, 13 May 2023 00:04:43 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5530442EC3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gTHkF4DeONSZ; Sat, 13 May 2023 00:04:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5D9CC42E90; Sat, 13 May 2023 00:04:38 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5D9CC42E90 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 25444C0094; Sat, 13 May 2023 00:04:34 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 91810C009E for ; Sat, 13 May 2023 00:04:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 540C242E5C for ; Sat, 13 May 2023 00:04:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 540C242E5C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yHv-zW4iWIoM for ; Sat, 13 May 2023 00:04:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org AAC0D42E1C Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id AAC0D42E1C for ; Sat, 13 May 2023 00:04:30 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 91EF41C0004; Sat, 13 May 2023 00:04:27 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:48 -0700 Message-Id: <20230513000356.2475960-7-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 06/14] northd: Track lsp names referenced by LB health-check. 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" Maintain a set of lsp names that are referenced in the column "ip_port_mappings" of load_balancer records (used for health check purpose), which will be used for lsp incremental processing. Signed-off-by: Han Zhou --- northd/northd.c | 21 ++++++++++++++------- northd/northd.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index 3214b86fc589..13d45adf6f08 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -3835,7 +3835,8 @@ create_or_get_service_mon(struct ovsdb_idl_txn *ovnsb_txn, static void ovn_lb_svc_create(struct ovsdb_idl_txn *ovnsb_txn, struct ovn_northd_lb *lb, - struct hmap *monitor_map, struct hmap *ls_ports) + struct hmap *monitor_map, struct hmap *ls_ports, + struct sset *svc_monitor_lsps) { if (lb->template) { return; @@ -3866,6 +3867,7 @@ ovn_lb_svc_create(struct ovsdb_idl_txn *ovnsb_txn, struct ovn_northd_lb *lb, if (p) { *p = 0; p++; + sset_add(svc_monitor_lsps, port_name); op = ovn_port_find(ls_ports, port_name); struct sockaddr_storage svc_mon_src_addr; if (!inet_parse_address(p, &svc_mon_src_addr)) { @@ -4147,8 +4149,7 @@ static void build_lb_svcs( struct ovsdb_idl_txn *ovnsb_txn, const struct sbrec_service_monitor_table *sbrec_service_monitor_table, - struct hmap *ls_ports, - struct hmap *lbs) + struct hmap *ls_ports, struct hmap *lbs, struct sset *svc_monitor_lsps) { struct hmap monitor_map = HMAP_INITIALIZER(&monitor_map); @@ -4166,7 +4167,8 @@ build_lb_svcs( struct ovn_northd_lb *lb; HMAP_FOR_EACH (lb, hmap_node, lbs) { - ovn_lb_svc_create(ovnsb_txn, lb, &monitor_map, ls_ports); + ovn_lb_svc_create(ovnsb_txn, lb, &monitor_map, ls_ports, + svc_monitor_lsps); } struct service_monitor_info *mon_info; @@ -4345,11 +4347,12 @@ build_lb_port_related_data( struct ovsdb_idl_txn *ovnsb_txn, const struct sbrec_service_monitor_table *sbrec_service_monitor_table, struct ovn_datapaths *lr_datapaths, struct hmap *ls_ports, - struct hmap *lbs, struct hmap *lb_groups) + struct hmap *lbs, struct hmap *lb_groups, struct sset *svc_monitor_lsps) { build_lrouter_lbs_check(lr_datapaths); build_lrouter_lbs_reachable_ips(lr_datapaths, lbs, lb_groups); - build_lb_svcs(ovnsb_txn, sbrec_service_monitor_table, ls_ports, lbs); + build_lb_svcs(ovnsb_txn, sbrec_service_monitor_table, ls_ports, lbs, + svc_monitor_lsps); build_lswitch_lbs_from_lrouter(lr_datapaths, lbs, lb_groups); } @@ -16499,6 +16502,7 @@ northd_init(struct northd_data *data) .ct_lb_related = true, }; data->ovn_internal_version_changed = false; + sset_init(&data->svc_monitor_lsps); } void @@ -16542,6 +16546,8 @@ northd_destroy(struct northd_data *data) &data->ls_ports, &data->lr_ports, &data->lr_list); destroy_debug_config(); + + sset_destroy(&data->svc_monitor_lsps); } static void @@ -16653,7 +16659,8 @@ ovnnb_db_run(struct northd_input *input_data, build_lb_port_related_data(ovnsb_txn, input_data->sbrec_service_monitor_table, &data->lr_datapaths, &data->ls_ports, - &data->lbs, &data->lb_groups); + &data->lbs, &data->lb_groups, + &data->svc_monitor_lsps); build_lb_count_dps(&data->lbs, ods_size(&data->ls_datapaths), ods_size(&data->lr_datapaths)); diff --git a/northd/northd.h b/northd/northd.h index dc630b488410..35195549d6e4 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -97,6 +97,7 @@ struct northd_data { struct ovs_list lr_list; bool ovn_internal_version_changed; struct chassis_features features; + struct sset svc_monitor_lsps; }; struct lflow_data { From patchwork Sat May 13 00:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5VD6kJCz20KD for ; Sat, 13 May 2023 10:04:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 59458702D9; Sat, 13 May 2023 00:04:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 59458702D9 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oZnMUwSpjKfN; Sat, 13 May 2023 00:04:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7D68B702DA; Sat, 13 May 2023 00:04:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7D68B702DA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 81A97C0089; Sat, 13 May 2023 00:04:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24A19C0089 for ; Sat, 13 May 2023 00:04:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id E0B88429A0 for ; Sat, 13 May 2023 00:04:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org E0B88429A0 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HRnf_B_dJXRz for ; Sat, 13 May 2023 00:04:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B73E742E04 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id B73E742E04 for ; Sat, 13 May 2023 00:04:31 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id DBAA81C0003; Sat, 13 May 2023 00:04:28 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:49 -0700 Message-Id: <20230513000356.2475960-8-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 07/14] northd: Incremental processing of VIF changes in 'northd' node. 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" This patch introduces a change handler for NB logical_switch within the 'northd' node. It specifically handles cases where logical switch ports in the tracked logical switches are changed (added/updated/deleted). Only regular logical switch ports - which are common for VMs/Pods - are addressed. For other scenarios, it reverts to recompute. This update avoids recompute in the northd node (especially the resource-intensive build_ports()) for NB changes of VIF add/update/delete. However, it does not eliminate the need for lflow recompute. Below are the performance test results simulating an ovn-k8s topology of 500 nodes x 50 lsp per node: Before: ovn-nbctl --wait=hv --print-wait-time lsp-del lsp_1_0001_01 ovn-northd completion: 955ms ovn-nbctl --wait=hv --print-wait-time lsp-add ls_1_0001 lsp_1_0001_01 -- lsp-set-addresses lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" -- lsp-set-port-security lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" ovn-northd completion: 919ms After: ovn-nbctl --wait=hv --print-wait-time lsp-del lsp_1_0001_01 ovn-northd completion: 776ms ovn-nbctl --wait=hv --print-wait-time lsp-add ls_1_0001 lsp_1_0001_01 -- lsp-set-addresses lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" -- lsp-set-port-security lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" ovn-northd completion: 773ms Both addition and deletion show ~20% reduction of ovn-northd completion time. Note: the test uses only 1 thread of ovn-northd for flow recompute. Using multithread should show a larger percentage of improvement. Signed-off-by: Han Zhou --- lib/ovn-util.c | 15 ++ lib/ovn-util.h | 1 + northd/en-northd.c | 130 ++++++--- northd/en-northd.h | 2 + northd/inc-proc-northd.c | 12 +- northd/northd.c | 567 +++++++++++++++++++++++++++++++++------ northd/northd.h | 27 +- tests/ovn-northd.at | 59 ++++ 8 files changed, 686 insertions(+), 127 deletions(-) diff --git a/lib/ovn-util.c b/lib/ovn-util.c index bffb521cfd9d..da2a9d45ac64 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -720,6 +720,21 @@ ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min, return 0; } +bool +ovn_free_tnlid(struct hmap *tnlids, uint32_t tnlid) +{ + uint32_t hash = hash_int(tnlid, 0); + struct tnlid_node *node; + HMAP_FOR_EACH_IN_BUCKET (node, hmap_node, hash, tnlids) { + if (node->tnlid == tnlid) { + hmap_remove(tnlids, &node->hmap_node); + free(node); + return true; + } + } + return false; +} + char * ovn_chassis_redirect_name(const char *port_name) { diff --git a/lib/ovn-util.h b/lib/ovn-util.h index f79301addec9..cfc1398f89d2 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -160,6 +160,7 @@ bool ovn_add_tnlid(struct hmap *set, uint32_t tnlid); bool ovn_tnlid_present(struct hmap *tnlids, uint32_t tnlid); uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min, uint32_t max, uint32_t *hint); +bool ovn_free_tnlid(struct hmap *tnlids, uint32_t tnlid); static inline void get_unique_lport_key(uint64_t dp_tunnel_key, uint64_t lport_tunnel_key, diff --git a/northd/en-northd.c b/northd/en-northd.c index a3dc37e198e3..f2bf98f774b1 100644 --- a/northd/en-northd.c +++ b/northd/en-northd.c @@ -31,92 +31,103 @@ VLOG_DEFINE_THIS_MODULE(en_northd); -void en_northd_run(struct engine_node *node, void *data) +static void +northd_get_input_data(struct engine_node *node, + struct northd_input *input_data) { - const struct engine_context *eng_ctx = engine_get_context(); - - struct northd_input input_data; - - northd_destroy(data); - northd_init(data); - - input_data.sbrec_chassis_by_name = + input_data->sbrec_chassis_by_name = engine_ovsdb_node_get_index( engine_get_input("SB_chassis", node), "sbrec_chassis_by_name"); - input_data.sbrec_chassis_by_hostname = + input_data->sbrec_chassis_by_hostname = engine_ovsdb_node_get_index( engine_get_input("SB_chassis", node), "sbrec_chassis_by_hostname"); - input_data.sbrec_ha_chassis_grp_by_name = + input_data->sbrec_ha_chassis_grp_by_name = engine_ovsdb_node_get_index( engine_get_input("SB_ha_chassis_group", node), "sbrec_ha_chassis_grp_by_name"); - input_data.sbrec_ip_mcast_by_dp = + input_data->sbrec_ip_mcast_by_dp = engine_ovsdb_node_get_index( engine_get_input("SB_ip_multicast", node), "sbrec_ip_mcast_by_dp"); - input_data.sbrec_static_mac_binding_by_lport_ip = + input_data->sbrec_static_mac_binding_by_lport_ip = engine_ovsdb_node_get_index( engine_get_input("SB_static_mac_binding", node), "sbrec_static_mac_binding_by_lport_ip"); + input_data->sbrec_fdb_by_dp_and_port = + engine_ovsdb_node_get_index( + engine_get_input("SB_fdb", node), + "sbrec_fdb_by_dp_and_port"); - input_data.nbrec_nb_global_table = + input_data->nbrec_nb_global_table = EN_OVSDB_GET(engine_get_input("NB_nb_global", node)); - input_data.nbrec_logical_switch_table = + input_data->nbrec_logical_switch_table = EN_OVSDB_GET(engine_get_input("NB_logical_switch", node)); - input_data.nbrec_logical_router_table = + input_data->nbrec_logical_router_table = EN_OVSDB_GET(engine_get_input("NB_logical_router", node)); - input_data.nbrec_load_balancer_table = + input_data->nbrec_load_balancer_table = EN_OVSDB_GET(engine_get_input("NB_load_balancer", node)); - input_data.nbrec_load_balancer_group_table = + input_data->nbrec_load_balancer_group_table = EN_OVSDB_GET(engine_get_input("NB_load_balancer_group", node)); - input_data.nbrec_port_group_table = + input_data->nbrec_port_group_table = EN_OVSDB_GET(engine_get_input("NB_port_group", node)); - input_data.nbrec_meter_table = + input_data->nbrec_meter_table = EN_OVSDB_GET(engine_get_input("NB_meter", node)); - input_data.nbrec_acl_table = + input_data->nbrec_acl_table = EN_OVSDB_GET(engine_get_input("NB_acl", node)); - input_data.nbrec_static_mac_binding_table = + input_data->nbrec_static_mac_binding_table = EN_OVSDB_GET(engine_get_input("NB_static_mac_binding", node)); - input_data.nbrec_chassis_template_var_table = + input_data->nbrec_chassis_template_var_table = EN_OVSDB_GET(engine_get_input("NB_chassis_template_var", node)); - input_data.nbrec_mirror_table = + input_data->nbrec_mirror_table = EN_OVSDB_GET(engine_get_input("NB_mirror", node)); - input_data.sbrec_sb_global_table = + input_data->sbrec_sb_global_table = EN_OVSDB_GET(engine_get_input("SB_sb_global", node)); - input_data.sbrec_datapath_binding_table = + input_data->sbrec_datapath_binding_table = EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node)); - input_data.sbrec_port_binding_table = + input_data->sbrec_port_binding_table = EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); - input_data.sbrec_mac_binding_table = + input_data->sbrec_mac_binding_table = EN_OVSDB_GET(engine_get_input("SB_mac_binding", node)); - input_data.sbrec_ha_chassis_group_table = + input_data->sbrec_ha_chassis_group_table = EN_OVSDB_GET(engine_get_input("SB_ha_chassis_group", node)); - input_data.sbrec_chassis_table = + input_data->sbrec_chassis_table = EN_OVSDB_GET(engine_get_input("SB_chassis", node)); - input_data.sbrec_fdb_table = + input_data->sbrec_fdb_table = EN_OVSDB_GET(engine_get_input("SB_fdb", node)); - input_data.sbrec_load_balancer_table = + input_data->sbrec_load_balancer_table = EN_OVSDB_GET(engine_get_input("SB_load_balancer", node)); - input_data.sbrec_service_monitor_table = + input_data->sbrec_service_monitor_table = EN_OVSDB_GET(engine_get_input("SB_service_monitor", node)); - input_data.sbrec_port_group_table = + input_data->sbrec_port_group_table = EN_OVSDB_GET(engine_get_input("SB_port_group", node)); - input_data.sbrec_meter_table = + input_data->sbrec_meter_table = EN_OVSDB_GET(engine_get_input("SB_meter", node)); - input_data.sbrec_dns_table = + input_data->sbrec_dns_table = EN_OVSDB_GET(engine_get_input("SB_dns", node)); - input_data.sbrec_ip_multicast_table = + input_data->sbrec_ip_multicast_table = EN_OVSDB_GET(engine_get_input("SB_ip_multicast", node)); - input_data.sbrec_static_mac_binding_table = + input_data->sbrec_static_mac_binding_table = EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node)); - input_data.sbrec_chassis_template_var_table = + input_data->sbrec_chassis_template_var_table = EN_OVSDB_GET(engine_get_input("SB_chassis_template_var", node)); - input_data.sbrec_mirror_table = + input_data->sbrec_mirror_table = EN_OVSDB_GET(engine_get_input("SB_mirror", node)); +} +void +en_northd_run(struct engine_node *node, void *data) +{ + const struct engine_context *eng_ctx = engine_get_context(); + + struct northd_input input_data; + + northd_destroy(data); + northd_init(data); + + northd_get_input_data(node, &input_data); northd_run(&input_data, data, eng_ctx->ovnnb_idl_txn, eng_ctx->ovnsb_idl_txn); @@ -148,17 +159,48 @@ northd_nb_nb_global_handler(struct engine_node *node, return true; } -void *en_northd_init(struct engine_node *node OVS_UNUSED, - struct engine_arg *arg OVS_UNUSED) +bool +northd_nb_logical_switch_handler(struct engine_node *node, + void *data) { - struct northd_data *data = xmalloc(sizeof *data); + const struct engine_context *eng_ctx = engine_get_context(); + struct northd_data *nd = data; + + struct northd_input input_data; + + northd_get_input_data(node, &input_data); + + if (!northd_handle_ls_changes(eng_ctx->ovnsb_idl_txn, &input_data, nd)) { + return false; + } + + if (nd->change_tracked) { + engine_set_node_state(node, EN_UPDATED); + } + + return true; +} + +void +*en_northd_init(struct engine_node *node OVS_UNUSED, + struct engine_arg *arg OVS_UNUSED) +{ + struct northd_data *data = xzalloc(sizeof *data); northd_init(data); return data; } -void en_northd_cleanup(void *data) +void +en_northd_cleanup(void *data) { northd_destroy(data); } + +void +en_northd_clear_tracked_data(void *data_) +{ + struct northd_data *data = data_; + destroy_northd_data_tracked_changes(data); +} diff --git a/northd/en-northd.h b/northd/en-northd.h index 8d8343b459a6..a53a162bda48 100644 --- a/northd/en-northd.h +++ b/northd/en-northd.h @@ -13,6 +13,8 @@ void en_northd_run(struct engine_node *node OVS_UNUSED, void *data OVS_UNUSED); void *en_northd_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg); void en_northd_cleanup(void *data); +void en_northd_clear_tracked_data(void *data); bool northd_nb_nb_global_handler(struct engine_node *, void *data OVS_UNUSED); +bool northd_nb_logical_switch_handler(struct engine_node *, void *data); #endif /* EN_NORTHD_H */ diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index 863c9323c444..f992a9ec8420 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -128,7 +128,7 @@ enum sb_engine_node { /* Define engine nodes for other nodes. They should be defined as static to * avoid sparse errors. */ -static ENGINE_NODE(northd, "northd"); +static ENGINE_NODE_WITH_CLEAR_TRACK_DATA(northd, "northd"); static ENGINE_NODE(lflow, "lflow"); static ENGINE_NODE(mac_binding_aging, "mac_binding_aging"); static ENGINE_NODE(mac_binding_aging_waker, "mac_binding_aging_waker"); @@ -143,7 +143,8 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, * on the second argument */ engine_add_input(&en_northd, &en_nb_nb_global, northd_nb_nb_global_handler); - engine_add_input(&en_northd, &en_nb_logical_switch, NULL); + engine_add_input(&en_northd, &en_nb_logical_switch, + northd_nb_logical_switch_handler); engine_add_input(&en_northd, &en_nb_port_group, NULL); engine_add_input(&en_northd, &en_nb_load_balancer, NULL); engine_add_input(&en_northd, &en_nb_load_balancer_group, NULL); @@ -252,6 +253,13 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, "sbrec_address_set_by_name", sbrec_address_set_by_name); + struct ovsdb_idl_index *sbrec_fdb_by_dp_and_port + = ovsdb_idl_index_create2(sb->idl, &sbrec_fdb_col_dp_key, + &sbrec_fdb_col_port_key); + engine_ovsdb_node_add_index(&en_sb_fdb, + "sbrec_fdb_by_dp_and_port", + sbrec_fdb_by_dp_and_port); + struct northd_data *northd_data = engine_get_internal_data(&en_northd); unixctl_command_register("debug/chassis-features-list", "", 0, 0, diff --git a/northd/northd.c b/northd/northd.c index 13d45adf6f08..be206d7a3622 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -19,6 +19,7 @@ #include "debug.h" #include "bitmap.h" +#include "coverage.h" #include "dirs.h" #include "ipam.h" #include "openvswitch/dynamic-string.h" @@ -59,6 +60,8 @@ VLOG_DEFINE_THIS_MODULE(northd); +COVERAGE_DEFINE(northd_run); + static bool controller_event_en; static bool lflow_hash_lock_initialized = false; @@ -868,13 +871,20 @@ ovn_datapath_create(struct hmap *datapaths, const struct uuid *key, od->port_key_hint = 0; hmap_insert(datapaths, &od->key_node, uuid_hash(&od->key)); od->lr_group = NULL; - ovs_list_init(&od->port_list); + hmap_init(&od->ports); return od; } static void ovn_ls_port_group_destroy(struct hmap *nb_pgs); static void destroy_mcast_info_for_datapath(struct ovn_datapath *od); +static void +destroy_ports_for_datapath(struct ovn_datapath *od) +{ + ovs_assert(hmap_is_empty(&od->ports)); + hmap_destroy(&od->ports); +} + static void ovn_datapath_destroy(struct hmap *datapaths, struct ovn_datapath *od) { @@ -895,6 +905,7 @@ ovn_datapath_destroy(struct hmap *datapaths, struct ovn_datapath *od) free(od->l3dgw_ports); ovn_ls_port_group_destroy(&od->nb_pgs); destroy_mcast_info_for_datapath(od); + destroy_ports_for_datapath(od); free(od); } @@ -1541,6 +1552,9 @@ struct ovn_port { struct lport_addresses *ps_addrs; /* Port security addresses. */ unsigned int n_ps_addrs; + bool lsp_can_be_inc_processed; /* If it can be incrementally processed when + the port changes. */ + /* Logical router port data. */ const struct nbrec_logical_router_port *nbrp; /* May be NULL. */ @@ -1582,11 +1596,16 @@ struct ovn_port { struct ovs_list list; /* In list of similar records. */ - struct ovs_list dp_node; + struct hmap_node dp_node; /* Node in od->ports. */ struct lport_addresses proxy_arp_addrs; + + /* Temporarily used for traversing a list (or hmap) of ports. */ + bool visited; }; +static bool lsp_can_be_inc_processed(const struct nbrec_logical_switch_port *); + static bool is_l3dgw_port(const struct ovn_port *op) { @@ -1646,6 +1665,9 @@ ovn_port_set_nb(struct ovn_port *op, const struct nbrec_logical_router_port *nbrp) { op->nbsp = nbsp; + if (nbsp) { + op->lsp_can_be_inc_processed = lsp_can_be_inc_processed(nbsp); + } op->nbrp = nbrp; init_mcast_port_info(&op->mcast_info, op->nbsp, op->nbrp); } @@ -1671,35 +1693,46 @@ ovn_port_create(struct hmap *ports, const char *key, } static void -ovn_port_destroy(struct hmap *ports, struct ovn_port *port) +ovn_port_destroy_orphan(struct ovn_port *port) { - if (port) { - /* Don't remove port->list. It is used within build_ports() as a - * private list and once we've exited that function it is not safe to - * use it. */ - hmap_remove(ports, &port->key_node); + if (port->tunnel_key) { + ovs_assert(port->od); + ovn_free_tnlid(&port->od->port_tnlids, port->tunnel_key); + } + for (int i = 0; i < port->n_lsp_addrs; i++) { + destroy_lport_addresses(&port->lsp_addrs[i]); + } + free(port->lsp_addrs); - if (port->peer) { - port->peer->peer = NULL; - } + if (port->peer) { + port->peer->peer = NULL; + } - for (int i = 0; i < port->n_lsp_addrs; i++) { - destroy_lport_addresses(&port->lsp_addrs[i]); - } - free(port->lsp_addrs); + for (int i = 0; i < port->n_ps_addrs; i++) { + destroy_lport_addresses(&port->ps_addrs[i]); + } + free(port->ps_addrs); - for (int i = 0; i < port->n_ps_addrs; i++) { - destroy_lport_addresses(&port->ps_addrs[i]); - } - free(port->ps_addrs); + destroy_routable_addresses(&port->routables); - destroy_routable_addresses(&port->routables); + destroy_lport_addresses(&port->lrp_networks); + destroy_lport_addresses(&port->proxy_arp_addrs); + free(port->json_key); + free(port->key); + free(port); +} - destroy_lport_addresses(&port->lrp_networks); - destroy_lport_addresses(&port->proxy_arp_addrs); - free(port->json_key); - free(port->key); - free(port); +static void +ovn_port_destroy(struct hmap *ports, struct ovn_port *port) +{ + if (port) { + /* Don't remove port->list. The node should be removed from such lists + * before calling this function. */ + hmap_remove(ports, &port->key_node); + if (port->od && !port->l3dgw_port) { + hmap_remove(&port->od->ports, &port->dp_node); + } + ovn_port_destroy_orphan(port); } } @@ -2469,6 +2502,53 @@ tag_alloc_create_new_tag(struct hmap *tag_alloc_table, } +static void +parse_lsp_addrs(struct ovn_port *op) +{ + const struct nbrec_logical_switch_port *nbsp = op->nbsp; + ovs_assert(nbsp); + op->lsp_addrs + = xmalloc(sizeof *op->lsp_addrs * nbsp->n_addresses); + for (size_t j = 0; j < nbsp->n_addresses; j++) { + if (!strcmp(nbsp->addresses[j], "unknown")) { + op->has_unknown = true; + continue; + } + if (!strcmp(nbsp->addresses[j], "router")) { + continue; + } + if (is_dynamic_lsp_address(nbsp->addresses[j])) { + continue; + } else if (!extract_lsp_addresses(nbsp->addresses[j], + &op->lsp_addrs[op->n_lsp_addrs])) { + static struct vlog_rate_limit rl + = VLOG_RATE_LIMIT_INIT(1, 1); + VLOG_INFO_RL(&rl, "invalid syntax '%s' in logical " + "switch port addresses. No MAC " + "address found", + op->nbsp->addresses[j]); + continue; + } + op->n_lsp_addrs++; + } + op->n_lsp_non_router_addrs = op->n_lsp_addrs; + + op->ps_addrs + = xmalloc(sizeof *op->ps_addrs * nbsp->n_port_security); + for (size_t j = 0; j < nbsp->n_port_security; j++) { + if (!extract_lsp_addresses(nbsp->port_security[j], + &op->ps_addrs[op->n_ps_addrs])) { + static struct vlog_rate_limit rl + = VLOG_RATE_LIMIT_INIT(1, 1); + VLOG_INFO_RL(&rl, "invalid syntax '%s' in port " + "security. No MAC address found", + op->nbsp->port_security[j]); + continue; + } + op->n_ps_addrs++; + } +} + static void join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, struct hmap *ls_datapaths, struct hmap *lr_datapaths, @@ -2568,49 +2648,11 @@ join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, od->has_vtep_lports = true; } - op->lsp_addrs - = xmalloc(sizeof *op->lsp_addrs * nbsp->n_addresses); - for (size_t j = 0; j < nbsp->n_addresses; j++) { - if (!strcmp(nbsp->addresses[j], "unknown")) { - op->has_unknown = true; - continue; - } - if (!strcmp(nbsp->addresses[j], "router")) { - continue; - } - if (is_dynamic_lsp_address(nbsp->addresses[j])) { - continue; - } else if (!extract_lsp_addresses(nbsp->addresses[j], - &op->lsp_addrs[op->n_lsp_addrs])) { - static struct vlog_rate_limit rl - = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_INFO_RL(&rl, "invalid syntax '%s' in logical " - "switch port addresses. No MAC " - "address found", - op->nbsp->addresses[j]); - continue; - } - op->n_lsp_addrs++; - } - op->n_lsp_non_router_addrs = op->n_lsp_addrs; - - op->ps_addrs - = xmalloc(sizeof *op->ps_addrs * nbsp->n_port_security); - for (size_t j = 0; j < nbsp->n_port_security; j++) { - if (!extract_lsp_addresses(nbsp->port_security[j], - &op->ps_addrs[op->n_ps_addrs])) { - static struct vlog_rate_limit rl - = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_INFO_RL(&rl, "invalid syntax '%s' in port " - "security. No MAC address found", - op->nbsp->port_security[j]); - continue; - } - op->n_ps_addrs++; - } + parse_lsp_addrs(op); op->od = od; - ovs_list_push_back(&od->port_list, &op->dp_node); + hmap_insert(&od->ports, &op->dp_node, + hmap_node_hash(&op->key_node)); tag_alloc_add_existing_tags(tag_alloc_table, nbsp); } } @@ -2657,7 +2699,8 @@ join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, op->lrp_networks = lrp_networks; op->od = od; - ovs_list_push_back(&od->port_list, &op->dp_node); + hmap_insert(&od->ports, &op->dp_node, + hmap_node_hash(&op->key_node)); if (!od->redirect_bridged) { const char *redirect_type = @@ -3378,6 +3421,10 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, struct smap new; smap_init(&new); if (is_cr_port(op)) { + ovs_assert(sbrec_chassis_by_name); + ovs_assert(sbrec_chassis_by_hostname); + ovs_assert(sbrec_ha_chassis_grp_by_name); + ovs_assert(active_ha_chassis_grps); const char *redirect_type = smap_get(&op->nbrp->options, "redirect-type"); @@ -3497,9 +3544,11 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, } if (has_qos && !queue_id) { + ovs_assert(chassis_qdisc_queues); queue_id = allocate_chassis_queueid(chassis_qdisc_queues, uuid, name); } else if (!has_qos && queue_id) { + ovs_assert(chassis_qdisc_queues); free_chassis_queueid(chassis_qdisc_queues, uuid, queue_id); queue_id = 0; } @@ -3538,6 +3587,10 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, sbrec_port_binding_set_nat_addresses(op->sb, NULL, 0); if (!strcmp(op->nbsp->type, "external")) { + ovs_assert(sbrec_chassis_by_name); + ovs_assert(sbrec_chassis_by_hostname); + ovs_assert(sbrec_ha_chassis_grp_by_name); + ovs_assert(active_ha_chassis_grps); if (op->nbsp->ha_chassis_group) { sync_ha_chassis_group_for_sbpb( ovnsb_txn, sbrec_chassis_by_name, @@ -3794,6 +3847,24 @@ cleanup_stale_fdb_entries(const struct sbrec_fdb_table *sbrec_fdb_table, } } +static void +delete_fdb_entry(struct ovsdb_idl_index *sbrec_fdb_by_dp_and_port, + uint32_t dp_key, uint32_t port_key) +{ + struct sbrec_fdb *target = + sbrec_fdb_index_init_row(sbrec_fdb_by_dp_and_port); + sbrec_fdb_index_set_dp_key(target, dp_key); + sbrec_fdb_index_set_port_key(target, port_key); + + struct sbrec_fdb *fdb_e = sbrec_fdb_index_find(sbrec_fdb_by_dp_and_port, + target); + sbrec_fdb_index_destroy_row(target); + + if (fdb_e) { + sbrec_fdb_delete(fdb_e); + } +} + struct service_monitor_info { struct hmap_node hmap_node; const struct sbrec_service_monitor *sbrec_mon; @@ -3885,14 +3956,15 @@ ovn_lb_svc_create(struct ovsdb_idl_txn *ovnsb_txn, struct ovn_northd_lb *lb, } ds_destroy(&key); - backend_nb->op = op; - backend_nb->svc_mon_src_ip = svc_mon_src_ip; - if (!lb_vip_nb->lb_health_check || !op || !svc_mon_src_ip || !lsp_is_enabled(op->nbsp)) { + free(svc_mon_src_ip); continue; } + backend_nb->op = op; + backend_nb->svc_mon_src_ip = svc_mon_src_ip; + const char *protocol = lb->nlb->protocol; if (!protocol || !protocol[0]) { protocol = "tcp"; @@ -4220,7 +4292,7 @@ build_lrouter_lb_reachable_ips(struct ovn_datapath *od, ovs_be32 vip_ip4 = in6_addr_get_mapped_ipv4(&lb->vips[i].vip); struct ovn_port *op; - LIST_FOR_EACH (op, dp_node, &od->port_list) { + HMAP_FOR_EACH (op, dp_node, &od->ports) { if (lrouter_port_ipv4_reachable(op, vip_ip4)) { sset_add(&od->lb_ips->ips_v4_reachable, lb->vips[i].vip_str); @@ -4230,7 +4302,7 @@ build_lrouter_lb_reachable_ips(struct ovn_datapath *od, } else { struct ovn_port *op; - LIST_FOR_EACH (op, dp_node, &od->port_list) { + HMAP_FOR_EACH (op, dp_node, &od->ports) { if (lrouter_port_ipv6_reachable(op, &lb->vips[i].vip)) { sset_add(&od->lb_ips->ips_v6_reachable, lb->vips[i].vip_str); @@ -4567,7 +4639,10 @@ ovn_port_add_tnlid(struct ovn_port *op, uint32_t tunnel_key) return added; } -static void +/* Returns false if the requested key is confict with another allocated key, so + * that the I-P engine can fallback to recompute if needed; otherwise return + * true (even if the key is not allocated). */ +static bool ovn_port_assign_requested_tnl_id( const struct sbrec_chassis_table *sbrec_chassis_table, struct ovn_port *op) { @@ -4582,7 +4657,7 @@ ovn_port_assign_requested_tnl_id( VLOG_WARN_RL(&rl, "Tunnel key %"PRIu32" for port %s " "is incompatible with VXLAN", tunnel_key, op_get_name(op)); - return; + return true; } if (!ovn_port_add_tnlid(op, tunnel_key)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); @@ -4590,11 +4665,13 @@ ovn_port_assign_requested_tnl_id( "%"PRIu32" as another LSP or LRP", op->nbsp ? "switch" : "router", op_get_name(op), tunnel_key); + return false; } } + return true; } -static void +static bool ovn_port_allocate_key(const struct sbrec_chassis_table *sbrec_chassis_table, struct hmap *ports, struct ovn_port *op) @@ -4610,8 +4687,10 @@ ovn_port_allocate_key(const struct sbrec_chassis_table *sbrec_chassis_table, } ovs_list_remove(&op->list); ovn_port_destroy(ports, op); + return false; } } + return true; } /* Updates the southbound Port_Binding table so that it contains the logical @@ -4634,6 +4713,8 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, struct hmap *ls_ports, struct hmap *lr_ports) { struct ovs_list sb_only, nb_only, both; + /* XXX: Add tag_alloc_table and chassis_qdisc_queues as part of northd_data + * to improve I-P. */ struct hmap tag_alloc_table = HMAP_INITIALIZER(&tag_alloc_table); struct hmap chassis_qdisc_queues = HMAP_INITIALIZER(&chassis_qdisc_queues); @@ -4739,6 +4820,329 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, sset_destroy(&active_ha_chassis_grps); } +void +destroy_northd_data_tracked_changes(struct northd_data *nd) +{ + struct ls_change *ls_change; + LIST_FOR_EACH_SAFE (ls_change, list_node, + &nd->tracked_ls_changes.updated) { + struct ovn_port *op; + LIST_FOR_EACH (op, list, &ls_change->added_ports) { + ovs_list_remove(&op->list); + } + LIST_FOR_EACH (op, list, &ls_change->updated_ports) { + ovs_list_remove(&op->list); + } + LIST_FOR_EACH_SAFE (op, list, &ls_change->deleted_ports) { + ovs_list_remove(&op->list); + ovn_port_destroy_orphan(op); + } + ovs_list_remove(&ls_change->list_node); + free(ls_change); + } + + nd->change_tracked = false; +} + +/* Check if a changed LSP can be handled incrementally within the I-P engine + * node en_northd. + */ +static bool +lsp_can_be_inc_processed(const struct nbrec_logical_switch_port *nbsp) +{ + /* Currently only support normal VIF. */ + if (nbsp->type[0]) { + return false; + } + + /* Currently not support tag allocation. */ + if ((nbsp->parent_name && nbsp->parent_name[0]) || nbsp->tag || + nbsp->tag_request) { + return false; + } + + /* Currently not support port with qos settings (need special handling for + * chassis_qdisc_queues sync. */ + if (port_has_qos_params( ->options)) { + return false; + } + + for (size_t j = 0; j < nbsp->n_addresses; j++) { + /* Currently not support dynamic address handling. */ + if (is_dynamic_lsp_address(nbsp->addresses[j])) { + return false; + } + /* Currently not support "unknown" address handling. XXX: Need to + * handle od->has_unknown change and track it when the first LSP with + * 'unknown' is added or when the last one is removed. */ + if (!strcmp(nbsp->addresses[j], "unknown")) { + return false; + } + } + + return true; +} + +static bool +ls_port_has_changed(const struct nbrec_logical_switch_port *old, + const struct nbrec_logical_switch_port *new) +{ + if (old != new) { + return true; + } + /* XXX: Need a better OVSDB IDL interface for this check. */ + return (nbrec_logical_switch_port_row_get_seqno(new, + OVSDB_IDL_CHANGE_MODIFY) > 0); +} + +static struct ovn_port * +ovn_port_find_in_datapath(struct ovn_datapath *od, const char *name) +{ + struct ovn_port *op; + HMAP_FOR_EACH_WITH_HASH (op, dp_node, hash_string(name, 0), &od->ports) { + if (!strcmp(op->key, name)) { + return op; + } + } + return NULL; +} + +static struct ovn_port * +ls_port_create(struct ovsdb_idl_txn *ovnsb_txn, struct hmap *ls_ports, + const char *key, const struct nbrec_logical_switch_port *nbsp, + struct ovn_datapath *od, const struct sbrec_port_binding *sb, + const struct sbrec_mirror_table *sbrec_mirror_table, + const struct sbrec_chassis_table *sbrec_chassis_table, + struct ovsdb_idl_index *sbrec_chassis_by_name, + struct ovsdb_idl_index *sbrec_chassis_by_hostname) +{ + struct ovn_port *op = ovn_port_create(ls_ports, key, nbsp, NULL, + NULL); + parse_lsp_addrs(op); + op->od = od; + hmap_insert(&od->ports, &op->dp_node, hmap_node_hash(&op->key_node)); + + /* Assign explicitly requested tunnel ids first. */ + if (!ovn_port_assign_requested_tnl_id(sbrec_chassis_table, op)) { + return NULL; + } + if (sb) { + op->sb = sb; + /* Keep nonconflicting tunnel IDs that are already assigned. */ + if (!op->tunnel_key) { + ovn_port_add_tnlid(op, op->sb->tunnel_key); + } + } else { + /* XXX: the new SB port_binding will change in IDL, so need to handle + * SB port_binding updates incrementally to achieve end-to-end + * incremental processing. */ + op->sb = sbrec_port_binding_insert(ovnsb_txn); + sbrec_port_binding_set_logical_port(op->sb, op->key); + } + /* Assign new tunnel ids where needed. */ + if (!ovn_port_allocate_key(sbrec_chassis_table, ls_ports, op)) { + return NULL; + } + ovn_port_update_sbrec(ovnsb_txn, sbrec_chassis_by_name, + sbrec_chassis_by_hostname, NULL, sbrec_mirror_table, + op, NULL, NULL); + return op; +} + +static bool +check_ls_changes_other_than_lsp(const struct nbrec_logical_switch *ls) +{ + /* Check if the columns are changed in this row. */ + enum nbrec_logical_switch_column_id col; + for (col = 0; col < NBREC_LOGICAL_SWITCH_N_COLUMNS; col++) { + if (nbrec_logical_switch_is_updated(ls, col) && + col != NBREC_LOGICAL_SWITCH_COL_PORTS) { + return true; + } + } + + /* Check if the referenced rows are changed. + XXX: Need a better OVSDB IDL interface for this check. */ + for (size_t i = 0; i < ls->n_acls; i++) { + if (nbrec_acl_row_get_seqno(ls->acls[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + if (ls->copp && nbrec_copp_row_get_seqno(ls->copp, + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + for (size_t i = 0; i < ls->n_dns_records; i++) { + if (nbrec_dns_row_get_seqno(ls->dns_records[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + for (size_t i = 0; i < ls->n_forwarding_groups; i++) { + if (nbrec_forwarding_group_row_get_seqno(ls->forwarding_groups[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + for (size_t i = 0; i < ls->n_load_balancer; i++) { + if (nbrec_load_balancer_row_get_seqno(ls->load_balancer[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + for (size_t i = 0; i < ls->n_load_balancer_group; i++) { + if (nbrec_load_balancer_group_row_get_seqno(ls->load_balancer_group[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + for (size_t i = 0; i < ls->n_qos_rules; i++) { + if (nbrec_qos_row_get_seqno(ls->qos_rules[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + return false; +} + +/* Return true if changes are handled incrementally, false otherwise. + * When there are any changes, try to track what's exactly changed and set + * northd_data->change_tracked accordingly: change tracked - true, otherwise, + * false. */ +bool +northd_handle_ls_changes(struct ovsdb_idl_txn *ovnsb_idl_txn, + const struct northd_input *ni, + struct northd_data *nd) +{ + const struct nbrec_logical_switch *changed_ls; + struct ls_change *ls_change = NULL; + + NBREC_LOGICAL_SWITCH_TABLE_FOR_EACH_TRACKED (changed_ls, + ni->nbrec_logical_switch_table) { + ls_change = NULL; + if (nbrec_logical_switch_is_new(changed_ls) || + nbrec_logical_switch_is_deleted(changed_ls)) { + goto fail; + } + struct ovn_datapath *od = ovn_datapath_find( + &nd->ls_datapaths.datapaths, + &changed_ls->header_.uuid); + if (!od) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); + VLOG_WARN_RL(&rl, "Internal error: a tracked updated LS doesn't " + "exist in ls_datapaths: "UUID_FMT, + UUID_ARGS(&changed_ls->header_.uuid)); + goto fail; + } + + /* Now only able to handle lsp changes. */ + if (check_ls_changes_other_than_lsp(changed_ls)) { + goto fail; + } + + ls_change = xzalloc(sizeof *ls_change); + ls_change->od = od; + ovs_list_init(&ls_change->added_ports); + ovs_list_init(&ls_change->deleted_ports); + ovs_list_init(&ls_change->updated_ports); + + struct ovn_port *op; + HMAP_FOR_EACH (op, dp_node, &od->ports) { + op->visited = false; + } + + /* Compare the individual ports in the old and new Logical Switches */ + for (size_t j = 0; j < changed_ls->n_ports; ++j) { + struct nbrec_logical_switch_port *new_nbsp = changed_ls->ports[j]; + op = ovn_port_find_in_datapath(od, new_nbsp->name); + + if (!op) { + if (!lsp_can_be_inc_processed(new_nbsp)) { + goto fail; + } + op = ls_port_create(ovnsb_idl_txn, &nd->ls_ports, + new_nbsp->name, new_nbsp, od, NULL, + ni->sbrec_mirror_table, + ni->sbrec_chassis_table, + ni->sbrec_chassis_by_name, + ni->sbrec_chassis_by_hostname); + if (!op) { + goto fail; + } + ovs_list_push_back(&ls_change->added_ports, + &op->list); + } else if (ls_port_has_changed(op->nbsp, new_nbsp)) { + /* Existing port updated */ + bool temp = false; + if (lsp_is_type_changed(op->sb, new_nbsp, &temp) || + !op->lsp_can_be_inc_processed || + !lsp_can_be_inc_processed(new_nbsp)) { + goto fail; + } + const struct sbrec_port_binding *sb = op->sb; + if (sset_contains(&nd->svc_monitor_lsps, new_nbsp->name)) { + /* This port is used for svc monitor, which may be impacted + * by this change. Fallback to recompute. */ + goto fail; + } + ovn_port_destroy(&nd->ls_ports, op); + op = ls_port_create(ovnsb_idl_txn, &nd->ls_ports, + new_nbsp->name, new_nbsp, od, sb, + ni->sbrec_mirror_table, + ni->sbrec_chassis_table, + ni->sbrec_chassis_by_name, + ni->sbrec_chassis_by_hostname); + if (!op) { + goto fail; + } + ovs_list_push_back(&ls_change->updated_ports, &op->list); + } + op->visited = true; + } + + /* Check for deleted ports */ + HMAP_FOR_EACH_SAFE (op, dp_node, &od->ports) { + if (!op->visited) { + if (!op->lsp_can_be_inc_processed) { + goto fail; + } + if (sset_contains(&nd->svc_monitor_lsps, op->key)) { + /* This port was used for svc monitor, which may be + * impacted by this deletion. Fallback to recompute. */ + goto fail; + } + ovs_list_push_back(&ls_change->deleted_ports, + &op->list); + hmap_remove(&nd->ls_ports, &op->key_node); + hmap_remove(&od->ports, &op->dp_node); + sbrec_port_binding_delete(op->sb); + delete_fdb_entry(ni->sbrec_fdb_by_dp_and_port, od->tunnel_key, + op->tunnel_key); + } + } + + if (!ovs_list_is_empty(&ls_change->added_ports) || + !ovs_list_is_empty(&ls_change->updated_ports) || + !ovs_list_is_empty(&ls_change->deleted_ports)) { + ovs_list_push_back(&nd->tracked_ls_changes.updated, + &ls_change->list_node); + } else { + free(ls_change); + } + } + + if (!ovs_list_is_empty(&nd->tracked_ls_changes.updated)) { + nd->change_tracked = true; + } + return true; + +fail: + free(ls_change); + destroy_northd_data_tracked_changes(nd); + return false; +} + struct multicast_group { const char *name; uint16_t key; /* OVN_MIN_MULTICAST...OVN_MAX_MULTICAST. */ @@ -6068,7 +6472,7 @@ build_interconn_mcast_snoop_flows(struct ovn_datapath *od, struct ovn_port *op; - LIST_FOR_EACH (op, dp_node, &od->port_list) { + HMAP_FOR_EACH (op, dp_node, &od->ports) { if (!lsp_is_remote(op->nbsp)) { continue; } @@ -12314,7 +12718,7 @@ build_mcast_lookup_flows_for_lrouter( * own mac addresses. */ struct ovn_port *op; - LIST_FOR_EACH (op, dp_node, &od->port_list) { + HMAP_FOR_EACH (op, dp_node, &od->ports) { ds_clear(match); ds_put_format(match, "eth.src == %s && igmp", op->lrp_networks.ea_s); @@ -16469,9 +16873,6 @@ destroy_datapaths_and_ports(struct ovn_datapaths *ls_datapaths, } } - ovn_datapaths_destroy(ls_datapaths); - ovn_datapaths_destroy(lr_datapaths); - struct ovn_port *port; HMAP_FOR_EACH_SAFE (port, key_node, ls_ports) { ovn_port_destroy(ls_ports, port); @@ -16482,6 +16883,9 @@ destroy_datapaths_and_ports(struct ovn_datapaths *ls_datapaths, ovn_port_destroy(lr_ports, port); } hmap_destroy(lr_ports); + + ovn_datapaths_destroy(ls_datapaths); + ovn_datapaths_destroy(lr_datapaths); } void @@ -16503,6 +16907,8 @@ northd_init(struct northd_data *data) }; data->ovn_internal_version_changed = false; sset_init(&data->svc_monitor_lsps); + data->change_tracked = false; + ovs_list_init(&data->tracked_ls_changes.updated); } void @@ -16960,6 +17366,7 @@ void northd_run(struct northd_input *input_data, struct ovsdb_idl_txn *ovnnb_txn, struct ovsdb_idl_txn *ovnsb_txn) { + COVERAGE_INC(northd_run); stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); ovnnb_db_run(input_data, data, ovnnb_txn, ovnsb_txn); stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); diff --git a/northd/northd.h b/northd/northd.h index 35195549d6e4..f549fee0b5f7 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -65,6 +65,7 @@ struct northd_input { struct ovsdb_idl_index *sbrec_ha_chassis_grp_by_name; struct ovsdb_idl_index *sbrec_ip_mcast_by_dp; struct ovsdb_idl_index *sbrec_static_mac_binding_by_lport_ip; + struct ovsdb_idl_index *sbrec_fdb_by_dp_and_port; }; struct chassis_features { @@ -83,6 +84,22 @@ struct ovn_datapaths { struct ovn_datapath **array; }; +/* Track what's changed for a single LS. + * Now only track port changes. */ +struct ls_change { + struct ovs_list list_node; + struct ovn_datapath *od; + struct ovs_list added_ports; + struct ovs_list deleted_ports; + struct ovs_list updated_ports; +}; + +/* Track what's changed for logical switches. + * Now only track updated ones (added or deleted may be supported in the + * future). */ +struct tracked_ls_changes { + struct ovs_list updated; /* Contains struct ls_change */ +}; struct northd_data { /* Global state for 'en-northd'. */ @@ -98,6 +115,8 @@ struct northd_data { bool ovn_internal_version_changed; struct chassis_features features; struct sset svc_monitor_lsps; + bool change_tracked; + struct tracked_ls_changes tracked_ls_changes; }; struct lflow_data { @@ -291,13 +310,19 @@ struct ovn_datapath { /* Port groups related to the datapath, used only when nbs is NOT NULL. */ struct hmap nb_pgs; - struct ovs_list port_list; + /* Map of ovn_port objects belonging to this datapath. + * This map doesn't include derived ports. */ + struct hmap ports; }; void northd_run(struct northd_input *input_data, struct northd_data *data, struct ovsdb_idl_txn *ovnnb_txn, struct ovsdb_idl_txn *ovnsb_txn); +bool northd_handle_ls_changes(struct ovsdb_idl_txn *, + const struct northd_input *, + struct northd_data *); +void destroy_northd_data_tracked_changes(struct northd_data *); void northd_destroy(struct northd_data *data); void northd_init(struct northd_data *data); void northd_indices_create(struct northd_data *data, diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index 58098fa91c06..428237e432c2 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -8975,3 +8975,62 @@ mac_binding_timestamp: true AT_CLEANUP ]) + +OVN_FOR_EACH_NORTHD_NO_HV([ +AT_SETUP([LSP incremental processing]) +ovn_start + +net_add n1 +sim_add hv1 +as hv1 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.11 +ovs-vsctl add-port br-int lsp0-0 -- set interface lsp0-0 external_ids:iface-id=lsp0-0 +ovs-vsctl add-port br-int lsp0-1 -- set interface lsp0-1 external_ids:iface-id=lsp0-1 +ovs-vsctl add-port br-int lsp0-2 -- set interface lsp0-2 external_ids:iface-id=lsp0-2 + +check ovn-nbctl --wait=hv ls-add ls0 + +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=hv lsp-add ls0 lsp0-0 -- lsp-set-addresses lsp0-0 "unknown" +OVS_WAIT_UNTIL([test `as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute` = 5]) +OVS_WAIT_UNTIL([test `as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute` = 5]) + +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=hv lsp-add ls0 lsp0-1 -- lsp-set-addresses lsp0-1 "aa:aa:aa:00:00:01 192.168.0.11" +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 +]) +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [6 +]) + +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=hv lsp-add ls0 lsp0-2 -- lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:02 192.168.0.12" +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 +]) +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [6 +]) + +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=hv lsp-del lsp0-1 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [1 +]) +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +]) + +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=hv lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:88 192.168.0.88" +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [1 +]) +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +]) + +# No change, no recompute +check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats +check ovn-nbctl --wait=sb sync +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 +]) + +OVN_CLEANUP([hv1]) +AT_CLEANUP +]) + From patchwork Sat May 13 00:03:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5V76Rdnz20dF for ; Sat, 13 May 2023 10:04:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 877E584C6C; Sat, 13 May 2023 00:04:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 877E584C6C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tOTrw5nDaSAt; Sat, 13 May 2023 00:04:43 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 92123843E4; Sat, 13 May 2023 00:04:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 92123843E4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 996FAC008F; Sat, 13 May 2023 00:04:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 18DC0C002A for ; Sat, 13 May 2023 00:04:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D138842E6A for ; Sat, 13 May 2023 00:04:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org D138842E6A X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1n83OYggTEQQ for ; Sat, 13 May 2023 00:04:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 203A042E64 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id 203A042E64 for ; Sat, 13 May 2023 00:04:32 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 98ADE1C0002; Sat, 13 May 2023 00:04:30 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:50 -0700 Message-Id: <20230513000356.2475960-9-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 08/14] northd: Refactor the logic related to "unknown" mc_group. 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" This patch moves the logic responsible for adding ports to the 'unknown' multicast group. This logic is now part of the build_mcast_groups() function. This not only improves readability but also removes the unnecessary dependency of mcast_groups from build_lflows(). Signed-off-by: Han Zhou --- northd/northd.c | 73 ++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index be206d7a3622..2cb568b8e1dd 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -2651,6 +2651,9 @@ join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, parse_lsp_addrs(op); op->od = od; + if (op->has_unknown) { + od->has_unknown = true; + } hmap_insert(&od->ports, &op->dp_node, hmap_node_hash(&op->key_node)); tag_alloc_add_existing_tags(tag_alloc_table, nbsp); @@ -6232,6 +6235,8 @@ build_lswitch_learn_fdb_od( ovs_assert(od->nbs); ovn_lflow_add(lflows, od, S_SWITCH_IN_LOOKUP_FDB, 0, "1", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_IN_PUT_FDB, 0, "1", "next;"); + ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_LKUP, 0, "1", + "outport = get_fdb(eth.dst); next;"); } /* Egress tables 8: Egress port security - IP (priority 0) @@ -8834,36 +8839,20 @@ is_vlan_transparent(const struct ovn_datapath *od) } static void -build_lswitch_flows(const struct ovn_datapaths *ls_datapaths, - struct hmap *lflows) -{ - /* This flow table structure is documented in ovn-northd(8), so please - * update ovn-northd.8.xml if you change anything. */ - - struct ovn_datapath *od; - - /* Ingress table 25/26: Destination lookup for unknown MACs - * (priority 0). */ - HMAP_FOR_EACH (od, key_node, &ls_datapaths->datapaths) { - if (!od->nbs) { - continue; - } - - ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_LKUP, 0, "1", - "outport = get_fdb(eth.dst); next;"); - - if (od->has_unknown) { - ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 50, - "outport == \"none\"", - "outport = \""MC_UNKNOWN "\"; output;"); - } else { - ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 50, - "outport == \"none\"", debug_drop_action()); - } - ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 0, "1", - "output;"); +build_lswitch_lflows_l2_unknown(struct ovn_datapath *od, + struct hmap *lflows) +{ + /* Ingress table 25/26: Destination lookup for unknown MACs. */ + if (od->has_unknown) { + ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 50, + "outport == \"none\"", + "outport = \""MC_UNKNOWN "\"; output;"); + } else { + ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 50, + "outport == \"none\"", debug_drop_action()); } - + ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_UNKNOWN, 0, "1", + "output;"); } /* Build pre-ACL and ACL tables for both ingress and egress. @@ -9613,13 +9602,10 @@ build_lswitch_ip_mcast_igmp_mld(struct ovn_igmp_group *igmp_group, } } -static struct ovs_mutex mcgroup_mutex = OVS_MUTEX_INITIALIZER; - /* Ingress table 25: Destination lookup, unicast handling (priority 50), */ static void build_lswitch_ip_unicast_lookup(struct ovn_port *op, struct hmap *lflows, - struct hmap *mcgroups, struct ds *actions, struct ds *match) { @@ -9658,12 +9644,7 @@ build_lswitch_ip_unicast_lookup(struct ovn_port *op, ds_cstr(actions), &op->nbsp->header_); } else if (!strcmp(op->nbsp->addresses[i], "unknown")) { - if (lsp_enabled) { - ovs_mutex_lock(&mcgroup_mutex); - ovn_multicast_add(mcgroups, &mc_unknown, op); - ovs_mutex_unlock(&mcgroup_mutex); - op->od->has_unknown = true; - } + continue; } else if (is_dynamic_lsp_address(op->nbsp->addresses[i])) { if (!op->nbsp->dynamic_addresses || !ovs_scan(op->nbsp->dynamic_addresses, @@ -15157,7 +15138,6 @@ struct lswitch_flow_build_info { const struct hmap *lr_ports; const struct hmap *port_groups; struct hmap *lflows; - struct hmap *mcgroups; struct hmap *igmp_groups; const struct shash *meter_groups; const struct hmap *lbs; @@ -15195,6 +15175,7 @@ build_lswitch_and_lrouter_iterate_by_ls(struct ovn_datapath *od, lsi->meter_groups); build_lswitch_output_port_sec_od(od, lsi->lflows); build_lswitch_lb_affinity_default_flows(od, lsi->lflows); + build_lswitch_lflows_l2_unknown(od, lsi->lflows); } /* Helper function to combine all lflow generation which is iterated by @@ -15256,8 +15237,8 @@ build_lswitch_and_lrouter_iterate_by_lsp(struct ovn_port *op, build_lswitch_dhcp_options_and_response(op, lsi->lflows, lsi->meter_groups); build_lswitch_external_port(op, lsi->lflows); - build_lswitch_ip_unicast_lookup(op, lsi->lflows, lsi->mcgroups, - &lsi->actions, &lsi->match); + build_lswitch_ip_unicast_lookup(op, lsi->lflows, &lsi->actions, + &lsi->match); /* Build Logical Router Flows. */ build_ip_routing_flows_for_router_type_lsp(op, lsi->lr_ports, @@ -15450,7 +15431,6 @@ build_lswitch_and_lrouter_flows(const struct ovn_datapaths *ls_datapaths, const struct hmap *lr_ports, const struct hmap *port_groups, struct hmap *lflows, - struct hmap *mcgroups, struct hmap *igmp_groups, const struct shash *meter_groups, const struct hmap *lbs, @@ -15478,7 +15458,6 @@ build_lswitch_and_lrouter_flows(const struct ovn_datapaths *ls_datapaths, lsiv[index].ls_ports = ls_ports; lsiv[index].lr_ports = lr_ports; lsiv[index].port_groups = port_groups; - lsiv[index].mcgroups = mcgroups; lsiv[index].igmp_groups = igmp_groups; lsiv[index].meter_groups = meter_groups; lsiv[index].lbs = lbs; @@ -15513,7 +15492,6 @@ build_lswitch_and_lrouter_flows(const struct ovn_datapaths *ls_datapaths, .lr_ports = lr_ports, .port_groups = port_groups, .lflows = lflows, - .mcgroups = mcgroups, .igmp_groups = igmp_groups, .meter_groups = meter_groups, .lbs = lbs, @@ -15572,7 +15550,6 @@ build_lswitch_and_lrouter_flows(const struct ovn_datapaths *ls_datapaths, } free(svc_check_match); - build_lswitch_flows(ls_datapaths, lflows); } static void @@ -15672,7 +15649,7 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, input_data->ls_ports, input_data->lr_ports, input_data->port_groups, lflows, - &mcast_groups, &igmp_groups, + &igmp_groups, input_data->meter_groups, input_data->lbs, input_data->bfd_connections, input_data->features); @@ -16576,6 +16553,10 @@ build_mcast_groups(const struct sbrec_igmp_group_table *sbrec_igmp_group_table, ovn_multicast_add(mcast_groups, &mc_flood_l2, op); } + if (op->has_unknown) { + ovn_multicast_add(mcast_groups, &mc_unknown, op); + } + /* If this port is connected to a multicast router then add it * to the MC_MROUTER_FLOOD group. */ From patchwork Sat May 13 00:03:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Vm0nD7z20dC for ; Sat, 13 May 2023 10:05:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1A97B70345; Sat, 13 May 2023 00:05:18 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1A97B70345 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m8OJrC_0K5jG; Sat, 13 May 2023 00:05:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id B3337702FA; Sat, 13 May 2023 00:04:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B3337702FA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 55CCBC009B; Sat, 13 May 2023 00:04:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 45B97C0089 for ; Sat, 13 May 2023 00:04:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2436E42E4C for ; Sat, 13 May 2023 00:04:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2436E42E4C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C9DdlsSNf36w for ; Sat, 13 May 2023 00:04:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 8158B42C67 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp2.osuosl.org (Postfix) with ESMTPS id 8158B42C67 for ; Sat, 13 May 2023 00:04:34 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id EFCA11C0004; Sat, 13 May 2023 00:04:31 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:51 -0700 Message-Id: <20230513000356.2475960-10-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 09/14] northd: Incremental processing of VIF additions in 'lflow' node. 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" This patch introduces a change handler for 'northd' input within the 'lflow' node. It specifically handles cases when VIFs are created, which is an easier start for lflow incremental processing. Support for update/delete will be added later. Below are the performance test results simulating an ovn-k8s topology of 500 nodes x 50 lsp per node: Before: ovn-nbctl --wait=hv --print-wait-time lsp-add ls_1_0001 lsp_1_0001_01 -- lsp-set-addresses lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" -- lsp-set-port-security lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" ovn-northd completion: 773ms After: ovn-nbctl --wait=hv --print-wait-time lsp-add ls_1_0001 lsp_1_0001_01 -- lsp-set-addresses lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" -- lsp-set-port-security lsp_1_0001_01 "ff:f1:bb:00:01:01 1.0.1.101" ovn-northd completion: 30ms It is more than 95% reduction (or 20x faster). Signed-off-by: Han Zhou --- northd/en-lflow.c | 82 ++++++++----- northd/en-lflow.h | 1 + northd/inc-proc-northd.c | 2 +- northd/northd.c | 245 +++++++++++++++++++++++++++++++++------ northd/northd.h | 6 +- tests/ovn-northd.at | 4 +- 6 files changed, 277 insertions(+), 63 deletions(-) diff --git a/northd/en-lflow.c b/northd/en-lflow.c index 081ec7c353ed..28ab1c67fb8f 100644 --- a/northd/en-lflow.c +++ b/northd/en-lflow.c @@ -30,43 +30,49 @@ VLOG_DEFINE_THIS_MODULE(en_lflow); -void en_lflow_run(struct engine_node *node, void *data) +static void +lflow_get_input_data(struct engine_node *node, + struct lflow_input *lflow_input) { - const struct engine_context *eng_ctx = engine_get_context(); - - struct lflow_input lflow_input; - struct northd_data *northd_data = engine_get_input_data("northd", node); - - struct hmap bfd_connections = HMAP_INITIALIZER(&bfd_connections); - - lflow_input.nbrec_bfd_table = + lflow_input->nbrec_bfd_table = EN_OVSDB_GET(engine_get_input("NB_bfd", node)); - lflow_input.sbrec_bfd_table = + lflow_input->sbrec_bfd_table = EN_OVSDB_GET(engine_get_input("SB_bfd", node)); - lflow_input.sbrec_logical_flow_table = + lflow_input->sbrec_logical_flow_table = EN_OVSDB_GET(engine_get_input("SB_logical_flow", node)); - lflow_input.sbrec_multicast_group_table = + lflow_input->sbrec_multicast_group_table = EN_OVSDB_GET(engine_get_input("SB_multicast_group", node)); - lflow_input.sbrec_igmp_group_table = + lflow_input->sbrec_igmp_group_table = EN_OVSDB_GET(engine_get_input("SB_igmp_group", node)); - lflow_input.sbrec_mcast_group_by_name_dp = + lflow_input->sbrec_mcast_group_by_name_dp = engine_ovsdb_node_get_index( engine_get_input("SB_multicast_group", node), "sbrec_mcast_group_by_name"); - lflow_input.ls_datapaths = &northd_data->ls_datapaths; - lflow_input.lr_datapaths = &northd_data->lr_datapaths; - lflow_input.ls_ports = &northd_data->ls_ports; - lflow_input.lr_ports = &northd_data->lr_ports; - lflow_input.port_groups = &northd_data->port_groups; - lflow_input.meter_groups = &northd_data->meter_groups; - lflow_input.lbs = &northd_data->lbs; - lflow_input.bfd_connections = &bfd_connections; - lflow_input.features = &northd_data->features; - lflow_input.ovn_internal_version_changed = + lflow_input->ls_datapaths = &northd_data->ls_datapaths; + lflow_input->lr_datapaths = &northd_data->lr_datapaths; + lflow_input->ls_ports = &northd_data->ls_ports; + lflow_input->lr_ports = &northd_data->lr_ports; + lflow_input->port_groups = &northd_data->port_groups; + lflow_input->meter_groups = &northd_data->meter_groups; + lflow_input->lbs = &northd_data->lbs; + lflow_input->features = &northd_data->features; + lflow_input->ovn_internal_version_changed = northd_data->ovn_internal_version_changed; + lflow_input->bfd_connections = NULL; +} + +void en_lflow_run(struct engine_node *node, void *data) +{ + const struct engine_context *eng_ctx = engine_get_context(); + + struct lflow_input lflow_input; + lflow_get_input_data(node, &lflow_input); + + struct hmap bfd_connections = HMAP_INITIALIZER(&bfd_connections); + lflow_input.bfd_connections = &bfd_connections; struct lflow_data *lflow_data = data; lflow_data_destroy(lflow_data); @@ -76,8 +82,8 @@ void en_lflow_run(struct engine_node *node, void *data) build_bfd_table(eng_ctx->ovnsb_idl_txn, lflow_input.nbrec_bfd_table, lflow_input.sbrec_bfd_table, - &bfd_connections, - &northd_data->lr_ports); + lflow_input.lr_ports, + &bfd_connections); build_lflows(eng_ctx->ovnsb_idl_txn, &lflow_input, &lflow_data->lflows); bfd_cleanup_connections(lflow_input.nbrec_bfd_table, &bfd_connections); @@ -87,6 +93,30 @@ void en_lflow_run(struct engine_node *node, void *data) engine_set_node_state(node, EN_UPDATED); } +bool +lflow_northd_handler(struct engine_node *node, + void *data) +{ + struct northd_data *northd_data = engine_get_input_data("northd", node); + if (!northd_data->change_tracked) { + return false; + } + const struct engine_context *eng_ctx = engine_get_context(); + struct lflow_data *lflow_data = data; + + struct lflow_input lflow_input; + lflow_get_input_data(node, &lflow_input); + + if (!lflow_handle_northd_ls_changes(eng_ctx->ovnsb_idl_txn, + &northd_data->tracked_ls_changes, + &lflow_input, &lflow_data->lflows)) { + return false; + } + + engine_set_node_state(node, EN_UPDATED); + return true; +} + void *en_lflow_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg OVS_UNUSED) { diff --git a/northd/en-lflow.h b/northd/en-lflow.h index 0e4d522ff3fe..5e3fbc25e3e0 100644 --- a/northd/en-lflow.h +++ b/northd/en-lflow.h @@ -12,5 +12,6 @@ void en_lflow_run(struct engine_node *node, void *data); void *en_lflow_init(struct engine_node *node, struct engine_arg *arg); void en_lflow_cleanup(void *data); +bool lflow_northd_handler(struct engine_node *, void *data); #endif /* EN_LFLOW_H */ diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index f992a9ec8420..f6ceb8280624 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -182,7 +182,7 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, engine_add_input(&en_lflow, &en_sb_logical_flow, NULL); engine_add_input(&en_lflow, &en_sb_multicast_group, NULL); engine_add_input(&en_lflow, &en_sb_igmp_group, NULL); - engine_add_input(&en_lflow, &en_northd, NULL); + engine_add_input(&en_lflow, &en_northd, lflow_northd_handler); engine_add_input(&en_sync_to_sb_addr_set, &en_nb_address_set, sync_to_sb_addr_set_nb_address_set_handler); diff --git a/northd/northd.c b/northd/northd.c index 2cb568b8e1dd..32c18ab3c932 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -5500,6 +5500,7 @@ ovn_igmp_group_destroy(struct hmap *igmp_groups, struct ovn_lflow { struct hmap_node hmap_node; + struct ovs_list list_node; struct ovn_datapath *od; /* 'logical_datapath' in SB schema. */ unsigned long *dpg_bitmap; /* Bitmap of all datapaths by their 'index'.*/ @@ -5557,6 +5558,7 @@ ovn_lflow_init(struct ovn_lflow *lflow, struct ovn_datapath *od, char *match, char *actions, char *io_port, char *ctrl_meter, char *stage_hint, const char *where) { + ovs_list_init(&lflow->list_node); lflow->dpg_bitmap = bitmap_allocate(dp_bitmap_len); lflow->od = od; lflow->stage = stage; @@ -5685,7 +5687,18 @@ ovn_dp_group_add_with_reference(struct ovn_lflow *lflow_ref, /* Adds a row with the specified contents to the Logical_Flow table. * Version to use when hash bucket locking is NOT required. + * + * Note: This function can add generated lflows to the global variable + * temp_lflow_list as its output, controlled by the global variable + * add_lflow_to_temp_list. The caller of the ovn_lflow_add_... marcros can get + * a list of lflows generated by setting add_lflow_to_temp_list to true. The + * caller is responsible for initializing the temp_lflow_list, and also + * reset the add_lflow_to_temp_list to false when it is no longer needed. + * XXX: this mechanism is temporary and will be replaced when we add hash index + * to lflow_data and refactor related functions. */ +static bool add_lflow_to_temp_list = false; +static struct ovs_list temp_lflow_list; static void do_ovn_lflow_add(struct hmap *lflow_map, const struct ovn_datapath *od, const unsigned long *dp_bitmap, size_t dp_bitmap_len, @@ -5702,12 +5715,17 @@ do_ovn_lflow_add(struct hmap *lflow_map, const struct ovn_datapath *od, size_t bitmap_len = od ? ods_size(od->datapaths) : dp_bitmap_len; ovs_assert(bitmap_len); - old_lflow = ovn_lflow_find(lflow_map, NULL, stage, priority, match, - actions, ctrl_meter, hash); - if (old_lflow) { - ovn_dp_group_add_with_reference(old_lflow, od, dp_bitmap, - bitmap_len); - return; + if (add_lflow_to_temp_list) { + ovs_assert(od); + ovs_assert(!dp_bitmap); + } else { + old_lflow = ovn_lflow_find(lflow_map, NULL, stage, priority, match, + actions, ctrl_meter, hash); + if (old_lflow) { + ovn_dp_group_add_with_reference(old_lflow, od, dp_bitmap, + bitmap_len); + return; + } } lflow = xmalloc(sizeof *lflow); @@ -5728,6 +5746,10 @@ do_ovn_lflow_add(struct hmap *lflow_map, const struct ovn_datapath *od, hmap_insert_fast(lflow_map, &lflow->hmap_node, hash); thread_lflow_counter++; } + + if (add_lflow_to_temp_list) { + ovs_list_insert(&temp_lflow_list, &lflow->list_node); + } } /* Adds a row with the specified contents to the Logical_Flow table. */ @@ -9867,7 +9889,7 @@ void build_bfd_table(struct ovsdb_idl_txn *ovnsb_txn, const struct nbrec_bfd_table *nbrec_bfd_table, const struct sbrec_bfd_table *sbrec_bfd_table, - struct hmap *bfd_connections, struct hmap *lr_ports) + const struct hmap *lr_ports, struct hmap *bfd_connections) { struct hmap sb_only = HMAP_INITIALIZER(&sb_only); const struct sbrec_bfd *sb_bt; @@ -15219,32 +15241,28 @@ build_lswitch_and_lrouter_iterate_by_lr(struct ovn_datapath *od, */ static void build_lswitch_and_lrouter_iterate_by_lsp(struct ovn_port *op, - struct lswitch_flow_build_info *lsi) + const struct hmap *ls_ports, + const struct hmap *lr_ports, + const struct shash *meter_groups, + struct ds *match, + struct ds *actions, + struct hmap *lflows) { ovs_assert(op->nbsp); /* Build Logical Switch Flows. */ - build_lswitch_port_sec_op(op, lsi->lflows, &lsi->actions, &lsi->match); - build_lswitch_learn_fdb_op(op, lsi->lflows, &lsi->actions, - &lsi->match); - build_lswitch_arp_nd_responder_skip_local(op, lsi->lflows, - &lsi->match); - build_lswitch_arp_nd_responder_known_ips(op, lsi->lflows, - lsi->ls_ports, - lsi->meter_groups, - &lsi->actions, - &lsi->match); - build_lswitch_dhcp_options_and_response(op, lsi->lflows, - lsi->meter_groups); - build_lswitch_external_port(op, lsi->lflows); - build_lswitch_ip_unicast_lookup(op, lsi->lflows, &lsi->actions, - &lsi->match); + build_lswitch_port_sec_op(op, lflows, actions, match); + build_lswitch_learn_fdb_op(op, lflows, actions, match); + build_lswitch_arp_nd_responder_skip_local(op, lflows, match); + build_lswitch_arp_nd_responder_known_ips(op, lflows, ls_ports, + meter_groups, actions, match); + build_lswitch_dhcp_options_and_response(op, lflows, meter_groups); + build_lswitch_external_port(op, lflows); + build_lswitch_ip_unicast_lookup(op, lflows, actions, match); /* Build Logical Router Flows. */ - build_ip_routing_flows_for_router_type_lsp(op, lsi->lr_ports, - lsi->lflows); - build_arp_resolve_flows_for_lsp(op, lsi->lflows, lsi->lr_ports, - &lsi->match, &lsi->actions); + build_ip_routing_flows_for_router_type_lsp(op, lr_ports, lflows); + build_arp_resolve_flows_for_lsp(op, lflows, lr_ports, match, actions); } /* Helper function to combine all lflow generation which is iterated by logical @@ -15330,7 +15348,12 @@ build_lflows_thread(void *arg) if (stop_parallel_processing()) { return NULL; } - build_lswitch_and_lrouter_iterate_by_lsp(op, lsi); + build_lswitch_and_lrouter_iterate_by_lsp(op, lsi->ls_ports, + lsi->lr_ports, + lsi->meter_groups, + &lsi->match, + &lsi->actions, + lsi->lflows); } } for (bnum = control->id; @@ -15515,7 +15538,11 @@ build_lswitch_and_lrouter_flows(const struct ovn_datapaths *ls_datapaths, stopwatch_stop(LFLOWS_DATAPATHS_STOPWATCH_NAME, time_msec()); stopwatch_start(LFLOWS_PORTS_STOPWATCH_NAME, time_msec()); HMAP_FOR_EACH (op, key_node, ls_ports) { - build_lswitch_and_lrouter_iterate_by_lsp(op, &lsi); + build_lswitch_and_lrouter_iterate_by_lsp(op, lsi.ls_ports, + lsi.lr_ports, + lsi.meter_groups, + &lsi.match, &lsi.actions, + lsi.lflows); } HMAP_FOR_EACH (op, key_node, lr_ports) { build_lswitch_and_lrouter_iterate_by_lrp(op, &lsi); @@ -15629,6 +15656,20 @@ build_mcast_groups(const struct sbrec_igmp_group_table *sbrec_igmp_group_table, struct hmap *mcast_groups, struct hmap *igmp_groups); +static struct sbrec_multicast_group * +create_sb_multicast_group(struct ovsdb_idl_txn *ovnsb_txn, + const struct sbrec_datapath_binding *dp, + const char *name, + int64_t tunnel_key) +{ + struct sbrec_multicast_group *sbmc = + sbrec_multicast_group_insert(ovnsb_txn); + sbrec_multicast_group_set_datapath(sbmc, dp); + sbrec_multicast_group_set_name(sbmc, name); + sbrec_multicast_group_set_tunnel_key(sbmc, tunnel_key); + return sbmc; +} + /* Updates the Logical_Flow and Multicast_Group tables in the OVN_SB database, * constructing their contents based on the OVN_NB database. */ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, @@ -15995,10 +16036,8 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, ovn_multicast_destroy(&mcast_groups, mc); continue; } - sbmc = sbrec_multicast_group_insert(ovnsb_txn); - sbrec_multicast_group_set_datapath(sbmc, mc->datapath->sb); - sbrec_multicast_group_set_name(sbmc, mc->group->name); - sbrec_multicast_group_set_tunnel_key(sbmc, mc->group->key); + sbmc = create_sb_multicast_group(ovnsb_txn, mc->datapath->sb, + mc->group->name, mc->group->key); ovn_multicast_update_sbrec(mc, sbmc); ovn_multicast_destroy(&mcast_groups, mc); } @@ -16013,6 +16052,146 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, hmap_destroy(&mcast_groups); } +bool lflow_handle_northd_ls_changes(struct ovsdb_idl_txn *ovnsb_txn, + struct tracked_ls_changes *ls_changes, + struct lflow_input *lflow_input, + struct hmap *lflows) +{ + struct ls_change *ls_change; + LIST_FOR_EACH (ls_change, list_node, &ls_changes->updated) { + ovs_list_init(&temp_lflow_list); + add_lflow_to_temp_list = true; + if (!ovs_list_is_empty(&ls_change->updated_ports) || + !ovs_list_is_empty(&ls_change->deleted_ports)) { + /* XXX: implement lflow index so that we can handle updated and + * deleted LSPs incrementally. */ + ovs_list_init(&temp_lflow_list); + add_lflow_to_temp_list = false; + return false; + } + + const struct sbrec_multicast_group *sbmc_flood = + mcast_group_lookup(lflow_input->sbrec_mcast_group_by_name_dp, + MC_FLOOD, ls_change->od->sb); + const struct sbrec_multicast_group *sbmc_flood_l2 = + mcast_group_lookup(lflow_input->sbrec_mcast_group_by_name_dp, + MC_FLOOD_L2, ls_change->od->sb); + const struct sbrec_multicast_group *sbmc_unknown = + mcast_group_lookup(lflow_input->sbrec_mcast_group_by_name_dp, + MC_UNKNOWN, ls_change->od->sb); + + struct ovn_port *op; + LIST_FOR_EACH (op, list, &ls_change->added_ports) { + struct ds match = DS_EMPTY_INITIALIZER; + struct ds actions = DS_EMPTY_INITIALIZER; + build_lswitch_and_lrouter_iterate_by_lsp(op, lflow_input->ls_ports, + lflow_input->lr_ports, + lflow_input->meter_groups, + &match, &actions, + lflows); + ds_destroy(&match); + ds_destroy(&actions); + if (!sbmc_flood) { + sbmc_flood = create_sb_multicast_group(ovnsb_txn, + ls_change->od->sb, MC_FLOOD, OVN_MCAST_FLOOD_TUNNEL_KEY); + } + sbrec_multicast_group_update_ports_addvalue(sbmc_flood, op->sb); + + if (!sbmc_flood_l2) { + sbmc_flood_l2 = create_sb_multicast_group(ovnsb_txn, + ls_change->od->sb, MC_FLOOD_L2, + OVN_MCAST_FLOOD_L2_TUNNEL_KEY); + } + sbrec_multicast_group_update_ports_addvalue(sbmc_flood_l2, op->sb); + + if (op->has_unknown) { + if (!sbmc_unknown) { + sbmc_unknown = create_sb_multicast_group(ovnsb_txn, + ls_change->od->sb, MC_UNKNOWN, + OVN_MCAST_UNKNOWN_TUNNEL_KEY); + } + sbrec_multicast_group_update_ports_addvalue(sbmc_unknown, + op->sb); + } + } + /* Sync the newly added flows to SB. */ + struct ovn_lflow *lflow; + LIST_FOR_EACH (lflow, list_node, &temp_lflow_list) { + size_t n_datapaths; + struct ovn_datapath **datapaths_array; + if (ovn_stage_to_datapath_type(lflow->stage) == DP_SWITCH) { + n_datapaths = ods_size(lflow_input->ls_datapaths); + datapaths_array = lflow_input->ls_datapaths->array; + } else { + n_datapaths = ods_size(lflow_input->lr_datapaths); + datapaths_array = lflow_input->lr_datapaths->array; + } + uint32_t n_ods = bitmap_count1(lflow->dpg_bitmap, n_datapaths); + ovs_assert(n_ods == 1); + /* There is only one datapath, so it should be moved out of the + * group to a single 'od'. */ + size_t index = bitmap_scan(lflow->dpg_bitmap, true, 0, + n_datapaths); + + bitmap_set0(lflow->dpg_bitmap, index); + lflow->od = datapaths_array[index]; + + /* Logical flow should be re-hashed to allow lookups. */ + uint32_t hash = hmap_node_hash(&lflow->hmap_node); + /* Remove from lflows. */ + hmap_remove(lflows, &lflow->hmap_node); + hash = ovn_logical_flow_hash_datapath(&lflow->od->sb->header_.uuid, + hash); + /* Add back. */ + hmap_insert(lflows, &lflow->hmap_node, hash); + + /* Sync to SB. */ + const struct sbrec_logical_flow *sbflow; + sbflow = sbrec_logical_flow_insert(ovnsb_txn); + const char *pipeline = ovn_stage_get_pipeline_name(lflow->stage); + uint8_t table = ovn_stage_get_table(lflow->stage); + sbrec_logical_flow_set_logical_datapath(sbflow, lflow->od->sb); + sbrec_logical_flow_set_logical_dp_group(sbflow, NULL); + sbrec_logical_flow_set_pipeline(sbflow, pipeline); + sbrec_logical_flow_set_table_id(sbflow, table); + sbrec_logical_flow_set_priority(sbflow, lflow->priority); + sbrec_logical_flow_set_match(sbflow, lflow->match); + sbrec_logical_flow_set_actions(sbflow, lflow->actions); + if (lflow->io_port) { + struct smap tags = SMAP_INITIALIZER(&tags); + smap_add(&tags, "in_out_port", lflow->io_port); + sbrec_logical_flow_set_tags(sbflow, &tags); + smap_destroy(&tags); + } + sbrec_logical_flow_set_controller_meter(sbflow, lflow->ctrl_meter); + /* Trim the source locator lflow->where, which looks something like + * "ovn/northd/northd.c:1234", down to just the part following the + * last slash, e.g. "northd.c:1234". */ + const char *slash = strrchr(lflow->where, '/'); +#if _WIN32 + const char *backslash = strrchr(lflow->where, '\\'); + if (!slash || backslash > slash) { + slash = backslash; + } +#endif + const char *where = slash ? slash + 1 : lflow->where; + + struct smap ids = SMAP_INITIALIZER(&ids); + smap_add(&ids, "stage-name", ovn_stage_to_str(lflow->stage)); + smap_add(&ids, "source", where); + if (lflow->stage_hint) { + smap_add(&ids, "stage-hint", lflow->stage_hint); + } + sbrec_logical_flow_set_external_ids(sbflow, &ids); + smap_destroy(&ids); + } + } + ovs_list_init(&temp_lflow_list); + add_lflow_to_temp_list = false; + return true; + +} + /* Each port group in Port_Group table in OVN_Northbound has a corresponding * entry in Port_Group table in OVN_Southbound. In OVN_Northbound the entries * contains lport uuids, while in OVN_Southbound we store the lport names. diff --git a/northd/northd.h b/northd/northd.h index f549fee0b5f7..8be504811921 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -330,11 +330,15 @@ void northd_indices_create(struct northd_data *data, void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, struct lflow_input *input_data, struct hmap *lflows); +bool lflow_handle_northd_ls_changes(struct ovsdb_idl_txn *ovnsb_txn, + struct tracked_ls_changes *, + struct lflow_input *, struct hmap *lflows); void build_bfd_table(struct ovsdb_idl_txn *ovnsb_txn, const struct nbrec_bfd_table *, const struct sbrec_bfd_table *, - struct hmap *bfd_connections, struct hmap *lr_ports); + const struct hmap *lr_ports, + struct hmap *bfd_connections); void bfd_cleanup_connections(const struct nbrec_bfd_table *, struct hmap *bfd_map); void run_update_worker_pool(int n_threads); diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index 428237e432c2..deeb1d310925 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -9000,14 +9000,14 @@ check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-1 -- lsp-set-addresses lsp0-1 "aa:aa:aa:00:00:01 192.168.0.11" AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [6 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [5 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-2 -- lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:02 192.168.0.12" AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [6 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [5 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats From patchwork Sat May 13 00:03:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5VJ1VX0z20KD for ; Sat, 13 May 2023 10:04:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 54B4184C9D; Sat, 13 May 2023 00:04:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 54B4184C9D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mKuXu4TV5Na8; Sat, 13 May 2023 00:04:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6813B84C69; Sat, 13 May 2023 00:04:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6813B84C69 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B4F3EC0098; Sat, 13 May 2023 00:04:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 28E5AC0094 for ; Sat, 13 May 2023 00:04:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DEAC0841BC for ; Sat, 13 May 2023 00:04:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org DEAC0841BC X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6L3uMdSkhbWp for ; Sat, 13 May 2023 00:04:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org B5728847DA Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.osuosl.org (Postfix) with ESMTPS id B5728847DA for ; Sat, 13 May 2023 00:04:35 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 54D951C0003; Sat, 13 May 2023 00:04:33 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:52 -0700 Message-Id: <20230513000356.2475960-11-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 10/14] northd: Omit alerts for SB lflow and mc-group table. 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" The SB logical_flow table and multicast_group tables should be updated by northd only. Omitting the alerts (making them write-only) avoids unnecessary recompute triggered in northd. Signed-off-by: Han Zhou --- northd/ovn-northd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 3515b68a2e62..0b8bbfb95cf7 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -822,6 +822,14 @@ main(int argc, char *argv[]) ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_sb_global_col_nb_cfg); ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_address_set_col_name); ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_address_set_col_addresses); + for (size_t i = 0; i < SBREC_LOGICAL_FLOW_N_COLUMNS; i++) { + ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, + &sbrec_logical_flow_columns[i]); + } + for (size_t i = 0; i < SBREC_MULTICAST_GROUP_N_COLUMNS; i++) { + ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, + &sbrec_multicast_group_columns[i]); + } unixctl_command_register("sb-connection-status", "", 0, 0, ovn_conn_show, ovnsb_idl_loop.idl); From patchwork Sat May 13 00:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Vc1wzvz20dC for ; Sat, 13 May 2023 10:05:12 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9C22A84BF1; Sat, 13 May 2023 00:05:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 9C22A84BF1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AQo_Dbj71Ra2; Sat, 13 May 2023 00:05:07 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 90D3784CBA; Sat, 13 May 2023 00:04:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 90D3784CBA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E83C5C0036; Sat, 13 May 2023 00:04:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 10442C0089 for ; Sat, 13 May 2023 00:04:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 6239242EAF for ; Sat, 13 May 2023 00:04:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 6239242EAF X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0SvTSHsNb5BK for ; Sat, 13 May 2023 00:04:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 23E1242E6A Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id 23E1242E6A for ; Sat, 13 May 2023 00:04:36 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id A0EC21C0002; Sat, 13 May 2023 00:04:34 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:53 -0700 Message-Id: <20230513000356.2475960-12-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 11/14] northd: Split a new node "sync-from-sb" from the "northd" node. 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" The ovnsb_db_run() handles changes from SB DB and then updates NB/SB accordingly. These changes are not directly related to the rest part of the "northd" node, so split as a new node from it. This node doesn't maintain any data, but simply output to NB/SB DBs. It is similar to the sync-to-sb node but the input is from the other direction. This enables handling SB changes in different (more efficient) ways from each node. Signed-off-by: Han Zhou --- northd/automake.mk | 2 + northd/en-northd.c | 12 ++++-- northd/en-sync-from-sb.c | 86 ++++++++++++++++++++++++++++++++++++++++ northd/en-sync-from-sb.h | 11 +++++ northd/inc-proc-northd.c | 9 +++++ northd/northd.c | 67 +++++++++++++------------------ northd/northd.h | 14 +++++-- 7 files changed, 154 insertions(+), 47 deletions(-) create mode 100644 northd/en-sync-from-sb.c create mode 100644 northd/en-sync-from-sb.h diff --git a/northd/automake.mk b/northd/automake.mk index 3c3719a24936..f8e61a1683e8 100644 --- a/northd/automake.mk +++ b/northd/automake.mk @@ -16,6 +16,8 @@ northd_ovn_northd_SOURCES = \ northd/en-northd-output.h \ northd/en-sync-sb.c \ northd/en-sync-sb.h \ + northd/en-sync-from-sb.c \ + northd/en-sync-from-sb.h \ northd/inc-proc-northd.c \ northd/inc-proc-northd.h \ northd/ipam.c \ diff --git a/northd/en-northd.c b/northd/en-northd.c index f2bf98f774b1..785a592516c0 100644 --- a/northd/en-northd.c +++ b/northd/en-northd.c @@ -18,6 +18,7 @@ #include #include +#include "coverage.h" #include "en-northd.h" #include "lib/inc-proc-eng.h" #include "lib/ovn-nb-idl.h" @@ -25,11 +26,14 @@ * lib/ovn-parallel-hmap.h should be updated * to include this dependency itself */ #include "lib/ovn-parallel-hmap.h" +#include "stopwatch.h" +#include "lib/stopwatch-names.h" #include "northd.h" #include "lib/util.h" #include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(en_northd); +COVERAGE_DEFINE(northd_run); static void northd_get_input_data(struct engine_node *node, @@ -128,9 +132,11 @@ en_northd_run(struct engine_node *node, void *data) northd_init(data); northd_get_input_data(node, &input_data); - northd_run(&input_data, data, - eng_ctx->ovnnb_idl_txn, - eng_ctx->ovnsb_idl_txn); + COVERAGE_INC(northd_run); + stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); + ovnnb_db_run(&input_data, data, eng_ctx->ovnnb_idl_txn, + eng_ctx->ovnsb_idl_txn); + stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); engine_set_node_state(node, EN_UPDATED); } diff --git a/northd/en-sync-from-sb.c b/northd/en-sync-from-sb.c new file mode 100644 index 000000000000..55ece2d1627c --- /dev/null +++ b/northd/en-sync-from-sb.c @@ -0,0 +1,86 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "openvswitch/util.h" + +#include "en-sync-from-sb.h" +#include "include/ovn/expr.h" +#include "lib/inc-proc-eng.h" +#include "lib/lb.h" +#include "lib/ovn-nb-idl.h" +#include "lib/ovn-sb-idl.h" +#include "lib/ovn-util.h" +#include "stopwatch.h" +#include "lib/stopwatch-names.h" +#include "timeval.h" +#include "northd.h" + +#include "openvswitch/vlog.h" + +VLOG_DEFINE_THIS_MODULE(en_sync_from_sb); + +void * +en_sync_from_sb_init(struct engine_node *node OVS_UNUSED, + struct engine_arg *arg OVS_UNUSED) +{ + return NULL; +} + +void +en_sync_from_sb_run(struct engine_node *node, void *data OVS_UNUSED) +{ + const struct engine_context *eng_ctx = engine_get_context(); + struct northd_data *nd = engine_get_input_data("northd", node); + + const struct sbrec_port_binding_table *sb_pb_table = + EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); + const struct sbrec_ha_chassis_group_table *sb_ha_ch_grp_table = + EN_OVSDB_GET(engine_get_input("SB_ha_chassis_group", node)); + struct ovsdb_idl_index *sb_ha_ch_grp_by_name = + engine_ovsdb_node_get_index( + engine_get_input("SB_ha_chassis_group", node), + "sbrec_ha_chassis_grp_by_name"); + stopwatch_start(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec()); + ovnsb_db_run(eng_ctx->ovnnb_idl_txn, eng_ctx->ovnsb_idl_txn, + sb_pb_table, sb_ha_ch_grp_table, sb_ha_ch_grp_by_name, + &nd->ls_ports); + stopwatch_stop(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec()); +} + +bool +sync_from_sb_northd_handler(struct engine_node *node, + void *data OVS_UNUSED) +{ + struct northd_data *nd = engine_get_input_data("northd", node); + if (nd->change_tracked) { + /* There are only NB LSP related changes and the only field this node + * cares about is the "up" column, which is considered write-only to + * this node, so it is safe to ignore the change. (The real change + * matters to this node is always from the SB DB.) */ + return true; + } + return false; +} + +void +en_sync_from_sb_cleanup(void *data OVS_UNUSED) +{ + +} diff --git a/northd/en-sync-from-sb.h b/northd/en-sync-from-sb.h new file mode 100644 index 000000000000..1f0cfd2cdbc2 --- /dev/null +++ b/northd/en-sync-from-sb.h @@ -0,0 +1,11 @@ +#ifndef EN_SYNC_FROM_SB_H +#define EN_SYNC_FROM_SB_H 1 + +#include "lib/inc-proc-eng.h" + +void *en_sync_from_sb_init(struct engine_node *, struct engine_arg *); +void en_sync_from_sb_run(struct engine_node *, void *data); +void en_sync_from_sb_cleanup(void *data); +bool sync_from_sb_northd_handler(struct engine_node *, void *data OVS_UNUSED); + +#endif /* end of EN_SYNC_FROM_SB_H */ diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index f6ceb8280624..0642c9514b7c 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -34,6 +34,7 @@ #include "en-lflow.h" #include "en-northd-output.h" #include "en-sync-sb.h" +#include "en-sync-from-sb.h" #include "unixctl.h" #include "util.h" @@ -129,6 +130,7 @@ enum sb_engine_node { /* Define engine nodes for other nodes. They should be defined as static to * avoid sparse errors. */ static ENGINE_NODE_WITH_CLEAR_TRACK_DATA(northd, "northd"); +static ENGINE_NODE(sync_from_sb, "sync_from_sb"); static ENGINE_NODE(lflow, "lflow"); static ENGINE_NODE(mac_binding_aging, "mac_binding_aging"); static ENGINE_NODE(mac_binding_aging_waker, "mac_binding_aging_waker"); @@ -196,6 +198,13 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, * Right now this engine only syncs the SB Address_Set table. */ engine_add_input(&en_sync_to_sb, &en_sync_to_sb_addr_set, NULL); + + engine_add_input(&en_sync_from_sb, &en_northd, + sync_from_sb_northd_handler); + engine_add_input(&en_sync_from_sb, &en_sb_port_binding, NULL); + engine_add_input(&en_sync_from_sb, &en_sb_ha_chassis_group, NULL); + + engine_add_input(&en_northd_output, &en_sync_from_sb, NULL); engine_add_input(&en_northd_output, &en_sync_to_sb, northd_output_sync_to_sb_handler); engine_add_input(&en_northd_output, &en_lflow, diff --git a/northd/northd.c b/northd/northd.c index 32c18ab3c932..f65b69848a09 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -60,8 +60,6 @@ VLOG_DEFINE_THIS_MODULE(northd); -COVERAGE_DEFINE(northd_run); - static bool controller_event_en; static bool lflow_hash_lock_initialized = false; @@ -17116,7 +17114,7 @@ northd_destroy(struct northd_data *data) sset_destroy(&data->svc_monitor_lsps); } -static void +void ovnnb_db_run(struct northd_input *input_data, struct northd_data *data, struct ovsdb_idl_txn *ovnnb_txn, @@ -17331,16 +17329,16 @@ struct ha_chassis_group_node { }; static void -update_sb_ha_group_ref_chassis(struct northd_input *input_data, - struct shash *ha_ref_chassis_map) +update_sb_ha_group_ref_chassis( + const struct sbrec_ha_chassis_group_table *sb_ha_ch_grp_table, + struct shash *ha_ref_chassis_map) { struct hmap ha_ch_grps = HMAP_INITIALIZER(&ha_ch_grps); struct ha_chassis_group_node *ha_ch_grp_node; /* Initialize a set of all ha_chassis_groups in SB. */ const struct sbrec_ha_chassis_group *ha_ch_grp; - SBREC_HA_CHASSIS_GROUP_TABLE_FOR_EACH (ha_ch_grp, - input_data->sbrec_ha_chassis_group_table) { + SBREC_HA_CHASSIS_GROUP_TABLE_FOR_EACH (ha_ch_grp, sb_ha_ch_grp_table) { ha_ch_grp_node = xzalloc(sizeof *ha_ch_grp_node); ha_ch_grp_node->ha_ch_grp = ha_ch_grp; hmap_insert(&ha_ch_grps, &ha_ch_grp_node->hmap_node, @@ -17402,7 +17400,7 @@ update_sb_ha_group_ref_chassis(struct northd_input *input_data, * - 'ref_chassis' of hagrp1. */ static void -build_ha_chassis_group_ref_chassis(struct northd_input *input_data, +build_ha_chassis_group_ref_chassis(struct ovsdb_idl_index *ha_ch_grp_by_name, const struct sbrec_port_binding *sb, struct ovn_port *op, struct shash *ha_ref_chassis_map) @@ -17428,7 +17426,7 @@ build_ha_chassis_group_ref_chassis(struct northd_input *input_data, SSET_FOR_EACH (ha_group_name, &lr_group->ha_chassis_groups) { const struct sbrec_ha_chassis_group *sb_ha_chassis_grp; sb_ha_chassis_grp = ha_chassis_group_lookup_by_name( - input_data->sbrec_ha_chassis_grp_by_name, ha_group_name); + ha_ch_grp_by_name, ha_group_name); if (sb_ha_chassis_grp) { struct ha_ref_chassis_info *ref_ch_info = @@ -17443,17 +17441,18 @@ build_ha_chassis_group_ref_chassis(struct northd_input *input_data, * this column is not empty, it means we need to set the corresponding logical * port as 'up' in the northbound DB. */ static void -handle_port_binding_changes(struct northd_input *input_data, - struct ovsdb_idl_txn *ovnsb_txn, - struct hmap *ports, - struct shash *ha_ref_chassis_map) +handle_port_binding_changes(struct ovsdb_idl_txn *ovnsb_txn, + const struct sbrec_port_binding_table *sb_pb_table, + const struct sbrec_ha_chassis_group_table *sb_ha_ch_grp_table, + struct ovsdb_idl_index *sb_ha_ch_grp_by_name, + struct hmap *ls_ports, + struct shash *ha_ref_chassis_map) { const struct sbrec_port_binding *sb; bool build_ha_chassis_ref = false; if (ovnsb_txn) { const struct sbrec_ha_chassis_group *ha_ch_grp; - SBREC_HA_CHASSIS_GROUP_TABLE_FOR_EACH (ha_ch_grp, - input_data->sbrec_ha_chassis_group_table) { + SBREC_HA_CHASSIS_GROUP_TABLE_FOR_EACH (ha_ch_grp, sb_ha_ch_grp_table) { if (ha_ch_grp->n_ha_chassis > 1) { struct ha_ref_chassis_info *ref_ch_info = xzalloc(sizeof *ref_ch_info); @@ -17464,9 +17463,8 @@ handle_port_binding_changes(struct northd_input *input_data, } } - SBREC_PORT_BINDING_TABLE_FOR_EACH (sb, - input_data->sbrec_port_binding_table) { - struct ovn_port *op = ovn_port_find(ports, sb->logical_port); + SBREC_PORT_BINDING_TABLE_FOR_EACH (sb, sb_pb_table) { + struct ovn_port *op = ovn_port_find(ls_ports, sb->logical_port); if (!op || !op->nbsp) { /* The logical port doesn't exist for this port binding. This can @@ -17493,18 +17491,20 @@ handle_port_binding_changes(struct northd_input *input_data, if (build_ha_chassis_ref && ovnsb_txn && sb->chassis) { /* Check and add the chassis which has claimed this 'sb' * to the ha chassis group's ref_chassis if required. */ - build_ha_chassis_group_ref_chassis(input_data, sb, op, + build_ha_chassis_group_ref_chassis(sb_ha_ch_grp_by_name, sb, op, ha_ref_chassis_map); } } } /* Handle a fairly small set of changes in the southbound database. */ -static void -ovnsb_db_run(struct northd_input *input_data, - struct ovsdb_idl_txn *ovnnb_txn, +void +ovnsb_db_run(struct ovsdb_idl_txn *ovnnb_txn, struct ovsdb_idl_txn *ovnsb_txn, - struct hmap *ports) + const struct sbrec_port_binding_table *sb_pb_table, + const struct sbrec_ha_chassis_group_table *sb_ha_ch_grp_table, + struct ovsdb_idl_index *sb_ha_ch_grp_by_name, + struct hmap *ls_ports) { if (!ovnnb_txn || !ovsdb_idl_has_ever_connected(ovsdb_idl_txn_get_idl(ovnsb_txn))) { @@ -17512,29 +17512,16 @@ ovnsb_db_run(struct northd_input *input_data, } struct shash ha_ref_chassis_map = SHASH_INITIALIZER(&ha_ref_chassis_map); - handle_port_binding_changes(input_data, - ovnsb_txn, ports, &ha_ref_chassis_map); + handle_port_binding_changes(ovnsb_txn, sb_pb_table, sb_ha_ch_grp_table, + sb_ha_ch_grp_by_name, ls_ports, + &ha_ref_chassis_map); if (ovnsb_txn) { - update_sb_ha_group_ref_chassis(input_data, + update_sb_ha_group_ref_chassis(sb_ha_ch_grp_table, &ha_ref_chassis_map); } shash_destroy(&ha_ref_chassis_map); } -void northd_run(struct northd_input *input_data, - struct northd_data *data, - struct ovsdb_idl_txn *ovnnb_txn, - struct ovsdb_idl_txn *ovnsb_txn) -{ - COVERAGE_INC(northd_run); - stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); - ovnnb_db_run(input_data, data, ovnnb_txn, ovnsb_txn); - stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec()); - stopwatch_start(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec()); - ovnsb_db_run(input_data, ovnnb_txn, ovnsb_txn, &data->ls_ports); - stopwatch_stop(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec()); -} - const char * northd_get_svc_monitor_mac(void) { diff --git a/northd/northd.h b/northd/northd.h index 8be504811921..c77b6b3685bc 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -315,10 +315,16 @@ struct ovn_datapath { struct hmap ports; }; -void northd_run(struct northd_input *input_data, - struct northd_data *data, - struct ovsdb_idl_txn *ovnnb_txn, - struct ovsdb_idl_txn *ovnsb_txn); +void ovnnb_db_run(struct northd_input *input_data, + struct northd_data *data, + struct ovsdb_idl_txn *ovnnb_txn, + struct ovsdb_idl_txn *ovnsb_txn); +void ovnsb_db_run(struct ovsdb_idl_txn *ovnnb_txn, + struct ovsdb_idl_txn *ovnsb_txn, + const struct sbrec_port_binding_table *, + const struct sbrec_ha_chassis_group_table *, + struct ovsdb_idl_index *sb_ha_ch_grp_by_name, + struct hmap *ls_ports); bool northd_handle_ls_changes(struct ovsdb_idl_txn *, const struct northd_input *, struct northd_data *); From patchwork Sat May 13 00:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Vf41Pvz20dC for ; Sat, 13 May 2023 10:05:14 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 0F8BC42F19; Sat, 13 May 2023 00:05:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0F8BC42F19 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nGp5Wbx8ccB0; Sat, 13 May 2023 00:05:09 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 9293442EAD; Sat, 13 May 2023 00:04:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 9293442EAD Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 25AF7C009D; Sat, 13 May 2023 00:04:51 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17FECC008F for ; Sat, 13 May 2023 00:04:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id CB87142E69 for ; Sat, 13 May 2023 00:04:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CB87142E69 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aFHeJ_s-7ZbO for ; Sat, 13 May 2023 00:04:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 9A518429A0 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id 9A518429A0 for ; Sat, 13 May 2023 00:04:38 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id F327B1C0004; Sat, 13 May 2023 00:04:35 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:54 -0700 Message-Id: <20230513000356.2475960-13-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 12/14] northd: Avoid another round-trip for clearing additional-chassis-activated. 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" When a LSP has multiple requested-chassis specified, northd will set requested_additional_chassis column in SB port_binding, and ovn-controller on one or more chassis will claim the LSP and update the SB port_binding record's options:additional-chassis-activated. When the LSP is updated with only one (or no) chassis left in requested-chassis, northd will clear the requested_additional_chassis of the SB port_binding, and later when the SB port_binding update notification come back to northd, it will see that there is no requested_additional_chassis and then clear the options:additional-chassis-activated accordingly. This is very inefficient. It requires two round-trips just to clear the SB port_binding's options:additional-chassis-activated. The second round-trip is essentially a change to SB DB made by northd, which is triggered by another SB DB change also made by northd, which is in fact unnecessary. When the LSP is updated, northd can directly update the options:additional-chassis-activated when the column requested_additional_chassis is updated at the same time. Signed-off-by: Han Zhou --- northd/northd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index f65b69848a09..2dbcf219dcc9 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -3564,6 +3564,9 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, smap_add(&options, "vlan-passthru", "true"); } + ovn_port_update_sbrec_chassis(sbrec_chassis_by_name, + sbrec_chassis_by_hostname, op); + /* Retain activated chassis flags. */ if (op->sb->requested_additional_chassis) { const char *activated_str = smap_get( @@ -3610,9 +3613,6 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, * ha_chassis_group cleared in the same transaction. */ sbrec_port_binding_set_ha_chassis_group(op->sb, NULL); } - - ovn_port_update_sbrec_chassis(sbrec_chassis_by_name, - sbrec_chassis_by_hostname, op); } else { const char *chassis = NULL; if (op->peer && op->peer->od && op->peer->od->nbr) { From patchwork Sat May 13 00:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Vs4yl2z20dC for ; Sat, 13 May 2023 10:05:25 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 739B142F10; Sat, 13 May 2023 00:05:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 739B142F10 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fqA2Bbyu4UTi; Sat, 13 May 2023 00:05:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id C1A5142F4E; Sat, 13 May 2023 00:05:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org C1A5142F4E Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E67B4C0093; Sat, 13 May 2023 00:04:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 14893C0098 for ; Sat, 13 May 2023 00:04:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B2B9E42ED5 for ; Sat, 13 May 2023 00:04:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B2B9E42ED5 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ioy8WNVPfFTK for ; Sat, 13 May 2023 00:04:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 743C442EA1 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp4.osuosl.org (Postfix) with ESMTPS id 743C442EA1 for ; Sat, 13 May 2023 00:04:40 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 4B0F91C0005; Sat, 13 May 2023 00:04:37 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:55 -0700 Message-Id: <20230513000356.2475960-14-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 13/14] northd: Incremental processing of SB port_binding in "northd" node. 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" Most SB port_binding changes do not need to be handled by "northd" node, because they are either result of SB transactions from northd itself, or changes already handled by sync-from-sb node. This change reduces number of recompute of both "northd" and "lflow" nodes that would have been triggered by SB port_binding changes. Now for common VIF changes there is zero recompute of "northd" node. Signed-off-by: Han Zhou --- northd/en-northd.c | 18 ++++++++++++++ northd/en-northd.h | 1 + northd/inc-proc-northd.c | 12 ++++++---- northd/northd.c | 52 ++++++++++++++++++++++++++++++++++++++++ northd/northd.h | 2 ++ tests/ovn-northd.at | 16 ++++++------- 6 files changed, 88 insertions(+), 13 deletions(-) diff --git a/northd/en-northd.c b/northd/en-northd.c index 785a592516c0..044fa7019023 100644 --- a/northd/en-northd.c +++ b/northd/en-northd.c @@ -187,6 +187,24 @@ northd_nb_logical_switch_handler(struct engine_node *node, return true; } +bool +northd_sb_port_binding_handler(struct engine_node *node, + void *data) +{ + struct northd_data *nd = data; + + struct northd_input input_data; + + northd_get_input_data(node, &input_data); + + if (!northd_handle_sb_port_binding_changes( + input_data.sbrec_port_binding_table, &nd->ls_ports)) { + return false; + } + + return true; +} + void *en_northd_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg OVS_UNUSED) diff --git a/northd/en-northd.h b/northd/en-northd.h index a53a162bda48..20cc77f108a3 100644 --- a/northd/en-northd.h +++ b/northd/en-northd.h @@ -16,5 +16,6 @@ void en_northd_cleanup(void *data); void en_northd_clear_tracked_data(void *data); bool northd_nb_nb_global_handler(struct engine_node *, void *data OVS_UNUSED); bool northd_nb_logical_switch_handler(struct engine_node *, void *data); +bool northd_sb_port_binding_handler(struct engine_node *, void *data); #endif /* EN_NORTHD_H */ diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index 0642c9514b7c..3ec791c8941c 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -143,10 +143,6 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, { /* Define relationships between nodes where first argument is dependent * on the second argument */ - engine_add_input(&en_northd, &en_nb_nb_global, - northd_nb_nb_global_handler); - engine_add_input(&en_northd, &en_nb_logical_switch, - northd_nb_logical_switch_handler); engine_add_input(&en_northd, &en_nb_port_group, NULL); engine_add_input(&en_northd, &en_nb_load_balancer, NULL); engine_add_input(&en_northd, &en_nb_load_balancer_group, NULL); @@ -163,7 +159,6 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, engine_add_input(&en_northd, &en_sb_mirror, NULL); engine_add_input(&en_northd, &en_sb_meter, NULL); engine_add_input(&en_northd, &en_sb_datapath_binding, NULL); - engine_add_input(&en_northd, &en_sb_port_binding, NULL); engine_add_input(&en_northd, &en_sb_mac_binding, NULL); engine_add_input(&en_northd, &en_sb_dns, NULL); engine_add_input(&en_northd, &en_sb_ha_chassis_group, NULL); @@ -174,6 +169,13 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, engine_add_input(&en_northd, &en_sb_static_mac_binding, NULL); engine_add_input(&en_northd, &en_sb_chassis_template_var, NULL); + engine_add_input(&en_northd, &en_sb_port_binding, + northd_sb_port_binding_handler); + engine_add_input(&en_northd, &en_nb_nb_global, + northd_nb_nb_global_handler); + engine_add_input(&en_northd, &en_nb_logical_switch, + northd_nb_logical_switch_handler); + engine_add_input(&en_mac_binding_aging, &en_nb_nb_global, NULL); engine_add_input(&en_mac_binding_aging, &en_sb_mac_binding, NULL); engine_add_input(&en_mac_binding_aging, &en_northd, NULL); diff --git a/northd/northd.c b/northd/northd.c index 2dbcf219dcc9..ce0912570afd 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -5144,6 +5144,58 @@ fail: return false; } +bool +northd_handle_sb_port_binding_changes( + const struct sbrec_port_binding_table *sbrec_port_binding_table, + struct hmap *ls_ports) +{ + const struct sbrec_port_binding *pb; + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, sbrec_port_binding_table) { + struct ovn_port *op = ovn_port_find(ls_ports, pb->logical_port); + if (op && !op->lsp_can_be_inc_processed) { + return false; + } + if (sbrec_port_binding_is_new(pb)) { + /* Most likely the PB was created by northd and this is the + * notification of that trasaction. So we just update the sb + * pointer in northd data. Fallback to recompute otherwise. */ + if (!op) { + VLOG_WARN_RL(&rl, "A port-binding for %s is created but the " + "LSP is not found.", pb->logical_port); + return false; + } + op->sb = pb; + } else if (sbrec_port_binding_is_deleted(pb)) { + /* Most likely the PB was deleted by northd and this is the + * notification of that transaction, and we can ignore in this + * case. Fallback to recompute otherwise, to avoid dangling + * sb idl pointers and other unexpected behavior. */ + if (op) { + VLOG_WARN_RL(&rl, "A port-binding for %s is deleted but the " + "LSP still exists.", pb->logical_port); + return false; + } + } else { + /* The PB is updated, most likely because of binding/unbinding + * to/from a chassis, and we can ignore the change (updating NB + * "up" will be handled in the engine node "sync_from_sb"). + * Fallback to recompute for anything unexpected. */ + if (!op) { + VLOG_WARN_RL(&rl, "A port-binding for %s is updated but the " + "LSP is not found.", pb->logical_port); + return false; + } + if (op->sb != pb) { + VLOG_WARN_RL(&rl, "A port-binding for %s is updated with a new" + "IDL row, which is unusual.", pb->logical_port); + return false; + } + } + } + return true; +} + struct multicast_group { const char *name; uint16_t key; /* OVN_MIN_MULTICAST...OVN_MAX_MULTICAST. */ diff --git a/northd/northd.h b/northd/northd.h index c77b6b3685bc..1a36ddb385c5 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -339,6 +339,8 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, bool lflow_handle_northd_ls_changes(struct ovsdb_idl_txn *ovnsb_txn, struct tracked_ls_changes *, struct lflow_input *, struct hmap *lflows); +bool northd_handle_sb_port_binding_changes( + const struct sbrec_port_binding_table *, struct hmap *ls_ports); void build_bfd_table(struct ovsdb_idl_txn *ovnsb_txn, const struct nbrec_bfd_table *, diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index deeb1d310925..efe6073b6a2c 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -8998,30 +8998,30 @@ OVS_WAIT_UNTIL([test `as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-1 -- lsp-set-addresses lsp0-1 "aa:aa:aa:00:00:01 192.168.0.11" -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [5 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-2 -- lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:02 192.168.0.12" -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [3 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [5 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-del lsp0-1 -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [1 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [1 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:88 192.168.0.88" -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [1 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [1 ]) # No change, no recompute From patchwork Sat May 13 00:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1780870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ5Vz0651z20dC for ; Sat, 13 May 2023 10:05:30 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A174884D63; Sat, 13 May 2023 00:05:28 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A174884D63 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6Gb2y7Ov-TQg; Sat, 13 May 2023 00:05:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2CBD483B69; Sat, 13 May 2023 00:05:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 2CBD483B69 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D7930C0036; Sat, 13 May 2023 00:05:08 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 124D1C0036 for ; Sat, 13 May 2023 00:05:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 0666941C9C for ; Sat, 13 May 2023 00:04:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0666941C9C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fNdDAMPovPCx for ; Sat, 13 May 2023 00:04:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org EFDF342E4D Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp2.osuosl.org (Postfix) with ESMTPS id EFDF342E4D for ; Sat, 13 May 2023 00:04:40 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 97AB01C0002; Sat, 13 May 2023 00:04:38 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Fri, 12 May 2023 17:03:56 -0700 Message-Id: <20230513000356.2475960-15-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230513000356.2475960-1-hzhou@ovn.org> References: <20230513000356.2475960-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 14/14] northd: Ignore "up" column change if ignore_lsp_down is true. 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" This change avoids the unnecessary change handling in "lflow" when NB_Global:options:ignore_lsp_down is true (default) if the only change of the LSP is the column "up". This further reduces the number of recompute of "lflow" to zero for the VIF creation-and-binding scenario. Signed-off-by: Han Zhou --- northd/northd.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ tests/ovn-northd.at | 4 ++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index ce0912570afd..f35965b16582 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -5007,6 +5007,44 @@ check_ls_changes_other_than_lsp(const struct nbrec_logical_switch *ls) return false; } +static bool +check_lsp_changes_other_than_up(const struct nbrec_logical_switch_port *nbsp) +{ + /* Check if the columns are changed in this row. */ + enum nbrec_logical_switch_port_column_id col; + for (col = 0; col < NBREC_LOGICAL_SWITCH_PORT_N_COLUMNS; col++) { + if (nbrec_logical_switch_port_is_updated(nbsp, col) && + col != NBREC_LOGICAL_SWITCH_PORT_COL_UP) { + return true; + } + } + + /* Check if the referenced rows are changed. + XXX: Need a better OVSDB IDL interface for this check. */ + if (nbsp->dhcpv4_options && + nbrec_dhcp_options_row_get_seqno(nbsp->dhcpv4_options, + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + if (nbsp->dhcpv6_options && + nbrec_dhcp_options_row_get_seqno(nbsp->dhcpv6_options, + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + if (nbsp->ha_chassis_group && + nbrec_ha_chassis_group_row_get_seqno(nbsp->ha_chassis_group, + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + for (size_t i = 0; i < nbsp->n_mirror_rules; i++) { + if (nbrec_mirror_row_get_seqno(nbsp->mirror_rules[i], + OVSDB_IDL_CHANGE_MODIFY) > 0) { + return true; + } + } + return false; +} + /* Return true if changes are handled incrementally, false otherwise. * When there are any changes, try to track what's exactly changed and set * northd_data->change_tracked accordingly: change tracked - true, otherwise, @@ -5087,6 +5125,14 @@ northd_handle_ls_changes(struct ovsdb_idl_txn *ovnsb_idl_txn, * by this change. Fallback to recompute. */ goto fail; } + if (!check_lsp_is_up && + !check_lsp_changes_other_than_up(new_nbsp)) { + /* If the only change is the "up" column while the + * "ignore_lsp_down" is set to true, just ignore this + * change. */ + op->visited = true; + continue; + } ovn_port_destroy(&nd->ls_ports, op); op = ls_port_create(ovnsb_idl_txn, &nd->ls_ports, new_nbsp->name, new_nbsp, od, sb, diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index efe6073b6a2c..cfea065b8b84 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -9000,14 +9000,14 @@ check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-1 -- lsp-set-addresses lsp0-1 "aa:aa:aa:00:00:01 192.168.0.11" AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [0 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats check ovn-nbctl --wait=hv lsp-add ls0 lsp0-2 -- lsp-set-addresses lsp0-2 "aa:aa:aa:00:00:02 192.168.0.12" AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats northd recompute], [0], [0 ]) -AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [2 +AT_CHECK([as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats lflow recompute], [0], [0 ]) check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats