ofp-parse: Add test.
authorBen Pfaff <blp@nicira.com>
Fri, 1 Oct 2010 20:08:14 +0000 (13:08 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 1 Oct 2010 20:09:05 +0000 (13:09 -0700)
tests/automake.mk
tests/ovs-ofctl.at [new file with mode: 0644]
tests/testsuite.at
utilities/ovs-ofctl.c

index e647bbb99d516aa4a4faf7e154e3cb5e14a6520c..1fac4578282abd09a0aa35c3d0fa0a7e61a73b63 100644 (file)
@@ -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 (file)
index 0000000..2a0ce2c
--- /dev/null
@@ -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
index 42e62dfbea8f89c3c954629673a6a68f339012df..d66563c8fc2da921a379261aab96a9e9a4df4c76 100644 (file)
@@ -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])
index c21c4f982e3f7a53031f4f62516d536ae1ce5748..13f583e7e3a1bbb064cb4bac1e03d37115370642 100644 (file)
@@ -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 },
 };