CS | Computer Networks Note (No.3)

CS | Computer Networks Notes (NO.3)

Table of contents

  • 1-4 Life of a Packet
    • 1.4.1 TCP Byte Stream
    • 1.4.2 Three Way Handshake
    • 1.4.3 Two Address
    • 1.4.4 The "Hops" and "Routers"
    • 1.4.5 A forwarding table

1-4 Life of a Packet

1.4.1 TCP Byte Stream

The 4-layer model of the Internet takes a stream of data from the application layer.The transport layer breaks this stream into segments of data that it reliably delivers to an application running on another computer. The transport layer sends these segments as network layer packets, which the network layer delivers to the other computer. Let's see what that looks like in practice, the actual packets that a web browser and server sendand receive.

First, let's look at the transport layer. Almost all web traffic is over TCP, the Transport Control Protocol. In its typical operation, there's a client and a server. A server listens for connection requests. To open a connection, a client issues a connection request, which the server responds to. We won't go into the details of exactly how this works, but it turns out this exchange takes three messages, something called the "three way handshake."

1.4.2 Three Way Handshake

  • The first step of handshake is when the client sends a “synchronize" message to the server, oftencalled a SYN.

  • The second step is when the server responds with a “synchronize” message that also acknowledges the clients “synchronize", or a “synchronize and acknowledge message", often calleda SYN-ACK.

  • The third and final step is when the client responds by acknowledging the server's synchronize, often called an ACK.

So often the three way handshake is described as “synchronize, synchronize and acknowledge, acknowledge", or "SYN,SYN-ACK, ACK".

1.4.3 Two Address

Recall that the network layer is responsible for delivering packets to computers, but the transportlayer is responsible for delivering data to applications. From the perspective of the network layer, packets sent to different applications on the same computer look the same. This means that to open a TCP stream to another program, we need two addresses.

  • The first, an Internet Protocol address, is the address the network layer uses to deliver packets to the computer.

  • The second, the TCP port, tells the computer's software which application to deliver data to. Web servers usually run on TCP port 80.So when we open a connection to a web server,we send IP packets to the computer running the web server whose destination address is that computer's IP address. Those IP packetshave TCP segments whose destination port is 80.

1.4.4 The "Hops" and "Routers"

But how do those IP packets get to their destination? We don't have a direct wire connecting myclient to the server. Instead, my client is connected to an intermediate computer, a router. This routeris itself connected to other routers. IP packets between the client and server take many "hops," where a hop is a link connecting two routers.

For example, since my client is on a WiFi network, the first hop is wireless to the WiFi access point. The access point has a wired connection to the broader Internet, so it forwards my client's packets along this wired hop.

A router can have many links connecting it. As each packet arrives, a router decides which of its links to send it out on. Routers have IP addresses, so it's also the case that it might not forward a packet but rather deliver it to its own software.

For example, when you log into a router using TCP, the IP packets are destined to the router's own IP address.

1.4.5 A forwarding table

How does a router make this decision? It does so through something called a forwarding table, shown here on the right. A forwarding table consists of a set of IP address patterns and the link to send across for each pattern.

When a packet arrives, the router checks which forwarding table entry's pattern best matches the packet. It forwards the packet along that entry's link. Generally, "best" means the most specific match.

In this simple example let's just consider the default route, the first entry in the table above. The default route is the least specific route -- it matches every IP address. If, when a packet arrives, there isn't a more specific route than the default route, the router will just use the default one.

The default route is especially useful in edge networks. Say, for example, you're Stanford University and have a router connecting you to the larger Internet. Your router will have many specific routesfor the IP addresses of Stanford's network: "send packets to the engineering school over this link",“send packets to the library over that link.” But if the destination IP address isn't Stanford's, then the router should send it out to the larger Internet.