1 m4_divert_push([PREPARE_TESTS])
3 # Strips out uninteresting parts of ovs-ofctl output, as well as parts
4 # that vary from one run to another.
7 s/ (xid=0x[0-9a-fA-F]*)//
8 s/ duration=[0-9.]*s,//
15 s/dp_hash=0x[0-9a-f]*\//dp_hash=0x0\//
16 s/recirc_id=0x[0-9a-f]*,/recirc_id=0x0,/
17 s/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z|//
18 s/dir\/[0-9]*\/br0.mgmt/dir\/XXXX\/br0.mgmt/
22 # Filter (multiline) vconn debug messages from ovs-vswitchd.log.
23 # Use with vconn_sub() and ofctl_strip()
24 print_vconn_debug () { awk -F\| < ovs-vswitchd.log '
26 /\|vconn\|DBG\|/ { sub(/[ \t]*$/, ""); print $3 "|" $4 "|" $5; prt=1; next }
27 $4 != "" { prt=0; next }
28 prt==1 { sub(/[ \t]*$/, ""); print $0 }
34 s/tcp:127.0.0.1:[0-9][0-9]*:/unix:/
40 # PARSE_LISTENING_PORT LOGFILE VARIABLE
42 # Parses the TCP or SSL port on which a server is listening from
43 # LOGFILE, given that the server was told to listen on a kernel-chosen
44 # port, and assigns the port number to shell VARIABLE. You should
45 # specify the listening remote as ptcp:0:127.0.0.1 or
46 # pssl:0:127.0.0.1, or the equivalent with [::1] instead of 127.0.0.1.
48 # Here's an example of how to use this with ovsdb-server:
50 # ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ...
51 # PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
52 # # Now $TCP_PORT holds the listening port.
53 m4_define([PARSE_LISTENING_PORT],
54 [OVS_WAIT_UNTIL([$2=`sed -n 's/.*0:.*: listening on port \([[0-9]]*\)$/\1/p' "$1"` && test X != X"[$]$2"])])
57 "$@" -vconsole:off --detach --no-chdir --pidfile --log-file
58 pidfile="$OVS_RUNDIR"/$1.pid
59 on_exit "test -e \"$pidfile\" && kill \`cat \"$pidfile\"\`"
64 # Starts a new simulated Open vSwitch instance named SANDBOX. Files related to
65 # the instance, such as logs, databases, sockets, and pidfiles, are created in
66 # a subdirectory of the main test directory also named SANDBOX. Afterward, the
67 # "as" command (see below) can be used to run Open vSwitch utilities in the
68 # context of the new sandbox.
70 # The new sandbox starts out without any bridges. Use ovs-vsctl in the context
71 # of the new sandbox to create a bridge, e.g.:
73 # sim_add hv0 # Create sandbox hv0.
74 # as hv0 # Set hv0 as default sandbox.
75 # ovs-vsctl add-br br0 # Add bridge br0 inside hv0.
80 # as hv0 ovs-vsctl add-br br0
83 echo "adding simulator '$1'"
88 local d="$ovs_base"/$1
89 mkdir "$d" || return 1
92 # Create database and start ovsdb-server.
93 : > "$d"/.conf.db.~lock~
94 as $1 ovsdb-tool create "$d"/conf.db "$abs_top_srcdir"/vswitchd/vswitch.ovsschema || return 1
95 as $1 start_daemon ovsdb-server --remote=punix:"$d"/db.sock || return 1
97 # Initialize database.
98 as $1 ovs-vsctl --no-wait -- init || return 1
101 as $1 start_daemon ovs-vswitchd --enable-dummy=system -vvconn -vofproto_dpif -vunixctl
104 # "as $1" sets the OVS_*DIR environment variables to point to $ovs_base/$1.
106 # "as $1 COMMAND..." sets those variables in a subshell and invokes COMMAND
109 if test "X$2" != X; then
110 (ovs_setenv $1; shift; "$@")
116 # Strips 'xid=0x1234' from ovs-ofctl output.
118 sed 's/ (xid=0x[[0-9a-fA-F]]*)//'
121 # Changes all 'used:...' to say 'used:0.0', to make output easier to compare.
123 sed 's/used:[[0-9]]\.[[0-9]]*/used:0.0/'
126 # Removes all 'duration=...' to make output easier to compare.
128 sed 's/duration=[[0-9]]*\.[[0-9]]*s,//'
131 # Strips 'ufid:...' from output, to make it easier to compare.
132 # (ufids are random.)
134 sed 's/mega_ufid:[[-0-9a-f]]* //
135 s/ufid:[[-0-9a-f]]* //'
137 m4_divert_pop([PREPARE_TESTS])
139 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
141 # _OVS_VSWITCHD_START([vswitchd-aux-args])
143 # Creates an empty database and starts ovsdb-server.
144 # Starts ovs-vswitchd, with additional arguments 'vswitchd-aux-args'.
146 m4_define([_OVS_VSWITCHD_START],
147 [dnl Create database.
148 touch .conf.db.~lock~
149 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
151 dnl Start ovsdb-server.
152 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
153 on_exit "kill `cat ovsdb-server.pid`"
154 AT_CHECK([[sed < stderr '
155 /vlog|INFO|opened log file/d
156 /ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
157 AT_CAPTURE_FILE([ovsdb-server.log])
159 dnl Initialize database.
160 AT_CHECK([ovs-vsctl --no-wait init $2])
162 dnl Start ovs-vswitchd.
163 AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
164 AT_CAPTURE_FILE([ovs-vswitchd.log])
165 on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`"
166 AT_CHECK([[sed < stderr '
167 /ovs_numa|INFO|Discovered /d
168 /vlog|INFO|opened log file/d
169 /vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
171 /dpif_netlink|INFO|Generic Netlink family .ovs_datapath. does not exist/d
172 /ofproto|INFO|using datapath ID/d
173 /netdev_linux|INFO|.*device has unknown hardware address family/d
174 /ofproto|INFO|datapath ID changed to fedcba9876543210/d
175 /dpdk|INFO|DPDK Disabled - Use other_config:dpdk-init to enable/d
176 /netlink_socket|INFO|netlink: could not enable listening to all nsid/d
178 /tc: Using policy/d']])
181 # OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override],
182 # [vswitchd-aux-args])
184 # Creates a database and starts ovsdb-server, starts ovs-vswitchd
185 # connected to that database, calls ovs-vsctl to create a bridge named
186 # br0 with predictable settings, passing 'vsctl-args' as additional
187 # commands to ovs-vsctl. If 'vsctl-args' causes ovs-vsctl to provide
188 # output (e.g. because it includes "create" commands) then 'vsctl-output'
189 # specifies the expected output after filtering through uuidfilt.
191 # If a test needs to use "system" devices (as dummies), then specify
192 # =override (literally) as the third argument. Otherwise, system devices
193 # won't work at all (which makes sense because tests should not access a
194 # system's real Ethernet devices).
196 # 'vswitchd-aux-args' provides a way to pass extra command line arguments
198 m4_define([OVS_VSWITCHD_START],
199 [_OVS_VSWITCHD_START([--enable-dummy$3 --disable-system --disable-system-route $4])
200 AT_CHECK([add_of_br 0 $1 m4_if([$2], [], [], [| uuidfilt])], [0], [$2])
203 # check_logs scans through all *.log files (except '*.log' and testsuite.log)
204 # and reports all WARN, ERR, EMER log entries. User can add custom sed filters
206 m4_divert_push([PREPARE_TESTS])
211 '*.log'|testsuite.log) ;; # (
212 *) logs="${logs} ${log}" ;;
216 # We most notably ignore 'Broken pipe' warnings. These often and
217 # intermittently appear in ovsdb-server.log, because *ctl commands
218 # (e.g. ovs-vsctl) exit right after committing a change to the
219 # database. However, in reaction, some daemon may immediately update the
220 # database, and this later update may cause database sending update back to
221 # *ctl command if *ctl has not exited yet. If *ctl command exits before
222 # the database calls send, the send fails with 'Broken pipe' or
223 # 'not connected' depending on system. Also removes all 'connection reset'
224 # warning logs for similar reasons (EPIPE, ENOTCONN or ECONNRESET can be
225 # returned on a send depending on whether the peer had unconsumed data
226 # when it closed the socket).
228 # We also ignore "Dropped # log messages..." messages. Otherwise, even if
229 # we ignore the messages that were rate-limited, we can end up failing just
230 # because of the announcement that rate-limiting happened (and in a racy,
231 # timing-dependent way, too).
236 /timeval.*Unreasonably long [[0-9]]*ms poll interval/d
237 /timeval.*faults: [[0-9]]* minor, [[0-9]]* major/d
238 /timeval.*disk: [[0-9]]* reads, [[0-9]]* writes/d
239 /timeval.*context switches: [[0-9]]* voluntary, [[0-9]]* involuntary/d
240 /ovs_rcu.*blocked [[0-9]]* ms waiting for .* to quiesce/d
241 /Dropped [[0-9]]* log messages/d
247 # add_of_br BRNUM [ARG...]
249 local brnum=$1; shift
251 local dpid=fedcba987654321$brnum
252 local mac=aa:55:aa:55:00:0$brnum
255 -- set bridge $br datapath-type=dummy \
257 other-config:datapath-id=$dpid \
258 other-config:hwaddr=$mac \
259 protocols="[[OpenFlow10,OpenFlow11,OpenFlow12,\
260 OpenFlow13,OpenFlow14,OpenFlow15]]" \
264 # add_of_ports__ PORT_TYPE [--pcap] BRIDGE PNUM...
266 # Creates PORT_TYPE interfaces in BRIDGE named pPNUM, OpenFlow port number
267 # PNUM, and datapath port number PNUM (the latter is a consequence of
268 # the dummy implementation, which tries to assign datapath port
269 # numbers based on port names).
271 # If --pcap is supplied then packets received from the interface will
272 # be written to $port-rx.pcap and those sent to it to $port-tx.pcap.
278 if test "$1" = --pcap; then
284 AS_VAR_APPEND([args], [" -- add-port $br p$pnum -- set Interface p$pnum type=$ptype ofport_request=$pnum"])
286 AS_VAR_APPEND([args], [" -- set Interface p$pnum options:rxq_pcap=p$pnum-rx.pcap options:tx_pcap=p$pnum-tx.pcap"])
293 # add_of_ports [--pcap] BRIDGE PNUM...
296 add_of_ports__ dummy $@
299 # add_pmd_of_ports [--pcap] BRIDGE PNUM...
301 add_pmd_of_ports () {
302 add_of_ports__ dummy-pmd $@
305 m4_divert_pop([PREPARE_TESTS])
307 # OVS_VSWITCHD_STOP([ALLOWLIST])
309 # Gracefully stops ovs-vswitchd and ovsdb-server, checking their log files
310 # for messages with severity WARN or higher and signaling an error if any
311 # is present. The optional ALLOWLIST may contain shell-quoted "sed"
312 # commands to delete any warnings that are actually expected, e.g.:
314 # OVS_VSWITCHD_STOP(["/expected error/d"])
315 m4_define([OVS_VSWITCHD_STOP],
316 [AT_CHECK([check_logs $1])
317 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
318 OVS_APP_EXIT_AND_WAIT([ovsdb-server])])
320 m4_define([OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP],
321 [AT_CHECK([ovs-appctl dpif/set-dp-features br0 tnl_push_pop false], [0])
324 # WAIT_FOR_DUMMY_PORTS(NETDEV_DUMMY_PORT[, NETDEV_DUMMY_PORT...])
326 # Wait until the netdev dummy ports are connected to each other
327 m4_define([WAIT_FOR_DUMMY_PORTS], \
328 [m4_foreach([dummy_port], [$@],
330 OVS_WAIT_WHILE([ovs-appctl netdev-dummy/conn-state dummy_port \
331 | grep 'unknown\|disconnected'])])])