]> git.proxmox.com Git - mirror_ovs.git/blob - tests/ofproto-macros.at
ofproto-dpif: Expose datapath capability to ovsdb.
[mirror_ovs.git] / tests / ofproto-macros.at
1 m4_divert_push([PREPARE_TESTS])
2 [
3 # Strips out uninteresting parts of ovs-ofctl output, as well as parts
4 # that vary from one run to another.
5 ofctl_strip () {
6 sed '
7 s/ (xid=0x[0-9a-fA-F]*)//
8 s/ duration=[0-9.]*s,//
9 s/ cookie=0x0,//
10 s/ table=0,//
11 s/ n_packets=0,//
12 s/ n_bytes=0,//
13 s/ idle_age=[0-9]*,//
14 s/ hard_age=[0-9]*,//
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/
19 '
20 }
21
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 '
25 BEGIN { prt=0 }
26 /\|vconn\|DBG\|/ { sub(/[ \t]*$/, ""); print $3 "|" $4 "|" $5; prt=1; next }
27 $4 != "" { prt=0; next }
28 prt==1 { sub(/[ \t]*$/, ""); print $0 }
29 '
30 }
31
32 vconn_sub() {
33 sed '
34 s/tcp:127.0.0.1:[0-9][0-9]*:/unix:/
35 s/unix#[0-9]*:/unix:/
36 '
37 }
38 ]
39
40 # PARSE_LISTENING_PORT LOGFILE VARIABLE
41 #
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.
47 #
48 # Here's an example of how to use this with ovsdb-server:
49 #
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"])])
55
56 start_daemon () {
57 "$@" -vconsole:off --detach --no-chdir --pidfile --log-file
58 pidfile="$OVS_RUNDIR"/$1.pid
59 on_exit "test -e \"$pidfile\" && kill \`cat \"$pidfile\"\`"
60 }
61
62 # sim_add SANDBOX
63 #
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.
69 #
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.:
72 #
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.
76 #
77 # or:
78 #
79 # sim_add hv0
80 # as hv0 ovs-vsctl add-br br0
81 sims=
82 sim_add () {
83 echo "adding simulator '$1'"
84
85 sims="$sims $1"
86
87 # Create sandbox.
88 local d="$ovs_base"/$1
89 mkdir "$d" || return 1
90 ovs_setenv $1
91
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
96
97 # Initialize database.
98 as $1 ovs-vsctl --no-wait -- init || return 1
99
100 # Start ovs-vswitchd
101 as $1 start_daemon ovs-vswitchd --enable-dummy=system -vvconn -vofproto_dpif -vunixctl
102 }
103
104 # "as $1" sets the OVS_*DIR environment variables to point to $ovs_base/$1.
105 #
106 # "as $1 COMMAND..." sets those variables in a subshell and invokes COMMAND
107 # there.
108 as() {
109 if test "X$2" != X; then
110 (ovs_setenv $1; shift; "$@")
111 else
112 ovs_setenv $1
113 fi
114 }
115
116 # Strips 'xid=0x1234' from ovs-ofctl output.
117 strip_xids () {
118 sed 's/ (xid=0x[[0-9a-fA-F]]*)//'
119 }
120
121 # Changes all 'used:...' to say 'used:0.0', to make output easier to compare.
122 strip_used () {
123 sed 's/used:[[0-9]]\.[[0-9]]*/used:0.0/'
124 }
125
126 # Removes all 'duration=...' to make output easier to compare.
127 strip_duration () {
128 sed 's/duration=[[0-9]]*\.[[0-9]]*s,//'
129 }
130
131 # Strips 'ufid:...' from output, to make it easier to compare.
132 # (ufids are random.)
133 strip_ufid () {
134 sed 's/ufid:[[-0-9a-f]]* //'
135 }
136 m4_divert_pop([PREPARE_TESTS])
137
138 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
139
140 # _OVS_VSWITCHD_START([vswitchd-aux-args])
141 #
142 # Creates an empty database and starts ovsdb-server.
143 # Starts ovs-vswitchd, with additional arguments 'vswitchd-aux-args'.
144 #
145 m4_define([_OVS_VSWITCHD_START],
146 [dnl Create database.
147 touch .conf.db.~lock~
148 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
149
150 dnl Start ovsdb-server.
151 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
152 on_exit "kill `cat ovsdb-server.pid`"
153 AT_CHECK([[sed < stderr '
154 /vlog|INFO|opened log file/d
155 /ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
156 AT_CAPTURE_FILE([ovsdb-server.log])
157
158 dnl Initialize database.
159 AT_CHECK([ovs-vsctl --no-wait init $2])
160
161 dnl Start ovs-vswitchd.
162 AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
163 AT_CAPTURE_FILE([ovs-vswitchd.log])
164 on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`"
165 AT_CHECK([[sed < stderr '
166 /ovs_numa|INFO|Discovered /d
167 /vlog|INFO|opened log file/d
168 /vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
169 /reconnect|INFO|/d
170 /dpif_netlink|INFO|Generic Netlink family .ovs_datapath. does not exist/d
171 /ofproto|INFO|using datapath ID/d
172 /netdev_linux|INFO|.*device has unknown hardware address family/d
173 /ofproto|INFO|datapath ID changed to fedcba9876543210/d
174 /dpdk|INFO|DPDK Disabled - Use other_config:dpdk-init to enable/d
175 /netlink_socket|INFO|netlink: could not enable listening to all nsid/d
176 /probe tc:/d
177 /tc: Using policy/d']])
178 ])
179
180 # OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override],
181 # [vswitchd-aux-args])
182 #
183 # Creates a database and starts ovsdb-server, starts ovs-vswitchd
184 # connected to that database, calls ovs-vsctl to create a bridge named
185 # br0 with predictable settings, passing 'vsctl-args' as additional
186 # commands to ovs-vsctl. If 'vsctl-args' causes ovs-vsctl to provide
187 # output (e.g. because it includes "create" commands) then 'vsctl-output'
188 # specifies the expected output after filtering through uuidfilt.
189 #
190 # If a test needs to use "system" devices (as dummies), then specify
191 # =override (literally) as the third argument. Otherwise, system devices
192 # won't work at all (which makes sense because tests should not access a
193 # system's real Ethernet devices).
194 #
195 # 'vswitchd-aux-args' provides a way to pass extra command line arguments
196 # to ovs-vswitchd
197 m4_define([OVS_VSWITCHD_START],
198 [_OVS_VSWITCHD_START([--enable-dummy$3 --disable-system --disable-system-route $4])
199 AT_CHECK([add_of_br 0 $1 m4_if([$2], [], [], [| uuidfilt])], [0], [$2])
200 ])
201
202 # check_logs scans through all *.log files (except '*.log' and testsuite.log)
203 # and reports all WARN, ERR, EMER log entries. User can add custom sed filters
204 # in $1.
205 m4_divert_push([PREPARE_TESTS])
206 check_logs () {
207 local logs
208 for log in *.log; do
209 case ${log} in # (
210 '*.log'|testsuite.log) ;; # (
211 *) logs="${logs} ${log}" ;;
212 esac
213 done
214
215 # We most notably ignore 'Broken pipe' warnings. These often and
216 # intermittently appear in ovsdb-server.log, because *ctl commands
217 # (e.g. ovs-vsctl) exit right after committing a change to the
218 # database. However, in reaction, some daemon may immediately update the
219 # database, and this later update may cause database sending update back to
220 # *ctl command if *ctl has not exited yet. If *ctl command exits before
221 # the database calls send, the send fails with 'Broken pipe' or
222 # 'not connected' depending on system. Also removes all 'connection reset'
223 # warning logs for similar reasons (EPIPE, ENOTCONN or ECONNRESET can be
224 # returned on a send depending on whether the peer had unconsumed data
225 # when it closed the socket).
226 #
227 # We also ignore "Dropped # log messages..." messages. Otherwise, even if
228 # we ignore the messages that were rate-limited, we can end up failing just
229 # because of the announcement that rate-limiting happened (and in a racy,
230 # timing-dependent way, too).
231 sed -n "$1
232 /reset by peer/d
233 /Broken pipe/d
234 /is not connected/d
235 /timeval.*Unreasonably long [[0-9]]*ms poll interval/d
236 /timeval.*faults: [[0-9]]* minor, [[0-9]]* major/d
237 /timeval.*disk: [[0-9]]* reads, [[0-9]]* writes/d
238 /timeval.*context switches: [[0-9]]* voluntary, [[0-9]]* involuntary/d
239 /ovs_rcu.*blocked [[0-9]]* ms waiting for .* to quiesce/d
240 /Dropped [[0-9]]* log messages/d
241 /|WARN|/p
242 /|ERR|/p
243 /|EMER|/p" ${logs}
244 }
245
246 # add_of_br BRNUM [ARG...]
247 add_of_br () {
248 local brnum=$1; shift
249 local br=br$brnum
250 local dpid=fedcba987654321$brnum
251 local mac=aa:55:aa:55:00:0$brnum
252 ovs-vsctl \
253 -- add-br $br \
254 -- set bridge $br datapath-type=dummy \
255 fail-mode=secure \
256 other-config:datapath-id=$dpid \
257 other-config:hwaddr=$mac \
258 protocols="[[OpenFlow10,OpenFlow11,OpenFlow12,\
259 OpenFlow13,OpenFlow14,OpenFlow15]]" \
260 -- "$@"
261 }
262
263 # add_of_ports__ PORT_TYPE [--pcap] BRIDGE PNUM...
264 #
265 # Creates PORT_TYPE interfaces in BRIDGE named pPNUM, OpenFlow port number
266 # PNUM, and datapath port number PNUM (the latter is a consequence of
267 # the dummy implementation, which tries to assign datapath port
268 # numbers based on port names).
269 #
270 # If --pcap is supplied then packets received from the interface will
271 # be written to $port-rx.pcap and those sent to it to $port-tx.pcap.
272 add_of_ports__ () {
273 local args
274 local pcap=false
275 local ptype=$1
276 shift
277 if test "$1" = --pcap; then
278 pcap=:
279 shift
280 fi
281 local br=$1; shift
282 for pnum; do
283 AS_VAR_APPEND([args], [" -- add-port $br p$pnum -- set Interface p$pnum type=$ptype ofport_request=$pnum"])
284 if $pcap; then
285 AS_VAR_APPEND([args], [" -- set Interface p$pnum options:rxq_pcap=p$pnum-rx.pcap options:tx_pcap=p$pnum-tx.pcap"])
286 fi
287 done
288 echo ovs-vsctl $args
289 ovs-vsctl $args
290 }
291
292 # add_of_ports [--pcap] BRIDGE PNUM...
293 #
294 add_of_ports () {
295 add_of_ports__ dummy $@
296 }
297
298 # add_pmd_of_ports [--pcap] BRIDGE PNUM...
299 #
300 add_pmd_of_ports () {
301 add_of_ports__ dummy-pmd $@
302 }
303
304 m4_divert_pop([PREPARE_TESTS])
305
306 # OVS_VSWITCHD_STOP([WHITELIST])
307 #
308 # Gracefully stops ovs-vswitchd and ovsdb-server, checking their log files
309 # for messages with severity WARN or higher and signaling an error if any
310 # is present. The optional WHITELIST may contain shell-quoted "sed"
311 # commands to delete any warnings that are actually expected, e.g.:
312 #
313 # OVS_VSWITCHD_STOP(["/expected error/d"])
314 m4_define([OVS_VSWITCHD_STOP],
315 [AT_CHECK([check_logs $1])
316 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
317 OVS_APP_EXIT_AND_WAIT([ovsdb-server])])
318
319 m4_define([OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP],
320 [AT_CHECK([ovs-appctl dpif/set-dp-features br0 tnl_push_pop false], [0])
321 ])
322
323 # WAIT_FOR_DUMMY_PORTS(NETDEV_DUMMY_PORT[, NETDEV_DUMMY_PORT...])
324 #
325 # Wait until the netdev dummy ports are connected to each other
326 m4_define([WAIT_FOR_DUMMY_PORTS], \
327 [m4_foreach([dummy_port], [$@],
328 [ \
329 OVS_WAIT_WHILE([ovs-appctl netdev-dummy/conn-state dummy_port \
330 | grep 'unknown\|disconnected'])])])
331
332