ovs-ofctl: Implement documented semantics of --flow-format for flow_mods.
authorBen Pfaff <blp@nicira.com>
Tue, 22 Feb 2011 21:43:14 +0000 (13:43 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 1 Mar 2011 22:20:52 +0000 (14:20 -0800)
Also adds a test and moves some code around in tests/ to make sure that
OFPROTO_START and OFPROTO_STOP are available in tests/ovs-ofctl.at.

Reported-by: Michael Mao <mmao@nicira.com>
Bug #4566.

tests/automake.mk
tests/ofproto-macros.at [new file with mode: 0644]
tests/ofproto.at
tests/ovs-ofctl.at
tests/testsuite.at
utilities/ovs-ofctl.c

index 09ec23f2262ce8d82395c4b173f6dcdc668e4090..e2d3388a41b1446ef69254166636b3715e2edcc9 100644 (file)
@@ -25,6 +25,7 @@ TESTSUITE_AT = \
        tests/timeval.at \
        tests/lockfile.at \
        tests/reconnect.at \
+       tests/ofproto-macros.at \
        tests/ofproto.at \
        tests/ovsdb.at \
        tests/ovsdb-log.at \
diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
new file mode 100644 (file)
index 0000000..06f9b65
--- /dev/null
@@ -0,0 +1,16 @@
+m4_define([STRIP_XIDS], [[sed 's/ (xid=0x[0-9a-fA-F]*)//']])
+m4_define([STRIP_DURATION], [[sed 's/\bduration=[0-9.]*s/duration=?s/']])
+
+m4_define([OFPROTO_START],
+  [OVS_RUNDIR=$PWD; export OVS_RUNDIR
+   OVS_LOGDIR=$PWD; export OVS_LOGDIR
+   trap 'kill `cat ovs-openflowd.pid`' 0
+   AT_CAPTURE_FILE([ovs-openflowd.log])
+   AT_CHECK(
+     [ovs-openflowd --detach --pidfile --enable-dummy --log-file dummy@br0 none --datapath-id=fedcba9876543210 $1],
+     [0], [ignore], [ignore])
+])
+
+m4_define([OFPROTO_STOP],
+  [AT_CHECK([ovs-appctl -t ovs-openflowd exit])
+   trap '' 0])
index a7dda06f01af026d5ef146d945a7cf02bb0bd51f..f266f34be2cf2ecfa77182b88afd87c4802d4d1c 100644 (file)
@@ -1,22 +1,5 @@
 AT_BANNER([ofproto])
 
-m4_define([STRIP_XIDS], [[sed 's/ (xid=0x[0-9a-fA-F]*)//']])
-m4_define([STRIP_DURATION], [[sed 's/\bduration=[0-9.]*s/duration=?s/']])
-
-m4_define([OFPROTO_START],
-  [OVS_RUNDIR=$PWD; export OVS_RUNDIR
-   OVS_LOGDIR=$PWD; export OVS_LOGDIR
-   trap 'kill `cat ovs-openflowd.pid`' 0
-   AT_CAPTURE_FILE([ovs-openflowd.log])
-   AT_CHECK(
-     [ovs-openflowd --detach --pidfile --enable-dummy --log-file dummy@br0 none --datapath-id=fedcba9876543210 $1],
-     [0], [ignore], [ignore])
-])
-
-m4_define([OFPROTO_STOP],
-  [AT_CHECK([ovs-appctl -t ovs-openflowd exit])
-   trap '' 0])
-
 AT_SETUP([ofproto - echo request])
 OFPROTO_START
 AT_CHECK([ovs-ofctl -vANY:ANY:WARN probe br0])
index 111ed881ce846c2f411bcd625365448b55cdd79e..dfdebd3e4d6219c9c659eaf677f37aa9edb29921 100644 (file)
@@ -464,3 +464,25 @@ nx_pull_match() returned error 44010101
 nx_pull_match() returned error 44010101
 ])
 AT_CLEANUP
+
+dnl Check that "-F openflow10" rejects a flow_mod with a tun_id, since
+dnl OpenFlow 1.0 doesn't support tunnels.
+AT_SETUP([ovs-ofctl -F option and tun_id])
+AT_CHECK([ovs-ofctl -F openflow10 add-flow dummy tun_id=123,actions=drop],
+  [1], [], [ovs-ofctl: flow cannot be expressed in flow format openflow10 (flow format tun_id_from_cookie or better is required)
+])
+AT_CLEANUP
+
+dnl Check that "-F nxm" really forces add-flow to use the NXM flow format.
+dnl (If it doesn't, then either the tun_id won't show up at all, or it will
+dnl additionally show up as the top 32 bits of the cookie.)  This checks
+dnl for regression against bug #4566.
+AT_SETUP([ovs-ofctl -F option with flow_mods])
+OFPROTO_START
+AT_CHECK([ovs-ofctl -F nxm add-flow br0 tun_id=0x12345678,actions=drop])
+AT_CHECK([ovs-ofctl dump-flows br0 | STRIP_XIDS | STRIP_DURATION], [0], [dnl
+NXST_FLOW reply:
+ cookie=0x0, duration=?s, table_id=0, n_packets=0, n_bytes=0, tun_id=0x12345678 actions=drop
+])
+OFPROTO_STOP
+AT_CLEANUP
index d41f504b4e33c147a4583244579f9938eefff224..5625f8b0d9750faee8fe13a585f2874c1d405884 100644 (file)
@@ -1,6 +1,6 @@
 AT_INIT
 
-AT_COPYRIGHT([Copyright (c) 2009, 2010 Nicira Networks.
+AT_COPYRIGHT([Copyright (c) 2009, 2010, 2011 Nicira Networks.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ m4_define([OVS_WAIT_UNTIL], [OVS_WAIT([if $1; then exit 0; fi], [$2])])
 m4_define([OVS_WAIT_WHILE], [OVS_WAIT([if $1; then :; else exit 0; fi], [$2])])
 
 m4_include([tests/ovsdb-macros.at])
+m4_include([tests/ofproto-macros.at])
 
 m4_include([tests/library.at])
 m4_include([tests/classifier.at])
index 9f5a0a524f12640a06d930f74b7f3522a210d86c..a96b77a94be9e9634c0ac5b19fe551b7fb16d179 100644 (file)
@@ -622,6 +622,43 @@ do_queue_stats(int argc, char *argv[])
     dump_stats_transaction(argv[1], request);
 }
 
+/* Sets up the flow format for a vconn that will be used to modify the flow
+ * table.  Returns the flow format used, after possibly adding an OpenFlow
+ * request to 'requests'.
+ *
+ * If 'preferred_flow_format' is -1, returns NXFF_OPENFLOW10 without modifying
+ * 'requests', since NXFF_OPENFLOW10 is the default flow format for any
+ * OpenFlow connection.
+ *
+ * If 'preferred_flow_format' is a specific format, adds a request to set that
+ * format to 'requests' and returns the format. */
+static enum nx_flow_format
+set_initial_format_for_flow_mod(struct list *requests)
+{
+    if (preferred_flow_format < 0) {
+        return NXFF_OPENFLOW10;
+    } else {
+        struct ofpbuf *sff;
+
+        sff = ofputil_make_set_flow_format(preferred_flow_format);
+        list_push_back(requests, &sff->list_node);
+        return preferred_flow_format;
+    }
+}
+
+/* Checks that 'flow_format' is acceptable as a flow format after a flow_mod
+ * operation, given the global 'preferred_flow_format'. */
+static void
+check_final_format_for_flow_mod(enum nx_flow_format flow_format)
+{
+    if (preferred_flow_format >= 0 && flow_format != preferred_flow_format) {
+        ovs_fatal(0, "flow cannot be expressed in flow format %s "
+                  "(flow format %s or better is required)",
+                  ofputil_flow_format_to_string(preferred_flow_format),
+                  ofputil_flow_format_to_string(flow_format));
+    }
+}
+
 static void
 do_flow_mod__(int argc OVS_UNUSED, char *argv[], uint16_t command)
 {
@@ -630,9 +667,11 @@ do_flow_mod__(int argc OVS_UNUSED, char *argv[], uint16_t command)
     struct vconn *vconn;
 
     list_init(&requests);
-    flow_format = NXFF_OPENFLOW10;
+    flow_format = set_initial_format_for_flow_mod(&requests);
+
     parse_ofp_flow_mod_str(&requests, &flow_format, argc > 2 ? argv[2] : "",
                            command);
+    check_final_format_for_flow_mod(flow_format);
 
     open_vconn(argv[1], &vconn);
     transact_multiple_noreply(vconn, &requests);
@@ -659,10 +698,11 @@ do_add_flows(int argc OVS_UNUSED, char *argv[])
     }
 
     list_init(&requests);
-    flow_format = NXFF_OPENFLOW10;
+    flow_format = set_initial_format_for_flow_mod(&requests);
 
     open_vconn(argv[1], &vconn);
     while (parse_ofp_add_flow_file(&requests, &flow_format, file)) {
+        check_final_format_for_flow_mod(flow_format);
         transact_multiple_noreply(vconn, &requests);
     }
     vconn_close(vconn);