From patchwork Mon Aug 13 07:36:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 956870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LdRv4ugr"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41pnj32W1Yz9s8T for ; Mon, 13 Aug 2018 17:41:11 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3171ECC6; Mon, 13 Aug 2018 07:37:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9F88AC96 for ; Mon, 13 Aug 2018 07:37:38 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 057BE1FB for ; Mon, 13 Aug 2018 07:37:37 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id w19-v6so6571864ply.8 for ; Mon, 13 Aug 2018 00:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cq9zKfZ22pSBpEDqitL3DLfo4uBWk0fnTWqPnmddWC4=; b=LdRv4ugrJhNPFLQ3NAypiW6C6Q9vQPD33LiMIxz5iFakgpheqLVEmJiO1N+ngnzJ4K Wdfa044KvoEDg0bOQBFGUjsSZYSZ4iLrAvoSh3YSwaNeCFoSC1PB9UmFkwIGp25BfhGg bGfIUhvrvbDi06xIDUgyqfBH5B4qkOEnYpDRavGmJVsxmbJVXE8h+zxTy9qtbUY9cI33 8AYZVKwH1SlPB4CqVW73CMC+W9LYqDK9DYlOxDlgizNVhYqltLejR9xdq65WhdHpeKrd KNGfxH05M6nGcLYKEu6GvNm6I51RomTn+jYGN9/uQXWXVgoGhm0M9hvADw0/C3iU8XOm gzsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cq9zKfZ22pSBpEDqitL3DLfo4uBWk0fnTWqPnmddWC4=; b=gxjggyA5KDMw/0zTaCnrKyVj4P5SYcBnwS536xAx8sEJhe9uDCeUdqhYMJce06J3YO ljrjHxD2CXqcREGnAjNC6SlwdLhVx5/ia8miV47rqfflxmkGfR1f5u9v/fw9pTRoM2JF oWwHu2CI9lI06LScxPzr/CY6U6AS5gty/TZSDscYHjUzALXTc6E3zRZNldsme1IdFdpS ZZNFJ8HF9ZUXsnMbgHeO6ho91ijpZGc6qC90j+oTExCx+0+eiBYJENZVn6D2xIr3OQyj ij3XQl3mRe8Wyt6GaIMS6G3D7muPA3JOMSXe0mvgZ6Ugy5tnD+XJ8b6RPEuExvqZUCqL 2tFQ== X-Gm-Message-State: AOUpUlG8+uVPF9thl2Iwtrki+zdkBclDkJSuLAY/999SDXK55GAHyIIu fFxyyA62ltTuO+D60o/fWdWrV+0a X-Google-Smtp-Source: AA+uWPy4Z2ABJDiRh0G18HLOH3OkBpWTb2F63hJNWTugb1DFRR5+GWsxZPa+WYM7fgKF9DwBEPUHmw== X-Received: by 2002:a17:902:6b:: with SMTP id 98-v6mr15333219pla.68.1534145857418; Mon, 13 Aug 2018 00:37:37 -0700 (PDT) Received: from localhost.localdomain.localdomain (c-73-162-150-77.hsd1.ca.comcast.net. [73.162.150.77]) by smtp.gmail.com with ESMTPSA id o10-v6sm30456465pfk.76.2018.08.13.00.37.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 00:37:37 -0700 (PDT) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Mon, 13 Aug 2018 00:36:48 -0700 Message-Id: <1534145820-119903-9-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1534145820-119903-1-git-send-email-hzhou8@ebay.com> References: <1534145820-119903-1-git-send-email-hzhou8@ebay.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v4 08/20] ovn-controller: Incremental logical flow processing X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Implements change handler of flow_output for SB lflow changes. Signed-off-by: Han Zhou --- ovn/controller/lflow.c | 84 +++++++++++++++++++++++++++++++++++++++++ ovn/controller/lflow.h | 18 +++++++++ ovn/controller/ovn-controller.c | 76 ++++++++++++++++++++++++++++++++++++- 3 files changed, 177 insertions(+), 1 deletion(-) diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c index 72b1ec7..f7cb6d4 100644 --- a/ovn/controller/lflow.c +++ b/ovn/controller/lflow.c @@ -200,6 +200,90 @@ add_logical_flows( nd_ra_opts_destroy(&nd_ra_opts); } +bool +lflow_handle_changed_flows( + struct ovsdb_idl_index *sbrec_chassis_by_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, + uint32_t *conj_id_ofs) +{ + bool ret = true; + 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) { + 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) { + dhcp_opt_add(&dhcpv6_opts, dhcpv6_opt_row->name, dhcpv6_opt_row->code, + dhcpv6_opt_row->type); + } + + struct hmap nd_ra_opts = HMAP_INITIALIZER(&nd_ra_opts); + nd_ra_opts_init(&nd_ra_opts); + + /* 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) { + /* 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); + } + } + SBREC_LOGICAL_FLOW_TABLE_FOR_EACH_TRACKED (lflow, 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 + * for this row, and then add new 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); + } + VLOG_DBG("handle new lflow "UUID_FMT, + UUID_ARGS(&lflow->header_.uuid)); + if (!consider_logical_flow(sbrec_chassis_by_name, + sbrec_multicast_group_by_name_datapath, + sbrec_port_binding_by_name, + lflow, local_datapaths, + chassis, &dhcp_opts, &dhcpv6_opts, + &nd_ra_opts, addr_sets, port_groups, + active_tunnels, local_lport_ids, + flow_table, group_table, meter_table, + conj_id_ofs)) { + ret = false; + break; + } + } + } + dhcp_opts_destroy(&dhcp_opts); + dhcp_opts_destroy(&dhcpv6_opts); + nd_ra_opts_destroy(&nd_ra_opts); + return ret; +} + static bool update_conj_id_ofs(uint32_t *conj_id_ofs, uint32_t n_conjs) { diff --git a/ovn/controller/lflow.h b/ovn/controller/lflow.h index b4120d0..31e34e2 100644 --- a/ovn/controller/lflow.h +++ b/ovn/controller/lflow.h @@ -84,6 +84,24 @@ void lflow_run(struct ovsdb_idl_index *sbrec_chassis_by_name, struct ovn_extend_table *meter_table, uint32_t *conj_id_ofs); +bool lflow_handle_changed_flows( + struct ovsdb_idl_index *sbrec_chassis_by_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, + uint32_t *conj_id_ofs); + void lflow_destroy(void); #endif /* ovn/lflow.h */ diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index bfe99dd..5c24cba 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -973,6 +973,80 @@ en_flow_output_run(struct engine_node *node) node->changed = true; } +static bool +flow_output_sb_logical_flow_handler(struct engine_node *node) +{ + struct ed_type_runtime_data *data = + (struct ed_type_runtime_data *)engine_get_input( + "runtime_data", node)->data; + struct hmap *local_datapaths = &data->local_datapaths; + struct sset *local_lport_ids = &data->local_lport_ids; + struct sset *active_tunnels = &data->active_tunnels; + struct shash *addr_sets = &data->addr_sets; + struct shash *port_groups = &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)); + 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 = get_chassis_id(ovs_table); + + 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 = + (struct ed_type_flow_output *)node->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 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)); + + bool handled = lflow_handle_changed_flows(sbrec_chassis_by_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, conj_id_ofs); + + node->changed = true; + return handled; +} + struct ovn_controller_exit_args { bool *exiting; bool *restart; @@ -1092,7 +1166,7 @@ main(int argc, char *argv[]) engine_add_input(&en_flow_output, &en_sb_datapath_binding, NULL); engine_add_input(&en_flow_output, &en_sb_port_binding, NULL); engine_add_input(&en_flow_output, &en_sb_mac_binding, NULL); - engine_add_input(&en_flow_output, &en_sb_logical_flow, NULL); + engine_add_input(&en_flow_output, &en_sb_logical_flow, flow_output_sb_logical_flow_handler); engine_add_input(&en_flow_output, &en_sb_dhcp_options, NULL); engine_add_input(&en_flow_output, &en_sb_dhcpv6_options, NULL); engine_add_input(&en_flow_output, &en_sb_dns, NULL);