source: trunk/package/qos-scripts/files/usr/lib/qos/tcrules.awk @ 26622

Last change on this file since 26622 was 26622, checked in by jow, 5 years ago

This patch updates qos-scripts to support fair traffic sharing using the
SFQ with external classifiers method. It also corrects a bug in the
unsupported ESFQ method already used by qos-scripts. (ESFQ:
http://fatooh.org/esfq-2.6/ only updated to 2.6.24, it was switched to
an SFQ patch after that and not updated since 2008)

A class can be forced to use SFQ, and an external classifier added like
this:

config class "Normal"

option avgrate 10
option priority 30
option packetdelay 100
option limitrate 94

# option qdisc "sfq perturb 2"
config class "Normal_up"
# option filter "protocol all flow hash keys src divisor 1024"
config class "Normal_down"
# option filter "protocol all flow hash keys dst divisor 1024"

Using these options, the user needs to load cls_flow before qos-scripts
starts.

I've got more information here:
http://oneitguy.com/blogs/netprince/fair-traffic-sharing-esfq-broken-switching-sfqexternal-classifiers

This has been tested on r23914.

Signed-off-by: Ben Pfountz <netprince<>vt_edu>

File size: 3.3 KB
Line 
1BEGIN {
2        dmax=100
3        if (!(linespeed > 0)) linespeed = 128
4        FS=":"
5        n = 0
6}
7
8($1 != "") {
9        n++
10        class[n] = $1
11        prio[n] = $2
12        avgrate[n] = ($3 * linespeed / 100)
13        pktsize[n] = $4
14        delay[n] = $5
15        maxrate[n] = ($6 * linespeed / 100)
16        qdisc[n] = $7
17        filter[n] = $8
18}
19
20END {
21        allocated = 0
22        maxdelay = 0
23
24        for (i = 1; i <= n; i++) {
25                # set defaults
26                if (!(pktsize[i] > 0)) pktsize[i] = 1500
27                if (!(prio[i] > 0)) prio[i] = 1
28
29                allocated += avgrate[i]
30                sum_prio += prio[i]
31                if ((avgrate[i] > 0) && !(delay[i] > 0)) {
32                        sum_rtprio += prio[i]
33                }
34        }
35       
36        # allocation of m1 in rt classes:
37        # sum(d * m1) must not exceed dmax * (linespeed - allocated)
38        dmax = 0
39        for (i = 1; i <= n; i++) {
40                if (avgrate[i] > 0) {
41                        rtm2[i] = avgrate[i]
42                        if (delay[i] > 0) {
43                                d[i] = delay[i]
44                        } else {
45                                d[i] = 2 * pktsize[i] * 1000 / (linespeed * 1024)
46                                if (d[i] > dmax) dmax = d[i]
47                        }
48                }
49        }       
50
51        ds_avail = dmax * (linespeed - allocated)
52        for (i = 1; i <= n; i++) {
53                lsm1[i] = 0
54                rtm1[i] = 0
55                lsm2[i] = linespeed * prio[i] / sum_prio
56                if ((avgrate[i] > 0) && (d[i] > 0)) {
57                        if (!(delay[i] > 0)) {
58                                ds = ds_avail * prio[i] / sum_rtprio
59                                ds_avail -= ds
60                                rtm1[i] = rtm2[i] + ds/d[i]
61                        }
62                        lsm1[i] = rtm1[i]
63                }
64                else {
65                        d[i] = 0
66                }
67        }
68
69        # main qdisc
70        for (i = 1; i <= n; i++) {
71                printf "tc class add dev "device" parent 1:1 classid 1:"class[i]"0 hfsc"
72                if (rtm1[i] > 0) {
73                        printf " rt m1 " int(rtm1[i]) "kbit d " int(d[i] * 1000) "us m2 " int(rtm2[i])"kbit"
74                }
75                printf " ls m1 " int(lsm1[i]) "kbit d " int(d[i] * 1000) "us m2 " int(lsm2[i]) "kbit"
76                print " ul rate " int(maxrate[i]) "kbit"
77        }
78
79        # leaf qdisc
80        avpkt = 1200
81        for (i = 1; i <= n; i++) {
82                printf "tc qdisc add dev "device" parent 1:"class[i]"0 handle "class[i]"00: "
83
84                # RED parameters - also used to determine the queue length for sfq
85                # calculate min value. for links <= 256 kbit, we use 1500 bytes
86                # use 50 ms queue length as min threshold for faster links
87                # max threshold is fixed to 3*min
88                base_pkt=3000
89                base_rate=256
90                min_lat=50
91                if (maxrate[i] <= base_rate) min = base_pkt
92                else min = int(maxrate[i] * 1024 / 8 * 0.05)
93                max = 3 * min
94                limit = (min + max) * 3
95
96                if (qdisc[i] != "") {
97                        # user specified qdisc
98                        print qdisc[i] " limit " limit
99                } else if (rtm1[i] > 0) {
100                        # rt class - use sfq
101                        print "sfq perturb 2 limit "  limit
102                } else {
103                        # non-rt class - use RED
104
105                        avpkt = pktsize[i]
106                        # don't use avpkt values less than 500 bytes
107                        if (avpkt < 500) avpkt = 500
108                        # if avpkt is too close to min, scale down avpkt to allow proper bursting
109                        if (avpkt > min * 0.70) avpkt *= 0.70
110
111
112                        # according to http://www.cs.unc.edu/~jeffay/papers/IEEE-ToN-01.pdf a drop
113                        # probability somewhere between 0.1 and 0.2 should be a good tradeoff
114                        # between link utilization and response time (0.1: response; 0.2: utilization)
115                        prob="0.12"
116               
117                        rburst=int((2*min + max) / (3 * avpkt))
118                        if (rburst < 2) rburst = 2
119                        print "red min " min " max " max " burst " rburst " avpkt " avpkt " limit " limit " probability " prob " ecn"
120                }
121        }
122       
123        # filter rule
124        for (i = 1; i <= n; i++) {
125                print "tc filter add dev "device" parent 1: prio "class[i]" protocol ip handle "class[i]" fw flowid 1:"class[i] "0"
126                filterc=1
127                if (filter[i] != "") {
128                        print " tc filter add dev "device" parent "class[i]"00: handle "filterc"0 "filter[i]
129                        filterc=filterc+1
130                }
131        }
132}
133
Note: See TracBrowser for help on using the repository browser.