The Network Layer

Overview

The network layer, embodied by IP on the Internet, is the glue that connects millions of LANs together. When one computer wants to send data to another computer over the Internet, it puts a chunk of the data into an IP Packet. It then sends this packet to another device on the same link layer network. That device then forwards the packet along, and the process is repeated until the packet reaches its destination. The number of devices that a packet passes through on its journey is known as the number of Hops in its path.

IP Addresses

When billions of computers are connected together, they need a way to refer to each other. If a computer in France wants to send a packet to a computer in China, it needs to put an address on the packet so that the Internet will know where to send it. To that end, IP uses IP Addresses, which are 32-bit numbers that uniquely identify computers on the Internet. There are roughly four billion possible IP addresses, and the world is quickly running out of them. Since the current version of IP (version 4) specifies that IP addresses must be 32 bits, researchers have devised a specification for a new version, IP Version 6 (IPv6), which uses 128-bit addresses. This corresponds to more than ten billion billion billion times as many addresses as IP Version 4, so it will likely serve the needs of the world for quite a while. However, IPv4 is so entrenched in the Internet that IPv6 has yet to take over despite over a decade of availability.

The Internet Corporation for Assigned Names and Numbers (ICANN) is in charge of handing out numbers. Usually, ICAAN gives a block of addresses to an Internet Service Provider (ISP), which in turn distributes them to its customers. In the early days, a person would need to ask their ISP or network administrator for an IP address, which they would then need to manually enter into their computer. Recently, this task has been automated by the Dynamic Host Configuration Protocol (DHCP). When a computer first connects to a network, it sends a link-layer frame to the broadcast address asking for an IP address. Another computer on the network, which has been programmed to distribute IP addresses, receives the request and responds with an offer. For the next few hours, the requester can use the address as the source address for packets it sends and receive the packets sent to that address.

Routing in the Internet

When a computer sends a packet to some other computer on the Internet, that packet will have to follow some path through the Internet. The creation of this path is known as Routing. In general, routing does not occur all in one place. Instead, each machine that receives a packet makes its own decision as to the best place for the packet to go next. In the case of a home or office computer, this decision is usually straightforward: the computer just sends any packet to the address of its Gateway. When a computer receives an offer for an IP address using DHCP, the offer also contains an address to which the computer can send packets bound for the Internet. A gateway or series of gateways generally take a packet to the ISP.

Once a packet gets to the 'core' of the Internet, things get slightly more complicated. Unlike home or office networks where there is usually a straightforward path of gateways for a packet to follow, the machines owned by an ISP are usually connected together in a mesh. These machines, which are generally special purpose computers called Routers, have many ports and can forward an incoming packet out any port. This gives rise to several complications.

One major consequence of connecting routers in a mesh is that there is no immediately obvious next hop for a packet. Routers must instead construct Routing Tables, which they use to determine the next hop for a packet based on its IP address. However, since there are roughly four billion possible IP addresses, a complete table of them would have roughly four billion entries. This is impractical, since the tables would be big and using them would be slow. Instead, IP addresses are allocated in a Hierarchical fashion. When an ISP needs IP addresses, ICANN gives them a group of addresses that all begin with the same prefix. This means that routing tables can have entries that say 'send any packet destined for an IP address whose first 12 bits are X to this location'. This shrinks routing tables to a much more reasonable size. The creation of these tables is a complicated topic that is beyond the scope of this website. For more information on the subject, see a textbook or online resource on routing.

Another consequence of connecting routers in a mesh is that the load on different ports can vary erratically. A 40-port router could suddenly receive a barrage of incoming packets on 39 of its ports that all need to be sent out the 40th port. Since a router understandably cannot squeeze 39 ports worth of packets out one port, the packets are stored in a temporary storage area known as a Buffer. This process is known as Queuing since a packet wait in line for their turn to be sent. This sort of traffic jam can slow things down considerably. Moreover, since buffer space is limited, a packet can arrive to find that the buffer is full. In this case, the packet is Dropped, which means that the router deletes it and forgets about it entirely. Since the Internet is a best-effort service, there is no guarantee that a packet will make it all the way to its destination. Adding reliability on top of this unreliable network is the job of the transport layer.

The Address Resolution Protocol

Thus far, we have glossed over one very important point. Even when a computer knows the IP address of the next hop for a packet, how does it translate this into a MAC address? When a computer wants to send a frame containing an IP packet to the next hop, it needs some way to translate the IP address of that next hop into a MAC address. This is accomplished using the Address Resolution Protocol (ARP).

To determine the MAC address corresponding to an IP address, a computer sends a frame to the broadcast address asking 'who has this IP address?' The owner of that address then sends a frame back to the sender saying 'I do'. The receiver then examines the source MAC address of that frame, and uses it as a destination address for the packet. The receiver also stores the address in a table for about fifteen seconds so that it does not constantly spam the network asking for the same information.