From patchwork Tue May 17 00:56:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 622806 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3r7zTH5hHlz9sDC for ; Tue, 17 May 2016 10:57:55 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id B322C105A2; Mon, 16 May 2016 17:57:18 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 1915710563 for ; Mon, 16 May 2016 17:57:16 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 6DDCF162113 for ; Mon, 16 May 2016 18:57:15 -0600 (MDT) X-ASG-Debug-ID: 1463446634-0b3237192a73390001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar6.cudamail.com with ESMTP id NFmqsbcEyXOQEH8K (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 16 May 2016 18:57:14 -0600 (MDT) X-Barracuda-Envelope-From: diproiettod@vmware.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO smtp-outbound-2.vmware.com) (208.91.2.13) by mx3-pf3.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 17 May 2016 00:57:14 -0000 Received-SPF: error (mx3-pf3.cudamail.com: error in processing during lookup of vmware.com: DNS problem) X-Barracuda-Apparent-Source-IP: 208.91.2.13 X-Barracuda-RBL-IP: 208.91.2.13 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id CAB6A98223 for ; Mon, 16 May 2016 17:57:12 -0700 (PDT) Received: from sc9-mailhost2.vmware.com (htb-1n-eng-dhcp491.eng.vmware.com [10.33.75.235]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id EAE2018568; Mon, 16 May 2016 17:57:13 -0700 (PDT) X-CudaMail-Envelope-Sender: diproiettod@vmware.com From: Daniele Di Proietto To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-515061147 X-CudaMail-DTE: 051616 X-CudaMail-Originating-IP: 208.91.2.13 Date: Mon, 16 May 2016 17:56:32 -0700 X-ASG-Orig-Subj: [##CM-V3-515061147##][PATCH v3 07/16] tests: Add test-conntrack pcap test. Message-Id: <1463446601-12916-8-git-send-email-diproiettod@vmware.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463446601-12916-1-git-send-email-diproiettod@vmware.com> References: <1463446601-12916-1-git-send-email-diproiettod@vmware.com> X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1463446634 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-ASG-Whitelist: EmailCat (corporate) Subject: [ovs-dev] [PATCH v3 07/16] tests: Add test-conntrack pcap test. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Simple program that runs the packet in a pcap file through the connection tracker and prints the 'ct_state' for each packet. E.g. the line: `./test/ovstest test-conntrack capture.pcap 2` sends the packets in `capture.pcap` to the connection tracker, 2 per call. Useful for debugging. Signed-off-by: Daniele Di Proietto Acked-by: Flavio Leitner --- tests/test-conntrack.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/test-conntrack.c b/tests/test-conntrack.c index de18e1a..157b51f 100644 --- a/tests/test-conntrack.c +++ b/tests/test-conntrack.c @@ -23,6 +23,7 @@ #include "netdev.h" #include "ovs-thread.h" #include "ovstest.h" +#include "pcap-file.h" #include "timeval.h" static const char payload[] = "50540000000a50540000000908004500001c0000000000" @@ -143,6 +144,67 @@ test_benchmark(struct ovs_cmdl_context *ctx) pthread_barrier_destroy(&barrier); free(threads); } + +static void +test_pcap(struct ovs_cmdl_context *ctx) +{ + struct dp_packet *pkts[NETDEV_MAX_BURST]; + size_t total_count, i, pkt_count, batch_size; + FILE *pcap; + int err; + + pcap = ovs_pcap_open(ctx->argv[1], "rb"); + if (!pcap) { + return; + } + + batch_size = 1; + if (ctx->argc > 2) { + batch_size = strtoul(ctx->argv[2], NULL, 0); + if (batch_size == 0 || batch_size > NETDEV_MAX_BURST) { + ovs_fatal(0, + "batch_size must be between 1 and NETDEV_MAX_BURST(%u)", + NETDEV_MAX_BURST); + } + } + + conntrack_init(&ct); + total_count = 0; + for (;;) { + for (i = 0; i < batch_size; i++) { + struct flow dummy_flow; + + err = ovs_pcap_read(pcap, &pkts[i], NULL); + if (err) { + break; + } + flow_extract(pkts[i], &dummy_flow); + } + + pkt_count = i; + if (pkt_count == 0) { + break; + } + + conntrack_execute(&ct, pkts, pkt_count, true, 0, NULL, NULL, NULL); + + for (i = 0; i < pkt_count; i++) { + struct ds ds = DS_EMPTY_INITIALIZER; + + total_count++; + + format_flags(&ds, ct_state_to_string, pkts[i]->md.ct_state, '|'); + printf("%"PRIuSIZE": %s\n", total_count, ds_cstr(&ds)); + + dp_packet_delete(pkts[i]); + ds_destroy(&ds); + } + if (err) { + break; + } + } + conntrack_destroy(&ct); +} static const struct ovs_cmdl_command commands[] = { /* Connection tracker tests. */ @@ -152,6 +214,10 @@ static const struct ovs_cmdl_command commands[] = { * destination port */ {"benchmark", "n_threads n_pkts batch_size [change_connection]", 3, 4, test_benchmark}, + /* Reads packets from 'file' and sends them to the connection tracker, + * 'batch_size' (1 by default) per call, with the commit flag set. + * Prints the ct_state of each packet. */ + {"pcap", "file [batch_size]", 1, 2, test_pcap}, {NULL, NULL, 0, 0, NULL}, };