cyso 发表于 2008-11-6 23:19:26

PPPOE限速脚本

###### 用户为PPPOE方式上网,RADIUS设速率为:512K/1M 其中免费组为128K/256K#######
###### 脚本目地是想在空闲时间 让用户有更大速率,充分利用带宽####
#定义变量
:local RxCurRate 0
:local RxCurRate1 0
:local RxCurRate2 0
:local RxCurRate3 0
:local RxCurSet 0
:local TxCurSet 0

#4次平均下行即时流量(总出口为40M)
interface monitor ydwan once do={:set RxCurRate $received-bits-per-second}
#interface monitor ydwan once do={:set RxCurRate $sent-bits-per-second}
:delay 3
interface monitor ydwan once do={:set RxCurRate1 $received-bits-per-second}
:delay 3
interface monitor ydwan once do={:set RxCurRate2 $received-bits-per-second}
:delay 3
interface monitor ydwan once do={:set RxCurRate3 $received-bits-per-second}
:set RxCurRate (($RxCurRate+$RxCurRate1+$RxCurRate2+$RxCurRate3)/4)

#步进长度,以32M为基准,大于32M取决对值。(留些用户突发空间)
:set RxCurRate1 (32-($RxCurRate/1000000))
:if($RxCurRate1<0) do={:set RxCurRate1 ($RxCurRate1+-($RxCurRate1*2))}
:set RxCurRate1 (($RxCurRate1+-1)*100000)


#下行当前设置("PCQ-Download"只是作为临时数据存放,也便于观察程序运行状态。)
#/queuetype
#add name="PCQ-Download" kind=pcq pcq-rate=3500000 pcq-limit=50 pcq-classifier=dst-address pcq-total-limit=2000
#add name="PCQ-Upload" kind=pcq pcq-rate=200000 pcq-limit=50 pcq-classifier=src-address pcq-total-limit=2000

#:set TxCurSet pcq-rate]
:set RxCurSet pcq-rate]
# 如果流量太大,应该快速减少用户速率。
#:if($RxCurRate>36000000&&$RxCurSet>2000000) do={:set RxCurSet 2000000}
:set TxCurSet (($RxCurSet+0)/2)

# 下行 加大限制带宽(我的总带宽40M,用户最多可达8M速率)
:if($RxCurRate<30000000&&$RxCurSet<8000000) do={
# 步进长度动态决定
:set RxCurSet ($RxCurSet+$RxCurRate1)
:if($RxCurSet>8000000) do={:set RxCurSet 8000000}
:set TxCurSet (($RxCurSet+0)/2)
#上传不能太大
:if($TxCurSet>2000000) do={:set TxCurSet 2000000}
## limit-at=512000/1000000和limit-at=128000/256000是PPPOE用户首次登录时的默认值
/queue simple set max-limit=($TxCurSet . "/" . $RxCurSet) priority=6 burst-limit=(($TxCurSet*2) . "/" . ($RxCurSet*2)) burst-threshold=(($TxCurSet/4) . "/" . ($RxCurSet/4)) burst-time=5s/10s
/queue simple set max-limit=(($TxCurSet/4) . "/" . ($RxCurSet/4)) priority=7 burst-limit=(($TxCurSet/2) . "/" . ($RxCurSet/2)) burst-threshold=(($TxCurSet/16) . "/" . ($RxCurSet/16)) burst-time=5s/10s
/queue type set "PCQ-Download" kind=pcq pcq-rate=$RxCurSet pcq-classifier=dst-address
/queue type set "PCQ-Upload" kind=pcq pcq-rate=$RxCurRate1 pcq-classifier=src-address
}

# 下行 减少限制带宽
:if($RxCurRate>34000000&&$RxCurSet>1100000) do={
#步进长度动态决定
:set RxCurSet ($RxCurSet+-$RxCurRate1)
:if($RxCurSet<1100000) do={:set RxCurSet 1100000}
:set TxCurSet (($RxCurSet+0)/2)
:if($TxCurSet>2000000) do={:set TxCurSet 2000000}
/queue simple set max-limit=($TxCurSet . "/" . $RxCurSet) priority=6 burst-limit=(($TxCurSet*2) . "/" . ($RxCurSet*2)) burst-threshold=(($TxCurSet/4) . "/" . ($RxCurSet/4)) burst-time=5s/10s
/queue simple set max-limit=(($TxCurSet/4) . "/" . ($RxCurSet/4)) priority=7 burst-limit=(($TxCurSet/2) . "/" . ($RxCurSet/2)) burst-threshold=(($TxCurSet/16) . "/" . ($RxCurSet/16)) burst-time=5s/10s
/queue type set "PCQ-Download" kind=pcq pcq-rate=$RxCurSet pcq-classifier=dst-address
/queue type set "PCQ-Upload" kind=pcq pcq-rate=$RxCurRate1 pcq-classifier=src-address
}

#上面两个条件运行其中的一个后下面不会起作用,因为已没了priority=8的队列,
#下面的只是在上面两条件都没成立时,为新上线用户加入到统一队列中来。
/queue simple set max-limit=($TxCurSet . "/" . $RxCurSet) priority=6 burst-limit=(($TxCurSet*2) . "/" . ($RxCurSet*2)) burst-threshold=(($TxCurSet/4) . "/" . ($RxCurSet/4)) burst-time=5s/10s
/queue simple set max-limit=(($TxCurSet/4) . "/" . ($RxCurSet/4)) priority=7 burst-limit=(($TxCurSet/2) . "/" . ($RxCurSet/2)) burst-threshold=(($TxCurSet/16) . "/" . ($RxCurSet/16)) burst-time=5s/10s

#######      此脚本我设定为一分钟运行一次。总流量一直在30M到38M间运行。开网页很好。    完#####################
###记得速率参数大少顺序:burst-limit>max-limit>limit-at>burst-threshold 大小反了程序无法运行 ###
页: [1]
查看完整版本: PPPOE限速脚本