From patchwork Mon Oct 21 00:51:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1180139 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.169.12; helo=mail.linuxfoundation.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 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 46xJDB2mgYz9sPV for ; Mon, 21 Oct 2019 11:58:34 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id F2290CC9; Mon, 21 Oct 2019 00:51:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 26E77CAB for ; Mon, 21 Oct 2019 00:51:56 +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 smtp2.linuxfoundation.org (Postfix) with ESMTPS id E4A8E1DAA7 for ; Mon, 21 Oct 2019 00:51:54 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [216.113.160.71]) (Authenticated sender: hzhou@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 47007100005; Mon, 21 Oct 2019 00:51:51 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sun, 20 Oct 2019 17:51:12 -0700 Message-Id: <1571619079-75503-13-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1571619079-75503-1-git-send-email-hzhou@ovn.org> References: <1571619079-75503-1-git-send-email-hzhou@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn 12/19] ovn-ic: Transit switch controller. 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 Processing transit switches and sync between INB, ISB and NB. Signed-off-by: Han Zhou --- ic/ovn-ic.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ northd/ovn-northd.c | 8 ++++ ovn-nb.xml | 10 +++++ ovn-sb.xml | 9 +++++ tests/ovn-ic.at | 41 +++++++++++++++++++ 5 files changed, 181 insertions(+) diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c index 7cc80bc..0a8c7df 100644 --- a/ic/ovn-ic.c +++ b/ic/ovn-ic.c @@ -139,11 +139,124 @@ az_run(struct ic_context *ctx) return NULL; } +static uint32_t +allocate_ts_dp_key(struct hmap *dp_tnlids) +{ + static uint32_t hint = OVN_MIN_DP_KEY_GLOBAL; + return ovn_allocate_tnlid(dp_tnlids, "transit switch datapath", + OVN_MIN_DP_KEY_GLOBAL, OVN_MAX_DP_KEY_GLOBAL, + &hint); +} + +static void +ts_run(struct ic_context *ctx) +{ + const struct inbrec_transit_switch *ts; + + /* Sync INB TS to AZ NB */ + if (ctx->ovnnb_txn) { + struct shash nb_tses = SHASH_INITIALIZER(&nb_tses); + const struct nbrec_logical_switch *ls; + + /* Get current NB Logical_Switch with other_config:interconn-ts */ + NBREC_LOGICAL_SWITCH_FOR_EACH (ls, ctx->ovnnb_idl) { + const char *ts_name = smap_get(&ls->other_config, "interconn-ts"); + if (ts_name) { + shash_add(&nb_tses, ts_name, ls); + } + } + + /* Create NB Logical_Switch for each TS */ + INBREC_TRANSIT_SWITCH_FOR_EACH (ts, ctx->ovninb_idl) { + ls = shash_find_and_delete(&nb_tses, ts->name); + if (!ls) { + ls = nbrec_logical_switch_insert(ctx->ovnnb_txn); + nbrec_logical_switch_set_name(ls, ts->name); + nbrec_logical_switch_update_other_config_setkey(ls, + "interconn-ts", + ts->name); + } + } + + /* Delete extra NB Logical_Switch with other_config:interconn-ts */ + struct shash_node *node; + SHASH_FOR_EACH (node, &nb_tses) { + nbrec_logical_switch_delete(node->data); + } + shash_destroy(&nb_tses); + } + + struct hmap dp_tnlids = HMAP_INITIALIZER(&dp_tnlids); + struct shash isb_dps = SHASH_INITIALIZER(&isb_dps); + const struct isbrec_datapath_binding *isb_dp; + ISBREC_DATAPATH_BINDING_FOR_EACH (isb_dp, ctx->ovnisb_idl) { + shash_add(&isb_dps, isb_dp->transit_switch, isb_dp); + ovn_add_tnlid(&dp_tnlids, isb_dp->tunnel_key); + } + + /* Sync ISB TS tunnel key to AZ SB datapath. (AZ SB datapath is created by + * northd.) */ + if (ctx->ovnsb_txn) { + const struct sbrec_datapath_binding *sb_dp; + SBREC_DATAPATH_BINDING_FOR_EACH (sb_dp, ctx->ovnsb_idl) { + const char *ts_name = smap_get(&sb_dp->external_ids, + "interconn-ts"); + if (ts_name) { + isb_dp = shash_find_data(&isb_dps, ts_name); + if (!isb_dp) { + VLOG_DBG("SB datapath "UUID_FMT" with interconn-ts %s not " + "found in ISB, ignore.", + UUID_ARGS(&sb_dp->header_.uuid), + ts_name); + continue; + } + sbrec_datapath_binding_set_tunnel_key(sb_dp, + isb_dp->tunnel_key); + } + } + } + + /* Sync TS between INB and ISB. This is performed after syncing with AZ + * SB, to avoid uncommitted ISB datapath tunnel key to be synced back to + * AZ. */ + if (ctx->ovnisb_txn) { + /* Create ISB Datapath_Binding */ + INBREC_TRANSIT_SWITCH_FOR_EACH (ts, ctx->ovninb_idl) { + isb_dp = shash_find_and_delete(&isb_dps, ts->name); + if (!isb_dp) { + /* Allocate tunnel key */ + int64_t dp_key = allocate_ts_dp_key(&dp_tnlids); + if (!dp_key) { + continue; + } + + isb_dp = isbrec_datapath_binding_insert(ctx->ovnisb_txn); + isbrec_datapath_binding_set_transit_switch(isb_dp, ts->name); + isbrec_datapath_binding_set_tunnel_key(isb_dp, dp_key); + } + } + + /* Delete extra ISB Datapath_Binding */ + struct shash_node *node; + SHASH_FOR_EACH (node, &isb_dps) { + isbrec_datapath_binding_delete(node->data); + } + } + ovn_destroy_tnlids(&dp_tnlids); + shash_destroy(&isb_dps); +} + static void ovn_db_run(struct ic_context *ctx) { const struct isbrec_availability_zone *az = az_run(ctx); VLOG_DBG("Availability zone: %s", az ? az->name : "not created yet."); + + if (!az) { + return; + } + + ts_run(ctx); } static void diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 1582f1f..ccce96a 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -866,6 +866,14 @@ ovn_datapath_update_external_ids(struct ovn_datapath *od) if (name2 && name2[0]) { smap_add(&ids, "name2", name2); } + + /* Set interconn-ts. */ + if (od->nbs) { + const char *ts = smap_get(&od->nbs->other_config, "interconn-ts"); + if (ts) { + smap_add(&ids, "interconn-ts", ts); + } + } sbrec_datapath_binding_set_external_ids(od->sb, &ids); smap_destroy(&ids); } diff --git a/ovn-nb.xml b/ovn-nb.xml index 05091fb..a24a587 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -354,6 +354,16 @@ + + + The + of corresponding transit switch in + database. This kind of logical switch is created and controlled + by ovn-ic. + + + See External IDs at the beginning of this document. diff --git a/ovn-sb.xml b/ovn-sb.xml index e5fb51a..471310d 100644 --- a/ovn-sb.xml +++ b/ovn-sb.xml @@ -2291,6 +2291,15 @@ tcp.flags = RST; the database. + + For a logical datapath that represents a logical switch that represents + a transit switch for interconnection, ovn-northd stores in + this key the value of the same interconn-ts key of the + column of the corresponding row in the database. + +

ovn-northd copies these from the name fields in the