Sub topic 7
Packet switching and store-and-forward
This chapter assumes you know what bits, bytes and bits per second are, and that you can convert units such as milli and mega. It also assumes you know what a router is at a basic level. Later chapters give the full delay model. Here the aim is to understand how packet switching moves data and why store-and-forward behaves the way it does.
What packet switching is
In packet switching, the sender splits a message into chunks called packets. Each packet carries a header with addressing information, and each packet is forwarded through the network independently. No path is reserved in advance. Packets from many senders share the same links, and each link is used only while a packet is actually being transmitted on it.
A packet is the unit of data at the network layer, made of a header and a payload. The header holds what a router needs to decide where to send the packet. The payload is the data being carried.
Packet switching differs from circuit switching in three ways:
- No setup phase. A sender can transmit immediately.
- No reserved capacity. A link's full rate goes to whichever packet is being sent right now.
- Variable delay. A packet may wait in a queue behind other packets, so delay depends on current load.
Store-and-forward at a router
Most packet switches use store-and-forward transmission. A router must receive an entire packet before it starts transmitting the first bit onto the next link. It buffers the packet in memory, which is the "store" step. It then reads the destination from the header, chooses an output link and transmits the packet, which is the "forward" step.
Two reasons explain why the router waits for the whole packet:
- The router often needs the complete packet to verify it. A checksum or frame check sequence at the end can only be checked once the whole packet has arrived.
- The output link may run at a different rate from the input link, so the router cannot simply copy bits through as they arrive.
The consequence is that every link on the path retransmits the whole packet. For a packet of L bits on a link of rate R bits per second, each link adds L/R seconds of transmission delay.
A path with N links has N-1 routers between the end hosts. Here each link has rate R and carries a packet of L bits. If you ignore propagation, queuing and processing, one packet needs N × L/R seconds to arrive.
A first delay calculation
Two delays matter for a single packet crossing a path. Transmission delay is paid once per link, because each link transmits the packet again. Propagation delay depends only on the total distance and the signal speed. It is not multiplied by the number of links.
def end_to_end_delay(packet_bits, rate_bps, links, distance_m, prop_speed_mps):
"""Store-and-forward delay of one packet; queuing and processing ignored."""
transmission = packet_bits / rate_bps # time to push the packet onto one link
propagation = distance_m / prop_speed_mps # total signal travel time
return links * transmission + propagation
# 12000-bit packet, 10 Mbps links, 3 links, 3000 km of cable at 2e8 m/s
print(round(end_to_end_delay(12_000, 10_000_000, 3, 3_000_000, 2e8), 6)) # 0.0186The transmission part is 3 × 1.2 ms = 3.6 ms. The propagation part is 3,000,000 / 2×10^8 = 15 ms. The total is 18.6 ms.
Why splitting a message helps
Suppose a router sends a whole message as one unit. Every link must transmit the entire message before the next link can start. This is message switching, and its delay is N × M/R for a message of M bits.
Packet switching changes this by splitting the message into P packets of L bits each. While the second link carries packet 1, the first link can already carry packet 2. The links work in a pipeline.
The first packet arrives after N × L/R seconds. After that, one more packet arrives every L/R seconds, because the last link finishes one packet and starts the next. The last packet therefore arrives after:
(N + P − 1) × L/R
import math
def message_delay(message_bits, packet_bits, rate_bps, links):
"""Time to deliver a message split into equal packets over store-and-forward links.
Propagation, queuing and header overhead are ignored."""
packets = math.ceil(message_bits / packet_bits)
return (links + packets - 1) * packet_bits / rate_bps
# 1,000,000-bit message, 1000-bit packets, 1 Mbps links, 3 links
print(message_delay(1_000_000, 1_000, 1_000_000, 3)) # 1.002 (segmented)
print(message_delay(1_000_000, 1_000_000, 1_000_000, 3)) # 3.0 (sent as one unit)With 1000 packets, the segmented delay is 1002 × 1 ms = 1.002 s. Sent as one unit, the same message takes 3 × 1 s = 3 s. The more links there are, the larger the saving. As P grows, the delay approaches the single-link time M/R.
Setting P = 1 in the formula gives N × M/R, which is the message-switching result. You can use one formula for both cases.
Limits of splitting
Splitting does not help without limit. Each packet carries its own header, so smaller packets mean more total bits on the wire. With a header of h bits and a payload of L bits, the formula becomes (N + P − 1) × (L + h)/R, where P = ⌈M/L⌉. Very small packets increase P, and the header overhead grows with it. Very large packets lose the pipeline benefit. GATE questions often ask you to choose the packet size that minimises total delay. Compute the formula for each candidate size and compare, or take the derivative if the question lets you treat P as continuous.
Sharing links: statistical multiplexing
Packet switching works well for bursty traffic because link capacity is allocated on demand. This is statistical multiplexing. A user who is idle uses no capacity, so other users can use it.
The standard comparison uses a 1 Mbps link. Each user sends at 100 kbps when active and is active 10% of the time. Circuit switching must reserve 100 kbps per user, so it supports 10 users. Packet switching can admit more, because it is unlikely that many are active at once.
from math import comb
def prob_more_than(n_users, p_active, capacity_users):
"""Probability that more than capacity_users of n_users are active at once."""
return sum(
comb(n_users, k) * p_active**k * (1 - p_active) ** (n_users - k)
for k in range(capacity_users + 1, n_users + 1)
)
# 35 users, each active 10% of the time, link carries 10 active users
print(prob_more_than(35, 0.1, 10)) # about 0.0004With 35 users, the chance that 11 or more are active together is about 0.04%. Packet switching supports 3.5 times as many users as circuit switching with little penalty. When too many users are active, packets wait in buffers. If a buffer fills, the router drops packets.
Behaviour to remember
| Property | Packet switching | Circuit switching |
|---|---|---|
| Setup before data | None | Required |
| Capacity | Shared on demand | Reserved for the call |
| Delay | Variable, includes queuing | Nearly constant after setup |
| Congestion effect | Queuing, then packet loss | Call blocked at setup |
| Best for | Bursty traffic | Steady traffic such as voice |
The following points often cause errors:
- A packet that is dropped must be detected and resent by a higher layer. The network layer does not guarantee delivery.
- In a datagram network, packets from the same message may take different paths and arrive out of order.
- Queuing delay is zero in the standard GATE formulas unless the question mentions it. Read the question for statements such as "ignore queuing and processing".
- Check units. A rate in Mbps means 10^6 bits per second, and a packet size in bytes must be multiplied by 8.
Exercise
A message of 10,000 bits crosses 3 links, each with a rate of 1 Mbps. Ignore propagation, queuing, processing and headers. Compare the delay when the message is sent as one unit with the delay when it is split into 10 packets of 1000 bits.
Show answer
One unit: 3 × 10,000 / 1,000,000 = 30 ms. Split into packets: (3 + 10 − 1) × 1000 / 1,000,000 = 12 × 1 ms = 12 ms. Splitting saves 18 ms.
Exercise
A 1500-byte packet crosses 4 store-and-forward links of 100 Mbps each. The total cable length is 2000 km and the signal speed is 2×10^8 m/s. Find the end-to-end delay of the packet, ignoring queuing and processing. How many routers does the packet pass through?
Show answer
The packet has 12,000 bits. Transmission per link is 12,000 / 10^8 = 120 µs, so four links give 480 µs. Propagation is 2,000,000 / 2×10^8 = 10 ms. Total delay is 10.48 ms. A path of 4 links has 3 routers.