5.2.10 Forwarding of IP packets (1)

5.2.10 Forwarding of IP packets (1)

We already know that the IP protocol provides a connectionless, unreliable, best-effort IP packet delivery service. Here we will learn how an IP packet is delivered from the source host to the destination host. If there are two hosts sending data on the Internet, how does the packet reach the destination after being forwarded by several routers? First of all, we must first understand a very important network device that works in the network layer-the router.

1. Router

  • A router is actually a computer dedicated to communication, with a structure similar to that of a computer.

  • Each router is directly connected to two or more physical networks. Each network interface of a router provides two-way communication, including input and output ports.

  • Interface : The interface of the router can be divided into console interface, LAN interface, WAN interface and so on.

  • The structure of the whole router can be divided into two parts: routing part and packet forwarding part . as shown in the picture

    router structure

    The routing part is simply to construct and maintain the routing table according to the selected routing protocol (this will be introduced later)

  • The packet forwarding part consists of three parts: as shown in the figure above, the switching structure in the middle , a set of input ports and a set of output ports .

    as shown in the picture

    input port

    Routers receive packets on input ports, and from a layered perspective,

    1. First, receive the bit stream according to the physical layer protocol
    2. Then receive and encapsulate the IP packet frame according to the data link layer protocol
    3. Then check the frame through the frame check sequence in the data frame. If the frame is correct, the IP packet encapsulated in the frame is handed over to the network layer for processing. At this time, if the network layer module is busy, the datagram or IP packet is processed. Temporarily held in the input queue for processing
    4. After the queuing is over, the network layer module searches the routing table according to the IP address of the destination host in the IP packet header. According to the found IP address of the next-hop router and the corresponding output port of the router, the IP address is passed through the switching structure. The packet is sent to the output port just found.

    As shown in the picture:

    output port

    1. Like the input port, the output port is also equipped with a queue. When the arrival rate of the packets transmitted by the switch structure exceeds the sending rate of the output link, the IP packets that are too late to be sent are temporarily stored in the queue.
    2. After queuing, the data link layer processing module in the output port adds the header and tail of the frame to the IP packet, that is, encapsulates it in a new data frame
    3. After encapsulation, it is handed over to the physical layer entity through the RJ45 interface of the network card and then sent to the transmission line

    In practical applications, the overflow of input or output queues in routers is an important reason for packet loss.

2. Direct delivery and indirect delivery

We also said just now that each router in the Internet must be connected to at least two physical networks, that is, it has direct contact with at least two physical networks. For the host, it is usually only connected to one physical network, or the host only It belongs to a physical network, but in fact, whether it is a host or a router, it must participate in the process of transmitting IP packets. When an application on a host tries to communicate, the TCP/IP protocol will generate several For IP packets, it is necessary for the host to make the initial forwarding decision , that is, to decide where to send this IP packet. Before learning the forwarding strategy, we should learn and be familiar with the concepts of direct delivery and indirect delivery.

(1) Direct Delivery

as shown in the picture

direct delivery

When the source host A and the destination host B are in the same physical network, they do not need to be forwarded through routers. This method is called direct delivery.

(2) Indirect delivery

as shown in the picture

indirect delivery

The source host A and the destination host C are not connected to the same physical network. At this time, the IP packet should be sent to a router on the network, and the router will forward the IP packet to the next router according to the route indicated by the forwarding table. has since been referred to as indirect delivery.

When the IP packet can be delivered directly, it can be obtained through the address resolution protocol ARP we have learned. For example, for host A, the MAC address of the destination host B is obtained according to the ARP protocol, and then the IP packet is encapsulated in a physical frame. sent directly to the destination host.

If it is not in the same physical network, the IP packet is handed over to a local network connection of the local router. At this time, we obtain the first hop through ARP, which is the MAC address of the default router, and then encapsulate the IP packet into the frame and sent to the router. Each router indirectly delivers the IP packet to the next router until the IP packet reaches the router closest to the destination host on the path, and then the router delivers the IP packet to the destination host through direct delivery, that is to say, for The routers in the TCP/IP Internet form a mutually cooperative interconnection structure. For IP packets whose source and destination hosts are not on the same physical network, they are first transmitted to the local router by the source host, and then after several indirect deliveries, the final destination is the one that can be delivered. Routers that perform direct delivery, that is, reach the last hop, and are finally delivered directly, which means that direct delivery is the last step in any IP packet transmission .

According to the above content, we know that the key issue of routing and forwarding is

  • The key question is , for the source host, how to judge whether the source host and the destination host are in the same physical network?

  • Using classified IP address analysis : If the initial classified IP address is used, we can easily extract the destination network address from the destination IP address according to the classification addressing rules, and compare it with the network address corresponding to the local IP address. For example, the source host 202.119.224.201 and the destination host 202.119.224.8, first of all, they are both Class C addresses, and the upper 24 bits of the two IP addresses are the same. It is easy to judge that the two hosts belong to the same network. When the recipient communicates, it is a direct delivery.

  • Using subnetting or unclassified addressing analysis , it is similar to the network that has been subnetted or unclassified addressing. It is still based on the destination IP address, source IP address and the subnet mask of the subnet where the source host is located. It is judged whether the result of code phase AND is equal.

    Such as: source 192.168.23.184, destination host 192.168.23.66, subnet mask 255.255.255.224

    Analysis: The result of the AND of the source IP address and the subnet mask is 192.168.23.184 AND 255.255.255.224=192.168.23.160

    ​ The result of combining the destination IP address with the subnet mask of the source host is 192.168.23.66 AND 255.255.255.224 =192.168.23.64

    After the first three decimals are combined with 255, there is no change. Only the last decimal digit is converted into binary and then combined with 224. It can be seen that the results of the two comparisons are different, indicating that the two hosts are separated. Belonging to different subnets, since they belong to different subnets, indirect delivery is required to communicate between hosts in these two days.

After understanding the concepts of direct delivery and indirect delivery, let's learn about the unified IP packet forwarding algorithm.

Guess you like

Origin blog.csdn.net/nytcjsjboss/article/details/131164050