Rapid Spanning Tree Protocol (RSTP) 快速生成樹協定

前言

Rapid Spanning Tree Protocol (RSTP 或 802.1w) 是傳統 Spanning Tree Protocol (STP 或 802.1D) 的進化版本,RSTP 在 Spanning Tree Algorithm 並沒有大改變,方向仍是選出 Root Switch,再按 Cost 選出 Root Port、Designated Port 等去避免 Loop。但傳統 802.1D 的收斂時間 (Convergence Time) 太慢,當有 Topology 改變,整個網絡需時 30 秒或以上才能回復穩定狀態,這是現代網絡不能接受的。RSTP 的出現就是為了縮短收斂時間。

傳統 STP 的問題

所以,30 秒真的有那麽重要嗎?試想像網絡是用來提供證券交易服務 (所謂秒秒鐘幾廿萬上落),或者用作緊急電話通訊,30 秒的 Down Time 可能足夠讓你失去工作。本文假設讀者已完全了解傳統 STP 的運作,如信心不夠,可先到這裡溫習溫習。

傳統 STP 存在以下幾個問題:

Listening 及 Learning 時間

STP 預設 Listening 和 Learning 為 15 秒 (Forward Delay),Port 由 Down 至 Up 一共等待 30 秒。而 RSTP 則使用 Synchronization 的概念,Switch 並非被動地等待 Root Switch 傳來的 BPDU 訊息在判斷 Topology,取而代之的是主動去跟相鄰的 Switch 溝通,盡快把網絡 Topology 傳開去。這就能省卻那 30 秒的被動學習時間,稍後詳述。

Max Age 時間

STP 的預設 Max Age 為 20 秒,如 Topology 改變或其他原因令 BPDU 不能到達 Blocking Port,這 Port 要到 20 秒才被喚醒進入 Listening。問題一樣,太慢!RSTP 縮短為 3 個 Hello Time 的長度,即 6 秒。

Uplinkfast 及 Backbonefast

STP 的進階功能 Uplinkfast 及 Backbonefast 機制已成 RSTP 內建功能。(如想了解 Uplinkfast 及 Backbonefast,請到這裡)

Topology Change

STP 在 Port 發生 Up/Down 時會產生 Topology Change 把整個網絡中 Switch 的 MAC Address Table 裡失效的紀錄清掉。可惜清除時間太慢。而 RSTP 則改善了 Topology Change 的機制,並縮短清除 Mac Address 的時間,稍後詳述。

要達成以上幾項進化,RSTP 在 STP 的基礎上作出了兩項修改,包括 Port Role 及 Port State,另外又加入了 Link type 的概念,以下逐一說明。為了讓我們容易適應,RSTP 源用了大部份 STP 的指令,這算 Cisco 貼心,由 STP 改用 RSTP 所需的工夫不多,就一句 spanning-tree mode rapid-pvst 即可。

使用 STP 時,會見到 Protocol 一行顥示為 ieee,代表正在使用傳統 STP。

SW#show spanning-tree

VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     0016.468f.xxxx
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0016.468f.xxxx
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

<--Output Omitted-->

轉成 RSTP 後,則會顥示 rstp。

SW(config)#spanning-tree mode rapid-pvst
SW(config)#exit
SW#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    24577
             Address     0016.468f.xxxx
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0016.468f.xxxx
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

<--Output Omitted-->

如果 Switch 支緩 RSTP 的話,請把所有 Switch 都轉為 RSTP,以發揮最佳效果。然而,RSTP 可以向下支緩 STP,如果遇到另一端不支緩 RSTP 的話,會自動轉為 STP 運作,用 show spanning-tree 指令時會有顯示。

SW#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    24577
             Address     0016.468f.xxxx
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0016.468f.xxxx
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa1/0/1          Desg FWD 19        128.3    P2p
Fa1/0/2          Desg FWD 19        128.4    P2p Peer(STP)
Fa1/0/3          Desg FWD 19        128.5    P2p
Fa1/0/14         Desg FWD 19        128.16   P2p Peer(STP)
Fa1/0/15         Desg FWD 19        128.17   P2p Peer(STP)
Fa1/0/16         Desg FWD 19        128.18   P2p Peer(STP)

Port Role

RSTP 保留 Root Port 和 Designated Port 的 設計,選擇方法與 STP 相同。另外加進了 Alternate Port 和 Backup Port,以便加快收斂時間 (Convergence Time)。

Root Port

Switch 上最接近 (即 Root Cost 最小) Root Switch 的 Port 成為 Root Port。每隻 Switch 只會有一個 Root Port。

Designated Port

在沒有成為 Root Port 的情況下,網段裡最接近 (即 Root Cost 最小) Root Switch 的 Port 成為 Designated Port。每個網段只會有一個 Designated Port。

在 STP 中,沒被選中成為 Root Port 或 Designated Port 的 Port 只能成為 Non-Designated Port,但在 RSTP 中則會成為 Alternate Port 或 Backup Port。

Alternate Port

沒有成為 Root Port 或 Designated Port 的 Port 如收到較佳 BPDU (對方是 DP) 來自其他 Switch,就會成為 Alternate Port,Alternate Port 為 Switch 提供通往 Root Switch 的後備路徑。以下圖為例,SW2 與 SW3 之間的網段,由於 SW2 收到的 BPDU 是來自 SW3,SW2 判斷這 Port 是另一個到 Root Switch 的路徑。

rstp

Backup Port

沒有成為 Root Port 或 Designated Port 的 Port 如收到較佳 BPDU (對方是 DP) 來自自己,則會成為 Backup Port,Backup Port 為該網段提供通往 Root Switch 的後備路徑。如在同一網段有 Alternate Port 和 Backup Port,當 Designated Port 掛掉時,一般情況下,Backup Port 會優先補上成為新的 Designated Port。這看以下例子,SW3 會收到來自自己的較佳 BPDU,因而成為 Backup Port。

rstp

Port State

RSTP 在 Port State 上也有進化,把傳統 STP 中的 Disabled、Blocking 和 Listening 統一變成 Discarding。而 Learning 與 Forwarding 則維持不變。換句話說,Root Port 和 Designated Port 會被設成 Forwarding,而 Alternate Port 和 Backup Port 會被設成 Discarding。當 Alternate Port 和 Backup Port 有一天被喚醒的話,它會先進入 Learning (非常短暫的時間),然後進入 Forwarding。

STP Port State RSTP Port State
Disabled Discarding
Blocking Discarding
Listening Discarding
Learning Learning
Forwarding Forwarding

Link Type

Link Type 是 RSTP 新增的概念,RSTP 把 Link 分為 Edge Port,Point to Point Non-edge Port 及 Shared Non-edge Port 三種。

Edge Port

即是接駁 Host 的 Port,亦即承傳了在 STP 中的 Portfast,Edge Port 設定容許該 Port 由 Discarding 直接進入 Forwarding,並假設不會引致 Loop 而不產生 TCN (Topology Change Notification) 訊息,這就避免了 Switch 清空 Mac Address Table。Edge Port 需要用指令去設定,RSTP 源用了 spanning-tree portfast 這個指令,設定完成後可用 show spanning-tree 去驗證。

SW(config)#int fastEthernet 1/0/3
SW(config-if)#spanning-tree portfast
SW(config-if)#end
SW#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    24577
             Address     0016.468f.xxxx
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0016.468f.xxxx
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa1/0/1          Desg FWD 19        128.3    P2p
Fa1/0/2          Desg FWD 19        128.4    Shr
Fa1/0/3          Desg FWD 19        128.5    Edge P2p

Point to Point Non-edge Port

RSTP 會把 Full Duplex Port 定性為 Point to Point Non-edge Port,並會用 RSTP 與對方進行溝通 (Synchronization Process)。

Shared Non-edge Port

而 Half Duplex Port 則會成為 Shared Non-edge Port,只能用傳統 STP 方法溝通。不過 Half Duplex Port 在現今網絡世界已經比較難找到了,除非網絡中仍有使用舊式的 HUB。

show spanning-tree 可以查看 Link Type。P2P 就昰 Point to Point Non-edge Port,而 Shr 則是 Shared Non-edge Port。

SW#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    24577
             Address     0016.468f.xxxx
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0016.468f.xxxx
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa1/0/1          Desg FWD 19        128.3    P2p
Fa1/0/2          Desg FWD 19        128.4    Shr
Fa1/0/3          Desg FWD 19        128.5    Edge P2p

我們也可以用指令 spanning-tree link-type <type>  去強行設定。

SW(config-if)#spanning-tree link-type ?
  point-to-point  Consider the interface as point-to-point
  shared          Consider the interface as shared

SW(config-if)#spanning-tree link-type shared

Synchronization Process

我們不斷說 RSTP 很快很快,究竟 RSTP 有什麽魔法可以在短時間內讓網絡穩定下來?答案就是 Synchronization Process。每當有新的 Switch 加入網絡,就會發起 Synchronization,流程如下。

  1. 新加入的 Switch 假設自己是 Root Switch 並向相鄰的 Switch (Point to Point Non-edge Port) 發出 Proposal,希望對方同意自己成為 Root Switch。此時,雙方的 Port 都是 Discarding 狀態。
  2. 收到 Proposal 的 Switch 會檢視這位新成員是否比現時的 Root Switch 更理想 (比較方法跟 STP 一樣,不在此重覆),然後回覆同意或是不同意。
    1. 如果不同意新成員成為 Root Switch,老實告訴對方。新成員無耐接受,並把 Port 定性為 Root Port 並立刻完成 Learning 並進入 Forwarding。
    2. 如果接受新成員成為 Root Switch,要做的事就多了:
      • 因為出現了新的 Root Switch,Topology 將有無法預期的改變,所以先把自己正在 Forwarding 的 Non-edge Port 轉成 Discarding 去避免 Loop。
      • 回應新成員接受對方成為 Root Switch,並把連接這個新成員的 Port 變成 Root Port,並立刻完成 Learning 並進入 Forwarding。
      • 同一時間向其他所有的 Point to Point Non-edge Port 發出 Proposal,把消息傳開去,並重覆以上 Synchronization Process。

單看文字始終較解理解,我嘗試把流程漫畫化,以下是新 Switch 無法成為 Root Switch 的程況。

rstp

rstp

rstp

以下是新 Switch 能夠成為 Root Switch 的流程。

rstp

rstp

rstp

rstp

rstp

rstp

看 SW2 與 SW3 誰先完成 SW1 的 Synchronization,誰就先發 Proposal。

rstp

rstp

rstp

BPDU

在傳統 STP 中,BPDU 只會由 Root Switch 每 2 秒 (Hello Time) 發放一次,然後用一個傳一個的方式,散播到網絡上所有 Switch。而在 RSTP 中每隻 Switch 都會發放 BPDU,同樣每 2 秒發放一次,RSTP 中的 BPDU 有 Keepalive 的作用,如果 Root Port 過了 6 秒鐘都收不到對放的 BPDU (3 個 Hello Time),則會作出以下應變:

  • 如有 Alternate Port,立刻把 Alternate Port 升級成為 Root Port
  • 如沒有 Alternate Port,則把自己成為 Root Switch 啟動 Synchronization Process

Topology Change

當網絡的 Topology 改變,無論 STP 或 RSTP 都會觸發 Topology Change,提示網絡裡所有 Switch 要清掉 Mac Address Table 裡可能已經失效的紀錄。然而,STP 的機制有個缺點就是慢!RSTP 作出了一些改變,請看下表比較。

STP RSTP
如何觸發 Topology Change
1. 當一個 Port 轉到 Forwarding 狀態
2. 當一個 Listening 或 Forwarding 的 Port 轉到 Blocking 或 Disabled
當 Non-edge Port 轉到 Forwarding
如何通知其他 Switch 發 TCN 通知 Root Switch,再由 Root Switch 通知其他 Switch 透過 BPDU 直接通知相鄰 Switch,以一個傳一個的方式傳開去
收到 Topology Change 的相應動作 縮短 Mac Address Table 的 Timeout 時間,等待失效的紀錄自然死亡。 除了接收到 Topology Change 那個 Port 的紀錄外(因為從發生 Topology Change 的 Port 得到的紀錄肯定是準確的),把 Mac Address Table 裡其他的紀錄都即時殺掉,寧枉勿縱。
清除失效紀錄所需時間 最少需要 1 個 Forward Delay 的時間 (15秒),這還未計算 TCN 傳到 Root Switch 再傳到所有 Switch 的時間。 由 Topology Change 發生直至傳遍整個網絡,需時 = 2秒 x [Topology Change Switch 與最邊緣 Switch 的 Hop Count]

相關主題

發佈留言

2017-02-13

Posted In: Layer 2 網絡技術, menu-tall-2-zh-hant

Leave a Comment