Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ##QOS_CHECK v1.4 released 02/20/2017
- ##Script Tested on ASUS AC-68U, FW380.64_2, using Adaptive QOS with Manual Bandwidth Settings
- ##Script Changes Unidentified Packet QOS destination from Default Traffic Container (Category7) into Other Traffic Container
- ##Script Changes Minimum Guarenteed Bandwidth per QOS category from 128Kbit each to user defined percentages upload/download.
- cru a QOS_CHECK "0 0 * * * /jffs/scripts/firewall-start" ## schedules a daily check to see if modifcation is till persistant
- if [ "$(nvram get qos_enable)" = "1" ] && [ "$(nvram get qos_type)" = "1" ] ; then
- logger "Adaptive QOS: Modification Script Started"
- sleep 10
- NetControl_DownBandPercent=5 #Percent of total download speed alloted for QOS catagories, change as desired
- VoIP_DownBandPercent=20
- Gaming_DownBandPercent=15
- Others_DownBandPercent=10 #Note unidentified will be moved here per script default
- WebSurfing_DownBandPercent=10
- Video_DownBandPercent=30
- FileTransfer_DownBandPercent=5
- Default_DownBandPercent=5
- NetControl_UpBandPercent=5 #Percent of total upload speed alloted for QOS catagories, change as desired
- VoIP_UpBandPercent=20
- Gaming_UpBandPercent=15
- Others_UpBandPercent=30 #Note unidentified will be moved here per script default
- WebSurfing_UpBandPercent=10
- Video_UpBandPercent=10
- FileTransfer_UpBandPercent=5
- Default_UpBandPercent=5
- ############################### Unidentified Packet Priority ##########################
- DestCat="$(tc filter show dev eth0 | grep "mark 0x40000000 0x4000ffff" -B 1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n 1)"
- NewDestCat="$(tc filter show dev eth0 | grep "mark 0x400a" -B1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n1)" #Identifies current catagory of the "Others" Traffic Container. Result used to route unclassifed traffic into catagory of "Others" container.
- #NewDestCat="1:13" #Uncomment and change to manually define QOS traffic container for unidentified traffic instead of routing to "Others" category container.
- if [ "${DestCat}" = "1:17" ] ; then
- logger "Adaptive QOS: Changing default priority for Unidentified Traffic"
- tc filter del dev eth0 parent 1: handle 813::800 prio 1 protocol all u32
- tc filter replace dev eth0 protocol all prio 1 handle 813::800 u32 match mark 0x40000000 0x4000ffff flowid ${NewDestCat}
- tc filter del dev br0 parent 1: handle 813::800 prio 1 protocol all u32
- tc filter replace dev br0 protocol all prio 1 handle 813::800 u32 match mark 0x80000000 0x8000ffff flowid ${NewDestCat}
- else
- logger "Adaptive QOS: No change required for Unidentified Traffic priority"
- fi
- ######################## Minimum Guarenteed Class Bandwidth ##########################
- Cat0DownBandPercent=${NetControl_DownBandPercent}
- Cat7DownBandPercent=${Default_DownBandPercent}
- Cat0UpBandPercent=${NetControl_UpBandPercent}
- Cat7UpBandPercent=${Default_UpBandPercent}
- while read -r line;
- do
- flowid="$( echo -n ${line} | sed -n -e 's/.*flowid //p' | tail -c 1)"
- if [ "${flowid}" != "" ] ; then
- read line
- mark="$(echo ${line} | sed -n -e 's/.*mark \([a-zA-z0-9]*\).*/\1/p')"
- if [ "${mark}" = "0x80060000" ] ; then #VOIP
- eval "Cat${flowid}DownBandPercent=${VoIP_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${VoIP_UpBandPercent}"
- fi
- if [ "${mark}" = "0x80080000" ] ; then #Gaming
- eval "Cat${flowid}DownBandPercent=${Gaming_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${Gaming_UpBandPercent}"
- fi
- if [ "${mark}" = "0x800a0000" ] ; then #Others
- eval "Cat${flowid}DownBandPercent=${Others_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${Others_UpBandPercent}"
- fi
- if [ "${mark}" = "0x800d0000" ] ; then #Web Surfing
- eval "Cat${flowid}DownBandPercent=${WebSurfing_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${WebSurfing_UpBandPercent}"
- fi
- if [ "${mark}" = "0x80040000" ] ; then #Video Streaming
- eval "Cat${flowid}DownBandPercent=${Video_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${Video_UpBandPercent}"
- fi
- if [ "${mark}" = "0x80030000" ] ; then #File Downloads
- eval "Cat${flowid}DownBandPercent=${FileTransfer_DownBandPercent}"
- eval "Cat${flowid}UpBandPercent=${FileTransfer_UpBandPercent}"
- fi
- fi
- done <<EOF
- $(tc filter show dev br0 | grep -o "flowid.*" -A1 | sed '/^--$/d')
- EOF
- DownRate1="$(tc class show dev br0 | grep -w "1:11" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
- DownCeil="$(printf "%.0f" $(nvram get qos_ibw))"
- DownBurst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
- DownCburst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
- UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
- UpBurst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
- UpCburst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
- NewDownRate0="$(expr ${DownCeil} \* ${Cat0DownBandPercent} / 100)"Kbit
- NewDownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"Kbit
- NewDownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"Kbit
- NewDownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"Kbit
- NewDownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"Kbit
- NewDownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"Kbit
- NewDownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"Kbit
- NewDownRate7="$(expr ${DownCeil} \* ${Cat7DownBandPercent} / 100)"Kbit
- NewUpRate0="$(expr ${UpCeil} \* ${Cat0UpBandPercent} / 100)"Kbit
- NewUpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"Kbit
- NewUpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"Kbit
- NewUpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"Kbit
- NewUpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"Kbit
- NewUpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"Kbit
- NewUpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"Kbit
- NewUpRate7="$(expr ${UpCeil} \* ${Cat7UpBandPercent} / 100)"Kbit
- if [ "${DownRate1}" != "${NewDownRate1}" ] ; then
- logger "Adaptive QOS: Changing default minimum guaranteed bandwidth for QOS categories"
- tc class change dev br0 parent 1:1 classid 1:10 htb prio 0 rate ${NewDownRate0} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:11 htb prio 1 rate ${NewDownRate1} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:12 htb prio 2 rate ${NewDownRate2} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:13 htb prio 3 rate ${NewDownRate3} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:14 htb prio 4 rate ${NewDownRate4} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:15 htb prio 5 rate ${NewDownRate5} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:16 htb prio 6 rate ${NewDownRate6} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev br0 parent 1:1 classid 1:17 htb prio 7 rate ${NewDownRate7} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
- tc class change dev eth0 parent 1:1 classid 1:10 htb prio 0 rate ${NewUpRate0} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:11 htb prio 1 rate ${NewUpRate1} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:12 htb prio 2 rate ${NewUpRate2} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:13 htb prio 3 rate ${NewUpRate3} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:14 htb prio 4 rate ${NewUpRate4} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:15 htb prio 5 rate ${NewUpRate5} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:16 htb prio 6 rate ${NewUpRate6} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- tc class change dev eth0 parent 1:1 classid 1:17 htb prio 7 rate ${NewUpRate7} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
- else
- logger "Adaptive QOS: No change required for QOS categories guaranteed bandwidth"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement