From patchwork Sat May 22 18:49:00 2021
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Alexey Roytman
X-Patchwork-Id: 1482434
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.166.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=KzLv/WSV;
dkim-atps=neutral
Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.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 4FnXZW1hh2z9sRN
for ; Sun, 23 May 2021 04:49:21 +1000 (AEST)
Received: from localhost (localhost [127.0.0.1])
by smtp1.osuosl.org (Postfix) with ESMTP id DAFB683B56;
Sat, 22 May 2021 18:49:18 +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 asMhLANPZqNY; Sat, 22 May 2021 18:49:17 +0000 (UTC)
Received: from lists.linuxfoundation.org (lf-lists.osuosl.org
[IPv6:2605:bc80:3010:104::8cd3:938])
by smtp1.osuosl.org (Postfix) with ESMTP id 0862C837A4;
Sat, 22 May 2021 18:49:16 +0000 (UTC)
Received: from lf-lists.osuosl.org (localhost [127.0.0.1])
by lists.linuxfoundation.org (Postfix) with ESMTP id CE070C000D;
Sat, 22 May 2021 18:49:15 +0000 (UTC)
X-Original-To: dev@openvswitch.org
Delivered-To: ovs-dev@lists.linuxfoundation.org
Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133])
by lists.linuxfoundation.org (Postfix) with ESMTP id 00AD9C0001
for ; Sat, 22 May 2021 18:49:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
by smtp2.osuosl.org (Postfix) with ESMTP id DB5ED40178
for ; Sat, 22 May 2021 18:49:14 +0000 (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Authentication-Results: smtp2.osuosl.org (amavisd-new);
dkim=pass (2048-bit key) header.d=gmail.com
Received: from smtp2.osuosl.org ([127.0.0.1])
by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id efoUOprPr6bh for ;
Sat, 22 May 2021 18:49:13 +0000 (UTC)
X-Greylist: whitelisted by SQLgrey-1.8.0
Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com
[IPv6:2a00:1450:4864:20::635])
by smtp2.osuosl.org (Postfix) with ESMTPS id 5EDC240002
for ; Sat, 22 May 2021 18:49:13 +0000 (UTC)
Received: by mail-ej1-x635.google.com with SMTP id et19so28367595ejc.4
for ; Sat, 22 May 2021 11:49:13 -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=ivcNRPzrS8yHiGOSqhId8qp8RFBulc0LNYzMjH0YAm0=;
b=KzLv/WSV34meQPg9BaWP4auiwCS4eY4c18MYYQEPTNdzux5ZRvXxPW5wfE/ME8Cmtt
WhrHZryi6FSNaSmHoK2rHZB+NiMEFQ7UbEVgLr9icv/fHqcxZ0kKVj0X/06OI8tPO5QD
qmg6VMcJUVvFhqbvZGYkXwj2tUyL+txHvEdMM6z0tKlhNoKoGI5d+QRaO37XBBQIyBF8
pteAD6F9NBHwK8lhA5ECpE2w1MMpNdNvlgtUrmlx5gmEROnMfzeAVURcuAp6yjCdEr+J
p9gm5aPmbYvcQP4Y27/511QNXYoRcnsGHGPx0EQQUdDcHTI1eJTR4gnXN7d+ZhxjsoaK
Na/A==
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=ivcNRPzrS8yHiGOSqhId8qp8RFBulc0LNYzMjH0YAm0=;
b=CrRxWNBmd9DvDsGBgjQVDcEIxnfTNSEMFXUANgMD13etrHhkpUVYYLtE/EvxNxF0yS
jE1ckQq1p5w6MzayFPNpkuEbtNXe7PXl9frY0yoI/FoUVxZqfuu3n5GIxm7rJolhnIhO
LAjIMCxD+a4xrileiS9Id2DbS5riF/HG9vmjSTAr5ID2POUW63Jk4zQJrbVkWWQdOyCr
BvD2yIwGZhm3ItpAYBVJYxZfUyrV46HprJE0ywnjvqv48oYCtdrl3NyreWPLWUs2zAo2
KGboM0IknbixC7gPoABkN755kQrh62SmzzLNrFf2etN6GCSO8FhaI7WR8ntaDwUA7lXa
Lhgw==
X-Gm-Message-State: AOAM530okqmevQxq0jHt0AHCBR20rPhg9ewAr7W+8tDonwGTW36qfG1q
Ir38Vs562GGQzHAXe6kBRTT0EtdDixY=
X-Google-Smtp-Source:
ABdhPJxGbON5Mf2Sm7wyZfUC4957pJq7JZQbp1xwnZ5+ikM9yjzKc3ydd5eHFMcEVQ15FlMZVN1/iw==
X-Received: by 2002:a17:906:5495:: with SMTP id
r21mr16002127ejo.471.1621709351145;
Sat, 22 May 2021 11:49:11 -0700 (PDT)
Received: from localhost (109-186-150-93.bb.netvision.net.il.
[109.186.150.93])
by smtp.gmail.com with ESMTPSA id zg18sm5606118ejb.41.2021.05.22.11.49.10
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Sat, 22 May 2021 11:49:10 -0700 (PDT)
From: Alexey Roytman
To: dev@openvswitch.org
Date: Sat, 22 May 2021 21:49:00 +0300
Message-Id: <20210522184900.736461-1-aroytman@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Cc: Alexey Roytman
Subject: [ovs-dev] [PATCH ovn v4] ovn-sbctl.c Add logical flows count numbers
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"
From: Alexey Roytman
For big scale deployments, when number of logical flows can be 2M+,
sometimes users just need to know the total number of logical flows
and numbers of logical flows per table/per datapath.
New command output
Datapath: "sw1" (4b1e53d8-9f0f-4768-b4a6-6cbc58a4bfda) pipeline: ingress
table=0 (ls_in_port_sec_l2 ) lflows=2
table=1 (ls_in_port_sec_ip ) lflows=1
table=2 (ls_in_port_sec_nd ) lflows=1
table=3 (ls_in_lookup_fdb ) lflows=1
table=4 (ls_in_put_fdb ) lflows=1
table=5 (ls_in_pre_acl ) lflows=2
table=6 (ls_in_pre_lb ) lflows=3
table=7 (ls_in_pre_stateful ) lflows=2
table=8 (ls_in_acl_hint ) lflows=1
table=9 (ls_in_acl ) lflows=2
table=10(ls_in_qos_mark ) lflows=1
table=11(ls_in_qos_meter ) lflows=1
table=12(ls_in_lb ) lflows=1
table=13(ls_in_stateful ) lflows=8
table=14(ls_in_pre_hairpin ) lflows=1
table=15(ls_in_nat_hairpin ) lflows=1
table=16(ls_in_hairpin ) lflows=1
table=17(ls_in_arp_rsp ) lflows=1
table=18(ls_in_dhcp_options ) lflows=1
table=19(ls_in_dhcp_response) lflows=1
table=20(ls_in_dns_lookup ) lflows=1
table=21(ls_in_dns_response ) lflows=1
table=22(ls_in_external_port) lflows=1
table=23(ls_in_l2_lkup ) lflows=3
table=24(ls_in_l2_unknown ) lflows=2
Total number of logical flows in the datapath "sw1" (4b1e53d8-9f0f-4768-b4a6-6cbc58a4bfda) pipeline: ingress = 41
Datapath: "sw1" (4b1e53d8-9f0f-4768-b4a6-6cbc58a4bfda) pipeline: egress
table=0 (ls_out_pre_lb ) lflows=3
table=1 (ls_out_pre_acl ) lflows=2
table=2 (ls_out_pre_stateful) lflows=2
table=3 (ls_out_lb ) lflows=1
table=4 (ls_out_acl_hint ) lflows=1
table=5 (ls_out_acl ) lflows=2
table=6 (ls_out_qos_mark ) lflows=1
table=7 (ls_out_qos_meter ) lflows=1
table=8 (ls_out_stateful ) lflows=3
table=9 (ls_out_port_sec_ip ) lflows=1
table=10(ls_out_port_sec_l2 ) lflows=1
Total number of logical flows in the datapath "sw1" (4b1e53d8-9f0f-4768-b4a6-6cbc58a4bfda) pipeline: egress = 18
Total number of logical flows = 59
Signed-off-by: Alexey Roytman
---
v3 -> v4
* Addressed review comments from Mark
tests/ovn-sbctl.at | 44 ++++++++++++++++-
utilities/ovn-sbctl.8.xml | 10 ++++
utilities/ovn-sbctl.c | 100 ++++++++++++++++++++++++++++++++++----
3 files changed, 144 insertions(+), 10 deletions(-)
diff --git a/tests/ovn-sbctl.at b/tests/ovn-sbctl.at
index f49134381..34ee452e5 100644
--- a/tests/ovn-sbctl.at
+++ b/tests/ovn-sbctl.at
@@ -175,4 +175,46 @@ inactivity_probe : 30000
OVN_SBCTL_TEST([ovn_sbctl_invalid_0x_flow], [invalid 0x flow], [
check ovn-sbctl lflow-list 0x12345678
-])
\ No newline at end of file
+])
+
+dnl ---------------------------------------------------------------------
+
+AT_SETUP([ovn-sbctl --count lflow-list/dump-flows])
+OVN_SBCTL_TEST_START
+
+count_entries() {
+ ovn-sbctl --column=_uuid list Logical_Flow | sed -r '/^\s*$/d' | wc -l
+}
+
+count_pipeline() {
+ ovn-sbctl --column=pipeline list Logical_Flow | grep $1 | sed -r '/^\s*$/d' | wc -l
+}
+
+# we start with empty Logical_Flow table
+# validate that the table is indeed empty
+AT_CHECK([count_entries], [0], [dnl
+0
+])
+
+AT_CHECK([ovn-sbctl --count lflow-list], [0], [dnl
+Total number of logical flows = 0
+])
+
+# create some logical flows
+check ovn-nbctl ls-add count-test
+total_lflows=`count_entries`
+egress_lflows=`count_pipeline egress`
+ingress_lflows=`count_pipeline ingress`
+
+AT_CHECK_UNQUOTED([ovn-sbctl --count lflow-list | grep "flows =" | awk 'NF>1{print $NF}'], [0], [dnl
+$total_lflows
+])
+AT_CHECK_UNQUOTED([ovn-sbctl --count lflow-list | grep Total | grep egress | awk 'NF>1{print $NF}'], [0], [dnl
+$egress_lflows
+])
+AT_CHECK_UNQUOTED([ovn-sbctl --count lflow-list | grep Total | grep ingress | awk 'NF>1{print $NF}'], [0], [dnl
+$ingress_lflows
+])
+
+OVN_SBCTL_TEST_STOP
+AT_CLEANUP
diff --git a/utilities/ovn-sbctl.8.xml b/utilities/ovn-sbctl.8.xml
index 4e6b21c47..2030bcda9 100644
--- a/utilities/ovn-sbctl.8.xml
+++ b/utilities/ovn-sbctl.8.xml
@@ -416,10 +416,20 @@
chassis. The --ovs
and --stats
can also be used in conjunction with --vflows
.
+
+
+ --count
lflow-list
[logical-datapath]
+ prints numbers of logical flows per table and per datapath.
+
+
[--uuid
] dump-flows
[logical-datapath]
Alias for lflow-list
.
+
+ --count
dump-flow
[logical-datapath]
+ Alias for --count
lflow-list
[logical-datapath]
+
Remote Connectivity Commands
diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c
index 53f10cdd8..ca9d21d52 100644
--- a/utilities/ovn-sbctl.c
+++ b/utilities/ovn-sbctl.c
@@ -898,11 +898,92 @@ sbctl_lflow_add(struct sbctl_lflow **lflows,
if (*n_flows == *n_capacity) {
*lflows = x2nrealloc(*lflows, n_capacity, sizeof **lflows);
}
- (*lflows)[*n_flows].lflow = lflow;
- (*lflows)[*n_flows].dp = dp;
+ (*lflows)[ *n_flows ].lflow = lflow;
+ (*lflows)[ *n_flows ].dp = dp;
(*n_flows)++;
}
+static void
+print_datapath_prompt(const struct sbrec_datapath_binding *dp,
+ const struct uuid *uuid,
+ char *pipeline) {
+ printf("Datapath: ");
+ print_datapath_name(dp);
+ printf(" ("UUID_FMT") pipeline: %s\n", UUID_ARGS(uuid), pipeline);
+}
+
+static void
+print_datapath_sum(const struct sbrec_datapath_binding *dp,
+ const struct uuid *uuid,
+ char *pipeline,
+ long lflows) {
+ printf("Total number of logical flows in the datapath ");
+ print_datapath_name(dp);
+ printf(" ("UUID_FMT") pipeline: %s = %ld\n\n",
+ UUID_ARGS(uuid), pipeline, lflows);
+}
+
+
+static void
+print_lflows_count(int64_t table_id, const char *name, long count) {
+ printf(" table=%-2"PRId64"(%-19s) lflows=%ld\n", \
+ table_id, name, count);
+}
+
+static void
+print_lflow_counters(size_t n_flows, struct sbctl_lflow *lflows)
+{
+ const struct sbctl_lflow *curr, *prev = NULL;
+ long table_lflows = 0;
+ long dp_lflows = 0;
+
+ for (size_t i = 0; i < n_flows; i++) {
+ bool new_datapath = false;
+ curr = &lflows[i];
+ if (!prev
+ || prev->dp != curr->dp
+ || strcmp(prev->lflow->pipeline, curr->lflow->pipeline)) {
+ new_datapath = true;
+ }
+
+ if (prev &&
+ (prev->lflow->table_id != curr->lflow->table_id || new_datapath)) {
+ print_lflows_count(prev->lflow->table_id,
+ smap_get_def(&prev->lflow->external_ids, "stage-name", ""),
+ table_lflows);
+ table_lflows = 1;
+ if (new_datapath) {
+ print_datapath_sum(prev->dp, &prev->dp->header_.uuid,
+ prev->lflow->pipeline, dp_lflows);
+ dp_lflows = 1;
+ } else {
+ dp_lflows++;
+ }
+ } else {
+ dp_lflows++;
+ table_lflows++;
+ }
+
+ if (new_datapath) {
+ print_datapath_prompt(curr->dp,
+ &curr->dp->header_.uuid,
+ curr->lflow->pipeline);
+ }
+ prev = curr;
+ }
+ if (n_flows > 0) {
+ print_lflows_count(prev->lflow->table_id,
+ smap_get_def(&prev->lflow->external_ids,
+ "stage-name",
+ ""),
+ table_lflows);
+ print_datapath_sum(prev->dp, &prev->dp->header_.uuid,
+ prev->lflow->pipeline, dp_lflows);
+
+ }
+ printf("Total number of logical flows = %ld\n", n_flows);
+}
+
static void
cmd_lflow_list(struct ctl_context *ctx)
{
@@ -966,6 +1047,10 @@ cmd_lflow_list(struct ctl_context *ctx)
qsort(lflows, n_flows, sizeof *lflows, sbctl_lflow_cmp);
}
+ if (shash_find(&ctx->options, "--count") != NULL) {
+ print_lflow_counters(n_flows, lflows);
+ goto cleanup;
+ }
bool print_uuid = shash_find(&ctx->options, "--uuid") != NULL;
const struct sbctl_lflow *curr, *prev = NULL;
@@ -997,11 +1082,7 @@ cmd_lflow_list(struct ctl_context *ctx)
if (!prev
|| prev->dp != curr->dp
|| strcmp(prev->lflow->pipeline, curr->lflow->pipeline)) {
- printf("Datapath: ");
- print_datapath_name(curr->dp);
- printf(" ("UUID_FMT") Pipeline: %s\n",
- UUID_ARGS(&curr->dp->header_.uuid),
- curr->lflow->pipeline);
+ print_datapath_prompt(curr->dp, &curr->dp->header_.uuid, curr->lflow->pipeline);
}
/* Print the flow. */
@@ -1028,6 +1109,7 @@ cmd_lflow_list(struct ctl_context *ctx)
cmd_lflow_list_load_balancers(ctx, vconn, datapath, stats, print_uuid);
}
+cleanup:
vconn_close(vconn);
free(lflows);
}
@@ -1375,10 +1457,10 @@ static const struct ctl_command_syntax sbctl_commands[] = {
/* Logical flow commands */
{"lflow-list", 0, INT_MAX, "[DATAPATH] [LFLOW...]",
pre_get_info, cmd_lflow_list, NULL,
- "--uuid,--ovs?,--stats,--vflows?", RO},
+ "--uuid,--ovs?,--stats,--vflows?,--count?", RO},
{"dump-flows", 0, INT_MAX, "[DATAPATH] [LFLOW...]",
pre_get_info, cmd_lflow_list, NULL,
- "--uuid,--ovs?,--stats,--vflows?",
+ "--uuid,--ovs?,--stats,--vflows?,--count?",
RO}, /* Friendly alias for lflow-list */
/* IP multicast commands. */