What is the difference between a layer-2 switch, a layer-3 switch, and a layer-4 switch?

Source: Internet
Author: User
Tags domain name server

1) layer-2 Exchange Technology

The layer-2 switching technology is relatively mature. The layer-2 switch is a data link layer device that can identify MAC locations in data packets.
Address information, which is forwarded based on the MAC address, and the corresponding MAC addresses and ports are recorded in a local location.
Address Table. The specific workflow is as follows:

1) when the switch receives a packet from a port, it first reads the source MAC address from the packet header so that it knows
Port on which the machine with the source MAC address is connected;2) read the target MAC address in the header and find the corresponding port in the address table;

3) if the table contains a port corresponding to the destination MAC address, copy the packet directly to the port;

4) if no corresponding port is found in the table, the data packet is broadcast to all ports. When the target machine responds to the source machine
The switch can learn which port the target MAC address corresponds.
A port is available for broadcasting.

In this process, the MAC address information of the entire network can be learned, and the layer-2 switch is established in this way and
Maintain its own address table.

The working principle of a L2 Switch can be inferred from the following three points:

1) because the switch exchanges data on most ports at the same time, a wide switching bus bandwidth is required,
If the L2 Switch has N ports, the bandwidth of each port is M, and the bandwidth of the switch bus exceeds N × M
The machine can achieve line rate switching;

2) the MAC address of the machine connected by the Learning port, which is written to the address table. The size of the address table is generally expressed in two ways:
One is beffer ram and the other is MAC table item value). The address table size affects the access capacity of the switch;

3) Another layer-2 switch generally contains ASIC Applicati dedicated for packet forwarding.
On specific Integrated Circuit) chip, so the forwarding speed can be very fast. Various manufacturers
Different ASIC specifications directly affect product performance.

The above three points are also the main technical parameters used to judge the performance of Layer 2 and Layer 3 switches. Please consider device selection.
Pay attention to the comparison.

2) routing technology

The router operates on the layer 3 of the OSI model-the network layer. Its working mode is similar to that of the Layer 2 switch.
In the third layer, the difference determines that routes and switches use different control information to implement functions when delivering packets.
Is different. The working principle is that there is also a table inside the vro, which indicates that if you want to go to a certain location
Party, the next step should be to go there. If you can find the data packet from the routing table, next step to go there, the link layer information
Add the forwarded packet. If you do not know where to proceed, discard the packet and return a message to the source.
Address.

In essence, the routing technology has two features: determining the optimal route and forwarding data packets. Write various information in the routing table
The routing algorithm calculates the Optimal Path to the destination address, and then sends data by a relatively simple and direct forwarding mechanism.
Package. The next vro that receives data continues forwarding according to the same working method, and so on until the data packet arrives.
Destination router.

There are two different ways to maintain the route table. One is the update of route information.
After the information is published, the router learns route information from each other to master the topology of the entire network.
The distance vector routing protocol is also known as the distance vector routing protocol. The router broadcasts its own link status information through mutual
Learn to master route information across the network, and then calculate the best forwarding path. This type of routing protocol is called Link Status routing.
Protocol.

Because a vro requires a lot of path computing, the performance of a general processor is determined directly.
Of course, this judgment is still for low-end routers, because high-end routers often adopt Distributed Processing System
.

3) layer-3 Switching Technology

In recent years, three-layer technology has been widely promoted, and many people call it very well.
Some people also say that layer-3 switching is nothing new than the stacking of routers and layer-2 switches.
Is that true? Next, let's take a look at the working process of a layer-3 Switch through a simple network.

Easy networking

Device A using IP ---------------------- layer-3 Switch ---------------------- using IP
Device B

For example, if A wants to send data to B and the destination IP address is known, A uses the subnet mask to obtain the network address and determine whether the destination IP address matches
You are in the same CIDR block.

If you are in the same network segment but do not know the MAC address required for data forwarding, A sends an ARP request and B returns its MAC address
Address, A uses this MAC encapsulation packet and sends it to the switch. The switch uses the layer-2 switch module to find the MAC address table and
Data packets are forwarded to the corresponding port.

If the destination IP address is not displayed in the same CIDR Block, communication between A and B is not matched in the stream cache entry.
The MAC address entry sends the first normal packet to a default gateway.
Corresponding to the layer-3 routing module. Therefore, for data not in the same subnet
The MAC address of the default gateway. Then, the layer-3 module receives the packet and queries the route table to determine whether the packet reaches B.
Route, a new frame header is constructed, with the MAC address of the default gateway as the source MAC address, with the MAC address of host B
The destination MAC address. Through A certain identification trigger mechanism, the MAC address and forwarding port of host A and host B are established.
System, and record the data into the stream cache entry table. The data from A to B will be directly transferred to the layer-2 Switching Module. This is the case
It is often said that one route is forwarded multiple times.

The above is a brief summary of the three-layer switch process. We can see the characteristics of the three-layer switch:

Hardware is used together to achieve high-speed data forwarding.

This is not a simple superposition of Layer 2 switches and routers. The Layer 3 routing module is directly superimposed on the Layer 2 switching high-speed backend.
On the board bus, it breaks through the interface speed limit of traditional routers, and the speed can reach dozens of Gbit/s. Calculate the bandwidth of the backboard.
These are two important parameters for the performance of a layer-3 switch.

The simple routing software simplifies the routing process.

Most of the data forwarding, except for the necessary route selection to be handled by the routing software, is the second-layer module for high-speed forwarding,
Most of the routing software is processed efficient optimization software, not simply copying the software in the router.

Conclusion

L2 switches are used in small local networks. There is no need to talk about this. In a small LAN, broadcast packets have little impact.
The two-layer switch's fast switching function, multiple access ports, and low cost provide a perfect solution for small network users.
Solution.

The advantage of a vro lies in its rich interface types, powerful L3 functions, and powerful routing capabilities. It is suitable for large-scale
The advantage of inter-network routing is to select the best route, load balancing, link backup, and routing with other networks.
Information exchange and so on.

The most important function of a layer-3 switch is to speed up data forwarding within a large local area network.
It serves this purpose. If a large network is divided into small local networks by department, region, and other factors,
This will lead to a large number of Internet mutual access, simply using a layer-2 switch cannot achieve Internet mutual access; for example, simply using a route
Because the number of interfaces is limited and the route forwarding speed is slow, the speed and scale of the network are limited.
A layer-3 Switch with fast forwarding becomes the first choice.

In general, in a network with a large volume of intranet data streams that require fast response forwarding, for example, all three-layer switches do this
The layer-3 switch is overloaded, and the response speed is affected.
To make full use of the advantages of different devices, is a good networking strategy, of course, the premise is that the customer's pockets are great,
Otherwise, it would take a second step, so that layer-3 switches are also interconnected over the Internet.

A simple definition of layer-4 switching is that it is a function that determines that the transmission is not only based on the MAC address (layer-2 network
Or source/Target IP address (layer-3 route), and the port number is based on TCP/UDP (layer-4. Layer-4 Switching
It can be like a virtual IP, pointing to a physical server. Its transmission services are subject to a variety of protocols, including HTTP, FTP, and NFS.
, Telnet, or other protocols. These services require complex load balancing algorithms based on physical servers. In the IP world
The business type is determined by the TCP or UDP port address of the terminal, and the application interval in layer-4 switching is determined by the source and end
The IP address, TCP port, and UDP port are jointly determined.

Set up virtual IP address VIP for each server group for search in layer-4 switch.
An application. In the Domain Name Server DNS), the address of each application server stored is VIP, rather than a real service.
Server address.

When a user applies for an application, a VIP connection request with the target server group, such as a tcp syn packet, is sent
To the server switch. The server switch selects the best server in the group and uses the VIP address in the terminal address as the actual service.
And send the connection request to the server. In this way, all packets in the same range are reflected by the server switch.
Transmission between the user and the same server.
Principle of layer-4 Switching

The fourth layer of the OSI model is the transport layer. The transport layer is responsible for peer communication, that is, coordination between the network source and the target system.
Communication. In the IP protocol stack, This is a TCP transmission protocol) and UDP user packet protocol.

In Layer 4, the TCP and UDP headers contain port numbers (portnumber), which uniquely differentiate each packet.
Which application protocols are included, such as HTTP and FTP ). The endpoint system uses this information to distinguish data in packets, especially
The port number enables a computer system at the receiving end to determine the type of the IP packet it receives and hand it over to the appropriate high-level
Software. The combination of the port number and the IP address of the device is usually called "socket )".

The port numbers between 1 and 255 are retained. They are called "well-known" ports, that is, these ports are the same in all TCP/I P protocol stack implementations of the host. In addition to the "well-known" port, standard UNIX services are allocated between 256 and
Port 1024 range. custom applications generally allocate port numbers over port 1024.

You can find the latest list of allocated port Numbers on RFc1700 "Assigned Numbers. The additional information provided by TCP/UDP Slogans can be used by network switches, which is the basis for layer-3 switching.
Example of "familiar" Port Number:
Application Protocol port number
FTP 20 Data)
21 Control)
TELNET23
SMTP 25
HTTP 80
NNTP 119
NNMP 16
162 SNMP traps)
The additional information provided by the TCP/UDP port number can be used by the network switch, which is the basis for layer-4 switching.

A vswitch with the layer-4 function can act as the "virtual IP" (VIP) frontend connected to the server.

Each server and server group supporting a single or common application is configured with a VIP address. This VIP address is sent out
Go to and register on the domain name system.

When a service request is sent, the layer-4 switch identifies the start of a session by determining the start of TCP. However
Then it uses complex algorithms to determine the best server for processing this request. Once this decision is made, the switch will
The session is associated with a specific IP address, and the real IP address of the server is used to replace the VIP location on the server.
Address.

Each layer-4 switch stores a source IP address that matches the selected server and a connection table associated with the source TCP port. The layer-4 switch then forwards the connection request to the server. All subsequent packets are reinjected and forwarded between the client and the server until the switch discovers a session.

When layer-4 switching is used, the access can be connected with the real server to meet user-defined requirements.
Then, such as making each server have an equal number of accesses or allocating transmission streams based on the capacity of different servers.

How to choose a layer-4 Switch
A, speed
To be effective in Enterprise Networks, layer-4 switching must provide comparable performance with layer-3 line rate routers. Also
That is to say, layer-4 switching must be performed on all ports at full-media speed, even on multiple Gigabit Ethernet connections
So. The Gigabit Ethernet speed is equal to the maximum speed of 1488000 packets per second (assuming the worst case, that is
All packages are the minimum size defined by the network and are 64 bytes long ).

B. server capacity balancing algorithm
Based on the desired capacity balancing interval, there are many algorithms for layer-4 switches to allocate applications to servers,
There are simple detection loop recent connections, detection loop latency, or detection server closed loop feedback. In all the pre-
During testing, closed-loop feedback provides the most accurate detection that reflects the current business volume of the server.

C. Table capacity
It should be noted that the switch for layer-4 Switching requires the ability to differentiate and store a large number of sending table items. Vswitch
This is especially true for the core of a CEN instance. Many second/third-layer switches tend to send table sizes and network device
The quantity is proportional. For a layer-4 switch, this number must be multiplied by the number of different application protocols and Sessions used in the network.
Quantity. Therefore, the size of the table to be sent increases rapidly as the number of device and application types increases. Layer-4 switch design
Users need to consider the growth of tables when designing their products. Large table capacity for manufacturing support wire speed to send layer-4 traffic
High-performance switches are crucial.

D. Redundancy
The layer-4 switch supports the redundant topology. When a dual-link network card is connected for fault tolerance
A fully redundant system can be built from a server to a nic, link, and server switch.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.