From patchwork Wed Jul 25 00:59:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 948972 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="kTngOla6"; 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 41Zxkx5Nvnz9s0R for ; Wed, 25 Jul 2018 11:01:45 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 86F5FDC5; Wed, 25 Jul 2018 00:59:45 +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 6CC09DC6 for ; Wed, 25 Jul 2018 00:59:42 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl0-f47.google.com (mail-pl0-f47.google.com [209.85.160.47]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C0A5B709 for ; Wed, 25 Jul 2018 00:59:41 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id s17-v6so2502918plp.7 for ; Tue, 24 Jul 2018 17:59:41 -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=M3to7Kpoah3wMC7E10CZfqiT3eahgHnwB/OrAAwD2x4=; b=kTngOla6RPv44Blxf9fe4X+QXFRggKC00avCo9bHy9ynbblSrL1I/NnnVpgVlEAN0q XobYfnM38O/1MismL7+qJv4/K5O5TGBtdvc14H5WuoGEuaa1gbO9G3yFFgO2uPs9HH+t RRbC/SuJyd4sRzf8R5ErCsMu+BpsxDFRvxJC9msQzFobScGdyouCmywFhpbP6MbS4FcA GNFR538jtJlG3zBxBdMaD+zz0cpfmPYdWTqfpY9rhWGYle54Otty1jacJXEePAo6xIVa rz67PfSQH7CwG5+W1xrwqinK1IN3tan6IDiCNMVifR2fLG5uvNizFXu4b2EmswVY6mIE k2yA== 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=M3to7Kpoah3wMC7E10CZfqiT3eahgHnwB/OrAAwD2x4=; b=sqMt5niDR2D53AuRWybDWvECHWf3HwkF72sVpvp39DSknKVIM87niklGc+jlW/eS8S iuT/brKhz+w8l6Fz8f0Ut4lTZh6p7Ain5CbPlaCNdm1au+UcJqy3gR04ahDdo9JIPnO5 j/Zj2CMWg5g19VJ4C4A+lVtYmWFB5Tqg9NdJeORVbcC0IzEb2aFvdV7X5ImYc3kyLiFf Ap/f09BT7qAnXrhb6vQ2B/ZS1G6enrBRyfkBvjAaE5MHnQn64GHNXn5AcMEgWZ7CbP/2 yzD2EZsZASu/jJ6SSugS9rn5HY60GaZTGn1w9U03FbbuTqpoyCO9Z5IftmoVGwW9t0Ls /+dg== X-Gm-Message-State: AOUpUlEMc64zmygpYraIAxL5vT53BEqc9aHogL43HzvYvJ6+8gZ0aOSD NKGXTwn+5sH1Fpk9Q5QeGDLveM5l X-Google-Smtp-Source: AAOMgpcchZ1nUpx3dpsnm5nMpq5OuhGz9TCF2Cl0PINxQhGBkuO5FwfuKxeRHFPWwHzPYLH4iwhIGA== X-Received: by 2002:a17:902:a60b:: with SMTP id u11-v6mr18910232plq.158.1532480381187; Tue, 24 Jul 2018 17:59:41 -0700 (PDT) Received: from localhost.localdomain.localdomain ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id g11-v6sm18798424pgi.90.2018.07.24.17.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jul 2018 17:59:40 -0700 (PDT) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Tue, 24 Jul 2018 17:59:32 -0700 Message-Id: <1532480380-97578-7-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1532480380-97578-1-git-send-email-hzhou8@ebay.com> References: <1532480380-97578-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] [RFC 06/14] ovn-controller: runtime_data change handler for SB port-binding 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 Evaluates change for SB port-binding in runtime_data node. If the port-binding change has no impact for the runtime_data it will not trigger runtime_data change. Signed-off-by: Han Zhou --- ovn/controller/binding.c | 91 +++++++++++++++++++++++++++++++++++++++++ ovn/controller/binding.h | 7 ++++ ovn/controller/ovn-controller.c | 42 ++++++++++++++++++- 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c index a4b30cb..7ec6074 100644 --- a/ovn/controller/binding.c +++ b/ovn/controller/binding.c @@ -615,6 +615,97 @@ binding_run(struct ovsdb_idl_txn *ovnsb_idl_txn, hmap_destroy(&qos_map); } +static bool +is_our_chassis(struct ovsdb_idl_index *sbrec_chassis_by_name, + const struct sbrec_chassis *chassis_rec, + const struct sbrec_port_binding *binding_rec, + const struct sset *active_tunnels, + const struct shash *lport_to_iface, + const struct sset *local_lports) +{ + const struct ovsrec_interface *iface_rec + = shash_find_data(lport_to_iface, binding_rec->logical_port); + struct ovs_list *gateway_chassis = NULL; + + bool our_chassis = false; + if (iface_rec + || (binding_rec->parent_port && binding_rec->parent_port[0] && + sset_contains(local_lports, binding_rec->parent_port))) { + /* This port is in our chassis unless it is a localport. */ + if (strcmp(binding_rec->type, "localport")) { + our_chassis = true; + } + } else if (!strcmp(binding_rec->type, "l2gateway")) { + const char *chassis_id = smap_get(&binding_rec->options, + "l2gateway-chassis"); + our_chassis = chassis_id && !strcmp(chassis_id, chassis_rec->name); + } else if (!strcmp(binding_rec->type, "chassisredirect")) { + gateway_chassis = gateway_chassis_get_ordered(sbrec_chassis_by_name, + binding_rec); + if (gateway_chassis && + gateway_chassis_contains(gateway_chassis, chassis_rec)) { + + our_chassis = gateway_chassis_is_active( + gateway_chassis, chassis_rec, active_tunnels); + + } + gateway_chassis_destroy(gateway_chassis); + } else if (!strcmp(binding_rec->type, "l3gateway")) { + const char *chassis_id = smap_get(&binding_rec->options, + "l3gateway-chassis"); + our_chassis = chassis_id && !strcmp(chassis_id, chassis_rec->name); + } else if (!strcmp(binding_rec->type, "localnet")) { + our_chassis = false; + } + + return our_chassis; +} + +/* Returns true if port-binding changes potentially require flow changes on + * the current chassis. Returns false if we are sure there is no impact. */ +bool +binding_evaluate_port_binding_changes( + struct ovsdb_idl_index *sbrec_chassis_by_name, + const struct sbrec_port_binding_table *pb_table, + const struct ovsrec_bridge *br_int, + const struct sbrec_chassis *chassis_rec, + struct sset *active_tunnels, + struct sset *local_lports) +{ + if (!chassis_rec) { + return true; + } + + const struct sbrec_port_binding *binding_rec; + struct shash lport_to_iface = SHASH_INITIALIZER(&lport_to_iface); + struct sset egress_ifaces = SSET_INITIALIZER(&egress_ifaces); + if (br_int) { + get_local_iface_ids(br_int, &lport_to_iface, local_lports, + &egress_ifaces); + } + SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding_rec, pb_table) { + /* XXX: currently OVSDB change tracking doesn't support getting old + * data when the operation is update, so if a port-binding moved from + * this chassis to another, we would not know it with this check. + * However, if the port is unbound from this chassis, the local ovsdb + * interface table will be updated, which will trigger recompute. + * If the port is still bound on this chassis, then below check + * is_our_chassis() will take care of that case. */ + if (binding_rec->chassis == chassis_rec) { + return true; + } + if (is_our_chassis(sbrec_chassis_by_name, chassis_rec, binding_rec, + active_tunnels, &lport_to_iface, local_lports) + || !strcmp(binding_rec->type, "patch") + || !strcmp(binding_rec->type, "localport") + || !strcmp(binding_rec->type, "vtep") + || !strcmp(binding_rec->type, "localnet")) { + return true; + } + } + return false; +} + /* Returns true if the database is all cleaned up, false if more work is * required. */ bool diff --git a/ovn/controller/binding.h b/ovn/controller/binding.h index 837e109..6c62cc5 100644 --- a/ovn/controller/binding.h +++ b/ovn/controller/binding.h @@ -48,5 +48,12 @@ void binding_run(struct ovsdb_idl_txn *ovnsb_idl_txn, bool binding_cleanup(struct ovsdb_idl_txn *ovnsb_idl_txn, const struct sbrec_port_binding_table *, const struct sbrec_chassis *); +bool binding_evaluate_port_binding_changes( + struct ovsdb_idl_index *sbrec_chassis_by_name, + const struct sbrec_port_binding_table *, + const struct ovsrec_bridge *br_int, + const struct sbrec_chassis *, + struct sset *active_tunnels, + struct sset *local_lports); #endif /* ovn/binding.h */ diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 9d78182..ed70c36 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -793,6 +793,46 @@ en_runtime_data_run(struct engine_node *node) node->changed = true; } +static bool +runtime_data_sb_port_binding_handler(struct engine_node *node) +{ + struct ed_type_runtime_data *data = + (struct ed_type_runtime_data *)node->data; + struct sset *local_lports = &data->local_lports; + struct sset *active_tunnels = &data->active_tunnels; + + 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 char *chassis_id = get_chassis_id(ovs_table); + const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table); + + ovs_assert(br_int && chassis_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 + = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id); + ovs_assert(chassis); + + struct sbrec_port_binding_table *pb_table = + (struct sbrec_port_binding_table *)EN_OVSDB_GET( + engine_get_input("SB_port_binding", node)); + + bool changed = binding_evaluate_port_binding_changes( + sbrec_chassis_by_name, pb_table, + br_int, chassis, active_tunnels, + local_lports); + + return !changed; +} + struct ed_type_flow_output { /* desired flows */ struct ovn_desired_flow_table flow_table; @@ -1125,7 +1165,7 @@ main(int argc, char *argv[]) engine_add_input(&en_runtime_data, &en_sb_address_set, NULL); engine_add_input(&en_runtime_data, &en_sb_port_group, NULL); engine_add_input(&en_runtime_data, &en_sb_datapath_binding, NULL); - engine_add_input(&en_runtime_data, &en_sb_port_binding, NULL); + engine_add_input(&en_runtime_data, &en_sb_port_binding, runtime_data_sb_port_binding_handler); engine_add_input(&en_runtime_data, &en_sb_gateway_chassis, NULL); engine_init(&en_flow_output);