The process of packet forwarding

Computer Network Eighth Edition [Example 4-2]

[Example 4-2] In Figure 4-23, there are three subnets interconnected through two routers. Host H 1 sends out a packet whose destination address is 128.1.2.132. Now the source host is H1 and the destination host is H2 . Discuss how packets are transmitted from source host to destination host.
insert image description here
[Solution] The host H 1 must first determine: Is the destination host connected to the network? If so, then the problem is very simple, and it is delivered directly without using a router; if not, it is delivered indirectly, and the packet is sent to the connected host The router on this network will handle all the things to be done in the future by this router.

The host H 1 performs bitwise AND operation on the destination address of the packet to be sent and the subnet mask of the local network N 1 to obtain the operation result. If the operation result is equal to the prefix of the local network N1 , it indicates that the destination host is connected to the local network; otherwise, the packet must be sent to the router R1 , and the subsequent tasks are completed by the router R1 .

Since the CIDR notation is used, all the network prefixes are given in the forwarding table, and the subnet mask is not given obviously. In fact, as long as you carefully observe the numbers behind the slash, you can know the corresponding subnet mask. For example, a subnet mask of /26 is 255.255.255.192 in dotted decimal notation. Now, the destination address of the packet to be sent is 128.1.2.132, and the mask of this network is 26 1s followed by 6 0s. As shown in Figure 4-24(a), the result of the bitwise AND operation is 128.1.2.128, which is not equal to the prefix of N 1 in this network . This means that the destination host is not connected to the network. Source host H 1 must send the packet to router R 1 to have router R 1 process the packet according to its forwarding table.
insert image description here
Part of the forwarding table of router R1 is shown in the upper right of Figure 4-23. The first column in the forwarding table is "prefix match", this is because the process of searching the forwarding table is the process of finding the prefix match .

Now check first row 1 in router R1's forwarding table .

The destination address of the packet to be sent by the source host H 1 is 128.1.2.132. The prefix of this network 128.1.2.192/26 has 26 bits, so the mask of this network is 26 1s followed by 6 0s. The result of the bitwise AND operation of the destination address and the subnet mask is 128.1.2.128/26 (see Figure 4-24(a)). Obviously, the result of the AND operation does not match the prefix in line 1 of the forwarding table.

Next examine line 2 in router R1's forwarding table . The operation result is 128.1.2.128/26, as shown in Figure 4-24(b). This result matches the prefix in line 2 of the forwarding table. The direct delivery of the packet (via interface 1 of router R1) then takes place on network N2 as indicated in line 2 of the forwarding table . At this time, the router R 1 invokes ARP, resolves the MAC address of the destination host H 2 , encapsulates it into a link layer frame, and directly delivers it to the destination host H 2 connected to the network N 2 .

If you follow the same method and check the third line in the forwarding table of router R 1 , it is not difficult to get the result of mismatch.

The process of router packet forwarding

  1. Determine whether the destination host is connected to the network, if yes, deliver it directly, if not, execute step 2, send the packet to router R, and router R completes the subsequent tasks.
  2. Check whether there is a specific host route for the destination IP address in the forwarding table, if yes, forward according to the specific host route, if not, go to step 3
  3. Compare the destination address of the packet to be sent with the subnet mask of the network in the forwarding table line by line , the result matches the prefix of a certain line in the forwarding table , and forward according to the interface indicated by the line, if the result does not match, Just go to step 4
  4. Check whether there is a default route in the forwarding table, if so, forward according to the default routing table, if not, go to step 5
  5. Report an error to the source host

The method of judging whether the destination host is connected to the local network: carry out bitwise AND operation on the destination address of the sent packet and the subnet mask of the local network, and obtain the operation result. If the operation result is equal to the prefix of this network, it means that the destination host is connected to this network

Guess you like

Origin blog.csdn.net/qq_51453356/article/details/125577300