From patchwork Thu May 24 22:10: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: 920132 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="shHkMjzC"; 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 40sNv44jrfz9s0q for ; Fri, 25 May 2018 08:13:36 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BAFC2D91; Thu, 24 May 2018 22:10:28 +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 9E720D67 for ; Thu, 24 May 2018 22:10:24 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f41.google.com (mail-pg0-f41.google.com [74.125.83.41]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 131EE6D3 for ; Thu, 24 May 2018 22:10:24 +0000 (UTC) Received: by mail-pg0-f41.google.com with SMTP id 15-v6so1056317pge.2 for ; Thu, 24 May 2018 15:10:23 -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=H00atMnAqaRst0t72BZmvSBov+5nwsFXXQrmhtaAQ98=; b=shHkMjzCC/XX/2e1EPm4xyz/YIBvNQA+le+5hllwHH44GVBVPZ2Q2vRTs3mVyoo2b4 TVB+v9Er54UJCMOujF2qTme1NXfOVBbo/mxPLXXWU/uB3eZYgUf3YldpNrEWs+H8XuHO N9tQC0Jr4e7i5Vm5ci8ZyB79GVLr+VtwNrcWiT+O2XAtd64LTnHAy8JG9fPG2+/AqnlQ JF1fvGt6pI3RxhHb/TNWu1fjsWJmfZ1S5EUhmf5LU3gbmGKVy9Aq1D62nMR6JQvmWtQq MHkuiSD1OzFu3TWZgKQ1gKljteFpf2+UK3AH/OdR8wQ+9uY9gB2K4XUl5ptgex8pc5HU xDCQ== 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=H00atMnAqaRst0t72BZmvSBov+5nwsFXXQrmhtaAQ98=; b=EWdD7Q3FBdscDJUY/q9dDC9VBP3zmdotJzsB5yTorcjobLvyc2cJiVCm/ASXE83MIU FpkLxzwtUZARMrqEAVZ7i4bmKGVf4OfPiwoTI4A9Ho1VqTeo0xLTFDdMtf49zCHO9JgA qbAq5U+vbWgtIj0Jxz+KCRW0Beq54E/ZhRisseiX5j2NKspaNrhRE3Gk0knmNuja329L eospWEf8UwXX04oXJd4+fWfo/Uw+Uag8Gnk+kGuJNsT/GgWC6a9pSQon0uvyWM0EG7Ek ylt6mk5QhcywGBZZSY3GtWS+iJn2vfw7CgJtUmYVmIaor7UkTs6XMvLiDvX5LU6QUvlM SvBQ== X-Gm-Message-State: ALKqPwdn1hm6J9NeWN83IVLDK9Be1UGKnW89MrW6r5ECFxBdZSU37FmF Nee63YOEw+JvbOBYt7RElxUHkA== X-Google-Smtp-Source: AB8JxZolMrzRCMGrHnOQocqYalvKZqx/h6Bh1yzEw4aiacHhEse330DjuAQ4iIz/V13n3GmZ5RgCiA== X-Received: by 2002:a63:79ce:: with SMTP id u197-v6mr7299349pgc.284.1527199823400; Thu, 24 May 2018 15:10:23 -0700 (PDT) Received: from localhost.localdomain.localdomain ([216.113.160.70]) by smtp.gmail.com with ESMTPSA id y18-v6sm47493651pfi.104.2018.05.24.15.10.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 15:10:22 -0700 (PDT) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Thu, 24 May 2018 15:10:48 -0700 Message-Id: <1527199851-107563-8-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1527199851-107563-1-git-send-email-hzhou8@ebay.com> References: <1527199851-107563-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 v2 07/10] 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 | 92 +++++++++++++++++++++++++++++++++++++++++ ovn/controller/binding.h | 4 ++ ovn/controller/ovn-controller.c | 28 ++++++++++++- 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c index 84ff4d6..0c5b47b 100644 --- a/ovn/controller/binding.c +++ b/ovn/controller/binding.c @@ -580,6 +580,98 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int, hmap_destroy(&qos_map); } +static bool +is_our_chassis(const struct chassis_index *chassis_index, + struct sset *active_tunnels, + const struct sbrec_chassis *chassis_rec, + const struct sbrec_port_binding *binding_rec, + struct shash *lport_to_iface, + 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(binding_rec, + chassis_index); + 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 controller_ctx *ctx, const struct ovsrec_bridge *br_int, + const struct sbrec_chassis *chassis_rec, + const struct chassis_index *chassis_index, + 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_FOR_EACH_TRACKED (binding_rec, ctx->ovnsb_idl) { + /* 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 that case. */ + if (binding_rec->chassis == chassis_rec) { + return true; + } + if (is_our_chassis(chassis_index, + active_tunnels, chassis_rec, binding_rec, + &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 89fc2ec..ea4fb81 100644 --- a/ovn/controller/binding.h +++ b/ovn/controller/binding.h @@ -34,5 +34,9 @@ void binding_run(struct controller_ctx *, const struct ovsrec_bridge *br_int, struct sset *active_tunnels, struct hmap *local_datapaths, struct sset *local_lports, struct sset *local_lport_ids); bool binding_cleanup(struct controller_ctx *, const struct sbrec_chassis *); +bool binding_evaluate_port_binding_changes( + struct controller_ctx *ctx, const struct ovsrec_bridge *br_int, + const struct sbrec_chassis *, const struct chassis_index *, + 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 7f81c93..215146b 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -745,6 +745,32 @@ en_runtime_data_run(struct engine_node *node) node->changed = true; } +static bool +runtime_data_sb_port_binding_handler(struct engine_node *node) +{ + struct controller_ctx *ctx = (struct controller_ctx *)node->context; + 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 chassis_index *chassis_index = &data->chassis_index; + + const char *chassis_id = get_chassis_id(ctx->ovs_idl); + const struct ovsrec_bridge *br_int = get_br_int(ctx); + + ovs_assert(br_int && chassis_id); + const struct sbrec_chassis *chassis = NULL; + chassis = get_chassis(ctx->ovnsb_idl, chassis_id); + ovs_assert(chassis); + + bool changed = binding_evaluate_port_binding_changes( + ctx, br_int, chassis, + chassis_index, active_tunnels, + local_lports); + + return !changed; +} + struct ed_type_flow_output { /* desired flows */ struct ovn_desired_flow_table flow_table; @@ -977,7 +1003,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);