Showing posts with label Layer 3 switch. Show all posts
Showing posts with label Layer 3 switch. Show all posts

Thursday, September 14, 2023

Switch layer2 or layer3 which one to choose and why?

An Ethernet switch performs several tasks, including creating VLANs.  However, there are two types of switches: Layer 2 (L2) and Layer 3 (L3) and both are networking devices, but they operate at different layers of the OSI (Open Systems Interconnection) model and serve different purposes. 


First, a small summary about VLANs VLANs are like islands within a network. Equipment on one "island" does not have direct access to equipment on another. Thus, VLANs create isolation between parts of the network, even if the equipment is connected to the same switch.

 

However, sometimes it is necessary to have some communication between different VLANs. Either to access a server (communication between the users' VLANs and the servers' VLAN), or to access the Internet (communication between the users' VLANs and the Internet exit router). And these are just a few examples of applications where we may need to "interconnect" these "islands".

 

Here's a comparison of the Layer 2 and Layer 3 switchs:
 

Layer 2 Switch:
1. Operating Layer: Layer 2 switches operate at the Data Link Layer (Layer 2) of the OSI model.
2. Function: They are primarily responsible for forwarding Ethernet frames based on the physical MAC (Media Access Control) addresses of devices on the network.
3. Forwarding Decision: L2 switches make forwarding decisions solely based on MAC addresses, creating a table that maps MAC addresses to specific switch ports (MAC address table).
4. Local Segmentation: L2 switches are used to segment a LAN (Local Area Network) into smaller collision domains, reducing network congestion and improving network efficiency.
5. Limited Routing: L2 switches do not perform routing functions. They are unaware of IP addresses or higher-layer protocols, making them less suitable for routing traffic between different IP subnets or VLANs (Virtual LANs).


Layer 3 Switch:
1. Operating Layer: Layer 3 switches operate at the Network Layer (Layer 3) of the OSI model.
2. Function: They combine the capabilities of traditional Layer 2 switching with some routing capabilities.
3. Forwarding Decision: L3 switches make forwarding decisions based on both MAC addresses and IP addresses. They maintain a routing table to determine the best path for IP packets.
4. Routing Between Subnets: L3 switches can route traffic between different IP subnets or VLANs, effectively acting as routers. This makes them suitable for interconnecting multiple subnets within a network.
5. Advanced Routing: Some Layer 3 switches support advanced routing protocols like OSPF (Open Shortest Path First) or BGP (Border Gateway Protocol), allowing them to participate in complex routing scenarios.
6. Network Segmentation: L3 switches can create multiple VLANs and route traffic between them, enabling network segmentation for security, performance, and management purposes.
7. More Complex Configurations: Configuring and managing Layer 3 switches can be more complex than Layer 2 switches due to the additional routing functionality.


A managed L2 switch allows the creation of VLANs, but does not interconnect them. So, if I have a network made entirely of L2 switches, I can create VLANs, but I can't make them communicate. I can even use a router (which is also a Layer 3 equipment) to interconnect the VLANs, but normally a router is an equipment that has a low packet switching capacity, or - translating into Portuguese - a router can become a bottleneck in communication between VLANs.

 

An L3 switch, on the other hand, is a switch that is the same as an L2 switch (it has ports, creates VLANs, manageability, etc.) but it has a functionality that L2 switches do not have: it allows VLANs to be interconnected.

One comment before we continue: an L3 switch is a router. Many people think that a router is just the equipment that connects to the Internet. Is not true. A router is any device that connects different networks. Thus an L3 switch is also a router. So when I said above that "..but normally a router is a piece of equipment that has a low packet switching capacity..." I wasn't being 100% honest with you, reader. A router (the type that connects a network to the Internet) is normally a piece of equipment with a lower switching capacity. However, an L3 switch is a router, which is "inside" the L2 switch (that is, it does everything that an L2 switch does) and has greater capacity. Let us now return to our subject.

 

So, with an L3 switch, the network administrator can - in an organized way - communicate between the VLANs. It is important that I can have multiple L3 switches or just one L3 on my network, even though I have multiple L2 switches.

 

If I have one L3 switch and several L2 switches, that L3 switch is typically the central switch. All inter-VLAN traffic passes through it.

 

If I have several L3 switches, the cost of my project is greater and also the configuration complexity is greater. However, with several L3s I share my load, so I can have better performance in the interconnection between VLANs.

 

Nowadays, most projects aim to connect users' VLANs with the servers' VLAN and the Internet, and nothing else. In other words, nowadays most projects do not need large arrays of L3 switches: several L2 switches connected to a central L3 switch (or if I want redundancies, connected to two central L3 switches) is enough for the vast majority of the projects.

 

Choosing Between L2 and L3 Switches:


Use L2 Switches When:
• You need basic Ethernet frame switching within a single VLAN or subnet.
• Network segmentation at the IP layer is not required.
• You want a simple and cost-effective solution for LAN connectivity.
 

Use L3 Switches When:
• You need to route traffic between different IP subnets or VLANs.
• Advanced routing features like OSPF or BGP are required.
• You want to create a more secure and segmented network.
• You need efficient routing within your LAN, especially in environments with heavy inter-VLAN traffic.
 

 

In practice, many modern network switches are capable of both Layer 2 and Layer 3 operations, allowing network administrators to choose the appropriate mode based on their specific requirements. These switches are sometimes referred to as "multilayer switches." The choice between L2 and L3 switches depends on the complexity and goals of the network design.


If you have needs for Huawei switch like S5720 S6720 S6730 amd other data center switch, you can contact thunder-link.com.

Thursday, December 9, 2021

Ethernet switching - The working mechanism of a layer 3 switch

In the current live network environment, we can always see that it is the core switch like Huawei CE6800 switch that processing the data forwarding. You might be curious about that, isn't the switch forwarding Layer 2 data packets? Why are switches used at the core layer to forward data packets? Can the switch also handle IP packets? In this chapter, we will give you a detailed introduction to the working mechanism of the three-layer exchange.

As mentioned above, switches can be divided into layer 2 switches such as Huawei S1700 S2700 series and layer 3 switches, and Layer 3 switches can also forward IP packets based on the routing table, the same as routers. Is the working mechanism the same as that of routers? Obviously, the answer is no. Before comparing the forwarding process of the two in detail, let's briefly introduce the forwarding process of the three-layer switch, so that everyone can understand the forwarding process of the data packet in the layer 3 switches in more detail. For the forwarding of Layer 2 packets in the same network segment, the processing mechanism of the Layer 3 switch is the same as that of the Layer 2 switch, which is based on the destination MAC address. We will skip that part in this chapter. We are mainly concerned about the layer 3 IP packet forwarding across the network segment.

Brief architecture of the layer 3 switch

Figure 1: Brief architecture of the layer 3 switch

ASIC: Charge in layer 2 and layer 3 forwarding functions, including the MAC address table for layer 3 forwarding and the layer 3 forwarding table for IP forwarding;

CPU: Used for forwarding control. It mainly maintains software entries (including software routing tables, software ARP tables, etc.), and configures the ASIC's hardware layer 3 forwarding table according to the forwarding information of the software entries. Of course, the CPU itself can also complete the software three-layer forwarding.

Brief architecture of the layer 3 switch

Figure 2PC A and PC B communicate across network segments

Assuming that PC A wants to communicate with PC B that is not on the same network segment, we will introduce the entire communication process in detail as follows:

  1. PC A realizes that PC B is not in the same network segment as itself, and it will send an ARP request message to request the MAC address of the gateway, that is, the MAC address of the switch.

  2. After receiving the ARP request, the switch responds with an ARP reply message to PC A. At the same time, it will also record the MAC address and IP address of PC A in the ARP table.

  3. PC A encapsulates the data packet (source IP: PC A, destination IP: PCB, source MAC: PC A, destination MAC: switch) and sends it to the switch.

  4. After the switch receives the modified message, it looks up the source MAC of the message and the VLAN where the port is located to update the MAC address table and then looks up the MAC table according to the destination MAC and VLAN number for forwarding (this is a layer 2 forwarding mechanism). But the switch discovers that the destination MAC is the MAC table of its own Layer 3 interface, and the switch realizes that this packet is either sent to itself or needs to be forwarded at Layer 3. Therefore, the switch searches for the three-layer table entry of the switching chip according to the destination IP. Since notable entry has been created before, the search fails. Then, the switch sends the message to the CPU for processing.

  5. The CPU searches the routing table according to the destination IP of the message, finds the matching item (if there is no match, the message will be discarded), and continues to look up the software ARP table, but the corresponding entry is not found.

  6. The switch sends ARP request packets on all interfaces of the VLAN corresponding to the destination IP, requesting the MAC address of the destination IP.

  7. PC B responds to the ARP reply message after receiving the request. After the switch learns the MAC, it will also record the corresponding data and send the message from PC A to PC B to complete the transfer from PC A to PC B. Communication.

From PC B to PC A, since the forwarding entry has been established on the switch, subsequent messages will not be sent to the CPU, and the table lookup and forwarding process will be completed directly on the forwarding chip.

It can be known from the above process that ASIC plays an extremely important role in the forwarding process of the layer 3 switches. It can realize fast forwarding after establishing the layer 3 forwarding entry after the first communication process, thereby eliminating the need for continuous lookup of the routing table. The mechanism not only speeds up the forwarding process but also saves the occupation of system CPU resources. This is also a huge difference compared to router layer three forwardings.

Back to the question at the beginning of this chapter, why the core device of the network is often the core switch because the destination IP address of the devices in the same network to exchange data with each other is very limited, when the establishment of the layer 3 forwarding table is completed, the core switch Data will be forwarded very efficiently. For data accessing the Internet, routers will have better processing capabilities than Layer 3 switches due to the vastly different destination addresses.