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.

Gói 1 đi A–R1–R3–R5–B, gói 2 đi A–R2–R4–R5–B A R1 R2 R3 R4 R5 B Nét đậm: gói 1 · nét đứt: gói 2 · R5–B là chặng chung cuối cùng Gói 2 có thể tới B trước gói 1 — TCP dựa vào số thứ tự để ráp lại
Hai gói, hai đường. Router R1 gửi gói 1 sang R3 vì lúc đó R4 đang bận; một khoảnh khắc sau router R2 gửi gói 2 sang R4. Cả hai đường đều 4 chặng, nhưng không ai đảm bảo gói nào tới trước. Nếu R3 hỏng ngay sau khi gói 1 đi qua, các gói sau vẫn tới B qua R4.

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.

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.

Common mistake

Bẫy số một: khẳng định gói tin đi cùng một đường hay tới đúng thứ tự gửi — cả hai đều không được đảm bảo. Bẫy số hai: đếm chặng bằng số thiết bị (ra thừa 1) hoặc bằng số router trung gian (ra thiếu 1). Bẫy số ba: tính số địa chỉ IPv6 so với IPv4 bằng phép chia số bit $128/32=4$ thay vì lũy thừa $2^{96}$.

Key takeaway

Dữ liệu đi thành gói, mỗi gói tự tìm đường từng chặng; vì thế gói có thể lệch thứ tự hoặc mất, và TCP lo ráp lại. Internet mở rộng được vì không có trung tâm và giao thức mở. Mỗi bit địa chỉ thêm vào nhân đôi số địa chỉ.

← The Internet, Protocols and Bandwidth · All AP Computer Science Principles lessons · Practice AP Computer Science Principles questions (free, instant scoring) · Redundancy and Fault Tolerance →