Salta al contenuto
Note per Studenti UDP - User Datagram Protocol Report

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 65 535−20−8=65 50765\,535-20-8=65\,507 bytes; minimum length 8.

Formula. data=UDP length−8\text{data}=\text{UDP length}-8. Example: length 12 carries 12−8=412-8=4 bytes.

Services

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 =0=0) 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 FFFF\texttt{FFFF}.

It works because S+S‾S+\overline S has all bits at 1. A changed bit alters the sum so the receiver's result is no longer FFFF\texttt{FFFF}.

Full example. Host 192.168.0.1192.168.0.1 sends from port 50005000 to port 5353 of 192.168.0.199192.168.0.199 the 4 bytes Ciao (43 69 61 6F\texttt{43}\ \texttt{69}\ \texttt{61}\ \texttt{6F}). UDP length =8+4=12=000C=8+4=12=\texttt{000C}. Hexadecimal: 192=C0192=\texttt{C0}, 168=A8168=\texttt{A8}, 199=C7199=\texttt{C7}, 5000=13885000=\texttt{1388}, 53=003553=\texttt{0035}.

field words
source IP C0A8 0001\texttt{C0A8}\ \texttt{0001}
destination IP C0A8 00C7\texttt{C0A8}\ \texttt{00C7}
zeros + protocol 17 0011\texttt{0011}
UDP length 000C\texttt{000C}
source port 1388\texttt{1388}
destination port 0035\texttt{0035}
UDP length 000C\texttt{000C}
checksum (set to 0) 0000\texttt{0000}
data 4369 616F\texttt{4369}\ \texttt{616F}

Pseudo-header: C0A8+0001=C0A9\texttt{C0A8}+\texttt{0001}=\texttt{C0A9}; +C0A8=18151+\texttt{C0A8}=\texttt{18151}; +00C7=18218+\texttt{00C7}=\texttt{18218}; +0011=18229+\texttt{0011}=\texttt{18229}; +000C=18235+\texttt{000C}=\texttt{18235}. Header and data: 1388+0035=13BD\texttt{1388}+\texttt{0035}=\texttt{13BD}; +000C=13C9+\texttt{000C}=\texttt{13C9}; +4369=5732+\texttt{4369}=\texttt{5732}; +616F=B8A1+\texttt{616F}=\texttt{B8A1}. Total 18235+B8A1=23AD6\texttt{18235}+\texttt{B8A1}=\texttt{23AD6}; fold the carry: 3AD6+2=3AD8\texttt{3AD6}+2=\texttt{3AD8}. Checksum =FFFF−3AD8=C527=\texttt{FFFF}-\texttt{3AD8}=\texttt{C527}. Check: 3AD8+C527=FFFF\texttt{3AD8}+\texttt{C527}=\texttt{FFFF}.

Optional checksum and special values. If the checksum is not wanted, the field is all 0. If it is computed and equals 0000\texttt{0000}, FFFF\texttt{FFFF} is transmitted instead (in one's complement they are the same quantity). Example: data 4369 2697\texttt{4369}\ \texttt{2697} would give a folded sum of FFFF\texttt{FFFF} and a complement of 0000\texttt{0000}, sent as FFFF\texttt{FFFF}. The opposite case cannot happen since the pseudo-header contains 0011≠0\texttt{0011}\neq0.

Typical applications

Overhead example. A voice packet with 160 bytes of audio has 8 bytes of UDP and 20 of IP: efficiency η=L/(L+H)=160/188=85.1%\eta=L/(L+H)=160/188=85.1\%. With TCP (20-byte header) it would be 160/200=80%160/200=80\%, with handshake and ACKs on top. Small packets pay more for headers.

Versione ripasso

Teoria collegata