From patchwork Thu Jan 5 02:13:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 711197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tvBBf2N8mz9svs for ; Thu, 5 Jan 2017 13:16:42 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B9D24C30; Thu, 5 Jan 2017 02:13:27 +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 09AEDC1D for ; Thu, 5 Jan 2017 02:13:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CB42590 for ; Thu, 5 Jan 2017 02:13:23 +0000 (UTC) Received: from mfilter36-d.gandi.net (mfilter36-d.gandi.net [217.70.178.167]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id AF855A80C8 for ; Thu, 5 Jan 2017 03:13:22 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter36-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter36-d.gandi.net (mfilter36-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id ol019IKLWRGq for ; Thu, 5 Jan 2017 03:13:21 +0100 (CET) X-Originating-IP: 208.91.2.3 Received: from localhost.localdomain (unknown [208.91.2.3]) (Authenticated sender: jpettit@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id B4F9FA80D2 for ; Thu, 5 Jan 2017 03:13:20 +0100 (CET) From: Justin Pettit To: dev@openvswitch.org Date: Wed, 4 Jan 2017 18:13:10 -0800 Message-Id: <1483582391-114359-8-git-send-email-jpettit@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483582391-114359-1-git-send-email-jpettit@ovn.org> References: <1483582391-114359-1-git-send-email-jpettit@ovn.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 8/9] ovn-test: Add 'expr-to-packets' command. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Parses OVN expressions from stdin and prints out matching packets in hexadecimal on stdout. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- tests/test-ovn.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/test-ovn.c b/tests/test-ovn.c index c0bc484..9165f5c 100644 --- a/tests/test-ovn.c +++ b/tests/test-ovn.c @@ -19,6 +19,7 @@ #include #include #include "command-line.h" +#include "dp-packet.h" #include "fatal-signal.h" #include "flow.h" #include "openvswitch/dynamic-string.h" @@ -1120,6 +1121,48 @@ test_exhaustive(struct ovs_cmdl_context *ctx OVS_UNUSED) expr_symtab_destroy(&symtab); shash_destroy(&symtab); } + +static void +test_expr_to_packets(struct ovs_cmdl_context *ctx OVS_UNUSED) +{ + struct shash symtab; + struct ds input; + + create_symtab(&symtab); + + ds_init(&input); + while (!ds_get_test_line(&input, stdin)) { + struct flow uflow; + memset(&uflow, '\0', sizeof uflow); + char *error = expr_parse_microflow(ds_cstr(&input), &symtab, NULL, + lookup_atoi_cb, NULL, &uflow); + if (error) { + puts(error); + free(error); + continue; + } + + uint64_t packet_stub[128 / 8]; + struct dp_packet packet; + dp_packet_use_stub(&packet, packet_stub, sizeof packet_stub); + flow_compose(&packet, &uflow); + + struct ds output = DS_EMPTY_INITIALIZER; + const uint8_t *buf = dp_packet_data(&packet); + for (int i = 0; i < dp_packet_size(&packet); i++) { + uint8_t val = buf[i]; + ds_put_format(&output, "%02"PRIx8, val); + } + puts(ds_cstr(&output)); + ds_destroy(&output); + + dp_packet_uninit(&packet); + } + ds_destroy(&input); + + expr_symtab_destroy(&symtab); + shash_destroy(&symtab); +} /* Actions. */ @@ -1291,10 +1334,14 @@ annotate-expr\n\ simplify-expr\n\ normalize-expr\n\ expr-to-flows\n\ - Parses OVN expressions from stdin and print them back on stdout after\n\ + Parses OVN expressions from stdin and prints them back on stdout after\n\ differing degrees of analysis. Available fields are based on packet\n\ headers.\n\ \n\ +expr-to-packets\n\ + Parses OVN expressions from stdin and prints out matching packets in\n\ + hexadecimal on stdout.\n\ +\n\ evaluate-expr MICROFLOW\n\ Parses OVN expressions from stdin and evaluates them against the flow\n\ specified in MICROFLOW, which must be an expression that constrains\n\ @@ -1451,6 +1498,7 @@ test_ovn_main(int argc, char *argv[]) {"composition", NULL, 1, 1, test_composition, OVS_RO}, {"tree-shape", NULL, 1, 1, test_tree_shape, OVS_RO}, {"exhaustive", NULL, 1, 1, test_exhaustive, OVS_RO}, + {"expr-to-packets", NULL, 0, 0, test_expr_to_packets, OVS_RO}, /* Actions. */ {"parse-actions", NULL, 0, 0, test_parse_actions, OVS_RO},