From: Ben Pfaff Date: Fri, 1 Oct 2010 20:08:14 +0000 (-0700) Subject: ofp-parse: Add test. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e581146fe81fce12c9e72cb70e06eba940720b5;p=openvswitch ofp-parse: Add test. --- diff --git a/tests/automake.mk b/tests/automake.mk index e647bbb9..1fac4578 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -12,6 +12,7 @@ TESTSUITE_AT = \ tests/check-structs.at \ tests/daemon.at \ tests/daemon-py.at \ + tests/ovs-ofctl.at \ tests/vconn.at \ tests/dir_name.at \ tests/aes128.at \ diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at new file mode 100644 index 00000000..2a0ce2cf --- /dev/null +++ b/tests/ovs-ofctl.at @@ -0,0 +1,22 @@ +AT_BANNER([ovs-ofctl]) + +AT_SETUP([ovs-ofctl parse-flows]) +AT_DATA([flows.txt], [ +# comment +tcp,tp_src=123,actions=flood +in_port=LOCAL dl_vlan=9 dl_src=00:0A:E4:25:6B:B0 actions=drop +arp,nw_src=192.168.0.1,actions=drop_spoofed_arp,NORMAL +udp dl_vlan_pcp=7 idle_timeout=5 actions=strip_vlan output:0 +cookie=0x123456789abcdef hard_timeout=10 priority=60000 actions=controller +actions=drop +]) +AT_CHECK([ovs-ofctl parse-flows flows.txt], [0], [stdout]) +AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [dnl +flow_mod: tcp,tp_src=123, ADD: actions=FLOOD +flow_mod: in_port=65534,dl_vlan=9,dl_src=00:0a:e4:25:6b:b0, ADD: actions=drop +flow_mod: arp,nw_src=192.168.0.1, ADD: actions=drop_spoofed_arp,NORMAL +flow_mod: udp,dl_vlan_pcp=7, ADD: idle:5 actions=strip_vlan,output:0 +flow_mod: ADD: cookie:0x123456789abcdef hard:10 pri:60000 actions=CONTROLLER:65535 +flow_mod: ADD: actions=drop +]) +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index 42e62dfb..d66563c8 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -42,6 +42,7 @@ m4_include([tests/classifier.at]) m4_include([tests/check-structs.at]) m4_include([tests/daemon.at]) m4_include([tests/daemon-py.at]) +m4_include([tests/ovs-ofctl.at]) m4_include([tests/vconn.at]) m4_include([tests/dir_name.at]) m4_include([tests/aes128.at]) diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index c21c4f98..13f583e7 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -859,6 +859,26 @@ do_benchmark(int argc OVS_UNUSED, char *argv[]) count * message_size / (duration / 1000.0)); } +/* This command is really only useful for testing the flow parser (ofp_parse), + * so it is undocumented. */ +static void +do_parse_flows(int argc OVS_UNUSED, char *argv[]) +{ + struct ofpbuf *b; + FILE *file; + + file = fopen(argv[1], "r"); + if (file == NULL) { + ovs_fatal(errno, "%s: open", argv[2]); + } + + while ((b = parse_ofp_add_flow_file(file)) != NULL) { + ofp_print(stdout, b->data, b->size, 0); + ofpbuf_delete(b); + } + fclose(file); +} + static void do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { @@ -885,6 +905,7 @@ static const struct command all_commands[] = { { "probe", 1, 1, do_probe }, { "ping", 1, 2, do_ping }, { "benchmark", 3, 3, do_benchmark }, + { "parse-flows", 1, 1, do_parse_flows }, { "help", 0, INT_MAX, do_help }, { NULL, 0, 0, NULL }, };