Compilation of computer network knowledge - Summary of data link layer knowledge (Computer Network Getting Started Reference Guide)

Chapter 3 Data Link Layer

3.1 What do we need to learn about the data link layer?

The data link layer belongs to the second layer of the five-layer computer network architecture and is the lower layer of the computer network. What we need to understand and master is as follows:

  • Point-to-point channels and broadcast channels at the data link layer, and the protocols used by these two channels (PPP protocol, CSMA/CD protocol)
  • Fundamental issues at the data link layer for point-to-point channels: framing, transparent transmission, and error detection.
  • Fundamental issues at the data link layer for broadcast channels: identifying hosts and handling data collisions.
  • Knowledge related to Ethernet MAC address.
  • The functions and applicable occasions of adapters, repeaters, hubs, bridges, and Ethernet switches.

Just focus on understanding the PPP protocol and CSMA/CD protocol, as well as solutions to several basic problems at the link layer.

3.2 Data link layer overview

Before starting to learn the data link layer, we need to clarify the concepts of some exclusive nouns.

  • Link : A link is a passive point-to-point physical line segment without any other switching nodes in the middle.
  • Node : Here we refer to any device running a data link layer protocol as a node (i.e. hosts, routers, switches, WiFi access points, etc.).
  • Frame : The data unit transmitted by the data link layer. In the data link layer, each transmission node encapsulates the datagram in a link layer frame and transmits the frame to the link.

3.2.1 Data link layer classification

The data link layer can be divided into two categories according to the channels used: point-to-point communication and broadcast communication .

3.2.1.1 Point-to-point channel

Point-to-point channel : uses one-to-one point-to-point communication.

The data link layer using point-to-point channels faces three problems:

  • Encapsulation into frames : The network layer is delivered to the data unit of the data link layer. After adding the first and last control information of the data link layer, the frame is used as the data transmission unit to continue transmitting data. This process is called encapsulation into frames . (See section 3.3 for details)
  • Transparent transmission : In the data link layer, what we mean by transparent transmission means that the data link layer is transparent (does not exist) to the data to be transmitted , that is, no matter what bit combination the data is It is placed in the frame and passes through the data link layer completely without errors. (See section 3.4 for details)
  • Error detection : During the data transmission process, bit 0 may become bit 1 due to external influence, resulting in a bit error . In order to detect whether the above problems occur during data transmission, the data link layer adopts a loop Redundancy Check (CRC) technology performs error detection. (See section 3.5 for details)

3.2.1.2 Broadcast channel

Broadcast channel : This channel uses a one-to-many broadcast communication method, so the process is more complicated. There are many hosts connected on the broadcast channel, so a dedicated shared channel protocol must be used to coordinate the data sending of these hosts.

In addition to the three problems faced by the data link layer using point-to-point channels, the data link layer using broadcast channels also faces the following two problems:

  • Identify the host : In the broadcast channel, multiple hosts share the same channel for data transmission. Therefore, each host may receive data that is not sent to itself. At this time, the "MAC address of the destination host " is often attached to the It is transmitted in a data frame so that each host in the channel can identify whether the data is transmitted to itself. If it receives data that is not sent to itself, it will generally discard the data frame directly.
  • Handling data collisions : In the broadcast channel, since multiple hosts share the same channel to transmit data, multiple hosts will send data at the same time, which will cause data collisions and prevent each host from receiving the correct data. data frame. There are many ways to deal with this situation, the most common one is the CSMA/CD control protocol.

3.2.2 Where is the data link layer implemented?

The following figure shows a typical host architecture. The subject part of the data link layer is implemented in the network adapter (network interface card, or network card). At the core of the network adapter is the link layer controller, which is usually It is a dedicated chip that implements many link layer services (framing, link access, error detection, etc.). Therefore, many functions of the link layer controller are implemented in hardware.

Although most functions of the data link layer are implemented in hardware, some data link layer functions are implemented in software running on the CPU, such as assembling link layer addressing information, activating controller hardware, Functions such as delivering datagrams up to the network layer. Therefore the data link layer is a combination of software and hardware .

Insert image description here

3.3 Encapsulation and framing

3.3.1 Basic concepts

Encapsulation into frames is the most basic service provided by the data link layer. At the sending end of the data link layer, the received datagram delivered by the network layer will be added with a header and a tail to form a frame, and the frame will be delivered to Physical layer, this process is called encapsulation into frames . At the same time, at the receiving end, after receiving the bit stream delivered by the physical layer, it delimits each frame according to the header and tail of the data frame, extracts the data, and then converts the data Delivered upward to the network layer.

In this process, the important role of the frame header and frame trailer is for frame delimitation (determining the boundaries of the frame) and adding necessary control information . Because the bit stream transmitted by the physical layer is a data stream, the data cannot be delimited.

Insert image description here

The function of adding frame header and frame trailer:

  • Add necessary control information for the data link layer
  • frame delimited

Maximum Transmission Unit (MTU): The upper limit of the length of the data portion of a frame that can be transmitted as specified by the link layer protocol.

3.3.2 Frame delimitation

When the data to be transmitted by the data link layer is text consisting of printable (keyboard input) ASCII codes, the frame delimitation can use special frame delimiters . (ASCII code is a 7-bit code. A total of 128 different ASCII codes can be formed. 95 of them can be printed, and there are 33 non-printable control characters. Therefore, these 33 non-printable control characters can be used as Frame delimiter performs frame delimitation.)

The following figure shows the concept of frame delimitation. The control character SOH is placed at the front of the frame, indicating the beginning of the frame, and EOT is placed at the end of the frame, indicating the end of the frame.

Insert image description here

Note: SOH and EOT are the names of control characters, and their hexadecimal codes are 01 and 04, not the three characters S, O, H or E, O, T.

The role of frame delimitation : determine whether the received frame is complete, and discard it if it is not complete.

3.4 Transparent transmission

The data link layer is transparent (does not exist) to the data to be transmitted, that is, no matter what bit combination the data is, it can be placed in the frame and pass through the data link layer completely without errors.

Based on the frame delimitation introduced earlier, we can find that if the transmitted data is text composed of non-ASCII codes, it may happen that the binary code of a certain byte in the data happens to be the same as SOH or EOT. At this time, the data link There will be errors in the frame delimitation of the layer, only part of the frame will be received, and then the other part of the frame will be discarded. In this case, the transmission of the data link layer hinders the correct transmission of data. At this time, the data link layer is "visible" to the data, violating the principle of "transparent transmission".

In order to solve this situation that may occur in the data link layer, we often use byte stuffing or bit stuffing to perform special processing on the data and escape the delimiters that appear in the data to prevent link Misreading of layers, resulting in opacity.

  • Byte stuffing

    In the byte stuffing method, the frame delimiters are SOH and EOT.

    Insert an escape character ESC (1B in hexadecimal encoding, 00011011 in binary) before SOH and EOT at the sender. In the data link layer at the receiver, this inserted escape will be deleted before delivering the data to the network layer. character. If an escape character also appears in the data, then insert another escape character before the escape character. If two adjacent escape characters are encountered at the receiving end, the previous escape character will be deleted. This processing method is called character padding .

Insert image description here

  • bit stuffing

    In the bit stuffing method, the frame delimiter is 01111110.

    At the sending end, the data part of the frame is scanned before sending the frame. If there are five consecutive ones, one zero will be added subsequently. In the data link layer at the receiving end, the data part of the frame is scanned. If five consecutive 1s appear, the subsequent 0s are replaced with 1s.

3.5 Error detection

3.5.1 Basic concepts

  • Bit error: During the transmission of data over the channel, bits may change from 0 to 1, or from 1 to 0, due to the influence of various external factors. This phenomenon is called a bit error .

  • Code error rate: Within a period of time, the ratio of transmitted erroneous bits to the total number of transmitted bits is called the code error rate.

    In real life, communication links are not ideal and various error detection measures must be adopted.

Cyclic redundancy check (CRC) error detection technology is currently widely used in the data link layer.

3.5.2 CRC error detection technology

CRC error detection technology is also called polynomial coding , because this coding can treat the transmitted bit string as a polynomial with coefficients of 0 and 1, and operations on the bit string are interpreted as polynomial arithmetic.

The steps of CRC error detection technology are summarized as follows:

  1. Before sending data, the sender and receiver agree on a generator polynomial G.
  2. The sender groups the data to be sent into groups of k bits, calculates an n-bit redundant code based on the data to be sent and the generator polynomial G, and adds the redundant code to the back of the data to be transmitted and sends it to the receiver. square.
  3. The receiver calculates whether there is an error in the received data by generating a polynomial G.

Calculation rules for redundant codes:

  • Use the binary modulo 2 operation to multiply 2 to the nth power by M, which is equivalent to adding n zeros after M.
  • The obtained (k + n) digit number is divided by the pre-selected divisor G with a length of (n + 1) digits, and the quotient is Q and the remainder is R. The remainder R is 1 digit less than the divisor G, that is, R It is n bits.
  • The remainder R is spliced ​​after the data M as a redundant code and sent out.

Give an example to illustrate the principle of CRC:

  • Assume k = 6, the data to be sent M = 101001, the number of redundant code bits is n = 3, and the generator polynomial G = 1101 agreed upon by both parties.
  • The dividend can be obtained as 101001000. The modulo 2 operation is performed to obtain the quotient Q = 110101 and the remainder R = 001. The sender splices R as a redundant code after M and sends it to the receiver. That is, the data sent by the sender is 101001001, in total. (k + n) bits.

Insert image description here

  • The redundant code added after the data is called the frame check sequence FCS (Frame Check Sequence).
  • The cyclic redundancy check CRC and the frame check sequence FCS are not equivalent.
    • CRC is a commonly used error detection method, while FCS is a redundant code added behind the data.
    • FCS can be obtained using CRC, but CRC is not the only method used to obtain FCS.

Notice:

If the data link layer only uses CRC error detection technology, it can only achieve error-free acceptance of frames, that is: "Any frame received by the data link layer at the receiving end, we can consider these frames with a probability very close to 1 "No errors occurred during transmission", the receiving end will discard the error frames after receiving them. Although these frames have been received, they were eventually discarded and have not been accepted. The above can be approximately expressed as "all frames accepted by the receiving end at the data link layer are error-free."

But here, what we are talking about is error-free, which means no bit errors , not just reliable transmission. If you want to achieve reliable transmission at the data link layer, it cannot be accomplished by just using CRC error detection technology. You must add frames . Numbering, acknowledgment and retransmission mechanisms .

3.6 Reliable transmission

Note: Since reliable transmission is rarely used in the data link layer of existing actual wired networks, the blogger intends to put this part of the knowledge points into the transmission layer for sorting.

3.7 PPP Agreement

3.7.1 Introduction

In the era of poor communication line quality, a reliable transmission protocol, HDLC (High-Level Data Link Control Protocol), was generally used at the data link layer. However, in today's situation where the quality of communication lines is generally good, reliable transmission protocols are generally not used in the data link layer. For point-to-point links, the relatively simple point-to-point protocol PPP protocol is currently widely used.

The PPP protocol was formulated by the IETF in 1992. After revisions in 1993 and 1994, the current PPP protocol became the official standard of the Internet in 1994.

When a user uses a dial-up phone line to access the Internet, the data link layer protocol used by the user's computer to communicate with the ISP is the PPP protocol.

Insert image description here

3.7.2 Requirements that the PPP agreement should meet

  • Simplicity: When designing the Internet architecture, the IETF placed the most complex functional parts in the TCP protocol, while the IP protocol is relatively simple and does not provide reliable packet services. Therefore, in this case, the data link layer The PPP protocol does not need to provide more functions than the IP protocol, so simplicity is the primary requirement of the PPP protocol.
  • Encapsulation into frames: The PPP protocol must specify special characters as frame delimiters.
  • Transparency: Transparency of data transmission must be guaranteed.
  • Support multiple network protocols: Able to support multiple network layer protocols simultaneously on the same physical link.
  • Supports multiple link types: Able to operate on multiple types of links.
  • Error detection: Ability to detect frames received by the receiving end and immediately discard frames with errors.
  • Detect connection status: It can automatically detect whether the link is in normal working status in a timely manner.
  • Maximum Transmission Unit: A standard default value for the Maximum Transmission Unit MTU must be set for each type of point-to-point link to facilitate interoperability between implementations.
  • Network address negotiation: A mechanism must be provided to enable two communicating network layer entities to know or be able to configure each other's network layer addresses through negotiation.
  • Data compression negotiation: A method must be provided to negotiate the use of data compression algorithms.

The PPP protocol does not need to guarantee reliable transmission and does not provide frame sequence numbers and confirmation mechanisms.

Here’s why:

  • When the probability of errors in the data link layer is low, it is more reasonable to use the simpler PPP protocol.
  • In the Internet environment, the data put in the PPP information field is IP datagrams. Reliable transmission at the data link layer does not guarantee that transmission at the network layer is also reliable.
  • The Frame Check Sequence FCS field ensures error-free acceptance.

3.7.3 Composition of PPP Agreement

The PPP agreement consists of three parts

  • A method of encapsulating IP datagrams onto a serial link . PPP supports both asynchronous links and bit-oriented synchronous links.
  • A Link Control Protocol LCP used to establish, configure and test data link connections .
  • A set of network control protocols NCP , each of which supports different network layer protocols, such as IP, OSI network layer, DECnet, and AppleTalk.

3.7.4 Frame format of PPP protocol

Insert image description here

  • The header and trailer of the PPP frame are 4 fields and 2 fields respectively.
  • Flag field F = 0x7E (The symbol "0x" indicates that the following characters are expressed in hexadecimal. The binary representation of 7E in hexadecimal is 01111110).
  • Address field A is specified as 0xFF. The address field doesn't actually work.
  • Control field C is specified as 0x03.
  • PPP is byte-oriented, and the length of all PPP frames is integer bytes.

PPP has a 2-byte protocol field.

  • If it is 0x0021, the information field is the IP datagram.
  • If it is 0x8021, the information field is network control data.
  • If it is 0xC021, the information field is PPP link control data.
  • If it is 0xC023, the information field is identification data.

3.7.5 Transparent transmission issues of PPP protocol

  • When PPP is used on a synchronous transmission link, the protocol specifies the use of hardware to perform bit stuffing (as is the case with HDLC).
  • When PPP is used for asynchronous transmission, a special character padding method is used.

3.7.5.1 Byte stuffing

When using the PPP protocol for asynchronous transmission, it will define the transfer character as 0x7E and use byte padding . The rules for byte padding are as follows:

  • Convert each 0x7E byte appearing in the information field into a 2-byte sequence (0x7D, 0x5E).
  • If a 0x7D byte appears in the information field, it is converted into a 2-byte sequence (0x7D, 0x5D).
  • If an ASCII code control character (that is, a character with a value less than 0x20) appears in the information field, a 0x7D byte must be added in front of the character, and the encoding of the character must be changed. For example, if 0x03 appears, it must be converted to 2-byte sequence (0x7D, 0x23).

The receiver performs reverse conversion on the received data to correctly restore the data information sent by the sender.

3.7.5.2 Zero bit padding

When using the PPP protocol for synchronous transmission, zero-bit padding is used to achieve transparent transmission.

  • At the sending end, as long as there are 5 consecutive 1's, a 0 will be filled in immediately.
  • The receiving end scans the bit stream in the frame. Whenever 5 consecutive 1s are found, the 0 after these 5 consecutive 1s is deleted.

Insert image description here

3.7.6 Working status of PPP protocol

The PPP protocol plays the following roles in the entire process from the user dialing up to the Internet using the PPP protocol to the final completion of the dial-up Internet access:

  • Initially, the line is in a static state and there is no physical layer connection.

  • When a user dials to access the ISP, the router's modem confirms the dial and establishes a physical connection, at which point the line becomes a link establishment state.

  • The PC sends a series of LCP packets (encapsulated into multiple PPP frames) to the router in order to establish an LCP connection. These packets and their responses select some PPP parameters to be used. After the agreement is successful, they will enter the identity verification. When the identity verification of both parties passes, they will enter the network layer protocol state.

  • When in the network layer protocol state, network layer configuration is required. NCP assigns a temporary IP address to the newly connected PC, making the PC a host on the Internet. At this time, the link is in the link open state. Data transmission can then be carried out.

  • When the communication is completed, NCP releases the network layer connection and takes back the originally allocated IP address. Next, LCP releases the data link layer connection. The last thing released is the physical layer connection, and eventually the link returns to its quiescent state.

    It can be seen that the PPP protocol is no longer a pure data link layer protocol, it also includes the content of the physical layer and network layer.

    The above process can be described with the following diagram.
    Insert image description here

3.8 Data link layer using broadcast channels

The data link layer using the broadcast channel can achieve one-to-many communication. The data link layer in the local area network uses the broadcast channel. Therefore, the blogger uses the local area network as an example to introduce the data link layer using the broadcast channel.

3.8.1 LAN

First of all, students who have studied the first chapter should have a certain understanding of LAN. Next, I will explain the characteristics, topology, transmission media used and other related knowledge of LAN in a little detail.

3.8.1.1 Characteristics and advantages of LAN

Characteristics of a local area network: The network is owned by one unit, and its geographical scope and number of sites are limited.

Advantages of LAN:

  • With broadcast function, you can easily access the entire network from one site.
  • To facilitate the expansion and gradual evolution of the system, the location of each device can be flexibly adjusted and changed.
  • Improved system reliability, availability and survivability.

3.8.1.2 Topology of LAN

There are four main types of topology structures commonly used in local area networks: star structure, ring structure, bus structure, and composite structure that combines star and bus structures.

3.8.1.3 Transmission media and media access control of LAN

LAN can use a variety of transmission media such as twisted pair, copper cable, and optical fiber. The most mainstream one is twisted pair.

The media access control methods of LAN are mainly CSMA/CD, token bus and token ring. The first two are mainly used in bus-shaped LAN, and the token ring is mainly used in ring-shaped LAN.

3.8.1.4 Two standards for local area networks

  • DIX Ethernet V2 : The world's first LAN product (Ethernet) protocol.
  • IEEE 802.3 : The first IEEE Ethernet standard.

The DIX Ethernet V2 standard has only a small difference from the IEEE 802.3 standard, so the 802.3 LAN can be referred to as "Ethernet" for short.

Strictly speaking, "Ethernet" should refer to a local area network that complies with the DIX Ethernet V2 standard.

The LAN reference model defined by the IEEE802 standard only corresponds to the data link layer and physical layer of the OSI reference model, and splits the data link layer into two sublayers: the logical link control LLC sublayer and the media access control MAC sublayer. .

  • MAC sublayer: Contents related to access to the transmission media are placed in the MAC sublayer, which shields various differences in access to the physical layer upwards and provides a unified access interface to the physical layer. The main functions include: framing and disassembly of frames, Bit transmission error detection, transparent transmission.
  • LLC sublayer: The LLC sublayer provides the network layer with four different connection service types: no confirmation and no connection, connection-oriented, confirmation and no connection, and high-speed confirmation. Regardless of the LAN protocol used, it is transparent to the LLC sublayer.

Insert image description here

Since the LAN often used in the TCP/IP system is DIX Ethernet V2 ( Ethernet ) instead of several LANs in the 802.3 standard, the logical link control sublayer LLC (i.e., the 802.2 standard) developed by the 802 committee is no longer of much use. . The adapters produced by many manufacturers are only equipped with the MAC protocol but not the LLC protocol.

3.8.2 Media sharing technology (media access control)

The data link layer using broadcast channels encounters the two additional problems mentioned above: identifying hosts and handling collisions . Therefore, media access control needs to be adopted at the data link layer to ensure that the communication between two pairs of nodes on the same broadcast channel will not interfere with each other and can correctly identify and receive signals.

3.8.2.1 Classification of media access control

Media access control is divided into two categories: static channel allocation and dynamic media access control.

  • Static channel division: This method is the four channel multiplexing methods introduced in Section 2.5. This type of method costs too much and is not suitable for local area networks.
  • Dynamic media access control: The characteristic of this method is that the channel is not fixedly assigned to the user when the user communicates, but is dynamically assigned to the user. At this time, it is divided into two types: random access and controlled access.

3.8.2.2 Random access medium access control

In random access medium access control, centralized control is not used to solve the problem of the order of sending information. All users can send information randomly according to their own needs, occupying the entire rate of the channel. However, in a bus-shaped network, when two or more users send information at the same time, frame conflicts will occur, causing the sending results of all conflicting users to fail. Therefore, there must be a protocol to solve this frame conflict problem. Commonly used protocols include ALOHA protocol, CSMA protocol, CSMA/CD protocol, and CSMA/CA protocol.

The core idea of ​​these protocols is that the winner obtains the right to use the channel through contention. Therefore, the random access medium access control protocol is also called a contention-based protocol .

3.8.2.2.1 ALOHA protocol

The ALOHA protocol is a random access system developed early by the University of Hawaii. The ALOHA protocol is divided into two types: pure ALOHA protocol and slotted ALOHA protocol .

  • Pure ALOHA protocol

    Implementation principle : When any station in the network needs to send data, it can send the data without any detection. If no confirmation is received within a period of time, the station will think that there is a conflict during the transmission process, and the sending station will wait. Send the data again after a period of time until the transmission is successful.

Insert image description here

Disadvantages : As can be seen from the above figure, when there are many network users, the probability of collision in the pure ALOHA protocol is very high. In order to overcome this shortcoming, the slotted ALOHA protocol was improved and developed based on the pure ALOHA protocol.

  • Slotted ALOHA Protocol

    Implementation principle : The time-slotted ALOHA protocol synchronizes all stations on the shared channel in time, and divides time into equal-length time slots, stipulating that frames can only be sent at the beginning of each time slot. This method can reduce the randomness of data sent by users, thereby reducing the probability of data collision and improving channel utilization.

    The sample picture is as follows

Insert image description here

In the figure above, the time slot length is T. After each frame arrives at the site, it generally needs to wait in the cache for a period of time less than T before it can be sent. When multiple frames arrive in a time slot, a collision will inevitably occur in the next time slot. The collision retransmission mechanism after the collision is similar to pure ALOHA.

Disadvantages : Although the time-slotted ALOHA protocol is improved on the basis of the pure ALOHA protocol and reduces the probability of data collision, users can still send data as they wish. Even if other stations are sending data, they will still be sent without error. Therefore, the probability of data collision is still high.

3.8.2.2.2 CSMA protocol

The previous section introduced the shortcomings of the ALOHA protocol (send data as you wish, even if other stations are sending data, it will still be sent). Therefore, if each station listens to the channel before sending, it will send data after the sending channel is free. , which will greatly reduce the probability of data collision. Based on this idea, the Carrier Sense Multiple Access (CSMA) protocol was produced . The CSMA protocol is further improved on the basis of the ALOHA protocol. The main difference between the two is that the CSMA protocol has more carrier sensing devices than the ALOHA protocol.

According to the different listening methods and processing methods after detecting that the channel is busy, the CSMA protocol is divided into three types: 1-persistent CSMA , non-persistent CSMA and p-persistent CSMA .

  • 1-persistent CSMA(1-persistent CSMA)

    Implementation principle : When a node wants to send data, it must first listen to the channel. If the channel is idle, the data is sent immediately. If there are other stations in the channel sending data, no data is sent (wait), and the channel continues to be listened to until the channel becomes free and data is sent immediately. If a data collision occurs, wait for a random period of time before listening to the channel.

    Some readers may be wondering, why does data collision occur when using 1-adherence to the CSMA protocol?

    The reason is that the propagation speed of data on the link is limited. When two sites are far away from each other, at time T1, site A listens to the channel and finds that the channel is idle, and site B listens to the channel and finds that the channel is also idle. Then site A listens to the channel and finds that the channel is also idle. Both site B and site B will send data immediately, resulting in data collision. Or at time T1, site A is sending data, and site B also wants to send data. However, since the data sent by site A has not yet been propagated to site B, site B listens to the channel and finds that the channel is idle at this time. Site B then Data will be sent immediately, and data collision will also occur.

    Disadvantages : Largely affected by propagation delay.

  • Non-persistent CSMA

    Implementation principle : When a node wants to send data, it must first listen to the channel. If the channel is idle, the data is sent immediately. If there are other stations in the channel sending data, no data is sent and listening is given up, and the above process is repeated after waiting for a random time.

    This protocol gives up listening after detecting that the channel is idle, which reduces the probability of collision caused by multiple nodes waiting for the channel to send data immediately after it is idle.

    Disadvantages : Increases the average delay of data in the network.

  • p-persistent CSMA (P-persistent CSMA)

    Implementation principle : When a node wants to send data, it must first listen to the channel. If there are other stations in the channel sending data, it will continue to listen until the channel is idle. If the channel is idle, data is sent with probability p and postponed to the next time slot with probability 1-p. If the channel is still idle in the next time slot, the data is still sent with probability p and postponed to the next time slot with probability 1-p. This process continues until the data is sent successfully or the channel is busy because other nodes have sent data. If it is the latter, wait for the next time slot and start listening to the channel again.

    This agreement is a compromise between the 1-adherent CSMA agreement and the non-adherent CSMA agreement. Persistent listening is to overcome the problem of increased delay due to random waiting in the non-persistent CSMA protocol. Sending data with p probability is to overcome the problem of 1-persistent CSMA protocol due to multiple nodes sending immediately after detecting that the channel is idle. Data causes data conflicts.

The comparison of the three CSMA protocols is summarized as follows

channel status 1-Adhere to CSMA Non-persistent CSMA p-stick to CSMA
idle Send data immediately Send data immediately Send data with probability p and postpone it to the next time slot with probability 1-p
Busy Continuous listening Give up listening and wait for a random amount of time before listening again Continuous listening
3.8.2.2.3 CSMA/CD protocol

The protocol widely used by Ethernet to solve data collisions is the Carrier Sense Multiple Access with Collision Detection (CSMA/CD) protocol . This protocol is further improved on the basis of the CSMA protocol. The protocol is suitable for bus-shaped networks and half-duplex network environments.

The workflow of the CSMA/CD protocol can be summarized in sixteen words: " Listen before transmitting, listen while transmitting, stop transmitting due to conflict, and retransmit randomly ."

  1. The station obtains the packet from the network layer, encapsulates it into an Ethernet frame, puts it in the cache, and prepares to send.
  2. The station listens to the channel, and if it finds the channel is idle, it immediately sends the frame. If it finds the channel is busy, it continues to listen until the channel is free, and then sends the frame immediately.
  3. During the process of sending the frame, the station continues to listen to the channel. If no data collision is detected, the frame is successfully sent. If a data collision is detected, the frame transmission is stopped and a congestion signal is sent to notify other stations on the channel that a data collision has occurred.
  4. After aborting the transmission, execute the exponential backoff algorithm , wait for a random period of time and then return to step 2.

Although the CSMA/CD protocol has been improved on the CSMA protocol, it still avoids data collision (the reason is also stated above, that is, the transmission speed of electromagnetic waves in the channel is limited). The figure below is a schematic diagram of the impact of propagation delay on carrier sensing.

Insert image description here

In the figure above, site A and site B are 1KM apart and connected by a coaxial cable. The propagation delay of electromagnetic waves in the 1KM cable is about 5 microseconds. Therefore, the data sent by A to B can not be transmitted to B until 5 microseconds later. Assume that the one-way propagation delay in the figure is x, and when t=0, A sends data. When t=xy, the data sent by A has not yet reached B. At this time, B detects that the channel is idle and sends the data immediately. When t=xy/2, the data sent by A collides with the data sent by B, but at this time neither A nor B knows that a collision has occurred. When t=x, B detects a collision and stops sending data. When t=2x-y, A also detects a collision and stops sending data.

  • Ethernet with CSMA/CD protocol can only use half-duplex communication

    It can also be seen from the above examples that the channel using the CSMA/CD protocol cannot transmit and receive at the same time, so the Ethernet using the CSMA/CD protocol can only perform half-duplex communication .

  • contention period

    It can also be seen from the above figure that after station A sends data, it can know whether a collision has occurred after up to twice the end-to-end propagation delay . Therefore, the Ethernet end-to-end round-trip time is also called contention . period ( conflict window or collision window ), if there is still no collision within the contention period, it means that there will be no collision in the data sent this time.

  • Minimum frame length

    In order to ensure that the sending station can detect whether a collision occurs while sending data, it needs to be able to receive whether the data it sends has a collision before it completes sending the frame. Therefore, the transmission delay of the frame must be at least twice the propagation delay of the signal in the bus . Therefore, all data frames in the bus network using the CSMA/CD protocol must be larger than the minimum frame length. When any station on the bus receives a data frame smaller than the minimum frame length, it will be discarded as an invalid frame.

    最小帧长 = 总线传播时延 * 数据传输速率 * 2
    

    So what should we do if a data frame is indeed smaller than the minimum frame length?

    If the data frame is smaller than the minimum frame length, a padding field of certificate bytes needs to be added after the data field in the MAC sublayer of the data link layer to ensure that the data frame is not smaller than the minimum frame length.

  • Binary exponential backoff algorithm

    If the data sent by two sites collides and the data is resent immediately, endless conflicts will result. Therefore, the CSMA/CD protocol uses a truncated binary exponential backoff algorithm to calculate the waiting time for retransmission after a conflict.

    Algorithm steps:

    1. Determine the basic backoff time, usually the contention period.
    2. Define parameter k, which is equal to the number of retransmissions, but k does not exceed 10, that is, k=min[number of retransmissions, 10]. When the number of retransmissions does not exceed 10, k is equal to the number of retransmissions. When the number of retransmissions is greater than 10 , k is still equal to 10.
    3. Randomly pick a number r from the discrete integer set [0,1,…,(2^k - 1)], and the backoff time required for retransmission is the contention period *r.
    4. When the number of retransmissions reaches 16 and still fails, it indicates that the network is too congested and the frame can never be sent correctly. At this time, the station at the data link layer will discard the frame and report the situation to the network layer.

    Using the binary exponential backoff algorithm can make the waiting time for retransmissions increase as the number of retransmissions increases, thereby reducing the probability of data collision and improving channel utilization.

3.8.2.2.4 CSMA/CA protocol

The CSMA/CD protocol is currently widely used in wired LANs. However, in wireless LANs, the CSMA/CD protocol cannot be used. Here’s why:

  1. "Collision detection" requires a station to continuously detect the channel while sending its own data. However, the strength of the received signal is often much smaller than the strength of the transmitted signal. This function must be implemented in wireless LAN equipment. It costs too much. .

  2. In wireless communications, there are 'shielded station' problems and 'exposed station' problems.

    • Blocking station problem

Insert image description here

 当站点A和C同时想和站点B进行通信时,由于A和C相隔较远,彼此都无法接收到对方发送的信号,因此当它们检测到信道空闲时,都会向站点B发送数据,于是就会产生碰撞。

 这种未能检测出信道上其他站点信号的问题被称为**屏蔽站问题**。
  • Exposed site issues

Insert image description here

 当站点B向站点A发送数据,站点C向站点D发送数据,但是此时,站点C能够接收到站点B发送的数据,因此它误以为当前信道是忙碌的,因此站点C就不会向站点D发送数据,这种问题就被称为**暴露站问题**。

Due to the above problems, collision detection cannot be used in wireless LAN. Once a station in a wireless LAN starts sending data, it must send the frame completely. This results in the need for data collision in the wireless LAN. Resending the entire frame will cause a serious waste of channel resources. Therefore, collisions should be avoided as much as possible in wireless LANs . At the same time, the CSMA/CA protocol introduces the concept of channel reservation, and the sending station can reserve the channel through RTS and CTS control frames.

In wireless LAN, improvements were made on the basis of the CSMA/CD protocol, and collision detection was changed to collision avoidance (CA), resulting in the CSMA/CA protocol. Note that collision avoidance does not mean that collisions can be completely avoided by using the CSMA/CA protocol, but that the protocol can minimize the probability of collisions. At the same time, in the wireless LAN, in addition to using the CSMA/CA protocol, the stop-and-wait protocol also needs to be used (the communication quality of the wireless channel is far inferior to the limited channel). That is, in the wireless LAN, after each station sends a frame, it It needs to wait for the confirmation frame from the receiver. After receiving the confirmation frame, the sender can continue to send the next frame.

There are several key points in the CAMS/CA agreement:

  • SIFS (inter frame space)

    In order to avoid collisions as much as possible, it is stipulated in wireless LAN that each time a station sends a frame, it needs to wait for a short period of time before sending the next frame. This time interval is the inter-frame interval . The length of SIFS depends on the type of frames sent by the station. There are three commonly used SIFS.

    • SIFS (Short IFS): The shortest IFS, used to separate frames belonging to the same conversation. Generally, the frame types using SIFS include ACK frames, CTS frames, fragmented data frames, and all frames that answer AP inquiries, etc.
    • PIFS (Point Coordinated IFS): Medium length IFS, used in PCF operations.
    • DIFS (Distributed Coordination IFS): The longest IFS, used for the delay of asynchronous frame contention access.
  • RTS and CTS

    As described above, RTS and CTS control frames are used for channel reservation to avoid data collisions.

    Examples are as follows:

Insert image description here

In the figure, A, B, and C represent three sites respectively. Sites A and C are both within the communication range of site B. At this time, if site A needs to send data to site B, then A needs to broadcast a short control message first. Frame RTS (Request To Send) , this frame includes the source address, destination address and the time required for this communication (including the time required to receive the confirmation frame). This frame will be received by all stations within the communication range of A (of course These stations include B). When station B receives the RTS control frame, if the channel is idle, station B will broadcast a short control frame CTS (Clear To Send) . This frame includes the duration required for this communication. time, the frame will be received by all stations within the communication range of station B. When station C and other stations receive the frame, they will suppress sending within the time specified by the CTS. When station A receives the CTS, it will Will try to send a data frame (of course, you need to follow the CSMA/CA data frame sending process ).

Note: Although using RTS and CTS control frames will reduce the communication efficiency of the network, since these two control frames are very short, compared with the decrease in communication efficiency caused by retransmission after collision of data frames, this overhead is acceptable. Yes. And whether to use control frames is not mandatory, each site can decide on its own.

  • CSMA/CA backoff algorithm

    The binary exponential backoff algorithm is also used in the CSMA/CA protocol , but the specific methods are different:

    When backing off for the i-th time, one of the 2^(2+i) time slots is selected. That is, for the first time of backing off, one must be selected from 8 time slots instead of two.

    • The i-th backoff randomly selects one of the 2^(2 + i) time slots, that is: the i-th backoff is in the time slots {0, 1, …, 2^(2 + i) – 1} Choose one at random.
    • The first backoff is a random selection of 8 time slots (instead of 2).
    • The second backoff is to randomly select one of 16 time slots (instead of 4).
    • When the slot number reaches 255 (which corresponds to the 6th backoff) it is no longer increased.

    The variable i that determines the backoff time here is called the backoff variable.

    When a station wants to send data, it uses the backoff algorithm to select a time slot in the contention window, and then sets a backoff timer based on the position of the time slot . When the backoff timer decreases to 0, data is sent. Of course, there is also a situation where the channel becomes busy again before the backoff timer decreases to 0. At this time, the value of the backoff timer will be frozen, and the channel will wait until it becomes idle again. After waiting for DIFS, the backoff timer will continue to be started. device.

  • CSMA/CA steps

    1.若站点最初有数据要发送(而不是发送不成功再进行重传),且检测到信道空闲,在等待时间 DIFS 后,就发送整个数据帧。
    2.否则,站点执行 CSMA/CA 协议的退避算法。一旦检测到信道忙,就冻结退避计时器。只要信道空闲,退避计时器就进行倒计时。
    3.当退避计时器时间减少到0时(这时信道只可能是空闲的),站点就发送整个的帧并等待确认。
    4.发送站若收到确认,就知道已发送的帧被目的站正确收到了。这时如果要发送第二帧,就要从上面的**步骤 2**开始,执行 CSMA/CA 协议的退避算法,随机选定一段退避时间。若源站在规定时间内没有收到确认帧 ACK(由重传计时器控制这段时间),就必须重传此帧(再次使用 CSMA/CA 协议争用接入信道),直到收到确认为止,或者经过若干次的重传失败后放弃发送。
    

Insert image description here

The picture above is the workflow diagram of the CSMA/CA protocol.

  • The difference between CSMA/CA and CMSA/CD

    1.CSMA/CA协议适用于无线局域网,CSMA/CD协议适用于有线局域网
    2.CSMA/CA协议不可以检测冲突,只能尽量避免冲突,CSMA/CD协议可以检测冲突。
    3.CSMA/CA协议的基本思想是发送站点先广播告知其他结点,自己要发送数据了,让其他结点在这个时间段内抑制发送。而CSMA/CD协议的基本思想是发送前先监听,一旦监听到信道空闲就发送数据,且边发边听,一旦发现碰撞,就停止发送。
    

3.8.2.3 Controlled access medium access control

The relevant protocols for controlled access medium access control mainly include: token passing protocol .

The token access protocol is mainly used in ring networks. The main steps are as follows:

  1. When the network is idle, only token frames are passed around in the loop.
  2. When the token is passed to a station that has data to send, the station will modify the flag bit of the token frame and append the data it needs to transmit to the token frame, turning the token frame into a data frame, and then convert the token frame into a data frame. The frame is sent out.
  3. The data frame is continuously transmitted along the ring. When it is transmitted to the destination address, the receiving station will copy the data of the data frame for further processing, and continue to pass the token to the next station. Each station along the way will check the frame. Whether the destination address is the same as its own, if not, continue forwarding to the next site.
  4. After the data frame is transmitted back to the sending station along the ring, the sending station will not continue to transmit the frame. At the same time, the sending station will check the frame to determine whether there is a transmission error, and retransmit it if there is an error.
  5. After the sending station completes transmitting the data, it will regenerate a token frame and pass it to the next station to hand over control of the channel.

Note: The token frame is a special MAC control frame. It does not contain information itself and is only used for channel control to ensure that only one station in the entire ring has the authority to send data at the same time.

Therefore in the loop, there will be no data collision.

3.8.3 Ethernet

3.8.3.1 Ethernet transmission media

The transmission medium currently used by Ethernet on the market is twisted pair , and it is equipped with a hub to form a logical bus topology ( physically a star topology ).

  • hub

    The hub has multiple interfaces, and each interface is connected to the computer's adapter through an RJ-45 plug using two pairs of twisted pairs. Therefore, we can think of the hub as a repeater with multiple interfaces. It works at the physical layer . Each of its interfaces simply forwards bits without collision detection , and the hub uses a special chip that can adaptively cancel crosstalk echoes , so that the stronger signals forwarded by the interface are not affected by the weaker signals received by the interface. Signal interference occurs.

3.8.3.2 MAC layer of Ethernet

  • MAC layer hardware address

    In LAN, the hardware address is also called the physical address or MAC address.

    The MAC address is equivalent to the computer's 'ID number', which is a globally unique string of 48-bit characters used to identify the computer. The location of this address is in the ROM of the computer's adapter . If a computer has multiple adapters, it will have multiple MAC addresses. At the same time, if the computer replaces the adapter, the computer's MAC address will also change. (Even if the computer's physical address has not changed).

    So, how to ensure that the MAC address in each adapter is globally unique?

    Now the IEEE registration authority RA is the legal authority for the global address of LAN. It is responsible for allocating the first 3 bytes of the 6 bytes of the address field (that is, the high 24 bits). All manufacturers of LAN adapters in the world must report to The IEEE purchases a number composed of these three bytes . The official name of this number is the Organizational Unique Character OUI , also known as the company identifier . The last three digits (lower 24 bits) of the 6-byte MAC address are allocated by the manufacturer. Note that the manufacturer must ensure that the last three digits allocated by it do not overlap.

  • MAC frame

    The data layer link frames used in Ethernet are called MAC frames.

    There are three types of MAC frames: unicast frames, broadcast frames, and multicast frames.

    Unicast frame: One-to-one, that is, the frame is used for communication between two sites.

    Broadcast frame: a group of all, that is, the frame is sent to all stations in the LAN.

    Multicast frame: one-to-many, that is, the frame is sent to multiple sites on the LAN.

    A general adapter must be able to receive and recognize the first two frames, and the third frame can be recognized using programming methods.

    An Ethernet MAC frame consists of five fields

    The first field: destination address, the address of the destination site

    The second field: source address, the address of the sending site

    The third field: Type field, used to identify the type of upper layer protocol

    The fourth field: data field, the length range is 46~1500

    The fifth field: Frame check sequence FCS, used for CRC check

    The format of MAC is as shown below

Insert image description here

Notice:

The above figure shows that there is no field in the MAC frame that identifies the frame length. So how does the MAC sublayer know how many bytes to take out of the received Ethernet frame and hand them over to the upper layer protocol?

The solution is that the encoding format used by Ethernet as mentioned before is Manchester encoding. After receiving the Ethernet frame from the sender, the MAC sublayer of Ethernet can obtain the end of the MAC frame based on the voltage change. Position, 4 bytes ahead of this position, is the end position of the data of the MAC frame. When the data field length is less than 46 bytes, the MAC sublayer will fill in a padding field of integer bytes later to ensure that the frame is larger than the minimum frame length in Ethernet.

So, when there is a padding field, after the MAC sublayer delivers the data field and the padding field to the upper layer protocol together, how should the upper layer protocol identify the padding field?

In fact, the upper layer protocol has the function of identifying the length of the valid data field. When the upper layer protocol uses the IP protocol, there is a field in the header of the datagram to identify the 'total length', so this total length + padding field is equal to the MAC delivered by the MAC sublayer. The length of the data field of the frame, so the data field can be effectively identified.

In the above figure, 8 bytes of data are inserted in front of the MAC frame. This is because when a station first receives the MAC frame, the adapter's clock has not yet synchronized with the arriving bit stream, so the maximum length of the MAC frame is The first few bits cannot be received, which will make the entire MAC frame unable to be received. Therefore, in order for the receiving end to quickly achieve clock synchronization , the sender inserts 8 bytes at the front of the MAC frame, of which the first 7 bytes are synchronization codes, which are used to enable the receiving end adapter to quickly synchronize the clock after receiving the MAC frame. Adjust the clock frequency to achieve clock synchronization. The last byte is the delimiter of the start of the frame, which is used to tell the receiving end that the position following this byte is the MAC frame.

3.8.4 802.11 Wireless LAN

3.8.4.1 Introduction

Wireless LAN is a local area network that does not transmit data through wired media media. Wireless LAN can be divided into two categories: wireless LAN with fixed infrastructure and mobile self-organizing network without fixed infrastructure. The so-called "fixed infrastructure" refers to a group of fixed base stations established in advance that can cover a certain geographical range.

  • Wireless LAN with fixed infrastructure

    IEEE has formulated the 802.11 series of protocol standards for wireless LANs with fixed infrastructure. The 802.11 series of protocols are quite complex, but in simple terms, it is the standard for wireless Ethernet . It uses a star topology , and the central point is called the access point . Access Point AP , the protocol used in the MAC sublayer is the CSMA/CA protocol introduced above. (Wireless LAN using the 802.11 standard is the most commonly used Wi-Fi in our daily lives).

    The 802.11 standard stipulates that the minimum component of a wireless LAN is the basic service set BBS . The BBS is composed of a base station and several mobile stations. All stations can communicate directly within this BBS, but if they want to communicate with sites other than the BBS, they must go through this BBS. BBS base station. The AP mentioned above is the base station of the BBS. When the network administrator sets up the AP, he will set a service set identifier SSID of no more than 32 bytes and a communication channel for the AP. The SSID is equivalent to the name of the wireless LAN using the AP. The effective range covered by a BBS is called the basic service area BSA . The diameter of a basic service area BSA generally does not exceed 100 meters.

    We can use portals to connect multiple BBSs together. The figure below shows a distribution system DS consisting of two BBSs.

Insert image description here

In the figure above, site A wants to communicate with site A', then its data flow path is A->AP1->AP2->A'.

  • Mobile self-organizing network without fixed infrastructure

    The mobile self-organizing network without fixed infrastructure has no access point AP. It is a temporary network composed of some mobile stations in an equal state communicating with each other.

    This kind of network is often used in special activity scenarios. For example, in the military field, soldiers carrying mobile stations can communicate using temporarily established mobile ad hoc networks. When a natural disaster occurs, it is often very effective to use mobile ad hoc networks for timely communication during rescue and disaster relief.

    Mobile ad hoc networks are not mobile IP. Mobile IP technology allows roaming hosts to connect to the Internet in a variety of ways. Its core network functions are still based on various routing protocols that have been used in fixed networks, while ad hoc networks are Mobility extends to autonomous systems in the wireless realm, with their own specific routing protocols that may not be connected to the Internet.

3.8.4.2 MAC layer of 802.11 LAN

There are three types of MAC frames in 802.11 LAN: control frames , data frames and management frames .

The data frame consists of three parts: MAC header , frame body and frame check sequence FCS .

  • The MAC header is 30 bytes in total. The complexity of the frame is in the header of the frame.

  • The frame body , which is the data part of the frame, does not exceed 2312 bytes. This value is much longer than the maximum length of Ethernet. However, the length of 802.11 frames is usually less than 1500 bytes.

  • The frame check sequence FCS is the tail , a total of 4 bytes.

The most special thing about the 802.11 data frame is that it has four address fields. Address 4 is used for ad hoc networks. We only discuss the first three types of addresses here.

Go to AP from AP Address 1 Address 2 Address 3 Address 4
0 1 Receiving address = destination address Sending address=AP address source address ---------
1 0 Receiving address=AP address Sending address = source address Destination address ---------

Address 1 is the node address that directly receives the data frame, and address 2 is the node address that actually sends the data frame.

Based on this, we discuss two situations to help you understand the contents of the above table.

  • Now assume that site A in a basic service set BBS sends a data frame to site B. In the frame control field of the data frame sent by site A to the access point AP, "To AP=1", "From AP=0", address 1 is the MAC address of the access point AP, and address 2 is that of site A. MAC address, address 3 is the MAC address of site B. After AP receives the data frame, it forwards it to site B. At this time, in the frame control field of the data frame, "To AP=0", "From AP=1", address 1 is the MAC address of site B, and address 2 is The MAC address of the AP, address 3 is the MAC address of site A.

  • Now assume that there are two APs connected to the router through wired links. Now the router wants to send data to site A. Since the router is a network layer device, it cannot "see" the access point AP of the data link layer. It only knows the access point AP of site A. IP address, and the AP is a data link layer device. It only knows the MAC address, not the IP address. The specific structure is shown in the figure below

Insert image description here

(1)路由器向站点A发送数据的情况模拟
路由器从IP数据报获取站点A的IP地址,使用ARP获取站点A的MAC地址后,路由器接口R1将该IP数据报封装成802.3帧,该帧的源地址是R1的MAC地址,目的地址是站点A的MAC地址。当AP收到该帧后,将该帧转换为802.11帧,在帧控制字段中,“去往AP=0”,“来自AP=1”,地址1时站点A的MAC地址,地址2是AP的MAC地址,地址3是R1的MAC地址。于是站点A就可以通过地址3确定将数据报发送到子网中的路由器接口的MAC地址了。
(2)站点A向路由器接口R1发送数据的情况模拟
站点A生成一个802.11帧,在帧的控制字段中,“去往AP=1”,“来自AP=0”,地址1是AP的MAC地址,地址2是站点A的MAC地址,地址3是R1的MAC地址。当AP接收到该802.11帧后,将其转换为802.3帧,该帧的源地址字段为站点A的MAC地址,目的地址是R1的MAC地址。

It can be seen from the above situation simulation that address 3 plays a key role in the interconnection between BBS and limited networks. It allows the AP to determine the MAC address of the destination address when constructing an Ethernet frame.

3.9 Data link layer equipment

3.9.1 Bridge

The bridge works in the MAC sublayer of the data link layer and is used to connect multiple Ethernet hardware devices. After multiple Ethernets are connected through it, a larger Ethernet is formed. At this time, the original Each Ethernet network is called a network segment .

The network bridge isolates each network segment into independent collision domains (conflict domains). Each network segment is relatively independent, so a failure in one network segment will not affect the normal operation of other network segments.

The bridge has a path selection function. After receiving the frame, it can determine the correct path to forward the frame to the correct station.

When network 1 and network 2 are connected through a bridge, after the bridge receives the data frame sent by network 1, it will query the address in the data frame. If the address is the address in network 2, then it will be forwarded to network 2. If If it is the address of Network 1, it will be discarded. Because the source site and the destination site are on the same network segment, the destination site can receive the frame directly without the need for a bridge to forward it.

3.9.2 Adapter

The adapter introduced here is also called a network adapter (Adapter) or a network card. It is a bridge used to connect the computer to the external LAN. There is a processor and memory in the adapter, which is a network component that works at the data link layer. The communication between the adapter and the LAN is carried out in a serial manner through a twisted pair , while the communication between the adapter and the host is carried out in a parallel manner through the I/O bus on the computer motherboard . Therefore, the important function of the adapter is to serialize data. Parallel conversion.

Every adapter in the world has a unique code when it leaves the factory. This code is the MAC address mentioned above.

3.9.3 Hub

The hub has been introduced above, see 3.8.3.1 for details.

3.9.4 Switch

The switch introduced here refers to an Ethernet switch . An Ethernet switch is essentially a multi-port bridge that works at the data link layer.

3.9.4.1 Characteristics of Ethernet switches

  • Each interface of an Ethernet switch is directly connected to a single host or another Ethernet switch, and generally operates in full-duplex mode.
  • Ethernet switches are parallel and can connect multiple pairs of interfaces at the same time, allowing multiple pairs of hosts to communicate at the same time.
  • Hosts connected using Ethernet switches all have exclusive transmission media and transmit data without collision .
  • An Ethernet switch is a plug-and-play device, and its internal frame forwarding table is automatically and gradually established through a self-learning algorithm .
  • Ethernet switches use dedicated switching fabric chips with high switching speeds.

3.9.4.2 Advantages of Ethernet switches

  • Users using Ethernet switches have exclusive bandwidth, increasing total capacity.

    For an ordinary 10 Mbit/s shared Ethernet, if there are N users in total, the average bandwidth occupied by each user is only one-Nth of the total bandwidth (10 Mbit/s).

    When using an Ethernet switch, although the bandwidth from each interface to the host is still 10 Mbit/s, since one user is exclusively communicating rather than sharing the transmission media bandwidth with other network users, for a switch with N interfaces The total capacity is N 10 Mbit/s.

  • When switching from shared bus Ethernet to switched Ethernet, no changes are required to the software and hardware of all access devices, adapters, etc.

  • Ethernet switches generally have interfaces with multiple speeds, which is convenient for users in various situations.

3.9.4.3 Switching mode of Ethernet switch

Ethernet switches have two switching modes: pass-through switches and store-and-forward switches .

  • pass-through switch

    When receiving a data frame, it immediately determines the forwarding interface of the frame according to the destination MAC address of the data frame. This method has a fast switching speed, but it forwards the frame directly without checking for errors, so it is possible that some invalid frames will be forwarded to other stations.

  • store-and-forward switch

    Using the store-and-forward method, the received frame is first cached in the switch's cache, error detection is performed, and after confirmation, the frame is converted into an output port through a lookup table and forwarded out. If an error is found in a frame, the frame is discarded.

3.9.4.4 Self-learning function of Ethernet switch

After an Ethernet switch receives a data frame, the process of deciding whether the frame should be forwarded to an interface or discarding the frame is called filtering , and deciding which interface the frame should be moved to is called forwarding .

The filtering and forwarding functions of an Ethernet switch are completed through the switching table . The entries in the switching table include: a MAC address and the switch interface connected to the MAC address .

Next, we use an example to understand how an Ethernet switch performs self-learning.

Assume that the Ethernet switch has four interfaces, each interface is connected to a host, and the MAC addresses of the four hosts are A, B, C, and D respectively. Initially, the switching table of the Ethernet switch is empty, as shown in the figure below.

Insert image description here

A first sends a frame to B and enters the switch through interface 1. After receiving the frame, the switch first searches the switching table and finds that it does not find out which interface the frame should be forwarded from. Therefore, the switch writes the source address A and interface 1 of the frame into the switching table, recorded as (A,1), and Broadcast this frame to all interfaces except interface 1 (this frame comes from interface 1, of course it should not be forwarded out from interface 1). C and D will discard the frame after receiving it because the destination address is B. Only B can accept this frame.

It can be seen from the newly written record (A,1) in the switching table that no matter which interface the frame is received from in the future, as long as the destination address is A, the switch should forward the received frame out of interface 1. (The basis for this action is that since the frame sent by A enters the switch through interface 1, the frame forwarded from interface 1 of the switch should also be able to reach A).

When B receives the data frame sent by A, it will send the frame to A through interface 3. The switch looks up the switching table and finds that there is A in the MAC address in the switching table, so it forwards the frame to interface 1. At the same time, the switch A new record (B,3) will be added to the table.

After a period of operation, as long as hosts C and D send frames to other hosts, the switching table will gradually record the interfaces corresponding to hosts C and D. Of course, considering that sometimes the host may need to be replaced on the switch interface or the host needs to replace the adapter, therefore, entries with valid time will be set up in the switching table, and records that exceed the valid time will be automatically deleted.

Insert image description here

The self-learning capability of Ethernet switches allows Ethernet switches to be plug-and- play without manual configuration.

references

《计算机网络:自顶向下方法第七版》- Kurose
《计算机网络(第7版)》-谢希仁
《2023年计算机网络考研复习指导》-王道论坛

If this article is helpful to you, you may wish to like, forward, and save it~

Guess you like

Origin blog.csdn.net/weixin_42584100/article/details/124916577