Packets, Routing and Scalability
AP Computer Science Principles · Unit 4 — Computer Systems and Networks
Packet switching
Data sent over the Internet is broken into packets. Each packet carries a chunk of the data plus metadata: the source and destination addresses, and (under TCP) a sequence number. Routers forward each packet independently, one hop at a time, choosing the next device based on current conditions. Because the choice is made packet by packet, two packets of the same message can take different paths and arrive out of order, and a packet can be lost when a router is overloaded.
This is called packet switching, and it is the opposite of reserving one fixed line for the whole conversation. Its advantages are efficiency (links are shared by many users at once) and resilience (if a router fails mid-transfer, later packets are simply routed around it). Its cost is that the receiving side must be prepared to buffer, reorder and request missing packets, which is exactly the work TCP does.
Routing on the Internet is dynamic: no device knows a fixed path in advance, and the path used at 9:00 may differ from the one used at 9:01. When an exam question asks which path a packet "will" take, the honest answer is usually that it cannot be determined; what can be determined is which paths are possible and how many hops the shortest one needs.
Why the Internet scales
Scalability is the capacity of a system to change in size and scale to meet new demands. The Internet was designed to scale: there is no central computer that every packet must visit, routing decisions are made locally by each router, and new networks join simply by following the open protocols.
Addresses are a scaling limit. IPv4 uses 32-bit addresses, so it can name at most $2^{32}\approx 4{.}3$ billion devices, which is fewer than the number of connected devices today. IPv6 uses 128-bit addresses, giving $2^{128}$ possible addresses. Adding one bit doubles the count, so going from 32 to 128 bits multiplies the number of addresses by $2^{128-32}=2^{96}$, not by 4.
Counting hops is the other routine calculation. The number of hops on a path is the number of connections crossed, which is one less than the number of devices on the path including both endpoints. A path A–R1–R3–B has 3 hops and 2 intermediate routers.
Worked example: đếm đường và chặng
Trong mạng ở hình trên, (a) liệt kê mọi đường đi từ A tới B không ghé thiết bị nào hai lần, và số chặng của mỗi đường; (b) nếu đường nối R1–R4 và R3–R5 cùng hỏng, còn bao nhiêu đường?
Solution
(a) Từ A có hai lối ra: R1 hoặc R2. Mọi đường đều phải kết thúc bằng R5–B vì B chỉ nối với R5.
- A–R1–R3–R5–B: 4 chặng.
- A–R1–R4–R5–B: 4 chặng.
- A–R2–R4–R5–B: 4 chặng.
- A–R2–R4–R1–R3–R5–B: 6 chặng (từ R4 quay lên R1 rồi sang R3).
Tổng cộng 4 đường, ngắn nhất 4 chặng.
(b) Bỏ R1–R4 thì mất đường thứ hai và thứ tư; bỏ R3–R5 thì mất đường thứ nhất. Chỉ còn A–R2–R4–R5–B. Mạng vẫn thông, nhưng giờ R5 và đường R5–B là điểm mà nếu hỏng thì A mất liên lạc với B — và thực ra R5–B vốn đã là điểm hỏng đơn ngay từ đầu.