]> git.proxmox.com Git - ovs.git/blame - 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
CommitLineData
119db2cb
DDP
1# DEL_NAMESPACES(ns [, ns ... ])
2#
3# Delete namespaces from the running OS
4m4_define([DEL_NAMESPACES],
5 [m4_foreach([ns], [$@],
6 [ip netns del ns
7])
8 ]
9)
b1778a55 10
119db2cb
DDP
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.
15m4_define([ADD_NAMESPACES],
16 [m4_foreach([ns], [$@],
17 [DEL_NAMESPACES(ns)
1e50983c
IM
18 AT_CHECK([ip netns add ns || return 77])
19 on_exit 'DEL_NAMESPACES(ns)'
ac0b2510 20 ip netns exec ns sysctl -w net.netfilter.nf_conntrack_helper=0
119db2cb
DDP
21 ])
22 ]
23)
24
b1778a55
DDP
25# NS_EXEC([namespace], [command])
26#
27# Execute 'command' in 'namespace'
28m4_define([NS_EXEC],
5fd56271
JS
29 [ip netns exec $1 sh << NS_EXEC_HEREDOC
30$2
31NS_EXEC_HEREDOC])
b1778a55
DDP
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.
37m4_define([NS_CHECK_EXEC],
38 [ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ]
39)
40
7ca476af
JS
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.
45m4_define([ADD_BR], [ovs-vsctl _ADD_BR([$1]) -- $2])
46
0e27c629
JS
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).
51m4_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
84f72cae
EG
59# ADD_VETH([port], [namespace], [ovs-br], [ip_addr] [mac_addr], [gateway],
60# [ip_addr_flags])
119db2cb
DDP
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#
8ab9b45e
GS
68# Optionally, one can specify the 'mac_addr' for 'port' and the default
69# 'gateway'.
70#
119db2cb
DDP
71# The existing 'port' or 'ovs-port' will be removed before new ones are added.
72#
73m4_define([ADD_VETH],
1e50983c 74 [ AT_CHECK([ip link add $1 type veth peer name ovs-$1 || return 77])
ddcf96d2 75 CONFIGURE_VETH_OFFLOADS([$1])
119db2cb 76 AT_CHECK([ip link set $1 netns $2])
119db2cb 77 AT_CHECK([ip link set dev ovs-$1 up])
37f8ab6f
GS
78 AT_CHECK([ovs-vsctl add-port $3 ovs-$1 -- \
79 set interface ovs-$1 external-ids:iface-id="$1"])
84f72cae 80 NS_CHECK_EXEC([$2], [ip addr add $4 dev $1 $7])
b1778a55 81 NS_CHECK_EXEC([$2], [ip link set dev $1 up])
8ab9b45e
GS
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
53eb8cb8 88 on_exit 'ip link del ovs-$1'
119db2cb
DDP
89 ]
90)
91
ddb5f937
LR
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#
101m4_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
119db2cb
DDP
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'.
133m4_define([ADD_VLAN],
f3c67047 134 [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan proto 802.1q id $3])
b1778a55
DDP
135 NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
136 NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
119db2cb
DDP
137 ]
138)
de22d08f 139
f3c67047
EG
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'.
144m4_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#
157m4_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
e3441997
EG
163# ADD_OVS_TUNNEL([type], [bridge], [port], [remote-addr], [overlay-addr],
164# [tunnel-args])
810e1785
JS
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#
172m4_define([ADD_OVS_TUNNEL],
173 [AT_CHECK([ovs-vsctl add-port $2 $3 -- \
e3441997 174 set int $3 type=$1 options:remote_ip=$4 $6])
810e1785
JS
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])
53eb8cb8 178 on_exit 'ip addr del dev $2 $5'
810e1785
JS
179 ]
180)
181
34d52aa2
WT
182# ADD_OVS_TUNNEL6([type], [bridge], [port], [remote-addr], [overlay-addr],
183# [tunnel-args])
ecd6e789
EG
184#
185# Same as ADD_OVS_TUNNEL, but drops MTU enough for the IPv6 underlay.
186#
187m4_define([ADD_OVS_TUNNEL6],
34d52aa2 188 [ADD_OVS_TUNNEL([$1], [$2], [$3], [$4], [$5], [$6])
ecd6e789
EG
189 AT_CHECK([ip link set dev $2 mtu 1430])
190 ]
191)
192
810e1785 193# ADD_NATIVE_TUNNEL([type], [port], [namespace], [remote-addr], [overlay-addr],
2b9f3924 194# [type-args], [link-args])
810e1785
JS
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#
2b9f3924
WT
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.
810e1785
JS
206#
207m4_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])
2b9f3924 210 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1450 $7 up])
810e1785
JS
211 ]
212)
213
ecd6e789
EG
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#
219m4_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
de22d08f
JS
225# FORMAT_PING([])
226#
227# Strip variant pieces from ping output so the output can be reliably compared.
228#
229m4_define([FORMAT_PING], [grep "transmitted" | sed 's/time.*ms$/time 0ms/'])
07659514 230
88b5874e
WT
231# STRIP_MONITOR_CSUM([])
232#
233# Strip the csum value from ovs-ofctl monitor.
234#
235m4_define([STRIP_MONITOR_CSUM], [grep "csum:" | sed 's/csum:.*/csum: <skip>/'])
236
ec3aa16c
DDP
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'.
07659514 241#
07659514 242m4_define([FORMAT_CT],
420c73b2 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]])
07659514
JS
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#
250m4_define([NETNS_DAEMONIZE],
251 [ip netns exec $1 $2 & echo $! > $3
252 echo "kill \`cat $3\`" >> cleanup
253 ]
254)
dfb21e96 255
ebd39eda
YHW
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.
260m4_define([OVS_CHECK_FIREWALL],
261 [AT_SKIP_IF([systemctl status firewalld 2>&1 | grep running > /dev/null])])
262
7ed40afe
JS
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#
268m4_define([OVS_START_L7],
269 [PIDFILE=$(mktemp $2XXX.pid)
1ca0323e 270 NETNS_DAEMONIZE([$1], [[$PYTHON3 $srcdir/test-l7.py $2]], [$PIDFILE])
f38371be
JS
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])])
7ed40afe
JS
275 ]
276)
277
08905c93
TZ
278# OFPROTO_CLEAR_DURATION_IDLE([])
279#
280# Clear the duration from the piped input which would differ from test to test
281#
282m4_define([OFPROTO_CLEAR_DURATION_IDLE], [[sed -e 's/duration=.*s,/duration=<cleared>,/g' -e 's/idle_age=[0-9]*,/idle_age=<cleared>,/g']])
283
dfb21e96
JS
284# OVS_CHECK_VXLAN()
285#
286# Do basic check for vxlan functionality, skip the test if it's not there.
287m4_define([OVS_CHECK_VXLAN],
ebd39eda
YHW
288 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep dstport >/dev/null])
289 OVS_CHECK_FIREWALL()])
523256cc 290
67e3ddf1
TZ
291# OVS_CHECK_VXLAN_UDP6ZEROCSUM()
292m4_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
88b19194
EG
296# OVS_CHECK_VXLAN_GPE()
297m4_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
523256cc
JS
301# OVS_CHECK_GRE()
302m4_define([OVS_CHECK_GRE],
ad44534e
EG
303 [AT_SKIP_IF([! ip link add foo type gretap help 2>&1 | grep gretap >/dev/null])
304 OVS_CHECK_FIREWALL()])
305
98514eea
WT
306# OVS_CHECK_ERSPAN()
307m4_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
ad44534e
EG
311# OVS_CHECK_GRE_L3()
312m4_define([OVS_CHECK_GRE_L3],
313 [AT_SKIP_IF([! ip link add foo type gre help 2>&1 | grep "gre " >/dev/null])
ebd39eda 314 OVS_CHECK_FIREWALL()])
92b8af2c
JS
315
316# OVS_CHECK_GENEVE()
317m4_define([OVS_CHECK_GENEVE],
ebd39eda
YHW
318 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep geneve >/dev/null])
319 OVS_CHECK_FIREWALL()])
7c121b48 320
67e3ddf1
TZ
321# OVS_CHECK_GENEVE_UDP6ZEROCSUM()
322m4_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
7c121b48
EG
326# OVS_CHECK_8021AD()
327m4_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]])])
65d80912
EG
330
331# OVS_CHECK_IPROUTE_ENCAP()
332m4_define([OVS_CHECK_IPROUTE_ENCAP],
333 [AT_SKIP_IF([! ip route help 2>&1 |grep encap >/dev/null])])
08becaa2
EG
334
335# OVS_CHECK_CT_CLEAR()
336m4_define([OVS_CHECK_CT_CLEAR],
337 [AT_SKIP_IF([! grep -q "Datapath supports ct_clear action" ovs-vswitchd.log])])