UDP - User Datagram Protocol
In questa pagina 5
UDP is the basic transport protocol: connectionless and unreliable. It adds nothing to IP (IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →) except process-to-process instead of host-to-host communication, i.e. port numbers (Transport Layer - Ports and MultiplexingThe transport layer provides logical end-to-end communication between application processes on different hosts and exists only in end hosts; the network layer delivers to the right computer (IP address) and transport to the right process (16-bit port number, 0 to 65535); an IP address plus a port is a socket and the four-tuple of IPs and ports identifies a connection, with multiplexing and demultiplexing done by UDP on the destination socket and by TCP on the whole four-tuple, and the protocols are UDP (connectionless, unreliable), TCP (connection-oriented, reliable) and SCTP.Transport Layer - Ports and Multiplexing →). UDP segments can be lost or reach the application out of order.
Why use it
A process that sends a short message and does not care much about reliability is much faster with UDP than TCP:
- no connection setup (adds delay);
- no congestion control: UDP can send at the rate the application wants;
- simple: no connection state at either end (stateless);
- small header: 8 bytes versus at least 20 for TCP;
- supports multicast.
Format
The header is 8 bytes, four 16-bit fields:
| bits 0-15 | bits 16-31 |
|---|---|
| source port | destination port |
| UDP length | checksum (optional) |
| data |
Length: header plus data in bytes; since the datagram travels in an IP datagram of at most 65 535 bytes with a 20-byte header, UDP data is at most bytes; minimum length 8.
Formula. . Example: length 12 carries bytes.
Services
- Process-to-process with socket addresses .
- Connectionless: each user datagram is independent, unnumbered, may follow a different path.
- No flow control (no window; the receiver can be overwhelmed). No error control except the checksum: a datagram with a wrong checksum is discarded, silently. No congestion control (UDP assumes small sporadic packets; a UDP video flow does not slow down in congestion, at the expense of TCP flows: TCP Congestion ControlCongestion arises when fast links feed a slow one, router queues fill and packets are lost or delayed, possibly up to network collapse; TCP controls its congestion window cwnd using loss feedback (timeout or three duplicate ACKs): slow start doubles cwnd every RTT up to the threshold ssthresh, then congestion avoidance adds 1 MSS per RTT, and on a loss ssthresh becomes W/2; variants differ in reaction to three dupACKs: Tahoe restarts from cwnd=1, Reno uses fast recovery (ssthresh=cwnd/2, cwnd=ssthresh+3, +1 per further dupACK), NewReno handles partial ACKs and recovers several losses in one window, SACK acknowledges received blocks and resends only what is missing.TCP Congestion Control →).
- Encapsulation/decapsulation with the 8-byte header; multiplexing by (destination IP, destination port).
Checksum and pseudo-header
The checksum is computed over a pseudo-header, the UDP header and the data. The pseudo-header is taken from the IP header and is not transmitted:
| word | content |
|---|---|
| 1-2 | source IP (32 bit) |
| 3-4 | destination IP (32 bit) |
| 5 | 8 zeros + protocol (17 for UDP) |
| 6 | UDP length |
It protects against datagrams delivered to the wrong host or protocol, at the cost of violating strict layering (UDP must know IP information).
Formula. Sum all 16-bit words of pseudo-header, header (checksum field ) and data (pad with a zero byte if the data length is odd), fold the carry back (one's complement), and take the bitwise NOT. The receiver sums everything, checksum included: with no error the result is .
It works because has all bits at 1. A changed bit alters the sum so the receiver's result is no longer .
Full example. Host sends from port to port of the 4 bytes Ciao (). UDP length . Hexadecimal: , , , , .
| field | words |
|---|---|
| source IP | |
| destination IP | |
| zeros + protocol 17 | |
| UDP length | |
| source port | |
| destination port | |
| UDP length | |
| checksum (set to 0) | |
| data |
Pseudo-header: ; ; ; ; . Header and data: ; ; ; . Total ; fold the carry: . Checksum . Check: .
Optional checksum and special values. If the checksum is not wanted, the field is all 0. If it is computed and equals , is transmitted instead (in one's complement they are the same quantity). Example: data would give a folded sum of and a complement of , sent as . The opposite case cannot happen since the pseudo-header contains .
Typical applications
- Simple request-response with little flow/error control (DNS: DNS - Domain Name SystemDNS translates names such as www.amazon.com into IP addresses; it is a distributed hierarchical database (an inverted tree of up to 128 levels, with 13 root servers and domains registered through ICANN-accredited registrars), each ISP has a local DNS whose address the host gets from DHCP, the host asks it (usually over UDP) and it queries root, top-level and organisation servers, every server caches what it learns marking answers as non-authoritative until the TTL expires, records are (name, type, value, class, TTL), with NAT the DNS must return the public address, and there are four types of attack including cache poisoning.DNS - Domain Name System →).
- Processes with their own flow and error control (TFTP), multicast, network management (SNMP).
- Routing table updates such as RIP, port 520 (Internet Routing Protocols - RIP, OSPF and BGPInternet routing is hierarchical for scalability and administrative autonomy: each ISP is an autonomous system (AS) and uses an interior protocol inside it, either RIP (distance vector, hop count with maximum 15, updates about every 30 s, over UDP port 520) or OSPF (link state with Dijkstra, areas attached to backbone area 0, five LSA types, carried directly in IP), while BGP4 (path vector over TCP port 179, eBGP between ASes and iBGP inside) connects ASes with policy-based route choice and loop avoidance by discarding paths that contain the own AS.Internet Routing Protocols - RIP, OSPF and BGP →).
- DHCP, ports 67 and 68: the client has no IP and cannot open a TCP connection (DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration →).
- Real-time interactive applications (audio, video, games), which do not tolerate irregular delays.
- Traceroute, which sends UDP to an unused port to provoke ICMP errors (ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →).
Overhead example. A voice packet with 160 bytes of audio has 8 bytes of UDP and 20 of IP: efficiency . With TCP (20-byte header) it would be , with handshake and ACKs on top. Small packets pay more for headers.
Versione ripasso
- Connectionless, unreliable; adds only ports (process-to-process) and an optional checksum to IP (Transport Layer - Ports and MultiplexingThe transport layer provides logical end-to-end communication between application processes on different hosts and exists only in end hosts; the network layer delivers to the right computer (IP address) and transport to the right process (16-bit port number, 0 to 65535); an IP address plus a port is a socket and the four-tuple of IPs and ports identifies a connection, with multiplexing and demultiplexing done by UDP on the destination socket and by TCP on the whole four-tuple, and the protocols are UDP (connectionless, unreliable), TCP (connection-oriented, reliable) and SCTP.Transport Layer - Ports and Multiplexing →). No setup, no state, no flow, error or congestion control; supports multicast.
- Header 8 bytes: source port, destination port, length, checksum (16 bits each). Data ; maximum data bytes.
- Checksum: one's complement sum over pseudo-header (source IP, destination IP, zeros + protocol 17, UDP length; not transmitted), header (checksum ) and data; NOT of the sum; receiver obtains . Odd data length: pad a zero byte.
- Optional: all zeros = not computed; a computed is sent as . Errors: datagram discarded silently.
- Example
Ciao, : sum , checksum . - Uses: DNS, DHCP (67/68), RIP (520), SNMP, TFTP, multicast, real-time audio/video, traceroute probes (ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →).
- Efficiency: bytes of voice give with UDP+IP versus with TCP+IP.
- Typical errors: forgetting the pseudo-header; saying UDP detects and fixes loss; forgetting the .
Teoria collegata
- Client-Server Programming
- Internet Structure, Packet Switching and the TCP-IP Stack
- DHCP - Dynamic Host Configuration
- DNS - Domain Name System
- Internet Routing Protocols - RIP, OSPF and BGP
- Public-Key Cryptography, RSA and TLS
- TCP - Connection, Reliability and Flow Control
- TCP Congestion Control
- Transport Layer - Ports and Multiplexing