home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / iproute / examples / diffserv / Edge31-cb-chains < prev    next >
Encoding:
Text File  |  2004-04-15  |  3.9 KB  |  133 lines

  1. #! /bin/sh -x
  2. #
  3. # sample script on using the ingress capabilities
  4. # This script fwmark tags(IPchains) 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 no PIR configured
  8. # based on draft-wahjak-mcm-00.txt (section 3.1)
  9. #
  10. #path to various utilities;
  11. #change to reflect yours.
  12. #
  13. IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
  14. TC=$IPROUTE/tc/tc
  15. IP=$IPROUTE/ip/ip
  16. IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
  17. INDEV=eth2
  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. meter1="police rate $CIR1 burst $CBS1 "
  27. meter2="police rate $CIR1 burst $CBS2 "
  28. meter3="police rate $CIR2 burst $CBS1 "
  29. meter4="police rate $CIR2 burst $CBS2 "
  30. meter5="police rate $CIR2 burst $CBS2 "
  31. #
  32. # tag the rest of incoming packets from subnet 10.2.0.0/24 to fw value 1
  33. # tag all incoming packets from any other subnet to fw tag 2
  34. ############################################################ 
  35. $IPCHAINS -A input -i $INDEV -s 0/0 -m 2
  36. $IPCHAINS -A input -i $INDEV -s 10.2.0.0/24 -m 1
  37. #
  38. ############################################################ 
  39. # install the ingress qdisc on the ingress interface
  40. $TC qdisc add dev $INDEV handle ffff: ingress
  41. #
  42. ############################################################ 
  43.  
  44. # All packets are marked with a tcindex value which is used on the egress
  45. # tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
  46. #
  47. ############################################################ 
  48. # anything with fw tag of 1 is passed on with a tcindex value 1
  49. #if it doesnt exceed its allocated rate (CIR/CBS)
  50. $TC filter add dev $INDEV parent ffff: protocol ip prio 4 handle 1 fw \
  51. $meter1 \
  52. continue flowid 4:1
  53. #
  54. # if it exceeds the above but not the extra rate/burst below, it gets a 
  55. #tcindex value  of 2
  56. #
  57. $TC filter add dev $INDEV parent ffff: protocol ip prio 5 handle 1 fw \
  58. $meter2 \
  59. continue flowid 4:2
  60. #
  61. # if it exceeds the above but not the rule below, it gets a tcindex value
  62. # of 3
  63. #
  64. $TC filter add dev $INDEV parent ffff: protocol ip prio 6 handle 1 fw \
  65. $meter3 \
  66. drop flowid 4:3
  67. #
  68. # Anything else (not from the subnet 10.2.0.24/24) gets discarded if it 
  69. # exceeds 1Mbps and by default goes to BE if it doesnt
  70. #
  71. $TC filter add dev $INDEV parent ffff: protocol ip prio 6 handle 2 fw \
  72. $meter5 \
  73. drop flowid 4:4
  74.  
  75.  
  76. ######################## Egress side ########################
  77.  
  78.  
  79. # attach a dsmarker
  80. #
  81. $TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
  82. #
  83. # values of the DSCP to change depending on the class
  84. #note that the ECN bits are masked out
  85. #
  86. #AF41 (0x88 is 0x22 shifted to the right by two bits)
  87. #
  88. $TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
  89.        value 0x88
  90. #AF42
  91. $TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
  92.        value 0x90
  93. #AF43
  94. $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
  95.        value 0x98
  96. #BE
  97. $TC class change $EGDEV classid 1:4 dsmark mask 0x3 \
  98.        value 0x0
  99. #
  100. #
  101. # The class mapping (using tcindex; could easily have
  102. # replaced it with the fw classifier instead)
  103. #
  104. $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
  105.           handle 1 tcindex classid 1:1
  106. $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
  107.           handle 2 tcindex  classid 1:2
  108. $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
  109.           handle 3 tcindex  classid 1:3
  110. $TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
  111.           handle 4 tcindex  classid 1:4
  112. #
  113.  
  114. #
  115. echo "---- qdisc parameters Ingress  ----------"
  116. $TC qdisc ls dev $INDEV
  117. echo "---- Class parameters Ingress  ----------"
  118. $TC class ls dev $INDEV
  119. echo "---- filter parameters Ingress ----------"
  120. $TC filter ls dev $INDEV parent ffff:
  121.  
  122. echo "---- qdisc parameters Egress  ----------"
  123. $TC qdisc ls $EGDEV
  124. echo "---- Class parameters Egress  ----------"
  125. $TC class ls $EGDEV
  126. echo "---- filter parameters Egress ----------"
  127. $TC filter ls $EGDEV parent 1:0
  128. #
  129. #deleting the ingress qdisc
  130. #$TC qdisc del $INDEV ingress
  131.