From patchwork Sat Dec 21 19:51:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1214587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47gGTb1ZSqz9sPc for ; Sun, 22 Dec 2019 06:51:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 4B9E187EA0; Sat, 21 Dec 2019 19:51:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FGSTFQNWUllV; Sat, 21 Dec 2019 19:51:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id BBEDF87E79; Sat, 21 Dec 2019 19:51:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 91D0EC1D84; Sat, 21 Dec 2019 19:51:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 494A2C077D for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 35B3087368 for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HeZThSE42XhK for ; Sat, 21 Dec 2019 19:51:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 306DC8733D for ; Sat, 21 Dec 2019 19:51:35 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [73.241.94.255]) (Authenticated sender: hzhou@ovn.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 78C5F240006; Sat, 21 Dec 2019 19:51:33 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sat, 21 Dec 2019 11:51:04 -0800 Message-Id: <1576957867-69488-2-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1576957867-69488-1-git-send-email-hzhou@ovn.org> References: <1576957867-69488-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH 2.12 1/4] ovn-controller.c: Refactor meter-table-list and meter-group-list commands. 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Remove redundant code. Acked-by: Dumitru Ceara Signed-off-by: Han Zhou --- ovn/controller/ovn-controller.c | 54 ++++++++++------------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 605c2b0..c8bf29d 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -69,8 +69,7 @@ VLOG_DEFINE_THIS_MODULE(main); static unixctl_cb_func ovn_controller_exit; static unixctl_cb_func ct_zone_list; -static unixctl_cb_func meter_table_list; -static unixctl_cb_func group_table_list; +static unixctl_cb_func extend_table_list; static unixctl_cb_func inject_pkt; static unixctl_cb_func ovn_controller_conn_show; @@ -1882,10 +1881,10 @@ main(int argc, char *argv[]) get_ofctrl_probe_interval(ovs_idl_loop.idl)); unixctl_command_register("group-table-list", "", 0, 0, - group_table_list, &ed_flow_output.group_table); + extend_table_list, &ed_flow_output.group_table); unixctl_command_register("meter-table-list", "", 0, 0, - meter_table_list, &ed_flow_output.meter_table); + extend_table_list, &ed_flow_output.meter_table); unixctl_command_register("ct-zone-list", "", 0, 0, ct_zone_list, &ed_runtime_data.ct_zones); @@ -2311,54 +2310,27 @@ ct_zone_list(struct unixctl_conn *conn, int argc OVS_UNUSED, } static void -meter_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED, - const char *argv[] OVS_UNUSED, void *meter_table_) +extend_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *extend_table_) { - struct ovn_extend_table *meter_table = meter_table_; + struct ovn_extend_table *extend_table = extend_table_; struct ds ds = DS_EMPTY_INITIALIZER; - struct simap meters = SIMAP_INITIALIZER(&meters); + struct simap items = SIMAP_INITIALIZER(&items); - struct ovn_extend_table_info *m_installed, *next_meter; - EXTEND_TABLE_FOR_EACH_INSTALLED (m_installed, next_meter, meter_table) { - simap_put(&meters, m_installed->name, m_installed->table_id); + struct ovn_extend_table_info *installed, *next; + EXTEND_TABLE_FOR_EACH_INSTALLED (installed, next, extend_table) { + simap_put(&items, installed->name, installed->table_id); } - const struct simap_node **nodes = simap_sort(&meters); - size_t n_nodes = simap_count(&meters); + const struct simap_node **nodes = simap_sort(&items); + size_t n_nodes = simap_count(&items); for (size_t i = 0; i < n_nodes; i++) { const struct simap_node *node = nodes[i]; ds_put_format(&ds, "%s: %d\n", node->name, node->data); } free(nodes); - simap_destroy(&meters); - - unixctl_command_reply(conn, ds_cstr(&ds)); - ds_destroy(&ds); -} - -static void -group_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED, - const char *argv[] OVS_UNUSED, void *group_table_) -{ - struct ovn_extend_table *group_table = group_table_; - struct ds ds = DS_EMPTY_INITIALIZER; - struct simap groups = SIMAP_INITIALIZER(&groups); - - struct ovn_extend_table_info *m_installed, *next_group; - EXTEND_TABLE_FOR_EACH_INSTALLED (m_installed, next_group, group_table) { - simap_put(&groups, m_installed->name, m_installed->table_id); - } - - const struct simap_node **nodes = simap_sort(&groups); - size_t n_nodes = simap_count(&groups); - for (size_t i = 0; i < n_nodes; i++) { - const struct simap_node *node = nodes[i]; - ds_put_format(&ds, "%s: %d\n", node->name, node->data); - } - - free(nodes); - simap_destroy(&groups); + simap_destroy(&items); unixctl_command_reply(conn, ds_cstr(&ds)); ds_destroy(&ds); From patchwork Sat Dec 21 19:51:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1214589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47gGTc6mrTz9sPh for ; Sun, 22 Dec 2019 06:51:48 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D22DD863E3; Sat, 21 Dec 2019 19:51:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Aj4PpW1RoFZM; Sat, 21 Dec 2019 19:51:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id BE052863E0; Sat, 21 Dec 2019 19:51:41 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83AD9C1D84; Sat, 21 Dec 2019 19:51:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id E3166C077D for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id D238086074 for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u5SLYd1mtOE5 for ; Sat, 21 Dec 2019 19:51:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by whitealder.osuosl.org (Postfix) with ESMTPS id 4CC3885FC4 for ; Sat, 21 Dec 2019 19:51:36 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [73.241.94.255]) (Authenticated sender: hzhou@ovn.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id CD274240005; Sat, 21 Dec 2019 19:51:34 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sat, 21 Dec 2019 11:51:05 -0800 Message-Id: <1576957867-69488-3-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1576957867-69488-1-git-send-email-hzhou@ovn.org> References: <1576957867-69488-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH 2.12 2/4] ovn-controller: Fix meter-table-list and group-table-list commands. 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" These commands are supposed to print existing items of the tables, but they actually print only items that is in existing table but not in desired table, which is useless because this would print nothing in normal conditions. The patch fixes it so that they behave as what the document says. Acked-by: Dumitru Ceara Signed-off-by: Han Zhou --- ovn/controller/ovn-controller.c | 6 +++--- tests/ovn.at | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index c8bf29d..e2fce92 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -2317,9 +2317,9 @@ extend_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED, struct ds ds = DS_EMPTY_INITIALIZER; struct simap items = SIMAP_INITIALIZER(&items); - struct ovn_extend_table_info *installed, *next; - EXTEND_TABLE_FOR_EACH_INSTALLED (installed, next, extend_table) { - simap_put(&items, installed->name, installed->table_id); + struct ovn_extend_table_info *item; + HMAP_FOR_EACH (item, hmap_node, &extend_table->existing) { + simap_put(&items, item->name, item->table_id); } const struct simap_node **nodes = simap_sort(&items); diff --git a/tests/ovn.at b/tests/ovn.at index 54aa19b..3acd8a1 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -7319,7 +7319,10 @@ echo "Meter duration: $d_secs" AT_SKIP_IF([test $d_secs -gt 9]) # Print some information that may help debugging. -as hv ovs-appctl -t ovn-controller meter-table-list +AT_CHECK([as hv ovs-appctl -t ovn-controller meter-table-list], [0], [dnl +http-rl1: 1 +http-rl2: 2 +]) as hv ovs-ofctl -O OpenFlow13 meter-stats br-int n_acl1=$(grep -c 'http-acl1' hv/ovn-controller.log) From patchwork Sat Dec 21 19:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1214590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47gGTg1Fpnz9sP3 for ; Sun, 22 Dec 2019 06:51:51 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 4CE8487F0C; Sat, 21 Dec 2019 19:51:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DsMXMWxrle-M; Sat, 21 Dec 2019 19:51:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id AA6B787ECD; Sat, 21 Dec 2019 19:51:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A839C1D88; Sat, 21 Dec 2019 19:51:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 08909C077D for ; Sat, 21 Dec 2019 19:51:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 02C0787368 for ; Sat, 21 Dec 2019 19:51:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 47dMlUMOVHyR for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 547DC8733D for ; Sat, 21 Dec 2019 19:51:38 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [73.241.94.255]) (Authenticated sender: hzhou@ovn.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 23A1E240002; Sat, 21 Dec 2019 19:51:35 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sat, 21 Dec 2019 11:51:06 -0800 Message-Id: <1576957867-69488-4-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1576957867-69488-1-git-send-email-hzhou@ovn.org> References: <1576957867-69488-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH 2.12 3/4] extend-table.c: Refactor code. 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Reuse xxx_clear() function in xxx_destroy() and remove redundant code. Acked-by: Dumitru Ceara Signed-off-by: Han Zhou --- ovn/lib/extend-table.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/ovn/lib/extend-table.c b/ovn/lib/extend-table.c index ccf70ca..3263da8 100644 --- a/ovn/lib/extend-table.c +++ b/ovn/lib/extend-table.c @@ -34,27 +34,6 @@ ovn_extend_table_init(struct ovn_extend_table *table) hmap_init(&table->existing); } -static void -ovn_extend_table_info_destroy(struct hmap *target) -{ - struct ovn_extend_table_info *e, *next; - HMAP_FOR_EACH_SAFE (e, next, hmap_node, target) { - hmap_remove(target, &e->hmap_node); - free(e->name); - free(e); - } - hmap_destroy(target); -} - -void -ovn_extend_table_destroy(struct ovn_extend_table *table) -{ - bitmap_free(table->table_ids); - - ovn_extend_table_info_destroy(&table->desired); - ovn_extend_table_info_destroy(&table->existing); -} - /* Finds and returns a group_info in 'existing' whose key is identical * to 'target''s key, or NULL if there is none. */ struct ovn_extend_table_info * @@ -91,6 +70,16 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) } } +void +ovn_extend_table_destroy(struct ovn_extend_table *table) +{ + ovn_extend_table_clear(table, false); + hmap_destroy(&table->desired); + ovn_extend_table_clear(table, true); + hmap_destroy(&table->existing); + bitmap_free(table->table_ids); +} + /* Remove an entry from existing table */ void ovn_extend_table_remove_existing(struct ovn_extend_table *table, From patchwork Sat Dec 21 19:51:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1214591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47gGTr5WSPz9sP3 for ; Sun, 22 Dec 2019 06:52:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 580AA87591; Sat, 21 Dec 2019 19:51:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X1JWJk3WC3R0; Sat, 21 Dec 2019 19:51:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 70B15875D6; Sat, 21 Dec 2019 19:51:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 599BEC1D7F; Sat, 21 Dec 2019 19:51:44 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id BFE14C077D for ; Sat, 21 Dec 2019 19:51:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id AE752204C8 for ; Sat, 21 Dec 2019 19:51:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PzIe2iS0u9Bd for ; Sat, 21 Dec 2019 19:51:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by silver.osuosl.org (Postfix) with ESMTPS id 45BBD2034D for ; Sat, 21 Dec 2019 19:51:39 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [73.241.94.255]) (Authenticated sender: hzhou@ovn.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 6EB2F240003; Sat, 21 Dec 2019 19:51:37 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sat, 21 Dec 2019 11:51:07 -0800 Message-Id: <1576957867-69488-5-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1576957867-69488-1-git-send-email-hzhou@ovn.org> References: <1576957867-69488-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH 2.12 4/4] extend-table: Fix reusing group/meter by multiple logical flows. 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" A meter/group can be used by multiple logical flows. However, current code didn't handle this properly. Each table_info item has a lflow_uuid field, which can keep track of only a single lflow. In most cases this doesn't create problems because multiple table_info entries are created even for same "name". However, when multiple lflows are added in the same main loop iteration using the same "name" (i.e. when the new_table_id == true), the function ovn_extend_table_assign_id() will return the old id without creating a new entry, and the reference by the second lflow is untracked. Later with incremental processing, if the old lflow is deleted, the table_info will be deleted, which results in the deletion of group/meter in OVS, even when it is still used by the second lflow. This patch fixes the problem by adding a hmap in each desired table_info item to keep track of multiple lflow references. A test case is added. The test case would fail without this fix. At the same time, this patch adds an index that maps from lflow_uuid to a list of desired table_info items used by the lflow, so that the ovn_extend_table_remove_desired() is more efficient, without having to do a O(N) iteration every time. Fixes: ca278d98a4f5 ("ovn-controller: Initial use of incremental engine - quiet mode.") Acked-by: Dumitru Ceara Signed-off-by: Han Zhou --- ovn/lib/extend-table.c | 180 ++++++++++++++++++++++++++++++++++++++++++------- ovn/lib/extend-table.h | 31 ++++++++- tests/ovn.at | 55 +++++++++++++++ 3 files changed, 241 insertions(+), 25 deletions(-) diff --git a/ovn/lib/extend-table.c b/ovn/lib/extend-table.c index 3263da8..18e16f7 100644 --- a/ovn/lib/extend-table.c +++ b/ovn/lib/extend-table.c @@ -31,9 +31,37 @@ ovn_extend_table_init(struct ovn_extend_table *table) table->table_ids = bitmap_allocate(MAX_EXT_TABLE_ID); bitmap_set1(table->table_ids, 0); /* table id 0 is invalid. */ hmap_init(&table->desired); + hmap_init(&table->lflow_to_desired); hmap_init(&table->existing); } +static struct ovn_extend_table_info * +ovn_extend_table_info_alloc(const char *name, uint32_t id, bool is_new_id, + uint32_t hash) +{ + struct ovn_extend_table_info *e = xmalloc(sizeof *e); + e->name = xstrdup(name); + e->table_id = id; + e->new_table_id = is_new_id; + e->hmap_node.hash = hash; + hmap_init(&e->references); + return e; +} + +static void +ovn_extend_table_info_destroy(struct ovn_extend_table_info *e) +{ + free(e->name); + struct ovn_extend_table_lflow_ref *r, *r_next; + HMAP_FOR_EACH_SAFE (r, r_next, hmap_node, &e->references) { + hmap_remove(&e->references, &r->hmap_node); + ovs_list_remove(&r->list_node); + free(r); + } + hmap_destroy(&e->references); + free(e); +} + /* Finds and returns a group_info in 'existing' whose key is identical * to 'target''s key, or NULL if there is none. */ struct ovn_extend_table_info * @@ -51,6 +79,89 @@ ovn_extend_table_lookup(struct hmap *exisiting, return NULL; } +static struct ovn_extend_table_lflow_to_desired * +ovn_extend_table_find_desired_by_lflow(struct ovn_extend_table *table, + const struct uuid *lflow_uuid) +{ + struct ovn_extend_table_lflow_to_desired *l; + HMAP_FOR_EACH_WITH_HASH (l, hmap_node, uuid_hash(lflow_uuid), + &table->lflow_to_desired) { + if (uuid_equals(&l->lflow_uuid, lflow_uuid)) { + return l; + } + } + return NULL; +} + +/* Add a reference to the list of items that uses. + * If the entry doesn't exist in lflow_to_desired mapping, add + * the entry first. */ +static void +ovn_extend_table_add_desired_to_lflow(struct ovn_extend_table *table, + const struct uuid *lflow_uuid, + struct ovn_extend_table_lflow_ref *r) +{ + struct ovn_extend_table_lflow_to_desired *l = + ovn_extend_table_find_desired_by_lflow(table, lflow_uuid); + if (!l) { + l = xmalloc(sizeof *l); + l->lflow_uuid = *lflow_uuid; + ovs_list_init(&l->desired); + hmap_insert(&table->lflow_to_desired, &l->hmap_node, + uuid_hash(lflow_uuid)); + VLOG_DBG("%s: add new lflow_to_desired entry "UUID_FMT, + __func__, UUID_ARGS(lflow_uuid)); + } + + ovs_list_insert(&l->desired, &r->list_node); + VLOG_DBG("%s: lflow "UUID_FMT" use new item %s, id %"PRIu32, + __func__, UUID_ARGS(lflow_uuid), r->desired->name, + r->desired->table_id); +} + +static struct ovn_extend_table_lflow_ref * +ovn_extend_info_find_lflow_ref(struct ovn_extend_table_info *e, + const struct uuid *lflow_uuid) +{ + struct ovn_extend_table_lflow_ref *r; + HMAP_FOR_EACH_WITH_HASH (r, hmap_node, uuid_hash(lflow_uuid), + &e->references) { + if (uuid_equals(&r->lflow_uuid, lflow_uuid)) { + return r; + } + } + return NULL; +} + +/* Create the cross reference between and */ +static void +ovn_extend_info_add_lflow_ref(struct ovn_extend_table *table, + struct ovn_extend_table_info *e, + const struct uuid *lflow_uuid) +{ + struct ovn_extend_table_lflow_ref *r = + ovn_extend_info_find_lflow_ref(e, lflow_uuid); + if (!r) { + r = xmalloc(sizeof *r); + r->lflow_uuid = *lflow_uuid; + r->desired = e; + hmap_insert(&e->references, &r->hmap_node, uuid_hash(lflow_uuid)); + + ovn_extend_table_add_desired_to_lflow(table, lflow_uuid, r); + } +} + +static void +ovn_extend_info_del_lflow_ref(struct ovn_extend_table_lflow_ref *r) +{ + VLOG_DBG("%s: name %s, lflow "UUID_FMT" n %"PRIuSIZE, __func__, + r->desired->name, UUID_ARGS(&r->lflow_uuid), + hmap_count(&r->desired->references)); + hmap_remove(&r->desired->references, &r->hmap_node); + ovs_list_remove(&r->list_node); + free(r); +} + /* Clear either desired or existing in ovn_extend_table. */ void ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) @@ -58,6 +169,16 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) struct ovn_extend_table_info *g, *next; struct hmap *target = existing ? &table->existing : &table->desired; + /* Clear lflow_to_desired index, if the target is desired table. */ + if (!existing) { + struct ovn_extend_table_lflow_to_desired *l, *l_next; + HMAP_FOR_EACH_SAFE (l, l_next, hmap_node, &table->lflow_to_desired) { + hmap_remove(&table->lflow_to_desired, &l->hmap_node); + free(l); + } + } + + /* Clear the target table. */ HMAP_FOR_EACH_SAFE (g, next, hmap_node, target) { hmap_remove(target, &g->hmap_node); /* Don't unset bitmap for desired group_info if the group_id @@ -65,8 +186,7 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) if (existing || g->new_table_id) { bitmap_set0(table->table_ids, g->table_id); } - free(g->name); - free(g); + ovn_extend_table_info_destroy(g); } } @@ -75,6 +195,7 @@ ovn_extend_table_destroy(struct ovn_extend_table *table) { ovn_extend_table_clear(table, false); hmap_destroy(&table->desired); + hmap_destroy(&table->lflow_to_desired); ovn_extend_table_clear(table, true); hmap_destroy(&table->existing); bitmap_free(table->table_ids); @@ -87,11 +208,10 @@ ovn_extend_table_remove_existing(struct ovn_extend_table *table, { /* Remove 'existing' from 'groups->existing' */ hmap_remove(&table->existing, &existing->hmap_node); - free(existing->name); /* Dealloc group_id. */ bitmap_set0(table->table_ids, existing->table_id); - free(existing); + ovn_extend_table_info_destroy(existing); } /* Remove entries in desired table that are created by the lflow_uuid */ @@ -99,29 +219,39 @@ void ovn_extend_table_remove_desired(struct ovn_extend_table *table, const struct uuid *lflow_uuid) { - struct ovn_extend_table_info *e, *next_e; - HMAP_FOR_EACH_SAFE (e, next_e, hmap_node, &table->desired) { - if (uuid_equals(&e->lflow_uuid, lflow_uuid)) { + struct ovn_extend_table_lflow_to_desired *l = + ovn_extend_table_find_desired_by_lflow(table, lflow_uuid); + + if (!l) { + return; + } + + hmap_remove(&table->lflow_to_desired, &l->hmap_node); + struct ovn_extend_table_lflow_ref *r, *next_r; + LIST_FOR_EACH_SAFE (r, next_r, list_node, &l->desired) { + struct ovn_extend_table_info *e = r->desired; + ovn_extend_info_del_lflow_ref(r); + if (hmap_is_empty(&e->references)) { + VLOG_DBG("%s: %s, "UUID_FMT, __func__, + e->name, UUID_ARGS(lflow_uuid)); hmap_remove(&table->desired, &e->hmap_node); - free(e->name); if (e->new_table_id) { bitmap_set0(table->table_ids, e->table_id); } - free(e); + ovn_extend_table_info_destroy(e); } } - + free(l); } static struct ovn_extend_table_info* ovn_extend_info_clone(struct ovn_extend_table_info *source) { - struct ovn_extend_table_info *clone = xmalloc(sizeof *clone); - clone->name = xstrdup(source->name); - clone->table_id = source->table_id; - clone->new_table_id = source->new_table_id; - clone->hmap_node.hash = source->hmap_node.hash; - clone->lflow_uuid = source->lflow_uuid; + struct ovn_extend_table_info *clone = + ovn_extend_table_info_alloc(source->name, + source->table_id, + source->new_table_id, + source->hmap_node.hash); return clone; } @@ -155,8 +285,12 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name, /* Check whether we have non installed but allocated group_id. */ HMAP_FOR_EACH_WITH_HASH (table_info, hmap_node, hash, &table->desired) { - if (!strcmp(table_info->name, name) && - table_info->new_table_id) { + if (!strcmp(table_info->name, name)) { + VLOG_DBG("ovn_externd_table_assign_id: reuse old id %"PRIu32 + " for %s, used by lflow "UUID_FMT, + table_info->table_id, table_info->name, + UUID_ARGS(&lflow_uuid)); + ovn_extend_info_add_lflow_ref(table, table_info, &lflow_uuid); return table_info->table_id; } } @@ -183,15 +317,13 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name, } bitmap_set1(table->table_ids, table_id); - table_info = xmalloc(sizeof *table_info); - table_info->name = xstrdup(name); - table_info->table_id = table_id; - table_info->hmap_node.hash = hash; - table_info->new_table_id = new_table_id; - table_info->lflow_uuid = lflow_uuid; + table_info = ovn_extend_table_info_alloc(name, table_id, new_table_id, + hash); hmap_insert(&table->desired, &table_info->hmap_node, table_info->hmap_node.hash); + ovn_extend_info_add_lflow_ref(table, table_info, &lflow_uuid); + return table_id; } diff --git a/ovn/lib/extend-table.h b/ovn/lib/extend-table.h index 5be13fe..c4bc5ff 100644 --- a/ovn/lib/extend-table.h +++ b/ovn/lib/extend-table.h @@ -31,16 +31,45 @@ struct ovn_extend_table { * for allocated group ids in either * desired or existing. */ struct hmap desired; + struct hmap lflow_to_desired; /* Index for looking up desired table + * items from given lflow uuid, with + * ovn_extend_table_lflow_to_desired nodes. + */ struct hmap existing; }; +struct ovn_extend_table_lflow_to_desired { + struct hmap_node hmap_node; /* In ovn_extend_table.lflow_to_desired. */ + struct uuid lflow_uuid; + struct ovs_list desired; /* List of desired items used by the lflow. */ +}; + struct ovn_extend_table_info { struct hmap_node hmap_node; char *name; /* Name for the table entity. */ - struct uuid lflow_uuid; uint32_t table_id; bool new_table_id; /* 'True' if 'table_id' was reserved from * ovn_extend_table's 'table_ids' bitmap. */ + struct hmap references; /* The lflows that are using this item, with + * ovn_extend_table_lflow_ref nodes. Only useful + * for items in ovn_extend_table.desired. */ +}; + +/* Maintains the link between a lflow and an ovn_extend_table_info item in + * ovn_extend_table.desired, indexed by both + * ovn_extend_table_lflow_to_desired.desired and + * ovn_extend_table_info.references. + * + * The struct is allocated whenever a new reference happens. + * It destroyed when a lflow is deleted (for all the desired table_info + * used by it), or when the lflow_to_desired table is being cleared. + * */ +struct ovn_extend_table_lflow_ref { + struct hmap_node hmap_node; /* In ovn_extend_table_info.references. */ + struct ovs_list list_node; /* In ovn_extend_table_lflow_to_desired.desired. + */ + struct uuid lflow_uuid; + struct ovn_extend_table_info *desired; }; void ovn_extend_table_init(struct ovn_extend_table *); diff --git a/tests/ovn.at b/tests/ovn.at index 3acd8a1..4792e28 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -7336,6 +7336,61 @@ OVN_CLEANUP([hv]) AT_CLEANUP +AT_SETUP([ovn -- same meter used by multiple logical flows]) +AT_KEYWORDS([ovn]) +ovn_start + +net_add n1 + +sim_add hv +as hv +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.1 +for i in lp1 lp2; do + ovs-vsctl -- add-port br-int $i -- \ + set interface $i external-ids:iface-id=$i \ + options:tx_pcap=hv/$i-tx.pcap \ + options:rxq_pcap=hv/$i-rx.pcap +done + +lp1_mac="f0:00:00:00:00:01" +lp1_ip="192.168.1.2" + +lp2_mac="f0:00:00:00:00:02" +lp2_ip="192.168.1.3" + +ovn-nbctl ls-add lsw0 +ovn-nbctl --wait=sb lsp-add lsw0 lp1 +ovn-nbctl --wait=sb lsp-add lsw0 lp2 +ovn-nbctl lsp-set-addresses lp1 $lp1_mac +ovn-nbctl lsp-set-addresses lp2 $lp2_mac +ovn-nbctl --wait=sb sync + +ovn-appctl -t ovn-controller vlog/set file:dbg + +# Add acl1 and acl2 using same meter. +ovn-nbctl meter-add http-rl1 drop 10 pktps +ovn-nbctl --log --meter=http-rl1 acl-add lsw0 to-lport 1000 'tcp.dst==80' drop \ + -- --log --meter=http-rl1 acl-add lsw0 to-lport 1000 'tcp.dst==81' allow + +ovn-nbctl --wait=hv sync + +AT_CHECK([ovs-ofctl -O OpenFlow13 dump-meters br-int | grep meter], [0], [ignore], [ignore]) + +# Delete acl1, meter should be kept in OVS +ovn-nbctl acl-del lsw0 to-lport 1000 'tcp.dst==80' +ovn-nbctl --wait=hv sync +AT_CHECK([ovs-ofctl -O OpenFlow13 dump-meters br-int | grep meter], [0], [ignore], [ignore]) + +# Delete acl2, meter should be deleted in OVS +ovn-nbctl acl-del lsw0 to-lport 1000 'tcp.dst==81' +ovn-nbctl --wait=hv sync +AT_CHECK([ovs-ofctl -O OpenFlow13 dump-meters br-int | grep meter], [1]) + +OVN_CLEANUP([hv]) +AT_CLEANUP + + AT_SETUP([ovn -- DSCP marking and meter check]) AT_KEYWORDS([ovn]) ovn_start