-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-ns
More file actions
executable file
·57 lines (51 loc) · 1.43 KB
/
test-ns
File metadata and controls
executable file
·57 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
#to test:
#ip netns exec test-1 bash
#ping 192.168.13.200
network=192.168.13
stop(){
for id in `seq 1 127`; do
idprev=$(( $id - 1))
ip netns del test-$id;
ip link del test-$idprev-$id
done;
}
bring(){
idprev=$1
id=$2
ipprev=$(( $idprev * 2 ))
ip=$(( $idprev * 2 + 1 ))
ip netns add test-$id
ip netns exec test-$id ip link set dev lo up
ip netns exec test-$id sysctl -w net.ipv4.conf.default.forwarding=1
# ip netns exec test-$id sysctl -w net.ipv4.conf.default.hop_limit=255
ip link add test-$1-$2 type veth peer name test-$2-$1
[ $idprev -eq 0 ] && ip link set test-$1-$2 up
[ $idprev -eq 0 ] && ip a a ${network}.$ipprev/31 dev test-$1-$2
[ $idprev -eq 0 ] && ip r a ${network}.0/24 via ${network}.$ip
[ $idprev -gt 0 ] && ip link set test-$1-$2 netns test-$idprev up
[ $idprev -gt 0 ] && ip netns exec test-$idprev ip a a ${network}.$ipprev/31 dev test-$1-$2
[ $idprev -gt 0 ] && ip netns exec test-$idprev ip r a ${network}.0/24 via $network.$ip
ip link set test-$2-$1 netns test-$id up
ip netns exec test-$id ip a a ${network}.$ip/31 dev test-$2-$1
ip netns exec test-$id ip r a default via ${network}.$ipprev
ip netns exec test-$id ip r a ${network}.0 via ${network}.$ipprev
}
start() {
for id in `seq 0 127`; do
bring $id $(( $id + 1 ))
done;
ip a a ${network}.0/31 dev test-0-1
ip r a ${network}.0/24 via ${network}.1
}
case $1 in
stop)
stop
;;
start)
start
;;
*)
echo stop or start
;;
esac