]> git.proxmox.com Git - mirror_ovs.git/blob - tests/system-common-macros.at
system-traffic: Fix clone test.
[mirror_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 #
61 # Add a pair of veth ports. 'port' will be added to name space 'namespace',
62 # and "ovs-'port'" will be added to ovs bridge 'ovs-br'.
63 #
64 # The 'port' in 'namespace' will be brought up with static IP address
65 # with 'ip_addr' in CIDR notation.
66 #
67 # Optionally, one can specify the 'mac_addr' for 'port' and the default
68 # 'gateway'.
69 #
70 # The existing 'port' or 'ovs-port' will be removed before new ones are added.
71 #
72 m4_define([ADD_VETH],
73 [ AT_CHECK([ip link add $1 type veth peer name ovs-$1 || return 77])
74 CONFIGURE_VETH_OFFLOADS([$1])
75 AT_CHECK([ip link set $1 netns $2])
76 AT_CHECK([ip link set dev ovs-$1 up])
77 AT_CHECK([ovs-vsctl add-port $3 ovs-$1 -- \
78 set interface ovs-$1 external-ids:iface-id="$1"])
79 NS_CHECK_EXEC([$2], [ip addr add $4 dev $1])
80 NS_CHECK_EXEC([$2], [ip link set dev $1 up])
81 if test -n "$5"; then
82 NS_CHECK_EXEC([$2], [ip link set dev $1 address $5])
83 fi
84 if test -n "$6"; then
85 NS_CHECK_EXEC([$2], [ip route add default via $6])
86 fi
87 on_exit 'ip link del ovs-$1'
88 ]
89 )
90
91 # ADD_VETH_BOND([ports], [namespace], [ovs-br], [bond], [mode], [ip_addr])
92 #
93 # Add a set of veth port pairs. Ports named in the list 'ports' will be added
94 # to 'namespace', and the corresponding port names, prefixed by 'ovs-' will
95 # be included in an OVS bond 'bond' which is added to bridge 'ovs-br'.
96 #
97 # The 'bond' in 'namespace' will be brought up with static IP address
98 # with 'ip_addr' in CIDR notation.
99 #
100 m4_define([ADD_VETH_BOND],
101 [
102 BONDPORTS=""
103 for port in $1; do
104 AT_CHECK([ip link add $port type veth peer name ovs-$port])
105 CONFIGURE_VETH_OFFLOADS([$port])
106 AT_CHECK([ip link set $port netns $2])
107 AT_CHECK([ip link set dev ovs-$port up])
108 BONDPORTS="$BONDPORTS ovs-$port"
109 on_exit 'ip link del ovs-$port'
110 done
111 NS_CHECK_EXEC([$2], [ip link add name $4 type bond])
112 case "$(echo $5 | sed 's/.*lacp=//' | sed 's/ .*//')" in
113 active|passive)
114 NS_CHECK_EXEC([$2], [sh -c "echo 802.3ad > /sys/class/net/$4/bonding/mode"])
115 NS_CHECK_EXEC([$2], [sh -c "echo 100 > /sys/class/net/$4/bonding/miimon"])
116 ;;
117 esac
118 for port in $1; do
119 NS_CHECK_EXEC([$2], [ip link set dev $port master $4])
120 done
121 NS_CHECK_EXEC([$2], [ip addr add $6 dev $4])
122 NS_CHECK_EXEC([$2], [ip link set dev $4 up])
123 AT_CHECK([ovs-vsctl add-bond $3 ovs-$4 $BONDPORTS $5])
124 on_exit 'ip link del ovs-$4'
125 ]
126 )
127
128 # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr])
129 #
130 # Add a VLAN device named 'port' within 'namespace'. It will be configured
131 # with the ID 'vlan-id' and the address 'ip-addr'.
132 m4_define([ADD_VLAN],
133 [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan proto 802.1q id $3])
134 NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
135 NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
136 ]
137 )
138
139 # ADD_SVLAN([port], [namespace], [vlan-id], [ip-addr])
140 #
141 # Add a SVLAN device named 'port' within 'namespace'. It will be configured
142 # with the ID 'vlan-id' and the address 'ip-addr'.
143 m4_define([ADD_SVLAN],
144 [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan proto 802.1ad id $3])
145 NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
146 NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
147 NS_CHECK_EXEC([$2], [ip link set $1.$3 mtu 1496])
148 ]
149 )
150
151 # ADD_CVLAN([port], [namespace], [vlan-id], [ip-addr])
152 #
153 # Similar to ADD_VLAN(), but sets MTU. Lower MTU here instead of increase MTU
154 # on bridge/SVLAN because older kernels didn't work.
155 #
156 m4_define([ADD_CVLAN],
157 [ ADD_VLAN([$1], [$2], [$3], [$4])
158 NS_CHECK_EXEC([$2], [ip link set $1.$3 mtu 1492])
159 ]
160 )
161
162 # ADD_OVS_TUNNEL([type], [bridge], [port], [remote-addr], [overlay-addr])
163 #
164 # Add an ovs-based tunnel device in the root namespace, with name 'port' and
165 # type 'type'. The tunnel device will be configured as point-to-point with the
166 # 'remote-addr' as the underlay address of the remote tunnel endpoint.
167 #
168 # 'port will be configured with the address 'overlay-addr'.
169 #
170 m4_define([ADD_OVS_TUNNEL],
171 [AT_CHECK([ovs-vsctl add-port $2 $3 -- \
172 set int $3 type=$1 options:remote_ip=$4])
173 AT_CHECK([ip addr add dev $2 $5])
174 AT_CHECK([ip link set dev $2 up])
175 AT_CHECK([ip link set dev $2 mtu 1450])
176 on_exit 'ip addr del dev $2 $5'
177 ]
178 )
179
180 # ADD_NATIVE_TUNNEL([type], [port], [namespace], [remote-addr], [overlay-addr],
181 # [type-args], [link-args])
182 #
183 # Add a native tunnel device within 'namespace', with name 'port' and type
184 # 'type'. The tunnel device will be configured as point-to-point with the
185 # 'remote-addr' as the underlay address of the remote tunnel endpoint (as
186 # viewed from the perspective of that namespace).
187 #
188 # 'port' will be configured with the address 'overlay-addr'. 'type-args' is
189 # made available so that additional arguments can be passed to "ip link add"
190 # for configuring specific link type's arguments, for instance to configure
191 # the vxlan destination port. 'link-args' is made for arguments passed to
192 # "ip link set", for instance to configure MAC address.
193 #
194 m4_define([ADD_NATIVE_TUNNEL],
195 [NS_CHECK_EXEC([$3], [ip link add dev $2 type $1 remote $4 $6])
196 NS_CHECK_EXEC([$3], [ip addr add dev $2 $5])
197 NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1450 $7 up])
198 ]
199 )
200
201 # FORMAT_PING([])
202 #
203 # Strip variant pieces from ping output so the output can be reliably compared.
204 #
205 m4_define([FORMAT_PING], [grep "transmitted" | sed 's/time.*ms$/time 0ms/'])
206
207 # STRIP_MONITOR_CSUM([])
208 #
209 # Strip the csum value from ovs-ofctl monitor.
210 #
211 m4_define([STRIP_MONITOR_CSUM], [grep "csum:" | sed 's/csum:.*/csum: <skip>/'])
212
213 # FORMAT_CT([ip-addr])
214 #
215 # Strip content from the piped input which would differ from test to test
216 # and limit the output to the rows containing 'ip-addr'.
217 #
218 m4_define([FORMAT_CT],
219 [[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]])
220
221 # NETNS_DAEMONIZE([namespace], [command], [pidfile])
222 #
223 # Run 'command' as a background process within 'namespace' and record its pid
224 # to 'pidfile' to allow cleanup on exit.
225 #
226 m4_define([NETNS_DAEMONIZE],
227 [ip netns exec $1 $2 & echo $! > $3
228 echo "kill \`cat $3\`" >> cleanup
229 ]
230 )
231
232 # OVS_CHECK_FIREWALL()
233 #
234 # Check if firewalld is active, skip the test if it is on.
235 # The following command currently only supports RHEL and CentOS.
236 m4_define([OVS_CHECK_FIREWALL],
237 [AT_SKIP_IF([systemctl status firewalld 2>&1 | grep running > /dev/null])])
238
239 # OVS_CHECK_VXLAN()
240 #
241 # Do basic check for vxlan functionality, skip the test if it's not there.
242 m4_define([OVS_CHECK_VXLAN],
243 [AT_SKIP_IF([! ip link add foo type vxlan help 2>&1 | grep dstport >/dev/null])
244 OVS_CHECK_FIREWALL()])
245
246 # OVS_CHECK_GRE()
247 m4_define([OVS_CHECK_GRE],
248 [AT_SKIP_IF([! ip link add foo type gretap help 2>&1 | grep gre >/dev/null])
249 OVS_CHECK_FIREWALL()])
250
251 # OVS_CHECK_GENEVE()
252 m4_define([OVS_CHECK_GENEVE],
253 [AT_SKIP_IF([! ip link add foo type geneve help 2>&1 | grep geneve >/dev/null])
254 OVS_CHECK_FIREWALL()])