Changeset 80


Ignore:
Timestamp:
06/05/06 18:04:20 (9 years ago)
Author:
root
Message:

A tweaked Wondershaper script by Brad Skiff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • floppyfw/scripts/wshaper.htb

    r1 r80  
    11#!/bin/sh 
    22# 
    3 # Wonder Shaper 
    4 # 
    5  
    6 # -- 
     3# Wonder Shaper r12 
     4# 
     5 
     6# --# 
    77# Some small things changed by Thomas Lundquist <thomasez@zelow.no> 
    88# to make it work with floppyfw 
    99# Basically, it's grabbing values from files in /etc and changing the 
    1010# calculations from bash'ism to using expr. 
     11# r1 Brad Skiff added mods for SunRocket VoIP <bbbrad2dbone@hotmail.com>  
     12# r1 Mostly adapted from Kristian Kielhofner's htb script <kris@krisk.org> 
     13# 060530 r2 dropped r2q 100 part and changed default class to 30 from 20. 
     14# 060530 r2 added "...Stopped - exit" message. 
     15# 060530 r3 added dst $SERVER_IP/32 to voip "tos" selection 
     16# 060531 r4 added r2q calc (r2q = 125*${UPLINK}kbit/mtu) 
     17# 060531 r5 added fixed rate values and calc'd ceil values to prio 1-4 
     18# 060531 r6 upped ingress burst from 10K to 20K - boosted download speed 
     19# 060531 r7 cleanup and tweaking - removed 90% and 80% CUTTED values 
     20# 060601 r8 added calc'd quantum to classes 
     21# 060601 r9 added kog script suggestions correctly 
     22# 060602 r10 calculating more stuff to make it easier to tweak 
     23# 060602 r11 made for-do loop for stochastic fairness 
     24# 060605 r12 thomasez: s/SERVER_IP/PHONE_IP/ 
    1125# -- 
    12  
    13 cut_to_percentage () { 
    14         BAR=`expr $2 \* $1` 
    15         CUTTED=`expr $BAR / 100` 
    16 } 
    1726 
    1827. /etc/config 
     
    2029. /etc/inside.info 
    2130 
     31# 
     32# Rate settings in bits per second for all classes should be <= UPLINK bps 
     33# 
     34RT10=90000 
     35RT20=110000 
     36RT30=110000 
     37RT40=50000 
     38 
     39# 
     40# calculated values 
     41# 
     42cut_to_percentage () { 
     43        echo `expr $2 \* $1 / 100` 
     44} 
     45 
     46calc_r2q_val () { 
     47        echo `expr $2 \* $1 / 1500` 
     48} 
     49 
     50calc_qtc_val () { 
     51        echo `expr $2 / $1` 
     52} 
     53 
    2254# This makes it "Somewhat less" based on the accurate numbers in /etc/config 
    23 cut_to_percentage $DOWNLOAD_SPEED 94 
    24 DOWNLINK=$CUTTED 
    25  
    26 cut_to_percentage $UPLOAD_SPEED 94 
    27 UPLINK=$CUTTED 
     55DOWNLINK=`cut_to_percentage $DOWNLOAD_SPEED 94` 
     56UPLINK=`cut_to_percentage $UPLOAD_SPEED 94` 
    2857 
    2958DEV=$OUTSIDE_DEVICE 
    3059 
    31 echo "Running Wondershaper with downlink $DOWNLINK and uplink $UPLINK on $DEV" 
     60QTUM=`calc_r2q_val ${UPLINK} 125` 
     61echo "Wondershaper with downlink $DOWNLINK - uplink $UPLINK - r2q $QTUM - on $DEV" 
     62 
     63# VOIP ATA IP - The IP of your Analog Telephone Adapter goes here 
     64PHONE_IP= 
     65 
     66# VOIP SunRocket rtp ports - space separated list 
     67VOIPPORTS="16384 16385 16386 16387 16388 16389 16390 16391 16392 16393 16394 16395 16396 16397 16398 16399 16400 16401 16402 16403" 
     68 
     69# INT SunRocket SIP priority ports - space separated if more than 1 
     70INTPORTS="5060" 
    3271 
    3372# low priority OUTGOING traffic - you can leave this blank if you want 
     
    5190fi 
    5291 
    53  
    5492# clean existing down- and uplink qdiscs, hide errors 
    5593tc qdisc del dev $DEV root    2> /dev/null > /dev/null 
     
    5896if [ "$1" = "stop" ]  
    5997then  
     98        echo "Wondershaper Stopped - exit" 
    6099        exit 
    61100fi 
    62101 
    63  
    64102###### uplink 
    65103 
    66 # install root HTB, point default traffic to 1:20: 
     104# install root HTB, point default traffic to 1:30: 
    67105 
    68106# The "r2q 100" may be wrong but default is 10 and seems to be too little. 
    69 # It should probably be calculated somehow. 
    70 tc qdisc add dev $DEV root handle 1: htb default 20 r2q 100 
     107# It should probably be calculated somehow. r2q = 125*${UPLINK}/mtu 
     108 
     109QTUM=`calc_r2q_val ${UPLINK} 125` 
     110tc qdisc add dev $DEV root handle 1: htb default 30 r2q $QTUM 
    71111 
    72112# shape everything at $UPLINK speed - this prevents huge queues in your 
    73113# DSL modem which destroy latency: 
    74  
    75 tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k 
    76  
    77 # high prio class 1:10: 
    78  
    79 tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \ 
    80    burst 6k prio 1 
    81  
    82 # bulk & default class 1:20 - gets slightly less traffic,  
    83 # and a lower priority: 
    84  
    85 # Making it 90% of the uplink. 
    86 cut_to_percentage $UPLINK 90 
    87 tc class add dev $DEV parent 1:1 classid 1:20 htb rate ${CUTTED}kbit \ 
    88    burst 6k prio 2 
    89  
    90 cut_to_percentage $UPLINK 80 
    91 tc class add dev $DEV parent 1:1 classid 1:30 htb rate ${CUTTED}kbit \ 
    92    burst 6k prio 2 
     114tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit ceil ${UPLINK}kbit burst 6k 
     115 
     116QTC10=`calc_qtc_val $QTUM $RT10` 
     117QTC20=`calc_qtc_val $QTUM $RT20` 
     118QTC30=`calc_qtc_val $QTUM $RT30` 
     119QTC40=`calc_qtc_val $QTUM $RT40` 
     120 
     121# VoIP prio class 1:10: 
     122tc class add dev $DEV parent 1:1 classid 1:10 htb rate $RT10 ceil ${UPLINK}kbit burst 6k prio 1 quantum $QTC10 
     123 
     124# high prio class 1:20 - gets slightly less traffic and a lower priority: 
     125tc class add dev $DEV parent 1:1 classid 1:20 htb rate $RT20 ceil ${UPLINK}kbit burst 6k prio 2 quantum $QTC20 
     126 
     127# The default class, 'non-interactive' ie 'bulk' traffic in 1:30 
     128tc class add dev $DEV parent 1:1 classid 1:30 htb rate $RT30 ceil ${UPLINK}kbit burst 6k prio 3 quantum $QTC30 
     129 
     130# low priority OUTGOING traffic class 1:40 
     131tc class add dev $DEV parent 1:1 classid 1:40 htb rate $RT40 ceil ${UPLINK} burst 6k prio 4 quantum $QTC40 
    93132 
    94133# all get Stochastic Fairness: 
    95 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 
    96 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10 
    97 tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10 
    98  
    99 # TOS Minimum Delay (ssh, NOT scp) in 1:10: 
    100  
    101 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \ 
    102       match ip tos 0x10 0xff  flowid 1:10 
    103  
    104 # ICMP (ip protocol 1) in the interactive class 1:10 so we  
    105 # can do measurements & impress our friends: 
    106 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \ 
    107         match ip protocol 1 0xff flowid 1:10 
    108  
    109 # To speed up downloads while an upload is going on, put ACK packets in 
    110 # the interactive class: 
    111  
    112 tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \ 
     134for i in 10 20 30 40 
     135do 
     136tc qdisc add dev $DEV parent 1:$i handle $i: sfq perturb 10 
     137done 
     138 
     139# Voip TOS in 1:10 # try matching the ATA's IP - seems to work ok! 
     140tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip src $PHONE_IP/32 flowid 1:10 
     141tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip dst $PHONE_IP/32 flowid 1:10 
     142 
     143# Ports as defined above 
     144for a in $VOIPPORTS 
     145do 
     146        tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 match ip dport $a 0xffff flowid 1:10 
     147        tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 match ip sport $a 0xffff flowid 1:10 
     148done 
     149 
     150# TOS Minimum Delay (ssh, NOT scp) in 1:20: 
     151tc filter add dev $DEV parent 1:0 protocol ip prio 20 u32 match ip tos 0x10 0xff  flowid 1:20 
     152 
     153# DNS in interactive class 1:20 
     154tc filter add dev $DEV parent 1:0 protocol ip prio 21 u32 match ip sport 53 0xffff flowid 1:20 
     155tc filter add dev $DEV parent 1:0 protocol ip prio 22 u32 match ip dport 53 0xffff flowid 1:20 
     156 
     157# only give TCP ACK's higher priority if this connection is asymmetrical 
     158if [ ! $DOWNLINK = $UPLINK ] 
     159then 
     160# give TCP ACK's higher priority in 1:20 
     161tc filter add dev $DEV parent 1: protocol ip prio 23 u32 \ 
    113162   match ip protocol 6 0xff \ 
    114163   match u8 0x05 0x0f at 0 \ 
    115164   match u16 0x0000 0xffc0 at 2 \ 
    116165   match u8 0x10 0xff at 33 \ 
    117    flowid 1:10 
    118  
    119 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20 
    120  
     166   flowid 1:20 
     167fi 
     168 
     169#Ports as defined above 
     170for a in $INTPORTS 
     171do 
     172        tc filter add dev $DEV parent 1:0 protocol ip prio 24 u32 match ip dport $a 0xffff flowid 1:20 
     173        tc filter add dev $DEV parent 1:0 protocol ip prio 24 u32 match ip sport $a 0xffff flowid 1:20 
     174done 
     175 
     176# ICMP (ip protocol 1) in the 'high prio' interactive class 1:20 so we  
     177# can do measurements & impress our friends: 
     178tc filter add dev $DEV parent 1: protocol ip prio 25 u32 match ip protocol 1 0xff flowid 1:20 
     179 
     180# The low priority OUTGOING traffic (if used) ends up here in 1:40 
    121181# some traffic however suffers a worse fate 
    122182for a in $NOPRIOPORTDST 
    123183do 
    124         tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \ 
    125            match ip dport $a 0xffff flowid 1:30 
     184        tc filter add dev $DEV parent 1: protocol ip prio 40 u32 match ip dport $a 0xffff flowid 1:40 
    126185done 
    127186 
    128187for a in $NOPRIOPORTSRC 
    129188do 
    130         tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \ 
    131            match ip sport $a 0xffff flowid 1:30 
     189        tc filter add dev $DEV parent 1: protocol ip prio 40 u32 match ip sport $a 0xffff flowid 1:40 
    132190done 
    133191 
    134192for a in $NOPRIOHOSTSRC 
    135193do 
    136         tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \ 
    137            match ip src $a flowid 1:30 
     194        tc filter add dev $DEV parent 1: protocol ip prio 40 u32 match ip src $a flowid 1:40 
    138195done 
    139196 
    140197for a in $NOPRIOHOSTDST 
    141198do 
    142         tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \ 
    143            match ip dst $a flowid 1:30 
    144 done 
    145  
    146 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20 
    147  
    148 tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \ 
    149    match ip dst 0.0.0.0/0 flowid 1:20 
    150  
     199        tc filter add dev $DEV parent 1: protocol ip prio 40 u32 match ip dst $a flowid 1:40 
     200done 
     201 
     202# The default class, 'non-interactive' ie 'bulk' traffic end up here in 1:30 
     203tc filter add dev $DEV parent 1: protocol ip prio 30 u32 match ip dst 0.0.0.0/0 flowid 1:30 
    151204 
    152205########## downlink ############# 
     
    163216 
    164217tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \ 
    165    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1 
    166  
    167  
     218   0.0.0.0/0 police rate ${DOWNLINK}kbit burst 20k drop flowid :1 
     219 
     220 
Note: See TracChangeset for help on using the changeset viewer.