Scripts to associate a token bucket with a virtual link (Yogesh)
[vsys.git] / factory / setup-link
index df3638f..5c93a30 100755 (executable)
@@ -22,7 +22,7 @@ $IP link set $EGRE up
 ETUN0=v$LINK
 ETUN1=etun$LINK
 echo $ETUN0,$ETUN1 > /sys/module/etun/parameters/newif
-ifconfig $ETUN0 up
+ifconfig $ETUN0 mtu 1458 up
 ifconfig $ETUN1 up
 
 ### Setup bridge
@@ -32,8 +32,13 @@ brctl addif $BRIDGE $EGRE
 brctl addif $BRIDGE $ETUN1
 ifconfig $BRIDGE up
 
+### Setup iptables so that packets are visible in the vserver
+iptables -t mangle -A FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
+
 ### Create "grab link" script
 GRAB=/vsys/grab-$ETUN0
+echo $SLICE > $GRAB.acl 
+rm -f $GRAB
 cat > $GRAB <<EOF
 #!/bin/sh
 
@@ -42,6 +47,64 @@ read PID
 chcontext --ctx 1 -- echo \$PID > /sys/class/net/$ETUN0/new_ns_pid 
 EOF
 chmod +x $GRAB
-echo $SLICE > $GRAB.acl 
 
+### Create "bind link" script
+BIND=/vsys/bind-link-$ETUN0
+echo $SLICE > $BIND.acl 
+rm -f $BIND
+cat > $BIND <<EOF
+#!/bin/sh
+
+read rt
+read lt
+read burs
+
+tc qdisc add dev $EGRE root tbf rate \$rt latency \$lt burst \$burs
+
+rm -rf $BIND.acl 
+touch $BIND.acl 
+
+EOF
+chmod +x $BIND
+
+### Create "unbind link" script
+UNBIND=/vsys/unbind-link-$ETUN0
+touch $UNBIND.acl 
+rm -f $UNBIND
+cat > $UNBIND <<EOF
+#!/bin/sh
+
+tc qdisc del root dev $EGRE
+
+EOF
+chmod +x $UNBIND
+
+### Create "delete link" script
+DELETE=/vsys/delete-$ETUN0
+echo $SLICE > $DELETE.acl 
+rm -f $DELETE
+cat > $DELETE <<EOF
+#!/bin/sh
+
+read NULL
 
+# Remove iptables rule
+iptables -t mangle -D FORWARD -o $BRIDGE -j MARK --set-mark $SLICEID
+
+# Get rid of etun devices, only need name of one of them
+echo $ETUN1 > /sys/module/etun/parameters/delif
+
+# Get rid of bridge
+ifconfig $BRIDGE down
+brctl delbr $BRIDGE
+
+# Get rid of EGRE tunnel
+ip tunnel del $EGRE
+
+# Clean up files
+rm -f $GRAB $GRAB.acl
+rm -f $DELETE $DELETE.acl
+rm -f $BIND $BIND.acl
+rm -f $UNBIND $UNBIND.acl
+EOF
+chmod +x $DELETE