[ovs-dev] [ofp-parse-test 3/3] ofp-parse: Add test.
Ben Pfaff
blp at nicira.com
Fri Oct 1 20:49:58 UTC 2010
---
tests/automake.mk | 1 +
tests/ovs-ofctl.at | 22 ++++++++++++++++++++++
tests/testsuite.at | 1 +
utilities/ovs-ofctl.c | 21 +++++++++++++++++++++
4 files changed, 45 insertions(+), 0 deletions(-)
create mode 100644 tests/ovs-ofctl.at
diff --git a/tests/automake.mk b/tests/automake.mk
index e647bbb..1fac457 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 0000000..2a0ce2c
--- /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 42e62df..d66563c 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 55278fb..9045f74 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -894,6 +894,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)
{
@@ -920,6 +940,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 },
};
--
1.7.1
More information about the dev
mailing list