]> git.proxmox.com Git - ovs.git/blob - tests/ofproto-macros.at
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[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/mega_ufid:[[-0-9a-f]]* //
135 s/ufid:[[-0-9a-f]]* //'
136 }
137 m4_divert_pop([PREPARE_TESTS])
138
139 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
140
141 # _OVS_VSWITCHD_START([vswitchd-aux-args])
142 #
143 # Creates an empty database and starts ovsdb-server.
144 # Starts ovs-vswitchd, with additional arguments 'vswitchd-aux-args'.
145 #
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])
150
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])
158
159 dnl Initialize database.
160 AT_CHECK([ovs-vsctl --no-wait init $2])
161
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
170 /reconnect|INFO|/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
177 /probe tc:/d
178 /tc: Using policy/d']])
179 ])
180
181 # OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override],
182 # [vswitchd-aux-args])
183 #
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.
190 #
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).
195 #
196 # 'vswitchd-aux-args' provides a way to pass extra command line arguments
197 # to ovs-vswitchd
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])
201 ])
202
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
205 # in $1.
206 m4_divert_push([PREPARE_TESTS])
207 check_logs () {
208 local logs
209 for log in *.log; do
210 case ${log} in # (
211 '*.log'|testsuite.log) ;; # (
212 *) logs="${logs} ${log}" ;;
213 esac
214 done
215
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).
227 #
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).
232 sed -n "$1
233 /reset by peer/d
234 /Broken pipe/d
235 /is not connected/d
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
242 /|WARN|/p
243 /|ERR|/p
244 /|EMER|/p" ${logs}
245 }
246
247 # add_of_br BRNUM [ARG...]
248 add_of_br () {
249 local brnum=$1; shift
250 local br=br$brnum
251 local dpid=fedcba987654321$brnum
252 local mac=aa:55:aa:55:00:0$brnum
253 ovs-vsctl \
254 -- add-br $br \
255 -- set bridge $br datapath-type=dummy \
256 fail-mode=secure \
257 other-config:datapath-id=$dpid \
258 other-config:hwaddr=$mac \
259 protocols="[[OpenFlow10,OpenFlow11,OpenFlow12,\
260 OpenFlow13,OpenFlow14,OpenFlow15]]" \
261 -- "$@"
262 }
263
264 # add_of_ports__ PORT_TYPE [--pcap] BRIDGE PNUM...
265 #
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).
270 #
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.
273 add_of_ports__ () {
274 local args
275 local pcap=false
276 local ptype=$1
277 shift
278 if test "$1" = --pcap; then
279 pcap=:
280 shift
281 fi
282 local br=$1; shift
283 for pnum; do
284 AS_VAR_APPEND([args], [" -- add-port $br p$pnum -- set Interface p$pnum type=$ptype ofport_request=$pnum"])
285 if $pcap; then
286 AS_VAR_APPEND([args], [" -- set Interface p$pnum options:rxq_pcap=p$pnum-rx.pcap options:tx_pcap=p$pnum-tx.pcap"])
287 fi
288 done
289 echo ovs-vsctl $args
290 ovs-vsctl $args
291 }
292
293 # add_of_ports [--pcap] BRIDGE PNUM...
294 #
295 add_of_ports () {
296 add_of_ports__ dummy $@
297 }
298
299 # add_pmd_of_ports [--pcap] BRIDGE PNUM...
300 #
301 add_pmd_of_ports () {
302 add_of_ports__ dummy-pmd $@
303 }
304
305 m4_divert_pop([PREPARE_TESTS])
306
307 # OVS_VSWITCHD_STOP([ALLOWLIST])
308 #
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.:
313 #
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])])
319
320 m4_define([OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP],
321 [AT_CHECK([ovs-appctl dpif/set-dp-features br0 tnl_push_pop false], [0])
322 ])
323
324 # WAIT_FOR_DUMMY_PORTS(NETDEV_DUMMY_PORT[, NETDEV_DUMMY_PORT...])
325 #
326 # Wait until the netdev dummy ports are connected to each other
327 m4_define([WAIT_FOR_DUMMY_PORTS], \
328 [m4_foreach([dummy_port], [$@],
329 [ \
330 OVS_WAIT_WHILE([ovs-appctl netdev-dummy/conn-state dummy_port \
331 | grep 'unknown\|disconnected'])])])
332
333