Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ## Paths and definitions
- tc=/sbin/tc
- IPT=iptables
- #The interface name of the internet link
- ext=ppp0
- #Ignore this
- ext_ingress=ifb0
- #Autocalculated... why?
- # 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?
- #q=1492
- # Set these as per your adsl sync rate, at 90% to start with, modify up and down until the tests work.
- ext_up=900kbit
- ext_down=16000kbit
- ethtool -K eth0 tso off gro off gso off
- ethtool -K eth1 tso off gro off gso off
- ethtool -K $ext tso off gro off gso off
- modprobe ifb
- modprobe sch_fq_codel
- modprobe act_mirred
- # Clear old queuing disciplines (qdisc) on the interfaces
- $tc qdisc del dev $ext root
- $tc qdisc del dev $ext ingress
- $tc qdisc del dev $ext_ingress root
- $tc qdisc del dev $ext_ingress ingress
- #########
- # INGRESS
- #########
- # Create ingress on external interface
- $tc qdisc add dev $ext handle ffff: ingress
- ifconfig $ext_ingress up # if the interace is not up bad things happen
- # Forward all ingress traffic to the IFB device
- $tc filter add dev $ext parent ffff: protocol all u32 match u32 0 0 action mirred egress redirect dev $ext_ingress
- # Create an EGRESS filter on the IFB device
- #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?
- $tc qdisc add dev $ext_ingress root handle 1: htb default 11 r2q 5
- # Add root class HTB with rate limiting
- #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)
- $tc class add dev $ext_ingress parent 1: classid 1:1 htb rate $ext_down overhead 40 mtu 1492 mpu 53 linklayer atm
- $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
- #This is where fq_codel is installed for downlink traffic
- #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?
- $tc qdisc add dev $ext_ingress parent 1:11 fq_codel noecn target 10ms interval 100ms quantum 1024 flows 1536 limit 800
- #Redoing the hash function for the fair queing part of fq_codel because of NAT.
- #FIXME? Really need to find/have a discussion and determine good values for this
- $tc filter replace dev $ext_ingress prio 1 protocol ip parent 1:11 handle 100 flow hash keys dst divisor 1536 baseclass 1:11
- #########
- # EGRESS
- #########
- # Add FQ_CODEL to EGRESS on external interface
- #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?
- $tc qdisc add dev $ext root handle 1: htb default 13 r2q 1
- # Add root class HTB with rate limiting
- #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)
- $tc class add dev $ext parent 1: classid 1:1 htb rate $ext_up overhead 40 mtu 1492 mpu 53 linklayer atm
- $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
- $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
- $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
- #This is where fq_codel is installed for uplink traffic
- #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?
- $tc qdisc add dev $ext parent 1:11 handle 11: fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
- $tc qdisc add dev $ext parent 1:12 handle 12: fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
- $tc qdisc add dev $ext parent 1:13 fq_codel noecn target 25ms interval 75ms quantum 512 flows 512 limit 300
- $tc filter add dev $ext parent 1:0 protocol ip pref 100 handle 0x11 fw classid 1:0x11
- $tc filter add dev $ext parent 1:0 protocol ip pref 100 handle 0x12 fw classid 1:0x12
- $IPT -t mangle -F
- $IPT -t mangle -X
- $IPT -t mangle -A PREROUTING -s 10.0.0.50/32 -j MARK --set-mark 0x11
- $IPT -t mangle -A PREROUTING -s 10.0.0.51/32 -j MARK --set-mark 0x11
- $IPT -t mangle -A PREROUTING -s 10.0.0.52/32 -j MARK --set-mark 0x11
- $IPT -t mangle -A PREROUTING -m mark --mark 0x11 -j ACCEPT
- $IPT -t mangle -A PREROUTING -s 10.0.0.60/32 -j MARK --set-mark 0x12
- $IPT -t mangle -A PREROUTING -s 10.0.0.61/32 -j MARK --set-mark 0x12
- $IPT -t mangle -A PREROUTING -m mark --mark 0x12 -j ACCEPT
- #Redoing the hash function for the fair queing part of fq_codel because of NAT.
- #FIXME? Really need to find/have a discussion and determine good values for this.
- #$tc filter add dev $ext prio 1 protocol ip parent 1: handle 100 flow hash keys nfct-src,dst divisor 2048 baseclass 1:11
- #$tc filter add dev $ext prio 1 protocol ip parent 1: handle 100 flow hash keys nfct-src,dst divisor 2048 baseclass 1:12
- #$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