Update for iproute-2.6.28
[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 VIRTNET=$7
13
14 SUBNET=`expr match "$VIRTNET" '.*\(/[0-9]*\)'`
15 LINK=${KEY}x${NODEID}
16
17 modprobe ip_gre
18
19 ### Setup EGRE tunnel
20 EGRE=d$LINK
21 $IP tunnel add $EGRE  mode gre type eth remote $REMOTE key $KEY ttl 64
22 $IP link set $EGRE up
23
24 ### Setup etun
25 ETUN0=a$LINK
26 ETUN1=b$LINK
27 ip link add name $ETUN0 type veth peer name $ETUN1
28 ifconfig $ETUN0 mtu 1458 up
29 ifconfig $ETUN1 up
30
31 ### Setup bridge
32 BRIDGE=c$LINK
33 brctl addbr $BRIDGE
34 brctl addif $BRIDGE $EGRE 
35 brctl addif $BRIDGE $ETUN1
36 ifconfig $BRIDGE up
37
38 ### Setup iptables so that packets are visible in the vserver
39 iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
40
41 ### Put a process in the vserver so we can move the interface there
42 su $SLICE -c "sleep 30 &"
43 PID=`su $SLICE -c "pgrep -n sleep"`
44 $IP link set $ETUN0 netns $PID
45 naddress --add --nid $SLICEID --ip ${VIRTIP}${SUBNET}
46 su $SLICE -c "sudo /sbin/ifconfig $ETUN0 ${VIRTIP}${SUBNET} up; sudo /sbin/route add -net $VIRTNET dev $ETUN0"
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