62 lines
1.2 KiB
Bash
62 lines
1.2 KiB
Bash
|
#!/bin/bash
|
||
|
if [ $# -eq 0 ]; then
|
||
|
echo "input client num"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
client_num=$1
|
||
|
|
||
|
#1 配置接口IP
|
||
|
ifconfig ens192 192.168.10.10/24
|
||
|
|
||
|
#2 配置VxLAN隧道
|
||
|
for (( i=0; i<$client_num; i++ ))
|
||
|
do
|
||
|
vni=$[ `expr $i + 100` ]
|
||
|
intf=vxlan$vni
|
||
|
ip link add $intf type vxlan id $vni dstport 4789 remote 192.168.10.254 local 192.168.10.10 dev ens192
|
||
|
ip link set $intf up
|
||
|
done
|
||
|
|
||
|
|
||
|
#3 配置 bridge
|
||
|
for (( i=0; i<$client_num; i++ ))
|
||
|
do
|
||
|
vni=$[ `expr $i + 100` ]
|
||
|
brctl addbr sw_$vni
|
||
|
ifconfig sw_$vni up
|
||
|
done
|
||
|
|
||
|
|
||
|
#4 配置netns
|
||
|
for (( i=0; i<$client_num; i++ ))
|
||
|
do
|
||
|
vni=$[ `expr $i + 100` ]
|
||
|
ip netns add ns$vni
|
||
|
ip link add veth0 type veth peer name veth$vni
|
||
|
ip link set veth0 netns ns$vni
|
||
|
ifconfig veth$vni up
|
||
|
ip netns exec ns$vni ifconfig veth0 up
|
||
|
brctl addif sw_$vni veth$vni vxlan$vni
|
||
|
done
|
||
|
|
||
|
|
||
|
#5 dhclient
|
||
|
for (( i=0; i<$client_num; i++ ))
|
||
|
do
|
||
|
vni=$[ `expr $i + 100` ]
|
||
|
ip netns exec ns$vni dhclient -r
|
||
|
ip netns exec ns$vni dhclient
|
||
|
ip netns exec ns$vni ifconfig
|
||
|
done
|
||
|
|
||
|
#6 run iperf
|
||
|
for (( i=0; i<$client_num; i++ ))
|
||
|
do
|
||
|
vni=$[ `expr $i + 100` ]
|
||
|
ip netns exec ns$vni ifconfig
|
||
|
ip netns exec ns$vni ping 192.168.123.1 -c 1
|
||
|
ip netns exec ns$vni ip route add 192.168.40.254/32 via 192.168.123.1
|
||
|
ip netns exec ns$vni ping 192.168.40.254 -c 1
|
||
|
done
|