15. Transport-Layer Services - TCP and UDP

Transport protocols provide logical communication between application processes running on different hosts.

The sender side breaks the application messages into segments and passes it to the network layer, while the receiver reassembles segments into messages and passes it to the application layer.

Multiple transport layer protocols are available, the most common being TCP and UDP.

The internet transport layer extends IP’s host-to-host delivery to process-to-process delivery (hence requiring multiplexing and demultiplexing), with TCP specifically adding reliable delivery, flow control and congestion control.

Multiplexing and Demultiplexing

Demultiplexing: the host receives IP datagrams; each has source/destination IP addresses and carries a single transport-layer segment. Inside each segment is the source/destination port number.

Connectionless-demultiplexing

With connectionless-demultiplexing (e.g. UDP), a two-tuple of the destination IP and port number can be used to identify the socket. Packets with different source IP and/or port numbers will be directed to the same socket.

Connection-oriented-demultiplexing

TCP sockets are identified by a 4-tuple: all four of the source and destination IP addresses and port numbers are required to direct the segment to the appropriate socket.

Hence, the server host may support many simultaneous TCP sockets through a single port number.

UDP

A bare bones, best effort service: segments can be lost or delivered out of order.

UDP is often used for streaming multimedia applications as this use case is loss-tolerate and rate-sensitive. UDP is also used in RIP, DNS, SNMP.

Segment structure:

|   16 bits   |      16 bits     |
| Source port | Destination port |
|   Length    |     Checksum     |
|              Data              |

The length is the length in bytes of the segment, including the header.

Advantages:

The UDP socket for an incoming packet can be identified by its destination IP and port.

TCP

Properties:

Packet structure:

| 16 bits     | 16 bits           |
| Source port | Destination port  |
|         Sequence Number         |
|      Acknowledgement Number     |
| Flags       | Receive window    |
| Checksum    | Urg. data pointer |
|     Options (variable)          |
|        Application Data         |

Notes:

Flags:

TCP Connection Management

Opening: three-way handshake

NB: segments with SYN or FIN flags are treated as if they have a 1 byte payload.

Step 1:

The second step both acknowledges the segment and sends the server’s ISN:

This third step is needed to confirm that the client has received the server’s ISN:

Termination

Client waits for double the maximum segment lifespan to ensure the ACK arrives.