天天看點

ROS QOS流量品質控制(轉貼)

/ ip firewall mangle

add chain=forward p2p=all-p2p action=mark-connection           new-connection-mark=p2p_conn passthrough=yes comment="" disabled=no

add chain=forward connection-mark=p2p_conn action=mark-packet           new-packet-mark=p2p passthrough=yes comment="" disabled=no

add chain=forward connection-mark=!p2p_conn action=mark-packet           new-packet-mark=general passthrough=yes comment="" disabled=no

add chain=forward packet-size=32-512 action=mark-packet new-packet-mark=small           passthrough=yes comment="" disabled=no

add chain=forward packet-size=512-1200 action=mark-packet new-packet-mark=big           passthrough=yes comment="" disabled=no

/ queue tree

add name="p2p1" parent=TEL packet-mark=p2p limit-at=2000000 queue=default           priority=8 max-limit=6000000 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="p2p2" parent=LAN packet-mark=p2p limit-at=2000000 queue=default           priority=8 max-limit=6000000 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="ClassA" parent=LAN packet-mark="" limit-at=0 queue=default priority=8           max-limit=100000000 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="ClassB" parent=ClassA packet-mark="" limit-at=0 queue=default           priority=8 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="Leaf1" parent=ClassA packet-mark=general limit-at=0 queue=default           priority=7 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="Leaf2" parent=ClassB packet-mark=small limit-at=0 queue=default           priority=5 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

add name="Leaf3" parent=ClassB packet-mark=big limit-at=0 queue=default           priority=6 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s           disabled=no

1-8級優先級控制,數字越小優先級越高

LAN内網接口

TEL 外網接口

SMALL 小包 32-512位元組        5級優先級

BIG 大包        512-1200位元組         6級優先級

general 其它包 1200-1500位元組        7級優先級

P2P類         8級優先,全局限速 600KB/S下載下傳

Leaf 子類

分層的令牌桶HTB

HTB (Hierarchical Token Bucket) is a classful queuing discipline that is useful for

applying different handling for different kinds of traffic. Generally, we can set only

one queue for an interface, but in RouterOS queues are attached to the main

Hierarchical Token Bucket (HTB) and thus have some properties derived from that

parent queue. For example, we can set a maximum data rate for a workgroup and

then distribute that amount of traffic between the members of that workgroup.

HTB是用于流量分類控制的經典理論。通常隻對一個接口進行流量控制,但ROS使用了HTB理論,

比如說,可以先限制一個工作組的流量然後在此工作組内部再一次細分流量。流量控制還挺複雜

的,神仙覺得。

Each class in the hierarchy can prioritize and shape traffic. There are 2 main

parameters in RouterOS :

* limit-at - data rate that is guaranteed to a class (CIR)

* max-limit - maximal data rate that is allowed for a class to reach (MIR)

兩個主要參數:

limit-at : 穩定速率

max-limit : 最大速率

* CIR(Committed Information Rate) - the guaranteed data rate. It means that traffic

rate, not exceeding this value should always be delivered

* MIR(Maximal Information Rate) - the maximal data rate router will provide

CIR:保底速率。不超過這個的速率總是允許的

MIR:最大速率

Each HTB class can be in one of 3 states, depending on data rate that it consumes:

每個HTB層級都有三種狀态:綠、黃、紅(winbox中queue可以看到三種顔色的圖示)

* green - a class the actual rate of which is equal or less than limit-at. At this state,

the class is attached to self slot at the corresponding priority at its level, and is

allowed to satisfy its limit-at limitation regardless of what limitations its parents

have. For example, if we have a leaf class with limit-at=512000 and its parent has

max-limit=limit-at=128000, the class will get its 512kbps!

綠色:指目前速率小于或等于穩定速率(limit-at)。這個狀态下,目前層級由自己自行控制,不受

上級層級控制。比如說,如果某個層級設定的穩定速率為512kbps,其上級層級的穩定速率設定為

128kbps,那麼此層級在綠色狀态下享受512kbps的速率

* yellow - a class the actual rate of which is greater than limit-at and equal or less

than max-limit. At this state, the class is attached to the inner slot of the

corresponding priority of its parent's inner feed, which, in turn, maybe attached

to either its parent's inner slot of the same priority(in case the parent is also yellow),

or to its own level self slot of the same priority (in case the parent is green). Upon

the transition to this state, the class 'disconnects' from self feed of its level,

and 'connects' to its parent's inner feed

×××:批目前速率大于穩定速率但不大于最大速率。這個狀态下,目前層級由其上級層級控制(其

上級如果也處于×××狀态則繼續此規則,即由上級的上級控制)。

* red - a class the actual rate of which exceeds max-limit. This class cannot borrow

rate from its parent class

紅色:指目前速率超過了最大速率。此層級不能從其上級層級分得任何流量

Bursts

突發速率

Bursts are used to allow higher data rates for a short period of time. Every second,

the router calculates the average data rate of each class over the last burst-time

seconds. If this average data rate is less than burst-threshold, burst is enabled

and the actual data rate reaches burst-limit bps, otherwise the actual data rate falls

to max-limit or limit-at.

突發速率用于短時間内的超高速率資料傳送。路由器每秒種都在計算前一時間段(burst-time)的平

均速率。如果平均速率低于設定的閥值(burst-threshold),就允許其使用突發速率(burst-

limit),否則就會降低到穩定速率或最大速率

Let us consider that we have a setup, where max-limit=256000, burst-time=8, burst-

threshold=192000 and burst-limit=512000. When a user is starting to download a

file via HTTP,we can observe such a situation: At the beginning the average data

rate over the last 8 seconds is 0bps because before applying the queue rule no

traffic was passed, using this rule. Since this average data rate is less than burst-

threshold (192kbps), burst is allowed. After the first second, the average data rate

is (0+0+0+0+0+0+0+512)/8 = 64kbps, which is under burst-threshold. After the

second second, average data rate is (0+0+0+0+0+0+512+512)/8 = 128kbps. After

the third second comes the breakpoint when the average data rate becomes larger

than burst-threshold. At this moment burst is disabled and the current data rate falls

down to max-limit(256kbps).

舉例說明:

假設我們設定最大速率(max-limit)為256k,時間段(burst-time)為8秒,閥值為192k,突發速率

(burst-limit)為512k,當使用者下載下傳檔案時可以觀察到:

開始下載下傳的前8秒速率為0,小于閥值192,是以允許達到突發速率即512;

1秒鐘後,前8秒的平均速率為64(0+0+0+0+0+0+0+512)/8=64,仍然小于閥值192,是以繼續

使用突發速率512;

2秒鐘後,前8秒的平均速率為(0+0+0+0+0+0+512+512)/8=128;

3秒鐘後,再次計算平均速率為(0+0+0+0+0+512+512+512)/8=192,達到了閥值192,是以,

3秒鐘後此使用者已不再允許使用突發速率,隻能使用允許的最大速率了,即256kbps

設定最多3秒的突發速率

limit-at burst-threshold max-limit burst-limit burst-time

128 192 256 512 8s

128 384k 512 2048 16s

mss和MTU2008-03-03 23:53先說一段話。。

MTU與MSS值到底設定為多少?

MTU: Maxitum Transmission Unit 最大傳輸單元

MSS: Maxitum Segment Size 最大分段大小

PPPoE: PPP Over Ethernet(在以太網上承載PPP協定)

[分析過程]

先說說這MTU最大傳輸單元,這個最大傳輸單元實際上和鍊路層協定有着密切的關系,讓我們先仔細回憶一下EthernetII幀的結構DMAC+SMAC+Type+Data+CRC由于以太網傳輸電氣方面的限制,每個以太網幀都有最小的大小64bytes最大不能超過1518bytes,對于小于或者大于這個限制的以太網幀我們都可以視之為錯誤的資料幀,一般的以太網轉發裝置會丢棄這些資料幀。(注:小于64Bytes的資料幀一般是由于以太網沖突産生的“碎片”或者線路幹擾或者壞的以太網接口産生的,對于大于1518Bytes的資料幀我們一般把它叫做Giant幀,這種一般是由于線路幹擾或者壞的以太網口産生)。

由于以太網EthernetII最大的資料幀是1518Bytes這樣,刨去以太網幀的幀頭(DMAC目的MAC位址48bit=6Bytes+SMAC源MAC位址48bit=6Bytes+Type域2bytes)14Bytes和幀尾CRC校驗部分4Bytes(這個部門有時候大家也把它叫做FCS),那麼剩下承載上層協定的地方也就是Data域最大就隻能有1500Bytes這個值我們就把它稱之為MTU。這個就是網絡層協定非常關心的地方,因為網絡層協定比如IP協定會根據這個值來決定是否把上層傳下來的資料進行分片。就好比一個盒子沒法裝下一大塊面包,我們需要把面包切成片,裝在多個盒子裡面一樣的道理。當兩台遠端PC互聯的時候,它們的資料需要穿過很多的路由器和各種各樣的網絡媒介才能到達對端,網絡中不同媒介的MTU各不相同,就好比一長段的水管,由不同粗細的水管組成(MTU不同 )通過這段水管最大水量就要由中間最細的水管決定。

對于網絡層的上層協定而言(我們以TCP/IP協定族為例)它們對水管粗細不在意它們認為這個是網絡層的事情。網絡層IP協定會檢查每個從上層協定下來的資料包的大小,并根據本機MTU的大小決定是否作“分片”處理。分片最大的壞處就是降低了傳輸性能,本來一次可以搞定的事情,分成多次搞定,是以在網絡層更高一層(就是傳輸層)的實作中往往會對此加以注意!有些高層因為某些原因就會要求我這個面包不能切片,我要完整地面包,是以會在IP資料包標頭裡面加上一個标簽:DF(Donot Fragment)。這樣當這個IP資料包在一大段網絡(水管裡面)傳輸的時候,如果遇到MTU小于IP資料包的情況,轉發裝置就會根據要求丢棄這個資料包。然後傳回一個錯誤資訊給發送者。這樣往往會造成某些通訊上的問題,不過幸運的是大部分網絡鍊路都是MTU1500或者大于1500。

對于UDP協定而言,這個協定本身是無連接配接的協定,對資料包的到達順序以及是否正确到達不甚關心,是以一般UDP應用對分片沒有特殊要求。

對于TCP協定而言就不一樣了,這個協定是面向連接配接的協定,對于TCP協定而言它非常在意資料包的到達順序以及是否傳輸中有錯誤發生。是以有些TCP應用對分片有要求---不能分片(DF)。

花開兩朵,各表一枝,說完MTU的故事我們該講講今天的第二個豬腳---PPPoE所謂PPPoE就是在以太網上面跑PPP協定,有人奇怪了,PPP協定和Ethernet不都是鍊路層協定嗎?怎麼一個鍊路層跑到另外一個鍊路層上面去了,難道更新成網絡層協定了不成。其實這是個誤區:就是某層協定隻能承載更上一層協定。為什麼會産生這種奇怪的需求呢?這是因為随着寬帶接入(這種寬帶接入一般為Cable Modem或者xDSL或者以太網的接入)由于以太網缺乏認證計費機制而傳統營運商是通過PPP協定來對撥号等接入服務進行認證計費的,是以就出了這麼一個怪胎:PPPoE。(有關PPPoE的詳細介紹參見V大以及本站其他成員的一些介紹文章,我就不啰裡啰唆的了)。

PPPoE帶來了好處,也帶來了一些壞處,比如:二次封裝耗費資源,降低了傳輸效能等等,這些壞處俺也不多說了,最大的壞處就是PPPoE導緻MTU變小了以太網的MTU是1500,再減去PPP的標頭包尾的開銷(8Bytes),就變成1492。如果兩台主機之間的某段網絡使用了PPPoE那麼就會導緻某些不能分片的應用無法通訊。這個時候就需要我們調整一下主機的MTU,通過降低主機的MTU,這樣我們就能夠順利地進行通訊了。

當然對于TCP應用而言還有另外的解決方案。馬上請出今天第三位豬腳:MSS。MSS最大傳輸大小的縮寫,是TCP協定裡面的一個概念。MSS就是TCP資料包每次能夠傳輸的最大資料分段。為了達到最佳的傳輸效能TCP協定在建立連接配接的時候通常要協商雙方的MSS值,這個值TCP協定在實作的時候往往用MTU值代替(需要減去IP資料包標頭的大小20Bytes和TCP資料段的標頭20Bytes)是以往往MSS為1460。通訊雙方會根據雙方提供的MSS值得最小值确定為這次連接配接的最大MSS值。

介紹完這三位豬腳,我們回過頭來看前言裡面的那個問題,我們試想一下,如果我們在中間路由器上把每次TCP連接配接的最大MSS進行調整這樣使得通過PPPoE鍊路的最大MSS值加上資料標頭包尾不會超過PPPoE的MTU大小1492這樣就不會造成無法通訊的問題,是以上面的問題可以通過ip tcp adjust-mss 1452來解決,當然問題也可以通過修改PC機的MTU來解決。

不改MSS會如何?有可能會出現部分網站打不開,例如陶寶,線上銀行什麼的。或者開網頁慢,都可能和MSS有關系的。

修改辦法(2927版本)

IP==>>Firwwall==>>Mangle==>>點+号==>>

General頁

Chain:forward

Protocol:tcp

Advanced頁

Tcpflags選SYN

Action頁

action:Change mss

new tcpmss:1472

關于MSS數值的多少,以及取值辦法~

ping 目标網站 -f -l 1500   然後看能否PING通,如果PING不通,就以4為機關往下減,目标網站可以是

你想通路,但通路不了,也可以是其他一些網站,這個要求不多。。

比如我PING 百度

ping www.baidu.com -f -l 1500

得到以下提示:

程式代碼

C:\>ping www.baidu.com -f -l 1500

Pinging www.a.shifen.com [202.108.22.5] with 1500 bytes of data:

Packet needs to be fragmented but DF set.

Ping statistics for 202.108.22.5:

     Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

這就說明,1500這個MSS數值不可取,需要往下了換,那麼就以4位機關往下減,減到通為止,就是1500-4=???自己去算了。我這裡是1472才通的,是以我改的就是1472