1 # DEL_NAMESPACES(ns [, ns ... ])
3 # Delete namespaces from the running OS
4 m4_define([DEL_NAMESPACES],
5 [m4_foreach([ns], [$@],
11 # ADD_NAMESPACES(ns [, ns ... ])
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], [$@],
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
25 # NS_EXEC([namespace], [command])
27 # Execute 'command' in 'namespace'
29 [ip netns exec $1 sh << NS_EXEC_HEREDOC
33 # NS_CHECK_EXEC([namespace], [command], other_params...)
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($@))) ]
41 # ADD_BR([name], [vsctl-args])
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])
47 # ADD_INT([port], [namespace], [ovs-br], [ip_addr])
49 # Add an internal port to 'ovs-br', then shift it into 'namespace' and
50 # configure it with 'ip_addr' (specified in CIDR notation).
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])
59 # ADD_VETH([port], [namespace], [ovs-br], [ip_addr] [mac_addr], [gateway],
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'.
65 # The 'port' in 'namespace' will be brought up with static IP address
66 # with 'ip_addr' in CIDR notation.
68 # Optionally, one can specify the 'mac_addr' for 'port' and the default
71 # The existing 'port' or 'ovs-port' will be removed before new ones are added.
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])
83 NS_CHECK_EXEC([$2], [ip link set dev $1 address $5])
86 NS_CHECK_EXEC([$2], [ip route add default via $6])
88 on_exit 'ip link del ovs-$1'
92 # ADD_VETH_BOND([ports], [namespace], [ovs-br], [bond], [mode], [ip_addr])
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'.
98 # The 'bond' in 'namespace' will be brought up with static IP address
99 # with 'ip_addr' in CIDR notation.
101 m4_define([ADD_VETH_BOND],
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'
112 NS_CHECK_EXEC([$2], [ip link add name $4 type bond])
113 case "$(echo $5 | sed 's/.*lacp=//' | sed 's/ .*//')" in
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"])
120 NS_CHECK_EXEC([$2], [ip link set dev $port master $4])
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'
129 # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr])
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])
140 # ADD_SVLAN([port], [namespace], [vlan-id], [ip-addr])
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])
152 # ADD_CVLAN([port], [namespace], [vlan-id], [ip-addr])
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.
157 m4_define([ADD_CVLAN],
158 [ ADD_VLAN([$1], [$2], [$3], [$4])
159 NS_CHECK_EXEC([$2], [ip link set $1.$3 mtu 1492])
163 # ADD_OVS_TUNNEL([type], [bridge], [port], [remote-addr], [overlay-addr],
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.
170 # 'port will be configured with the address 'overlay-addr'.
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'
182 # ADD_OVS_TUNNEL6([type], [bridge], [port], [remote-addr], [overlay-addr])
184 # Same as ADD_OVS_TUNNEL, but drops MTU enough for the IPv6 underlay.
186 m4_define([ADD_OVS_TUNNEL6],
187 [ADD_OVS_TUNNEL([$1], [$2], [$3], [$4], [$5])
188 AT_CHECK([ip link set dev $2 mtu 1430])
192 # ADD_NATIVE_TUNNEL([type], [port], [namespace], [remote-addr], [overlay-addr],
193 # [type-args], [link-args])
195 # Add a native tunnel device within 'namespace', with name 'port' and type
196 # 'type'. The tunnel device will be configured as point-to-point with the
197 # 'remote-addr' as the underlay address of the remote tunnel endpoint (as
198 # viewed from the perspective of that namespace).
200 # 'port' will be configured with the address 'overlay-addr'. 'type-args' is
201 # made available so that additional arguments can be passed to "ip link add"
202 # for configuring specific link type's arguments, for instance to configure
203 # the vxlan destination port. 'link-args' is made for arguments passed to
204 # "ip link set", for instance to configure MAC address.
206 m4_define([ADD_NATIVE_TUNNEL],
207 [NS_CHECK_EXEC([$3], [ip link add dev $2 type $1 remote $4 $6])
208 NS_CHECK_EXEC([$3], [ip addr add dev $2 $5])
209 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1450 $7 up])
213 # ADD_NATIVE_TUNNEL6([type], [port], [namespace], [remote-addr], [overlay-addr],
214 # [type-args], [link-args])
216 # Same as ADD_NATIVE_TUNNEL, but drops MTU enough for the IPv6 underlay.
218 m4_define([ADD_NATIVE_TUNNEL6],
219 [ADD_NATIVE_TUNNEL([$1], [$2], [$3], [$4], [$5], [$6], [$7])
220 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1430])
226 # Strip variant pieces from ping output so the output can be reliably compared.
228 m4_define([FORMAT_PING], [grep "transmitted" | sed 's/time.*ms$/time 0ms/'])
230 # STRIP_MONITOR_CSUM([])
232 # Strip the csum value from ovs-ofctl monitor.
234 m4_define([STRIP_MONITOR_CSUM], [grep "csum:" | sed 's/csum:.*/csum: <skip>/'])
236 # FORMAT_CT([ip-addr])
238 # Strip content from the piped input which would differ from test to test
239 # and limit the output to the rows containing 'ip-addr'.
241 m4_define([FORMAT_CT],
242 [[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 # NETNS_DAEMONIZE([namespace], [command], [pidfile])
246 # Run 'command' as a background process within 'namespace' and record its pid
247 # to 'pidfile' to allow cleanup on exit.
249 m4_define([NETNS_DAEMONIZE],
250 [ip netns exec $1 $2 & echo $! > $3
251 echo "kill \`cat $3\`" >> cleanup
255 # OVS_CHECK_FIREWALL()
257 # Check if firewalld is active, skip the test if it is on.
258 # The following command currently only supports RHEL and CentOS.
259 m4_define([OVS_CHECK_FIREWALL],
260 [AT_SKIP_IF([systemctl status firewalld 2>&1 | grep running > /dev/null])])
262 # OVS_START_L7([namespace], [protocol])
264 # Start a server serving 'protocol' within 'namespace'. The server will exit
265 # when the test finishes.
267 m4_define([OVS_START_L7],
268 [PIDFILE=$(mktemp $2XXX.pid)
269 NETNS_DAEMONIZE([$1], [[$PYTHON $srcdir/test-l7.py $2]], [$PIDFILE])
271 dnl netstat doesn't print http over IPv6 as "http6"; drop the number.
272 PROTO=$(echo $2 | sed -e 's/\([[a-zA-Z]]*\).*/\1/')
273 OVS_WAIT_UNTIL([NS_EXEC([$1], [netstat -l | grep $PROTO])])
279 # Do basic check for vxlan functionality, skip the test if it's not there.
280 m4_define([OVS_CHECK_VXLAN],
281 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep dstport >/dev/null])
282 OVS_CHECK_FIREWALL()])
284 # OVS_CHECK_VXLAN_UDP6ZEROCSUM()
285 m4_define([OVS_CHECK_VXLAN_UDP6ZEROCSUM],
286 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep udp6zerocsum >/dev/null])
287 OVS_CHECK_FIREWALL()])
289 # OVS_CHECK_VXLAN_GPE()
290 m4_define([OVS_CHECK_VXLAN_GPE],
292 AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep gpe >/dev/null])])
295 m4_define([OVS_CHECK_GRE],
296 [AT_SKIP_IF([! ip link add foo type gretap help 2>&1 | grep gretap >/dev/null])
297 OVS_CHECK_FIREWALL()])
300 m4_define([OVS_CHECK_GRE_L3],
301 [AT_SKIP_IF([! ip link add foo type gre help 2>&1 | grep "gre " >/dev/null])
302 OVS_CHECK_FIREWALL()])
305 m4_define([OVS_CHECK_GENEVE],
306 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep geneve >/dev/null])
307 OVS_CHECK_FIREWALL()])
309 # OVS_CHECK_GENEVE_UDP6ZEROCSUM()
310 m4_define([OVS_CHECK_GENEVE_UDP6ZEROCSUM],
311 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep udp6zerocsum >/dev/null])
312 OVS_CHECK_FIREWALL()])
315 m4_define([OVS_CHECK_8021AD],
316 [AT_SKIP_IF([! grep -q "VLAN header stack length probed as" ovs-vswitchd.log])
317 AT_SKIP_IF([[test `sed -n 's/.*VLAN header stack length probed as \([0-9]\+\).*/\1/p' ovs-vswitchd.log` -lt 2]])])
319 # OVS_CHECK_IPROUTE_ENCAP()
320 m4_define([OVS_CHECK_IPROUTE_ENCAP],
321 [AT_SKIP_IF([! ip route help 2>&1 |grep encap >/dev/null])])