Routing – How does a packet travel across multiple routers/subnets

ipipv4routerrouting

After reading various resources and examining the example below, the step-by-step process for a packet to travel the route below is still not 100% clear to me. I'm hoping to get clarification.

Image and description from the Wiki article for Default Gateway:

Accessing internal resources If PC2 (172.16.1.100) needs to access PC3 (192.168.1.100), since PC2 has no route to 192.168.1.100 it will send packets for PC3 to its default gateway (router2). Router2 also has no route to PC3, and it will forward the packets to its default gateway (router1). Router1 has a route for this network (192.168.1.0/24) so router1 will forward the packets to router3, which will deliver the packets to PC3; reply packets will follow the same route to PC2.

multiple routers

EDIT: removed misuse of NAT.

My understanding of how a TCP/UDP packet would be processed in the example above:

  1. Host 2's default gateway is set to 172.16.1.1 (by default somehow?), and it sends a frame to Router 2's eth1 MAC address (obtained through ARP?). The enclosed packet has source 172.16.1.100:portA and destination 192.168.1.100:portX.
  2. Router 2's default gateway is 10.1.1.1, and it sends the packet in a new frame from eth0 to Router 1's eth1 MAC address.
  3. The HUB (layer 2 switch?) simply forwards the packet to Router 1's eth1 (not sure how this device initially maps MAC addresses to physical ports).
  4. Router 1's routing table has an entry for the subnet containing the destination IP and sends a frame from eth1 to Router 3's eth0 MAC address.
  5. Router 3's routing table has an entry for the subnet containing the destination IP and sends a frame from eth1 to Host 3's MAC address.
  6. Host 3's OS delivers the packet to the appropriate process listening on portX.

If a reply is sent back, the process unfolds in reverse. In lesser detail:

  1. Host 3 addresses reply packet to Host 2, 172.16.1.100:portA, sending it first to Router 3.
  2. Router 3 sends to default gateway Router 1.
  3. Router 1 sends to Router 2, the gateway listed for the subnet that 172.16.1.100 exists on.
  4. Router 2 sends to Host 2.
  5. Host 2's OS delivers the packet to the original process that opened portA.

What parts am I missing or misunderstanding? Am I mixing ideas or concepts incorrectly? What assumptions have I made about this setup that may not apply to all networks?

Best Answer

For your question about the hub, consider a hub a powered cable. It simply repeats any signal from one interface to all the other interfaces, and it does not know anything about frames or MAC addresses.

Depending on how Router 1 is configured, it may just send a redirect back to Router 2 to tell it to send the packet to Router 3.

You also seem to have really left out the transport protocol. You did mention TCP and UDP at first, but those sit between the application and IP. TCP and UDP are separate protocols, and IP will see the protocol number in its header, and it will deliver the payload of the IP packet to the correct transport protocol. While TCP and UDP both have addresses (called ports) that are the same number range, they are not the same ports (TCP port 5678 is not UDP port 5678).

The application will open a port with whichever transport protocol is used, and IP will encapsulate that datagram in an IP packet. The data-link protocol (ethernet?) will encapsulate the IP packet inside a data-link frame that gets encoded and signaled on the wire to the host gateway.

The host gateway router will strip off the frame, look up the destination address in its routing table, and create a new frame for the next interface to encapsulate the IP packet. This happens for every router hop, with the final router sending it out the destination network address.

The host will receive the final frame, and look at the Ether Type (or equivalent for whichever protocol it uses). The data-link protocol will send the frame payload (IP packet) to the process indicated in the frame Ether Type (IP). IP will then look at the packet header to see the protocol number, and it will send the packet payload to the correct transport protocol (TCP, UDP, etc.). The transport protocol will then send the datagram payload to the application registered to it (TCP and UDP use ports for this, other transport protocols may do something else).

Replies follow the same path in reverse.