STP principle-Routing Switching Principle 11-"Hcna notes"

Source: Internet
Author: User
Tags switches

1. BPDU Message Format

The switches use BPDUs (Bridge Protocol data units) to Exchange STP (Spanning Tree Protocol) information, and the BPDU messages are divided into two scenarios (STP working at the data Link layer) that are two classes of configuration BPDUs and TCN BPDUs respectively.

BPDU Frame
Frame Header Data (BPDU message) Fcs

Configure BPDUs (configuration BPDUs) messages: used for spanning tree calculations and maintenance spanning tree topologies.

Configuring BPDU messages 1
" TD valign= "Top" width= "156" > Protocol Version ID BPDUs Type Flags Root P Ath cost
2 bytes 1 bytes 1 bytes 1 bytes 8 bytes 4 bytes
Configuring BPDU Messages 2
Bridge ID
Port ID Message Age Max Age Hello time Fonward Delay
8 bytes 2 bytes 2 bytes 2 bytes 2 bytes 2 bytes

TCN BPDU (topology change Notification BPDU) message: a message used to notify a related device when the topology changes.

TCN BPDU Message
Protocol ID Protocol Version ID BPDU Type
2 bytes 1 bytes 1 bytes

Protocol ID: The protocol type, fixed to 0x0000, represents the spanning tree protocol.

Protocol version ID: protocol release number, spanning tree currently has three versions, 0x00 stands for STP.

BPDU Type: The BPDU type, which is used to distinguish whether the message is configured with BPDUs or TCN BPDUs.

Flags: The BPDU flag bit, consisting of 8 bits, of which the lowest (0 bit) is TC (topology change, topology changes) flag bit, the highest bit (7 bits) is TCA (topology change acknowledge, topology changes acknowledgment) flag bit, and the other 6 bits are reserved unused.

Root ID: The root bridge ID that identifies the device identity that has been selected as the root bridge, the first 2 bytes representing the priority, and the last 6 bytes for their MAC address.

Root path cost : the root bridge path overhead, the path cost to the root bridge.

Bridge ID: sends the network Bridge ID, sends the Network bridge information for that BPDU, the first 2 bytes represents the priority, and the last 6 bytes is its MAC address.

Port ID: The number and priority of the port ID, which is the bridge port ID that sends the BPDU.

Message Age: The lifetime of the BPDU propagation in the network, representing how long the BPDU message has spread over the network.

Max Age: The switch will issue BPDUs packets to all other switches and recalculate the spanning tree if more than that time has not received a BPDU packet from the root bridge.

Hello Time: the interval at which the root bridge continuously sends BPDUs.

Fonward delay: The time it takes for the switch port State to migrate. When a network failure causes the spanning tree to recalculate, the recalculated new configuration message cannot be propagated to the network immediately, and may result in a transient loop if the port status is migrated immediately. Therefore, the spanning tree Protocol adopts State migration mechanism to ensure that new configuration messages are spread throughout the network.


2. Switch port status

The switch running the Spanning tree protocol is always in a forward or blocked state during normal operation, and when the device recognizes a change in the network topology, the switch automatically makes state transitions, during which the port is temporarily in the listening and learning state.

Listening: Monitor , switch boot, access network, or identify the network topology changes when all the ports are switched to the listening state, this state will not receive and forward data, but can receive and send BPDUs. Each device and port in the listening state determines its role, electing the root bridge, the root port, the specified bridge, and the specified port. Then, depending on the result of the election, some ports are converted to learning state and some ports to blocking state.

Learning: Learning , after the election is completed the switch participates in the work port will be converted to learning State, mainly to learn and improve the MAC address table. The data is not received and forwarded in this state, but BPDUs can be received and sent.

Forwarding: Forwarding , MAC Address Table after learning is complete, the switch can start to work, and the participating ports enter the forwarding state. In this state, you can receive and forward data, learn MAC addresses, receive and send BPDUs.

Blocking: Block , the switch part of the port enters the blocking state after the election completes, and maintains that state during the work. You cannot receive or forward data in this state, you cannot send BPDUs, you can only receive BPDUs.


3, STP of the work process

election root bridge: when the switch that opens the STP protocol starts itself as the root bridge, all ports enter the listening state and send configuration BPDU packets to the other switches connected to the port. The root bridge ID in the message is the ID of the sending device, and the switch emits BPDUs and receives bpdus from other devices, which compares the two BPDU messages. The priority in the root bridge ID is compared first, and the smaller the value, the higher the priority level. The priority can be set by the user, and if the user does not set the default priority for all switches is the same, then the MAC address in the root bridge ID is compared, and the lower the value the higher the priority. If the device discovers that the root bridge ID in the BPDU it receives is higher than the BPDU it is currently sending, the device starts forwarding higher-priority bpdus. In this way the entire network will soon send only the highest-priority bpdus of the root-bridge ID, and everyone knows that the device has the highest BPDU priority and agrees that the device is the root bridge.

In the network shown, because the default priority of the switch is the same, so compare its MAC address to get SW1 the highest priority, so you should choose SW1 as the root bridge.


election root port: Once the root bridge is elected, all devices in the network will only forward BPDUs from the root bridge. There is a "root path cost" field in the BPDUs emitted by the root bridge, which accumulates the "cost value" of the port when it enters the switch from a port, and when the switch forwards the root bridge's bpdus to other devices, the root-path Cost field continuously accumulates the cost values of each switch's receive port, which can be set by the user. The default is the same if not set (the cost value at both ends of the link is set to the same as the general setting). A switch in the network may receive bpdus from the root bridge from multiple ports, he compares the value of the Path Cost field in all BPDUs, and considers the least BPDU of the path Cost field to be the best, and the port that receives the BPDU is the root port. If the path Cost field value in the BPDUs received by multiple ports is the same, the switch designates the one with the smallest port ID as the root port, and if the port ID is the same, the lower MAC address value is the root port. The root port is selected in different ports on the same switch, meaning that if the root bridge sends a piece of data to the device, the path that comes in through the root port is optimal. Root bridge does not have a root port.

In the network shown, with SW1 as the root bridge, each port on the switch receives a path cost calculation for BPDUs from the root bridge and a root port election as shown in the following table:

path cost calculation with root port election
Switch Port Path overhead Root Port
SW2 sw2-0 19
sw2-0
Sw2-1 19+4+19 = 42
SW3 sw3-0 19+19 = 38 Sw3-1
Sw3-1 19+4 = 23
SW4 sw4-0 19 sw4-0
Sw4-1 19+19+4 = 42

election of designated ports: after the Root bridge is elected, the switches SW2 and SW3 receive bpdus from different directions on their respective ports, where sw2-1 receives sw3-0-forwarded BPDUs, and sw3-0 receives BPDUs from the other side. After the switch SW2 and SW3 each receive will compare these two bpdus, the root Path Cost field value of the smaller one is excellent, if the value is the same as the number of the smaller, if the number is also the same as the MAC address value is better, the port to send the BPDU is selected as the specified port. The specified port is chosen from two interconnect ports of two different devices, meaning that the optimal transmission direction is chosen from two devices that send BPDUs to each other.

In the network shown, the path cost calculation and the specified port for BPDUs emitted by the switch ports are shown in the following table, as all bpdus are emitted from the root bridge, SW1, so the root bridge port emits a BPDU path cost of 0:

path cost calculation and specified port election
Switch Port Path overhead Specify port
Sw1-sw2 sw1-0 0 sw1-0
sw2-0 19+4+19 = 42
Sw1-sw4
Sw1-1
0 Sw1-1
sw4-0 19+19+4 = 42
Sw2-sw3
Sw2-1 19
Sw2-1
sw3-0 19+4 = 23
Sw3-sw4
Sw3-1
19+19 = 38
Sw4-1
Sw4-1 19

blocking port: After electing the designated port and root port, each switch has the best receive port and the best send port, when the non-designated port, non-root port is blocked, the loop of the whole network disappears, and the path of the root bridge to each switch is optimal.

In the network shown, sw3-0 is not the root port nor the specified port, so it is blocked, then the path sw2-1 to sw3-0 is interrupted and the network loop disappears.


4. Topology Change

Later supplements


"Whether the root port is the specified port" becomes the root port condition is the same switch, the path from the root bridge to reach that port is the least cost, the condition that becomes the specified port is two switches directly connected to the two ports the BPDU path overhead is minimal. As shown in the two switches, we first assume that the port sw1-1 is the specified port, the BPDUs path from Port sw1-0 into a cost value of a, the sw4-1 into the BPDUs path cost value of B, the two switches directly connected to the port cost of C.

Because Sw1-1 is the specified port, the BPDU path cost from Sw1-1 is less than the BPDU path cost value from sw4-0, so we can derive a<b.

Assuming that sw1-1 is also the root port, the BPDUs path cost value received from Sw1-1 is less than the BPDU path cost value received from sw1-0, so a>b+c can be derived.

According to the above calculation, if the sw1-1 is a specified port, a is less than B, if the sw1-1 is the root port, then a is greater than b+c, contradictory, then we can conclude that a port is not the specified port is the root port.


"The Role of STP" in practical applications in order to make the link more stable, users always use multiple paths to achieve the purpose of the link, or the network is quite complex when the generation of one or more loops. The generation of loops is prone to side effects such as broadcast storms, multi-frame replication and MAC Address Table jitter, resulting in a "Spanning tree protocol" to address these issues. The spanning tree sees a complex network topology as a tree, selecting one of the switches as the root bridge, and the switch connected to it to receive data from the root direction, select a "specified port" to send data from the root direction, and block the other ports. This enables data to reach all devices in the network from the root without loops and repeated reception, and the path to the data from any device to another device is unique.


The "loop hazard" loop mainly causes three problems, broadcast storms, multi-frame replication, and MAC Address Table jitter.

broadcast storm: simply speaking, when broadcast data flooding the network can not be processed, and occupy a large amount of network bandwidth, so that normal business can not run, or even completely paralyzed, this happened "broadcast storm." Assume AB two points into a ring, located on the same switch. A broadcast packet with an unknown address, B received after the switch because there is no such Mac, re-launch a broadcast, the broadcast packet to a, because the target can not match from the Mac table, a will again send a broadcast, so the cycle continues, resulting in a broadcast storm.

Multi-frame replication: Unicast data frames may be transferred to the destination site multiple copies. Many protocols require only one copy to be transmitted at a time. Multi-frame replication causes the destination site to receive multiple copies of a data frame, not only wasting the resources of the destination host, but also causing the upper layer protocol to be unable to select when processing these data frames, and potentially causing unrecoverable errors when critical.

MAC Address Table jitter: that is, the MAC address table is unstable because copies of the same frame are received on different ports on the switch. If the switch consumes resources on a copy-unstable MAC address table, the data forwarding function may be weakened.


"Port cost" network access to the switch model is various, the same switch different ports its rate performance is not consistent, so the data from a device to B devices or B devices to reach the C device loss or rate is not consistent, that the transmission costs are inconsistent, Therefore, the concept of a port cost to distinguish this difference, the cost of two direct-connect port is always consistent, because the data receive and send is bidirectional, there is no fast reception slow.


The "path cost" data passes through one or more ports on the network, and the cumulative value of these port costs is the path cost, which represents the total cost of reaching the other end from the end of the link.


The bridge's early bridges are used to connect two hubs, so bridges can isolate conflict domains. The bridge can be seen as a switch with only two ports, and similarly, if the switch uses two ports to connect the two networks, it can also be said that the switch's two ports implement a bridge. So in the previous narrative, bridges are often confused with switches.

STP principle-Routing Switching Principle 11-"Hcna notes"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.