Visualized understanding of STP protocol

Source: Internet
Author: User


The visual understanding of the STP protocol is still the same. When learning a protocol, we should first find out what the problem is, that is, the Protocol is designed to solve what problems meet what needs, then try to implement it in your mind. That is to say, if you encounter such a problem, how can you solve it without any background or any available technology. When I think of a solution, I will compare it with the standard protocol to see what I think is missing and where I understand the deviation. Only in this way can I understand the essence of the design idea of the Protocol, learning will get twice the result! If we look at RFC, IEEE, and code, we will get lost in the details. In the end, we will get tired and have no accumulation, in a few days, you don't have to wait for a review... isn't that true? Www.2cto.com for Ethernet, why is there a problem with the Minimum Spanning Tree? This is actually a kind of price paid for redundancy compensation. After all, nothing is free, and no technology can solve all the problems. Unfortunately, crazu didn't realize this, end up killing patiya... ethernet was originally a broadcast network. As long as a data frame is sent at a time, it will not be long before the data frame will be transmitted throughout the network. At that time, no device had any learning mechanism, if you receive a frame, you will not hesitate to forward it. Whether this method is faulty depends on how it is connected. If a ring occurs on the connection cable, the data frame will always surround the network, leading to a broadcast storm, if no ring exists, the data frame is automatically absorbed and disappears when it reaches the end of the cable. To understand the above text, you only need to know that the original cable is a half-duplex coaxial cable, and the device is only a two-port bridge or a multi-port HUB for flood forwarding. Is it okay to explicitly avoid loops during cabling? However, if a link has a problem, re-wiring is required, which is also not desirable. Therefore, a mechanism is required, that is, redundant wiring is provided manually, that is, Ethernet is formed into a loop, then, a software mechanism is designed to avoid the appearance of the loop, that is, to disconnect a connection through the software channel to cut off the ring, and when the link is faulty, another loop-free link can be automatically generated, which can be achieved without manual intervention. This requires that all devices can perform the preceding tasks together. All in all, STP occurs on Ethernet because of two reasons. First, ethernet was initially designed to run on a coaxial broadcast network. Second, redundancy is required. The combination of the two will result in "automatically avoiding loops and dynamically triggering update paths", and the solution to this problem is STP, that is, the Spanning Tree Protocol. Www.2cto.com any technology must have theoretical support, and STP is no exception. We almost all know the minimum spanning tree algorithm. The tree generated by the Prim algorithm grows slowly from a root, and the tree generated by the Kruskal algorithm starts to be N rootless trees, and then graft it into a tree. Although their thoughts are different, they can be the same. If you encounter an Ethernet loop problem, how can we use the existing Spanning Tree Algorithm to implement an STP protocol (to distinguish IEEE Spanning Tree Protocol? Because Ethernet is essentially a broadcasting network and data frames can be transmitted over the whole network, the Kruskal algorithm is not suitable. The essence of the Kruskal algorithm is that it can graft a free tree into a tree, on Ethernet, nothing is free. As long as the device nodes are connected by cables, they are a tree. For redundant backup, all nodes are interconnected when they are manually connected, this determines the intentional loop for Ethernet. It is better to use the Prim algorithm. The problem is that for an Ethernet with a ring, although we can see at a glance where the ring is, for devices (HUB, bridge, switch ...) they are just a machine. What we need is to build a consensus between these devices. This consensus can let every one of them know the global situation. This is the advantage of Ethernet, because it is a broadcast network. By the way, all network routing protocols, including link layer and network layer, have two algorithms. One is the protocol that is calculated separately after all nodes become global databases, for example, OSPF in the layer-3 routing protocol and Distributed Flood-Time-Dependent protocol, such as the layer-3 RIP Protocol and layer-2 STP protocol. For the former, it is relatively simple to use a global database because all databases are consistent and the computing results are also consistent. However, for the latter, distributed computing is difficult, decision-making on each node depends on other nodes, and a device may not know the status of other devices. What should I do? What is omnipotent? Time! We only need to know how long the messages sent by a node can be distributed across the network at most, so that we can know how long the messages of all nodes have been consistent. After this time, we can let it do the next step. Of course, the premise of this conclusion is that each node trusts messages from other nodes and does not tamper with messages on its own. This is a principle called "Efficiency Comes from trust" (I will write another article ). What should we do? Select a root. In the Prim algorithm, the root is randomly selected, but for devices, the word "random" is the simplest for humans, but it is too complicated for machine devices, therefore, a mechanism is required to select a root node. For each device, it needs to have [and more than] A Path to connect to the root node. For the standard Prim algorithm, any "edge" that constitutes the ring will be cut down, however, for Ethernet, the so-called edge is where the computer is located, because you also need to select a link to reach the root for the cut edge. Only in this way can not only nodes but also edges, A tree can be formed by reaching the root node through a unique link! The root of the www.2cto.com Prim algorithm is randomly selected, but this is not the case in STPs. There must be rules to determine a root, you must select a tree root among all the switches/bridges. Remember, we essentially want to cut a fully connected graph into a tree. It is relatively simple to select the root of the tree. You only need to follow certain rules, such as numbering all switches in the 802.1d, and getting the minimum value. But how do you know who is the smallest? This is exactly the time when a data frame is transmitted over an Ethernet. An Ethernet is limited in size and must be limited to several hundred meters, and the transmission time of an electrical signal within such a distance is determined, so we can confirm that, A data frame can certainly spread across the entire network within the maximum X time, and the information obtained by each device node is eventually consistent. In the implementation of this choice, messages can be broadcast in a flood manner, of course, the implementation of IEEE has been optimized, that is, when a node receives better information, it no longer broadcasts its own messages. The next step is how to cut a link. Each device has only one route to the selected root, and a device may have multiple ports, therefore, each device must select one port among the multiple ports to serve as the port to the root of the tree. How can this problem be solved? This is also achieved through flood. Since the root of the tree has been selected, it sends a frame, which will eventually reach all ports due to the Ethernet broadcast feature, each device needs to add its own measurement value when forwarding this frame, and each port of each device will receive a frame with a measurement value, each device selects one of the frames on each port with the smallest measurement value and the port to the root of the device. This port is called the root port in the IEEE Standard! Www.2cto.com so far, the Spanning Tree has actually been generated. What else do I need to do? The standard Spanning Tree Prim algorithm resolutely cut down N edge entries that constitute a loop, which is no longer needed. However, for Ethernet applications, each edge cannot be discarded, because all computers are attached to these sides. In other words, each side is attached to a computer, therefore, you must select a device node for each edge cut down by the Prim algorithm as the exit from the edge to the root of the tree. We know that the so-called edges on Ethernet are actually a single axis or twisted pair wire. They have no intelligence at all, but smart devices. When selecting the root port of 802.1d, all ports except the root port should be blocked according to the Prim algorithm, however, they may also need to carry data frames of computers on the cut-down side, rather than be cut off. Which ports need to carry the traffic of the broken edge? This is still related to the measurement. We call it measurement 3. Each port has a measurement to the root of the tree, you can also receive the measurement from the peer to the root. Different from the root port selection, this measurement 3 has added the measurement of the device to both the local end and the peer end, the root port is not included in the measurement of the device. In the end, we only need to block the ports with measurement 3 greater than measurement 3 sent from the peer end! The unblocked port is called the specified port in this step. So far, www.2cto.com has generated a tree! And the smallest tree! The required knowledge is nothing more than the Prim algorithm, Ethernet broadcast characteristics, and flooding. If you summarize the entire process, you will get three points: 1. select a root node from all devices. 2. next, select a root port for each device to go to the root node. 3. select a port to the root for each broken link again. After understanding the above process and looking at the IEEE 802.1d document, it is just a summary process and there is nothing hard to understand. Is there anything simpler and more enjoyable than learning a protocol? Reading the IEEE documentation from the beginning is easier and more enjoyable than reading the Linux code. You only need to understand the Prim algorithm and then have a brain that you like to think about, right?

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.