2020-04-30 14:50:59 -05:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [-n <int>] swname" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVERS=2
|
|
|
|
|
|
|
|
while getopts ":n:" opt; do
|
|
|
|
case $opt in
|
|
|
|
n)
|
|
|
|
SERVERS=$((OPTARG))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $((OPTIND-1))
|
2017-10-24 00:01:42 -05:00
|
|
|
|
|
|
|
SWNAME=$1
|
|
|
|
|
|
|
|
pid=$(docker inspect --format '{{.State.Pid}}' $SWNAME)
|
|
|
|
|
|
|
|
echo Seting up servers
|
|
|
|
|
|
|
|
|
2020-04-30 14:50:59 -05:00
|
|
|
for srv in `seq 0 $((SERVERS-1))`; do
|
2017-10-24 00:01:42 -05:00
|
|
|
|
|
|
|
SRV="$SWNAME-srv$srv"
|
|
|
|
|
|
|
|
NSS="ip netns exec $SRV"
|
|
|
|
|
|
|
|
ip netns add $SRV
|
|
|
|
|
|
|
|
$NSS ip addr add 127.0.0.1/8 dev lo
|
|
|
|
$NSS ip addr add ::1/128 dev lo
|
|
|
|
$NSS ip link set dev lo up
|
|
|
|
|
|
|
|
# add virtual link between neighbor and the virtual switch docker
|
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
IF="eth$((srv+1))"
|
2017-10-24 00:01:42 -05:00
|
|
|
|
2020-04-30 14:50:59 -05:00
|
|
|
ip link add ${SRV}eth0 type veth peer name $SWNAME-$IF
|
2017-10-24 00:01:42 -05:00
|
|
|
ip link set ${SRV}eth0 netns $SRV
|
2020-04-30 14:50:59 -05:00
|
|
|
ip link set $SWNAME-$IF netns ${pid}
|
|
|
|
nsenter -t $pid -n ip link set dev $SWNAME-$IF name $IF
|
2017-10-24 00:01:42 -05:00
|
|
|
|
|
|
|
echo "Bring ${SRV}eth0 up"
|
|
|
|
$NSS ip link set dev ${SRV}eth0 name eth0
|
|
|
|
$NSS ip link set dev eth0 up
|
|
|
|
|
|
|
|
echo "Bring $IF up in the virtual switch docker"
|
|
|
|
nsenter -t $pid -n ip link set dev $IF up
|
|
|
|
|
|
|
|
done
|