]> git.proxmox.com Git - ovs.git/blob - tests/system-common-macros.at
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[ovs.git] / tests / system-common-macros.at
1 # DEL_NAMESPACES(ns [, ns ... ])
2 #
3 # Delete namespaces from the running OS
4 m4_define([DEL_NAMESPACES],
5 [m4_foreach([ns], [$@],
6 [ip netns del ns
7 ])
8 ]
9 )
10
11 # ADD_NAMESPACES(ns [, ns ... ])
12 #
13 # Add new namespaces, if ns exists, the old one
14 # will be remove before new ones are installed.
15 m4_define([ADD_NAMESPACES],
16 [m4_foreach([ns], [$@],
17 [DEL_NAMESPACES(ns)
18 AT_CHECK([ip netns add ns || return 77])
19 on_exit 'DEL_NAMESPACES(ns)'
20 ip netns exec ns sysctl -w net.netfilter.nf_conntrack_helper=0
21 ])
22 ]
23 )
24
25 # NS_EXEC([namespace], [command])
26 #
27 # Execute 'command' in 'namespace'
28 m4_define([NS_EXEC],
29 [ip netns exec $1 sh << NS_EXEC_HEREDOC
30 $2
31 NS_EXEC_HEREDOC])
32
33 # NS_CHECK_EXEC([namespace], [command], other_params...)
34 #
35 # Wrapper for AT_CHECK that executes 'command' inside 'namespace'.
36 # 'other_params' as passed as they are to AT_CHECK.
37 m4_define([NS_CHECK_EXEC],
38 [ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ]
39 )
40
41 # ADD_BR([name], [vsctl-args])
42 #
43 # Expands into the proper ovs-vsctl commands to create a bridge with the
44 # appropriate type, and allows additional arguments to be passed.
45 m4_define([ADD_BR], [ovs-vsctl _ADD_BR([$1]) -- $2])
46
47 # ADD_INT([port], [namespace], [ovs-br], [ip_addr])
48 #
49 # Add an internal port to 'ovs-br', then shift it into 'namespace' and
50 # configure it with 'ip_addr' (specified in CIDR notation).
51 m4_define([ADD_INT],
52 [ AT_CHECK([ovs-vsctl add-port $3 $1 -- set int $1 type=internal])
53 AT_CHECK([ip link set $1 netns $2])
54 NS_CHECK_EXEC([$2], [ip addr add $4 dev $1])
55 NS_CHECK_EXEC([$2], [ip link set dev $1 up])
56 ]
57 )
58
59 # ADD_VETH([port], [namespace], [ovs-br], [ip_addr] [mac_addr], [gateway],
60 # [ip_addr_flags])
61 #
62 # Add a pair of veth ports. 'port' will be added to name space 'namespace',
63 # and "ovs-'port'" will be added to ovs bridge 'ovs-br'.
64 #
65 # The 'port' in 'namespace' will be brought up with static IP address
66 # with 'ip_addr' in CIDR notation.
67 #
68 # Optionally, one can specify the 'mac_addr' for 'port' and the default
69 # 'gateway'.
70 #
71 # The existing 'port' or 'ovs-port' will be removed before new ones are added.
72 #
73 m4_define([ADD_VETH],
74 [ AT_CHECK([ip link add $1 type veth peer name ovs-$1 || return 77])
75 CONFIGURE_VETH_OFFLOADS([$1])
76 AT_CHECK([ip link set $1 netns $2])
77 AT_CHECK([ip link set dev ovs-$1 up])
78 AT_CHECK([ovs-vsctl add-port $3 ovs-$1 -- \
79 set interface ovs-$1 external-ids:iface-id="$1"])
80 NS_CHECK_EXEC([$2], [ip addr add $4 dev $1 $7])
81 NS_CHECK_EXEC([$2], [ip link set dev $1 up])
82 if test -n "$5"; then
83 NS_CHECK_EXEC([$2], [ip link set dev $1 address $5])
84 fi
85 if test -n "$6"; then
86 NS_CHECK_EXEC([$2], [ip route add default via $6])
87 fi
88 on_exit 'ip link del ovs-$1'
89 ]
90 )
91
92 # ADD_VETH_BOND([ports], [namespace], [ovs-br], [bond], [mode], [ip_addr])
93 #
94 # Add a set of veth port pairs. Ports named in the list 'ports' will be added
95 # to 'namespace', and the corresponding port names, prefixed by 'ovs-' will
96 # be included in an OVS bond 'bond' which is added to bridge 'ovs-br'.
97 #
98 # The 'bond' in 'namespace' will be brought up with static IP address
99 # with 'ip_addr' in CIDR notation.
100 #
101 m4_define([ADD_VETH_BOND],
102 [
103 BONDPORTS=""
104 for port in $1; do
105 AT_CHECK([ip link add $port type veth peer name ovs-$port])
106 CONFIGURE_VETH_OFFLOADS([$port])
107 AT_CHECK([ip link set $port netns $2])
108 AT_CHECK([ip link set dev ovs-$port up])
109 BONDPORTS="$BONDPORTS ovs-$port"
110 on_exit 'ip link del ovs-$port'
111 done
112 NS_CHECK_EXEC([$2], [ip link add name $4 type bond])
113 case "$(echo $5 | sed 's/.*lacp=//' | sed 's/ .*//')" in
114 active|passive)
115 NS_CHECK_EXEC([$2], [sh -c "echo 802.3ad > /sys/class/net/$4/bonding/mode"])
116 NS_CHECK_EXEC([$2], [sh -c "echo 100 > /sys/class/net/$4/bonding/miimon"])
117 ;;
118 esac
119 for port in $1; do
120 NS_CHECK_EXEC([$2], [ip link set dev $port master $4])
121 done
122 NS_CHECK_EXEC([$2], [ip addr add $6 dev $4])
123 NS_CHECK_EXEC([$2], [ip link set dev $4 up])
124 AT_CHECK([ovs-vsctl add-bond $3 ovs-$4 $BONDPORTS $5])
125 on_exit 'ip link del ovs-$4'
126 ]
127 )
128
129 # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr])
130 #
131 # Add a VLAN device named 'port' within 'namespace'. It will be configured
132 # with the ID 'vlan-id' and the address 'ip-addr'.
133 m4_define([ADD_VLAN],
134 [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan proto 802.1q id $3])
135 NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
136 NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
137 ]
138 )
139
140 # ADD_SVLAN([port], [namespace], [vlan-id], [ip-addr])
141 #
142 # Add a SVLAN device named 'port' within 'namespace'. It will be configured
143 # with the ID 'vlan-id' and the address 'ip-addr'.
144 m4_define([ADD_SVLAN],
145 [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan proto 802.1ad id $3])
146 NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
147 NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
148 NS_CHECK_EXEC([$2], [ip link set $1.$3 mtu 1496])
149 ]
150 )
151
152 # ADD_CVLAN([port], [namespace], [vlan-id], [ip-addr])
153 #
154 # Similar to ADD_VLAN(), but sets MTU. Lower MTU here instead of increase MTU
155 # on bridge/SVLAN because older kernels didn't work.
156 #
157 m4_define([ADD_CVLAN],
158 [ ADD_VLAN([$1], [$2], [$3], [$4])
159 NS_CHECK_EXEC([$2], [ip link set $1.$3 mtu 1492])
160 ]
161 )
162
163 # ADD_OVS_TUNNEL([type], [bridge], [port], [remote-addr], [overlay-addr],
164 # [tunnel-args])
165 #
166 # Add an ovs-based tunnel device in the root namespace, with name 'port' and
167 # type 'type'. The tunnel device will be configured as point-to-point with the
168 # 'remote-addr' as the underlay address of the remote tunnel endpoint.
169 #
170 # 'port will be configured with the address 'overlay-addr'.
171 #
172 m4_define([ADD_OVS_TUNNEL],
173 [AT_CHECK([ovs-vsctl add-port $2 $3 -- \
174 set int $3 type=$1 options:remote_ip=$4 $6])
175 AT_CHECK([ip addr add dev $2 $5])
176 AT_CHECK([ip link set dev $2 up])
177 AT_CHECK([ip link set dev $2 mtu 1450])
178 on_exit 'ip addr del dev $2 $5'
179 ]
180 )
181
182 # ADD_OVS_TUNNEL6([type], [bridge], [port], [remote-addr], [overlay-addr],
183 # [tunnel-args])
184 #
185 # Same as ADD_OVS_TUNNEL, but drops MTU enough for the IPv6 underlay.
186 #
187 m4_define([ADD_OVS_TUNNEL6],
188 [ADD_OVS_TUNNEL([$1], [$2], [$3], [$4], [$5], [$6])
189 AT_CHECK([ip link set dev $2 mtu 1430])
190 ]
191 )
192
193 # ADD_NATIVE_TUNNEL([type], [port], [namespace], [remote-addr], [overlay-addr],
194 # [type-args], [link-args])
195 #
196 # Add a native tunnel device within 'namespace', with name 'port' and type
197 # 'type'. The tunnel device will be configured as point-to-point with the
198 # 'remote-addr' as the underlay address of the remote tunnel endpoint (as
199 # viewed from the perspective of that namespace).
200 #
201 # 'port' will be configured with the address 'overlay-addr'. 'type-args' is
202 # made available so that additional arguments can be passed to "ip link add"
203 # for configuring specific link type's arguments, for instance to configure
204 # the vxlan destination port. 'link-args' is made for arguments passed to
205 # "ip link set", for instance to configure MAC address.
206 #
207 m4_define([ADD_NATIVE_TUNNEL],
208 [NS_CHECK_EXEC([$3], [ip link add dev $2 type $1 remote $4 $6])
209 NS_CHECK_EXEC([$3], [ip addr add dev $2 $5])
210 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1450 $7 up])
211 ]
212 )
213
214 # ADD_NATIVE_TUNNEL6([type], [port], [namespace], [remote-addr], [overlay-addr],
215 # [type-args], [link-args])
216 #
217 # Same as ADD_NATIVE_TUNNEL, but drops MTU enough for the IPv6 underlay.
218 #
219 m4_define([ADD_NATIVE_TUNNEL6],
220 [ADD_NATIVE_TUNNEL([$1], [$2], [$3], [$4], [$5], [$6], [$7])
221 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1430])
222 ]
223 )
224
225 # FORMAT_PING([])
226 #
227 # Strip variant pieces from ping output so the output can be reliably compared.
228 #
229 m4_define([FORMAT_PING], [grep "transmitted" | sed 's/time.*ms$/time 0ms/'])
230
231 # STRIP_MONITOR_CSUM([])
232 #
233 # Strip the csum value from ovs-ofctl monitor.
234 #
235 m4_define([STRIP_MONITOR_CSUM], [grep "csum:" | sed 's/csum:.*/csum: <skip>/'])
236
237 # FORMAT_CT([ip-addr])
238 #
239 # Strip content from the piped input which would differ from test to test
240 # and limit the output to the rows containing 'ip-addr'.
241 #
242 m4_define([FORMAT_CT],
243 [[grep "dst=$1" | sed -e 's/port=[0-9]*/port=<cleared>/g' -e 's/id=[0-9]*/id=<cleared>/g' -e 's/state=[0-9_A-Z]*/state=<cleared>/g' | sort | uniq]])
244
245 # NETNS_DAEMONIZE([namespace], [command], [pidfile])
246 #
247 # Run 'command' as a background process within 'namespace' and record its pid
248 # to 'pidfile' to allow cleanup on exit.
249 #
250 m4_define([NETNS_DAEMONIZE],
251 [ip netns exec $1 $2 & echo $! > $3
252 echo "kill \`cat $3\`" >> cleanup
253 ]
254 )
255
256 # OVS_CHECK_FIREWALL()
257 #
258 # Check if firewalld is active, skip the test if it is on.
259 # The following command currently only supports RHEL and CentOS.
260 m4_define([OVS_CHECK_FIREWALL],
261 [AT_SKIP_IF([systemctl status firewalld 2>&1 | grep running > /dev/null])])
262
263 # OVS_START_L7([namespace], [protocol])
264 #
265 # Start a server serving 'protocol' within 'namespace'. The server will exit
266 # when the test finishes.
267 #
268 m4_define([OVS_START_L7],
269 [PIDFILE=$(mktemp $2XXX.pid)
270 NETNS_DAEMONIZE([$1], [[$PYTHON3 $srcdir/test-l7.py $2]], [$PIDFILE])
271
272 dnl netstat doesn't print http over IPv6 as "http6"; drop the number.
273 PROTO=$(echo $2 | sed -e 's/\([[a-zA-Z]]*\).*/\1/')
274 OVS_WAIT_UNTIL([NS_EXEC([$1], [netstat -l | grep $PROTO])])
275 ]
276 )
277
278 # OFPROTO_CLEAR_DURATION_IDLE([])
279 #
280 # Clear the duration from the piped input which would differ from test to test
281 #
282 m4_define([OFPROTO_CLEAR_DURATION_IDLE], [[sed -e 's/duration=.*s,/duration=<cleared>,/g' -e 's/idle_age=[0-9]*,/idle_age=<cleared>,/g']])
283
284 # OVS_CHECK_VXLAN()
285 #
286 # Do basic check for vxlan functionality, skip the test if it's not there.
287 m4_define([OVS_CHECK_VXLAN],
288 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep dstport >/dev/null])
289 OVS_CHECK_FIREWALL()])
290
291 # OVS_CHECK_VXLAN_UDP6ZEROCSUM()
292 m4_define([OVS_CHECK_VXLAN_UDP6ZEROCSUM],
293 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep udp6zerocsum >/dev/null])
294 OVS_CHECK_FIREWALL()])
295
296 # OVS_CHECK_VXLAN_GPE()
297 m4_define([OVS_CHECK_VXLAN_GPE],
298 [OVS_CHECK_VXLAN()
299 AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep gpe >/dev/null])])
300
301 # OVS_CHECK_GRE()
302 m4_define([OVS_CHECK_GRE],
303 [AT_SKIP_IF([! ip link add foo type gretap help 2>&1 | grep gretap >/dev/null])
304 OVS_CHECK_FIREWALL()])
305
306 # OVS_CHECK_ERSPAN()
307 m4_define([OVS_CHECK_ERSPAN],
308 [AT_SKIP_IF([! ip link add foo type erspan help 2>&1 | grep erspan >/dev/null])
309 OVS_CHECK_FIREWALL()])
310
311 # OVS_CHECK_GRE_L3()
312 m4_define([OVS_CHECK_GRE_L3],
313 [AT_SKIP_IF([! ip link add foo type gre help 2>&1 | grep "gre " >/dev/null])
314 OVS_CHECK_FIREWALL()])
315
316 # OVS_CHECK_GENEVE()
317 m4_define([OVS_CHECK_GENEVE],
318 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep geneve >/dev/null])
319 OVS_CHECK_FIREWALL()])
320
321 # OVS_CHECK_GENEVE_UDP6ZEROCSUM()
322 m4_define([OVS_CHECK_GENEVE_UDP6ZEROCSUM],
323 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep udp6zerocsum >/dev/null])
324 OVS_CHECK_FIREWALL()])
325
326 # OVS_CHECK_8021AD()
327 m4_define([OVS_CHECK_8021AD],
328 [AT_SKIP_IF([! grep -q "VLAN header stack length probed as" ovs-vswitchd.log])
329 AT_SKIP_IF([[test `sed -n 's/.*VLAN header stack length probed as \([0-9]\+\).*/\1/p' ovs-vswitchd.log` -lt 2]])])
330
331 # OVS_CHECK_IPROUTE_ENCAP()
332 m4_define([OVS_CHECK_IPROUTE_ENCAP],
333 [AT_SKIP_IF([! ip route help 2>&1 |grep encap >/dev/null])])
334
335 # OVS_CHECK_CT_CLEAR()
336 m4_define([OVS_CHECK_CT_CLEAR],
337 [AT_SKIP_IF([! grep -q "Datapath supports ct_clear action" ovs-vswitchd.log])])