Which socket? UDP and TCP demultiplexing

Clients A, B (and D) send segments to server C. C looks at the header to choose the socket: UDP only looks at the destination (IP_D, PD); TCP looks at the four values (IP_O, PO, IP_D, PD). Follow each segment into the socket table of C.

Scenario

Transport protocol

Clients and ephemeral ports

The client’s OS chooses the source port from the ephemeral range. The new client (D, or a new connection of A, B or D) sends to the first port C listens on.

Mode

Practice

A random scenario with 4 to 6 segments, in prediction mode. Watch out for the same source port on two hosts and for ports where nobody listens.

View

Segments that reach C

Model assumptions
  • Addresses are written with letters (A, B, C, D), as in the slides. IP_O: source IP address; IP_D: destination IP address; PO: source port; PD: destination port.
  • UDP (connectionless): the socket is identified only by its destination (IP_D, PD). Segments with different origins and the same destination go to the same socket. The source port is used as the return address.
  • TCP (connection-oriented): the server has a welcome socket on the port it listens on, and one connection socket per simultaneous connection, identified by the four values (IP_O, PO, IP_D, PD). Here a segment with a new 4-tuple reaches the welcome socket, which creates the connection socket; how the connection is established is covered in GG32.
  • Processes: “one to one” is one process per connection (P0 holds the welcome socket and creates P4, P5…); “one to many” is one process with one thread per connection; event-driven (nginx, Node.js) is one process with many sockets. The number of sockets does not depend on it; the number of processes does.
  • The Protocol field of the IP header (6 = TCP, 17 = UDP) chooses the transport protocol before the port is looked at, so 443/TCP and 443/UDP are different sockets. A segment to a port where nobody listens with that protocol is discarded.
  • Ephemeral ports: the IANA range is 49152–65535; Linux uses 32768–60999 by default (net.ipv4.ip_local_port_range). Server ports are well known (80, 443…) or, as in the slides, fixed by the application (6428).

About this visualization

A visualization of transport-layer demultiplexing. Three client hosts (A, B and D) send segments with a visible header (Protocol, source and destination IP, source and destination port) to a server C, inside which the socket table is shown. With UDP the socket is identified only by the destination (IP_D, PD): every segment to the same port goes into a single socket, wherever it comes from. With TCP there is a welcome socket per listening port and one connection socket per distinct 4-tuple (IP_O, PO, IP_D, PD), so the same source port from two different IPs gives two sockets. A switch turns the same segments from UDP into TCP. The Reply button shows the server's reply with IPs and ports swapped: the source port is the return address. “New client” adds a segment with an ephemeral port chosen by the OS in the IANA range (49152–65535) or the Linux one (32768–60999). Scenarios from the slides: UDP with two clients and one socket, TCP “one to one” (one process per connection), “one to many” (threads), an event-driven web server with HTTP/2 and HTTP/1.1, and 443/TCP next to 443/UDP, with the three addressing levels view (IP, Protocol 6/17, port). It includes prediction mode, random exercises and a final question on how many sockets the server has.

Concepts: demultiplexing, multiplexing, UDP socket, TCP socket, welcome socket, connection socket, 4-tuple, source and destination port, ephemeral ports, return address, Protocol field (6/17), server processes and threads.

Formulas:

Network Architecture I, Session 3.1 · Enrique de la Hoz, University of Alcalá · License CC BY-SA 4.0 · Source and catalogue on GitHub · DOI 10.5281/zenodo.23285664