找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3636|回复: 0

[限速] PPPOE限速脚本

[复制链接]
发表于 2008-11-6 23:19:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
###### 用户为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"只是作为临时数据存放,也便于观察程序运行状态。)
#/queue  type
#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 [/queue type get [/queue type find name="PCQ-Upload"] pcq-rate]
:set RxCurSet [/queue type get [/queue type find name="PCQ-Download"] 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 [/queue simple find limit-at=512000/1000000] 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 [/queue simple find limit-at=128000/256000] 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 [/queue simple find limit-at=512000/1000000] 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 [/queue simple find limit-at=128000/256000] 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 [/queue simple find limit-at=512000/1000000 priority=8] 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 [/queue simple find limit-at=128000/256000 priority=8] 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 大小反了程序无法运行 ###
routeros
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-17 12:58 , Processed in 0.048836 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表