Networking
Table of Contents
1. Network Layering
We define networking protocols into many levels, each with a different responsibility:
- Physical layer: mechanical and electrical network
- Link layer: packet formats, error control (e.g. CSMA/CD)
- Network layer: network routing and addressing
- Transport layer: reliable message delivery
We can use the OSI model for layering (Open Systems Interconnection). It defines seven layers, of which Internet Protocol (IP) uses five; the functionalities of the missing layers are provided by the Application layer:
Each layer is defined by a service (what a layer does), the service interface (how to access the service), and a protocol (how peers communicate to implement the service).
1.1. Physical Layer
- Service: move information between two systems connected by a physical link.
- Interface: specifies how to send and receive bits.
- Protocol: coding scheme used to represent a bit, voltage levels, etc.
Examples include coaxial cable, optical fiber links, transmitters, receivers, etc. Routing is limited to within a physical link (wire) or perhaps through a switch, and packets of a limited size (the maximum transfer unit or MTU, often 200-1500 bytes).
1.2. Datalink Layer
- Service: enable end hosts to exchange frames on the same physical link.
- Interface: send frames to other end hosts; receive frames addressed to end host.
- Protocol: addressing, MAC, etc.
Each frame has a header wihch contains a source and a destination MAC address.
Local area networks or LANs are a group of hosts/devices that are in the same geographical proximity and use the same physical communication terminology. Examples include all laptops connected wirelessly at a café, or all host connected to wired Ethernet in an office.
Hosts in the same LAN can also be connected by switches. A switch forwards frames only to the intended recipients, which is far more efficient than a broadcast channel.
Typically, each network card is associated with two addresses:
- Media Access Control (MAC) address (or physical address)
- IP address (or network address)
The MAC address is a 48-bit unique identifier that is assigned by the card vendor when it is manufactured, and should be unique for every card that is produced. The IP address is a 32-bit (or 128-bit for IPv6) address either assigned by a network administrator or dynamically assigned by the network.
1.2.1. MAC Protocols
How do hosts access a broadcast media? How do multiple hosts who want to access this media prevent collisions? There are three solutions to this: channel partitioning, taking turns, or random access.
Channel partitioning methods such as frequency division multiple access (FDMA) allocates some fraction of the bandwidth to each host. This allows it to share the channel efficiently and fairly at high load, but inefficently at low load (1/N bandwidth even if only 1 active node).
We can also take turns, such as with a token ring. The idea is that we can pass around the token between the active hosts, and a host can only send data if it has the token. It is more efficient at low loads because there is also overhead in acquiring the token, and it is vulnerable to failures involving failed nodes or lost tokens.
Finally, there is random access, which is very efficient at low load, but has collision overhead under high load. Collisions can be handled with CSMA/CD: carrier sense, multiple access with collision detection. Carrier sense means to not send unless the line is idle, collision detection means that the sender checks if a collision happens. Then, there is a backoff scheme where we choose a wait time before trying again. This simple scheme was used in Ethernet in the early 80’s.
1.3. Network Layer
- Service: deliver packets to specified network address across multiple datalink layer networks.
- Interface: send packets to specified network address destination; receive packets destined for end host.
- Protocol: define network addresses, forwarding tables, packet forwarding.
The network layer for the internet is built upon the IP address: a unique address assigned to a network device. It provides “best-effort” packet delivery, which is to say packets may be lost, corrupted, or delivered out of order (called a datagram service).
1.3.1. IPv4 Address Space
The IPv4 standard defines a 32-bit integer used as the destination of an IP packet. It is often written as four dot-separated integers, with each integer from 0 to 255 (thus representing 8 times 4 which is 32 bits). A subnet is a network containing hosts with related IP addresses. The subnet is identified by a 32-bit value, bits which differ set to zero, followed by a slash and a mask. For example, 128.32.131.0/24 designates a subnet in which all the addresses look like 128.32.131.XX. The mask is the number of matching prefix bits, and can be expressed as a single value (e.g. 24) or a set of ones in a 32-bit value (e.g. 255.255.255.0).
The IP address space is divided into prefix-delimited ranges:
- Class A: NN.0.0.0/8
- NN is 1-126
- 10.xx.yy.zz is private
- 127.xx.yy.zz. is loopback
- Class B: NN.MM.0.0/16
- NN is 128-191, MM is 0-255
- 172.[16-31].xx.yy are private
- Class C: NN.MM.LL.0/24
- NN is 192-223, MM and LL are 0-255
- 192.168.xx.yy are private
Address ranges are often owned by organizations. Additional network ranges are reserved for multicast.
We use IP address and not MAC addresses for network routing because MAC does not scale. First of all, a MAC address stays the same as your location changes. Moreover, IP scales much better: IP addresses can be aggregated, e.g. all IP addresses at UC Berkeley start with 0xA9E5, so any address of the form 0xA9E5**** belongs to Berkeley.
1.3.2. Routing
A wide area network or WAN is a network that covers a broad area (e.g. city, state, country, entire world). For example, the Internet is a WAN. A WAN connects multiple separate LANs, often with routers.
A router forwards each packet received on an incoming link to an outgoing link based on the packet’s destination IP address. Packets are buffered before being forwarded. It also has a routing table, which is a mapping between an IP address and the output link. We don’t need 4 billion entries in the table, though, we can just route by subnet. For subnets without explicit entries, there is also a default route which forwards the packet to a more authoritative router.
How exactly do you set up routing tables? No single machine knows the entire topology, and the topology is constantly changing. We need a dynamic algorithm that acquires routing tables. The Border Gateway Protocol (BGP) is one algorithm that does this and is used to connect large networks.
1.3.3. Domain Name System
How to map human-readable names to IP address? If we type in ssl.berkeley.edu, we need to map it to 128.32.13.233; and for www.google.com, we may map it to different addresses depending on location and load!
The Domain Name System or DNS is a hierarchical mechanism for naming. A name is divided in domains, from right to left: www.eecs.berkeley.edu. Each domain is owned by a particular organization: the top level (e.g. .com) is handled by ICANN (Internet Corporation for Assigned Numbers and Names), with subsequent levels owned by organizations.
Names are then resolved to their proper IP addresses. Correct resolution is very important, as if an attacker gives you an incorrect mapping, they can get you to route to a different server. DNS can be thought of a weak link in this regard, as we need to avoid substitution attacks. In July 2008, for example, a hole in DNS security was found where if one person in an ISP convinced to load a particular web page, then all users of that ISP ended up pointing at that wrong address.
1.4. Transport Layer
- Service: provide end-to-end communication between processes and demultiplex communications between hosts.
- Interface: send message to specific process at given destination; local process receives messages sent to it.
- Protocol: port numbers, flow control, packetization, framing, etc.
Examples of transport layer protocols include TCP and UDP. Basic routing only gets us from machine to machine; we want process to process. To do so, we add ports, which are 16-bit identifiers. A connection is defined by a five-tuple:
- Source address
- Source port
- Destination address
- Destination port
- Protocol
The Unreliable Datagram Protocol (UDP, IP protocol 17), for example, uses datagrams: an unreliable, unordered packet sent from source user to destination user (call it UDP/IP). UDP can be thought of as an extension of “best-effort” IP but with multiplexing/demultiplexing between processes.
The Transmission Control Protocol (TCP, IP protocol 6), however, implements reliable in-order delivery of packets. It includes connection setup and teardown, discards corrupted packets, retransmits lost packets, flow control, and congestion control (TCP/IP).
Other protocols include the Datagram Congestion Control Protocol (DCCP), Stream Control Transmission Protocol (SCTP), and the Reliable Data Protocol (RDP).
1.5. Application Layer
- Service: any service provided to the end user.
- Interface: depends on the application.
- Protocol: depends on the application.
Examples include Zoom, SMTP (email), and HTTP (web).
2. Network Address Translation
Network Address Translation or NAT allows multiple clients to share the same public IP. Its purpose is to translate connections with private IP addresses to the public IP address (say of a firewall).
NAT operates in both the network and transport layers. It rewrites source and destination IP addresses in packet headers as traffic passes through the firewall. It can also track connections and rewrite TCP or UDP port numbers when using Port Address Translation.
3. Transmission Control Protocol
All physical networks can garble or drop packets. We need reliable message delivery on top of unreliable packets.
We can ensure the transmission of packets by using acknowledgements. The receiver must acknowledge (by sending “ACK”) when a packet is received properly at the destination; if the sender doesn’t get an ACK after a timeout, retransmit. Note that the sender not getting an ACK doesn’t necessarily mean that the packet didn’t make it: the ACK itself could’ve gotten dropped!
Using this idea, we can implement stop-and-wait with no packet loss:
We send, wait for ACK, then repeat. The Round Trip Time (RTT) is the time it takes for a packet to travel to the receiver and back, and \(d\) is the one-way latency. Assuming symmetric latency, \(\text{RTT} = 2d\). So bandwidth is then 1 packet per RTT. But suppose that RTT is 100 ms and 1 packet is 1500 bytes, then our throughput is 120 Kbps: very inefficient!
We also have to deal with duplication when we retransmit. The solution is to put a sequence number in the message to identify re-transmitted packets. The receiver checks for duplicate numbers and discards them if detected. If we have enough such identifiers, we can start pipelining packets to maximize bandwidth:
A single TCP connection needs four total queues: a send and receive queue on both sides. A host’s window size for a TCP connection is how much remaining space it has in its receive queue. A host advertises its window size in every TCP packet it sends. For TCP, the window is in bytes, not packets:
3.1. Congestion
We also want to avoid congestion with TCP. Congestion is closely related to the window size at sender: too big of a window size means we are putting too much data into the network. We try to match the rate of sending packets with the rate the slowest link can accommodate. TCP tries to “slow start:” if no timeout, slowly increase window size. Timeout implies congestion, so we cut the window size in half.
3.2. Open Connection
The goal is to agree on a set of parameters, i.e. the start sequence number for each side. It must be unique, because if it is possible to predict sequence numbers, then it might be possible for an attacker to hijack TCP connections.
To open a connection, we use a 3-way handshake process:
3.3. Close Connection
A connection is not closed until both sides agree: