Skip to content
BIASED

Computer networks

Layers and encapsulation, Ethernet/MAC, IP and routing, ports, UDP/TCP, DNS, latency vs bandwidth.

Layers and encapsulation

Pipes and local sockets live inside one kernel. A network is a shared medium for bits between machines that may disagree on everything else. Layers solve one problem each and talk only to neighbours. On the way out each wraps the payload in its header (encapsulation); on the way in each strips its own.

The Internet stack the course uses is:

Layer Job Examples
Application meaning of bytes HTTP, DNS
Transport process-to-process TCP, UDP
Network host-to-host across networks IP
Link hop on one segment Ethernet, Wi-Fi

A full Ethernet frame carrying TCP often holds 1,460 bytes of TCP payload inside 1,518 bytes on the wire (14 B Ethernet + 20 B IP + 20 B TCP + 1460 + 4 B FCS). Numbers vary with options and VLAN tags; the idea is headers stacked around the data.

UDP, TCP and DNS

A port (16 bits) selects the receiving process on a host. UDP sends datagrams: no connection, no delivery or order guarantee, but message boundaries survive — DNS queries often use it. TCP opens a connection with a three-way handshake (SYN, SYN+ACK, ACK), then provides a reliable ordered byte stream with no message boundaries, a receive window for flow control and a congestion window for the path. Closing uses FIN/ACK exchange; recv returning 0 is end of stream.

DNS maps names to addresses through a tree of servers, walked by a recursive resolver and cached by TTL. Time for a small request is dominated by latency: one-way delay LL gives RTT≈2L\mathrm{RTT} \approx 2L. Transfer time for SS bytes at bandwidth BB bits/s is about T=L+8S/BT = L + 8S/B for a one-way send after the path is ready; filling a fat path needs about B⋅RTTB\cdot\mathrm{RTT} bytes in flight (bandwidth-delay product). Next — Sockets: the API that binds these ports to file descriptors.

Endianness and checksums sit under these layers: IP and TCP headers store multi-byte fields big-endian, and each header carries a checksum the kernel verifies before the socket queue sees the bytes. Middleboxes and NATs rewrite addresses and ports; applications that embed addresses inside payloads break when the outer header changes.

Loss recovery distinguishes TCP from UDP. TCP acknowledges data, retransmits on timeout or duplicate ACKs, and slows the congestion window when the network is full — the “slow start / congestion avoidance” story. UDP applications that need reliability reinvent pieces of that (QUIC does it in user space over UDP). For this course the takeaway is sharper: choose UDP when you can tolerate loss and want boundaries; choose TCP when you want a stream and are willing to pay for handshake and head-of-line blocking.

Latency numbers ground design. Inside a datacenter RTT may be tens or hundreds of microseconds; across continents it is tens or hundreds of milliseconds. A 100 ms RTT with a 1 Gbit/s path has a bandwidth-delay product of about 10810^8 bits ≈ 12.5 MB in flight to fill the pipe — window sizes and buffering must match that scale, whether in the kernel’s TCP stack or in a userspace protocol.

IPv6 widens addresses to 128 bits and changes neighbor discovery, but the layering story is the same: DNS returns AAAA records, sockets use AF_INET6, and getaddrinfo hides the choice when programs are written the modern way. Link-local addresses and multiple prefixes per interface are why “the” IP of a host is often a list.

Putting it together with the next topic: an application that calls socket/bind/listen/accept never builds an Ethernet frame by hand. The kernel’s stack fills MAC and IP headers, runs ARP, fragments if needed, and retransmits TCP segments. The socket API is the narrow waist between process and network — the same philosophical role read/write play for files.

Worked sizing: a 1460-byte TCP payload inside a 1518-byte Ethernet frame is about 96% efficient on the wire; a 1-byte payload in the same headers is under 1% — another reason bulk transfers matter and tiny RPCs hurt.

The socket topic next makes these layers programmable: bind a port, accept a connection, and the kernel fills every header below the application.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.