Spanning Tree - MSTP (802.1s) 深度教學

Extreme XOS 網路架構大師系列 | 20 年實戰經驗分享

1 核心概念 (Concept)

一句話定義

MSTP (Multiple Spanning Tree Protocol) 是一種將多個 VLAN 映射到特定「實例 (Instance)」的技術,旨在解決傳統 STP 運算過慢與 PVST 運算過於耗費資源的問題,實現網路負載平衡。

生活化比喻:公車專用道系統

想像這是一座城市的交通系統,VLAN 就是不同的「乘客群體」(如:上班族、學生、觀光客)。

  • CST (傳統 STP): 所有乘客(所有 VLAN)只能擠同一輛公車走同一條路。如果這條路封閉,所有人都卡住。且即便有另一條空的路,也不能用(因為怕迴圈)。
  • PVST+ (Cisco 早期): 每個乘客群體(每個 VLAN)都派一輛專屬公車。雖然靈活,但路上車子太多(CPU 負載過高),交通指揮官(Switch CPU)會崩潰。
  • MSTP (802.1s): 這是最聰明的「共乘制度」。我們規定:「去北邊的乘客(VLAN 10, 20)搭 A 號公車,去南邊的乘客(VLAN 30, 40)搭 B 號公車」。這樣既不用太多車,也能充分利用所有道路(負載平衡)。

2 運作原理 (Mechanism)

技術細節

  • MST Region (區域): 這是 MSTP 的基本單位。要成為同一個 Region,三要素必須完全一致:
    Region Name (區域名稱)
    Revision Number (修訂版號)
    VLAN-to-Instance Mapping (映射表)
  • IST (Internal Spanning Tree): 即 Instance 0。這是預設的實例,負責攜帶所有未明確分組的 VLAN 以及控制封包 (BPDU)。在 Extreme XOS 中,這通常對應到 Default VLAN 或 Mgmt。
  • MSTI (MST Instance): 用戶自定義的實例(如 Instance 1, Instance 2)。每個 MSTI 都有獨立的 Root Bridge 計算與 Blocking Port,這就是實現負載平衡的關鍵。

Extreme XOS 關鍵參數 & 設定

# 設定 MSTP Region 範例

configure mstp region name "Hauman_HQ"

configure mstp revision 1


# 建立 Instance (MSTI)

create stpd s1

configure stpd s1 mode mstp cist


# 映射 VLAN 到 Instance

configure stpd s1 add vlan "Finance"

configure stpd s1 add vlan "HR"


# 啟用

enable mstp

* 註:CIST (Common and Internal Spanning Tree) 負責連結不同的 Regions 以及 Region 內部的 IST。

3 架構視覺化 (Visuals)

以下透過三個圖表層次,展示 MSTP 如何在同一個物理線路上,建立兩個邏輯上不同的轉送路徑(負載平衡)。

圖一:物理連接拓撲 (Physical Topology)

graph TD %% 物理層連接 CoreA[("Core Switch A
(Root for MSTI 1)")] CoreB[("Core Switch B
(Root for MSTI 2)")] Access1["Access Switch"] %% 連接線 CoreA ---|Link 1| CoreB CoreA ---|Link 2| Access1 CoreB ---|Link 3| Access1 style CoreA fill:#e0e7ff,stroke:#4338ca,stroke-width:2px style CoreB fill:#e0e7ff,stroke:#4338ca,stroke-width:2px style Access1 fill:#f3e8ff,stroke:#7e22ce,stroke-width:2px

實體線路全部接通,若無 STP 會產生迴圈。

圖二:MSTI 1 邏輯路徑 (VLAN 10, 20)

graph TD %% MSTI 1 視角 subgraph MSTI_1 [Instance 1: VLAN 10, 20] Root1[("Core A
(ROOT BRIDGE)")] NonRoot1[("Core B")] Acc1["Access Switch"] Root1 == "Forwarding" ==> NonRoot1 Root1 == "Forwarding" ==> Acc1 NonRoot1 -. "BLOCKING (x)" .- Acc1 end style Root1 fill:#dcfce7,stroke:#16a34a,stroke-width:3px style NonRoot1 fill:#fee2e2,stroke:#dc2626,stroke-width:1px linkStyle 0 stroke:#16a34a,stroke-width:2px; linkStyle 1 stroke:#16a34a,stroke-width:2px; linkStyle 2 stroke:#dc2626,stroke-width:2px,stroke-dasharray: 5 5;

在 Instance 1 中,流量主要走左側 (Core A)。右側 Link 3 被阻斷。

圖三:MSTI 2 邏輯路徑 (VLAN 30, 40)

graph TD %% MSTI 2 視角 subgraph MSTI_2 [Instance 2: VLAN 30, 40] NonRoot2[("Core A")] Root2[("Core B
(ROOT BRIDGE)")] Acc2["Access Switch"] NonRoot2 == "Forwarding" ==> Root2 NonRoot2 -. "BLOCKING (x)" .- Acc2 Root2 == "Forwarding" ==> Acc2 end style Root2 fill:#dcfce7,stroke:#16a34a,stroke-width:3px style NonRoot2 fill:#fee2e2,stroke:#dc2626,stroke-width:1px linkStyle 0 stroke:#16a34a,stroke-width:2px; linkStyle 1 stroke:#dc2626,stroke-width:2px,stroke-dasharray: 5 5; linkStyle 2 stroke:#16a34a,stroke-width:2px;

在 Instance 2 中,流量主要走右側 (Core B)。左側 Link 2 被阻斷。

4 實務應用場景 (Use Case)

案例:大型企業園區核心層 (Campus Core)

某科技公司有兩台核心交換器 (Core-A, Core-B) 透過 MLAG 或實體線路互連,並下接數十台 Access Switch。公司主要有兩個龐大的業務部門:
1. 研發部 (RD):使用 VLAN 100-199,資料量極大。
2. 行政部 (Admin):使用 VLAN 200-299,主要是 ERP 流量。

部署策略

  • 設定 Core-A 為 MSTI 1 (VLAN 100-199) 的 Root Bridge (Priority 4096),Core-B 為 Secondary。
  • 設定 Core-B 為 MSTI 2 (VLAN 200-299) 的 Root Bridge (Priority 4096),Core-A 為 Secondary。
  • Access Switch 設定相同 Region,並根據 Instance 自動計算最短路徑。

👍 優點 (Pros)

  • 頻寬利用最大化: 上行鏈路不再有一條閒置 (Blocked),兩條線路分別服務不同部門。
  • 資源節省: 相比 PVST 為每個 VLAN 跑一個運算程序,MSTP 只需要跑 2 個 Instance,CPU 負擔大幅降低。
  • 相容性: 802.1s 是國際標準,Extreme 可以跟 Cisco、Juniper 完美介接。

⚠️ 缺點 (Cons)

  • 設定複雜: Region 設定 (Name/Rev/Map) 必須在所有交換器上「完全一致」,錯一個字就會變成不同 Region,導致退化成傳統 STP 行為。
  • 除錯難度: 需要同時檢查不同 Instance 的拓撲,初學者容易混淆。

5 進階陷阱:VLAN 拓撲不一致的黑洞

當所有 VLAN 都在同一個 Instance,但每個 VLAN 的實體連接拓撲不同時,會發生什麼事?

一、核心概念:同命不同運

定義: 當多個 VLAN 綁定在同一個 MSTI (Instance),但這些 VLAN 在實體鏈路上的允許清單 (Tagged List) 不一致時,MSTP 計算出的「阻斷點 (Blocking Port)」可能會恰好阻斷某個 VLAN 的「唯一路徑」,導致該 VLAN 流量完全中斷 (Blackholed)。

生活化比喻: 想像 VLAN 10 (紅線) 和 VLAN 20 (藍線) 被捆成一束 (Instance 1) 搭乘火車。火車駕駛 (MSTP) 因為前方鐵軌維修,決定封閉右邊軌道,全車改走左邊。
但不幸的是,紅線乘客的票 (Tag) 只能走右邊。結果就是:車子走了左邊,但紅線乘客因為沒票上不了車;右邊軌道雖然有票但被封閉了。紅線乘客因此哪裡都去不了。

二、運作原理:STP 狀態與 VLAN Tag 的脫鉤

  • MSTP 只看 Instance: 交換器在計算路徑時,只根據 Instance 的參數 (Cost, Priority) 決定哪個 Port 要 Block。它不會去檢查裡面的 VLAN 10 是否在那個 Port 上有打 Tag。
  • State 優先於 VLAN: 如果 Port 2 被 MSTP 設為 Blocking,那麼屬於該 Instance 的所有 VLAN 封包都會被丟棄。
  • 沒有自動補救: 即使 VLAN 20 在 Port 1 (Forwarding 狀態) 沒有被允許 (未 Tagged),MSTP 也不會因此把 Port 2 打開。Loop-Free 是最高原則。

三、陷阱視覺化流程

圖A:物理配置與 VLAN 錯置 (設定失誤)

graph TD Core[Core Switch] Edge[Edge Switch] Core -- "Link 1
(VLAN 10 Only)
Cost 10" --- Edge Core -- "Link 2
(VLAN 20 Only)
Cost 20" --- Edge style Core fill:#e2e8f0 style Edge fill:#e2e8f0 linkStyle 0 stroke:#3b82f6,stroke-width:2px; linkStyle 1 stroke:#ef4444,stroke-width:2px;

注意:VLAN 10 只在左邊,VLAN 20 只在右邊。但兩者都在 Instance 1。

圖B:MSTP Instance 1 計算結果

graph TD Core[Core Switch] Edge[Edge Switch] Core == "Link 1
FORWARDING
(Root Port)" ==> Edge Core -. "Link 2
BLOCKING
(Alternate)" .- Edge style Core fill:#e2e8f0 style Edge fill:#e2e8f0 linkStyle 0 stroke:#16a34a,stroke-width:3px; linkStyle 1 stroke:#dc2626,stroke-width:3px,stroke-dasharray: 5 5;

MSTP 發現 Link 1 Cost 較低,選為 Forwarding。Link 2 為了防圈被 Block。

圖C:最終流量結果 (VLAN 20 斷線)

graph TD subgraph Result [Instance 1 Traffic Flow] L1["Link 1 (FWD)"] L2["Link 2 (BLK)"] V10(VLAN 10 Traffic) -->|VLAN Allowed| L1 V10 -->|Success| OK[通訊正常] V20(VLAN 20 Traffic) -->|VLAN NOT Allowed| L1 V20 -->|Drop| Fail1[斷線: Link 1 無 Tag] V20_2(VLAN 20 Traffic) -->|STP Blocked| L2 V20_2 -->|Drop| Fail2[斷線: Link 2 被 STP 阻擋] end style Fail1 fill:#fee2e2,stroke:#ef4444 style Fail2 fill:#fee2e2,stroke:#ef4444 style OK fill:#dcfce7,stroke:#16a34a

VLAN 20 兩邊都不通!這就是拓撲不一致造成的黑洞。

四、實務應用與教訓

這種情況常發生在「逐步遷移」「備援線路測試」場景:

工程師在 Core Switch 新增了一個測試用的 VLAN 999 (屬於 Instance 1),為了測試備援線路,他刻意只在 Backup Link (Link 2) 上放行 VLAN 999。
結果: 因為 Instance 1 判定 Link 1 才是主路徑,將 Link 2 Block 掉了。VLAN 999 雖然在 Link 2 上有設定,但路不通;在 Link 1 上路通,但沒設定。導致測試永遠失敗。

⚠️ 黃金準則:同一個 MST Instance 內的所有 VLAN,其 L2 實體拓撲 (Member Ports) 必須完全一致。

6 綜合隨堂測驗 (Quiz)

包含基礎概念與進階陷阱題。請點擊您認為正確的選項。