Minor bug fixes
[nodemanager-topo.git] / setup-egre-link
1 #!/bin/sh +x
2
3 IP=/sbin/ip
4
5 SLICE=$1
6 SLICEID=`id -u $SLICE`
7 NODEID=$2
8 REMOTE=$3
9 KEY=$4
10 RATE=$5
11 VIRTIP=$6
12
13 LINK=${KEY}x${NODEID}
14
15 modprobe ip_gre
16 modprobe etun
17
18 ### Setup EGRE tunnel
19 EGRE=d$LINK
20 $IP tunnel add $EGRE  mode gre/eth remote $REMOTE key $KEY ttl 64
21 $IP link set $EGRE up
22
23 ### Setup etun
24 ETUN0=a$LINK
25 ETUN1=b$LINK
26 echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif
27 ifconfig $ETUN0 mtu 1458 up
28 ifconfig $ETUN1 up
29
30 ### Setup bridge
31 BRIDGE=c$LINK
32 brctl addbr $BRIDGE
33 brctl addif $BRIDGE $EGRE 
34 brctl addif $BRIDGE $ETUN1
35 ifconfig $BRIDGE up
36
37 ### Setup iptables so that packets are visible in the vserver
38 iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
39
40 ### Put a process in the vserver so we can move the interface there
41 su $SLICE -c "sleep 60" &
42 sleep 1
43 PID=`su $SLICE -c "pgrep sleep"`
44 chcontext --ctx 1 -- echo $PID > /sys/class/net/$ETUN0/new_ns_pid 
45 sleep 1
46 su $SLICE -c "sudo /sbin/ifconfig $ETUN0 $VIRTIP/24 up"
47
48 ### Set rate
49 tc qdisc add dev $EGRE root handle 1: htb default 10
50 tc class add dev $EGRE parent 1: classid 1:10 htb rate $RATE ceil $RATE
51