Guest User

Untitled

a guest
May 20th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.74 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ## Paths and definitions
  4. tc=/sbin/tc
  5. IPT=iptables
  6.  
  7. #The interface name of the internet link
  8. ext=ppp0
  9.  
  10. #Ignore this
  11. ext_ingress=ifb0
  12.  
  13. #Autocalculated... why?
  14. # HTB Quantum = 1492bytes IP + 50 pppoe/pppoa overhead FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low?
  15. #q=1492
  16.  
  17. # Set these as per your adsl sync rate, at 90% to start with, modify up and down until the tests work.
  18. ext_up=900kbit
  19. ext_down=16000kbit
  20.  
  21. ethtool -K eth0 tso off gro off gso off
  22. ethtool -K eth1 tso off gro off gso off
  23. ethtool -K $ext tso off gro off gso off
  24.  
  25. modprobe ifb
  26. modprobe sch_fq_codel
  27. modprobe act_mirred
  28.  
  29. # Clear old queuing disciplines (qdisc) on the interfaces
  30. $tc qdisc del dev $ext root
  31. $tc qdisc del dev $ext ingress
  32. $tc qdisc del dev $ext_ingress root
  33. $tc qdisc del dev $ext_ingress ingress
  34.  
  35.  
  36.  
  37. #########
  38. # INGRESS
  39. #########
  40.  
  41. # Create ingress on external interface
  42. $tc qdisc add dev $ext handle ffff: ingress
  43. ifconfig $ext_ingress up # if the interace is not up bad things happen
  44.  
  45. # Forward all ingress traffic to the IFB device
  46. $tc filter add dev $ext parent ffff: protocol all u32 match u32 0 0 action mirred egress redirect dev $ext_ingress
  47.  
  48. # Create an EGRESS filter on the IFB device
  49. #You can play with the r2q value, higher for faster links, lower for slower. FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low?
  50. $tc qdisc add dev $ext_ingress root handle 1: htb default 11 r2q 5
  51.  
  52. # Add root class HTB with rate limiting
  53. #You can play with the overhead values, FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low? With overhead, if it's too low then you'll notice serious problems with Diablo 3 (Really need more testcases, probably any online game)
  54. $tc class add dev $ext_ingress parent 1: classid 1:1 htb rate $ext_down overhead 40 mtu 1492 mpu 53 linklayer atm
  55. $tc class add dev $ext_ingress parent 1:1 classid 1:11 htb rate $ext_down prio 0 overhead 40 mtu 1492 mpu 53 linklayer atm
  56.  
  57. #This is where fq_codel is installed for downlink traffic
  58. #You can play with the target/interval/limit/quantum/flows values. FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low?
  59. $tc qdisc add dev $ext_ingress parent 1:11 fq_codel noecn target 10ms interval 100ms quantum 1024 flows 1536 limit 800
  60.  
  61. #Redoing the hash function for the fair queing part of fq_codel because of NAT.
  62. #FIXME? Really need to find/have a discussion and determine good values for this
  63. $tc filter replace dev $ext_ingress prio 1 protocol ip parent 1:11 handle 100 flow hash keys dst divisor 1536 baseclass 1:11
  64.  
  65.  
  66.  
  67.  
  68. #########
  69. # EGRESS
  70. #########
  71.  
  72. # Add FQ_CODEL to EGRESS on external interface
  73. #You can play with the r2q value, higher for faster links, lower for slower. FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low?
  74. $tc qdisc add dev $ext root handle 1: htb default 13 r2q 1
  75.  
  76. # Add root class HTB with rate limiting
  77. #You can play with the overhead values, FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low? With overhead, if it's too low then you'll notice serious problems with Diablo 3 (Really need more testcases, probably any online game)
  78. $tc class add dev $ext parent 1: classid 1:1 htb rate $ext_up overhead 40 mtu 1492 mpu 53 linklayer atm
  79. $tc class add dev $ext parent 1:1 classid 1:11 htb rate 300kbit ceil $ext_up overhead 40 mtu 1492 mpu 53 linklayer atm
  80. $tc class add dev $ext parent 1:1 classid 1:12 htb rate 300kbit ceil $ext_up overhead 40 mtu 1492 mpu 53 linklayer atm
  81. $tc class add dev $ext parent 1:1 classid 1:13 htb rate 100kbit ceil $ext_up overhead 40 mtu 1492 mpu 53 linklayer atm
  82.  
  83.  
  84. #This is where fq_codel is installed for uplink traffic
  85. #You can play with the target/interval/limit/quantum/flows values. FIXME? Totally need some maths and tables for the correct values in various situations. Is being too high safer than being too low?
  86. $tc qdisc add dev $ext parent 1:11 handle 11: fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
  87. $tc qdisc add dev $ext parent 1:12 handle 12: fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
  88. $tc qdisc add dev $ext parent 1:13 fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
  89.  
  90.  
  91. $tc filter add dev $ext parent 1:0 protocol ip pref 100 handle 0x11 fw classid 1:0x11
  92.  
  93. $tc filter add dev $ext parent 1:0 protocol ip pref 100 handle 0x12 fw classid 1:0x12
  94.  
  95.  
  96. $IPT -t mangle -F
  97. $IPT -t mangle -X
  98. $IPT -t mangle -A PREROUTING -s 10.0.0.50/32 -j MARK --set-mark 0x11
  99. $IPT -t mangle -A PREROUTING -s 10.0.0.51/32 -j MARK --set-mark 0x11
  100. $IPT -t mangle -A PREROUTING -s 10.0.0.52/32 -j MARK --set-mark 0x11
  101. $IPT -t mangle -A PREROUTING -m mark --mark 0x11 -j ACCEPT
  102.  
  103. $IPT -t mangle -A PREROUTING -s 10.0.0.60/32 -j MARK --set-mark 0x12
  104. $IPT -t mangle -A PREROUTING -s 10.0.0.61/32 -j MARK --set-mark 0x12
  105. $IPT -t mangle -A PREROUTING -m mark --mark 0x12 -j ACCEPT
  106.  
  107.  
  108.  
  109. #Redoing the hash function for the fair queing part of fq_codel because of NAT.
  110. #FIXME? Really need to find/have a discussion and determine good values for this.
  111.  
  112. #$tc filter add dev $ext prio 1 protocol ip parent 1: handle 100 flow hash keys nfct-src,dst divisor 2048 baseclass 1:11
  113. #$tc filter add dev $ext prio 1 protocol ip parent 1: handle 100 flow hash keys nfct-src,dst divisor 2048 baseclass 1:12
  114. #$tc filter add dev $ext prio 1 protocol ip parent 1: handle 100 flow hash keys nfct-src,dst divisor 2048 baseclass 1:13
Advertisement
Add Comment
Please, Sign In to add comment