]>
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]) | |
19 | ON_EXIT(DEL_NAMESPACES(ns)) | |
20 | ]) | |
21 | ] | |
22 | ) | |
23 | ||
b1778a55 DDP |
24 | # NS_EXEC([namespace], [command]) |
25 | # | |
26 | # Execute 'command' in 'namespace' | |
27 | m4_define([NS_EXEC], | |
28 | [ip netns exec $1 bash -c "$2"] | |
29 | ) | |
30 | ||
31 | # NS_CHECK_EXEC([namespace], [command], other_params...) | |
32 | # | |
33 | # Wrapper for AT_CHECK that executes 'command' inside 'namespace'. | |
34 | # 'other_params' as passed as they are to AT_CHECK. | |
35 | m4_define([NS_CHECK_EXEC], | |
36 | [ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ] | |
37 | ) | |
38 | ||
119db2cb DDP |
39 | # ADD_VETH([port], [namespace], [ovs-br], [ip_addr]) |
40 | # | |
41 | # Add a pair of veth ports. 'port' will be added to name space 'namespace', | |
42 | # and "ovs-'port'" will be added to ovs bridge 'ovs-br'. | |
43 | # | |
44 | # The 'port' in 'namespace' will be brought up with static IP address | |
45 | # with 'ip_addr' in CIDR notation. | |
46 | # | |
47 | # The existing 'port' or 'ovs-port' will be removed before new ones are added. | |
48 | # | |
49 | m4_define([ADD_VETH], | |
50 | [ AT_CHECK([ip link add $1 type veth peer name ovs-$1]) | |
51 | AT_CHECK([ip link set $1 netns $2]) | |
119db2cb | 52 | AT_CHECK([ip link set dev ovs-$1 up]) |
d7c5426b | 53 | AT_CHECK([ovs-vsctl add-port $3 ovs-$1]) |
b1778a55 DDP |
54 | NS_CHECK_EXEC([$2], [ip addr add $4 dev $1]) |
55 | NS_CHECK_EXEC([$2], [ip link set dev $1 up]) | |
d7c5426b | 56 | ON_EXIT([ip link del ovs-$1]) |
119db2cb DDP |
57 | ] |
58 | ) | |
59 | ||
60 | # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr]) | |
61 | # | |
62 | # Add a VLAN device named 'port' within 'namespace'. It will be configured | |
63 | # with the ID 'vlan-id' and the address 'ip-addr'. | |
64 | m4_define([ADD_VLAN], | |
b1778a55 DDP |
65 | [ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan id $3]) |
66 | NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up]) | |
67 | NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4]) | |
119db2cb DDP |
68 | ] |
69 | ) |