Detailed description of the Spanning Tree

Source: Internet
Author: User

LAN switching technology, also known as Layer 2 switching technology, mainly includes the working principle of Layer 2 switching, network loops, and how to use the spanning-Tree Protocol to solve Network loops, VLANs, and VTP technologies, let's talk less, and the book goes to the beginning. Before introducing the exchange technology, we have to mention the traditional way of working on shared Ethernet to learn about conflicting domains, broadcast domains, and network segments, I would like to give a brief introduction to this knowledge in the basics of network:

We all know that the traditional shared Ethernet uses the CSMA/CD mechanism, that is, the carrier listens for Multi-Channel Access/conflict detection. Let's analyze it in detail:

CSMA/CD is a distributed media access control protocol. each node in the network can independently determine the transmission and receipt of data frames. Before sending data frames, each node must first perform carrier monitoring. frames can be sent only when the media is idle. At this time, if two or more nodes listen to the idle media and send frames at the same time, a conflict will occur. This will make all the sent frames invalid, and the sending will fail immediately. Each node must be able to detect conflicts at any time. In the event of a conflict, the transmission should be stopped to avoid wasted media bandwidth due to invalid frames transmitted. Then, after a random delay for a period of time, resend the media and resend the frame.

At first, three companies, Inter, Xerox and Dec, proposed the Ethernet standard. Later, the IEEE organization formulated the 802.3 standard, which stipulated the MAC Sub-layer of the Ethernet physical layer and the data link layer, it mainly defines 10base-2, 10base-5, 10base-t, 10base-f, etc., specifying the media, bandwidth, distance, and so on. At the same time, a 802.2 standard is also defined to define the LLC sub-layer of the Ethernet data link layer, that is, the Logical Link Control Sub-layer, which mainly provides an interface between the data link layer and the network layer,

There are many protocols at the network layer. The data link layer provides a distinction between many protocols. Which protocol is used at the network layer? This is why the data frame encapsulates the header information of an LLC. However, in Traditional Ethernet 2 frames, instead of using LLC encapsulation, there is a two-byte type in the data frame to indicate the protocol used for Internet access. For example, the network layer protocol used is arp.

Next let's take a look at the conflicting domain and broadcast domain.

Conflict domain: All nodes in a shared-bandwidth Ethernet can send data when they need to communicate with other nodes, but the CSMA/CD mechanism ensures that only one node can send data at a specific time, if the meat and meat send data at the same time, this will lead to a conflict, then such a range of conflicts may occur in this shared network, we are called a conflict domain.

Broadcast domain: A broadcast domain is a range that can be reached by a broadcast packet in a network. That is to say, if a broadcast packet is sent to a node on a network, the range that this broadcast packet can reach is called a broadcast domain,

As a professional network staff, the ability to identify conflicting domains and broadcast domains is an important skill. The first-layer device is added to expand the conflict domain. Only the second-layer device or third-layer device can be added to separate the conflict domain, that is to say, if a bridge, vswitch, and vro are added, the conflicting domain can be divided into smaller parts to reduce the bandwidth competition and conflict. A vro also has the advantage of dividing smaller broadcast domains. This is called network segmentation. Second-layer devices are used to reduce the range of conflicting domains, which is called "differential segments", that is, segments that are not meaningful. The true segmentation is that the CIDR block numbers are different and cannot be used for direct communication. Therefore, L2 devices can achieve segmentation, but the network cannot be truly segmented, while vrouters can achieve real network segmentation. Let's take a look at this sentence! Provide a table for your reference.

So our exchange technology is undoubtedly using a switch. Let's look at the function of a switch:

Three Functions of a vswitch:

Learning Maca addresses

Data Frame Forwarding or data frame Filtering

Use Spanning Tree Protocol to Prevent Network Loops

First, let's look at the MAC address learning function of the first vswitch. The vswitch performs exchange and forwarding through the Mac table. Therefore, the MAC address table is the core of the exchange, the difference between the network and the switch is that the bridge uses software to create and manage MAC address tables, while the switch uses ASIC to create and manage MAC address tables.

The MAC address learning function of the vswitch:

When the vswitch is initialized, you need to learn the source address of the data frame of the vswitch, and record the source address and the port number of the corresponding vswitch In the MAC address table. After the MAC address table is formed, the switch needs to learn the destination address of the data frame of the switch and compare it with the entries in the MAC address table to complete the corresponding forwarding.

When the switch is started, the MAC address table is empty because the MAC address table is stored in the memory.

If computer A sends a data frame to computer C, the E0 port of the switch receives the data frame, and the switch records the correspondence between the source address c of the data frame and the E0 port. :

Because the switch does not know the MAC address of C, it forwards the data frame to other ports except E0.

If computer D sends a data frame to computer C, the E3 port of the switch receives the data frame, and the switch records the correspondence between the source address D of the data frame and the port. At this time, the switch still does not know the C address, so it still needs to forward the port other than E0.

The switch constantly records the addresses of data frames received on each interface. After a period of time, the MAC addresses connected to all ports will be recorded in the MAC address table. In this case, when computer A sends data to computer C, it simply queries the MAC address table and forwards the data to other ports.

In this figure, computer A and computer B connect to the E0 port of the switch through the hub. Therefore, Two MAC addresses correspond to the same port in the MAC address table. If a communicates with B, the switch does not forward the data frame because both the source and Mac are on the same interface. This is the address learning function of the vswitch and packet forwarding filtering.

There are generally three switch Methods: Forward-through forwarding, segment forwarding, and storage forwarding.

Forward through: After the switch detects the directory address, it forwards the data frame. That is to say, it starts forwarding as long as it reads the target address. You can analyze the format of the data frame, add the leading bits and the object address, that is, about 14 bytes. You do not need to analyze them later. This reduces latency, but is not suitable for networks with high error rates. Because some data collision frames are smaller than 64 bytes, they will also be forwarded together!

Fragment forwarding: similar to forward through, it only detects the first 64 bytes of the frame during forwarding. The first 64 bytes contain a small part of data, the advantage is that you can discard bad frames smaller than 64 bytes to save bandwidth.

Storage forwarding: This is the most delayed type of forwarding. Before data forwarding, you must verify the integrity of the received frames and confirm that there are no errors before forwarding. If there is an error, no forwarding is performed. The advantage is that any packet smaller than 64 bytes and damaged data packets can be discarded, but the disadvantage is that the delay is high.

Next, let's take a look at the network loop and how to use the spanning-Tree Protocol to solve the network loop.

Network Loop

Let's take a look at the figure below,

In this topology, the switch becomes a single point of failure. If the switch is broken, several modules cannot work properly at this time, and the client cannot access the server or connect to the Internet, you cannot access the printer. A single point of failure (spof) means that the entire network cannot work normally if a single point of failure occurs. Therefore, in a general exchange network, we all need to perform redundancy on the exchange machine, but the introduction of redundancy will cause another problem. A very serious problem is the network loop. Next, let's take a look at the effect of the loop on our network. There are three major impacts:

1 Broadcast storms broadcast storm

2 multiple frame copies multi-repeat data frame

3. The Mac database instability MAC address table is unstable.

Let's take a look.

Broadcast STORM: Let's take a look at the figure to see what a broadcast storm is:

Analysis: If Host X wants to communicate with other hosts on the network, the data packet is sent to switch A, but the switch still sends the report again to switch A, which is similar in sequence, A ring is formed, and it is very serious behind it. Why? When talking about the network basics, we talked about the format of the data frame. you can recall it, but in this format, there is no TTL mechanism similar to the three-layer IP header, therefore, data frames will be transmitted infinitely in the network, resulting in a broadcast storm from the surface. If unicast data is better, if broadcast or multicast data is transmitted in such a loop network, the broadcast storm becomes more apparent.

Multiple data frames: Also known as repeated data frames

Analysis: Host X is preparing to send a unicast frame to vroy Y. After the datagram is sent, it is found that there are two routes to reach vroy Y. One is to send them directly, another one is to transfer data from vswitch A to vswitch B and then to vroy Y. Then, vroy y receives two identical data frames.

There is also an unstable MAC address table:

Analysis: Host X still sends data frames to vroy Y. the MAC address table of the vro has not been learned by the vswitch, and the data frames are sent to ports 0 of exchange a and switch B along the link, then both switch a and switch B record the MAC address of Host X at Port 0. Because it is a data frame received through port 0, Port 1 of the two switches will flood outward and cross-generate Port 1 of the two switches, it is also believed that the port corresponding to the MAC address of Host X is port1, that is, the data frame sent from vswitch A comes to Port 1 of vswitch B. Then, after receiving the data, switch B again floods the traffic through port 0, and so on. The data frame repeats the above process in the loop, vswitch A and vswitch B repeatedly learn the MAC address of Host X on Port 1 and port0, resulting in unstable MAC address table.

We can see that the network loop problem is indeed not small, so the solution is to use the Spanning Tree Protocol:

Spanning-Tree Protocol:

STP for short. This protocol can be applied to loop networks. path redundancy is achieved through certain algorithms, and the loop is trimmed into a non-loop tree network, this prevents the message from being "inactive" in the Loop Network ".

The RSTP (Rapid Spanning Tree procotol) Protocol implemented by the Ethernet Exchange is an optimized version of the Spanning Tree Protocol, its "fast" is reflected in the delay between the root port and the specified port entering the forwarding state, which is greatly shortened under certain conditions, thus reducing the time required for stable network topology.

MSTP (Multiple Spanning Tree procotol) is the abbreviation of the Multi-Spanning Tree Protocol, which is compatible with STP and RSTP.

Let's introduce STP in detail: STP was created to overcome the problem of transparent bridging in redundant networks, the purpose is to negotiate a non-circular path to the root bridge to avoid and eliminate the path in the network. It identifies the location of the loop in the network and dynamically blocks redundant links. In this way, it ensures that there is only one path to each destination, so there will never be a loop.

Set a sub-optimal interface in the loop in the block state to break the loop. Note: This interface is only set to block state, but is only a state, rather than actually closing this interface. Once other links in the network have problems, the blocked interface can be restored to the forwarding status. :

Basic Idea: Every switch is called a bridge here. So when we talk about the bridge, we will know that it refers to a switch. When each switch is started, it considers itself as a root bridge, so we will discuss who is the root of the competition and define a game rule, transmit a special message BPDU (Bridge procotol data unit) between bridges. The bridge protocol data unit contains enough information to do the following: select a root bridge from all the bridges in the network, then calculate the shortest path from the local bridge to the root bridge. In addition, the root bridge sends BPDU every 2 seconds. BPDU data frame contains a lot of content ,:

Here we only relate to the bridge ID (including the priority of two bytes and the MAC address of six bytes ).

The root bridge method is to compare the bridge ID of each vswitch, that is, the bridge ID. The format of this bridge ID is:

There are two components: one is the bridge priority, and the other is the MAC address, but the Cisco switch priority is 32768 by default. If the priority is the same and the MAC address is compared later, the MAC address is definitely different, so the small one is the root bridge,

In a network, only one root bridge can exist. Other bridges are called non-root bridges. Each port on the root bridge is called an assigned port, it can also be said that each port on the root bridge is the root port, but the port name on the non-root bridge is different. A non-root bridge has a port called the root port, and other ports are called non-assigned ports.

As we said just now, if there are multiple switches and the root bridge uses bridgeid, how can I know which is the root port and which is the non-assigned port on the non-root bridge, there is also a rule that compares the cost, priority, MAC address, and port number of each port to the root bridge in sequence (from left to right, it is relatively soft ), this can be divided into multiple ports of a vswitch and multiple ports of multiple vswitches if selected.

If the same vswitch is used, the minimum cost of reaching the root bridge is the root port. The key is how to know which port has the lowest cost. This is defined based on the bandwidth.

The lower the overhead, the higher the connection rate and the faster the speed. Let's look at the figure above. There are two links, one is 100 Baset, the other is 10base-t, the other is 100, and the other is 19. The above port is selected as the root port. The following port is a non-assigned port, which will be specified as a block and unavailable until the root port is unavailable ". However, it should be noted that the port is blocked and user data cannot be sent, but BPDU can be received.

If multiple non-root bridges want to select a root port, compare the cost first. If the cost is the same, compare the priority. If the priority is the same, then compare the MAC address, this must be different.

For this figure, the port used to process the block status should be Port 1 of switch y. Because the link prices on both sides are the same and the priority is the same by default, the MAC address is compared, however, because the MAC address of vswitch X is small, its ports are in the forwarding status. However, Port 1 of vswitch y is blocked.

The above are the root bridges, root ports, assigned ports, and non-assigned ports we have analyzed. Then, a port is in four statuses, namely block, listening, learning, and forward, from starting to running normally. Let's analyze them as follows:

Block ------ In order to prevent the bridge from loop, all ports start to be in the block state. If the switch receives the same BPDU on other ports, the switch considers that there is another link to reach the root bridge. If the spanning tree determines that the other links are in a better path to the root bridge, this port continues to be block. If this port is considered by the switch as the best port, it enters the following state. This time is 20 seconds, which is called the maximum life cycle.

Listening ----- the port is changed from the block status to the listening status. During this time, it uses listening to check whether there are other paths to the root bridge. In this status, the port can listen to the configuration message, but cannot forward or receive user data. The port is not allowed to put any information it has heard into the address table, which takes 15 seconds. The listening status during this period is actually used to indicate that the port is ready for transmission, but it is willing to listen again to confirm that it will not generate a loop.

Learning ------- the learning status is very similar to the listening status. Apart from the port, you can add the information it has learned to the address table, but it still cannot send or receive user data. This process is also 15 seconds.

Forward ----- this status indicates that user data can be sent and received.

If a non-root switch does not receive any configuration information within 20 seconds, that is, if it does not receive the BPDU, it will think that the link connecting to the port is faulty, so it re-calculates the STP. Select the root bridge, root port, assigned port, and unassigned port again.

The above is a detailed introduction of the Spanning Tree Protocol. Of course we have talked so much about it, and there are not many commands that really require us to configure, because CISCO has enabled the Spanning Tree Protocol by default, I will attach relevant experiments at the end of this section to verify the role of STP.

Note that STP only works for L2 loops and does not work for physical layer loops. A L2 loop can be said to be purely artificial !!!


The purpose of generating a tree is to avoid the endless circle of forwarded frames in the network.

To obtain the Spanning Tree that reflects the changes in the network topology, the root bridge of the spanning tree must update the topology of the spanning tree at intervals!

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.