2015-08-04 19:00:16 +01:00
|
|
|
# DEL_NAMESPACES(ns [, ns ... ])
|
|
|
|
#
|
|
|
|
# Delete namespaces from the running OS
|
|
|
|
m4_define([DEL_NAMESPACES],
|
|
|
|
[m4_foreach([ns], [$@],
|
|
|
|
[ip netns del ns
|
|
|
|
])
|
|
|
|
]
|
|
|
|
)
|
2015-08-07 19:40:35 +01:00
|
|
|
|
2015-08-04 19:00:16 +01:00
|
|
|
# ADD_NAMESPACES(ns [, ns ... ])
|
|
|
|
#
|
|
|
|
# Add new namespaces, if ns exists, the old one
|
|
|
|
# will be remove before new ones are installed.
|
|
|
|
m4_define([ADD_NAMESPACES],
|
|
|
|
[m4_foreach([ns], [$@],
|
|
|
|
[DEL_NAMESPACES(ns)
|
|
|
|
AT_CHECK([ip netns add ns])
|
|
|
|
ON_EXIT(DEL_NAMESPACES(ns))
|
|
|
|
])
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2015-08-07 19:40:35 +01:00
|
|
|
# NS_EXEC([namespace], [command])
|
|
|
|
#
|
|
|
|
# Execute 'command' in 'namespace'
|
|
|
|
m4_define([NS_EXEC],
|
|
|
|
[ip netns exec $1 bash -c "$2"]
|
|
|
|
)
|
|
|
|
|
|
|
|
# NS_CHECK_EXEC([namespace], [command], other_params...)
|
|
|
|
#
|
|
|
|
# Wrapper for AT_CHECK that executes 'command' inside 'namespace'.
|
|
|
|
# 'other_params' as passed as they are to AT_CHECK.
|
|
|
|
m4_define([NS_CHECK_EXEC],
|
|
|
|
[ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ]
|
|
|
|
)
|
|
|
|
|
2015-08-04 19:00:16 +01:00
|
|
|
# ADD_VETH([port], [namespace], [ovs-br], [ip_addr])
|
|
|
|
#
|
|
|
|
# Add a pair of veth ports. 'port' will be added to name space 'namespace',
|
|
|
|
# and "ovs-'port'" will be added to ovs bridge 'ovs-br'.
|
|
|
|
#
|
|
|
|
# The 'port' in 'namespace' will be brought up with static IP address
|
|
|
|
# with 'ip_addr' in CIDR notation.
|
|
|
|
#
|
|
|
|
# The existing 'port' or 'ovs-port' will be removed before new ones are added.
|
|
|
|
#
|
|
|
|
m4_define([ADD_VETH],
|
|
|
|
[ AT_CHECK([ip link add $1 type veth peer name ovs-$1])
|
|
|
|
AT_CHECK([ip link set $1 netns $2])
|
|
|
|
AT_CHECK([ip link set dev ovs-$1 up])
|
2015-08-07 19:40:36 +01:00
|
|
|
AT_CHECK([ovs-vsctl add-port $3 ovs-$1])
|
2015-08-07 19:40:35 +01:00
|
|
|
NS_CHECK_EXEC([$2], [ip addr add $4 dev $1])
|
|
|
|
NS_CHECK_EXEC([$2], [ip link set dev $1 up])
|
2015-08-07 19:40:36 +01:00
|
|
|
ON_EXIT([ip link del ovs-$1])
|
2015-08-04 19:00:16 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
# ADD_VLAN([port], [namespace], [vlan-id], [ip-addr])
|
|
|
|
#
|
|
|
|
# Add a VLAN device named 'port' within 'namespace'. It will be configured
|
|
|
|
# with the ID 'vlan-id' and the address 'ip-addr'.
|
|
|
|
m4_define([ADD_VLAN],
|
2015-08-07 19:40:35 +01:00
|
|
|
[ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan id $3])
|
|
|
|
NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
|
|
|
|
NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
|
2015-08-04 19:00:16 +01:00
|
|
|
]
|
|
|
|
)
|