STP - Spanning Tree Protocol ============================= .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is STP?** STP (Spanning Tree Protocol) is a network protocol used to prevent loops in Ethernet networks. It ensures a loop-free topology by selectively blocking redundant paths. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why is STP useful?** * Automatically detects loops * Disables redundant paths * Re-enables them if the active path fails .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How it works** * **Root Bridge Election** – Switches elect one switch as the Root Bridge (lowest Bridge ID) * **Path Cost Calculation** – Each switch finds the shortest path to the Root Bridge * **Loop Prevention** – STP blocks extra paths to prevent loops * **Failure Recovery** – If a path fails, STP activates a backup .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Where is STP used?** * Enterprise LANs with multiple switches * Data centers with redundant links * Campus networks * Any Ethernet-based network with loop potential .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which OSI layer does this protocol belong to?** * **Layer 2 – Data Link Layer** * Operates using MAC addresses * No dependence on IP addresses * Manages switch-to-switch behavior .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are common types of STP?** * **STP (802.1D)** – Original standard * **RSTP (802.1w)** – Rapid STP for faster convergence * **MSTP (802.1s)** – Supports multiple spanning trees for VLANs .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the port roles in STP?** * **Root Port (RP)** – Best path to the Root Bridge (one per switch) * **Designated Port (DP)** – Forwards frames on a segment * **Blocked Port** – Does not forward traffic (backup path) * **Disabled Port** – Shut down or not participating .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the STP port states?** * **Blocking** – Listens for BPDUs only * **Listening** – Prepares for data forwarding * **Learning** – Learns MACs but does not forward * **Forwarding** – Active traffic forwarding * **Disabled** – Manually turned off .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a BPDU?** A Bridge Protocol Data Unit (BPDU) is a special message used by STP to share topology information between switches. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What happens during a topology change?** * A switch detects a change (e.g., link down/up) * It sends a Topology Change Notification (TCN) BPDU * The Root Bridge updates the topology * Switches flush MAC tables and reconverge .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the working flow of STP?** * **All Switches Send BPDUs** – Each switch assumes it's the Root and sends its Bridge ID (priority + MAC) with path cost = 0 * **Elect the Root Bridge** – Lowest Bridge ID wins * **Calculate Path Cost to Root** – Cost based on link speed: - 10 Mbps = 100 - 100 Mbps = 19 - 1 Gbps = 4 - 10 Gbps = 2 * **Assign Port Roles** – Based on best paths and BPDUs: - Root Port - Designated Port - Blocked Port * **Block Redundant Links** – Only Root & Designated Ports forward * **Transition Port States (802.1D)** – Blocking → Listening → Learning → Forwarding * **Handle Topology Changes** – Affected switch sends TCN BPDU, MAC tables are flushed, and tree recalculates .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the real-time applications of STP?** * **VoIP (Voice over IP)** * **Video Conferencing** (e.g., Zoom, Microsoft Teams) * **Industrial Automation** * **IPTV / Live Video Streaming** .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is STP Windows-specific?** * No, STP (Spanning Tree Protocol) is not Windows-specific. * It is a network protocol implemented in network switches and bridges. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is STP Linux-specific?** * No, STP is not Linux-specific. * It is supported on various network devices regardless of operating system. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Transport Protocol is used by STP?** * STP operates at the **Data Link Layer (Layer 2)**. * It does not use TCP or UDP transport protocols. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Port is used by STP?** * STP does not use TCP/UDP ports. * It sends Bridge Protocol Data Units (BPDUs) directly over Ethernet frames with a reserved multicast MAC address. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is STP using Client-server model?** * No, STP does not use a client-server model. * It is a distributed protocol where network switches communicate with each other to prevent loops. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Terminology ` * :ref:`Version Info ` * :ref:`STP Version&IEEE Details ` * :ref:`STP Basic Setup on Ubuntu ` * :ref:`STP Protocol Packet Details ` * :ref:`STP Usecases ` * :ref:`STP Basic Features ` * :ref:`STP Feature : Loop Prevention ` * :ref:`STP Feature : Redundancy Support ` * :ref:`STP Feature : Automatic Topology Change Handling ` * :ref:`STP Feature : Bridge Election ` * :ref:`STP Feature : Port Roles Assignment ` * :ref:`STP Feature : Path Cost Calculation ` * :ref:`STP Feature : Timer Based Operation ` * :ref:`STP Feature : Dynamic Reconfiguration ` * :ref:`STP Feature : Standardized Protocol ` * :ref:`STP Feature : Layer 2 Operation ` * :ref:`Reference links ` .. _STP_step1: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. _STP_step2: .. tab-set:: .. tab-item:: Terminology * Terminology .. _STP_step3: .. tab-set:: .. tab-item:: Version Info * Version Info .. _STP_step5: .. tab-set:: .. tab-item:: STP Version&IEEE Details .. csv-table:: :file: ./STP/STP_IEEEdetails.csv :widths: 10,10,10,30,40 :header-rows: 1 .. _STP_step20: .. tab-set:: .. tab-item:: STP Basic Setup on Ubuntu **STP Basic Test Case** * To verify that both VMs running the bridge daemon can send and receive STP BPDUs every 2 seconds, and that the packets are visible in Wireshark /tcpdump. * Step-1: Install bridge utilities .. code-block:: shell test:~$sudo apt update test:~$sudo apt install bridge-utils -y * Step-2: Create a bridge interface and add a network interface to it .. code-block:: shell test:~$sudo brctl addbr br0 test:~$sudo brctl addif br0 en0ps8 #Replace enp0s8 with your secondary interface * Step-3: Enable STP on the bridge .. code-block:: shell test:~$sudo brctl stp br0 on * Step-4: Bring up the bridge and interface .. code-block:: shell test:~$sudo ip link set br0 up test:~$sudo ip link set enp0s8 up * Step-5: Check bridge status .. code-block:: shell test:~$brctl show bridge name bridge id STP enabled interfaces br0 8000.080027123456 yes enp0s8 * Step-6: Capture STP traffic on one VM * Run tcpdump to capture BPDUs (STP multicast MAC: 01:80:c2:00:00:00) .. code-block:: shell test:~$sudo tcpdump -i enp0s8 ether dst 01:80:c2:00:00:00 -nn -v # A sample look like this after running tcpdump: listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes 10:15:42.123456 STP 802.1d, Config, Flags [none], bridge-id 8000.08:00:27:12:34:56.8001, length 35 root-id 8000.08:00:27:65:43:21.8001, root-pathcost 0, age 1.20s, max-age 20.00s, hello-time 2.00s, forward-delay 15.00s 10:15:44.123456 STP 802.1d, Config, Flags [none], bridge-id 8000.08:00:27:12:34:56.8001, length 35 root-id 8000.08:00:27:65:43:21.8001, root-pathcost 0, age 3.20s, max-age 20.00s, hello-time 2.00s, forward-delay 15.00s * Step-6: * Expected result: * STP BPDUs are visible every 2 seconds (default hello time). * Wireshark captures: * Destination MAC: 01:80:c2:00:00:00. * Protocol: IEEE 802.1D Spanning Tree. * Bridge ID, Root ID, and timer values (hello time, max age, forward delay). * Step-7: Wireshark Capture. :download:`Download wireshark capture ` .. _STP_step6: .. tab-set:: .. tab-item:: STP Protocol Packet Details **STP CONFIGURATION BPDU Packet** .. csv-table:: :file: ./STP/STP_Configuration_BPDU_Packet.csv :widths: 10,20,30,40 :header-rows: 1 **STP TOPOLOGY CHANGE NOTIFICATION Packet** .. csv-table:: :file: ./STP/STP_Topology_Change_Notification_Packet.csv :widths: 10,20,30,40 :header-rows: 1 .. _STP_step7: .. tab-set:: .. tab-item:: STP Usecases .. csv-table:: :file: ./STP/STP_Use_Cases.csv :widths: 10,20,30 :header-rows: 1 .. _STP_step8: .. tab-set:: .. tab-item:: STP Basic Features .. csv-table:: :file: ./STP/STP_Features.csv :widths: 10,10,30 :header-rows: 1 .. _STP_step9: .. tab-set:: .. tab-item:: STP Feature : Loop Prevention **Loop Prevention - Testcases** .. csv-table:: :file: ./STP/STP_Feature1_Loop_Prevention_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step10: .. tab-set:: .. tab-item:: STP Feature : Redundancy Support **Redundancy Support - Testcases** .. csv-table:: :file: ./STP/STP_Feature2_Redundancy_Support_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step11: .. tab-set:: .. tab-item:: STP Feature : Automatic Topology Change Handling **Automatic Topology Change Handling - Testcases** .. csv-table:: :file: ./STP/STP_Feature3_Automatic_Topology_Change_Handling_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step12: .. tab-set:: .. tab-item:: STP Feature : Bridge Election **Bridge Election - Testcases** .. csv-table:: :file: ./STP/STP_Feature4_Bridge_Election_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step13: .. tab-set:: .. tab-item:: STP Feature : Port Roles Assignment **Port Roles Assignment - Testcases** .. csv-table:: :file: ./STP/STP_Feature5_Port_Roles_Assignment_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step14: .. tab-set:: .. tab-item:: STP Feature : Path Cost Calculation **Path Cost Calculation - Testcases** .. csv-table:: :file: ./STP/STP_Feature6_Path_Cost_Calculation_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step15: .. tab-set:: .. tab-item:: STP Feature : Timer Based Operation **Timer Based Operation - Testcases** .. csv-table:: :file: ./STP/STP_Feature7_Timer_Based_Operation_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step16: .. tab-set:: .. tab-item:: STP Feature : Dynamic Reconfiguration **Dynamic Reconfiguration - Testcases** .. csv-table:: :file: ./STP/STP_Feature8_Dynamic_Reconfiguration_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step17: .. tab-set:: .. tab-item:: STP Feature : Standardized Protocol **Standardized Protocol - Testcases** .. csv-table:: :file: ./STP/STP_Feature9_Standardized_Protocol_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step18: .. tab-set:: .. tab-item:: STP Feature : Layer 2 Operation **Layer 2 Operation - Testcases** .. csv-table:: :file: ./STP/STP_Feature10_Layer2_Operation_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _STP_step19: .. tab-set:: .. tab-item:: Reference links * Reference links