找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 83411|回复: 101

[脚本] 多ADSL负载--掉线后自动修改pcc/nth参数 保证网络畅通[修正版]

  [复制链接]
发表于 2011-2-24 02:36:12 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 zooyo 于 2011-3-21 22:15 编辑

很多朋友提出了这个问题,假如有4条ADSL跑PCC负载,掉了其中一条后网络就会出现问题,网页打不开或者很慢等等,这是由于PCC参数不匹配造成的。针对这样的情况WGHBOY兄已经发过一脚本,今天应一个朋友的需要测试后发现该脚本判断不太准确,呵呵。遂花了点时间重新编写达到所要目的。

以4线为例,其中某条线路断了后,会自动判断剩余可用的线路数量然后修改PCC规则的参数,线路恢复正常后会自动把参数修改回正常状态,注意连接标记名称一定要以纯数字“1、2、3、4...”来命名。一般该脚本设置30秒间隔就比较合适。

 
 
 
1.jpg
 
 
 
 
 

 
2.jpg
 
 
 
 
 
 

3.jpg
 
 
 
 
 

 
4.jpg
 
 
 
 
 
 

5.jpg


PCC:

{
:local status
:local i "5"
:local x "0"
:local y "0"
:local z "0"
:set x [:len [/interface pppoe-client find running=yes]]
:if ($x<$i) do={
:for ii from=1 to=$i do={
:set status [/interface get [find name=("pppoe-out".$ii)] running]
:if ($status=true) do={
/ip fir man set [find new-connection-mark=$ii] per-connection-classifier=("both-addresses:".$x."/".$y) disable=no;:set y ($y+1)} else={
/ip fir man set [find new-connection-mark=$ii] disable=yes}}}
:if ($x=$i) do={
:set z [:len [/ip fir man find action="mark-connection" disabled=yes chain=prerouting]]
:if ($z>0) do={
:for ii from=1 to=$i do={
/ip fi man set [find new-connection-mark=$ii] per-connection-classifier=("both-addresses:".$x."/".$y) disable=no;:set y ($y+1)}}}}

NTH:

{
:local status
:local i "5"
:local x "0"
:local y "1"
:local z "0"
:set x [:len [/interface pppoe-client find running=yes]]
:if ($x<$i) do={
:for ii from=1 to=$i do={
:set status [/interface get [find name=("pppoe-out".$ii)] running]
:if ($status=true) do={
/ip fir man set [find new-connection-mark=$ii] nth=($x.",".$y) disable=no;:set y ($y+1)} else={
/ip fir man set [find new-connection-mark=$ii] disable=yes}}}
:if ($x=$i) do={
:set z [:len [/ip fir man find action="mark-connection" disabled=yes chain=prerouting]]
:if ($z>0) do={
:for ii from=1 to=$i do={
/ip fi man set [find new-connection-mark=$ii] nth=($x.",".$y) disable=no;:set y ($y+1)}}}}

评分

参与人数 5铜板 +121 收起 理由
bobwalker + 1 有本事比穷
peterchen + 30
workbaby + 20
WGHBOY + 20
47771885 + 50

查看全部评分

routeros
发表于 2011-2-24 02:42:20 | 显示全部楼层
本帖最后由 47771885 于 2011-2-24 02:42 编辑

不错不错 哼好很好 学习
routeros
回复

使用道具 举报

发表于 2011-2-24 03:07:02 | 显示全部楼层
我那个只是会一直刷log
routeros
回复

使用道具 举报

发表于 2011-2-24 07:01:36 | 显示全部楼层
希望脚本有文本版本的
routeros
回复

使用道具 举报

发表于 2011-2-24 10:14:30 | 显示全部楼层
http://bbs.routerclub.com/forum. ... id=41204&extra=

看回复,我很早前发的,虽然写的不是很好。但也没啥问题。
routeros
回复

使用道具 举报

 楼主| 发表于 2011-2-24 10:23:05 | 显示全部楼层

哎。怪我眼神不好,没看到你回复,自己还闷着头写。
routeros
回复

使用道具 举报

发表于 2011-2-24 11:16:57 | 显示全部楼层
:local pccstatus
:local status
:local pccold
:local pccnew
:local link
:local ncm
:local nrm
:local y
:local z
:local x
:set x 4
:set link 0
:for i from=1 to="$x" do={
    :set status [/interface get [/interface find  name=("pppoe-out" . "$i")] running]
    :if ("$status" = true) do={
    :set link ($link + 1)
  }
}
:if ("$link" > 1) do={
    :set z "$link"
    :set y 0
    :for i from=1 to="$x" do={
         :set status [/interface get [/interface find  name=("pppoe-out" . "$i")] running]
         :set ncm ("adsl" . "$i" . "conn")
         :set nrm ("ADSL" . "$i")
         :if ("$status" = true) do={
                    :set pccnew ("both-addresses" . ":" . "$z" . "/" . "$y")
                    :set pccold [/ip firewall mangle get [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"] per-connection-classifier]
                    :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=bonding new-connection-mark="$ncm"] disable]
                    :if (("$pccnew" != $pccold) || ("$pccstatus" = true)) do={
                          /ip firewall mangle set [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"] per-connection-classifier=$pccnew disabled=no
                          /ip firewall mangle set [ /ip firewall mangle find chain=bonding new-routing-mark="$nrm"] disabled=no
                      }
             :set y ($y + 1)
          } else {
                  :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=bonding new-connection-mark="$ncm"] disable]
                  :if ("$pccstatus" = false) do={
                         /ip firewall mangle disable [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"]
                         /ip firewall mangle disable [/ip firewall mangle find chain=bonding new-routing-mark="$nrm"]
             }
        }
    }
  }
}


楼主的脚本跟这位朋友的脚本有什么区别呢?
routeros
回复

使用道具 举报

发表于 2011-2-24 12:31:19 | 显示全部楼层
是啊
希望脚本有文本版本的
routeros
回复

使用道具 举报

 楼主| 发表于 2011-2-24 12:31:59 | 显示全部楼层
回复 kyer2012 的帖子

区别就是,KSW520大哥的是文字版,我的是图片版。
routeros
回复

使用道具 举报

发表于 2011-2-24 12:35:11 | 显示全部楼层
修改版本的脚本在那里啊
routeros
回复

使用道具 举报

发表于 2011-2-24 13:10:22 | 显示全部楼层
连接标记名称是字母加数字的话 如何做改动
routeros
回复

使用道具 举报

发表于 2011-2-24 13:20:28 | 显示全部楼层
谢谢版主分享!
routeros
回复

使用道具 举报

 楼主| 发表于 2011-2-24 14:34:45 | 显示全部楼层
回复 leehomv 的帖子

很简单啊,把英文加数字的改成纯数字。
routeros
回复

使用道具 举报

发表于 2011-2-24 15:39:13 | 显示全部楼层
非常好,楼主你弄好的脚本能用文件形式下载吗
routeros
回复

使用道具 举报

发表于 2011-2-24 16:07:12 | 显示全部楼层
...都喜欢这玩意是吧  有空我也来瞅瞅热闹占位
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 05:39 , Processed in 0.080585 second(s), 6 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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