We have at least three layers on the network that use identifiers to trace or point to the correct location for a packet sent on the network.
In our journey to discover and learn more about them, you should also know that packets sent on the network are interleaved with other packets from other hosts on the network. So if a packet is split into chunks and sent on the network, it doesn’t mean it will be sent one chunk after the other of the same packet.
You can have one part from a packet, another from the next packet and so on, each of them being analyzed and sent to the destination by networking devices, where it will be re-ordered and assembled into the original packet before the segmentation.
So as a conclusion to what happens with a packet sent from a computer to another at each network layer, let’s just sum it up by saying that the Physical layer deals with the timing and synchronization bits, the Data Link layer adds the Destination and Source Physical Address (for example the MAC of the source and destination), the Network layer deals with the Destination and Source Logical Network Addresses (for example IP addresses for the source and destination), Transport layer will manage the Source and Destination Process Numbers (Ports for the Source and Destination) and last but not least, the Upper layers deal with the Encoded Data which is actually the original message sent to be put on the network while traveling to the corresponding Application layer of the device.
Below, you can see an example on how addressing on the network is working for layer 2 and 3. The rest will be covered later.
Let’s say a packet will be leaving COMP1 with a final destination of COMP2.
The Protocol Data Unit will contain the IP address of COMP2 as a destination IP, which is 192.168.1.2 with a source IP of 192.168.2.2. The destination MAC address will be changed on each network segment, while the source will stay the same.
When the packet will leave COMP1 and will be placed on the network, due to an ARP process that takes place before putting it on the network, this packet will have a destination MAC address of R1’s interface towards the COMP1, which is 0090.2b90.1502 while the packet will have a source MAC address of COMP1’s MAC.
The ARP process will be repeated at each hop, process that I will explain soon. You can see how the addresses tend to change in the following table, as I illustrated for each location that will be reached by the packet.
As you can see the IP addresses for a packet don’t change when packets travel from network to network, only the MAC addresses used by interfaces to communicate and locate themselves on each segment.
You can try to understand this as an analogy to the post office, where a letter can travel different countries without changing the sender and the receiver, as you can see printed on it. It will always be left as the original, but there is however a hidden mechanism, invisible to us, that makes postmen and post offices know how to and where to send that letter, which in a network would be done with the help of the MAC address.
When the packet finally arrives to the location, the next identifier to be checked after IPs and MACs is the PORT number. The targeted device removes the frame and packet headers and moves the PDU to the next layer, the 4th one.
Applications on different devices use port numbers as identifiers for layer 4. A unique dialogue between devices is identified with a source and destination port numbers that represent the communicating applications.
The ARP is a network protocol that resolves network addresses (like IP addresses) to link layer addresses (like MAC addresses). There is also a reverse-ARP which does the opposite, but I won’t explain this as you won’t need it for now. Later on, you will automatically understand more about it.
In the above examples the ARP was running too, or at least in a real network based on that example or any other network. How does it work?
Well, let’s say COMP1 wants to send a message to that interface we used of the router R1. We will call the interface Fa0/0 for a faster recognition. In this example, let’s say COMP1 does not have the MAC – IP association already saved in the ARP cache, else it would just use that match to send.
COMP1 does not know the MAC address of Fa0/0 interface so it will send a broadcast message to all the devices inside the local network, message that will contain its own MAC address as source, IP source of the COMP1 and IP destination of the remote machine the packet must reach. The message will also contain an empty field for the MAC destination, left blank to be filled by the destination device, as this is the information it needs to know before sending the actual packet.
The broadcast message will reach all devices in the network, and each device will analyze the packet, to be more precise: the destination IP. Those who don’t have a match with the IP it searches, will drop the packet. When the interface Fa0/0 will analyze the packet, it will see the match and it will send back a reply with its MAC address as source and the destination as COMP1. COMP1 will save the match in the ARP cache, because it will be needed soon for the original message.
After this, the computer will send the message using as destination the MAC address that it just learned, by doing the match IP – MAC from the ARP cache.
Now, if let’s say the IP is not in the same network and we try to send the message to COMP2 as it was in the picture, then there would be an exchange on each network segment along the way to COMP2.
One thing that would change: no match on the local network for a device in the same IP network. The one device that would reply with a MAC address would be the default gateway, which in our case would be Fa0/0. Then COMP1 would know and save this to the local cache. For any message outside of local network, the MAC address of the default gateway will be used in order to send the packet out of the network.