From patchwork Wed Apr 24 19:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Moreno?= X-Patchwork-Id: 1927354 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=f5LnQNva; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VPqSy3BZMz1yP2 for ; Thu, 25 Apr 2024 05:54:42 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B2F1A82660; Wed, 24 Apr 2024 19:54:40 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 0MVZCYjjPrST; Wed, 24 Apr 2024 19:54:38 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 654BA824A4 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=f5LnQNva Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 654BA824A4; Wed, 24 Apr 2024 19:54:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 019D6C0077; Wed, 24 Apr 2024 19:54:25 +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 0DA2AC0077 for ; Wed, 24 Apr 2024 19:54:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2633F417B0 for ; Wed, 24 Apr 2024 19:54:08 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id RxOJmGm1IBb7 for ; Wed, 24 Apr 2024 19:54:06 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 4ED974181C Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4ED974181C Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=f5LnQNva Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4ED974181C for ; Wed, 24 Apr 2024 19:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713988444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8r5ZipTVDR1826WALrLWImBLulhYf+f/tQ1YTO92eQI=; b=f5LnQNvatKrFHLK073sJdpwt78C0JtG7VNXyvyX47k6S7jgFlYyUrg4uRRPFQEKBoNMhZv UYrjvxTrTsvCiZNZUjEnmRroKVjgxqGcaVuJHz0YZrNT29/WIrI+j4Xv7rHhS3tPkyoUjE Bv+em+W1nrQ4+2dm0Ih6aNCRX0AQLGc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-syLQaQ3gPNKn92YFtDdOXw-1; Wed, 24 Apr 2024 15:54:00 -0400 X-MC-Unique: syLQaQ3gPNKn92YFtDdOXw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 613BF29AA38F; Wed, 24 Apr 2024 19:54:00 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.193.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13BEE2031A45; Wed, 24 Apr 2024 19:53:58 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Wed, 24 Apr 2024 21:53:36 +0200 Message-ID: <20240424195337.3596657-11-amorenoz@redhat.com> In-Reply-To: <20240424195337.3596657-1-amorenoz@redhat.com> References: <20240424195337.3596657-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC 10/11] ofproto-dpif-psample: Add command to show stats. 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" Signed-off-by: Adrian Moreno --- ofproto/ofproto-dpif-psample.c | 59 ++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif-psample.h | 1 + ofproto/ofproto-dpif.c | 1 + 3 files changed, 61 insertions(+) diff --git a/ofproto/ofproto-dpif-psample.c b/ofproto/ofproto-dpif-psample.c index ea4926eb2..2d73a4ded 100644 --- a/ofproto/ofproto-dpif-psample.c +++ b/ofproto/ofproto-dpif-psample.c @@ -20,9 +20,12 @@ #include "dpif.h" #include "hash.h" #include "ofproto.h" +#include "ofproto-dpif.h" +#include "openvswitch/dynamic-string.h" #include "openvswitch/hmap.h" #include "openvswitch/thread.h" #include "openvswitch/vlog.h" +#include "unixctl.h" VLOG_DEFINE_THIS_MODULE(psample); @@ -205,3 +208,59 @@ dpif_psample_unref(struct dpif_psample *ps) OVS_EXCLUDED(mutex) dpif_psample_destroy(ps); } } + +/* Unix commands. */ +static void +psample_unixctl_show(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) +{ + struct psample_exporter_map_node *node; + struct ds ds = DS_EMPTY_INITIALIZER; + const struct ofproto_dpif *ofproto; + bool first = true; + + ofproto = ofproto_dpif_lookup_by_name(argv[1]); + if (!ofproto) { + unixctl_command_reply_error(conn, "no such bridge"); + return; + } + + if (!ofproto->psample) { + unixctl_command_reply_error(conn, "no psample exporters configured"); + return; + } + + ds_put_format(&ds, "Psample statistics for bridge \"%s\":\n", argv[1]); + + ovs_mutex_lock(&mutex); + HMAP_FOR_EACH (node, node, &ofproto->psample->exporters_map) { + if (!first) { + ds_put_cstr(&ds, "\n"); + } else { + first = false; + } + + ds_put_format(&ds, "- Collector Set ID: %"PRIu32"\n", + node->exporter.collector_set_id); + ds_put_format(&ds, " Psample Group ID: %"PRIu32"\n", + node->exporter.group_id); + ds_put_format(&ds, " Total number of bytes: %"PRIu64"\n", + node->exporter.n_bytes); + ds_put_format(&ds, " Total number of packets: %"PRIu64"\n", + node->exporter.n_packets); + } + ovs_mutex_unlock(&mutex); + + unixctl_command_reply(conn, ds_cstr(&ds)); + ds_destroy(&ds); +} + +void dpif_psample_init(void) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + if (ovsthread_once_start(&once)) { + unixctl_command_register("psample/show", "bridge", 1, 1, + psample_unixctl_show, NULL); + ovsthread_once_done(&once); + } +} diff --git a/ofproto/ofproto-dpif-psample.h b/ofproto/ofproto-dpif-psample.h index 763fbd30b..f264ad4c2 100644 --- a/ofproto/ofproto-dpif-psample.h +++ b/ofproto/ofproto-dpif-psample.h @@ -34,5 +34,6 @@ bool dpif_psample_get_group_id(struct dpif_psample *, uint32_t, uint32_t *); void dpif_psample_credit_stats(struct dpif_psample *, uint32_t, const struct dpif_flow_stats *); +void dpif_psample_init(void); #endif // OFPROTO_DPIF_PSAMPLE_H diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index f1efdd482..ebb399307 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -287,6 +287,7 @@ init(const struct shash *iface_hints) ofproto_unixctl_init(); ofproto_dpif_trace_init(); udpif_init(); + dpif_psample_init(); } static void