Notes on Computer Networks
A computer network is created when two or more computers share data in some way. The most famous computer network (the Internet) is composed of tens of billions of devices connected via a lot of networking infrastructure (routers, switches, etc.). The Internet can be modeled as having 5 core layers.
The Five Layer Internet Protocol Stack
| Layer Name | Description | Protocols / Hardware |
|---|---|---|
| Layer 5: Application | The interface users interact with to send/receive messages. It handles high-level data exchange. | DNS, SMTP, HTTP, BitTorrent |
| Layer 4: Transport | Breaks data into segments. Ensures they arrive in the correct order without errors. | TCP, UDP |
| Layer 3: Network | Moves datagrams between hosts (routing) using IP addresses (IPv4/IPv6). Determines the best physical path. | IP, ICMP, OSPF, Routers |
| Layer 2: Data Link | Encapsulates datagrams into frames. Moves data between nodes on the same network using MAC addresses. | 802.11 (Wi-Fi), Ethernet, Switches |
| Layer 1: Physical | The actual hardware level. Transmits raw bit streams (1s and 0s) over physical media. | Ethernet cables, Fiber optics, Radio waves |
Encapsulation
How do the layers and protocols that run on each layer communicate with each other?
Layers receive messages from the layer above it. Once a message is received by a given layer, a layer specific header is appended to that message. For example, the transport layer receives a message (M) from the application layer and appends a header (TLH) to the message it receives. This creates a segment which is an application layer message with a transport layer header appended to it. We say a segment encapsulates the application layer message.
If we move down a layer then we see that the network layer appends its own header (HN) to a segment thus creating a datagram. The HN includes information about the source and destination addresses of the end hosts.
At each layer the message is a combination of two parts:
- the payload, which is the message from the layer above
- the new appended header information.
At the receiving end this process is reversed with headers being stripped off at each layer which is called de-encapsulation.
Routers and layer 2 switches do not implement all the layers of the protocol stack. Routers implement layers 1-3 and layer 2 switches just implement layers 1 and 2. End-hosts implement all five layers while the intermediate hosts do not. This is an intentional design choice known as the end-to-end principle. This keeps the core of the Internet simple while pushing complexity to edges.
The Transport and Application Layers
- the transport layer is responsible for end-to-end communication between hosts. TCP and UDP are transport layer protocols.
- multiplexing is the process by which data is sent from multiple processes and travels over the network. This is done by the sender of a message.
- demultiplexing is when a receiver takes a message and routes it to the correct socket
- How is it decided where a packet goes?
- connectionless all packets with the same destination port go to the same socket, no matter who sent them
- with connection-orientated muxing each connection gets its own socket, even if they share the same destination port
- serialization is the process by which a data structure is converted into a "flat format" such as a stream of bytes or a string so it can be easily stored, transmitted over a network or reconstructed at a later time
- UDP is connectionless and TCP is connection-orientated
TCP/UDP
- TCP offers:
- guaranteed delivery of the application layer messages
- flow-control
- congestion-control so that the sender slow its transmission rate when it perceives the network to be congested
- UDP offers:
- Connectionless, best-effort service to the applications that are running in the layer above without reliability, flow or congestion control guarantees
- At the transport layer, we refer to the packet of information as a segment