Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. #!/bin/sh
  2. ##QOS_CHECK v1.4 released 02/20/2017
  3. ##Script Tested on ASUS AC-68U, FW380.64_2, using Adaptive QOS with Manual Bandwidth Settings
  4. ##Script Changes Unidentified Packet QOS destination from Default Traffic Container (Category7) into Other Traffic Container
  5. ##Script Changes Minimum Guarenteed Bandwidth per QOS category from 128Kbit each to user defined percentages upload/download.
  6.  
  7. cru a QOS_CHECK "0 0 * * * /jffs/scripts/firewall-start" ## schedules a daily check to see if modifcation is till persistant
  8.  
  9. if [ "$(nvram get qos_enable)" = "1" ] && [ "$(nvram get qos_type)" = "1" ] ; then
  10. logger "Adaptive QOS: Modification Script Started"
  11. sleep 10
  12.  
  13. NetControl_DownBandPercent=5 #Percent of total download speed alloted for QOS catagories, change as desired
  14. VoIP_DownBandPercent=20
  15. Gaming_DownBandPercent=15
  16. Others_DownBandPercent=10 #Note unidentified will be moved here per script default
  17. WebSurfing_DownBandPercent=10
  18. Video_DownBandPercent=30
  19. FileTransfer_DownBandPercent=5
  20. Default_DownBandPercent=5
  21.  
  22. NetControl_UpBandPercent=5 #Percent of total upload speed alloted for QOS catagories, change as desired
  23. VoIP_UpBandPercent=20
  24. Gaming_UpBandPercent=15
  25. Others_UpBandPercent=30 #Note unidentified will be moved here per script default
  26. WebSurfing_UpBandPercent=10
  27. Video_UpBandPercent=10
  28. FileTransfer_UpBandPercent=5
  29. Default_UpBandPercent=5
  30.  
  31.  
  32. ############################### Unidentified Packet Priority ##########################
  33. DestCat="$(tc filter show dev eth0 | grep "mark 0x40000000 0x4000ffff" -B 1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n 1)"
  34. 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.
  35. #NewDestCat="1:13" #Uncomment and change to manually define QOS traffic container for unidentified traffic instead of routing to "Others" category container.
  36.  
  37. if [ "${DestCat}" = "1:17" ] ; then
  38. logger "Adaptive QOS: Changing default priority for Unidentified Traffic"
  39. tc filter del dev eth0 parent 1: handle 813::800 prio 1 protocol all u32
  40. tc filter replace dev eth0 protocol all prio 1 handle 813::800 u32 match mark 0x40000000 0x4000ffff flowid ${NewDestCat}
  41. tc filter del dev br0 parent 1: handle 813::800 prio 1 protocol all u32
  42. tc filter replace dev br0 protocol all prio 1 handle 813::800 u32 match mark 0x80000000 0x8000ffff flowid ${NewDestCat}
  43. else
  44. logger "Adaptive QOS: No change required for Unidentified Traffic priority"
  45. fi
  46.  
  47. ######################## Minimum Guarenteed Class Bandwidth ##########################
  48.  
  49. Cat0DownBandPercent=${NetControl_DownBandPercent}
  50. Cat7DownBandPercent=${Default_DownBandPercent}
  51. Cat0UpBandPercent=${NetControl_UpBandPercent}
  52. Cat7UpBandPercent=${Default_UpBandPercent}
  53.  
  54. while read -r line;
  55. do
  56. flowid="$( echo -n ${line} | sed -n -e 's/.*flowid //p' | tail -c 1)"
  57. if [ "${flowid}" != "" ] ; then
  58. read line
  59. mark="$(echo ${line} | sed -n -e 's/.*mark \([a-zA-z0-9]*\).*/\1/p')"
  60.  
  61. if [ "${mark}" = "0x80060000" ] ; then #VOIP
  62. eval "Cat${flowid}DownBandPercent=${VoIP_DownBandPercent}"
  63. eval "Cat${flowid}UpBandPercent=${VoIP_UpBandPercent}"
  64. fi
  65.  
  66. if [ "${mark}" = "0x80080000" ] ; then #Gaming
  67. eval "Cat${flowid}DownBandPercent=${Gaming_DownBandPercent}"
  68. eval "Cat${flowid}UpBandPercent=${Gaming_UpBandPercent}"
  69. fi
  70.  
  71. if [ "${mark}" = "0x800a0000" ] ; then #Others
  72. eval "Cat${flowid}DownBandPercent=${Others_DownBandPercent}"
  73. eval "Cat${flowid}UpBandPercent=${Others_UpBandPercent}"
  74. fi
  75.  
  76. if [ "${mark}" = "0x800d0000" ] ; then #Web Surfing
  77. eval "Cat${flowid}DownBandPercent=${WebSurfing_DownBandPercent}"
  78. eval "Cat${flowid}UpBandPercent=${WebSurfing_UpBandPercent}"
  79. fi
  80.  
  81. if [ "${mark}" = "0x80040000" ] ; then #Video Streaming
  82. eval "Cat${flowid}DownBandPercent=${Video_DownBandPercent}"
  83. eval "Cat${flowid}UpBandPercent=${Video_UpBandPercent}"
  84. fi
  85.  
  86. if [ "${mark}" = "0x80030000" ] ; then #File Downloads
  87. eval "Cat${flowid}DownBandPercent=${FileTransfer_DownBandPercent}"
  88. eval "Cat${flowid}UpBandPercent=${FileTransfer_UpBandPercent}"
  89. fi
  90. fi
  91. done <<EOF
  92. $(tc filter show dev br0 | grep -o "flowid.*" -A1 | sed '/^--$/d')
  93. EOF
  94.  
  95. DownRate1="$(tc class show dev br0 | grep -w "1:11" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  96.  
  97. DownCeil="$(printf "%.0f" $(nvram get qos_ibw))"
  98. DownBurst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
  99. DownCburst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
  100.  
  101. UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
  102. UpBurst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
  103. UpCburst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
  104.  
  105. NewDownRate0="$(expr ${DownCeil} \* ${Cat0DownBandPercent} / 100)"Kbit
  106. NewDownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"Kbit
  107. NewDownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"Kbit
  108. NewDownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"Kbit
  109. NewDownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"Kbit
  110. NewDownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"Kbit
  111. NewDownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"Kbit
  112. NewDownRate7="$(expr ${DownCeil} \* ${Cat7DownBandPercent} / 100)"Kbit
  113.  
  114. NewUpRate0="$(expr ${UpCeil} \* ${Cat0UpBandPercent} / 100)"Kbit
  115. NewUpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"Kbit
  116. NewUpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"Kbit
  117. NewUpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"Kbit
  118. NewUpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"Kbit
  119. NewUpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"Kbit
  120. NewUpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"Kbit
  121. NewUpRate7="$(expr ${UpCeil} \* ${Cat7UpBandPercent} / 100)"Kbit
  122.  
  123.  
  124.  
  125. if [ "${DownRate1}" != "${NewDownRate1}" ] ; then
  126. logger "Adaptive QOS: Changing default minimum guaranteed bandwidth for QOS categories"
  127. tc class change dev br0 parent 1:1 classid 1:10 htb prio 0 rate ${NewDownRate0} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  128. tc class change dev br0 parent 1:1 classid 1:11 htb prio 1 rate ${NewDownRate1} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  129. tc class change dev br0 parent 1:1 classid 1:12 htb prio 2 rate ${NewDownRate2} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  130. tc class change dev br0 parent 1:1 classid 1:13 htb prio 3 rate ${NewDownRate3} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  131. tc class change dev br0 parent 1:1 classid 1:14 htb prio 4 rate ${NewDownRate4} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  132. tc class change dev br0 parent 1:1 classid 1:15 htb prio 5 rate ${NewDownRate5} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  133. tc class change dev br0 parent 1:1 classid 1:16 htb prio 6 rate ${NewDownRate6} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  134. tc class change dev br0 parent 1:1 classid 1:17 htb prio 7 rate ${NewDownRate7} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  135. tc class change dev eth0 parent 1:1 classid 1:10 htb prio 0 rate ${NewUpRate0} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  136. tc class change dev eth0 parent 1:1 classid 1:11 htb prio 1 rate ${NewUpRate1} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  137. tc class change dev eth0 parent 1:1 classid 1:12 htb prio 2 rate ${NewUpRate2} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  138. tc class change dev eth0 parent 1:1 classid 1:13 htb prio 3 rate ${NewUpRate3} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  139. tc class change dev eth0 parent 1:1 classid 1:14 htb prio 4 rate ${NewUpRate4} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  140. tc class change dev eth0 parent 1:1 classid 1:15 htb prio 5 rate ${NewUpRate5} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  141. tc class change dev eth0 parent 1:1 classid 1:16 htb prio 6 rate ${NewUpRate6} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  142. tc class change dev eth0 parent 1:1 classid 1:17 htb prio 7 rate ${NewUpRate7} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  143. else
  144. logger "Adaptive QOS: No change required for QOS categories guaranteed bandwidth"
  145. fi
  146. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement