From patchwork Mon Aug 30 19:01:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Odintsov X-Patchwork-Id: 1522309 X-Patchwork-Delegate: zhouhan@gmail.com 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=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=dVr4uLuN; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gz06l5Ylfz9sT6 for ; Tue, 31 Aug 2021 05:01:51 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id F09BE80F45; Mon, 30 Aug 2021 19:01:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 93qZLOU7Gmrw; Mon, 30 Aug 2021 19:01:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4D4E680F03; Mon, 30 Aug 2021 19:01:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A175C001A; Mon, 30 Aug 2021 19:01:44 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 65185C000E for ; Mon, 30 Aug 2021 19:01:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4095680F08 for ; Mon, 30 Aug 2021 19:01:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VvdGAW5B8-Dv for ; Mon, 30 Aug 2021 19:01:42 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8563280F03 for ; Mon, 30 Aug 2021 19:01:42 +0000 (UTC) Received: by mail-ed1-x52a.google.com with SMTP id g22so23137239edy.12 for ; Mon, 30 Aug 2021 12:01:42 -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:mime-version :content-transfer-encoding; bh=3iGmpN1VNV/cNlgo5ZEpRJSRX4H1RttiCyYJoDYM7BA=; b=dVr4uLuN/SpoqwM/5M41s0sq0TDkWvr6tc/pRE7njYPfbfzNF4UBlTBfwyBdE3sXtp FKy/nYJDmAg99wlM33lF1ZgL38oQlpQjlxuYLWEt8D+9gxYZsv5ij9tROvzF7OHorPgT zrvp2tuDhpZQkPF8C0x0DTseTE2C4scWN514Vzvy3bcnXxXrpCUQ+Nzps9C3/2fhJddH Q3wjBwe/mvQyWaTuAenQLH9I86qVvG3pRucczY2xVNhGyX66Pdxj43dJ4F2vymFmfNxd vER+oal06oPz4E2O0YU9ASdAM4w17AMnVrBxUf6oEjcwjX43meftmDoO7dR994Y8wrsF IcLg== 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:mime-version :content-transfer-encoding; bh=3iGmpN1VNV/cNlgo5ZEpRJSRX4H1RttiCyYJoDYM7BA=; b=oGvXxyhrCAfDD/FQhzcZH4+7JGWp9+6nQVBR/Vv9urlIjsmpJRycSqepdK33wE52mY o09Y97y1QtOCwYh5cMHbDzox2kokFLzeh30Y7w4nOn39AR0URUjRv7RL6JUhZ2hyDRwH QrDmXsQxpRGGW3+UL+JwJ890rYWCkzc2GaGYWOoBK7e5HHhJh+HzmZJLy8ufX4ezmtQh pgcWXdpF5gyGjn4TTmhdvTBTkFWiQYkkaTNlHb5PpDhUk74IjRyJNQlgAmLocI0TJ3ex E79Qtcvep5h1QySlWFbY7U8dtQTAsIdyjfB/epHoWwN6rFb8DI/6TRZ3FddgsZbECDpl xDZw== X-Gm-Message-State: AOAM533G01dW7TLgzPW3H+lBpmSjM+vic7i6Iy1M9jqdwM4/9bG2NpK8 VlMvx3mn1iwOPVwkzr0MwCzioIWtRWw= X-Google-Smtp-Source: ABdhPJxefkKkr0NzBklTygCGYDSJVRxRSoprVxA1wgvN4uJZSlJN7nOMt/LKl5Xyq/t4kweYnEXUaw== X-Received: by 2002:a05:6402:3ce:: with SMTP id t14mr24764160edw.191.1630350100623; Mon, 30 Aug 2021 12:01:40 -0700 (PDT) Received: from localhost.localdomain ([85.187.18.241]) by smtp.gmail.com with ESMTPSA id ck4sm3616571edb.67.2021.08.30.12.01.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Aug 2021 12:01:40 -0700 (PDT) From: Vladislav Odintsov To: dev@openvswitch.org Date: Mon, 30 Aug 2021 22:01:38 +0300 Message-Id: <20210830190138.97835-1-odivlad@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Cc: Vladislav Odintsov Subject: [ovs-dev] [PATCH ovn] ic: use ovsdb_index to iterate over routes 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" Small optimization in routes advertizement code. Instead of iterating over all routes and checking for needed transit_switch and availability_zone, use ovsdb_index built with appropriate fields. Signed-off-by: Vladislav Odintsov --- ic/ovn-ic.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c index fc608af82..f5e31bd80 100644 --- a/ic/ovn-ic.c +++ b/ic/ovn-ic.c @@ -68,6 +68,7 @@ struct ic_context { struct ovsdb_idl_index *sbrec_port_binding_by_name; struct ovsdb_idl_index *icsbrec_port_binding_by_ts; struct ovsdb_idl_index *icsbrec_route_by_ts; + struct ovsdb_idl_index *icsbrec_route_by_ts_az; }; struct ic_state { @@ -1292,15 +1293,13 @@ advertise_route(struct ic_context *ctx, { ovs_assert(ctx->ovnisb_txn); const struct icsbrec_route *isb_route; - ICSBREC_ROUTE_FOR_EACH (isb_route, ctx->ovnisb_idl) { - if (strcmp(isb_route->transit_switch, ts_name)) { - continue; - } - - if (isb_route->availability_zone != az) { - continue; - } + const struct icsbrec_route *isb_route_key = + icsbrec_route_index_init_row(ctx->icsbrec_route_by_ts_az); + icsbrec_route_index_set_transit_switch(isb_route_key, ts_name); + icsbrec_route_index_set_availability_zone(isb_route_key, az); + ICSBREC_ROUTE_FOR_EACH_EQUAL (isb_route, isb_route_key, + ctx->icsbrec_route_by_ts_az) { struct in6_addr prefix, nexthop; unsigned int plen; @@ -1329,6 +1328,7 @@ advertise_route(struct ic_context *ctx, free(route_adv); } } + icsbrec_route_index_destroy_row(isb_route_key); /* Create the missing routes in IC-SB */ struct ic_route_info *route_adv, *next; @@ -1732,6 +1732,11 @@ main(int argc, char *argv[]) = ovsdb_idl_index_create1(ovnisb_idl_loop.idl, &icsbrec_route_col_transit_switch); + struct ovsdb_idl_index *icsbrec_route_by_ts_az + = ovsdb_idl_index_create2(ovnisb_idl_loop.idl, + &icsbrec_route_col_transit_switch, + &icsbrec_route_col_availability_zone); + /* Main loop. */ exiting = false; state.had_lock = false; @@ -1773,6 +1778,7 @@ main(int argc, char *argv[]) .sbrec_chassis_by_name = sbrec_chassis_by_name, .icsbrec_port_binding_by_ts = icsbrec_port_binding_by_ts, .icsbrec_route_by_ts = icsbrec_route_by_ts, + .icsbrec_route_by_ts_az = icsbrec_route_by_ts_az, }; if (!state.had_lock && ovsdb_idl_has_lock(ovnsb_idl_loop.idl)) {