Computer Network Review - Chapter 4 4.2.3 4.2.4 4.3

4.2.3 IP address and MAC address

IP address: virtual address, software address, logical address. Used by the network layer and above. Placed in the header of the IP datagram.

MAC address: solidified in the ROM on the network card. Hardware address, physical address. Used by the data link layer. Placed at the beginning of the MAC frame. The IP address is placed in the header of the IP datagram, and the MAC address is placed in the header of the MAC frame.

 On the Internet where the IP layer is abstracted, only IP datagrams can be seen, and on the link layer of the LAN, only MAC frames can be seen. The table below can be obtained from the communication path in the above figure.

 4.2.4 Address Resolution Protocol ARP

Two addresses are used when implementing IP communication: IP address (network layer address) MAC address (data link layer address)

So how do we find the MAC address if we know the IP address? Just use the ARP protocol for analysis.

Point 1: ARP cache (ARP cache)

Stores the mapping table from IP address to MAC address. The mapping table is dynamically updated (added or deleted after timeout).

<IP address; MAC address; survival time (Age); type, etc.>

Items that have expired are removed from the cache to accommodate network adapter changes.

Use the ARP protocol to find the MAC address corresponding to the IP address.

Broadcast and send ARP requests on the local area network (the router does not forward ARP requests).

ARP request group: contains sender hardware address/sender IP address/target hardware address (fill in 0 if unknown)/target IP address.

Unicast ARP response packet: contains sender hardware address/sender IP address/target hardware address/target IP address. ARP packets are encapsulated in Ethernet frames for transmission.

The specific process is shown in the figure:

The role of the ARP cache: to store the recently obtained IP address to MAC address binding. Reduce ARP broadcast traffic. To further reduce ARP traffic, when host A sends its ARP request packet, it writes its own IP address to MAC address mapping into the ARP request packet. When host B receives the ARP request packet from A, it writes the mapping of host A's IP address and its corresponding MAC address into host B's own ARP cache. No need to send ARP request. 

What to do if the two hosts are not in the same LAN:

Communication path: A → forwarded through R1 → B. Therefore, host A must know the IP address of router R1 and resolve its MAC address. The IP datagram is then sent to router R1.

Four typical situations when using ARP:

1. The sender is a host and wants to send the IP datagram to another host on this network. At this time, use ARP to find the hardware address of the destination host.

2. The sender is a host and wants to send the IP datagram to a host on another network. At this time, use ARP to find the hardware address of a router on this network. The router does the rest.

3. The sender is a router and wants to forward the IP datagram to a host on this network. At this time, use ARP to find the hardware address of the destination host.

4. The sender is a router and wants to forward the IP datagram to a host on another network. At this time, use ARP to find the hardware address of another router on the network. The router does the rest.

4.2.5 IP datagram format

IP datagram consists of header and data parts

The first part of the header is of fixed length, totaling 20 bytes, and is required by all IP datagrams. Optional fields whose length is variable are generally not used nowadays.

The fields in the fixed part of the IP datagram header:

Version: occupies 4 digits and refers to the version of the IP protocol. The current IP protocol version number is 4 (ie IPv4).

Header length: occupies 4 bits, and the maximum representable value is 15 units (one unit is 4 bytes), so the maximum value of the IP header length is 60 bytes.

Differentiated services: occupies 8 bits, used to obtain better services. This field only takes effect when using differentiated services (DiffServ). Under normal circumstances this field is not used.

Total length: 16 bits, refers to the length of the header and data, in bytes, so the maximum length of the datagram is 65535 bytes. The total length must not exceed the maximum transmission unit MTU. 

Identification: 16 bits, it is a counter used to generate the identification of IP datagrams. Each time a datagram is generated, the counter is incremented by 1 and this value is assigned to the identification field.

Flag: occupies 3 digits, currently only the first two are meaningful. The lowest bit of the flag field is MF (More Fragment). MF=1 indicates that there are more fragments later, and MF=0 indicates the last fragment. The middle bit of the flag field is DF (Don't Fragment). Fragmentation is only allowed when DF=0.

Fragment offset: occupies 13 bits, indicating: the relative position of a certain piece in the original grouping after the longer grouping is fragmented. The slice offset is in 8-byte offset units.

Time to Live: 8 bits, recorded as TTL (Time To Live), indicating the maximum number of routers that datagrams can pass through in the network. Each time it passes through a router, the TTL is subtracted by the time spent on that router. The datagram is discarded when the TTL decreases to 0.

Protocol: It occupies 8 bits and indicates which protocol is used for the data carried in this datagram, so that the IP layer of the destination host will hand over the data part to which processing process. The IP protocol supports multiple protocols, and IP datagrams can encapsulate multiple protocol PDUs.

Header checksum: occupies 16 bits, only checks the header of the datagram, not the data part. The CRC check code is not used here but a simple calculation method is used.

Source address: 32 bits of the IP address of the sending host.

Destination address: 32 bits of the IP address of the receiving host.

 4.3 The process of forwarding packets at the IP layer

1) Endpoint-based forwarding

Packets are forwarded hop by hop in the Internet. Destination-based forwarding: Transmission and forwarding based on the destination address in the packet header.

In order to compress the size of the forwarding table, the most important route in the forwarding table is ( destination network address , next hop address) instead of (destination address, next hop address). The process of searching the forwarding table is to look for prefix matches line by line. 

2) Longest prefix match

When using CIDR, you may get more than one match when looking up the forwarding table . The longest prefix matching principle: select the longest prefix as the matching prefix. The longer the network prefix, the smaller its address block and therefore the more specific the route. You can put the longest prefix in the first row of the forwarding table.

Longest prefix matching: Select the longest prefix as the matching prefix

The longer the network prefix, the smaller its address block and the more specific the routing. You can put the longest prefix in the first row of the forwarding table to speed up table lookup.

2 special routes in the forwarding table

Host route (host route) is also called specific host route. It is a route specifically designated for the IP address of a specific destination host. The network prefix is ​​abcd/32 placed at the front of the forwarding table.

Default route (default route) No matter where the final destination network of the packet is, it is processed by the designated router R and represented by the special prefix 0.0.0.0/0. As long as a match cannot be found during matching, it will be transferred to the default route, and then the default route will be forwarded to the next route.

Routing packet forwarding algorithm flow chart:

 

Guess you like

Origin blog.csdn.net/m0_53345417/article/details/130225901
Recommended