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 / afcbq next >
Encoding:
Text File  |  2004-04-15  |  3.4 KB  |  106 lines

  1. #!/usr/bin/perl
  2. #
  3. #
  4. # AF using CBQ for a single interface eth0 
  5. # 4 AF classes using GRED and one BE using RED
  6. # Things you might want to change:
  7. #    - the device bandwidth (set at 10Mbits)
  8. #    - the bandwidth allocated for each AF class and the BE class    
  9. #    - the drop probability associated with each AF virtual queue
  10. #
  11. # AF DSCP values used (based on AF draft 04)
  12. # -----------------------------------------
  13. # AF DSCP values
  14. # AF1 1. 0x0a 2. 0x0c 3. 0x0e
  15. # AF2 1. 0x12 2. 0x14 3. 0x16
  16. # AF3 1. 0x1a 2. 0x1c 3. 0x1e
  17. # AF4 1. 0x22 2. 0x24 3. 0x26
  18.  
  19. #
  20. # A simple DSCP-class relationship formula used to generate
  21. # values in the for loop of this script; $drop stands for the
  22. # DP
  23. #    $dscp = ($class*8+$drop*2)
  24. #
  25. #  if you use GRIO buffer sharing, then GRED priority is set as follows:
  26. #  $gprio=$drop+1; 
  27. #
  28.  
  29. $TC = "/usr/src/iproute2-current/tc/tc";
  30. $DEV = "dev lo";
  31. $DEV = "dev eth1";
  32. $DEV = "dev eth0";
  33. # the BE-class number
  34. $beclass = "5";  
  35.  
  36. #GRIO buffer sharing on or off?
  37. $GRIO = "";
  38. $GRIO = "grio";
  39. # The bandwidth of your device
  40. $linerate="10Mbit";
  41. # The BE and AF rates
  42. %rate_table=();
  43. $berate="1500Kbit";
  44. $rate_table{"AF1rate"}="1500Kbit";
  45. $rate_table{"AF2rate"}="1500Kbit";
  46. $rate_table{"AF3rate"}="1500Kbit";
  47. $rate_table{"AF4rate"}="1500Kbit";
  48. #
  49. #
  50. #
  51. print "\n# --- General setup  ---\n";
  52. print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n";
  53. print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex mask 0xfc " .
  54.    "shift 2 pass_on\n";
  55.    #"shift 2\n";
  56. print "$TC qdisc add $DEV parent 1:0 handle 2:0 cbq bandwidth $linerate ".
  57.   "cell 8 avpkt 1000 mpu 64\n";
  58. print "$TC filter add $DEV parent 2:0 protocol ip prio 1 tcindex ".
  59.   "mask 0xf0 shift 4 pass_on\n";
  60. for $class (1..4) {
  61.     print "\n# --- AF Class $class specific setup---\n";
  62.     $AFrate=sprintf("AF%drate",$class);
  63.     print "$TC class add $DEV parent 2:0 classid 2:$class cbq ".
  64.       "bandwidth $linerate rate $rate_table{$AFrate} avpkt 1000 prio ".
  65.       (6-$class)." bounded allot 1514 weight 1 maxburst 21\n";
  66.     print "$TC filter add $DEV parent 2:0 protocol ip prio 1 handle $class ".
  67.       "tcindex classid 2:$class\n";
  68.     print "$TC qdisc add $DEV parent 2:$class gred setup DPs 3 default 2 ".
  69.       "$GRIO\n";
  70. # per DP setup
  71. #
  72.     for $drop (1..3) {
  73.     print "\n# --- AF Class $class DP $drop---\n";
  74.     $dscp = $class*8+$drop*2;
  75.     $tcindex = sprintf("1%x%x",$class,$drop);
  76.     print "$TC filter add $DEV parent 1:0 protocol ip prio 1 ".
  77.       "handle $dscp tcindex classid 1:$tcindex\n";
  78.     $prob = $drop*0.02;
  79.         if ($GRIO) {
  80.     $gprio = $drop+1;
  81.     print "$TC qdisc change $DEV parent 2:$class gred limit 60KB min 15KB ".
  82.       "max 45KB burst 20 avpkt 1000 bandwidth $linerate DP $drop ".
  83.       "probability $prob ".
  84.           "prio $gprio\n";
  85.         } else {
  86.     print "$TC qdisc change $DEV parent 2:$class gred limit 60KB min 15KB ".
  87.       "max 45KB burst 20 avpkt 1000 bandwidth $linerate DP $drop ".
  88.       "probability $prob \n";
  89.     }
  90.     }
  91. }
  92. #
  93. #
  94. print "\n#------BE Queue setup------\n";
  95. print "$TC filter add $DEV parent 1:0 protocol ip prio 2 ".
  96.           "handle 0 tcindex mask 0 classid 1:1\n";
  97. print "$TC class add $DEV parent 2:0 classid 2:$beclass cbq ".
  98.       "bandwidth $linerate rate $berate avpkt 1000 prio 6 " .
  99.       "bounded allot 1514 weight 1 maxburst 21 \n";
  100. print "$TC filter add $DEV parent 2:0 protocol ip prio 1 handle 0 tcindex ".
  101.   "classid 2:5\n";
  102. print "$TC qdisc add $DEV parent 2:5 red limit 60KB min 15KB max 45KB ".
  103.   "burst 20 avpkt 1000 bandwidth $linerate probability 0.4\n";
  104.