The switch is a 2-layer device applied in the switched network. It realizes the functions of address learning and frame forwarding according to the hardware address on the data frame. It has six working principles, which are detailed as follows.
Learning based on source MAC address.
The switch receives frames and forwards frames, and the upper IP packets form frames after receiving two layers of encapsulation. There are destination MAC address and source MAC address in the frame structure. The destination MAC address is the hardware address of the host to which the frame is going, and the source MAC address is the address of the device encapsulating the frame. At the beginning, the switch does not know which interface the corresponding destination MAC address will be sent from, so it has to send the address from many other interfaces, but this is not appropriate every time, which will occupy the bandwidth of the network. Therefore, every time a data frame is received, the switch will record the interface receiving the frame and the source MAC address in the frame, and correspond them. In this way, the switch will know which interface corresponds to which MAC address, thus forming a MAC address table. After a period of time, the MAC address table will stabilize. Then, when a data frame is received, the switch can look at the destination MAC address in the frame, and then look up the MAC address table to know which interface it should be sent from.
Forwarding based on destination MAC address.
As mentioned above, after getting the MAC address table, when receiving a frame, the switch can check the destination MAC address, find the interface corresponding to the address in the MAC address table and forward it.
The same interface can learn multiple MAC addresses.
This situation may be hard to imagine at the moment. Take a look at the following topology.
When multiple devices are connected to the switch through a hub, the data will be forwarded between these devices. Due to the simple characteristics of the hub, the hub will also send the data to the switch, so it is possible for the same interface of the switch to learn multiple MAC addresses. At this time, if host 0 and host 1 communicate with each other, the switch will receive a frame whose source MAC address is host 0 and destination MAC address is host 1. Both addresses point to the same interface. At this time, the switch will not forward this frame, because an interface learning multiple MAC addresses indicates that the two devices can communicate before the appearance of the switch. There is no need to go through the switch.
The same MAC address Link for more is learned by multiple interfaces, and the later-interface should be selected.
Let’s simulate that the same MAC address is learned by multiple interfaces
The switch has two interfaces connected to the hub, so the MAC addresses of host 2 and host 3 will be learned on both interfaces. However, there cannot be two destination MAC address entries in the MAC address table of the switch, so the switch will only select one. In order to update in time, the switch selects the interface which learned the address later as the forwarding interface. This can be considered in a case that if a host really changes its physical location and connects to another interface of the switch, it needs to update the MAC address table in real time.
When receiving the broadcast / multicast frame, the switch will forward it to all other interfaces of this VLAN.
When receiving a frame whose destination address is broadcast or multicast address, the switch will flood the frame from all interfaces except the receiving interface. If VLAN strategy is deployed, it will be forwarded to all interfaces belonging to the same VLAN.
For frames without destination MAC address entries, the switch forwards them to all other interfaces of this VLAN.
Some frames may have no destination MAC address. In this case, the switch’s strategy is to forward this frame according to the strategy of broadcast or multicast frame.
In conclusion, as a 2-layer device, the switch works at the data link layer and is responsible for forwarding data frames. While forwarding frames, it will also go through a learning process, so that it can have clear targets in the process of forwarding frames later, instead of always using flooding to waste bandwidth. spotodumps.com