Home | History | Annotate | Download | only in diffserv
      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.2)
      9 #
     10 # The colors are defined using the Diffserv Fields
     11 #path to various utilities;
     12 #change to reflect yours.
     13 #
     14 IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
     15 TC=$IPROUTE/tc/tc
     16 IP=$IPROUTE/ip/ip
     17 IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
     18 INDEV=eth2
     19 EGDEV="dev eth1"
     20 CIR1=1000kbit
     21 CIR2=500kbit
     22 # the PIR is what is in excess of the CIR
     23 PIR1=1000kbit
     24 PIR2=500kbit
     25 
     26 #The CBS is about 60 MTU sized packets
     27 CBS1=90k
     28 CBS2=90k
     29 #the EBS is about 20 max sized packets
     30 EBS1=30k
     31 EBS2=30k
     32 
     33 # The meters: Note that we have shared meters in this case as identified
     34 # by the index parameter
     35 meter1=" police index 1 rate $CIR1 burst $CBS1 "
     36 meter1a=" police index 2 rate $PIR1 burst $EBS1 "
     37 meter2=" police index 3 rate $CIR2 burst $CBS1 "
     38 meter2a=" police index 4 rate $PIR2 burst $EBS1 "
     39 meter3=" police index 5 rate $CIR2 burst $CBS2 "
     40 meter3a=" police index 6 rate $PIR2 burst $EBS2 "
     41 meter4=" police index 7 rate $CIR1 burst $CBS2 "
     42 
     43 ############################################################ 
     44 #
     45 # install the ingress qdisc on the ingress interface
     46 $TC qdisc add dev $INDEV handle ffff: ingress
     47 ############################################################ 
     48 #
     49 # All packets are marked with a tcindex value which is used on the egress
     50 # tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
     51 #
     52 # *********************** AF41 *************************** 
     53 #AF41 (DSCP 0x22) from is passed on with a tcindex value 1
     54 #if it doesnt exceed its CIR/CBS + PIR/EBS
     55 #policer 1  is used.
     56 #
     57 $TC filter add dev $INDEV parent ffff: protocol ip prio 1 u32 \
     58 match ip tos 0x88 0xfc \
     59 $meter1 \
     60 continue flowid :1
     61 $TC filter add dev $INDEV parent ffff: protocol ip prio 2 u32 \
     62 match ip tos 0x88 0xfc \
     63 $meter1a \
     64 continue flowid :1
     65 #
     66 # if it exceeds the above but not the extra rate/burst below, it gets a 
     67 # tcindex value  of 2
     68 # policer 2 is used
     69 #
     70 $TC filter add dev $INDEV parent ffff: protocol ip prio 3 u32 \
     71 match ip tos 0x88 0xfc \
     72 $meter2 \
     73 continue flowid :2
     74 $TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \
     75 match ip tos 0x88 0xfc \
     76 $meter2a \
     77 continue flowid :2
     78 #
     79 # if it exceeds the above but not the rule below, it gets a tcindex value
     80 # of 3 (policer 3)
     81 #
     82 $TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
     83 match ip tos 0x88 0xfc \
     84 $meter3 \
     85 continue flowid :3
     86 $TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
     87 match ip tos 0x88 0xfc \
     88 $meter3a \
     89 drop flowid :3
     90 #
     91 # *********************** AF42 *************************** 
     92 #AF42 (DSCP 0x24) from is passed on with a tcindex value 2
     93 #if it doesnt exceed its CIR/CBS + PIR/EBS
     94 #policer 2 is used. Note that this is shared with the AF41
     95 #
     96 #
     97 $TC filter add dev $INDEV parent ffff: protocol ip prio 8 u32 \
     98 match ip tos 0x90 0xfc \
     99 $meter2 \
    100 continue flowid :2
    101 $TC filter add dev $INDEV parent ffff: protocol ip prio 9 u32 \
    102 match ip tos 0x90 0xfc \
    103 $meter2a \
    104 continue flowid :2
    105 #
    106 # if it exceeds the above but not the rule below, it gets a tcindex value
    107 # of 3 (policer 3)
    108 #
    109 $TC filter add dev $INDEV parent ffff: protocol ip prio 10 u32 \
    110 match ip tos 0x90 0xfc \
    111 $meter3 \
    112 continue flowid :3
    113 $TC filter add dev $INDEV parent ffff: protocol ip prio 11 u32 \
    114 match ip tos 0x90 0xfc \
    115 $meter3a \
    116 drop flowid :3
    117 
    118 #
    119 # *********************** AF43 *************************** 
    120 #
    121 #AF43 (DSCP 0x26) from is passed on with a tcindex value 3
    122 #if it doesnt exceed its CIR/CBS + PIR/EBS
    123 #policer 3 is used. Note that this is shared with the AF41 and AF42
    124 #
    125 $TC filter add dev $INDEV parent ffff: protocol ip prio 13 u32 \
    126 match ip tos 0x98 0xfc \
    127 $meter3 \
    128 continue flowid :3
    129 $TC filter add dev $INDEV parent ffff: protocol ip prio 14 u32 \
    130 match ip tos 0x98 0xfc \
    131 $meter3a \
    132 drop flowid :3
    133 #
    134 ## *********************** BE *************************** 
    135 ##
    136 ## Anything else (not from the AF4*) gets discarded if it 
    137 ## exceeds 1Mbps and by default goes to BE if it doesnt
    138 ## Note that the BE class is also used by the AF4* in the worst
    139 ## case
    140 ##
    141 $TC filter add dev $INDEV parent ffff: protocol ip prio 16 u32 \
    142 match ip src 0/0\
    143 $meter4 \
    144 drop flowid :4
    145 
    146 ######################## Egress side ########################
    147 
    148 # attach a dsmarker
    149 #
    150 $TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
    151 #
    152 # values of the DSCP to change depending on the class
    153 #note that the ECN bits are masked out
    154 #
    155 #AF41 (0x88 is 0x22 shifted to the right by two bits)
    156 #
    157 $TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
    158        value 0x88
    159 #AF42
    160 $TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
    161        value 0x90
    162 #AF43
    163 $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
    164        value 0x98
    165 #BE
    166 $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
    167        value 0x0
    168 #
    169 #
    170 # The class mapping
    171 #
    172 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
    173           handle 1 tcindex classid 1:1
    174 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
    175           handle 2 tcindex  classid 1:2
    176 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
    177           handle 3 tcindex  classid 1:3
    178 $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
    179           handle 4 tcindex  classid 1:4
    180 #
    181 
    182 #
    183 echo "---- qdisc parameters Ingress  ----------"
    184 $TC qdisc ls dev $INDEV
    185 echo "---- Class parameters Ingress  ----------"
    186 $TC class ls dev $INDEV
    187 echo "---- filter parameters Ingress ----------"
    188 $TC filter ls dev $INDEV parent ffff:
    189 
    190 echo "---- qdisc parameters Egress  ----------"
    191 $TC qdisc ls $EGDEV
    192 echo "---- Class parameters Egress  ----------"
    193 $TC class ls $EGDEV
    194 echo "---- filter parameters Egress ----------"
    195 $TC filter ls $EGDEV parent 1:0
    196 #
    197 #deleting the ingress qdisc
    198 #$TC qdisc del $INDEV ingress
    199