]>
Commit | Line | Data |
---|---|---|
119db2cb DDP |
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 | ) | |
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. | |
15 | m4_define([ADD_NAMESPACES], | |
16 | [m4_foreach([ns], [$@], | |
17 | [DEL_NAMESPACES(ns) | |
18 | AT_CHECK([ip netns add ns]) | |
53eb8cb8 | 19 | on_exit 'DEL_NAMESPACES(ns)' |
119db2cb DDP |
20 | ]) |
21 | ] | |
22 | ) | |
23 | ||
b1778a55 DDP |
24 | # NS_EXEC([namespace], [command]) |
25 | # | |
26 | # Execute 'command' in 'namespace' | |
27 | m4_define([NS_EXEC], | |
5fd56271 JS |
28 | [ip netns exec $1 sh << NS_EXEC_HEREDOC |
29 | $2 | |
30 | NS_EXEC_HEREDOC]) | |
b1778a55 DDP |
31 | |
32 | # NS_CHECK_EXEC([namespace], [command], other_params...) | |
33 | # | |
34 | # Wrapper for AT_CHECK that executes 'command' inside 'namespace'. | |
35 | # 'other_params' as passed as they are to AT_CHECK. | |
36 | m4_define([NS_CHECK_EXEC], | |
37 | [ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ] | |
38 | ) | |
39 | ||
7ca476af JS |
40 | # ADD_BR([name], [vsctl-args]) |
41 | # | |
42 | # Expands into the proper ovs-vsctl commands to create a bridge with the | |
43 | # appropriate type, and allows additional arguments to be passed. | |
44 | m4_define([ADD_BR], [ovs-vsctl _ADD_BR([$1]) -- $2]) | |
45 | ||
119db2cb DDP |
46 | # ADD_VETH([port], [namespace], [ovs-br], [ip_addr]) |
47 | # | |
48 | # Add a pair of veth ports. 'port' will be added to name space 'namespace', | |
49 | # and "ovs-'port'" will be added to ovs bridge 'ovs-br'. | |
50 | # | |
51 | # The 'port' in 'namespace' will be brought up with static IP address | |
52 | # with 'ip_addr' in CIDR notation. | |
53 | # | |
54 | # The existing 'port' or 'ovs-port' will be removed before new ones are added. | |
55 | # | |
56 | m4_define([ADD_VETH], | |
57 | [ AT_CHECK([ip link add $1 type veth peer name ovs-$1]) | |
58 | AT_CHECK([ip link set $1 netns $2]) | |
119db2cb | 59 | AT_CHECK([ip link set dev ovs-$1 up]) |
d7c5426b | 60 | AT_CHECK([ovs-vsctl add-port $3 ovs-$1]) |
b1778a55 DDP |
61 | NS_CHECK_EXEC([$2], [ip addr add $4 dev $1]) |
62 | NS_CHECK_EXEC([$2], [ip link set dev $1 up]) | |
53eb8cb8 | 63 | on_exit 'ip link del ovs-$1' |
119db2cb DDP |
64 | ] |
65 | ) | |
66 | ||
67 | # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr]) | |
68 | # | |
69 | # Add a VLAN device named 'port' within 'namespace'. It will be configured | |
70 | # with the ID 'vlan-id' and the address 'ip-addr'. | |
71 | m4_define([ADD_VLAN], | |
b1778a55 DDP |
72 | [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan id $3]) |
73 | NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up]) | |
74 | NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4]) | |
119db2cb DDP |
75 | ] |
76 | ) | |
de22d08f | 77 | |
810e1785 JS |
78 | # ADD_OVS_TUNNEL([type], [bridge], [port], [remote-addr], [overlay-addr]) |
79 | # | |
80 | # Add an ovs-based tunnel device in the root namespace, with name 'port' and | |
81 | # type 'type'. The tunnel device will be configured as point-to-point with the | |
82 | # 'remote-addr' as the underlay address of the remote tunnel endpoint. | |
83 | # | |
84 | # 'port will be configured with the address 'overlay-addr'. | |
85 | # | |
86 | m4_define([ADD_OVS_TUNNEL], | |
87 | [AT_CHECK([ovs-vsctl add-port $2 $3 -- \ | |
88 | set int $3 type=$1 options:remote_ip=$4]) | |
89 | AT_CHECK([ip addr add dev $2 $5]) | |
90 | AT_CHECK([ip link set dev $2 up]) | |
91 | AT_CHECK([ip link set dev $2 mtu 1450]) | |
53eb8cb8 | 92 | on_exit 'ip addr del dev $2 $5' |
810e1785 JS |
93 | ] |
94 | ) | |
95 | ||
96 | # ADD_NATIVE_TUNNEL([type], [port], [namespace], [remote-addr], [overlay-addr], | |
97 | # [link-args]) | |
98 | # | |
99 | # Add a native tunnel device within 'namespace', with name 'port' and type | |
100 | # 'type'. The tunnel device will be configured as point-to-point with the | |
101 | # 'remote-addr' as the underlay address of the remote tunnel endpoint (as | |
102 | # viewed from the perspective of that namespace). | |
103 | # | |
104 | # 'port' will be configured with the address 'overlay-addr'. 'link-args' is | |
105 | # made available so that additional arguments can be passed to "ip link", | |
106 | # for instance to configure the vxlan destination port. | |
107 | # | |
108 | m4_define([ADD_NATIVE_TUNNEL], | |
109 | [NS_CHECK_EXEC([$3], [ip link add dev $2 type $1 remote $4 $6]) | |
110 | NS_CHECK_EXEC([$3], [ip addr add dev $2 $5]) | |
111 | NS_CHECK_EXEC([$3], [ip link set dev $2 up]) | |
112 | NS_CHECK_EXEC([$3], [ip link set dev $2 mtu 1450]) | |
113 | ] | |
114 | ) | |
115 | ||
de22d08f JS |
116 | # FORMAT_PING([]) |
117 | # | |
118 | # Strip variant pieces from ping output so the output can be reliably compared. | |
119 | # | |
120 | m4_define([FORMAT_PING], [grep "transmitted" | sed 's/time.*ms$/time 0ms/']) | |
07659514 JS |
121 | |
122 | # FORMAT_CT() | |
123 | # | |
124 | # Strip content from the piped input which would differ from test to test. | |
125 | # | |
126 | m4_define([FORMAT_CT], | |
127 | [[grep "dst=$1" | sed -e 's/port=[0-9]*/port=<cleared>/g' -e 's/ */ /g' -e 's/secctx[^ ]* //' | cut -d' ' -f4- | sort | uniq]]) | |
128 | ||
129 | # NETNS_DAEMONIZE([namespace], [command], [pidfile]) | |
130 | # | |
131 | # Run 'command' as a background process within 'namespace' and record its pid | |
132 | # to 'pidfile' to allow cleanup on exit. | |
133 | # | |
134 | m4_define([NETNS_DAEMONIZE], | |
135 | [ip netns exec $1 $2 & echo $! > $3 | |
136 | echo "kill \`cat $3\`" >> cleanup | |
137 | ] | |
138 | ) |