Discussion on the Working Principle of Switches

 

  • Fundamental

There are many types of switches, which can be divided into two-layer switches, three-layer switches, four-layer switches and high-level switches according to the level of packet processing. The number of processing layers in the back of these types is sequentially increased compared with the front ones, and the specific number of layers can also be seen from its naming. So let's start with the simplest Layer 2 switch, and reveal the secrets of the internal working principle of the switch layer by layer.

In Layer 2 switching, the switch implements end-to-end switching according to the mac address. It maintains an address table of the mac address and the corresponding port internally. For distribution, if there is a port corresponding to the destination mac, the packet will be directly copied to this port; if not, the packet will be broadcast, and the mapping relationship will be learned when there is a response.

Influencing factors in Layer 2 switching include: bus bandwidth (the wire speed requires n×m, n is the number of ports, and m is the bandwidth of each port), and the size of the mapping table.

Layer 3 switching is not a simple stack of Layer 2 switching. In addition to Layer 2 switching modules, it also has Layer 3 routing modules. The working principle of the three-layer module is similar to that of a router. It maintains a routing table and a flow cache table (is it the address table in the two-layer module) . The destination ip, plus your own mac and then send it out, and determine the corresponding relationship between the mac address of the sender and the receiver and the forwarding port through a certain identification trigger mechanism, and record it into the stream cache table. After that, the data of the two will be directly by The second floor module is completed. This is what is commonly referred to as one route, multiple forwarding.

In a Layer 3 switching environment, when a machine sends a packet to another machine, the sending machine checks the destination IP address: if it is a local address, it will arp cache-arp, encapsulate it, and then send it to the Layer 2 module of the switch; if it is not a local address, it will Check the routing table. If there is no corresponding one in the routing table, it will be sent to the default route. Generally, the default route corresponds to the layer-3 module of the switch. (How to send this package to the two-layer module or the three-layer module differently?)

Influencing factors in Layer 3 switching are: port speed, backplane bandwidth (the Layer 3 module is on the backplane bus).

Four-layer switching is based on the application type of the packet request, and is distributed among various application types of servers. It judges the requested service type according to the tcp/udp port, sets up a VIP for the server group to be used, and uses a certain algorithm for the client's request. The scheduling server, once a session is established, replaces vip with the server's ip and establishes a port mapping relationship; in addition, it maintains a connection table associated with the source IP address and source TCP port of the selected server internally, Used to save sessions.

 

It can be seen from the above that the increase of switch application functions is at the cost of speed. The four-layer switch almost integrates various functions such as switching, routing, and load balancing. It is conceivable how busy it is in such a box.

  • internal structure

 

  • example

There are so many switch manufacturers nowadays, in addition to supporting some functions stipulated by international standards, they also have many own features. The picture below is the process of TNETX 3270 processing a data packet after Vlan is set :

As an example of a single packet, for example, Chris sends a data packet to Jackie (see Figure 3 for the structure), the process is as follows:

The packet arrives at port 9 of switch 1 , which is a packet with no tag header, so switch 1 adds a VLAN ID to the packet .

Query the database according to the destination mac address and vlan id , and know that the data packet needs to be sent to port 24 (or 25 , 26 , these 3 ports are bundled together, for the upper layer, these 3 ports are like a port , in fact, the switch will decide which port to send out from according to the traffic of the 3 ports) . If not known, the data packet will be sent to port 6. Of course, when sending to the Ethernet segment of port 6 , the label header will be removed first, and Altaf will discard the data packet after receiving it, because the destination address is not it. Since port 24 is a Tag Aware port, the tag header of the data packet sent to port 24 is not removed .

After TNETX 4090 switch receives this data packet, it looks up the route in its database according to the VLANID and destination MAC address. Finally, it knows that the data packet should be sent to port 4 ( 5 or 6 ), and the tag header is still not removed.

After switch 2 receives it, it searches the route in its database according to the VLAN ID and destination MAC address, and knows that the data packet needs to be sent to port 2 . Then send the packet out. Note that the sent data packets need to remove the tag header.

  • References:
  1. http://cisco.ynnu.edu.cn/show.aspx?ID=185
  2. http://www.pconline.com.cn/pcjob/nettech/cisco/others/0404/364151_4.html (and four others)

For more technical articles, please move to the official account: zhuji101

Guess you like

Origin blog.csdn.net/spacetiller/article/details/111269396