Markus Löning

Software Engineering & Machine Learning

Network engineering

Posted at Jul 24, 2025 23:07:58 — Last modified at Dec 28, 2025 09:41:34

Intro

I recently had to think more about network engineering. Here are my notes from reading Beej’s Guide to Network Programming and Computer Networking: A Top-Down Approach.

Overview

Five-layer version of Open System Interconnection (OSI) model:

LayerNameProtocol Data UnitFunctionDiagnostic Tools
5ApplicationDataProtocols for data exchange, resource sharing and remote file access (e.g. HTTP, SMTP, LDAP, DNS)Loggers, debuggers
4TransportSegmentLogical communication between processes on network hosts, including segmentation, reliability and multiplexing (e.g. TCP, UDP, ICMP)netstat, nc (netcat), tcpdump
3NetworkPacket, DatagramLogical communication between network hosts, including addressing, routing and traffic control (e.g. IPv4, IPv6, ICMP)ifconfig, route, ping, traceroute
2Data linkFrameTransmission of data between network hosts connected by a physical layer (e.g. Ethernet, WiFi)arp, ndp, tcpdump
1PhysicalBit, SymbolTransmission of raw streams over a physical medium (e.g. copper/fibre wires, WiFi/radio waves)Hardware status lights, ifconfig

Level 5 is sometimes broken down further (7-layer model), but for a high-level understanding, the differences are not critical; they all concern the application.

Intuitively, the layers works like a postal system. When sending a message, each layer passes its message (payload) down to the next layer, which wraps it in its own envelope, adding its own layer-specific information (headers) (see encapsulation). At reception, the reverse happens. Starting from the physical layer, each layer unwraps the message using the information in the headers and passes it up to the next layer (de-encapsulation). Each layer only acts on its layer-specific headers, leaving the rest untouched. In practice, encapsulation and de-encapsulation is more complex: a message may be split up into multiple segments, which in turn are split up into multiple datagrams.

The network edge consists of end systems (hosts) like computers and servers where applications run, while the network core is the mesh of routers and switches that interconnects them. Most complexity is designed to be in the network-edge devices (end systems), including the application and transport layer (see End-to-end Principle). Network-core devices, including everything from the network layer and below, are designed to be simple.

Upper layers are constrained by services provided by lower layers (e.g. physical limitations like bandwith or transmission delay), but can build services on top to remedy lower-level limitations (e.g. TCP provides reliable data transfer on the transport layer on top of the unreliable network layer IPv4 protocol).

Much of modern network engineering is defined by specific conventions adhered to by millions of networks around the world, rather than physical laws or an overarching, central design. Conventions are primarily defined by the Internet Engineering Task Force (IETF) in Request for Comments (RFCs).

Physical layer

While upper layers deal with logic, software and data, the physical layer is concerned with the transmission of raw bit streams over a physical medium. It bridges the gap between the digital and physical world (electricity, light, radio waves).

Transmission media

Real-world wireless transmission speed is typically lower due to interference, distance and shared bandwidth. Wired connections offer more consistent speeds and lower latency.

Signal encoding

Transmission modes

Devices

The link layer is responsible for node-to-node transfer of data across a physical link (hop-to-hop). It ensures data moves correctly from one device to the next one in the chain.

Key Responsibilities

The link layer is hop-to-hop rather than end-to-end. It gets the data to the next device in the network, not the final destination (e.g. connecting single laptop to the nearby Ethernet switch).

Link-layer functionality is primarily implemented in hardware on the network interface card (NIC) (fast bit sending/receiving), with software managing setup, addressing assembly and communication with the network layer (encapsulation/de-encapsulation).

The link layer defines two main connection types:

The link layer is also often divided into two sub-layers:

Devices

Services

Services provided by link layer:

Error detection and correction

Channel partitioning protocols

Random access protocols

Taking turns protocols

Local area network (LAN)

Switched LAN

Ethernet

Virtual LAN (VLAN)

Address Resolution Protocol (ARP)

Network layer: data plane

Control vs data plane

Control plane

Data plane

Router

Components

A router has the following components:

Input port processing (destination-based forwarding)

Switching

Output port processing

Queuing

Internet Protocol (IP)

Monitoring and diagnostics

IPv4

Datagram

Total of 20 bytes IPv4 headers + 20 bytes TCP headers

Fragmentation and Reassembly

Addressing

IP address assignment

Dynamic Host Configuration Protocol (DHCP)

Protocol flow for assigning an IP address to a new host:

  1. A new host send a UDP broadcast discovery message to 255.255.255.255:67 (server listens on port 67, client listens on port 68)
  2. Server(s) respond with UDP broadcast offer message, containing proposed address, lease time and ID of the discovery message
  3. Client sends request message choosing from received offer(s)
  4. Server responds with acknowledgement

Private IP addresses

Network Address Translation (NAT)

Proxies and firewalls

IPv6

Datagram

Fields:

Internet control message protocol (ICMP)

Generalized forwarding and software defined networking (SDN)

OpenFlow protocol

Middle boxes

Network layer: control plane

Centralized vs per-router control

Routing algorithms

Distance-vector algorithms (decentralized)

Autonomous systems (AS) and intra-AS routing protocol

Open-Shortest Path First (OSPF) protocol

Inter-AS routing (among Internet Service Providers)

Glues together thousands of Internet Service Providers in the Internet

Border Gateway Protocol (BGP)

IP Anycast

Example:

Software-Defined Networking (SDN)

Components

Controller

OpenFlow API

The OpenFlow API provides message protocols based on TCP based (port 6653).

Controller -> switch (Southbound interface):

Switch -> controller (Northbound interface):

Network management

Transport layer

Principles for choosing transport layer protocols

TCP/IP protocol stack

A single chunk of data, called a segment, is wrapped in a IPv4 or IPv6 packet for transmission which add source and destination IP address, which in turn is wrapped in a data link frame (i.e. “envelopes in envelopes”)

The stack encompasses common protocols including:

UDP

Segment structure

Reliable data transfer

To achieve reliable data transfer, essential aspects include:

These aspects require the following features:

TCP

Segment structure

Network congestion control

Costs of congested networks

Control strategies

Ports

If the subnet mask is like the stream name and the IP address like the house number, then the port is like a room number.

Monitoring and diagnostics:

Quick UDP Internet Connections (QUIC) (HTTP/3)

Application layer

High-level network application design

There are two main types of network applications, client/server and peer-to-peer (P2P). Many applications combine elements of both types.

Client/server

Server is

For example, HTTP web servers.

Peer-to-peer (P2P)

For example, BitTorrent, Skype (VoIP), brokerless messaging systems (e.g. ZeroMQ), message broadcasting.

Sockets

Bind (server) and connect (client)

Domain name system (DNS)

Monitoring and diagnostics:

Hypertext Transfer Protocol (HTTP)

Dynamic Adaptive Streaming over HTTP (MPEG-DASH)

Content Delivery Network (CDN)

Messaging systems

Network messaging systems can be categorized by architecture (centralized vs. decentralized) and data model (transient queues vs. persistent logs).

Why use messaging systems instead of direct HTTP calls?

Clock synchronization

Distributed systems often involve processing timestamp from different clocks, and being able to treat them as if they come from a single, unified time source.

The most common protocol for synchronizing clocks is NTP.

Also check out this blog post.

Security

Let’s Encrypt

Monitoring, diagnostics and debugging

Packet sniffing

tcpdump usage

Alternatively, use Wireshark.

Creating traffic

nc (netcat) usage:

Tracking traffic across the network

Tools

macOS

Linux

Many of the above macOS tools are also available on Linux.

Resources

For more recommendations, see this HackerNews thread.