...
 
Commits (1)
# vim: set noexpandtab sw=8 ts=8 filetype=sh :
PATH_TO_NETNS_BIN="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../netns-bin/" && pwd )"
PATH="$PATH:$PATH_TO_NETNS_BIN"
function netlab_init_node()
{
N=$1
echo "Preparing $N, for attach to the network namespace:"
netns_new sleep 30d &
PID=$!
eval $N=$PID
echo $PID > $N.pid
echo " # ${PATH_TO_NETNS_BIN}/netns_run $PID bash"
echo
ip netns add $N
}
function netlab_init()
{
for N in $NETLAB_NODES
do netlab_init_node $N
do
netlab_init_node $N
done
echo
}
function netlab_start_node()
{
N=$1
PID=${!N}
echo Starting $N
mkdir $N
cd $N
if [ -f ../$N.start ]
then netns_run $PID bash ../$N.start $N
then
ip netns exec $N bash ../$N.start $N
fi
if [ -f ../common.start ]
then netns_run $PID bash ../common.start $N
then
ip netns exec $N bash ../common.start $N
fi
cd ..
......@@ -52,41 +41,44 @@ function netlab_start_node()
function netlab_stop_node()
{
N=$1
PID=$2
echo Stopping $N
cd $N
if [ -f ../common.stop ]
then netns_run $PID bash ../common.stop $N
then
ip netns exec $N bash ../common.stop $N
fi
if [ -f ../$N.stop ]
then netns_run $PID bash ../$N.stop $N
then
ip netns exec $N bash ../$N.stop $N
fi
cd ..
rm -rf $N
echo
kill $PID
rm $N.pid
for i in $(ip netns pids $N)
do
kill $i
done
ip netns delete $N
}
function netlab_start()
{
for N in $NETLAB_NODES
do netlab_start_node $N
do
netlab_start_node $N
done
}
function netlab_stop()
{
# match no files will expand to null string
shopt -s nullglob
for N in *.pid
do netlab_stop_node ${N%.pid} $(cat $N)
for N in $NETLAB_NODES
do
netlab_stop_node $N
done
}
......@@ -95,12 +87,13 @@ function if_dummy()
{
ip link add name $2 netns $1 type dummy
netns_run $1 ip link set $2 up
ip netns exec $1 ip link set lo up
ip netns exec $1 ip link set $2 up
if [ -n "${3}" ]
then
netns_run $1 ip addr add ${3}.1/24 dev $2
netns_run $1 ip addr add ${4}::1/64 dev $2
ip netns exec $1 ip addr add ${3}.1/24 dev $2
ip netns exec $1 ip addr add ${4}::1/64 dev $2
fi
}
......@@ -108,13 +101,13 @@ function if_veth()
{
ip link add name $2 netns $1 type veth peer name $4 netns $3
netns_run $1 ip link set $2 up
netns_run $3 ip link set $4 up
ip netns exec $1 ip link set $2 up
ip netns exec $3 ip link set $4 up
if [ -n "${5}" ]
then
netns_run $1 ip addr add ${5}.1/24 dev $2
netns_run $3 ip addr add ${5}.2/24 dev $4
ip netns exec $1 ip addr add ${5}.1/24 dev $2
ip netns exec $3 ip addr add ${5}.2/24 dev $4
fi
}
......@@ -122,12 +115,12 @@ function if_veth6()
{
ip link add name $2 netns $1 type veth peer name $4 netns $3
netns_run $1 ip link set $2 up
netns_run $3 ip link set $4 up
if [ -n "${5}" ]
then
netns_run $1 ip addr add ${5}::1/48 dev $2
netns_run $3 ip addr add ${5}::2/48 dev $4
ip netns exec $1 ip addr add ${5}::1/48 dev $2
ip netns exec $3 ip addr add ${5}::2/48 dev $4
fi
ip netns exec $1 ip link set $2 up
ip netns exec $3 ip link set $4 up
}
......@@ -57,13 +57,13 @@ netlab_init
for((i = 1; i <= NETLAB_SIZE; i++))
do
if_dummy $(eval echo \$m$i) ve0 10.0.$i 2001:db8:$i:1
if_dummy m$i ve0 10.10.$i 2001:db8:$((i+100)):1
done
for((i = 1; i < NETLAB_SIZE; i++))
for((i = 1; i <= NETLAB_SIZE; i++))
do
if_veth $(eval echo \$m$i) ve1 $(eval echo \$m$((i+1))) ve2 10.0.$i
if_veth6 $(eval echo \$m$i) ve1 $(eval echo \$m$((i+1))) ve2 2001:db8:$i
if_veth m$i ve1 m$((i+1)) ve2 10.0.$i
if_veth6 m$i ve1 m$((i+1)) ve2 2001:db8:$i
done
netlab_start
......@@ -3,4 +3,6 @@
. netlab_lib
NETLAB_NODES="$(ip netns list | sed ':a;N;$!ba;s/\n/ /g')"
netlab_stop