Datagram
The basic unit of data transferred in the network layer.
0 | 4 | 8 | 16 | 24 | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Version | IHL | DSCP / ToS | Total Length | ||||||||||||||||||||||||||||
Identification | Flags | Fragment Offset | |||||||||||||||||||||||||||||
TTL | Protocol | Header Checksum | |||||||||||||||||||||||||||||
Source IP Address | |||||||||||||||||||||||||||||||
Destination IP Address | |||||||||||||||||||||||||||||||
Options (0–40 bytes) | |||||||||||||||||||||||||||||||
Payload (0-65,536 bytes) | |||||||||||||||||||||||||||||||
Header fields:
- Version (4 bits)
IP version. Set to4for IPv4. - IHL (4 bits)
Internet Header Length. Header size in 32-bit words. Minimum5= 20 bytes. - DSCP/ToS (8 bits)
Quality of service classification. - Total Length (16 bits)
Full packet size in bytes, header included. - Identification (16 bits)
Groups fragments belonging to the same original datagram. - Flags (3 bits)
Reserved, Don’t Fragment (DF), More Fragments (MF). - Fragment Offset (13 bits)
Position of this fragment within the original datagram, in 8-byte units. - TTL (8 bits)
Decremented by each router. Packet dropped when it reaches . - Protocol (8 bits)
Transport-layer protocol:6= TCP,17= UDP. - Header Checksum (16 bits)
Error detection for the header only. Verified and recomputed at each hop because TTL changes with each hop. - Source IP Address (32 bits)
Sender’s IP address. - Destination IP Address (32 bits)
Receiver’s IP address. - Options (0–40 bytes)
Present only if IHL > 5. Rarely used in practice.
Maximum size of a IPv4 packet is bytes. Payload carries the transport-layer segment (TCP or UDP). As most equipment cannot handle very big packets, usually the maximum transmission unit is capped at 1500 bytes. In that case, the IPv4 payload’s maximum size is 1480 bytes.
Network and Host Parts
An IPv4 address is divided into a network part and a host part.
- Network part
Identifies the network. - Host part
Identifies the device within the network.
Hosts sharing the same network part belong to the same subnet and communicate without a router. The boundary between parts is set by the subnet mask.
Network size is determined by the number of bits in the host part. More host bits means more addressable hosts but fewer subnets from the same block.
IP Address Allocation
- Host assignment
Manually configured, or dynamically via DHCP. - Network assignment
ISP allocates an address block. ISPs receive blocks from a RIR (e.g. APNIC). RIRs receive blocks from ICANN.
Dynamic Host Configuration Protocol
Aka. DHCP. Dynamically assigns IP addresses to hosts. Enables automatic configuration, address reuse, and host mobility.
Uses the DORA exchange:
- Discover
Client broadcasts to locate available DHCP servers. - Offer
Server responds with an available IP address and lease terms. - Request
Client broadcasts a request for the offered address. - Ack
Server confirms the lease. Client configures the address.
Packet Forwarding
Moving a packet toward its destination, hop by hop.
- Same network
Direct delivery to the destination host. - Different network
Forward to the next-hop router.
Routers use forwarding tables keyed on destination network prefix. The datagram is unchanged except for mutable fields (TTL, checksum).
Address Resolution Protocol
Aka. ARP. Maps IP addresses to MAC addresses within a local network. The sender broadcasts a query. The target host replies with its MAC address.
ARP cannot operate beyond the local network because broadcasts do not cross routers.
Longest Prefix Match
Aka. LPM. A router selects the most specific (longest) matching prefix in its routing table when forwarding a packet.
- Software implementation
Tree search. Slow but space-efficient. - Hardware implementation
TCAM. Fast but expensive and power-hungry.
Fragmentation
In IPv4, any router can fragment a packet that exceeds a link’s MTU. Reassembly happens only at the destination.
The Identification, Flags, and Fragment Offset header fields coordinate fragment reassembly. The MF flag marks all fragments except the last. Fragment Offset gives the fragment’s position in the original datagram.
Limitations
- Address exhaustion
32-bit addresses cap the pool at ~ billion. Insufficient for the number of connected devices. - Routing table growth
Flat addressing caused global BGP tables to exceed 1 million entries. TCAM storage is expensive, power-hungry, and physically limited. - LPM cost
Longest prefix match over large tables is costly even with TCAM. - Convergence delay
Topology changes propagate slowly when routing tables are large.