diff options
author | Justin Pettit <jpettit@ovn.org> | 2017-01-04 17:50:26 -0800 |
---|---|---|
committer | Justin Pettit <jpettit@ovn.org> | 2017-01-05 13:51:17 -0800 |
commit | 1e028b17dd25dd81bddd1db847edb584a3fbe4c7 (patch) | |
tree | d4025e0e1793497e9215a54e6aefb3e5f8079b8d /tests | |
parent | 714651c7db6a5cd8a22e2d0edb2d554718204bf3 (diff) | |
download | openvswitch-1e028b17dd25dd81bddd1db847edb584a3fbe4c7.tar.gz |
ovn-test: Add 'expr-to-packets' command.
Parses OVN expressions from stdin and prints out matching packets in
hexadecimal on stdout.
Signed-off-by: Justin Pettit <jpettit@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-ovn.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/test-ovn.c b/tests/test-ovn.c index c0bc48410..7edc0a014 100644 --- a/tests/test-ovn.c +++ b/tests/test-ovn.c @@ -19,6 +19,7 @@ #include <getopt.h> #include <sys/wait.h> #include "command-line.h" +#include "dp-packet.h" #include "fatal-signal.h" #include "flow.h" #include "openvswitch/dynamic-string.h" @@ -1120,6 +1121,47 @@ 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; + 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 +1333,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 +1497,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}, |