Monday, March 28, 2016

The Difference Between Layer 2 & Layer 3 Switches

The layer 2 switching and layer 3 switching are the most commonly used switches. This article will tell you a detail of layer 2 switching and layer 3 switching.

The difference between layer 2 & layer 3 switches

A Layer 2 switch does switching only. This means that it uses MAC addresses to switch the packets from a port to the destination port (and only the destination port). It therefore maintains a MAC address table so that it can remember which ports have which MAC address associated.
A Layer 3 switch also does switching exactly like a L2 switch. The L3 means that it has an identity from the L3 layer. Practically this means that a L3 switch is capable of having IP addresses and doing routing. For intra-VLAN communication, it uses the MAC address table. For extra-VLAN communication, it uses the IP routing table.

Layer 2 Switching

A Layer 2 switch works at the second layer of the OSI model and forwards data packets based on media access control (MAC) addresses. Ports on a Layer 2 switch send and receive data independently and belong to different collision domains. Collision domains are isolated at the physical layer so that collisions will not occur between hosts (or networks) connected through this Layer 2 switch due to uneven traffic rates on these hosts (or networks).
This section describes how Layer 2 switching is implemented on an Ethernet network.
A layer 2 switch parses and learns source MAC addresses of Ethernet frames and maintains a mapping table of MAC addresses and ports. This table is called a MAC address table. When receiving an Ethernet frame, the switch searches for the destination MAC address of the frame in the MAC table to determine through which port to forward this frame.
  • When the Layer 2 switch receives an Ethernet frame, it records the source MAC address and the inbound port of the frame in the MAC address table to guide Layer 2 forwarding. If the same MAC address entry exists in the MAC address table, the switch resets the aging time of the entry. An aging mechanism is used to maintain entries in the MAC address table. Entries that are not updated within the aging time are deleted from the MAC address table.
  • The switch looks up the MAC address table based on the destination MAC address of the Ethernet frame. If no matching entry is found, the switch forwards the frame to all its ports except the port that receives the frame. If the destination MAC address of the frame is a broadcast address, the switch forwards the frame to all its ports except the port that receives the frame. If a matching entry is found in the MAC address table, the switch forwards the frame to the port specified in the entry.
According to the preceding forwarding process, a Layer 2 switch maintains a MAC address table and forwards Ethernet frames based on destination MAC addresses. This forwarding mechanism fully uses network bandwidth and improves network performance. The below figure shows an example of Layer 2 switching.
layer-2-switch

Although Layer 2 switches can isolate collision domains, they cannot isolate broadcast domains. As described in the Layer 2 forwarding process, broadcast packets and packets that do not match nay entry in the MAC address table are forwarded to all ports (except the receiving port). Packet broadcasting consumes much bandwidth on network links and brings security issues. Routers can isolate broadcast domains, but high costs and low forwarding performance of routers limit the application of routers in Layer 2 forwarding. The virtual local area network (VLAN) technology is introduced to solve this problem in Layer 2 switching.

Layer 3 Switching

The layer 3 switches divide a Layer 2 network into multiple VLANs. They implement Layer 2 switching within the VLANs and Layer 3 IP connectivity between VLANs. Two hosts on different networks communicate with each other through the following process:
  • Before the source host starts communicating with the destination host, it compares its own IP address with the IP address of the destination host. If IP addresses of the two hosts have the same network ID (calculated by an AND operation between the IP addresses and masks), the hosts are located on the same network segment. In this case, the source host sends an Address Resolution Protocol (ARP) request to the destination host. After receiving an ARP reply from the destination host, the source host obtains the MAC address of the destination host and sends packets to this destination MAC address.
  • If the source and destination hosts are located on different network segments, the source host sends an ARP request to obtain the MAC address mapping the gateway IP address. After receiving an ARP reply from the gateway, the source host sends packets to the MAC address of the gateway. In these packets, the source IP address is the IP address of the source host, and destination IP address is still the IP address of the destination host.

The following is the detailed Layer 3 switching process.
As shown in the below figure, the source and destination hosts connect to the same Layer 3 switch but belong to different VLANs (network segments). Both the two hosts are located on the directly connected network segments of the Layer 3 switch, so the routes to the IP addresses of the hosts are direct routes.
Layer 3 forwarding
layer-3-switch

The above figure shows the MAC addresses, IP addresses, and gateway addresses of the hosts, MAC address of the Layer 3 switch, and IP addresses of Layer 3 interfaces configured in VLANs on the Layer 3 switch. The process of a ping from PC A to PC B is as follows (the Layer 3 switch has not created any MAC address entry):
1. PC A finds that the destination IP address 2.1.1.2 (PC B) is on a different network segment than its own IP address. Therefore, PC A sends an ARP request to request for the MACaddress mapping the gateway address 1.1.1.1.
2. L3 Switch receives the ARP request from PC A and finds that 1.1.1.1 is the IP address of its own Layer 3 interface. L3 switch then sends an ARP reply to PC A. The ARP reply carries the MAC address of its Layer 3 interface (MAC Switch). In addition, L3 switch adds the mapping between the IP address and MAC address of PC A (1.1.1.2 and MAC A) to its ARP table. The IP address and MAC address of PC A are carried in the ARP request sent from PC A.
3. After PC A receives the ARP reply from the gateway (L3 Switch), it sends an ICMP request packet. In the ICMP request packet, the destination MAC address (DMAC) is MAC Switch; the source MAC address (SMAC) is MAC A; the source IP address (SIP) is 1.1.1.2; the destination IP address (DIP) is 2.1.1.2.
4. When L3 Switch receives the ICMP request packet, it updates the matching MAC address entry according to the source MAC address and VLAN ID of the packet. Then L3 Switch looks up the MAC address table according to the destination MAC address and VLAN ID of the packet and finds the entry with the MAC address of its Layer 3 interface, the packet needs to be forwarded at Layer 3. Then L3 Switch looks up Layer 3 forwarding entries of the switching chip to guide Layer 3 forwarding.
5. The switching chip loops up Layer 3 forwarding entries according to the destination IP address of the packet. The entry lookup fails because no entry has been created. The switching chip then sends the packet to the CPU for software processing.
6. The CPU looks up the software routing table according to the destination IP address of the packet and finds a directly connected network segment, network segment of PC B. Then the CPU looks up its ARP table, and the lookup still fails. Therefore, L3 Switch sends an ARP request to all ports in VLAN 3 (network segment of PC B), to request the MAC address mapping IP address 2.1.1.2.
7. After PC B receives the ARP request from L3 Switch, it checks the ARP request and finds that 2.1.1.2 is its own IP address. PC B then sends an ARP reply carrying its MAC address (MAC B). Meanwhile, PC B records the mapping between the IP address and MAC address of L3 Switch (2.1.1.1 and MAC Switch) in its ARP table.
8. When L3 Switch receives the ARP reply from PC B, it records the mapping between the IP address and MAC address of PC B (2.1.1.2 and MAC B) in its ARP table. L3 Switch changes the destination MAC address in the ICMP request packet sent from PC A to MAC B and changes the source MAC address to its own MAC address (MAC Switch), and then sends the ICMP request to PC B. The Layer 3 forwarding entry containing the IP address and MAC address of PC B, outbound VLAN ID, and outbound port is also added to the Layer 3 forwarding of the switching chip. Subsequent packets sent from PC A to PC B are directly forwarded according to this hardware entry.
9. When PC B receives the ICMP request packet from L3 Switch, it sends an ICMP reply packet to PC A. The forwarding process for the ICMP reply packet is similar to that for the ICMP request packet except that the ICMP reply packet is directly forwarded to PC A by the switching chip according to the hardware entry. The reason is that L3 Switch has obtained the mapping between the IP address and MAC address of PC A and added matching Layer 3 forwarding entry to the L3 forwarding table of the switching chip.
10. Subsequent packets exchanged between PC A and PC B are forwarded following the same process: MAC address table lookup, Layer 3 forwarding table lookup, and hardware forwarding by the switching chip.
In a summary, a Layer 3 switch provides high-speed Layer 3 switching through one routing process (forwarding the first packet to the CPU and creating a hardware Layer 3 forwarding entry) and multiple switching processes (hardware forwarding of subsequent packets).

Thunder-link,com – the Huawei product supplier wholesales the Huawei switches at 50% off, the layer 2 switches including the Huawei S1700 SOHO&SMB switch and Huawei S2700 series switch;  the layer 3 switches including the Huawei S3700 switches,  S5700 Gigabit Switches, and S6700 10G Switches.

Telephone: 852-30623083
           Supports@Thunder-link.com            

No comments:

Post a Comment