What are Layer 1, 2, and 3 Ethernet Switches?
Nov 18, 2024
Leave a message
1. Layer 2 Switching Technology
Layer 2 switching technology is relatively mature. Layer 2 switches are data link layer devices that can recognize MAC address information in data packets, forward packets based on MAC addresses, and record these MAC addresses and their corresponding ports in an internal table. The specific working process is as follows:
A. When a ethernet switch receives a data packet from a certain port, it first reads the source MAC address from the packet header, thus knowing which port the machine with the source MAC address is connected to.
B. It then reads the destination MAC address from the packet header and looks up the corresponding port in the address table.
C. If the table contains a port corresponding to the destination MAC address, the data packet is directly copied to that port.
D. If the table does not find a corresponding port, the data packet is broadcast to all ports. When the destination machine responds to the source machine, the switch can learn which port corresponds to the destination MAC address, so that the next time data is transmitted, it no longer needs to broadcast to all ports.
This process keeps repeating, helping the switch learn all the MAC addresses in the network and maintain its own address table.
From the working principle of Layer 2 switches, we can infer the following three points:
A. Since the switch simultaneously exchanges data on most ports, it requires a wide bandwidth for the switching bus. If a L2 switch has N ports, each with a bandwidth of M, it can achieve line-speed switching if the total bus bandwidth exceeds N times M.
B. Learning the MAC addresses of machines connected to the ports, writing them into the address table, the size of the address table (typically represented in two ways: buffer RAM or the number of MAC entries), and the size of the address table affects the switch's capacity for access.
C. Most Layer 2 switches also contain ASIC chips (Application-specific Integrated Circuits) specifically designed for data packet forwarding, allowing for very fast forwarding speeds. The performance of products is directly affected by the ASICs used by different manufacturers.
These three points are also the main technical parameters for evaluating the performance of Layer 2 switches and Layer 3 switches. Please pay attention to these when considering device selection.
2. Routing Technology
Routers operate at the third layer of the OSI model-the network layer. Their working mode is similar to that of Layer 2 switches, but routers operate at the third layer, which determines that they use different control information and different methods to achieve their functions when forwarding packets. The working principle is that the router also has an internal table that indicates where to go next to reach a certain destination. If the router can find the next step in the routing table, it adds the link layer information and forwards the packet; if it cannot determine the next step, it discards the packet and returns an information to the source address.
Routing technology essentially has two functions: finding the best route and forwarding data packets. The routing table contains various information, and the routing algorithm calculates the best path to the destination address. Then, a relatively simple and direct forwarding mechanism sends the data packet. The next router keeps forwarding the data in the same way, and so on, until the packet reaches the destination router.
There are two different ways to maintain the routing table. One is the update of routing information, where part or all of the routing information is published. Routers learn routing information from each other, thus mastering the topology of the entire network. This type of routing protocol is called a distance vector routing protocol. The other is that routers broadcast their link state information, learning from each other to master the entire network's routing information and then calculating the best forwarding path. This type of routing protocol is called a link state routing protocol.
Since routers need to perform a large amount of path calculation work, the processing capability of the general-purpose processor directly determines its performance.
Of course, this applies to mid-to-low-end routers, since high-end routers often use a distributed processing system architecture.
3. Layer 3 Switching Technology
Recent years have seen a lot of hype about Third-Layer technology, with everyone talking about it. Some say it's a very new technology, while others say that layer 3 switching is just a stack of routers and Layer 2 switches, nothing new. Is this really the case?
3.1 Let's first look at the working process of a Layer 3 switch through a simple network.
Simple Network Setup
Device A (using IP) ----------- Layer 3 Switch -------- Device B (using IP)
For example, if A wants to send data to B and knows the destination IP, A uses the subnet mask to obtain the network address and determines whether the destination IP is in the same network segment.
If they are in the same segment but A doesn't know the MAC address needed to forward the data, A sends an ARP request, and B replies with its MAC address. A then encapsulates the data packet with this MAC address and sends it to the switch. The switch activates the Layer 2 switching module, looks up the MAC address table, and forwards the data packet to the corresponding port.
If the destination IP address shows that it is not in the same segment, A needs to communicate with B. If there is no corresponding MAC address entry in the flow cache, the first normal data packet is sent to a default gateway. This default gateway is usually set in the operating system and corresponds to the layer 3 routing module. Therefore, for data not in the same subnet, the first MAC address entry in the table is usually the default gateway's MAC address.
Then, the layer 3 module receives this data packet, queries the routing table to determine the route to B, constructs a new frame header with the default gateway's MAC address as the source MAC address and B's MAC address as the destination MAC address. Through a certain recognition trigger mechanism, the correspondence between A and B's MAC addresses and the forwarding port is established and recorded in the flow cache table. Subsequent data from A to B is directly handled by the Layer 2 switching module. This is commonly referred to as "one-time routing, multiple forwarding."
3.2 The above is a simple explanation of how a Layer 3 Ethernet switch works. It can be seen that the characteristics of Layer 3 switching are:
A. High-speed data forwarding is achieved through hardware integration.
B. This is not a simple stack of Layer 2 switches and routers. The Layer 3 routing module is directly stacked on the high-speed backplane bus of Layer 2 switching, breaking through the interface rate limits of traditional routers, with rates reaching tens of Gbit/s. Including backplane bandwidth, these are two important parameters for the performance of Layer 3 switches.
C. Simplified routing software makes the routing process more straightforward.
D. Most data forwarding, except for the necessary routing selection handled by the routing software, is handled by the Layer 2 module at high speed. The routing software is mostly highly efficient and optimized, not a simple copy of the software in routers.
4. Conclusion
Layer 2 switches are used in small local area networks. This is self-evident. In small LANs, broadcast packets have little impact, and the fast switching function, multiple access ports, and low price of Layer 2 switches provide a very complete solution for small network users.
Routers are great for large networks because they have many interface types, strong Layer 3 functions, and powerful routing capabilities. Their strengths include selecting the best routes, load distribution, link backup, and exchanging routing information with other networks.
The main job of Layer 3 switches is to speed up data forwarding in large LANs, and adding routing functions helps with that. If a large network is divided into small LANs according to factors such as departments and regions, this will lead to a large amount of inter-network access. Using only Layer 2 switches cannot achieve inter-network access.
If only routers are used, the limited number of interfaces and slow routing forwarding speed will restrict network speed and scale. Using Layer 3 switches with fast forwarding and routing functions becomes the preferred choice.
Generally speaking, in networks with large internal data traffic and high requirements for fast forwarding response, if all the work is done by Layer 3 switches, it will cause them to be overburdened and affect response speed. It's better to let routers handle inter-network routing, making the most of each device's strengths. Of course, this requires a well-funded client. Otherwise, L3 switches can also handle inter-network connectivity.