[Network basics] STP principle

table of Contents

1. Concept
2. STP working principle

  1. Layer 2 switching network
  2. Broadcast storm
  3. MAC address table shock
  4. The role of STP
  5. STP operation
  6. Election with bridge
  7. Root port election
  8. Port state transition
  9. BPDU
  10. Timer
  11. malfunction

One. concept

To improve network reliability, redundant links are usually used in switched networks. However, redundant links will bring loop risks to the switching network, and lead to broadcast storms and MAC address table instability issues, which will affect the user's communication quality. Spanning Tree Protocol (STP) can improve reliability while avoiding various problems caused by loops.

two. How STP works

1. Layer 2 switching network

Insert picture description here
There will be multiple links interconnected in the layer 2 switching network. Although the network reliability is improved, it will also cause loop problems

2. Broadcast Storm

Insert picture description here

As shown in the figure, for example, host A sends a broadcast frame, SWB will perform a flooding operation, and forward it to SWA and SWC. At this time, SWA also receives a broadcast frame, and it will also perform flooding and send it to SWC. At this time, SWC receives two broadcast frames. Broadcast frame, and will perform the flooding operation to host B and SWB, and SWB will flood to host A and SWA again, in an infinite loop. This caused a broadcast storm.

3. MAC address table shock

Insert picture description here

After the host A sends the data frame, the MAC address corresponds to the G0 / 0/3 interface and exists in the SWB's MAC address table. After forwarding in the loop, it returns to the SWB and G0 / 0/2 interface to form a correspondence SWB's MAC address table will cause the address table to oscillate.

4. The role of STP

  • Eliminate loops: logically block a link
  • Link backup:

5. STP operation

  1. Elect a root bridge.
  2. Each non-root switch elects a root port.
  3. Each network segment elects a designated port.
  4. Block non-root (neither root port nor designated port), non-designated port.

Port role:

  • RP: root port (non-root bridge sends data to the root bridge)
  • DP: Designated port (send BPDU)
  • AP: blocked port (can only accept BPDU)

6. Root bridge election

Insert picture description here
The root bridge is elected through the BID (bridge priority (must be a multiple of 4096, the default value is 32768) + device MAC address) in the BPDU (bridge data unit). The smaller the BID, the higher the priority.

After the switch starts, it automatically starts spanning tree convergence calculations. By default, all switches consider themselves as the root bridge when starting up, and all their ports are designated ports, so that BPDU packets can be forwarded through all ports. After receiving the BPDU message, the peer switch compares the root bridge ID in the BPDU with its own bridge ID. If the bridge ID in the received BPDU packet has a low priority, the receiving switch will continue to advertise its configuration BPDU packet to the neighboring switch. If the bridge ID in the received BPDU packet has a high priority, the switch will modify the root bridge ID field of its own BPDU packet to announce the new root bridge.

7. Root port election

The non-root switch selects the root port based on the root path cost of the port, the peer BID, the peer PID (port number + port priority (default is 128)) and the local PID.

8. Designated port election

The non-root switch selects the designated port based on the root path cost, local BID, and local PID respectively.
Ports that are not elected as root ports or designated ports are reserved ports and will be blocked (blocked ports).

9. Port state transition

Insert picture description here

  • Disabled: Disabled (do not send or receive any messages)
  • Blocking: Blocking state (no data is sent and received, but BPDUs are received)
  • Listening: Listening status (no data is sent and received, but BPDUs can be sent and received)
  • Learning: learning status (do not send and receive data, but can send and receive BPDUs and start address learning)
  • Forwarding: Forwarding status (receive data and BPDU, and can learn address)
  1. Port initialization or enabling;
  2. The port is selected as the root port or designated port.
  3. The port is no longer a root port or a designated port.
  4. The forward delay timer expires.
  5. The port is disabled or the link is invalid.

10. BPDU

Insert picture description here

  • PID: protocol ID
  • PVI: protocol version
  • BPDU Type:
    Arrangement BPDU
    TCN BPDU
  • Flags: Flag bit
    TC: Topology change flag
    TCA: Topology change confirmation flag
  • Root ID: root bridge ID
  • RPC: root path cost
  • Bridge ID:桥ID
  • Port ID: Port ID
  • Message age: lifetime
  • Max age: maximum survival time (20s)
  • Hello time: Interval for sending BPDUs
  • Fwd delay: forwarding delay (15s)

11. Timer

Each time a BPDU packet is configured to pass through a switch, Message Age is incremented by 1.
If Message Age is greater than Max Age, the non-root bridge will discard the configuration BPDU.

12. Failure

12.1 Root Bridge Failure
In a stable STP topology, non-root bridges will periodically receive BPDU packets from the root bridge. If the root bridge fails and stops sending BPDU packets, downstream switches cannot receive BPDU packets from the root bridge. If the downstream switch cannot receive the BPDU message, the Max Age timer will expire (the default value of Max Age is 20 seconds), which will cause the BPDU message that has been received to be invalid. BPDU packets, re-election of a new root bridge. A root bridge failure will result in a recovery time of about 50 seconds. The recovery time is approximately equal to Max Age plus twice the Forward Delay convergence time.

12.2 Direct link failure After the
SWB detects a physical failure of the direct link, it converts the standby port to the root port.
The new root port of SWB will return to the forwarding state after 30 seconds.

12.3 Indirect link failure

Published 30 original articles · won 9 · visited 1120

Guess you like

Origin blog.csdn.net/TKE_Yolanda/article/details/105525041