ROS(mikrotik)用PCQ实现线路带宽的平均分配

挨个限制速度(simple queue)并进行保底是不错的方案,不过也可以试试别的,如PCQ。
挨个限制最大速度要建立几百个规则,且限速后每客户机除了峰值时段外不能
使用全部的带宽,即使线路是空闲的,有点浪费??很浪费

ROS-用PCQ实现线路带宽的平均分配
要实现带宽的最大化利用,可以考虑PCQ   

PCQ:Per Connection Queue 即按连接分组
##下面的英文出处是 来自于mikrotik官方网站http://www.mikrotik.com/docs/ros/2.9/root/queue


If you classify the packets by src-address then all packets with different source
IP addresses will be grouped into different subqueues. Now you can do the limitation
or equalization for each subqueue with the pcq-rate parameter. Perhaps, the most
significant part is to decide to which interface should we attach this queue. If we
will attach it to the Local interface, all traffic from the Public interface will be
grouped by src-address (probably it's not what we want), but if we attach it to the
Public interface, all traffic from our clients will be grouped by src-address - so we
can easily limit or equalize upload for clients.
最关键的地方是决定关联哪块网卡。如果按源地址分组关联到内网网卡,那就等于是按外网的每个
地址进行分组了,这显然是错误的。但如果按源地址分组关联到外网网卡,就可以对按内网地址对
其上传进行带宽控制了。

To equalize rate among subqueues, classified by the pcq-classifier, set the pcq-rate to 0!
要平均分配的话,pcq-rate一定要设为0(这是默认值)。

PCQ can be used to dynamically equalize or shape traffic for multiple users, using
little administration.
使用PCQ只需很少的管理动作就可以实现多用户间的动态平均分配带宽。



Equal bandwidth sharing among users
怎样用PCQ实现平均分配带宽???

This example shows how to equally share 10Mibps download and 2Mibps upload among
active users in the network 192.168.0.0/24. If Host A is downloading 2 Mibps,
Host B gets 8 Mibps and vice versa. There might be situations when both hosts want
to use maximum bandwidth (10 Mibps), then they will receive 5 Mibps each, the same
goes for upload. This setup is also valid for more than 2 users.


举例说明一下怎样分配网络带宽.比如说某线路是下行10M,上行2M.现在要在192.168.0.0/24这个
网段里平均分配,也就是说,如果客户机A只使用了2M带宽进行下载(约200K),另个的客户机B就最高
可以达到8M的带宽,如果客户机A和B都想同时使用10M的带宽进行下载,结果就是两个客户机间进行
平均分配,即每客户机只能分得5M的带宽。更多客户按此类推。

At first,mark all traffic, coming from local network 192.168.0.0/24 with a mark 'users':
第一步是将来自192.168.0.0/24这个网段的流量打上标识,如'users'(神仙看前面有资料显示说过要
先标识相关连接才能标识相关数据包)

/ip firewall mangle add chain=forward src-address=192.168.0.0/24 /
action=mark-connection new-connection-mark=users-con
/ip firewall mangle add connection-mark=users-con action=mark-packet /
new-packet-mark=users chain=forward

Now we will add 2 new PCQ types. The first, called pcq-download will group all traffic
by destination address. As we will attach this queue type to the Local interface, it
will create a dynamic queue for each destination address (user) which is downloading
to the network 192.168.0.0/24. The second type, called pcq-upload will group the traffic
by source address. We will attach this queue to the Public interface so it will make one
dynamic queue for each user who is uploading to Internet from the local network 192.168.0.0/24.
然后是添加两种PCQ:第一种是关于下载的,名为pcq-download,关联到内网网卡Local,并动态地按
目标地址(相对于服务器就是指客户机)分组计算内网客户从外网下载的流量;第二种是关于上传的,
名为pcq-upload,关联到外网网卡Public,并动态地按源地址(相对于服务器还是指客户机)分组计算
向外网上传的流量。

/queue type add name=pcq-download kind=pcq pcq-classifier=dst-address
/queue type add name=pcq-upload kind=pcq pcq-classifier=src-address

Finally, make a queue tree for download traffic:
最后,生成下载流量树
/queue tree add name=Download parent=Local max-limit=10240000
/queue tree add parent=Download queue=pcq-download packet-mark=users

And for upload traffic:
和上传流量树
/queue tree add name=Upload parent=Public max-limit=2048000
/queue tree add parent=Upload queue=pcq-upload packet-mark=users

Note! If your ISP cannot guarantee you a fixed amount of traffic, you can use just
one queue for upload and one for download, attached directly to the interface:
当然,如果你的ISP提供的带宽经常在变化或者说根本不知道具体的带宽是多少,你可以只按网卡
给上传和下载各用一条规则就够了(即将上面的两组命令分别合二为一)
/queue tree add parent=Lan queue=pcq-download packet-mark=users
/queue tree add parent=Public queue=pcq-upload packet-mark=users

也就是说整个实现只需6行代码就可以了:

 

/ip firewall mangle add chain=forward src-address=192.168.0.0/24 action=mark-connection new-connection-mark=users-con
/ip firewall mangle add connection-mark=users-con action=mark-packet new-packet-mark=users chain=forward
/queue type add name=pcq-download kind=pcq pcq-classifier=dst-address
/queue type add name=pcq-upload kind=pcq pcq-classifier=src-address
/queue tree add parent=Lan queue=pcq-download packet-mark=users
/queue tree add parent=Public queue=pcq-upload packet-mark=users

你可能感兴趣的:(IT技术)