Richmond Low
2005-Jul-02 15:13 UTC
Bandwidth shaping script appears to incorrectly halve the bandwidth
Hi, I''m trying to modify the Wondershaper script so achieve the following. 1. Prioritize traffic to the few IP addresses. 2. Everyone else should get a fair amount of bandwidth The problem I am facing is when I run this script is that the bandwidth seems to get halved. I tried to apply this script to a site where the upstream and downstream were fully saturated. I immediately saw backlogs in the ''everyone else'' class but it seems like they were getting only 256 down and 256 up. I thought perhaps the the class was combining the upstream and downstream traffic but when I increased the INCOMING_BW and OUTGOING_BW to 1024, I didn''t see any increase. There still seemed to be only around 256kbps of traffic coming in and around 256kbps of traffic going out. Any help on this would be much appreciated. #!/bin/bash # Set the incoming and outgoing bandwidth here. INCOMING_BW=512 OUTGOING_BW=512 UL_DEV=eth0 DL_DEV=eth1 # clean existing down- and uplink qdiscs, hide errors tc qdisc del dev $UL_DEV root 2> /dev/null > /dev/null tc qdisc del dev $DL_DEV root 2> /dev/null > /dev/null # install root CBQ echo Installing Root CBQ tc qdisc add dev $UL_DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit tc qdisc add dev $DL_DEV root handle 2: cbq avpkt 1000 bandwidth 100mbit # shape everything on $UL_DEV at $OUTGOING_BW speed, $DL_DEV at $INCOMING_BW echo Creating Classes tc class add dev $UL_DEV parent 1: classid 1:1 cbq rate ${OUTGOING_BW}kbit allot 1500 prio 5 bounded isolated tc class add dev $DL_DEV parent 2: classid 2:1 cbq rate ${INCOMING_BW}kbit allot 1500 prio 5 bounded isolated tc class add dev $UL_DEV parent 1:1 classid 1:10 cbq rate 128kbit allot 1600 prio 1 avpkt 1000 tc class add dev $DL_DEV parent 2:1 classid 2:10 cbq rate 128kbit allot 1600 prio 1 avpkt 1000 tc class add dev $UL_DEV parent 1:1 classid 1:20 cbq rate 128kbit allot 1600 prio 2 avpkt 1000 bounded tc class add dev $DL_DEV parent 2:1 classid 2:20 cbq rate 128kbit allot 1600 prio 2 avpkt 1000 bounded tc class add dev $UL_DEV parent 1:1 classid 1:30 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded tc class add dev $DL_DEV parent 2:1 classid 2:30 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded tc class add dev $UL_DEV parent 1:1 classid 1:40 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded tc class add dev $DL_DEV parent 2:1 classid 2:40 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded tc class add dev $UL_DEV parent 1:1 classid 1:50 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded tc class add dev $DL_DEV parent 2:1 classid 2:50 cbq rate 128kbit allot 1600 prio 3 avpkt 1000 bounded # Low priority class for P2P and other traffic that we don''t like tc class add dev $UL_DEV parent 1:1 classid 1:60 cbq rate $[1*$OUTGOING_BW/10]kbit allot 1600 prio 8 avpkt 1000 tc class add dev $DL_DEV parent 2:1 classid 2:60 cbq rate $[1*$OUTGOING_BW/10]kbit allot 1600 prio 8 avpkt 1000 # Everyone else goes into this tc class add dev $UL_DEV parent 1:1 classid 1:80 cbq rate $[9*$OUTGOING_BW/10]kbit allot 1600 prio 5 avpkt 1000 tc class add dev $DL_DEV parent 2:1 classid 2:80 cbq rate $[9*$INCOMING_BW/10]kbit allot 1600 prio 5 avpkt 1000 echo Classes Created # all get Stochastic Fairness: echo Adding SFQ to all classes tc qdisc add dev $UL_DEV parent 1:10 handle 10: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:10 handle 10: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:20 handle 20: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:20 handle 20: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:30 handle 30: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:30 handle 30: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:40 handle 40: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:40 handle 40: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:50 handle 50: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:50 handle 50: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:60 handle 60: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:60 handle 60: sfq perturb 10 tc qdisc add dev $UL_DEV parent 1:80 handle 80: sfq perturb 10 tc qdisc add dev $DL_DEV parent 2:80 handle 80: sfq perturb 10 # start filters tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.1.1 flowid 1:10 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.1.2 flowid 1:10 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.1.3 flowid 1:10 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.1.4 flowid 1:10 # To speed up downloads while an upload is going on, put ACK packets in 1:10 as well tc filter add dev $UL_DEV parent 1: protocol ip prio 8 u32 \ match ip protocol 6 0xff \ match u8 0x05 0x0f at 0 \ match u16 0x0000 0xffc0 at 2 \ match u8 0x10 0xff at 33 \ flowid 1:10 # More filters lower priority tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.1 flowid 1:20 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.2 flowid 1:20 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.3 flowid 1:20 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.4 flowid 1:20 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.5 flowid 1:20 tc filter add dev $UL_DEV parent 1: protocol ip prio 1 u32 match ip dst 192.168.2.6 flowid 1:20 # rest is ''non-interactive'' ie ''bulk'' and ends up in 1:80 tc filter add dev $UL_DEV parent 1: protocol ip prio 5 u32 match ip dst 0.0.0.0/0 flowid 1:80 tc filter add dev $DL_DEV parent 2: protocol ip prio 5 u32 match ip dst 0.0.0.0/0 flowid 2:80