1#! /bin/sh 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 blind mode marker with PIR configured 8# based on draft-wahjak-mcm-00.txt (section 3.2) 9# 10#path to various utilities; 11#change to reflect yours. 12# 13IPROUTE=/root/DS-6-beta/iproute2-990530-dsing 14TC=$IPROUTE/tc/tc 15IP=$IPROUTE/ip/ip 16INDEV=eth2 17EGDEV="dev eth1" 18CIR1=1000kbit 19CIR2=1000kbit 20# The PIR is the excess (in addition to the CIR i.e if always 21# going to the PIR --> average rate is CIR+PIR) 22PIR1=1000kbit 23PIR2=500kbit 24 25#The CBS is about 60 MTU sized packets 26CBS1=90k 27CBS2=90k 28#the EBS is about 10 max sized packets 29EBS1=15k 30EBS2=15k 31# The meters 32meter1=" police rate $CIR1 burst $CBS1 " 33meter1a=" police rate $PIR1 burst $EBS1 " 34meter2=" police rate $CIR2 burst $CBS1 " 35meter2a="police rate $PIR2 burst $CBS1 " 36meter3=" police rate $CIR2 burst $CBS2 " 37meter3a=" police rate $PIR2 burst $EBS2 " 38meter4=" police rate $CIR1 burst $CBS2 " 39meter5=" police rate $CIR1 burst $CBS2 " 40 41 42# install the ingress qdisc on the ingress interface 43############################################################ 44$TC qdisc add dev $INDEV handle ffff: ingress 45############################################################ 46# 47############################################################ 48 49# All packets are marked with a tcindex value which is used on the egress 50# NOTE: tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE 51# 52#anything from subnet 10.2.0.2/24 is passed on with a tcindex value 1 53#if it doesnt exceed its CIR/CBS + PIR/EBS 54# 55$TC filter add dev $INDEV parent ffff: protocol ip prio 1 u32 \ 56match ip src 10.2.0.0/24 $meter1 \ 57continue flowid :1 58$TC filter add dev $INDEV parent ffff: protocol ip prio 2 u32 \ 59match ip src 10.2.0.0/24 $meter1a \ 60continue flowid :1 61 62# 63# if it exceeds the above but not the extra rate/burst below, it gets a 64#tcindex value of 2 65# 66$TC filter add dev $INDEV parent ffff: protocol ip prio 3 u32 \ 67match ip src 10.2.0.0/24 $meter2 \ 68continue flowid :2 69$TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \ 70match ip src 10.2.0.0/24 $meter2a \ 71continue flowid :2 72# 73# if it exceeds the above but not the rule below, it gets a tcindex value 74# of 3 75# 76$TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \ 77match ip src 10.2.0.0/24 $meter3 \ 78continue flowid :3 79$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \ 80match ip src 10.2.0.0/24 $meter3a \ 81drop flowid :3 82# 83# 84# Anything else (not from the subnet 10.2.0.24/24) gets discarded if it 85# exceeds 1Mbps and by default goes to BE if it doesnt 86# 87$TC filter add dev $INDEV parent ffff: protocol ip prio 7 u32 \ 88match ip src 0/0 $meter5 \ 89drop flowid :4 90 91 92######################## Egress side ######################## 93 94 95# attach a dsmarker 96# 97$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64 98# 99# values of the DSCP to change depending on the class 100#note that the ECN bits are masked out 101# 102#AF41 (0x88 is 0x22 shifted to the right by two bits) 103# 104$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \ 105 value 0x88 106#AF42 107$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \ 108 value 0x90 109#AF43 110$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \ 111 value 0x98 112#BE 113$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \ 114 value 0x0 115# 116# 117# The class mapping 118# 119$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \ 120 handle 1 tcindex classid 1:1 121$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \ 122 handle 2 tcindex classid 1:2 123$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \ 124 handle 3 tcindex classid 1:3 125$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \ 126 handle 4 tcindex classid 1:4 127# 128 129# 130echo "---- qdisc parameters Ingress ----------" 131$TC qdisc ls dev $INDEV 132echo "---- Class parameters Ingress ----------" 133$TC class ls dev $INDEV 134echo "---- filter parameters Ingress ----------" 135$TC filter ls dev $INDEV parent ffff: 136 137echo "---- qdisc parameters Egress ----------" 138$TC qdisc ls $EGDEV 139echo "---- Class parameters Egress ----------" 140$TC class ls $EGDEV 141echo "---- filter parameters Egress ----------" 142$TC filter ls $EGDEV parent 1:0 143# 144#deleting the ingress qdisc 145#$TC qdisc del $INDEV ingress 146