From patchwork Mon Aug 12 16:52:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jaime_Caama=C3=B1o_Ruiz?= X-Patchwork-Id: 1145807 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=none (p=none dis=none) header.from=suse.com 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 466hjm6cwqz9sN6 for ; Tue, 13 Aug 2019 02:52:59 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 69481C58; Mon, 12 Aug 2019 16:52:55 +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 CEABCB7A for ; Mon, 12 Aug 2019 16:52:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 49BA887D for ; Mon, 12 Aug 2019 16:52:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84407AEBB for ; Mon, 12 Aug 2019 16:52:51 +0000 (UTC) From: =?utf-8?q?Jaime_Caama=C3=B1o_Ruiz?= To: dev@openvswitch.org Date: Mon, 12 Aug 2019 18:52:27 +0200 Message-Id: <20190812165227.21609-1-jcaamano@suse.com> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: =?utf-8?q?Jaime_Caama=C3=B1o_Ruiz?= Subject: [ovs-dev] [PATCH] utilities: Improve ovs-dpctl-top flow parsing 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org * check that expected bytes and packets stats are correctly read from every flow. * check that the expected elements are read for every field type aggregation. Signed-off-by: Jaime CaamaƱo Ruiz --- utilities/ovs-dpctl-top.in | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in index 7f0f1f8c2..d8889b932 100755 --- a/utilities/ovs-dpctl-top.in +++ b/utilities/ovs-dpctl-top.in @@ -291,8 +291,9 @@ def element_passthrough_get(field_type, element, stats_dict): # pylint: disable-msg=R0903 class OutputFormat: """ Holds field_type and function to extract element value. """ - def __init__(self, field_type, generator): + def __init__(self, field_type, elements, generator): self.field_type = field_type + self.elements = elements self.generator = generator ## @@ -311,14 +312,14 @@ class OutputFormat: # All is added to the end of the OUTPUT_FORMAT list. ## OUTPUT_FORMAT = [ - OutputFormat("in_port", element_passthrough_get), - OutputFormat("eth", element_eth_get), - OutputFormat("eth_type", element_passthrough_get), - OutputFormat("ipv4", element_ipv4_get), - OutputFormat("ipv6", element_ipv6_get), - OutputFormat("udp", element_dst_port_get), - OutputFormat("tcp", element_dst_port_get), - OutputFormat("tunnel", element_tunnel_get), + OutputFormat("in_port", (), element_passthrough_get), + OutputFormat("eth", ("src","dst"), element_eth_get), + OutputFormat("eth_type", (), element_passthrough_get), + OutputFormat("ipv4", ("src","dst"), element_ipv4_get), + OutputFormat("ipv6", ("src","dst"), element_ipv6_get), + OutputFormat("udp", ("src","dst"), element_dst_port_get), + OutputFormat("tcp", ("src","dst"), element_dst_port_get), + OutputFormat("tunnel", ("src","dst"), element_tunnel_get), ] ## @@ -571,7 +572,7 @@ def flow_aggregate(fields_dict, stats_dict): for output_format in OUTPUT_FORMAT: field = fields_dict.get(output_format.field_type, None) - if (field): + if (field) and all (k in field for k in output_format.elements): obj = output_format.generator(output_format.field_type, field, stats_dict) result.append(obj) @@ -967,7 +968,7 @@ class FlowDB: raise ValueError("flow fields are missing %s", line) stats_dict = elements_to_dict(stats) - if (len(stats_dict) == 0): + if not all (k in stats_dict for k in ("packets","bytes")): raise ValueError("statistics are missing %s.", line) ##