Layer 2 switching and Layer 3 switching

In the second-tier network environment, the same VLAN can communicate, but different VLANs cannot communicate. If you want to communicate, you must use the third-tier equipment, so the three-tier switch must do routing and forwarding, but the second and third-tier switches are specific what differences are there?

The two-layer switch works on the second layer (data link layer) of the OSI model, so it is called a two-layer switch.

The development of the two-layer switching technology is relatively mature. The two-layer switch is a data link layer device. It can identify the MAC address information in the data packet, forward it according to the MAC address, and record these MAC addresses and corresponding ports in its own internal one. Address table.

The development of the two-layer switching technology is relatively mature. The two-layer switch is a data link layer device. It can identify the MAC address information in the data packet, forward it according to the MAC address, and record these MAC addresses and the corresponding ports in an internal address. Table. The specific workflow is as follows:

(1) When the switch receives a data packet from a certain port, it first reads the source MAC address in the packet header, so that it knows which port the machine with the source MAC address is connected to;

(2) Read the destination MAC address in the header, and look up the corresponding port in the address table;

(3) If there is a port corresponding to the destination MAC address in the table, copy the data packet directly to this port;

(4) If the corresponding port is not found in the table, the data packet will be broadcast to all ports. When the destination machine responds to the source machine, the switch can learn which port a destination MAC address corresponds to, and it will do so when the data is transmitted next time. It is no longer necessary to broadcast to all ports.

This process is repeated continuously, and the MAC address information of the entire network can be learned. This is how the Layer 2 switch establishes and maintains its own address table.

Layer 2 switching technology has developed from bridge to VLAN (virtual local area network), and has been widely used in the construction and transformation of local area networks. The second layer of switching technology is the second layer of the OSI seven-layer network model, that is, the data link layer. It forwards according to the destination MAC address of the received data packet, which is transparent to the network layer or high-level protocol. It does not process the IP address of the network layer, nor does it process the port addresses of high-level protocols such as TCP and UDP. It only needs the physical address of the data packet, namely the MAC address. The data exchange is realized by hardware, and its speed is quite fast. A significant advantage of Layer 2 switching. However, it cannot handle data exchange between different IP subnets. Traditional routers can handle a large number of data packets that cross the IP subnet, but its forwarding efficiency is lower than that of Layer 2. Therefore, if you want to take advantage of the high efficiency of Layer 2 forwarding, you must also process Layer 3 IP packets, and layer 3 switching. Technology was born.

Three-layer switching (also known as multi-layer switching technology, or IP switching technology) is proposed relative to the traditional switching concept. As we all know, the traditional switching technology operates on the second layer of the OSI network standard model-the data link layer, while the three-layer switching technology realizes the high-speed forwarding of data packets on the third layer of the network model. Simply put, the three-layer switching technology is: two-layer switching technology + three-layer forwarding technology.

A three-layer switch is a switch with some router functions.

The most important purpose of the three-layer switch is to speed up the data exchange within a large LAN. The routing function it has is also to serve this purpose. It can be routed once and forwarded many times. Regular processes such as packet forwarding are implemented by hardware at high speed, while functions such as routing information update, routing table maintenance, routing calculation, and routing determination are implemented by software. Layer 3 switching technology is Layer 2 switching technology + Layer 3 forwarding technology.

The emergence of the three-layer switching technology solves the situation that after the network segment is divided in the LAN, the subnet in the network segment must be managed by the router, and solves the network bottleneck problem caused by the low speed and complexity of the traditional router.

For example, students secretly pass a note during class. When a boy secretly passes a note to a girl, what will the girl do? Is to open the note to see what is written in it! When the layer 3 switch receives the destination mac address it is itself, it is also to decapsulate to the upper layer, check the layer 3 destination IP address, and then?

The girl opened it, and it said "please pass the note to the next person." The same is true for the Layer 3 switch. It turns out that the destination IP address is not itself, and then it performs routing-level forwarding; therefore, whether the switch is performing Layer 3 forwarding , It is at the same time that the destination mac is oneself, whether the IP address is oneself, if it is oneself, then forward something, don’t forward it.

Does the switch always check the routing table when it determines that the destination IP is not its own? No, this is the key to the switch. The switch will not check the routing table, the arp table, or the mac address table at this time; what table will the switch check?

At this time, the switch will check its own hardware forwarding table integrated in the ASIC hardware forwarding card. What content does this hardware forwarding table contain?

When the first packet comes, it is found that the hardware forwarding table does not have any entries, so the data packet must be handed over to the routing process at this time. Once handed over to the cpu for processing, it will inevitably consume cpu resources. At this time, the routing table will be checked. , And then found that this IP address is directly connected to itself, then check the arp to find out the mac address corresponding to this address, and then it can be forwarded.

In the process of deciding to forward, the switch will do at least three things. First, modify the ttl value of the IP header; second, modify the original mac address to change to its own outbound interface mac address; third, establish the switch hardware forwarding table, including the destination IP Address, the mac address corresponding to the destination IP address (next hop), the vlan corresponding to the mac address, and the corresponding port (each manufacturer has its own understanding)

In this way, when a packet comes, the switch will look at the hardware forwarding table and forward it directly without going through the routing table query, which is the principle of one-time routing of the switch and multiple-switching.

In short, Layer 2 switches are used for small local area networks. Needless to say, in a small local area network, broadcast packets have little effect. The fast switching function, multiple access ports and low cost of the two-layer switch provide a very complete solution for small network users.

The most important function of the three-layer switch is to speed up the fast forwarding of data within a large local area network, and the addition of the routing function also serves this purpose. If a large network is divided into small LANs according to factors such as departments, regions, etc., this will lead to a large number of inter-network visits, and the simple use of layer 2 switches cannot achieve inter-network visits; such as the simple use of routers, due to the limited number of interfaces and The routing and forwarding speed is slow, which will limit the network speed and network scale. The use of a fast forwarding three-layer switch with routing function becomes the first choice.

Generally speaking, in a network with large internal network data traffic and fast forwarding and response, if all the three-layer switches do this work, the three-layer switches will be overburdened, the response speed will be affected, and the routing between the networks will be overwhelmed. It is a good networking strategy to make full use of the advantages of different devices by routers. Of course, the premise is that your pockets are very bulging, or you should put it second and let the three-layer switch also serve as the Internet interconnection.

The traditional switching technology is operated on the second layer of the OSI network standard model-the data link layer, while the three-layer switching technology realizes the high-speed forwarding of data packets on the third layer of the network model, which can realize the network routing function. , And can achieve optimal network performance according to different network conditions.

Guess you like

Origin blog.csdn.net/qq_42533216/article/details/111207513