Spanning Tree Protocol (STP - IEEE 802.1D) Layer 2 Loop Prevention Guide
(English Language)



STP (Spanning Tree Protocol - IEEE 802.1D) is a Layer 2 (switching) network protocol designed to prevent Layer 2 loops when redundant links are used in a switched topology.

Unlike IP headers, Layer 2 Ethernet frames do not contain a TTL (Time To Live) field. When a Layer 2 loop occurs, frames can circulate endlessly, causing broadcast storms, MAC address table instability, and duplicate frames that can bring down the entire network. STP prevents loops by logically blocking redundant paths so that the active topology forms a loop-free tree structure.

------------------------------------------

Step-by-Step STP Operation

Once STP is active, switches exchange control frames called BPDUs (Bridge Protocol Data Units) every 2 seconds by default (Hello Time) and determine port roles and states through the following four steps:

------------------------------------------

Step 1: Elect the Root Bridge
The network first elects a single Root Bridge to act as the central reference point for the spanning tree topology.

* Selection Rule: The switch with the lowest Bridge ID (BID) becomes the Root Bridge.
* Bridge ID (8 Bytes) Structure:
  1. Bridge Priority (2 Bytes): Default value is 32768 (configurable in increments of 4096, such as 0, 4096, 8192). In per-VLAN implementations like PVST+, it uses Priority + VLAN ID (for example, 32768 + 10 = 32778 for VLAN 10).
  2. Base MAC Address (6 Bytes): If Bridge Priority values are tied, the switch with the lowest (smallest) base MAC address wins.

Best Practice: Do not leave Root Bridge election to chance; explicitly configure a core or distribution switch with a lower priority (such as 4096 or 8192).

-------------------------------------------

Step 2: Elect the Root Port (RP) on Non-Root Bridges
Every non-root switch must select one Root Port (RP), which is the port with the best (lowest-cost) path back to the Root Bridge. (A switch has at most one Root Port per STP instance).

* Tie-Breaker Order (4 Criteria):
  1. Lowest Root Path Cost: Sum of link costs along the path to the Root Bridge; lowest total cost wins.
  2. Lowest Sender Bridge ID: If path costs are equal, the port connected to the upstream switch with the lowest BID wins.
  3. Lowest Sender Port ID: If connected to the same upstream switch via multiple links (same BID), the port with the lowest remote Port ID (Port Priority + Port Number, e.g., Gi0/1 beats Gi0/2) wins.
  4. Lowest Local Port ID: If the first three criteria are still tied, the switch selects the port with the lowest local Port ID.

STP Link Cost Reference (IEEE 802.1D):
- 10 Mbps : Cost (Short / 802.1D) = 100 | Cost (Long / 802.1t) = 2,000,000
- 100 Mbps : Cost (Short / 802.1D) = 19 | Cost (Long / 802.1t) = 200,000
- 1 Gbps : Cost (Short / 802.1D) = 4 | Cost (Long / 802.1t) = 20,000
- 10 Gbps : Cost (Short / 802.1D) = 2 | Cost (Long / 802.1t) = 2,000

-------------------------------------------

Step 3: Elect the Designated Port (DP) on Each Network Segment
Each network segment (link between switches) elects one Designated Port (DP) responsible for forwarding traffic onto and receiving traffic from that segment.

* All operational ports on the Root Bridge are Designated Ports (DPs).
* For other segments:
  1. The switch with the lowest Root Path Cost to the Root Bridge provides the DP for that segment.
  2. If Root Path Costs are tied, the switch with the lowest Bridge ID provides the DP.

-------------------------------------------

Step 4: Block Remaining Ports (Non-Designated / Alternate)
Any port that is not elected as a Root Port (RP) or a Designated Port (DP) is placed into a blocking state to break the loop.

* A blocked port does not forward user data frames and does not learn MAC addresses.
* However, it continues to listen for incoming BPDUs so it can transition to forwarding if an active link fails.

-------------------------------------------

STP Port States (802.1D Classic STP)
In classic 802.1D STP, it typically takes 30 to 50 seconds for a port to move from blocking/listening into forwarding.

1. Blocking (20 sec - Max Age): Listens to BPDUs only; does not forward data or learn MAC addresses.
2. Listening (15 sec - Forward Delay): Sends and receives BPDUs and processes topology changes; does not forward data or learn MAC addresses.
3. Learning (15 sec - Forward Delay): Still does not forward user data frames, but begins populating the MAC address table.
4. Forwarding: Normal operation; forwards user data frames and updates MAC addresses.
(Note: Administratively shut down ports are in the Disabled state.)

------------------------------------------

STP Variants
* CST (Common Spanning Tree - 802.1D): Runs a single spanning tree instance across all VLANs.
* PVST+ (Per-VLAN Spanning Tree Plus): Cisco enhancement that runs a separate spanning tree instance per VLAN, enabling per-VLAN load balancing.
* RSTP (Rapid STP - 802.1w): Speeds up convergence from 30-50 seconds down to roughly 1-2 seconds (combines Blocking and Listening into Discarding).
* MSTP (Multiple STP - 802.1s): Maps multiple VLANs into a smaller number of instances to reduce CPU and memory overhead.

------------------------------------------

Key Practical Deployment Features
* PortFast: Enables access ports connected to end devices (PCs, servers, printers, IP cameras) to move to forwarding immediately without waiting through listening/learning timers.
* BPDU Guard: Immediately puts a PortFast-enabled port into err-disabled state if a BPDU is received, preventing accidental switch loops on edge ports.
* Root Guard: Prevents an unauthorized or misconfigured switch from becoming the Root Bridge by blocking superior BPDUs on designated ports.

Spanning Tree Protocol (STP - IEEE 802.1D) Layer 2 Loop Prevention Guide

(Burmese Language)

STP (Spanning Tree Protocol - IEEE 802.1D) ဆိုတာ Layer 2 (Switching) Network တွေမှာ Redundancy (လမ်းကြောင်းအပို) ထားတဲ့အခါ ဖြစ်ပေါ်လာနိုင်တဲ့ Layer 2 Loops တွေကို တားဆီးပေးတဲ့ Protocol ဖြစ်ပါတယ်။ 

Switch တွေကို Loop ဖြစ်အောင် ချိတ်ဆက်ထားတဲ့အခါ Layer 2 Frame Header မှာ IP Header လို TTL (Time To Live) တန်ဖိုး မပါတဲ့အတွက် Broadcast Storm၊ MAC Address Table Instability နဲ့ Multiple Frame Transmission စတဲ့ ပြဿနာတွေ တက်ပြီး Network တစ်ခုလုံး Down သွားနိုင်ပါတယ်။ STP က လမ်းကြောင်းအပို (Redundant link) တွေထဲက တစ်ခုကို Blocking (Logical အရ ပိတ်ထားခြင်း) လုပ်ပြီး Loop ကင်းရှင်းတဲ့ Tree ပုံစံ Topology တစ်ခုကို တည်ဆောက်ပေးပါတယ်။

-------------------------------------------

STP အလုပ်လုပ်ပုံ Step-by-Step အဆင့်ဆင့်

STP စတင်အလုပ်လုပ်ပြီဆိုတာနဲ့ Switch တွေအချင်းချင်း BPDU (Bridge Protocol Data Unit) လို့ခေါ်တဲ့ Control Frame တွေကို ၂ စက္ကန့်တစ်ကြိမ် (Hello Time) ပို့ဆောင်ပြီး အောက်ပါ အဆင့် (၄) ဆင့်အတိုင်း ဆုံးဖြတ်ပါတယ်။

-------------------------------------------

Step 1: Root Bridge ရွေးချယ်ခြင်း (Elect the Root Bridge)

Network တစ်ခုလုံးရဲ့ ဗဟိုချက် (Reference Point) အဖြစ် Root Bridge တစ်လုံးကို အရင်ဆုံး ရွေးချယ်ပါတယ်။

* ရွေးချယ်ပုံစံ: Bridge ID (BID) တန်ဖိုး အနည်းဆုံး (Lowest BID) ရှိတဲ့ Switch က Root Bridge ဖြစ်လာပါတယ်။

* Bridge ID (8 Bytes) ဖွဲ့စည်းပုံ:

  1. Bridge Priority (2 Bytes): Default တန်ဖိုးမှာ 32768 ဖြစ်ပါတယ်။ (4096 ရဲ့ ဆတိုးများဖြင့်သာ ပြင်ဆင်နိုင်ပါတယ် - ဥပမာ 0, 4096, 8192...)။ VLAN တစ်ခုချင်းစီအတွက် တွက်ချက်တဲ့ PVST+ မှာတော့ Priority + VLAN ID (ဥပမာ VLAN 10 ဆိုရင် 32768 + 10 = 32778) ကို ယူပါတယ်။

  2. Base MAC Address (6 Bytes): Priority တန်ဖိုးချင်း တူနေခဲ့ရင် Switch ရဲ့ MAC Address အနည်းဆုံး (အစောဆုံး/အငယ်ဆုံး) ရှိတဲ့ Switch က Root Bridge ဖြစ်ပါတယ်။

Best Practice: Root Bridge ကို Default တိုင်း မထားဘဲ Core/Distribution Switch ကို Priority 4096 (သို့) 8192 ပေးပြီး Manual သတ်မှတ်ထားသင့်ပါတယ်။

-------------------------------------------

Step 2: Non-Root Bridge များပေါ်တွင် Root Port (RP) ရွေးချယ်ခြင်း

Root Bridge မဟုတ်တဲ့ ကျန် Switch (Non-Root Bridge) တိုင်းမှာ Root Bridge ဆီကို ရောက်ဖို့ အနီးဆုံးနဲ့ အကောင်းဆုံး လမ်းကြောင်းဖြစ်တဲ့ Root Port (RP) တစ်ခုစီ ရှိရပါမယ်။ (Switch တစ်လုံးမှာ RP တစ်ခုပဲ ရှိပါတယ်)။

* ရွေးချယ်ပုံ Tie-Breaker အစဉ်လိုက် (၄) ဆင့်:

  1. Lowest Root Path Cost: Root Bridge ဆီရောက်ဖို့ ဖြတ်သန်းရတဲ့ Link တွေရဲ့ Cost စုစုပေါင်း အနည်းဆုံး လမ်းကြောင်းကို ရွေးပါတယ်။

  2. Lowest Sender Bridge ID: Path Cost တူနေရင် တစ်ဖက်က ချိတ်ဆက်ထားတဲ့ Upstream Switch ရဲ့ BID အနည်းဆုံးဘက်ကို ရွေးပါတယ်။

  3. Lowest Sender Port ID: Upstream Switch တစ်လုံးတည်းကို Link ၂ ကြိုးနဲ့ ချိတ်ထားလို့ BID လည်း တူနေရင် တစ်ဖက် Switch ရဲ့ Port ID (Port Priority + Port Number - ဥပမာ Gi0/1 နဲ့ Gi0/2 ဆိုရင် Gi0/1) အနည်းဆုံးဘက်ကို ရွေးပါတယ်။

  4. Lowest Local Port ID: အထက်ပါ ၃ ချက်လုံး တူနေသေးရင် မိမိ Switch ဘက်က Port ID အနည်းဆုံး Port ကို ရွေးပါတယ်။

STP Link Cost ဇယား (IEEE 802.1D Standard):

- 10 Mbps   : Cost (Short / 802.1D) = 100 | Cost (Long / 802.1t) = 2,000,000

- 100 Mbps  : Cost (Short / 802.1D) = 19  | Cost (Long / 802.1t) = 200,000

- 1 Gbps    : Cost (Short / 802.1D) = 4   | Cost (Long / 802.1t) = 20,000

- 10 Gbps   : Cost (Short / 802.1D) = 2   | Cost (Long / 802.1t) = 2,000

------------------------------------------

Step 3: Network Segment တိုင်းတွင် Designated Port (DP) ရွေးချယ်ခြင်း

Switch ၂ လုံးကြားက ချိတ်ဆက်ထားတဲ့ Cable/Segment တစ်ခုချင်းစီတိုင်းမှာ Data တွေ ပို့/လက်ခံ လုပ်ပေးမယ့် Designated Port (DP) တစ်ခုစီ ရွေးချယ်ရပါတယ်။

* Root Bridge ရဲ့ Port အားလုံးသည် အမြဲတမ်း Designated Port (DP) များ ဖြစ်ကြပါတယ်။

* ကျန် Segment များအတွက် ရွေးချယ်ပုံ:

  1. အဆိုပါ Segment ပေါ်ရှိ Switch ၂ လုံးအနက် Root Bridge ဆီသို့ Root Path Cost အနည်းဆုံး ရှိသော Switch ဘက်မှ Port သည် DP ဖြစ်သည်။

  2. Path Cost တူနေပါက Sender Bridge ID အနည်းဆုံး Switch ဘက်မှ Port သည် DP ဖြစ်သည်။

-------------------------------------------

Step 4: ကျန်ရှိသော Port များကို Blocking (Non-Designated) လုပ်ခြင်း

Step 2 မှာ Root Port (RP) လည်း မဖြစ်၊ Step 3 မှာ Designated Port (DP) လည်း မဖြစ်ဘဲ ကျန်နေခဲ့တဲ့ Port တွေအားလုံးကို Blocking State (Alternate/Non-Designated Port) အဖြစ် ပိတ်ချလိုက်ပါတယ်။

* ဒီ Blocking Port က User Data Frame တွေကို Forward မလုပ်တော့သလို MAC Address ကိုလည်း Learn မလုပ်တော့ပါဘူး။

* သို့သော် တစ်ဖက်က ပို့လာတဲ့ BPDU Frame တွေကိုတော့ ဆက်လက် နားထောင် (Listen) နေပါတယ်။ ဒါမှ မူလ Active Link ပြတ်တောက်သွားတဲ့အခါ Blocking Port ကို ပြန်ဖွင့်ပြီး Failover လုပ်နိုင်မှာ ဖြစ်ပါတယ်။

------------------------------------------

STP Port States များ (802.1D Classic STP)

Classic STP မှာ Port တစ်ခု Blocking ကနေ Data ပို့နိုင်တဲ့ Forwarding အဆင့်ရောက်ဖို့ စုစုပေါင်း ၃၀ မှ ၅၀ စက္ကန့် အထိ ကြာမြင့်ပါတယ်။

1. Blocking (20 sec - Max Age): BPDU ကိုသာ လက်ခံနားထောင်သည်။ Data မပို့၊ MAC မမှတ်။

2. Listening (15 sec - Forward Delay): BPDU တွေ အပြန်အလှန် ပို့/လက်ခံပြီး Topology ပြောင်းလဲမှုကို တွက်ချက်သည်။ Data မပို့၊ MAC မမှတ်။

3. Learning (15 sec - Forward Delay): Data Frame တွေ မပို့သေးသော်လည်း MAC Address Table ကို စတင် တည်ဆောက်သည်။

4. Forwarding: ပုံမှန်အတိုင်း Data Frame များကို ပို့ဆောင်ခြင်း၊ လက်ခံခြင်း ပြုလုပ်သည်။

(မှတ်ချက် - Admin က shutdown လုပ်ထားရင် Disabled State ဖြစ်ပါတယ်)

------------------------------------------

STP မျိုးကွဲများ (STP Variants)

* CST (Common Spanning Tree - 802.1D): VLAN အားလုံးအတွက် STP Instance တစ်ခုတည်းသာ အလုပ်လုပ်သည်။

* PVST+ (Per-VLAN Spanning Tree Plus): Cisco Proprietary ဖြစ်ပြီး VLAN တစ်ခုချင်းစီအတွက် သီးခြား Root Bridge နဲ့ Load Balancing လုပ်နိုင်သည်။

* RSTP (Rapid STP - 802.1w): Convergence အချိန်ကို စက္ကန့် ၃၀-၅၀ ကနေ ၁-၂ စက္ကန့်အတွင်း မြန်ဆန်အောင် မြှင့်တင်ထားသည်။ (Blocking နှင့် Listening ကို Discarding အဖြစ် ပေါင်းလိုက်သည်)။

* MSTP (Multiple STP - 802.1s): VLAN အများကြီးကို Instance အနည်းငယ်ထဲ စုစည်းပြီး CPU/Memory သက်သာအောင် လုပ်ဆောင်ပေးသည်။

-------------------------------------------

လက်တွေ့ Deployment အတွက် အရေးကြီး Feature များ

* PortFast: End Device (PC, Server, Printer, IP Camera) ချိတ်ထားတဲ့ Access Port တွေမှာ စက္ကန့် ၃၀ မစောင့်ဘဲ ချက်ချင်း Forwarding State ရောက်အောင် ဖွင့်ပေးရပါတယ်။

* BPDU Guard: PortFast ဖွင့်ထားတဲ့ Port မှာ မတော်တဆ Switch တစ်လုံး လာချိတ်မိပြီး BPDU ဝင်လာခဲ့ရင် Loop မဖြစ်အောင် အဲဒီ Port ကို ချက်ချင်း err-disabled (ပိတ်ချ) လုပ်ပေးပါတယ်။

* Root Guard: မသက်ဆိုင်တဲ့ Switch တစ်လုံးက Priority အနည်းဆုံးထားပြီး Root Bridge နေရာ လာလုတာကို ကာကွယ်ပေးပါတယ်။

Note by Myat Than Tint

#NetworkingNote

#20 Nov 2026