Last active
August 29, 2015 14:09
-
-
Save aojea/4f94998ac002446cbc30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
# | |
# License GPLv2 | |
# Version 0.1 | |
# Original script from http://wiki.openwrt.org/doc/howto/packet.scheduler/packet.scheduler.example4 | |
# Modified for control in LAN interface too | |
START=99 | |
EXTRA_COMMANDS="status" | |
############################################################## | |
# Variables | |
IF_WAN="eth0.2" #-- wan interface | |
IF_LAN="br-lan" #-- lan interface | |
WAN_NET="192.168.2.0/24" #-- wan local subnet | |
UP_RATE=1900 #-- 90% of internet upload bandwidth in kilobits/sec | |
DOWN_RATE=19000 #-- 90% of internet download bandwidth in kilobits/sec | |
PHY_RATE=90 #-- 90% of wan phy bandwidth in megabits/sec | |
TC=/usr/sbin/tc #-- location of traffic control | |
MODULES='sch_hfsc sch_ingress sch_fq_codel cls_flow cls_u32' | |
############################################################## | |
status() { | |
echo "### Statistics ###" | |
echo "# qdiscs #" | |
tc -s qdisc show dev $IF_WAN | |
tc -s qdisc show dev $IF_LAN | |
echo "# class #" | |
tc -s class show dev $IF_WAN | |
tc -s class show dev $IF_LAN | |
echo "# filter #" | |
tc -s filter show dev $IF_WAN root | |
tc -s filter show dev $IF_WAN parent 1: | |
tc -s filter show dev $IF_WAN parent 11: | |
tc -s filter show dev $IF_LAN root | |
tc -s filter show dev $IF_LAN parent 1: | |
tc -s filter show dev $IF_LAN parent 11: | |
} | |
############################################################## | |
############################################################## | |
stop() { | |
# Delete existing qdiscs (hide errors) | |
$TC qdisc del dev $IF_WAN root 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_WAN ingress 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_LAN root 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_LAN ingress 2> /dev/null > /dev/null | |
# Unload modules | |
for i in $MODULES ; do | |
rmmod $i | |
done | |
} | |
############################################################## | |
############################################################################### | |
start() { | |
# Load modules | |
for i in $MODULES ; do | |
insmod $i | |
done | |
# Modify the queues length | |
ifconfig $IF_WAN txqueuelen 1000 | |
ifconfig $IF_LAN txqueuelen 1000 | |
# reset qdiscs | |
$TC qdisc del dev $IF_WAN root 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_WAN ingress 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_LAN root 2> /dev/null > /dev/null | |
$TC qdisc del dev $IF_LAN ingress 2> /dev/null > /dev/null | |
##################### WAN SIDE ############################################## | |
$TC qdisc add dev $IF_WAN root handle 1 hfsc default 1 | |
$TC class add dev $IF_WAN parent 1: classid 1:1 hfsc sc rate ${UP_RATE}kbit ul rate ${UP_RATE}kbit | |
$TC qdisc add dev $IF_WAN parent 1:1 handle 11: fq_codel | |
$TC filter add dev $IF_WAN parent 11: handle 11 protocol all flow hash keys nfct-src divisor 1024 | |
$TC class add dev $IF_WAN parent 1: classid 1:2 hfsc sc rate ${PHY_RATE}mbit ul rate ${PHY_RATE}mbit | |
$TC filter add dev $IF_WAN parent 1: protocol ip prio 1 u32 match ip dst ${WAN_NET} flowid 1:2 | |
$TC filter add dev $IF_WAN parent 1: protocol arp prio 2 u32 match u32 0 0 flow id 1:2 | |
##################### LAN SIDE ############################################## | |
$TC qdisc add dev $IF_LAN root handle 1 hfsc default 1 | |
$TC class add dev $IF_LAN parent 1: classid 1:1 hfsc sc rate ${DOWN_RATE}kbit ul rate ${DOWN_RATE}kbit | |
$TC qdisc add dev $IF_LAN parent 1:1 handle 11: fq_codel | |
$TC filter add dev $IF_LAN parent 11: handle 11 protocol all flow hash keys nfct-src divisor 1024 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment