I. Data Link layer
The data link layer implements a logical link between adjacent nodes, which uses the protocol unit as the data frame. when data is transferred between two nodes, the data link layer assembles the IP datagram that is delivered by the network layer into frames and transmits the frames across the links between the two adjacent nodes .
Three basic issues with the Data link layer:
1. Encapsulated into frames, 2. Transparent transmission, 3. Error detection
Come down and discuss the encapsulation into frames:
Encapsulating Frames is the addition of headers and tails before and after a piece of data, which makes up a frame. The IP datagram of the network layer is transferred to the data link layer, which becomes the data part of the frame, and the head and tail are added before and after the data part of the frame to form a complete frame.
Two. MAC layer of Ethernet
Hardware address of the 1.MAC layer
in a local area network, the hardware address is also called the Physical address or MAC address . the length is 48 bits, is in the network card Factory
When cured. Under Linux with the Ifconfig command to see, "HWaddr 00:15:f2:14:9e:3f" part is the hardware address. This 6-byte MAC address is cured in the adapter's ROM while the adapter is being produced. So it's actually the adapter address or adapter identifier.
Format of 2.MAC Frames
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/11/wKiom1c1sNmiB0WVAABtDfxt_lo624.png "title=" catch. png " Width= "550" height= "278" border= "0" hspace= "0" vspace= "0" style= "width:550px;height:278px;" alt= " Wkiom1c1snmib0wvaabtdfxt_lo624.png "/>
Where the destination address and source address is the MAC address, the Frame protocol type field has three kinds of values, respectively, corresponding to IP, ARP (address resolution), RARP (inverse address resolution). The end of the frame is the CRC check code.
The length of the data in the Ethernet frame specifies a minimum of 46 bytes, a maximum of 1500 bytes, and the length of the ARP and RARP packets is not 46 bytes, to be padded at a later bit. The maximum value of 1500 is called the Maximum Transmission Unit (MTU) of the Ethernet, and different network types have different MTU, and if a packet is routed from Ethernet to a dial-up link, the packet length is greater than the MTU of the dial link, then the packet needs to be fragmented (fragmentation). There is also "mtu:1500" in the output of the Ifconfig command under Linux. Note that theConcept index of the MTU is the maximum length of the payload in the frame, excluding the length of the frame header.
3.ARP Datagram Format
In the network communication, the source host's application knows the destination host's IP address and port number, but does not know the destination host hardware address, and the packet first is received by the network card to deal with the upper layer protocol, if the received packet hardware address and the local machine does not match, then directly discarded. Therefore, the hardware address of the destination host must be obtained before communication. The ARP protocol plays this role.
The source host makes an ARP request, asks "What is the hardware address of the host that the IP address is 192.168.0.1", and broadcasts the request to the local network segment (the hardware address of the Ethernet frame header is filled FF:FF:FF:FF:FF:FF represents the broadcast), the destination host receives the broadcast ARP request, When the IP address is found to match the native computer, an ARP reply packet is sent to the source host, and its hardware address is filled in the reply packet.
Each host maintains an ARP cache table, which can be viewed under Linux with the ARP-A command. The table entries in the cache table have an expiration time (typically 20 minutes), and if a table entry is not reused within 20 minutes, the table entry fails and the next ARP request is sent to obtain the hardware address of the destination host.
the ARP Datagram frame format is as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/11/wKiom1c1s-Cw95YiAABrfguCZk4872.png "title=" catch. png " Width= "height=" 123 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:123px; "alt=" Wkiom1c1s-cw95yiaabrfguczk4872.png "/>
Note that the source MAC address, the destination MAC address appear once in the Ethernet header and the ARP request, for the link layer The situation for Ethernet is redundant, but it may be necessary if the link layer is a different type of network. The hardware type refers to the link layer network type, 1 is Ethernet, the protocol type is the type of address to be converted, the 0x0800 is the IP address, the two address length for the Ethernet address and IP address are 6 and 4 (bytes), the OP field is 1 for the ARP request, An OP field of 2 indicates an ARP reply.
Here is a specific example:
Host 1 sends ARP requests to host 2:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/80/0E/wKioL1c1wCyBShndAAAaFZDba2w271.png "title=" catch. png " alt= "Wkiol1c1wcybshndaaaafzdba2w271.png"/>
Host 2 responds to host 1ARP:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/80/0E/wKioL1c1wGuTtdZ5AAAZfmWFEeo704.png "title=" catch. png " alt= "Wkiol1c1wguttdz5aaazfmwfeeo704.png"/>
This article is from the "Output Diamond pattern" blog, so be sure to keep this source http://10541571.blog.51cto.com/10531571/1773161
Mac frames in a computer network