Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
[sliver-openvswitch.git] / tests / ofproto-macros.at
index 229e014..fe765ee 100644 (file)
+m4_divert_push([PREPARE_TESTS])
+[
+# Strips out uninteresting parts of ovs-ofctl output, as well as parts
+# that vary from one run to another.
+ofctl_strip () {
+    sed '
+s/ (xid=0x[0-9a-fA-F]*)//
+s/ duration=[0-9.]*s,//
+s/ cookie=0x0,//
+s/ table=0,//
+s/ n_packets=0,//
+s/ n_bytes=0,//
+s/ idle_age=[0-9]*,//
+s/ hard_age=[0-9]*,//
+'
+}
+
+# parse_listening_port [SERVER]
+#
+# Parses the TCP or SSL port on which a server is listening from the
+# log, given that the server was told to listen on a kernel-chosen
+# port, file provided on stdin, and prints the port number on stdout.
+# You should specify the listening remote as ptcp:0:127.0.0.1 or
+# pssl:0:127.0.0.1, or the equivalent with [::1] instead of 127.0.0.1.
+#
+# Here's an example of how to use this with ovsdb-server:
+#
+#    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
+#    ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ...
+#    TCP_PORT=`parse_listening_port < ovsdb-server.log`
+parse_listening_port () {
+    sed -n 's/.*0:.*: listening on port \([0-9]*\)$/\1/p'
+}]
+m4_divert_pop([PREPARE_TESTS])
+
 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([STRIP_USED], [[sed 's/used:[0-9]\.[0-9]*/used:0.0/']])
 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
 
-m4_define([OFPROTO_START],
-  [OVS_RUNDIR=$PWD; export OVS_RUNDIR
-   OVS_LOGDIR=$PWD; export OVS_LOGDIR
-   trap 'kill `cat test-openflowd.pid`' 0
-   AT_CAPTURE_FILE([test-openflowd.log])
-   AT_CHECK(
-     [test-openflowd --detach --pidfile --enable-dummy --log-file --fail=closed dummy@br0 none --datapath-id=fedcba9876543210 $1],
-     [0], [], [stderr])
-   AT_CHECK([[sed < stderr '
-/vlog|INFO|opened log file/d
-/openflowd|INFO|Open vSwitch version/d
-/openflowd|INFO|OpenFlow protocol version/d
-/ofproto|INFO|using datapath ID/d
-/ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
-])
-
-m4_define([OFPROTO_STOP],
-  [AT_CHECK([ovs-appctl -t test-openflowd exit])
-   trap '' 0])
-
+# OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override])
+#
+# Creates a database and starts ovsdb-server, starts ovs-vswitchd
+# connected to that database, calls ovs-vsctl to create a bridge named
+# br0 with predictable settings, passing 'vsctl-args' as additional
+# commands to ovs-vsctl.  If 'vsctl-args' causes ovs-vsctl to provide
+# output (e.g. because it includes "create" commands) then 'vsctl-output'
+# specifies the expected output after filtering through uuidfilt.pl.
+#
+# If a test needs to use "system" devices (as dummies), then specify
+# =override (literally) as the third argument.  Otherwise, system devices
+# won't work at all (which makes sense because tests should not access a
+# system's real Ethernet devices).
 m4_define([OVS_VSWITCHD_START],
-  [dnl Skip this test if running as root.  Otherwise ovs-vswitchd will tear
-   dnl down any existing datapaths if the kernel module is loaded.
-   AT_SKIP_IF([test "`id -u`" = 0])
-
-   OVS_RUNDIR=$PWD; export OVS_RUNDIR
-   OVS_LOGDIR=$PWD; export OVS_LOGDIR
-   OVS_SYSCONFDIR=$PWD; export OVS_SYSCONFDIR
-   trap 'kill `cat ovsdb-server.pid ovs-vswitchd.pid`' 0
+  [OVS_RUNDIR=`pwd`; export OVS_RUNDIR
+   OVS_LOGDIR=`pwd`; export OVS_LOGDIR
+   OVS_DBDIR=`pwd`; export OVS_DBDIR
+   OVS_SYSCONFDIR=`pwd`; export OVS_SYSCONFDIR
+   ON_EXIT([kill `cat ovsdb-server.pid ovs-vswitchd.pid`])
 
    dnl Create database.
-   mkdir openvswitch
-   touch openvswitch/.conf.db.~lock~
-   AT_CHECK([ovsdb-tool create openvswitch/conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
+   touch .conf.db.~lock~
+   AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
 
    dnl Start ovsdb-server.
-   AT_CHECK([ovsdb-server --detach --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
-   AT_CHECK([[sed < stderr '/vlog|INFO|opened log file/d']])
+   AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
+   AT_CHECK([[sed < stderr '
+/vlog|INFO|opened log file/d
+/ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
    AT_CAPTURE_FILE([ovsdb-server.log])
 
    dnl Initialize database.
    AT_CHECK([ovs-vsctl --no-wait init])
 
    dnl Start ovs-vswitchd.
-   AT_CHECK([ovs-vswitchd --detach --pidfile --enable-dummy --log-file], [0], [], [stderr])
+   AT_CHECK([ovs-vswitchd --detach --no-chdir --pidfile --enable-dummy$3 --disable-system --log-file -vvconn -vofproto_dpif], [0], [], [stderr])
    AT_CAPTURE_FILE([ovs-vswitchd.log])
    AT_CHECK([[sed < stderr '
 /vlog|INFO|opened log file/d
+/vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
 /reconnect|INFO|/d
-/dpif_linux|ERR|Generic Netlink family.*does not exist/d
-/dpif|WARN|failed to enumerate system datapaths: No such file or directory/d
 /ofproto|INFO|using datapath ID/d
 /ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
 
    dnl Add bridges, ports, etc.
-   AT_CHECK([ovs-vsctl -- add-br br0 -- set bridge br0 datapath-type=dummy other-config:datapath-id=fedcba9876543210 -- $1])
+   AT_CHECK([ovs-vsctl -- add-br br0 -- set bridge br0 datapath-type=dummy other-config:datapath-id=fedcba9876543210 other-config:hwaddr=aa:55:aa:55:00:00 fail-mode=secure -- $1 m4_if([$2], [], [], [| ${PERL} $srcdir/uuidfilt.pl])], [0], [$2])
 ])
 
+m4_divert_push([PREPARE_TESTS])
+check_logs () {
+    sed -n "$1
+/timeval.*Unreasonably long [[0-9]]*ms poll interval/d
+/timeval.*faults: [[0-9]]* minor, [[0-9]]* major/d
+/timeval.*disk: [[0-9]]* reads, [[0-9]]* writes/d
+/timeval.*context switches: [[0-9]]* voluntary, [[0-9]]* involuntary/d
+/ovs_rcu.*blocked [[0-9]]* ms waiting for .* to quiesce/d
+/|WARN|/p
+/|ERR|/p
+/|EMER|/p" ovs-vswitchd.log ovsdb-server.log
+}
+m4_divert_pop([PREPARE_TESTS])
+
+# OVS_VSWITCHD_STOP([WHITELIST])
+#
+# Gracefully stops ovs-vswitchd and ovsdb-server, checking their log files
+# for messages with severity WARN or higher and signaling an error if any
+# is present.  The optional WHITELIST may contain shell-quoted "sed"
+# commands to delete any warnings that are actually expected, e.g.:
+#
+#   OVS_VSWITCHD_STOP(["/expected error/d"])
 m4_define([OVS_VSWITCHD_STOP],
-  [AT_CHECK([ovs-appctl -t ovs-vswitchd exit])
-   AT_CHECK([ovs-appctl -t ovsdb-server exit])
-   trap '' 0])
+  [AT_CHECK([check_logs $1])
+   AT_CHECK([ovs-appctl -t ovs-vswitchd exit])
+   AT_CHECK([ovs-appctl -t ovsdb-server exit])])
+
+# ADD_OF_PORTS(BRIDGE, OF_PORT[, OF_PORT...])
+#
+# Creates a dummy interface with an OpenFlow port number of OF_PORT and
+# name of p{OF_PORT}.  The dummy implementation will treat the OF_PORT
+# as the datapath port number, which as the effect of making the
+# OpenFlow and datapath numbers the same.
+m4_define([ADD_OF_PORTS],
+ [ovs-vsctl m4_foreach([of_port], m4_cdr($@),
+    [ \
+    -- add-port $1 p[]of_port -- set Interface p[]of_port type=dummy ofport_request=of_port])])