Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.48 KB | None | 0 0
  1. #!/bin/sh
  2. ##Script Tested on ASUS AC-68U, FW380.64_2, using Adaptive QOS with Manual Bandwidth Settings
  3. ##Script Changes Unidentified Packet QOS destination from Default Traffic Container (Category7) into Other Traffic Container
  4. ##Script Changes Minimum Guarenteed Bandwidth per QOS category from 128Kbit each to user defined percentages upload/download.
  5. echo "Adaptive QOS: Modification Script Started"
  6.  
  7. Cat0DownBandPercent=5 #Percent of download speed for QOS catagories, change as desired
  8. Cat1DownBandPercent=20
  9. Cat2DownBandPercent=15
  10. Cat3DownBandPercent=10
  11. Cat4DownBandPercent=10
  12. Cat5DownBandPercent=30
  13. Cat6DownBandPercent=5
  14. Cat7DownBandPercent=5
  15.  
  16. Cat0UpBandPercent=5 #Percent of upload speed for QOS catagories, change as desired
  17. Cat1UpBandPercent=20
  18. Cat2UpBandPercent=15
  19. Cat3UpBandPercent=30
  20. Cat4UpBandPercent=10
  21. Cat5UpBandPercent=10
  22. Cat6UpBandPercent=5
  23. Cat7UpBandPercent=5
  24.  
  25. ############################### Unidentified Packet Priority ##########################
  26. DownloadPrio="$(tc filter show dev br0 | grep "mark 0x80000000 0x8000ffff" -B 1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n 1)"
  27. UploadPrio="$(tc filter show dev eth0 | grep "mark 0x40000000 0x4000ffff" -B 1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n 1)"
  28. NewDestCat="$(tc filter show dev eth0 | grep "mark 0x400a" -B1 | tr ' ' '\n' | grep "flowid" -A1 | tail -n1)" #Identifies current priority of the "Others" Traffic Container. Result used to route unclassifed traffic into same container.
  29. #NewDestCat="1:13" #Uncomment and change to manually define QOS traffic container for unidentified traffic instead of routing to currently set "Others" category
  30. ChangePrioReq=0
  31.  
  32. if [ "${DownloadPrio}" = "1:17" ] ; then
  33. ChangePrioReq=1
  34. tc filter del dev br0 parent 1: handle 813::800 prio 1 protocol all u32
  35. tc filter replace dev br0 protocol all prio 1 handle 813::800 u32 match mark 0x80000000 0x8000ffff flowid ${NewDestCat}
  36. fi
  37.  
  38. if [ "${UploadPrio}" = "1:17" ] ; then
  39. ChangePrioReq=1
  40. tc filter del dev eth0 parent 1: handle 813::800 prio 1 protocol all u32
  41. tc filter replace dev eth0 protocol all prio 1 handle 813::800 u32 match mark 0x40000000 0x4000ffff flowid ${NewDestCat}
  42. fi
  43.  
  44. if [ "${ChangePrioReq}" = "1" ] ; then
  45. echo "Adaptive QOS: Changing default priority for Unidentified Traffic"
  46. else
  47. echo "Adaptive QOS: No priority change required for Unidentified Traffic"
  48. fi
  49.  
  50. ######################## Minimum Guarenteed Class Bandwitdh ##########################
  51. DownCeil="$(tc class show dev br0 | grep -w "1:1 root" | tr ' ' '\n' | grep "ceil" -A1 | tail -n1 | tr -d 'Kbit')"
  52. DownBurst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
  53. DownCburst="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
  54. DownRate0="$(tc class show dev br0 | grep -w "1:10" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  55. DownRate1="$(tc class show dev br0 | grep -w "1:11" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  56. DownRate2="$(tc class show dev br0 | grep -w "1:12" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  57. DownRate3="$(tc class show dev br0 | grep -w "1:13" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  58. DownRate4="$(tc class show dev br0 | grep -w "1:14" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  59. DownRate5="$(tc class show dev br0 | grep -w "1:15" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  60. DownRate6="$(tc class show dev br0 | grep -w "1:16" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  61. DownRate7="$(tc class show dev br0 | grep -w "1:17" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  62. NewDownRate0="$(expr ${DownCeil} \* ${Cat0DownBandPercent} / 100)"Kbit
  63. NewDownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"Kbit
  64. NewDownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"Kbit
  65. NewDownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"Kbit
  66. NewDownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"Kbit
  67. NewDownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"Kbit
  68. NewDownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"Kbit
  69. NewDownRate7="$(expr ${DownCeil} \* ${Cat7DownBandPercent} / 100)"Kbit
  70.  
  71. UpCeil="$(tc class show dev eth0 | grep -w "1:1 root" | tr ' ' '\n' | grep "ceil" -A1 | tail -n1 | tr -d 'Kbit')"
  72. UpBurst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "burst" -A1 | tail -n1)"
  73. UpCburst="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep -w "cburst" -A1 | tail -n1)"
  74. UpRate0="$(tc class show dev eth0 | grep -w "1:10" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  75. UpRate1="$(tc class show dev eth0 | grep -w "1:11" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  76. UpRate2="$(tc class show dev eth0 | grep -w "1:12" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  77. UpRate3="$(tc class show dev eth0 | grep -w "1:13" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  78. UpRate4="$(tc class show dev eth0 | grep -w "1:14" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  79. UpRate5="$(tc class show dev eth0 | grep -w "1:15" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  80. UpRate6="$(tc class show dev eth0 | grep -w "1:16" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  81. UpRate7="$(tc class show dev eth0 | grep -w "1:17" | tr ' ' '\n' | grep "rate" -A1 | tail -n 1)"
  82. NewUpRate0="$(expr ${UpCeil} \* ${Cat0UpBandPercent} / 100)"Kbit
  83. NewUpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"Kbit
  84. NewUpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"Kbit
  85. NewUpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"Kbit
  86. NewUpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"Kbit
  87. NewUpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"Kbit
  88. NewUpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"Kbit
  89. NewUpRate7="$(expr ${UpCeil} \* ${Cat7UpBandPercent} / 100)"Kbit
  90.  
  91. ChangeRateReq=0
  92.  
  93. if [ "${DownRate0}" != "${NewDownRate0}" ] ; then
  94. tc class change dev br0 parent 1:1 classid 1:10 htb prio 0 rate ${NewDownRate0} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  95. ChangeRateReq=1
  96. fi
  97.  
  98. if [ "${DownRate1}" != "${NewDownRate1}" ] ; then
  99. tc class change dev br0 parent 1:1 classid 1:11 htb prio 1 rate ${NewDownRate1} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  100. ChangeRateReq=1
  101. fi
  102.  
  103. if [ "${DownRate2}" != "${NewDownRate2}" ] ; then
  104. tc class change dev br0 parent 1:1 classid 1:12 htb prio 2 rate ${NewDownRate2} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  105. ChangeRateReq=1
  106. fi
  107.  
  108. if [ "${DownRate3}" != "${NewDownRate3}" ] ; then
  109. tc class change dev br0 parent 1:1 classid 1:13 htb prio 3 rate ${NewDownRate3} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  110. ChangeRateReq=1
  111. fi
  112.  
  113. if [ "${DownRate4}" != "${NewDownRate4}" ] ; then
  114. tc class change dev br0 parent 1:1 classid 1:14 htb prio 4 rate ${NewDownRate4} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  115. ChangeRateReq=1
  116. fi
  117.  
  118. if [ "${DownRate5}" != "${NewDownRate5}" ] ; then
  119. tc class change dev br0 parent 1:1 classid 1:15 htb prio 5 rate ${NewDownRate5} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  120. ChangeRateReq=1
  121. fi
  122.  
  123. if [ "${DownRate6}" != "${NewDownRate6}" ] ; then
  124. tc class change dev br0 parent 1:1 classid 1:16 htb prio 6 rate ${NewDownRate6} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  125. ChangeRateReq=1
  126. fi
  127.  
  128. if [ "${DownRate7}" != "${NewDownRate7}" ] ; then
  129. tc class change dev br0 parent 1:1 classid 1:17 htb prio 7 rate ${NewDownRate7} ceil ${DownCeil}Kbit burst ${DownBurst} cburst ${DownCburst}
  130. ChangeRateReq=1
  131. fi
  132.  
  133. if [ "${UpRate0}" != "${NewUpRate0}" ] ; then
  134. tc class change dev eth0 parent 1:1 classid 1:10 htb prio 0 rate ${NewUpRate0} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  135. ChangeRateReq=1
  136. fi
  137.  
  138. if [ "${UpRate1}" != "${NewUpRate1}" ] ; then
  139. tc class change dev eth0 parent 1:1 classid 1:11 htb prio 1 rate ${NewUpRate1} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  140. ChangeRateReq=1
  141. fi
  142.  
  143. if [ "${UpRate2}" != "${NewUpRate2}" ] ; then
  144. tc class change dev eth0 parent 1:1 classid 1:12 htb prio 2 rate ${NewUpRate2} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  145. ChangeRateReq=1
  146. fi
  147.  
  148. if [ "${UpRate3}" != "${NewUpRate3}" ] ; then
  149. tc class change dev eth0 parent 1:1 classid 1:13 htb prio 3 rate ${NewUpRate3} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  150. ChangeRateReq=1
  151. fi
  152.  
  153. if [ "${UpRate4}" != "${NewUpRate4}" ] ; then
  154. tc class change dev eth0 parent 1:1 classid 1:14 htb prio 4 rate ${NewUpRate4} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  155. ChangeRateReq=1
  156. fi
  157.  
  158. if [ "${UpRate5}" != "${NewUpRate5}" ] ; then
  159. tc class change dev eth0 parent 1:1 classid 1:15 htb prio 5 rate ${NewUpRate5} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  160. ChangeRateReq=1
  161. fi
  162.  
  163. if [ "${UpRate6}" != "${NewUpRate6}" ] ; then
  164. tc class change dev eth0 parent 1:1 classid 1:16 htb prio 6 rate ${NewUpRate6} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  165. ChangeRateReq=1
  166. fi
  167.  
  168. if [ "${UpRate7}" != "${NewUpRate7}" ] ; then
  169. tc class change dev eth0 parent 1:1 classid 1:17 htb prio 7 rate ${NewUpRate7} ceil ${UpCeil}Kbit burst ${UpBurst} cburst ${UpCburst}
  170. ChangeRateReq=1
  171. fi
  172.  
  173. if [ "${ChangeRateReq}" = "1" ] ; then
  174. echo "Adaptive QOS: Changing default minimum guaranteed bandwidth for QOS categories"
  175. else
  176. echo "Adaptive QOS: No guaranteed bandwidth change required for QOS categories"
  177. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement