Tagging module iproute2 - iproute2-2.6.16-2
[iproute2.git] / examples / diffserv / Edge31-ca-u32
1 #! /bin/sh -x
2 #
3 # sample script on using the ingress capabilities using u32 classifier
4 # This script tags tcindex based on metering on the ingress 
5 # interface the result is used for fast classification and re-marking
6 # on the egress interface
7 # This is an example of a color aware mode marker with PIR configured
8 # based on draft-wahjak-mcm-00.txt (section 3.1)
9 #
10 # The colors are defined using the Diffserv Fields
11 #path to various utilities;
12 #change to reflect yours.
13 #
14 IPROUTE=/usr/src/iproute2-current
15 TC=$IPROUTE/tc/tc
16 IP=$IPROUTE/ip/ip
17 INDEV=eth0
18 EGDEV="dev eth1"
19 CIR1=1500kbit
20 CIR2=1000kbit
21
22 #The CBS is about 60 MTU sized packets
23 CBS1=90k
24 CBS2=90k
25
26 ############################################################ 
27 #
28 # install the ingress qdisc on the ingress interface
29 $TC qdisc add dev $INDEV handle ffff: ingress
30 ############################################################ 
31 #
32 # Create u32 filters 
33 $TC filter add dev $INDEV parent ffff: protocol ip prio 4 handle 1: u32 \
34 divisor 1
35 ############################################################ 
36
37 # The meters: Note that we have shared meters in this case as identified
38 # by the index parameter
39 meter1=" police index 1 rate $CIR1 burst $CBS1 "
40 meter2=" police index 2 rate $CIR2 burst $CBS1 "
41 meter3=" police index 3 rate $CIR2 burst $CBS2 "
42 meter4=" police index 4 rate $CIR1 burst $CBS2 "
43 meter5=" police index 5 rate $CIR1 burst $CBS2 "
44
45 # All packets are marked with a tcindex value which is used on the egress
46 # tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
47
48 # *********************** AF41 *************************** 
49 #AF41 (DSCP 0x22) is passed on with a tcindex value 1
50 #if it doesnt exceed its CIR/CBS 
51 #policer 1  is used.
52 #
53 $TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \
54 match ip tos 0x88 0xfc \
55 $meter1 \
56 continue flowid :1
57 #
58 # if it exceeds the above but not the extra rate/burst below, it gets a 
59 # tcindex value  of 2
60 # policer 2 is used
61 #
62 $TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
63 match ip tos 0x88 0xfc \
64 $meter2 \
65 continue flowid :2
66 #
67 # if it exceeds the above but not the rule below, it gets a tcindex value
68 # of 3 (policer 3)
69 #
70 $TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
71 match ip tos 0x88 0xfc \
72 $meter3 \
73 drop flowid :3
74 #
75
76 # *********************** AF42 *************************** 
77 #AF42 (DSCP 0x24) from is passed on with a tcindex value 2
78 #if it doesnt exceed its CIR/CBS 
79 #policer 2 is used. Note that this is shared with the AF41
80 #
81 #
82 $TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
83 match ip tos 0x90 0xfc \
84 $meter2 \
85 continue flowid :2
86 #
87 # if it exceeds the above but not the rule below, it gets a tcindex value
88 # of 3 (policer 3)
89 #
90 $TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
91 match ip tos 0x90 0xfc \
92 $meter3 \
93 drop flowid :3
94 #
95 # *********************** AF43 *************************** 
96 #
97 #AF43 (DSCP 0x26) from is passed on with a tcindex value 3
98 #if it doesnt exceed its CIR/CBS
99 #policer 3 is used. Note that this is shared with the AF41 and AF42
100 #
101 $TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
102 match ip tos 0x98 0xfc \
103 $meter3 \
104 drop flowid :3
105 #
106 # *********************** BE *************************** 
107 #
108 # Anything else (not from the AF4*) gets discarded if it 
109 # exceeds 1Mbps and by default goes to BE if it doesnt
110 # Note that the BE class is also used by the AF4* in the worst
111 # case
112 #
113 $TC filter add dev $INDEV parent ffff: protocol ip prio 7 u32 \
114 match ip src 0/0\
115 $meter4 \
116 drop flowid :4
117
118 ######################## Egress side ########################
119
120 # attach a dsmarker
121 #
122 $TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
123 #
124 # values of the DSCP to change depending on the class
125 #note that the ECN bits are masked out
126 #
127 #AF41 (0x88 is 0x22 shifted to the right by two bits)
128 #
129 $TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
130        value 0x88
131 #AF42
132 $TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
133        value 0x90
134 #AF43
135 $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
136        value 0x98
137 #BE
138 $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
139        value 0x0
140 #
141 #
142 # The class mapping
143 #
144 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
145           handle 1 tcindex classid 1:1
146 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
147           handle 2 tcindex  classid 1:2
148 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
149           handle 3 tcindex  classid 1:3
150 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
151           handle 4 tcindex  classid 1:4
152 #
153
154 #
155 echo "---- qdisc parameters Ingress  ----------"
156 $TC qdisc ls dev $INDEV
157 echo "---- Class parameters Ingress  ----------"
158 $TC class ls dev $INDEV
159 echo "---- filter parameters Ingress ----------"
160 $TC filter ls dev $INDEV parent ffff:
161
162 echo "---- qdisc parameters Egress  ----------"
163 $TC qdisc ls $EGDEV
164 echo "---- Class parameters Egress  ----------"
165 $TC class ls $EGDEV
166 echo "---- filter parameters Egress ----------"
167 $TC filter ls $EGDEV parent 1:0
168 #
169 #deleting the ingress qdisc
170 #$TC qdisc del $INDEV ingress