From patchwork Fri Jan 24 11:02:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1228751 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 483x7b2pjWz9sP3 for ; Fri, 24 Jan 2020 22:02:50 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id B7C9D877BB; Fri, 24 Jan 2020 11:02:48 +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 iPZhmru15Gs3; Fri, 24 Jan 2020 11:02:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id C562F877B3; Fri, 24 Jan 2020 11:02:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 96A8DC18DD; Fri, 24 Jan 2020 11:02:46 +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 25225C0174 for ; Fri, 24 Jan 2020 11:02:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 09A4222775 for ; Fri, 24 Jan 2020 11:02:45 +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 t5KQ1xrjrB-D for ; Fri, 24 Jan 2020 11:02:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by silver.osuosl.org (Postfix) with ESMTPS id B5AD322739 for ; Fri, 24 Jan 2020 11:02:43 +0000 (UTC) Received: from nummac.local (unknown [27.7.144.66]) (Authenticated sender: numans@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id EC8D210001B; Fri, 24 Jan 2020 11:02:39 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 24 Jan 2020 16:32:28 +0530 Message-Id: <20200124110228.1555340-1-numans@ovn.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 1/4] Make is_switch() in lflow.c a util function X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique This patch renames is_switch() to datapath_is_switch() and moves to lib/ovn-util.c. Upcoming patch will make use of it. Signed-off-by: Numan Siddique Acked-by: Han Zhou --- controller/lflow.c | 11 ++--------- lib/ovn-util.c | 6 ++++++ lib/ovn-util.h | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/controller/lflow.c b/controller/lflow.c index 9a3c1eb5b..3ddb0571e 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -149,13 +149,6 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name) } } -static bool -is_switch(const struct sbrec_datapath_binding *ldp) -{ - return smap_get(&ldp->external_ids, "logical-switch") != NULL; - -} - void lflow_resource_init(struct lflow_resource_ref *lfrr) { @@ -794,7 +787,7 @@ consider_logical_flow( .lookup_port = lookup_port_cb, .tunnel_ofport = tunnel_ofport_cb, .aux = &aux, - .is_switch = is_switch(ldp), + .is_switch = datapath_is_switch(ldp), .group_table = group_table, .meter_table = meter_table, .lflow_uuid = lflow->header_.uuid, @@ -818,7 +811,7 @@ consider_logical_flow( if (m->match.wc.masks.conj_id) { m->match.flow.conj_id += *conj_id_ofs; } - if (is_switch(ldp)) { + if (datapath_is_switch(ldp)) { unsigned int reg_index = (ingress ? MFF_LOG_INPORT : MFF_LOG_OUTPORT) - MFF_REG0; int64_t port_id = m->match.flow.regs[reg_index]; diff --git a/lib/ovn-util.c b/lib/ovn-util.c index e67c3c073..6e0bba2c5 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -423,3 +423,9 @@ ovn_logical_flow_hash(const struct uuid *logical_datapath, hash = hash_string(match, hash); return hash_string(actions, hash); } + +bool +datapath_is_switch(const struct sbrec_datapath_binding *ldp) +{ + return smap_get(&ldp->external_ids, "logical-switch") != NULL; +} diff --git a/lib/ovn-util.h b/lib/ovn-util.h index b58208e9b..422d69e5b 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -23,6 +23,7 @@ struct sbrec_logical_flow; struct uuid; struct eth_addr; struct sbrec_port_binding; +struct sbrec_datapath_binding; struct ipv4_netaddr { ovs_be32 addr; /* 192.168.10.123 */ @@ -86,5 +87,5 @@ uint32_t ovn_logical_flow_hash(const struct uuid *logical_datapath, uint8_t table_id, const char *pipeline, uint16_t priority, const char *match, const char *actions); - +bool datapath_is_switch(const struct sbrec_datapath_binding *); #endif From patchwork Fri Jan 24 11:03:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1228752 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 483x8h2bX0z9sRd for ; Fri, 24 Jan 2020 22:03:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id CE20F88231; Fri, 24 Jan 2020 11:03:45 +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 dIoazgsScbzo; Fri, 24 Jan 2020 11:03:44 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id B01DA88183; Fri, 24 Jan 2020 11:03:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83D36C18DD; Fri, 24 Jan 2020 11:03:44 +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 A298DC18DD for ; Fri, 24 Jan 2020 11:03:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 77BCC88183 for ; Fri, 24 Jan 2020 11:03:43 +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 I-vVInMAfdlg for ; Fri, 24 Jan 2020 11:03:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by hemlock.osuosl.org (Postfix) with ESMTPS id C98AC88182 for ; Fri, 24 Jan 2020 11:03:41 +0000 (UTC) X-Originating-IP: 27.7.144.66 Received: from nummac.local (unknown [27.7.144.66]) (Authenticated sender: numans@ovn.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 9D4C4FF821; Fri, 24 Jan 2020 11:03:38 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 24 Jan 2020 16:33:29 +0530 Message-Id: <20200124110329.1555571-1-numans@ovn.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200124110228.1555340-1-numans@ovn.org> References: <20200124110228.1555340-1-numans@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 2/4] ovn-controller: Remove ports from struct local_datapaths. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique struct local_datapaths stores the array of port bindings for each datapath. These ports are used only in the pinctrl module to check if a mac binding has been learnt for the buffered packets. MAC bindings are always learnt in the router pipeline and so logical_port column of MAC_Binding table will always refer to a logical router port. run_buffered_binding() of pinctrl module can use the peer ports stored in the struct local_datapaths instead. This would save many calls to mac_binding_lookup(). This patch doesn't store the array of port bindings for each local datapath as it is not required at all. Earlier, the peer ports were stored only for patch port bindings. But we can have peer ports even for l3gateway port bindings. This patch now considers l3gateway ports also for storing the peer ports in struct local_datapaths. Signed-off-by: Numan Siddique Acked-by: Han Zhou --- controller/binding.c | 9 +-------- controller/ovn-controller.c | 2 -- controller/ovn-controller.h | 4 ---- controller/pinctrl.c | 11 +++++++++-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/controller/binding.c b/controller/binding.c index 4c107c1af..8ab23203b 100644 --- a/controller/binding.c +++ b/controller/binding.c @@ -146,7 +146,7 @@ add_local_datapath__(struct ovsdb_idl_index *sbrec_datapath_binding_by_key, const struct sbrec_port_binding *pb; SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, target, sbrec_port_binding_by_datapath) { - if (!strcmp(pb->type, "patch")) { + if (!strcmp(pb->type, "patch") || !strcmp(pb->type, "l3gateway")) { const char *peer_name = smap_get(&pb->options, "peer"); if (peer_name) { const struct sbrec_port_binding *peer; @@ -172,13 +172,6 @@ add_local_datapath__(struct ovsdb_idl_index *sbrec_datapath_binding_by_key, } } } - - ld->n_ports++; - if (ld->n_ports > ld->n_allocated_ports) { - ld->ports = x2nrealloc(ld->ports, &ld->n_allocated_ports, - sizeof *ld->ports); - } - ld->ports[ld->n_ports - 1] = pb; } sbrec_port_binding_index_destroy_row(target); } diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index d81c7574d..9b88f88fe 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -965,7 +965,6 @@ en_runtime_data_cleanup(void *data) HMAP_FOR_EACH_SAFE (cur_node, next_node, hmap_node, &rt_data->local_datapaths) { free(cur_node->peer_ports); - free(cur_node->ports); hmap_remove(&rt_data->local_datapaths, &cur_node->hmap_node); free(cur_node); } @@ -989,7 +988,6 @@ en_runtime_data_run(struct engine_node *node, void *data) struct local_datapath *cur_node, *next_node; HMAP_FOR_EACH_SAFE (cur_node, next_node, hmap_node, local_datapaths) { free(cur_node->peer_ports); - free(cur_node->ports); hmap_remove(local_datapaths, &cur_node->hmap_node); free(cur_node); } diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h index 86b300e44..5d9466880 100644 --- a/controller/ovn-controller.h +++ b/controller/ovn-controller.h @@ -60,10 +60,6 @@ struct local_datapath { * hypervisor. */ bool has_local_l3gateway; - const struct sbrec_port_binding **ports; - size_t n_ports; - size_t n_allocated_ports; - struct { const struct sbrec_port_binding *local; const struct sbrec_port_binding *remote; diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 452ca8a1c..5825bb14b 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -2957,10 +2957,17 @@ run_buffered_binding(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, bool notify = false; HMAP_FOR_EACH (ld, hmap_node, local_datapaths) { + /* MAC_Binding.logical_port will always belong to a + * a router datapath. Hence we can skip logical switch + * datapaths. + * */ + if (datapath_is_switch(ld->datapath)) { + continue; + } - for (size_t i = 0; i < ld->n_ports; i++) { + for (size_t i = 0; i < ld->n_peer_ports; i++) { - const struct sbrec_port_binding *pb = ld->ports[i]; + const struct sbrec_port_binding *pb = ld->peer_ports[i].local; struct buffered_packets *cur_qp, *next_qp; HMAP_FOR_EACH_SAFE (cur_qp, next_qp, hmap_node, &buffered_packets_map) { From patchwork Fri Jan 24 11:03:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1228753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483x930njtz9s1x for ; Fri, 24 Jan 2020 22:04:06 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4A6CE227EC; Fri, 24 Jan 2020 11:04:04 +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 cCsxK5b4ZP1W; Fri, 24 Jan 2020 11:03:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id B4F32227F8; Fri, 24 Jan 2020 11:03:58 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A9A3FC18DD; Fri, 24 Jan 2020 11:03:58 +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 E81ACC0174 for ; Fri, 24 Jan 2020 11:03:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id CACC2869D3 for ; Fri, 24 Jan 2020 11:03:56 +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 z7Eo7YjY+gXy for ; Fri, 24 Jan 2020 11:03:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by whitealder.osuosl.org (Postfix) with ESMTPS id 9570B877CE for ; Fri, 24 Jan 2020 11:03:51 +0000 (UTC) X-Originating-IP: 27.7.144.66 Received: from nummac.local (unknown [27.7.144.66]) (Authenticated sender: numans@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 24AA860013; Fri, 24 Jan 2020 11:03:46 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 24 Jan 2020 16:33:39 +0530 Message-Id: <20200124110339.1555623-1-numans@ovn.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200124110228.1555340-1-numans@ovn.org> References: <20200124110228.1555340-1-numans@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 3/4] Refactor lflow functions to take two context argument - lflow_ctx_in and lflow_ctx_out. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique Presently most of the lflow_*() functions called from ovn-controller.c takes lots of arguments. This patch adds 'struct lflow_ctx_in' and 'struct lflow_ctx_out' to simplify the code a bit. This also reduces some code in ovn-controller.c and improves readability to some degree. No functional changes are introduced in this patch. Signed-off-by: Numan Siddique Acked-by: Han Zhou --- controller/lflow.c | 294 +++++++++++------------------------- controller/lflow.h | 91 ++++------- controller/ovn-controller.c | 251 ++++++++++++------------------ 3 files changed, 220 insertions(+), 416 deletions(-) diff --git a/controller/lflow.c b/controller/lflow.c index 3ddb0571e..95bc65735 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -61,27 +61,14 @@ struct condition_aux { const struct sset *active_tunnels; }; -static bool consider_logical_flow( - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_logical_flow *, - const struct hmap *local_datapaths, - const struct sbrec_chassis *, - struct hmap *dhcp_opts, - struct hmap *dhcpv6_opts, - struct hmap *nd_ra_opts, - struct controller_event_options *controller_event_opts, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - bool delete_expr_from_cache, - struct ovn_desired_flow_table *, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache); +static bool +consider_logical_flow(const struct sbrec_logical_flow *lflow, + struct hmap *dhcp_opts, struct hmap *dhcpv6_opts, + struct hmap *nd_ra_opts, + bool delete_expr_from_cache, + struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out, + struct controller_event_options *controller_event_opts); static bool lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp) @@ -331,31 +318,16 @@ lflow_expr_destroy(struct hmap *lflow_expr_cache) /* Adds the logical flows from the Logical_Flow table to flow tables. */ static void -add_logical_flows( - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *dhcp_options_table, - const struct sbrec_dhcpv6_options_table *dhcpv6_options_table, - const struct sbrec_logical_flow_table *logical_flow_table, - const struct hmap *local_datapaths, - const struct sbrec_chassis *chassis, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *flow_table, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache) +add_logical_flows(struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out) { const struct sbrec_logical_flow *lflow; struct hmap dhcp_opts = HMAP_INITIALIZER(&dhcp_opts); struct hmap dhcpv6_opts = HMAP_INITIALIZER(&dhcpv6_opts); const struct sbrec_dhcp_options *dhcp_opt_row; - SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, dhcp_options_table) { + SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, + l_ctx_in->dhcp_options_table) { dhcp_opt_add(&dhcp_opts, dhcp_opt_row->name, dhcp_opt_row->code, dhcp_opt_row->type); } @@ -363,7 +335,7 @@ add_logical_flows( const struct sbrec_dhcpv6_options *dhcpv6_opt_row; SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH (dhcpv6_opt_row, - dhcpv6_options_table) { + l_ctx_in->dhcpv6_options_table) { dhcp_opt_add(&dhcpv6_opts, dhcpv6_opt_row->name, dhcpv6_opt_row->code, dhcpv6_opt_row->type); } @@ -374,16 +346,11 @@ add_logical_flows( struct controller_event_options controller_event_opts; controller_event_opts_init(&controller_event_opts); - SBREC_LOGICAL_FLOW_TABLE_FOR_EACH (lflow, logical_flow_table) { - if (!consider_logical_flow(sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, - lflow, local_datapaths, - chassis, &dhcp_opts, &dhcpv6_opts, - &nd_ra_opts, &controller_event_opts, - addr_sets, port_groups, - active_tunnels, local_lport_ids, false, - flow_table, group_table, meter_table, - lfrr, conj_id_ofs, lflow_expr_cache)) { + SBREC_LOGICAL_FLOW_TABLE_FOR_EACH (lflow, l_ctx_in->logical_flow_table) { + if (!consider_logical_flow(lflow, &dhcp_opts, &dhcpv6_opts, + &nd_ra_opts, false, + l_ctx_in, l_ctx_out, + &controller_event_opts)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5); VLOG_ERR_RL(&rl, "Conjunction id overflow when processing lflow " UUID_FMT, UUID_ARGS(&lflow->header_.uuid)); @@ -397,24 +364,8 @@ add_logical_flows( } bool -lflow_handle_changed_flows( - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *dhcp_options_table, - const struct sbrec_dhcpv6_options_table *dhcpv6_options_table, - const struct sbrec_logical_flow_table *logical_flow_table, - const struct hmap *local_datapaths, - const struct sbrec_chassis *chassis, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *flow_table, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache) +lflow_handle_changed_flows(struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out) { bool ret = true; const struct sbrec_logical_flow *lflow; @@ -422,7 +373,8 @@ lflow_handle_changed_flows( struct hmap dhcp_opts = HMAP_INITIALIZER(&dhcp_opts); struct hmap dhcpv6_opts = HMAP_INITIALIZER(&dhcpv6_opts); const struct sbrec_dhcp_options *dhcp_opt_row; - SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, dhcp_options_table) { + SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, + l_ctx_in->dhcp_options_table) { dhcp_opt_add(&dhcp_opts, dhcp_opt_row->name, dhcp_opt_row->code, dhcp_opt_row->type); } @@ -430,7 +382,7 @@ lflow_handle_changed_flows( const struct sbrec_dhcpv6_options *dhcpv6_opt_row; SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH (dhcpv6_opt_row, - dhcpv6_options_table) { + l_ctx_in->dhcpv6_options_table) { dhcp_opt_add(&dhcpv6_opts, dhcpv6_opt_row->name, dhcpv6_opt_row->code, dhcpv6_opt_row->type); } @@ -441,27 +393,24 @@ lflow_handle_changed_flows( /* Handle removed flows first, and then other flows, so that when * the flows being added and removed have same match conditions * can be processed in the proper order */ - SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow, logical_flow_table) { + SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow, + l_ctx_in->logical_flow_table) { /* Remove any flows that should be removed. */ if (sbrec_logical_flow_is_deleted(lflow)) { VLOG_DBG("handle deleted lflow "UUID_FMT, UUID_ARGS(&lflow->header_.uuid)); - ofctrl_remove_flows(flow_table, &lflow->header_.uuid); + ofctrl_remove_flows(l_ctx_out->flow_table, &lflow->header_.uuid); /* Delete entries from lflow resource reference. */ - lflow_resource_destroy_lflow(lfrr, &lflow->header_.uuid); - - /* Delete the expr cache for this lflow. */ - struct lflow_expr *le = lflow_expr_get(lflow_expr_cache, lflow); - if (le) { - lflow_expr_delete(lflow_expr_cache, le); - } + lflow_resource_destroy_lflow(l_ctx_out->lfrr, + &lflow->header_.uuid); } } struct controller_event_options controller_event_opts; controller_event_opts_init(&controller_event_opts); - SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow, logical_flow_table) { + SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow, + l_ctx_in->logical_flow_table) { if (!sbrec_logical_flow_is_deleted(lflow)) { /* Now, add/modify existing flows. If the logical * flow is a modification, just remove the flows @@ -469,21 +418,17 @@ lflow_handle_changed_flows( if (!sbrec_logical_flow_is_new(lflow)) { VLOG_DBG("handle updated lflow "UUID_FMT, UUID_ARGS(&lflow->header_.uuid)); - ofctrl_remove_flows(flow_table, &lflow->header_.uuid); + ofctrl_remove_flows(l_ctx_out->flow_table, + &lflow->header_.uuid); /* Delete entries from lflow resource reference. */ - lflow_resource_destroy_lflow(lfrr, &lflow->header_.uuid); + lflow_resource_destroy_lflow(l_ctx_out->lfrr, + &lflow->header_.uuid); } VLOG_DBG("handle new lflow "UUID_FMT, UUID_ARGS(&lflow->header_.uuid)); - if (!consider_logical_flow(sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, - lflow, local_datapaths, - chassis, &dhcp_opts, &dhcpv6_opts, - &nd_ra_opts, &controller_event_opts, - addr_sets, port_groups, - active_tunnels, local_lport_ids, true, - flow_table, group_table, meter_table, - lfrr, conj_id_ofs, lflow_expr_cache)) { + if (!consider_logical_flow(lflow, &dhcp_opts, &dhcpv6_opts, + &nd_ra_opts, true, l_ctx_in, l_ctx_out, + &controller_event_opts)) { ret = false; break; } @@ -497,30 +442,14 @@ lflow_handle_changed_flows( } bool -lflow_handle_changed_ref( - enum ref_type ref_type, - const char *ref_name, - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *dhcp_options_table, - const struct sbrec_dhcpv6_options_table *dhcpv6_options_table, - const struct sbrec_logical_flow_table *logical_flow_table, - const struct hmap *local_datapaths, - const struct sbrec_chassis *chassis, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *flow_table, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache, - bool *changed) +lflow_handle_changed_ref(enum ref_type ref_type, const char *ref_name, + struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out, + bool *changed) { - struct ref_lflow_node *rlfn = ref_lflow_lookup(&lfrr->ref_lflow_table, - ref_type, ref_name); + struct ref_lflow_node *rlfn = + ref_lflow_lookup(&l_ctx_out->lfrr->ref_lflow_table, ref_type, + ref_name); if (!rlfn) { *changed = false; return true; @@ -530,7 +459,7 @@ lflow_handle_changed_ref( *changed = false; bool ret = true; - hmap_remove(&lfrr->ref_lflow_table, &rlfn->node); + hmap_remove(&l_ctx_out->lfrr->ref_lflow_table, &rlfn->node); struct lflow_ref_list_node *lrln, *next; /* Detach the rlfn->ref_lflow_head nodes from the lfrr table and clean @@ -539,19 +468,21 @@ lflow_handle_changed_ref( * when reparsing the lflows. */ LIST_FOR_EACH (lrln, ref_list, &rlfn->ref_lflow_head) { ovs_list_remove(&lrln->lflow_list); - lflow_resource_destroy_lflow(lfrr, &lrln->lflow_uuid); + lflow_resource_destroy_lflow(l_ctx_out->lfrr, &lrln->lflow_uuid); } struct hmap dhcp_opts = HMAP_INITIALIZER(&dhcp_opts); struct hmap dhcpv6_opts = HMAP_INITIALIZER(&dhcpv6_opts); const struct sbrec_dhcp_options *dhcp_opt_row; - SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, dhcp_options_table) { + SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, + l_ctx_in->dhcp_options_table) { dhcp_opt_add(&dhcp_opts, dhcp_opt_row->name, dhcp_opt_row->code, dhcp_opt_row->type); } const struct sbrec_dhcpv6_options *dhcpv6_opt_row; - SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH(dhcpv6_opt_row, dhcpv6_options_table) { + SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH(dhcpv6_opt_row, + l_ctx_in->dhcpv6_options_table) { dhcp_opt_add(&dhcpv6_opts, dhcpv6_opt_row->name, dhcpv6_opt_row->code, dhcpv6_opt_row->type); } @@ -565,7 +496,7 @@ lflow_handle_changed_ref( /* Re-parse the related lflows. */ LIST_FOR_EACH (lrln, ref_list, &rlfn->ref_lflow_head) { const struct sbrec_logical_flow *lflow = - sbrec_logical_flow_table_get_for_uuid(logical_flow_table, + sbrec_logical_flow_table_get_for_uuid(l_ctx_in->logical_flow_table, &lrln->lflow_uuid); if (!lflow) { VLOG_DBG("Reprocess lflow "UUID_FMT" for resource type: %d," @@ -578,17 +509,11 @@ lflow_handle_changed_ref( " name: %s.", UUID_ARGS(&lrln->lflow_uuid), ref_type, ref_name); - ofctrl_remove_flows(flow_table, &lrln->lflow_uuid); - - if (!consider_logical_flow(sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, - lflow, local_datapaths, - chassis, &dhcp_opts, &dhcpv6_opts, - &nd_ra_opts, &controller_event_opts, - addr_sets, port_groups, - active_tunnels, local_lport_ids, true, - flow_table, group_table, meter_table, - lfrr, conj_id_ofs, lflow_expr_cache)) { + ofctrl_remove_flows(l_ctx_out->flow_table, &lrln->lflow_uuid); + + if (!consider_logical_flow(lflow, &dhcp_opts, &dhcpv6_opts, + &nd_ra_opts, true, l_ctx_in, l_ctx_out, + &controller_event_opts)) { ret = false; break; } @@ -620,27 +545,13 @@ update_conj_id_ofs(uint32_t *conj_id_ofs, uint32_t n_conjs) } static bool -consider_logical_flow( - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_logical_flow *lflow, - const struct hmap *local_datapaths, - const struct sbrec_chassis *chassis, - struct hmap *dhcp_opts, - struct hmap *dhcpv6_opts, - struct hmap *nd_ra_opts, - struct controller_event_options *controller_event_opts, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - bool delete_expr_from_cache, - struct ovn_desired_flow_table *flow_table, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache) +consider_logical_flow(const struct sbrec_logical_flow *lflow, + struct hmap *dhcp_opts, struct hmap *dhcpv6_opts, + struct hmap *nd_ra_opts, + bool delete_expr_from_cache, + struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out, + struct controller_event_options *controller_event_opts) { /* Determine translation of logical table IDs to physical table IDs. */ bool ingress = !strcmp(lflow->pipeline, "ingress"); @@ -651,7 +562,7 @@ consider_logical_flow( UUID_ARGS(&lflow->header_.uuid)); return true; } - if (!get_local_datapath(local_datapaths, ldp->tunnel_key)) { + if (!get_local_datapath(l_ctx_in->local_datapaths, ldp->tunnel_key)) { VLOG_DBG("lflow "UUID_FMT" is not for local datapath, skip", UUID_ARGS(&lflow->header_.uuid)); return true; @@ -702,27 +613,28 @@ consider_logical_flow( struct sset addr_sets_ref = SSET_INITIALIZER(&addr_sets_ref); struct sset port_groups_ref = SSET_INITIALIZER(&port_groups_ref); - struct lflow_expr *le = lflow_expr_get(lflow_expr_cache, lflow); + struct lflow_expr *le = lflow_expr_get(l_ctx_out->lflow_expr_cache, lflow); if (le) { if (delete_expr_from_cache) { - lflow_expr_delete(lflow_expr_cache, le); + lflow_expr_delete(l_ctx_out->lflow_expr_cache, le); } else { expr = le->expr; } } if (!expr) { - expr = expr_parse_string(lflow->match, &symtab, addr_sets, port_groups, - &addr_sets_ref, &port_groups_ref, &error); + expr = expr_parse_string(lflow->match, &symtab, l_ctx_in->addr_sets, + l_ctx_in->port_groups, &addr_sets_ref, + &port_groups_ref, &error); const char *addr_set_name; SSET_FOR_EACH (addr_set_name, &addr_sets_ref) { - lflow_resource_add(lfrr, REF_TYPE_ADDRSET, addr_set_name, - &lflow->header_.uuid); + lflow_resource_add(l_ctx_out->lfrr, REF_TYPE_ADDRSET, + addr_set_name, &lflow->header_.uuid); } const char *port_group_name; SSET_FOR_EACH (port_group_name, &port_groups_ref) { - lflow_resource_add(lfrr, REF_TYPE_PORTGROUP, port_group_name, - &lflow->header_.uuid); + lflow_resource_add(l_ctx_out->lfrr, REF_TYPE_PORTGROUP, + port_group_name, &lflow->header_.uuid); } sset_destroy(&addr_sets_ref); sset_destroy(&port_groups_ref); @@ -748,13 +660,13 @@ consider_logical_flow( expr = expr_simplify(expr); expr = expr_normalize(expr); - lflow_expr_add(lflow_expr_cache, lflow, expr); + lflow_expr_add(l_ctx_out->lflow_expr_cache, lflow, expr); } struct condition_aux cond_aux = { - .sbrec_port_binding_by_name = sbrec_port_binding_by_name, - .chassis = chassis, - .active_tunnels = active_tunnels, + .sbrec_port_binding_by_name = l_ctx_in->sbrec_port_binding_by_name, + .chassis = l_ctx_in->chassis, + .active_tunnels = l_ctx_in->active_tunnels, }; expr = expr_clone(expr); @@ -762,8 +674,8 @@ consider_logical_flow( struct lookup_port_aux aux = { .sbrec_multicast_group_by_name_datapath - = sbrec_multicast_group_by_name_datapath, - .sbrec_port_binding_by_name = sbrec_port_binding_by_name, + = l_ctx_in->sbrec_multicast_group_by_name_datapath, + .sbrec_port_binding_by_name = l_ctx_in->sbrec_port_binding_by_name, .dp = lflow->logical_datapath }; uint32_t n_conjs = expr_to_matches(expr, lookup_port_cb, &aux, @@ -788,8 +700,8 @@ consider_logical_flow( .tunnel_ofport = tunnel_ofport_cb, .aux = &aux, .is_switch = datapath_is_switch(ldp), - .group_table = group_table, - .meter_table = meter_table, + .group_table = l_ctx_out->group_table, + .meter_table = l_ctx_out->meter_table, .lflow_uuid = lflow->header_.uuid, .pipeline = ingress ? OVNACT_P_INGRESS : OVNACT_P_EGRESS, @@ -809,7 +721,7 @@ consider_logical_flow( match_set_metadata(&m->match, htonll(lflow->logical_datapath->tunnel_key)); if (m->match.wc.masks.conj_id) { - m->match.flow.conj_id += *conj_id_ofs; + m->match.flow.conj_id += *l_ctx_out->conj_id_ofs; } if (datapath_is_switch(ldp)) { unsigned int reg_index @@ -819,7 +731,7 @@ consider_logical_flow( int64_t dp_id = lflow->logical_datapath->tunnel_key; char buf[16]; snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, dp_id, port_id); - if (!sset_contains(local_lport_ids, buf)) { + if (!sset_contains(l_ctx_in->local_lport_ids, buf)) { VLOG_DBG("lflow "UUID_FMT " port %s in match is not local, skip", UUID_ARGS(&lflow->header_.uuid), @@ -829,7 +741,7 @@ consider_logical_flow( } } if (!m->n) { - ofctrl_add_flow(flow_table, ptable, lflow->priority, + ofctrl_add_flow(l_ctx_out->flow_table, ptable, lflow->priority, lflow->header_.uuid.parts[0], &m->match, &ofpacts, &lflow->header_.uuid); } else { @@ -842,12 +754,13 @@ consider_logical_flow( struct ofpact_conjunction *dst; dst = ofpact_put_CONJUNCTION(&conj); - dst->id = src->id + *conj_id_ofs; + dst->id = src->id + *l_ctx_out->conj_id_ofs; dst->clause = src->clause; dst->n_clauses = src->n_clauses; } - ofctrl_add_or_append_flow(flow_table, ptable, lflow->priority, 0, + ofctrl_add_or_append_flow(l_ctx_out->flow_table, ptable, + lflow->priority, 0, &m->match, &conj, &lflow->header_.uuid); ofpbuf_uninit(&conj); } @@ -856,7 +769,7 @@ consider_logical_flow( /* Clean up. */ expr_matches_destroy(&matches); ofpbuf_uninit(&ofpacts); - return update_conj_id_ofs(conj_id_ofs, n_conjs); + return update_conj_id_ofs(l_ctx_out->conj_id_ofs, n_conjs); } static void @@ -965,7 +878,6 @@ lflow_handle_changed_neighbors( const struct sbrec_mac_binding_table *mac_binding_table, struct ovn_desired_flow_table *flow_table) { - const struct sbrec_mac_binding *mb; /* Handle deleted mac_bindings first, to avoid *duplicated flow* problem * when same flow needs to be added. */ @@ -995,35 +907,13 @@ lflow_handle_changed_neighbors( /* Translates logical flows in the Logical_Flow table in the OVN_SB database * into OpenFlow flows. See ovn-architecture(7) for more information. */ void -lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *dhcp_options_table, - const struct sbrec_dhcpv6_options_table *dhcpv6_options_table, - const struct sbrec_logical_flow_table *logical_flow_table, - const struct sbrec_mac_binding_table *mac_binding_table, - const struct sbrec_chassis *chassis, - const struct hmap *local_datapaths, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *flow_table, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *lfrr, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache) +lflow_run(struct lflow_ctx_in *l_ctx_in, struct lflow_ctx_out *l_ctx_out) { COVERAGE_INC(lflow_run); - add_logical_flows(sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, dhcp_options_table, - dhcpv6_options_table, logical_flow_table, - local_datapaths, chassis, addr_sets, port_groups, - active_tunnels, local_lport_ids, flow_table, group_table, - meter_table, lfrr, conj_id_ofs, lflow_expr_cache); - add_neighbor_flows(sbrec_port_binding_by_name, mac_binding_table, - flow_table); + add_logical_flows(l_ctx_in, l_ctx_out); + add_neighbor_flows(l_ctx_in->sbrec_port_binding_by_name, + l_ctx_in->mac_binding_table, l_ctx_out->flow_table); } void diff --git a/controller/lflow.h b/controller/lflow.h index a2fa087f8..8433cc0c6 100644 --- a/controller/lflow.h +++ b/controller/lflow.h @@ -115,67 +115,38 @@ void lflow_resource_init(struct lflow_resource_ref *); void lflow_resource_destroy(struct lflow_resource_ref *); void lflow_resource_clear(struct lflow_resource_ref *); -void lflow_init(void); -void lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *, - const struct sbrec_dhcpv6_options_table *, - const struct sbrec_logical_flow_table *, - const struct sbrec_mac_binding_table *, - const struct sbrec_chassis *chassis, - const struct hmap *local_datapaths, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache); - -bool lflow_handle_changed_flows( - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *, - const struct sbrec_dhcpv6_options_table *, - const struct sbrec_logical_flow_table *, - const struct hmap *local_datapaths, - const struct sbrec_chassis *, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache); - -bool lflow_handle_changed_ref( - enum ref_type, - const char *ref_name, - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath, - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_dhcp_options_table *, - const struct sbrec_dhcpv6_options_table *, - const struct sbrec_logical_flow_table *, - const struct hmap *local_datapaths, - const struct sbrec_chassis *, - const struct shash *addr_sets, - const struct shash *port_groups, - const struct sset *active_tunnels, - const struct sset *local_lport_ids, - struct ovn_desired_flow_table *, - struct ovn_extend_table *group_table, - struct ovn_extend_table *meter_table, - struct lflow_resource_ref *, - uint32_t *conj_id_ofs, - struct hmap *lflow_expr_cache, - bool *changed); +struct lflow_ctx_in { + struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath; + struct ovsdb_idl_index *sbrec_port_binding_by_name; + const struct sbrec_dhcp_options_table *dhcp_options_table; + const struct sbrec_dhcpv6_options_table *dhcpv6_options_table; + const struct sbrec_datapath_binding_table *dp_binding_table; + const struct sbrec_mac_binding_table *mac_binding_table; + const struct sbrec_logical_flow_table *logical_flow_table; + const struct sbrec_multicast_group_table *mc_group_table; + const struct sbrec_chassis *chassis; + const struct hmap *local_datapaths; + const struct shash *addr_sets; + const struct shash *port_groups; + const struct sset *active_tunnels; + const struct sset *local_lport_ids; +}; +struct lflow_ctx_out { + struct ovn_desired_flow_table *flow_table; + struct ovn_extend_table *group_table; + struct ovn_extend_table *meter_table; + struct lflow_resource_ref *lfrr; + struct hmap *lflow_expr_cache; + uint32_t *conj_id_ofs; +}; + +void lflow_init(void); +void lflow_run(struct lflow_ctx_in *, struct lflow_ctx_out *); +bool lflow_handle_changed_flows(struct lflow_ctx_in *, struct lflow_ctx_out *); +bool lflow_handle_changed_ref(enum ref_type, const char *ref_name, + struct lflow_ctx_in *, struct lflow_ctx_out *, + bool *changed); void lflow_handle_changed_neighbors( struct ovsdb_idl_index *sbrec_port_binding_by_name, const struct sbrec_mac_binding_table *, diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 9b88f88fe..efd5d258d 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -1214,6 +1214,85 @@ struct ed_type_flow_output { struct hmap lflow_expr_cache; }; +static void init_lflow_ctx(struct engine_node *node, + struct ed_type_runtime_data *rt_data, + struct ed_type_flow_output *fo, + struct lflow_ctx_in *l_ctx_in, + struct lflow_ctx_out *l_ctx_out) +{ + struct ovsdb_idl_index *sbrec_port_binding_by_name = + engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), + "name"); + + struct ovsdb_idl_index *sbrec_mc_group_by_name_dp = + engine_ovsdb_node_get_index( + engine_get_input("SB_multicast_group", node), + "name_datapath"); + + struct sbrec_dhcp_options_table *dhcp_table = + (struct sbrec_dhcp_options_table *)EN_OVSDB_GET( + engine_get_input("SB_dhcp_options", node)); + + struct sbrec_dhcpv6_options_table *dhcpv6_table = + (struct sbrec_dhcpv6_options_table *)EN_OVSDB_GET( + engine_get_input("SB_dhcpv6_options", node)); + + struct sbrec_mac_binding_table *mac_binding_table = + (struct sbrec_mac_binding_table *)EN_OVSDB_GET( + engine_get_input("SB_mac_binding", node)); + + struct sbrec_logical_flow_table *logical_flow_table = + (struct sbrec_logical_flow_table *)EN_OVSDB_GET( + engine_get_input("SB_logical_flow", node)); + + struct sbrec_multicast_group_table *multicast_group_table = + (struct sbrec_multicast_group_table *)EN_OVSDB_GET( + engine_get_input("SB_multicast_group", node)); + + const char *chassis_id = chassis_get_id(); + const struct sbrec_chassis *chassis = NULL; + struct ovsdb_idl_index *sbrec_chassis_by_name = + engine_ovsdb_node_get_index( + engine_get_input("SB_chassis", node), + "name"); + if (chassis_id) { + chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); + } + + ovs_assert(chassis); + + struct ed_type_addr_sets *as_data = + engine_get_input_data("addr_sets", node); + struct shash *addr_sets = &as_data->addr_sets; + + struct ed_type_port_groups *pg_data = + engine_get_input_data("port_groups", node); + struct shash *port_groups = &pg_data->port_groups; + + l_ctx_in->sbrec_multicast_group_by_name_datapath = + sbrec_mc_group_by_name_dp; + l_ctx_in->sbrec_port_binding_by_name = sbrec_port_binding_by_name; + l_ctx_in->dhcp_options_table = dhcp_table; + l_ctx_in->dhcpv6_options_table = dhcpv6_table; + l_ctx_in->mac_binding_table = mac_binding_table; + l_ctx_in->logical_flow_table = logical_flow_table; + l_ctx_in->mc_group_table = multicast_group_table; + l_ctx_in->chassis = chassis; + l_ctx_in->local_datapaths = &rt_data->local_datapaths; + l_ctx_in->addr_sets = addr_sets; + l_ctx_in->port_groups = port_groups; + l_ctx_in->active_tunnels = &rt_data->active_tunnels; + l_ctx_in->local_lport_ids = &rt_data->local_lport_ids; + + l_ctx_out->flow_table = &fo->flow_table; + l_ctx_out->group_table = &fo->group_table; + l_ctx_out->meter_table = &fo->meter_table; + l_ctx_out->lfrr = &fo->lflow_resource_ref; + l_ctx_out->lflow_expr_cache = &fo->lflow_expr_cache; + l_ctx_out->conj_id_ofs = &fo->conj_id_ofs; +} + static void * en_flow_output_init(struct engine_node *node OVS_UNUSED, struct engine_arg *arg OVS_UNUSED) @@ -1247,7 +1326,6 @@ en_flow_output_run(struct engine_node *node, void *data) engine_get_input_data("runtime_data", node); struct hmap *local_datapaths = &rt_data->local_datapaths; struct sset *local_lports = &rt_data->local_lports; - struct sset *local_lport_ids = &rt_data->local_lport_ids; struct sset *active_tunnels = &rt_data->active_tunnels; struct ed_type_ct_zones *ct_zones_data = @@ -1271,13 +1349,6 @@ en_flow_output_run(struct engine_node *node, void *data) engine_ovsdb_node_get_index( engine_get_input("SB_chassis", node), "name"); - struct ed_type_addr_sets *as_data = - engine_get_input_data("addr_sets", node); - struct shash *addr_sets = &as_data->addr_sets; - - struct ed_type_port_groups *pg_data = - engine_get_input_data("port_groups", node); - struct shash *port_groups = &pg_data->port_groups; const struct sbrec_chassis *chassis = NULL; if (chassis_id) { @@ -1303,43 +1374,16 @@ en_flow_output_run(struct engine_node *node, void *data) lflow_resource_clear(lfrr); } - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath = - engine_ovsdb_node_get_index( - engine_get_input("SB_multicast_group", node), - "name_datapath"); - struct ovsdb_idl_index *sbrec_port_binding_by_name = engine_ovsdb_node_get_index( engine_get_input("SB_port_binding", node), "name"); - struct sbrec_dhcp_options_table *dhcp_table = - (struct sbrec_dhcp_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcp_options", node)); - - struct sbrec_dhcpv6_options_table *dhcpv6_table = - (struct sbrec_dhcpv6_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcpv6_options", node)); - - struct sbrec_logical_flow_table *logical_flow_table = - (struct sbrec_logical_flow_table *)EN_OVSDB_GET( - engine_get_input("SB_logical_flow", node)); - - struct sbrec_mac_binding_table *mac_binding_table = - (struct sbrec_mac_binding_table *)EN_OVSDB_GET( - engine_get_input("SB_mac_binding", node)); - *conj_id_ofs = 1; - lflow_run(sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, - dhcp_table, dhcpv6_table, - logical_flow_table, - mac_binding_table, - chassis, local_datapaths, addr_sets, - port_groups, active_tunnels, local_lport_ids, - flow_table, group_table, meter_table, lfrr, - conj_id_ofs, - &fo->lflow_expr_cache); + struct lflow_ctx_in l_ctx_in; + struct lflow_ctx_out l_ctx_out; + init_lflow_ctx(node, rt_data, fo, &l_ctx_in, &l_ctx_out); + lflow_run(&l_ctx_in, &l_ctx_out); struct sbrec_multicast_group_table *multicast_group_table = (struct sbrec_multicast_group_table *)EN_OVSDB_GET( @@ -1371,17 +1415,6 @@ flow_output_sb_logical_flow_handler(struct engine_node *node, void *data) { struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); - struct hmap *local_datapaths = &rt_data->local_datapaths; - struct sset *local_lport_ids = &rt_data->local_lport_ids; - struct sset *active_tunnels = &rt_data->active_tunnels; - struct ed_type_addr_sets *as_data = - engine_get_input_data("addr_sets", node); - struct shash *addr_sets = &as_data->addr_sets; - - struct ed_type_port_groups *pg_data = - engine_get_input_data("port_groups", node); - struct shash *port_groups = &pg_data->port_groups; - struct ovsrec_open_vswitch_table *ovs_table = (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( engine_get_input("OVS_open_vswitch", node)); @@ -1389,58 +1422,14 @@ flow_output_sb_logical_flow_handler(struct engine_node *node, void *data) (struct ovsrec_bridge_table *)EN_OVSDB_GET( engine_get_input("OVS_bridge", node)); const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table); - const char *chassis_id = chassis_get_id(); - - struct ovsdb_idl_index *sbrec_chassis_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_chassis", node), - "name"); - - const struct sbrec_chassis *chassis = NULL; - if (chassis_id) { - chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); - } - - ovs_assert(br_int && chassis); + ovs_assert(br_int); struct ed_type_flow_output *fo = data; - struct ovn_desired_flow_table *flow_table = &fo->flow_table; - struct ovn_extend_table *group_table = &fo->group_table; - struct ovn_extend_table *meter_table = &fo->meter_table; - uint32_t *conj_id_ofs = &fo->conj_id_ofs; - struct lflow_resource_ref *lfrr = &fo->lflow_resource_ref; - - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath = - engine_ovsdb_node_get_index( - engine_get_input("SB_multicast_group", node), - "name_datapath"); - - struct ovsdb_idl_index *sbrec_port_binding_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_port_binding", node), - "name"); - - struct sbrec_dhcp_options_table *dhcp_table = - (struct sbrec_dhcp_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcp_options", node)); - - struct sbrec_dhcpv6_options_table *dhcpv6_table = - (struct sbrec_dhcpv6_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcpv6_options", node)); - - struct sbrec_logical_flow_table *logical_flow_table = - (struct sbrec_logical_flow_table *)EN_OVSDB_GET( - engine_get_input("SB_logical_flow", node)); + struct lflow_ctx_in l_ctx_in; + struct lflow_ctx_out l_ctx_out; + init_lflow_ctx(node, rt_data, fo, &l_ctx_in, &l_ctx_out); - bool handled = lflow_handle_changed_flows( - sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name, - dhcp_table, dhcpv6_table, - logical_flow_table, - local_datapaths, chassis, addr_sets, - port_groups, active_tunnels, local_lport_ids, - flow_table, group_table, meter_table, lfrr, - conj_id_ofs, &fo->lflow_expr_cache); + bool handled = lflow_handle_changed_flows(&l_ctx_in, &l_ctx_out); engine_set_node_state(node, EN_UPDATED); return handled; @@ -1628,17 +1617,12 @@ _flow_output_resource_ref_handler(struct engine_node *node, void *data, { struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); - struct hmap *local_datapaths = &rt_data->local_datapaths; - struct sset *local_lport_ids = &rt_data->local_lport_ids; - struct sset *active_tunnels = &rt_data->active_tunnels; struct ed_type_addr_sets *as_data = engine_get_input_data("addr_sets", node); - struct shash *addr_sets = &as_data->addr_sets; struct ed_type_port_groups *pg_data = engine_get_input_data("port_groups", node); - struct shash *port_groups = &pg_data->port_groups; struct ovsrec_open_vswitch_table *ovs_table = (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( @@ -1661,33 +1645,10 @@ _flow_output_resource_ref_handler(struct engine_node *node, void *data, ovs_assert(br_int && chassis); struct ed_type_flow_output *fo = data; - struct ovn_desired_flow_table *flow_table = &fo->flow_table; - struct ovn_extend_table *group_table = &fo->group_table; - struct ovn_extend_table *meter_table = &fo->meter_table; - uint32_t *conj_id_ofs = &fo->conj_id_ofs; - struct lflow_resource_ref *lfrr = &fo->lflow_resource_ref; - struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath = - engine_ovsdb_node_get_index( - engine_get_input("SB_multicast_group", node), - "name_datapath"); - - struct ovsdb_idl_index *sbrec_port_binding_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_port_binding", node), - "name"); - - struct sbrec_dhcp_options_table *dhcp_table = - (struct sbrec_dhcp_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcp_options", node)); - - struct sbrec_dhcpv6_options_table *dhcpv6_table = - (struct sbrec_dhcpv6_options_table *)EN_OVSDB_GET( - engine_get_input("SB_dhcpv6_options", node)); - - struct sbrec_logical_flow_table *logical_flow_table = - (struct sbrec_logical_flow_table *)EN_OVSDB_GET( - engine_get_input("SB_logical_flow", node)); + struct lflow_ctx_in l_ctx_in; + struct lflow_ctx_out l_ctx_out; + init_lflow_ctx(node, rt_data, fo, &l_ctx_in, &l_ctx_out); bool changed; const char *ref_name; @@ -1718,14 +1679,8 @@ _flow_output_resource_ref_handler(struct engine_node *node, void *data, SSET_FOR_EACH (ref_name, deleted) { - if (!lflow_handle_changed_ref(ref_type, ref_name, - sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name,dhcp_table, - dhcpv6_table, logical_flow_table, - local_datapaths, chassis, addr_sets, - port_groups, active_tunnels, local_lport_ids, - flow_table, group_table, meter_table, lfrr, - conj_id_ofs, &fo->lflow_expr_cache, &changed)) { + if (!lflow_handle_changed_ref(ref_type, ref_name, &l_ctx_in, + &l_ctx_out, &changed)) { return false; } if (changed) { @@ -1733,14 +1688,8 @@ _flow_output_resource_ref_handler(struct engine_node *node, void *data, } } SSET_FOR_EACH (ref_name, updated) { - if (!lflow_handle_changed_ref(ref_type, ref_name, - sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name,dhcp_table, - dhcpv6_table, logical_flow_table, - local_datapaths, chassis, addr_sets, - port_groups, active_tunnels, local_lport_ids, - flow_table, group_table, meter_table, lfrr, - conj_id_ofs, &fo->lflow_expr_cache, &changed)) { + if (!lflow_handle_changed_ref(ref_type, ref_name, &l_ctx_in, + &l_ctx_out, &changed)) { return false; } if (changed) { @@ -1748,14 +1697,8 @@ _flow_output_resource_ref_handler(struct engine_node *node, void *data, } } SSET_FOR_EACH (ref_name, new) { - if (!lflow_handle_changed_ref(ref_type, ref_name, - sbrec_multicast_group_by_name_datapath, - sbrec_port_binding_by_name,dhcp_table, - dhcpv6_table, logical_flow_table, - local_datapaths, chassis, addr_sets, - port_groups, active_tunnels, local_lport_ids, - flow_table, group_table, meter_table, lfrr, - conj_id_ofs, &fo->lflow_expr_cache, &changed)) { + if (!lflow_handle_changed_ref(ref_type, ref_name, &l_ctx_in, + &l_ctx_out, &changed)) { return false; } if (changed) { From patchwork Fri Jan 24 11:03:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1228754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483x9Q6HjPz9sSN for ; Fri, 24 Jan 2020 22:04:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 62C982281C; Fri, 24 Jan 2020 11:04:25 +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 xSVvpf9Ge0z9; Fri, 24 Jan 2020 11:04:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id E9B752284F; Fri, 24 Jan 2020 11:04:15 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C7E0AC18DD; Fri, 24 Jan 2020 11:04:15 +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 AB13CC0174 for ; Fri, 24 Jan 2020 11:04:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 911D3869D3 for ; Fri, 24 Jan 2020 11:04:14 +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 4o-CIz8ZwVLK for ; Fri, 24 Jan 2020 11:04:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by whitealder.osuosl.org (Postfix) with ESMTPS id E7A49877F5 for ; Fri, 24 Jan 2020 11:04:02 +0000 (UTC) X-Originating-IP: 27.7.144.66 Received: from nummac.local (unknown [27.7.144.66]) (Authenticated sender: numans@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id DE99B1C0010; Fri, 24 Jan 2020 11:03:58 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 24 Jan 2020 16:33:49 +0530 Message-Id: <20200124110349.1555678-1-numans@ovn.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200124110228.1555340-1-numans@ovn.org> References: <20200124110228.1555340-1-numans@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 4/4] Refactor physical module functions to take context argument - physical_ctx. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique No functional changes are introduced in this patch. Signed-off-by: Numan Siddique Acked-by: Han Zhou --- controller/ovn-controller.c | 183 ++++++++++++++---------------------- controller/physical.c | 104 +++++++++----------- controller/physical.h | 52 +++++----- 3 files changed, 136 insertions(+), 203 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index efd5d258d..cd6f57451 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -1214,6 +1214,66 @@ struct ed_type_flow_output { struct hmap lflow_expr_cache; }; +static void init_physical_ctx(struct engine_node *node, + struct ed_type_runtime_data *rt_data, + struct physical_ctx *p_ctx) +{ + struct ovsdb_idl_index *sbrec_port_binding_by_name = + engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), + "name"); + + struct sbrec_multicast_group_table *multicast_group_table = + (struct sbrec_multicast_group_table *)EN_OVSDB_GET( + engine_get_input("SB_multicast_group", node)); + + struct sbrec_port_binding_table *port_binding_table = + (struct sbrec_port_binding_table *)EN_OVSDB_GET( + engine_get_input("SB_port_binding", node)); + + struct sbrec_chassis_table *chassis_table = + (struct sbrec_chassis_table *)EN_OVSDB_GET( + engine_get_input("SB_chassis", node)); + + struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve = + engine_get_input_data("mff_ovn_geneve", node); + + struct ovsrec_open_vswitch_table *ovs_table = + (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( + engine_get_input("OVS_open_vswitch", node)); + struct ovsrec_bridge_table *bridge_table = + (struct ovsrec_bridge_table *)EN_OVSDB_GET( + engine_get_input("OVS_bridge", node)); + const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table); + const char *chassis_id = chassis_get_id(); + const struct sbrec_chassis *chassis = NULL; + struct ovsdb_idl_index *sbrec_chassis_by_name = + engine_ovsdb_node_get_index( + engine_get_input("SB_chassis", node), + "name"); + if (chassis_id) { + chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); + } + + ovs_assert(br_int && chassis); + + struct ed_type_ct_zones *ct_zones_data = + engine_get_input_data("ct_zones", node); + struct simap *ct_zones = &ct_zones_data->current; + + p_ctx->sbrec_port_binding_by_name = sbrec_port_binding_by_name; + p_ctx->port_binding_table = port_binding_table; + p_ctx->mc_group_table = multicast_group_table; + p_ctx->br_int = br_int; + p_ctx->chassis_table = chassis_table; + p_ctx->chassis = chassis; + p_ctx->active_tunnels = &rt_data->active_tunnels; + p_ctx->local_datapaths = &rt_data->local_datapaths; + p_ctx->local_lports = &rt_data->local_lports; + p_ctx->ct_zones = ct_zones; + p_ctx->mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve; +} + static void init_lflow_ctx(struct engine_node *node, struct ed_type_runtime_data *rt_data, struct ed_type_flow_output *fo, @@ -1324,17 +1384,6 @@ en_flow_output_run(struct engine_node *node, void *data) { struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); - struct hmap *local_datapaths = &rt_data->local_datapaths; - struct sset *local_lports = &rt_data->local_lports; - struct sset *active_tunnels = &rt_data->active_tunnels; - - struct ed_type_ct_zones *ct_zones_data = - engine_get_input_data("ct_zones", node); - struct simap *ct_zones = &ct_zones_data->current; - - struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve = - engine_get_input_data("mff_ovn_geneve", node); - enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve; struct ovsrec_open_vswitch_table *ovs_table = (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( @@ -1374,38 +1423,16 @@ en_flow_output_run(struct engine_node *node, void *data) lflow_resource_clear(lfrr); } - struct ovsdb_idl_index *sbrec_port_binding_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_port_binding", node), - "name"); - *conj_id_ofs = 1; struct lflow_ctx_in l_ctx_in; struct lflow_ctx_out l_ctx_out; init_lflow_ctx(node, rt_data, fo, &l_ctx_in, &l_ctx_out); lflow_run(&l_ctx_in, &l_ctx_out); - struct sbrec_multicast_group_table *multicast_group_table = - (struct sbrec_multicast_group_table *)EN_OVSDB_GET( - engine_get_input("SB_multicast_group", node)); - - struct sbrec_port_binding_table *port_binding_table = - (struct sbrec_port_binding_table *)EN_OVSDB_GET( - engine_get_input("SB_port_binding", node)); - - struct sbrec_chassis_table *chassis_table = - (struct sbrec_chassis_table *)EN_OVSDB_GET( - engine_get_input("SB_chassis", node)); + struct physical_ctx p_ctx; + init_physical_ctx(node, rt_data, &p_ctx); - physical_run(sbrec_port_binding_by_name, - multicast_group_table, - port_binding_table, - chassis_table, - mff_ovn_geneve, - br_int, chassis, ct_zones, - local_datapaths, local_lports, - active_tunnels, - flow_table); + physical_run(&p_ctx, &fo->flow_table); engine_set_node_state(node, EN_UPDATED); } @@ -1462,48 +1489,10 @@ flow_output_sb_port_binding_handler(struct engine_node *node, void *data) { struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); - struct hmap *local_datapaths = &rt_data->local_datapaths; - struct sset *active_tunnels = &rt_data->active_tunnels; - - struct ed_type_ct_zones *ct_zones_data = - engine_get_input_data("ct_zones", node); - struct simap *ct_zones = &ct_zones_data->current; - - struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve = - engine_get_input_data("mff_ovn_geneve", node); - enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve; - - struct ovsrec_open_vswitch_table *ovs_table = - (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( - engine_get_input("OVS_open_vswitch", node)); - struct ovsrec_bridge_table *bridge_table = - (struct ovsrec_bridge_table *)EN_OVSDB_GET( - engine_get_input("OVS_bridge", node)); - const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table); - const char *chassis_id = chassis_get_id(); - - struct ovsdb_idl_index *sbrec_chassis_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_chassis", node), - "name"); - const struct sbrec_chassis *chassis = NULL; - if (chassis_id) { - chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); - } - ovs_assert(br_int && chassis); struct ed_type_flow_output *fo = data; struct ovn_desired_flow_table *flow_table = &fo->flow_table; - struct ovsdb_idl_index *sbrec_port_binding_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_port_binding", node), - "name"); - - struct sbrec_port_binding_table *port_binding_table = - (struct sbrec_port_binding_table *)EN_OVSDB_GET( - engine_get_input("SB_port_binding", node)); - /* XXX: now we handle port-binding changes for physical flow processing * only, but port-binding change can have impact to logical flow * processing, too, in below circumstances: @@ -1551,11 +1540,10 @@ flow_output_sb_port_binding_handler(struct engine_node *node, void *data) * names and the lflows that uses them, and reprocess the related lflows * when related port-bindings change. */ - physical_handle_port_binding_changes( - sbrec_port_binding_by_name, - port_binding_table, mff_ovn_geneve, - chassis, ct_zones, local_datapaths, - active_tunnels, flow_table); + struct physical_ctx p_ctx; + init_physical_ctx(node, rt_data, &p_ctx); + + physical_handle_port_binding_changes(&p_ctx, flow_table); engine_set_node_state(node, EN_UPDATED); return true; @@ -1566,45 +1554,14 @@ flow_output_sb_multicast_group_handler(struct engine_node *node, void *data) { struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); - struct hmap *local_datapaths = &rt_data->local_datapaths; - - struct ed_type_ct_zones *ct_zones_data = - engine_get_input_data("ct_zones", node); - struct simap *ct_zones = &ct_zones_data->current; - - struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve = - engine_get_input_data("mff_ovn_geneve", node); - enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve; - - struct ovsrec_open_vswitch_table *ovs_table = - (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET( - engine_get_input("OVS_open_vswitch", node)); - struct ovsrec_bridge_table *bridge_table = - (struct ovsrec_bridge_table *)EN_OVSDB_GET( - engine_get_input("OVS_bridge", node)); - const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table); - const char *chassis_id = chassis_get_id(); - - struct ovsdb_idl_index *sbrec_chassis_by_name = - engine_ovsdb_node_get_index( - engine_get_input("SB_chassis", node), - "name"); - const struct sbrec_chassis *chassis = NULL; - if (chassis_id) { - chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); - } - ovs_assert(br_int && chassis); struct ed_type_flow_output *fo = data; struct ovn_desired_flow_table *flow_table = &fo->flow_table; - struct sbrec_multicast_group_table *multicast_group_table = - (struct sbrec_multicast_group_table *)EN_OVSDB_GET( - engine_get_input("SB_multicast_group", node)); + struct physical_ctx p_ctx; + init_physical_ctx(node, rt_data, &p_ctx); - physical_handle_mc_group_changes(multicast_group_table, - mff_ovn_geneve, chassis, ct_zones, local_datapaths, - flow_table); + physical_handle_mc_group_changes(&p_ctx, flow_table); engine_set_node_state(node, EN_UPDATED); return true; diff --git a/controller/physical.c b/controller/physical.c index af1d10f9b..a7edaddac 100644 --- a/controller/physical.c +++ b/controller/physical.c @@ -1396,30 +1396,26 @@ update_ofports(struct simap *old, struct simap *new) return changed; } -void physical_handle_port_binding_changes( - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_port_binding_table *pb_table, - enum mf_field_id mff_ovn_geneve, - const struct sbrec_chassis *chassis, - const struct simap *ct_zones, - struct hmap *local_datapaths, - struct sset *active_tunnels, - struct ovn_desired_flow_table *flow_table) +void +physical_handle_port_binding_changes(struct physical_ctx *p_ctx, + struct ovn_desired_flow_table *flow_table) { const struct sbrec_port_binding *binding; struct ofpbuf ofpacts; ofpbuf_init(&ofpacts, 0); - SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding, pb_table) { + SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding, + p_ctx->port_binding_table) { if (sbrec_port_binding_is_deleted(binding)) { ofctrl_remove_flows(flow_table, &binding->header_.uuid); } else { if (!sbrec_port_binding_is_new(binding)) { ofctrl_remove_flows(flow_table, &binding->header_.uuid); } - consider_port_binding(sbrec_port_binding_by_name, - mff_ovn_geneve, ct_zones, - active_tunnels, local_datapaths, - binding, chassis, + consider_port_binding(p_ctx->sbrec_port_binding_by_name, + p_ctx->mff_ovn_geneve, p_ctx->ct_zones, + p_ctx->active_tunnels, + p_ctx->local_datapaths, + binding, p_ctx->chassis, flow_table, &ofpacts); } } @@ -1427,40 +1423,26 @@ void physical_handle_port_binding_changes( } void -physical_handle_mc_group_changes( - const struct sbrec_multicast_group_table *multicast_group_table, - enum mf_field_id mff_ovn_geneve, - const struct sbrec_chassis *chassis, - const struct simap *ct_zones, - const struct hmap *local_datapaths, - struct ovn_desired_flow_table *flow_table) +physical_handle_mc_group_changes(struct physical_ctx *p_ctx, + struct ovn_desired_flow_table *flow_table) { const struct sbrec_multicast_group *mc; - SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc, multicast_group_table) { + SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc, p_ctx->mc_group_table) { if (sbrec_multicast_group_is_deleted(mc)) { ofctrl_remove_flows(flow_table, &mc->header_.uuid); } else { if (!sbrec_multicast_group_is_new(mc)) { ofctrl_remove_flows(flow_table, &mc->header_.uuid); } - consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths, - chassis, mc, flow_table); + consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones, + p_ctx->local_datapaths, + p_ctx->chassis, mc, flow_table); } } } void -physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_multicast_group_table *multicast_group_table, - const struct sbrec_port_binding_table *port_binding_table, - const struct sbrec_chassis_table *chassis_table, - enum mf_field_id mff_ovn_geneve, - const struct ovsrec_bridge *br_int, - const struct sbrec_chassis *chassis, - const struct simap *ct_zones, - const struct hmap *local_datapaths, - const struct sset *local_lports, - const struct sset *active_tunnels, +physical_run(struct physical_ctx *p_ctx, struct ovn_desired_flow_table *flow_table) { if (!hc_uuid) { @@ -1475,16 +1457,17 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, SIMAP_INITIALIZER(&new_localvif_to_ofport); struct simap new_tunnel_to_ofport = SIMAP_INITIALIZER(&new_tunnel_to_ofport); - for (int i = 0; i < br_int->n_ports; i++) { - const struct ovsrec_port *port_rec = br_int->ports[i]; - if (!strcmp(port_rec->name, br_int->name)) { + for (int i = 0; i < p_ctx->br_int->n_ports; i++) { + const struct ovsrec_port *port_rec = p_ctx->br_int->ports[i]; + if (!strcmp(port_rec->name, p_ctx->br_int->name)) { continue; } const char *tunnel_id = smap_get(&port_rec->external_ids, "ovn-chassis-id"); - if (tunnel_id && - encaps_tunnel_id_match(tunnel_id, chassis->name, NULL)) { + if (tunnel_id && encaps_tunnel_id_match(tunnel_id, + p_ctx->chassis->name, + NULL)) { continue; } @@ -1520,7 +1503,7 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, enum chassis_tunnel_type tunnel_type; if (!strcmp(iface_rec->type, "geneve")) { tunnel_type = GENEVE; - if (!mff_ovn_geneve) { + if (!p_ctx->mff_ovn_geneve) { continue; } } else if (!strcmp(iface_rec->type, "stt")) { @@ -1599,24 +1582,26 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, struct ofpbuf ofpacts; ofpbuf_init(&ofpacts, 0); - put_chassis_mac_conj_id_flow(chassis_table, chassis, &ofpacts, flow_table); + put_chassis_mac_conj_id_flow(p_ctx->chassis_table, p_ctx->chassis, + &ofpacts, flow_table); /* Set up flows in table 0 for physical-to-logical translation and in table * 64 for logical-to-physical translation. */ const struct sbrec_port_binding *binding; - SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) { - consider_port_binding(sbrec_port_binding_by_name, - mff_ovn_geneve, ct_zones, - active_tunnels, local_datapaths, - binding, chassis, + SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, p_ctx->port_binding_table) { + consider_port_binding(p_ctx->sbrec_port_binding_by_name, + p_ctx->mff_ovn_geneve, p_ctx->ct_zones, + p_ctx->active_tunnels, p_ctx->local_datapaths, + binding, p_ctx->chassis, flow_table, &ofpacts); } /* Handle output to multicast groups, in tables 32 and 33. */ const struct sbrec_multicast_group *mc; - SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, multicast_group_table) { - consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths, - chassis, mc, flow_table); + SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, p_ctx->mc_group_table) { + consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones, + p_ctx->local_datapaths, p_ctx->chassis, + mc, flow_table); } /* Table 0, priority 100. @@ -1637,9 +1622,9 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, ofpbuf_clear(&ofpacts); if (tun->type == GENEVE) { put_move(MFF_TUN_ID, 0, MFF_LOG_DATAPATH, 0, 24, &ofpacts); - put_move(mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15, + put_move(p_ctx->mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15, &ofpacts); - put_move(mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16, + put_move(p_ctx->mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16, &ofpacts); } else if (tun->type == STT) { put_move(MFF_TUN_ID, 40, MFF_LOG_INPORT, 0, 15, &ofpacts); @@ -1668,7 +1653,8 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, continue; } - SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) { + SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, + p_ctx->port_binding_table) { struct match match = MATCH_CATCHALL_INITIALIZER; if (!binding->chassis || @@ -1738,12 +1724,12 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, ofpbuf_clear(&ofpacts); put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts); const char *localport; - SSET_FOR_EACH (localport, local_lports) { + SSET_FOR_EACH (localport, p_ctx->local_lports) { /* Iterate over all local logical ports and insert a drop * rule with higher priority for every localport in this * datapath. */ const struct sbrec_port_binding *pb = lport_lookup_by_name( - sbrec_port_binding_by_name, localport); + p_ctx->sbrec_port_binding_by_name, localport); if (pb && !strcmp(pb->type, "localport")) { match_set_reg(&match, MFF_LOG_INPORT - MFF_REG0, pb->tunnel_key); match_set_metadata(&match, htonll(pb->datapath->tunnel_key)); @@ -1761,8 +1747,8 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, match_init_catchall(&match); ofpbuf_clear(&ofpacts); put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts); - ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0, &match, &ofpacts, - hc_uuid); + ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0, &match, + &ofpacts, hc_uuid); /* Table 34, Priority 0. * ======================= @@ -1787,8 +1773,8 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, match_init_catchall(&match); ofpbuf_clear(&ofpacts); put_resubmit(OFTABLE_LOG_TO_PHY, &ofpacts); - ofctrl_add_flow(flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match, &ofpacts, - hc_uuid); + ofctrl_add_flow(flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match, + &ofpacts, hc_uuid); ofpbuf_uninit(&ofpacts); diff --git a/controller/physical.h b/controller/physical.h index c0e17cd21..dadf84ea1 100644 --- a/controller/physical.h +++ b/controller/physical.h @@ -42,38 +42,28 @@ struct sset; #define OVN_GENEVE_TYPE 0x80 /* Critical option. */ #define OVN_GENEVE_LEN 4 +struct physical_ctx { + struct ovsdb_idl_index *sbrec_port_binding_by_name; + const struct sbrec_port_binding_table *port_binding_table; + const struct sbrec_multicast_group_table *mc_group_table; + const struct ovsrec_bridge *br_int; + const struct sbrec_chassis_table *chassis_table; + const struct sbrec_chassis *chassis; + const struct sset *active_tunnels; + struct hmap *local_datapaths; + struct sset *local_lports; + const struct simap *ct_zones; + enum mf_field_id mff_ovn_geneve; +}; + void physical_register_ovs_idl(struct ovsdb_idl *); -void physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_multicast_group_table *, - const struct sbrec_port_binding_table *, - const struct sbrec_chassis_table *chassis_table, - enum mf_field_id mff_ovn_geneve, - const struct ovsrec_bridge *br_int, - const struct sbrec_chassis *chassis, - const struct simap *ct_zones, - const struct hmap *local_datapaths, - const struct sset *local_lports, - const struct sset *active_tunnels, +void physical_run(struct physical_ctx *, struct ovn_desired_flow_table *); -void physical_handle_port_binding_changes( - struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct sbrec_port_binding_table *, - enum mf_field_id mff_ovn_geneve, - const struct sbrec_chassis *, - const struct simap *ct_zones, - struct hmap *local_datapaths, - struct sset *active_tunnels, - struct ovn_desired_flow_table *); +void physical_handle_port_binding_changes(struct physical_ctx *, + struct ovn_desired_flow_table *); +void physical_handle_mc_group_changes(struct physical_ctx *, + struct ovn_desired_flow_table *); -void physical_handle_mc_group_changes( - const struct sbrec_multicast_group_table *, - enum mf_field_id mff_ovn_geneve, - const struct sbrec_chassis *, - const struct simap *ct_zones, - const struct hmap *local_datapaths, - struct ovn_desired_flow_table *); -bool get_tunnel_ofport( - const char *chassis_name, - char *encap_ip, - ofp_port_t *ofport); +bool get_tunnel_ofport(const char *chassis_name, char *encap_ip, + ofp_port_t *ofport); #endif /* controller/physical.h */