[Computer Network]-Link Layer-Switched LAN

Preface

In a switched LAN , all sites are connected to a switching hub or LAN switch. The switching hub or LAN switch has a switching function. When the workstation needs to communicate, the switching hub or LAN switch can connect many ports at the same time, coordinate these workstations, so that each pair of ports can transmit data without conflict like exclusive communication media.

Link layer addressing and ARP

MAC

We know that hosts and routers and routers have link layer addresses. In fact, it is their adapters that have link layer addresses. Therefore, a host or router with multiple network interfaces will have multiple link layer addresses corresponding to it.
But link layer switches do not have link layer addresses corresponding to their interfaces, because the switch's task is to carry datagrams between the host and the router and perform this task transparently, without the host or router having to explicitly address it. to the switch in between, then the switch naturally does not need the link layer address attribute.

There are many kinds of link layer addresses: LAN address, physical address or MAC address , among which MAC address is the most popular.
The length of MAC address is 6 bytes, and there are 248 possible MAC addresses in total. Addresses are usually expressed in hexadecimal notation, where each byte is represented as a pair of hexadecimal numbers. Although MAC addresses are designed to be permanent, it is possible to change an adapter's MAC address using software.

Some properties of MAC addresses

  1. No two adapters have the same MAC address, and the IEEE manages the MAC address space to ensure this property. When a company wants to produce adapters, it needs to purchase an address space that consists of 224 addresses, and then the company itself generates a unique combination of the last 24 bits for each adapter.
  2. The MAC address has a flat structure (as opposed to a hierarchical structure) and does not change no matter where the adapter is used. For example, a laptop with an Ethernet interface always has the same MAC address, no matter where the computer is located. In contrast, the IP address has a hierarchical structure, that is, the network part plus the host part, and when the host moves, its IP address needs to change, that is, change the network it is connected to.

Frame sending and receiving

When an adapter wants to send a frame to some destination adapter, the sending adapter inserts the MAC address of the destination adapter into the frame and sends the frame to the LAN

An adapter can receive a frame that is not addressed to it because a switch occasionally broadcasts an incoming frame to all its interfaces. So when the adapter receives a frame, it will check whether the destination MAC address in the frame matches its own MAC address. If it matches, it will extract the encapsulated datagram and pass it up the protocol stack; if it does not match, it will discard the frame

When the sending adapter does want all other adapters on the LAN to receive and process the next frame it is about to send, it inserts a special MAC broadcast address (FF-FF-FF-FF-FF) into the frame's destination field. -FF)

Why do host and router interfaces have MAC addresses in addition to network layer addresses?

  1. First, LANs are designed for any network protocol, not just IP and the Internet. If an adapter is assigned only an IP address and no "neutral" MAC address, the adapter will not be able to easily support other network layer protocols.
  2. Second, if the adapter uses a network layer address instead of a MAC address, its network layer address must be stored in the adapter's RAM and reconfigured each time the adapter is moved; another option is to not use any addresses in the adapter, The problem with having the adapter pass every datagram it receives up, and letting the network layer check that the network addresses match, is that the host will be interrupted by every frame sent on the LAN, even if the destination is on the same broadcast LAN. other nodes of
  3. In summary, the specification requires that in order for the layers in the network architecture to be very independent building blocks, the different layers need to have their own addressing schemes

Address Resolution Protocol ARP

Address Resolution Protocol ( Address Resolution Protocol Address\ Resolution\ ProtocolA dd ress Reso l u t i o n Pro t oco l   (ARP) task is to convert between a network layer address such as an IP address and a link layer address that is a MAC address .

In the same subnet , if the source host wants to send a datagram to the destination host, the source must provide not only the IP datagram but also the MAC address of the destination host to its adapter, and then the sending adapter can construct a datagram containing the destination host. MAC address of the link layer frame, and send it to the LAN
Then the problem here is how to determine the MAC address of the destination host: the ARP module of the source host will take as input any IP address on the same LAN , and will return the corresponding Specifically, each host or router has an ARP table
in its memory , and this table contains the mapping relationship between IP addresses and MAC addresses. In addition to these two fields, each record in the foreign table also contains a lifetime TTL value, which indicates the time when each mapping is deleted from the table. From the time it is placed in an ARP table, the expiration time of an entry is usually 20 minutes.

When a host needs to send a datagram to another host or router in the subnet, it needs to obtain the MAC address of the destination host with a given IP address
. The value of this MAC address can be directly obtained
. If there is no corresponding entry in the table, in this case, the sender will use the ARP protocol to resolve this address:

  1. First, the sender constructs a special packet called an ARP packet . An ARP packet has several fields, including the IP address and MAC address of the sending and receiving hosts. ARP query packets and response packets have the same format.
  2. The sender then passes the ARP query packet to its adapter and indicates that the adapter should send the packet using the MAC broadcast address .
  3. So the adapter encapsulates this ARP packet in the link layer, uses the broadcast address as the destination address of the frame, and transmits the frame to the subnet
  4. The frame containing the ARP query can be received by all other adapters on the subnet. Receiving does not mean receiving, but due to the broadcast address, each adapter will receive and pass the ARP packet in the frame up to the ARP module
  5. Each ARP module checks whether its IP address matches the destination IP address in the ARP packet. The one that matches will send back an ARP response packet with the desired mapping to the querying host.
  6. The querying host can then update its ARP table and send its datagrams based on the mapping.

Send datagram outside subnet

In order to send a datagram with a destination address in a different subnet, the datagram must first be sent to the first-hop router, find the MAC address corresponding to the router's IP through the ARP protocol, and then send the frame containing the datagram to the router.

The router finds the interface to forward the datagram by querying the forwarding table, and sends the datagram to the router of the destination subnet through one or more forwardings. The router then finds the MAC address of the destination IP address of the datagram through ARP, and forwards it to the destination. IP host is enough

Ethernet

Ethernet technology provides connectionless and unreliable services to the network layer. It only performs CRC check on the frame, and does not send a confirmation frame when the frame passes the check, and does not send a negative confirmation when the frame fails the check. frame, just discard the frame. Therefore, the sending adapter has no idea whether the frame it transmitted has reached the receiving adapter and whether it has passed the CRC check.

Reliable delivery of data can only be guaranteed by the upper layer protocol, such as the transport layer using the TCP protocol. In this case, the missing or discarded data will arrive at the receiving adapter again. In this sense, Ethernet does retransmits the data, although it does not know whether it is transmitting a completely new datagram or a datagram that has been transmitted at least once

frame structure

The life course of a frame is roughly as follows: the adapter of the host sending the frame encapsulates an IP datagram in an Ethernet frame and passes the frame to the physical layer; the receiving adapter receives the frame from the physical layer and extracts the IP data report and pass the IP datagram to the network layer

illustration

  • Data : This field is 46 ~ 1500 bytes long, which carries IP datagrams

    The maximum transmission unit MTU of Ethernet is 1500 bytes, which means that the length of an IP datagram can only reach 1500 bytes at most, and if it exceeds 1500 bytes, the host must fragment the datagram

    If the IP datagram length is less than 46 bytes, it must be padded to 46 bytes. When padding is used, the data passed to the network layer will contain the IP datagram and the padding part. The network layer uses the IP datagram header. Length field to remove padding

  • Destination address : This field is 6 bytes long and contains the MAC address of the destination adapter, and of course the broadcast address. If the destination address of the frame received by the receiving adapter is its own MAC address or a broadcast address, it will pass the contents of the data field of the frame to the network layer; if it is any other MAC address, the frame will be discarded.

  • Source address : also 6 bytes long, the content is the MAC address of the sending adapter

  • Type : Length 2 bytes. This field allows Ethernet to multiplex multiple network layer protocols. A host can support multiple network layer protocols. Therefore, when a frame arrives at a receiving adapter, the adapter needs to know which network layer protocol it wants to pass the data field of the frame to. IP and other network layer protocols have their own type numbers. . If the arriving frame contains an ARP packet, that is, the value of the type field is 0806 in hexadecimal, the ARP packet will be decomposed to the ARP protocol

    This type field is similar to the protocol field in the network layer datagram and the port number field in the transport layer segment, both for the purpose of combining a certain protocol of the first layer with a certain protocol of the upper layer

  • CRC : length 4 bytes The purpose of cyclic redundancy detection is to enable the receiving adapter to detect whether bit errors have been introduced in the frame

  • Preamble : The Ethernet frame starts with an 8-byte preamble field. The first 7 bytes of the synchronization code are all 10101010, and the last byte is 10101011.

    The first 7 bytes are used to "wake up" the receiving adapters and synchronize their clocks with the sender's clock. Because it is difficult for the sending adapter to transmit frames at the exact rated rate, there is always some drift relative to the rated rate, and the LAN Other adapters on the network certainly have no way of knowing this drift in advance. By locking the first 7 byte bits of the preamble, the receiving adapter can lock the clock of the transmitting adapter.

    The last two bits of the synchronization code are used to tell the receiving adapter that the "important content", that is, other data parts are coming.

Virtual LAN

With the development of switched LANs, it has become possible for every host in the same LAN to be interconnected. The advantage is that any host can communicate directly with other hosts. The disadvantage is the lack of traffic isolation. The host 's broadcast frame must be sent across the entire organization network to For each host, this will bring a large amount of broadcast traffic and affect the performance of the LAN; more importantly, it is for the purpose of security or privacy to limit the broadcast traffic of the LAN and prohibit random communication between any hosts.

Virtual LANs can handle this problem. VLAN-enabled switches allow multiple virtual LANs to be defined over a single physical LAN infrastructure. Hosts in a VLAN communicate with each other

In the port-based VLAN, the ports of the switch are divided into groups by the network administrator, and each group constitutes a VLAN, and the ports in each VLAN form a broadcast domain, and the broadcast traffic from one of the ports can only reach the group In other ports , frames sent between different groups are isolated from each other. Moreover, in this case, even hosts in different groups can be connected to the same switch without fear of traffic spreading to each other, which improves the utilization rate of a single switch

In this case of isolation between groups, how can communication be achieved between different groups? One way is to connect a port of the VLAN switch to an external router. The datagrams from one group to another group first reach the router through its own VLAN, and then the router forwards the datagram across the VLAN of the other group to another group. destination host in group

Another problem is how to communicate between different switches. The solution to this problem is VLAN trunking VLAN\ trunkingV L A N trunking )  , a special port in each switch is configured as a trunk port, and the trunk ports are used to connect trunk lines between different switches for interconnection . This trunk port belongs to all VLANs, and frames sent to any VLAN are forwarded to other switches through the trunk link.

Guess you like

Origin blog.csdn.net/Pacifica_/article/details/125836400