2. The Architecture of the Internet

In Chapter 1, a request from the campus library passed through several routers before reaching the server that held the cat video. The routers were connected by links, but how much did the request depend on the particular technology used for each one? Suppose we replaced a link between two routers with something entirely different. How different could it be before we would have to change the software on the laptop or the server?

To explore that question, imagine a mountain village called Cooville, where the computers already communicate over a local network. Across the valley lies Buffering Heights, a village with an Internet connection, but the terrain prevents the residents from laying a cable or establishing a radio link between them.

Returno, a Cooville resident who wants to bring Internet access to his village, has found someone willing to help: Homer, who lives in Buffering Heights and has offered to share his connection. Together they have trained homing pigeons. When Returno takes one of Homer's birds to Cooville and releases it, the bird flies back to Homer's coop, carrying a small package if one has been attached. Could that package contain something Homer's computer could forward onto the Internet?

How do you get one message across the valley?

Sending data toward Buffering Heights is only half the problem, since Homer also needs a way to reply. Once one of his pigeons has flown home, it has no reason to return to Cooville; a reply therefore needs a different bird, one whose home is in Cooville. By the end of the day, both flocks have returned to their home villages, which are the wrong places for the next day's departures. Each morning, Returno walks to Buffering Heights carrying the Cooville birds that flew home the previous day, then returns with Homer's birds so that both flocks are ready to fly in the required direction. Flights operate only between sunrise and sunset.

The flock that lives in Buffering Heights flies there from Cooville, and the Cooville flock flies the other way. Returno walks each flock back to its launch village in the morning.

Figure 2.1. Each flock can fly only toward its home village, as indicated by the arrows. The lower panel shows Returno returning both flocks to their departure villages each morning.

Start with the simplest task: getting one message from Returno's computer to Homer's. Sketch what you would attach to the bird and how Homer would get its contents into his computer, keeping in mind that the load can weigh no more than about 30 grams. One student suggested printing a QR code, while another proposed putting the bytes on a USB stick. Either could work, but each raises questions about how the receiver interprets what arrives. If a printed code is smudged and Homer can recover only half of it, how will his computer recognize the damage? If a USB stick contains several messages, how will the computer know where one ends and the next begins?

If you chose paper, you would not be the first to consider it. On April 1, 1990, a networking engineer published a proposal for printing a packet, attaching it to a pigeon, and scanning it at the receiving end, complete with a specification for duct tape. Assume now that Returno and Homer have agreed on a way to carry bytes and have begun offering Internet service over their new link, FeatherNet. Each flight takes fifteen minutes, and on a well-stocked morning each village has fifty birds available for that day's departures. With those limits in place, what happens when two customers want to send a message to Homer at the same time?

Who gets the next departure?

Returno and Homer could reserve a share of the birds for each customer, or they could give the next available bird to whichever message is waiting. To understand what a reservation changes, return to the private wires considered in Chapter 1. Because connecting every pair of computers directly required so much wiring, we introduced a switch, a machine that receives data on one link and sends it out on another. In Figure 2.2, A and B can transmit to the switch simultaneously, but when both are sending to D, their packets must share the outgoing link from the switch to D.

Four computers need six wires when each pair is directly connected. In the switched arrangement each computer has one wire to the switch, and A and B both need the outgoing link to D.

Figure 2.2. Although A and B can transmit to the switch simultaneously, traffic destined for D must share the switch's outgoing link to D.

Suppose A and B have each been promised half the capacity of that outgoing link. We could enforce the agreement by dividing time into slots and assigning alternate slots to the two senders. This is one way to implement a reservation: in circuit switching, a connection reserves capacity along its path before sending data. The telephone operator from our earlier example made a reservation by physically connecting wires, whereas our switch does it by setting aside transmission time. Both approaches give a connection a predictable share of capacity once it has been established, but they can also waste that capacity. If A has nothing to send in its assigned slot, the slot remains unused even when B has packets waiting.

A packet switch, by contrast, can decide what to forward separately for each packet, using an available slot for traffic that is actually waiting. Compare the two designs using the same arrivals: at time zero, A has packet A1 while B has B1 and B2; B3 arrives at the beginning of slot 2. Each packet takes one slot to transmit, and the packet switch serves packets in arrival order, choosing A1 first when the initial arrivals are tied. Under each design, when can B2 leave?

The reserved link sends A1 in slot 0, B1 in slot 1, B2 in slot 3, and B3 in slot 5. Packet switching sends those four packets in slots 0, 1, 2, and 3.

Figure 2.3. In slot 2, B2 is waiting while A has nothing to send, so the packet switch can use the slot that a reservation would leave idle. When both senders are continuously busy, packets still have to wait for capacity.

By sharing capacity according to changing demand, the packet switch uses an approach called statistical multiplexing. It can make especially good use of a link when different senders become idle at different times, although it must then decide which waiting packet to send next, how many packets to keep in its queue, and what to discard if the queue fills. Reserving capacity can make a customer's wait more predictable, but doing so takes coordination and may leave usable capacity idle. Extending that promise across a path with several links also requires arranging a reservation on every link along the way.

FeatherNet faces a related choice, although a pigeon departure is not quite like a slot on a wire. As soon as one packet finishes crossing a wire, another can begin; once a bird leaves, however, that departure is gone for the day. Returno can get more use from each flight by loading several packets onto one bird, but waiting for a full load creates another problem. Imagine that the village has been uploading files all morning and, late in the afternoon, one small urgent message arrives with nothing else behind it. A bird is still available and could reach Buffering Heights before dark, yet a rule requiring full loads would leave the message waiting indefinitely. Sending every message immediately avoids that particular delay, but if fifty small messages arrive at breakfast, they could use every bird before the urgent afternoon message appears.

A compromise worth testing is to release a bird either when its load is full or when the oldest packet has waited a specified amount of time, whichever happens first. Returno might also reserve a few birds for messages that arrive later, though doing so could delay or prevent some morning traffic from crossing. The time a packet spends waiting to depart is its queueing delay, which is separate from the fifteen minutes the bird spends in flight. Packing more bytes onto a stick improves the amount of data delivered per departure, but it does not make the first byte cross the valley any faster. Which tradeoff should the service make for its customers?

How does the message get beyond the coop?

Suppose the dispatch rule works and Homer receives a load from Cooville. The load has crossed the valley, but the computer that sent it was trying to reach a server somewhere on the Internet, not Homer's coop. If its only label identifies the coop, Homer knows where the pigeon was supposed to land but has no basis for deciding where the data should go next.

The sending computer can solve this problem by including the server's IP address as the packet's destination and its own IP address as the source. The Internet Protocol, or IP, defines a common format for these addressed packets, known as IP datagrams, so that hosts and routers can handle them across different networks. Rather than planning the entire trip for each datagram, a router reads its destination address and consults a forwarding table to choose a next hop: the next machine to which it should pass the datagram. For now, we will assume that the necessary forwarding tables have already been set up.

A Cooville computer sends through the Cooville router, then across FeatherNet to the Buffering Heights router, then through the Internet to the server. A reply needs a route in the other direction.

Figure 2.4. The pigeon carries the datagram for one hop, to the router in Buffering Heights, even though the datagram's destination is the server beyond it.

As Figure 2.4 shows, a Cooville computer first sends its datagram across the village network to the Cooville router. That router's forwarding table identifies the Buffering Heights router as the next hop toward the server, so it hands the datagram to FeatherNet for the valley crossing. After Homer recovers the load, the Buffering Heights router reads the same destination address and forwards the datagram over its Internet connection. Routers farther along the path make their own forwarding decisions in turn. Because the destination address retains its meaning throughout these handoffs, each router can distinguish the machine that should receive the datagram next from the server that should ultimately receive it.

The return journey requires forwarding information in the opposite direction. When the server replies, it uses the Cooville computer's IP address as the destination, and the wider Internet needs a route that directs traffic for Cooville toward Buffering Heights. The Buffering Heights router must then know to send that traffic across FeatherNet, while the Cooville router must know how to deliver it on the local village network. Routers elsewhere do not need to know which bird will make the crossing; that decision belongs to the equipment at the valley. Draw the return route separately and notice the distinction: including the original sender's address gives the server somewhere to address its reply, but only appropriate forwarding information can bring that reply home.

Now imagine that someone sets out a sunflower-seed buffet in the middle of the valley and a pigeon never completes its flight. Does that mean IP has failed to meet its promise? Not necessarily, because IP provides best-effort delivery rather than a guarantee that every datagram will arrive. It can forward an addressed datagram without first reserving a route, but datagrams may be lost, arrive out of order, or take an unpredictable amount of time. When FeatherNet stops flying at sunset, its own policy may hold waiting datagrams until morning or discard them. Owls might extend the hours of service, but choosing them is not IP's responsibility.

What IP does require from a link is a way to submit a datagram for delivery to the next hop and to recover its bytes if delivery succeeds. The link therefore needs an agreed format and a usable size limit. If a datagram must be divided into smaller pieces to fit the carrier, the receiving link equipment can reassemble those pieces before handing the datagram back to IP. A smudged printout that is mistakenly accepted as an intact packet, or a link unable to carry the packet sizes it claims to support, reveals a problem with the link's design. A properly formatted load that disappears with its pigeon, or waits until morning for a departure, presents a different problem: either can occur on a best-effort path without violating IP's delivery model.

How does the server know which program should get it?

Reaching the right computer is not always enough. Suppose the datagram that has just reached the server contains a request for a weather forecast, but that server also runs a program for accepting crop reports. The destination IP address identifies the computer, not which of its programs should handle the request, so the receiving system needs another piece of information.

That information is a port number, which the receiving computer uses to direct data to the appropriate program. We might assign port 4000 to the crop-report program and port 4001 to the weather program, while the client chooses an available source port, such as 51000, to identify where the reply should be delivered. These numbers appear in a transport header attached to the application's data. For the weather query, we can use UDP, a transport protocol that sends each message the application supplies as a separate unit. If a UDP message arrives, the receiving application gets that message as a unit, although the message might instead be lost or arrive after a later one. A weather client may be able to tolerate that uncertainty by retrying a query or ignoring a reply that has become stale.

To see how the query travels, follow it down through the sender's software. UDP first places its transport header in front of the weather request; IP then adds a header identifying the source and destination computers and indicating that the contents should be passed to UDP at the receiving end. Finally, the local link wraps the IP datagram in the information needed for the next hop, producing a link frame. This process of placing a header around data received from the layer above is called encapsulation. The idea is much like packing a labeled box inside another box, with each recipient opening only the wrapping relevant to its part of the journey.

The sender adds UDP, IP, and local link headers in succession. The Cooville router removes the local wrapper and adds a FeatherNet wrapper around the IP datagram. The receiver unwraps the final link frame, IP, and UDP to hand the query to the weather program.

Figure 2.5. The query passes down through the sender's layers and back up to the appropriate program at the server. Routers replace the wrapping for each local link, while the IP addresses and UDP ports in this example remain the same.

When the frame reaches the Cooville router, its original link wrapper has served its purpose. The router removes that wrapper, examines the IP destination, and passes the datagram to FeatherNet, which adds its own wrapping—perhaps a record containing the load's length and a check for damage to the data on the stick. Some IP header fields can change as the datagram travels: for example, each router reduces its remaining hop allowance to prevent it from circulating indefinitely. In our example, however, the source and destination IP addresses and the UDP ports remain unchanged, and the router has no need to inspect the UDP header merely to forward the datagram. At Buffering Heights, the FeatherNet wrapper is removed and replaced by one suitable for the Internet-facing link. When the datagram finally reaches the server, the server removes its final link wrapper, uses the IP protocol field to pass the contents to UDP, and then uses UDP's destination port to deliver the query to the weather program.

A weather query may be useful even if an occasional message goes missing, but uploading a crop-report file raises different concerns. A report with missing numbers may be unusable, so Returno's computer could choose TCP, which provides the communicating programs with an ordered stream of bytes. The sending program can write a thousand bytes without deciding how to divide them into packets, while TCP handles transmission and can resend missing data if a packet is lost. The receiver may hold later bytes until a gap has been filled, allowing the receiving program to read the bytes in their original order. That guarantee does not mean the entire file will necessarily arrive: if the connection fails, the program may have received only its beginning. Nor does TCP identify file boundaries within the stream, so the application might need to put a length at the start of each file. This is the essential contrast: TCP preserves byte order in a stream, whereas UDP preserves the boundaries of individual messages.

The system we have built can now be described in four layers. The application determines what the data means; transport identifies the receiving program and provides either messages or a byte stream; IP carries addressed datagrams across networks through a sequence of hops; and the link, together with its physical medium, carries data across the next hop. IP's position between the varied services above it and the varied links below it is sometimes called the Internet's narrow waist. Many transports and applications can rely on the same IP service, while IP can operate over many different kinds of links. If someone eventually digs a tunnel between the villages and installs fiber, the routers at either end will need equipment for that new link, but the weather application need not be rewritten. Provided the addresses and routes still work, someone in Cooville could ask whether rain is coming and receive the answer quickly enough to bring a coat.

Who can tell whether the whole file arrived?

Suppose Homer receives the final packet of a file across FeatherNet and acknowledges its arrival, only for that packet to be dropped on the next link beyond Buffering Heights. If Returno now tells the sending program, “Your file arrived,” what has he actually confirmed? Receiving a load at the end of the valley is not the same as delivering it to the server, much less saving the complete file there.

Homer's acknowledgment can establish that a load crossed the valley, while TCP acknowledgments can tell the sending transport that bytes reached the receiving transport. Even that is not proof that the file was saved successfully: the server might run out of disk space after receiving every byte. Only the receiving file program can check whether it saved the entire file and verified its contents, perhaps by comparing its length and a fingerprint of the saved data with the sender's expectations. It could then send a receipt describing what it checked, although the receipt itself might be lost. If the sender hears nothing, it cannot distinguish between a file that never arrived and one that was saved successfully but whose receipt disappeared. How could it ask again without accidentally creating a second copy?

This illustrates the end-to-end principle: when success means that a complete, intact file has been saved, the applications at the two ends possess information that the intermediate machines do not. Lower layers can still perform useful parts of the work. A Wi-Fi link, for example, may retry a lost transmission locally instead of forcing the sender to retransmit data across the whole route. FeatherNet could likewise retain copies of loads and resend them when a pigeon disappears, although acknowledgments and replacement flights would consume birds that other customers might need. Such measures can improve delivery along the way, but they cannot replace verification by the receiving application when that is where successful delivery is defined.

Reliability is not the only issue that the application must consider; the time spent waiting for replies can matter just as much. If an entire file is ready at dawn and the sender is allowed to have several loads in flight, many pigeons can depart together. An application that needs an answer before it can decide what to ask next behaves differently, because each dependent request must wait for a reply to cross the valley. Figure 2.6 compares that situation with an ordinary link, assuming that birds are available at both ends, departures happen immediately, and reading or writing a load takes negligible time.

On an illustrative ordinary link the trip takes 10 milliseconds each way. On FeatherNet a load takes 15 minutes each way. Three dependent exchanges take at least 60 milliseconds or 90 minutes respectively, and there are no flights at night.

Figure 2.6. Multiple ready loads can travel concurrently, but a client that depends on each reply must wait for a full round trip before continuing. The timelines use different scales and exclude extra delays from queueing, loss, or nightfall.

In this model, fifty loads that each fit on a bird can all be airborne at once, yet three dependent request–reply exchanges still require at least ninety minutes of valley-crossing time, even if each message contains only a few bytes. TCP file transfers also involve traffic from the receiver, so connection setup, acknowledgments, recovery from losses, and limits on unacknowledged data can further affect completion time. A client with a ten-second timeout will give up before the first reply could possibly return, whereas one designed to wait may still function. An interactive application that depends on prompt responses, such as the castle game from Chapter 1, would behave very differently over FeatherNet. If tonight's work depended on confirming a completed file transfer before sunset, what would you change in the file-sending application?

What would you tell the FeatherNet designers?

Homer and Returno have named the Internet service they are building Wingternet. Before they accept more customers, prepare a design brief explaining what they should test, using your sketch of the first message crossing as a starting point. Your brief should address the following questions.

  1. Make a link for IP. What information and data should a bird carry, and under what conditions can the receiving router hand the recovered bytes to IP? Explain how the link handles a damaged load, a missing bird, and the end of the flying day.
  2. Set a departure rule. Decide how much data to accumulate on each bird, when a partly filled load should depart, and whether some flights should be reserved for later traffic. Propose one measure of useful bytes delivered per day and another of the waiting time that matters to a customer.
  3. Choose what to change above IP. Compare a file transfer that can prepare all its data in advance with an application that must wait for each reply before continuing. Which could operate unchanged, which would need tuning, and which would require a different way of working? Justify each decision with a concrete timer or dependency.
  4. Make packets find Cooville. The computers in Cooville already have electricity and an ordinary local network. Explain how you would give them distinct, ordinary IP addresses reachable through the village router, then trace a packet to an Internet server and a reply back home. Identify what the routers in the two villages and the wider Internet must know. For now, assume someone can assign addresses and install routes; later chapters will explain how.

Break this. Imagine that forty-nine routine departures have already taken place, leaving just one bird. A routine load is ready now, but an urgent message might arrive five minutes before the latest departure that could reach Buffering Heights before dark, and the two loads will not fit together. Test your rule both on a day when the urgent message arrives and on a day when it never does. What does the rule sacrifice in each case? Revise your brief accordingly, identifying which machines need to know about the new rule. If the Internet server itself must learn how to release a pigeon, reconsider what you decided to put on the bird.

Chapter 2 source notes