How Packet Switching Works?

How Packet Switching Works?

Transferring data from source to destination system

Most modern day applications need to communicate with other applications to perform something meaningful. This communication happens over the network and involves transfer of data by exchanging messages.

These messages can contain any type of data such as an email message, an image or an audio/video file. However, we cannot transfer messages directly from one system to another. We need to abide by some rules to carry out the transfer. This is where packet switching comes into the picture.

Packet switching is the method of transferring data or packets from the source system to the destination system. In today’s post, we are going to look into this extremely important concept of Computer Networking.

image.png

However, before we delve further into the topic, let us first answer a basic question.

What is a packet in computing terms?

In order to transfer efficiently, a typical message is broken up into small chunks. These chunks are known as packets. And hence the name Packet Switching.

1 - Understanding Packet Switching

Though we can understand that packet switching deals with the transfer of packets from source to destination, but we don’t know much about how the actual process works.

How do network packets actually travel from source to destination?

Packets travel through communication links and packet switches. Packet switches are nothing but routers and link-layer switches. In the context of a computer network, you can think of communication links as highways and packet switches as intersections.

image.png

A particular source and destination might have several communication links and packet switches in between. And most of these packet switches use an approach known as store-and-forward transmission.

Store-and-forward packet switching means that the packet switch or router must receive the entire packet and then only transmit it further.

Check out the below illustration where a router is present between the source and destination systems. The onward transmission of a packet starts only after the complete packet is received by the router.

image.png

The main advantage of store-and-forward transmission approach is high quality data packet transmission. Erroneous packets gets discarded at each hop in the network. This leads to a reduction in the number of bad packets on the network.

The seeming disadvantage of this approach is higher latency. Since every packet switch waits for the entire packet to arrive before transmitting it further, there is an increase in wait time at each step. As the number of switches increase, it can drastically increase the overall latency.

Subscribe to the Publication

2 - Forwarding Tables

In packet switching, a router receives a packet and forwards it to another one of its attached communication links (also known as the highways).

But how does the router determine which link or highway it should use?

There is something known as forwarding tables to take care of this. Forwarding tables take care of routing a packet onto the correct link. Each router has a forwarding table that maps destination addresses to the router’s outbound links.

But what exactly are these addresses? Well, they are nothing but IP addresses. Every end system on the internet has an IP address.

When a source system sends a packet to a destination, it includes the destination’s IP address in the packet’s header. You can think of IP address as a postal address. Just like the postal address, IP addresses also have a hierarchical structure. For example, a postman delivering a letter to 1015 Mill Street, Greenville, South Carolina will start with the top-level hierarchy (i.e. South Carolina) and then, move lower to the city, the street and finally the particular house number.

The same is true for packet switching using forwarding tables. When a packet arrives at a router, it examines a particular portion of the destination IP address and forwards the packet to an adjacent router based on the entry within its forwarding table.

3 - Types of Packet Switching

There are two types of packet switching – connectionless and connection-oriented.

3.1 - Connectionless Packet Switching

In connectionless packet switching, every packet contains all the information such as the source address and destination address. This approach is also known as datagram packet switching.

Basically, in this approach, each packet is independent. Packets belonging to the same message may travel through the network using completely different routes. The packets may also arrive at the destination out-of-order depending on the latency for each packet.

image.png

In the above illustration, every packet finds its own path through the network. Since there is no guarantee of packet delivery in this approach, additional checks should be present on the end-systems to ensure that the received message is complete.

3.2 - Connection-oriented Packet Switching

As the name suggests, connection-oriented packet switching establishes a logical path or a virtual connection using signalling protocol. All packets will flow through the pre-decided route. A virtual circuit id is setup to facilitate the transfer of packets. We call this approach as virtual-circuit approach.

image.png

In the above illustration, every packet follows the same path through the network. The path is highlighted in brown colour.

There are three phases in this approach – setup, data transfer and tear-down.

The address information is processed during the setup phase. Once the route is finalized, entries are made to the switching tables of every node present in the path. After the data transfer is complete, the tear-down of the connection takes place.

Conclusion

Packet switching is a fundamental concept in computer networking. It forms a key part of how the Internet actually works.

Store-and-forward transmission along with forwarding tables are the building blocks of packet switching.

We rarely pay attention to it in our day-to-day programming since the underlying network guarantees that it will work. Of course, from the point of view of computer science, it is important to understand how data is actually transferred over the network.

Have you ever had the need to deal with packet switching in some way? If yes, do share your experiences in the comments section below.

Did you find this article valuable?

Support Saurabh Dashora by becoming a sponsor. Any amount is appreciated!