🌳 Spanning Tree Protocol (STP)

 Hub -> Bridge -> Switch 

Bridge is same as Hub ( 4 ports )  with few extra ports.. 

Switch has CPU.. 

Targeted Packet Forwarding: Unlike hubs that broadcast data to all devices, intelligent switches learn device MAC addresses and send data only to the intended recipient.

Hub and Bridge - Creates one collision domain ( domain where collisions can occur ) and one broadcast domain..

Switch breaks collision domain.
Switch creates one Broadcast domain.

Router breaks collision domain and broadcast domain.. 

255.255.255.255 - Broadcast address to send Broadcast message.. 
----------------------------------------------------------------------------------------------------

                                Spanning tree is created by removing redundant paths 


                                        High bandwidth = low cost = Best path to Root e node.

🌳 Spanning Tree Protocol (STP)


🧠 Top 9 Key Points

  1. Prevents Switching Loops:
    STP detects and blocks redundant links in a network to prevent broadcast storms and MAC table instability.

  2. Selects a Root Bridge:
    The switch with the lowest Bridge ID (Priority + MAC address) becomes the Root Bridge for the network.

  3. Blocks Redundant Links:
    Redundant paths are put into a blocking state, ensuring a single active path between any two switches.

  4. Uses Bridge Protocol Data Units (BPDUs):
    Switches exchange BPDUs to share information about the network topology and root bridge.

  5. Automatically Reconfigures:
    If an active link fails, STP recalculates and unblocks a redundant link to restore connectivity — ensuring fault tolerance.

  6.  Five STP States
     
    Listening state : Process BPDU and Determines network topology.  (15 seconds )
    Learning state : Learns MAC address and loads MAC table ( 15 seconds ) 
    Forwarding state : Forwards user traffic.
    Disabled state : Does not forward traffic.  STP stopped working and loop occurs..
                              when faulty switch is added to the network the Bridge id is changed and STP is                                disabled.. 
    Blocking state : Redundant links to blocked, Prevents network loops

  7. Broadcast IP address : 255.255.255.255

  8. Types :
    Rapid Spanning Tree Protocol - Fastest 
    Per VLAN Spanning Tree Protocol
    Multiple Spanning Tree Protocol

  9. When a link fails, the switch waits out the Max Age timer (20s) before transitioning to the Listening (15s) and Learning (15s) stages, resulting in a total convergence delay of 50 seconds

  10. DP (Designated Port): Active, forwards traffic  
    RP (Root Port): Best path toward the Root Bridge. 
    AP (Alternate Port): Backup path, does not forward traffic unless the Root Port fails.

  11. In the Spanning Tree Protocol (STP), the cost to reach the Root Bridge is calculated based on link bandwidth. Faster interfaces are assigned lower path costs. A switch determines the best path by cumulatively adding the port costs of all incoming links along the route to the Root Bridge.
  12. Old devices cost value.. 

    Link SpeedPort Cost
    10 Mbps100
    100 Mbps19
    1 Gbps4
    10 Gbps2

     

    Modern Cisco devices can also use a "long" cost method that provides more granularity for very high-speed links.

    Link SpeedLong Cost
    10 Mbps2,000,000
    100 Mbps200,000
    1 Gbps20,000
    10 Gbps2,000
    100 Gbps200

  13.    


⚙️ Technical Summary

FeatureDescription
Layer2 (Data Link Layer)
StandardIEEE 802.1D (Classic STP)
TypesSTP, RSTP (802.1w), MSTP (802.1s)
Convergence Time50 seconds (STP), faster in RSTP
BPDU TransmissionEvery 2 seconds

🧰 Packet Tracer Lab: STP in Action

🎯 Goal:

Demonstrate how STP prevents loops when multiple switches are interconnected.


πŸ–₯️ Network Topology

[Switch1] // \\ [Switch2]==[Switch3]

Lab Description

  • All switches connected in a triangle (loop).

  • STP ensures one redundant link is blocked automatically to prevent loops.


πŸͺœ Step-by-Step Configuration

πŸ”Ή On All Switches (S1, S2, S3)

enable conf t spanning-tree vlan 1

This enables STP for VLAN 1 (default VLAN).
(It’s enabled by default on Cisco switches, but this reinforces the concept.)


πŸ”Ή Check Root Bridge

Run the command:

show spanning-tree

Example output:

Root ID Priority 32769 Address 0001.42B3.7C10 This bridge is the root
  • The switch with the lowest Bridge ID (Priority + MAC) is the Root Bridge.

  • Other switches will have some ports in forwarding state and one port in blocking state.


πŸ”Ή Force a Specific Root Bridge

Let’s make Switch1 the Root Bridge (for demonstration).

enable conf t spanning-tree vlan 1 priority 4096

πŸ’‘ Lower priority = higher chance of becoming Root Bridge.
(Default is 32768, so 4096 makes this switch root.)

Now verify again:

show spanning-tree

Switch1 will now show:

This bridge is the root

πŸ”Ή Observe Port Roles

  • Root Port (RP): Best path to Root Bridge.

  • Designated Port (DP):  other than Root port other forwarding ports are called Designated Ports.

  • Blocked Port (BP): Prevents loops (in “Blocking” or “Discarding” state).

You can see port roles using:

show spanning-tree interface

πŸ”Ή Test STP in Action

  1. From the topology, disconnect one active link between Switch1 and Switch2.

  2. Watch STP automatically unblock a previously blocked link between Switch2 and Switch3 — restoring full connectivity.

✅ This demonstrates STP convergence and loop prevention dynamically.


🧠 Key Learning Summary

ConceptDescription
STP PurposePrevents loops in Layer 2 networks
Root BridgeCentral switch selected by lowest Bridge ID ( Priority+ MAC)
BPDUControl messages exchanged between switches
Blocked PortsAvoid loops by disabling redundant links
FailoverAutomatically unblocks redundant link on failure

πŸ’¬ Teaching Tip

“STP is like a traffic controller — it lets only one car (frame) pass on a given path and keeps the others waiting, but if the main road closes, it quickly opens an alternate route.”




Comments

Popular posts from this blog

πŸ–§ VLAN (Virtual Local Area Network)

🌐 NAT (Network Address Translation)

πŸ›°️ OSPF (Open Shortest Path First)