Transport Layer Protocols, Connection Mechanisms, and Flow Control
Transport Layer Fundamentals and Services
- The transport layer is responsible for process-to-process delivery of data across a network.
- Key functions include:
- Demultiplexing of data streams.
- Creating long-lived connections (optional).
- Ensuring reliable, in-order packet delivery (optional).
- Error detection.
- Flow and congestion control (optional).
- Key challenges for this layer involve:
- Detecting and responding to network congestion.
- Balancing fairness among multiple users against high network utilization.
- Layer comparisons in delivery types:
- Node-to-node: Handled by the Data Link Layer.
- Host-to-host: Handled by the Network Layer.
- Process-to-process: Handled by the Transport Layer.
- Comparison of addressing at different layers:
- Data Link Layer: Uses MAC addresses to select one specific node among several on a local segment.
- Network Layer: Uses IP addresses to select one host among millions on the internet.
- Transport Layer: Uses transport layer addresses called Port Numbers to identify specific processes running on a host.
- Destination port numbers are used for delivery.
- Source port numbers are used for the reply.
- Multiplexing Necessity: Datagram networks (like the internet) do not have circuits or pre-established connections. Since clients run multiple applications simultaneously, the network must identify which application should receive a specific packet.
- IP Header Field: The IP header contains an 8-bit "protocol" field, which allows for up to 256 concurrent streams. The Transport Layer is inserted to handle complex demultiplexing beyond this limit.
- Demultiplexing Mechanics:
- Traffic endpoints are uniquely identified by a 4-tuple:
<src_ip, src_port, dest_ip, dest_port>.
- Each application on a host uses a unique port.
- Multiple applications share the same underlying network connection.
- Server applications use these identifiers to communicate with multiple clients simultaneously. - Layering Interaction:
- The Transport Layer is theoretically the lowest level end-to-end protocol.
- Transport headers are typically only read by the source and destination hosts.
- Intermediate routers view the transport header merely as part of the data payload.
User Datagram Protocol (UDP)
- Characteristics: Simple, connectionless datagram service.
- Socket Type: In C sockets, it is identified as
SOCK_DGRAM. - Port Numbers: Uses 16-bit identifiers, allowing for 65535 possible ports. Port 0 is considered invalid.
- Checksums: Used for error detection to identify corrupted packets. However, UDP does not detect dropped, duplicated, or reordered packets.
- Segment Fields:
- Source Port (16 bits)
- Destination Port (16 bits)
- Payload Length
- Checksum
Transmission Control Protocol (TCP)
- Characteristics: Provides reliable, in-order, bi-directional byte streams.
- Key Features:
- Virtual circuits (logical connections).
- Flow control to prevent receiver overflow.
- Congestion control to approximate fairness in the network.
- TCP Segment Structure:
- Source and Destination Ports: Identifying endpoints.
- Sequence Number (32 bits): Counts bytes in the byte stream (not segments).
- Acknowledgement Number (32 bits): The sequence number of the next expected byte.
- Header Length: Length of the TCP header.
- Flags: 1-bit each (URG, ACK, PSH, RST, SYN, FIN, CWR, ECE).
-
SYN: Used for connection setup synchronization.
- ACK: Indicates the acknowledgement field is valid.
- FIN: Used to terminate a connection.
- RST: Reset the connection.
- Receive Window: Used for flow control; indicates the number of bytes the receiver is currently willing to accept.
- Checksum: Error detection for header and payload.
- Urgent Pointer: Points to urgent data.
- Options: Variable length.
- Application Data: Variable length data from the TCP socket.
Connection Management and the Three-Way Handshake
- Importance of Connection Setup: Necessary to establish state on both hosts, primarily initial sequence numbers. These numbers count sent bytes and are chosen randomly to prevent connection confusion from the same host.
- The Three-Way Handshake Process:
- Step 1 (Client): Sends
SYN <SeqC, 0>. Client state moves to SYN_SENT.
- Step 2 (Server): Sends SYN/ACK <SeqS, SeqC+1>. Server state moves to SYN_RCVD. This ACKs the client's sequence number and provides its own.
- Step 3 (Client): Sends ACK <SeqC+1, SeqS+1>. Both enter ESTABLISHED state. This segment may contain actual data. - Why 2-Way Handshake Fails:
- Variable network delays and message reordering.
- Retransmitted connection requests due to loss can lead to half-open connections or duplicate data acceptance.
- Connection Issues:
- SYN Flood: A denial of service (DoS) attack where the server allocates state for every
SYN received but never receives the final ACK.
- Solution: SYN cookies. - Connection Tear Down:
- Either side can initiate.
- Uses a
FIN segment.
- Supports "half-open" connections where one side stops sending but continues receiving.
- The final FIN is acknowledged by Seq + 1.
Sequence Number Space and Bidirectional Communication
- Byte Stream Abstraction: TCP treats data as a continuous stream of bytes, each numbered with a 32-bit value that wraps around.
- MSS (Maximum Segment Size): Sets limits on segment size to avoid fragmentation across the network.
- Bidirectional Data Exchange Example:
- Host A to Host B: User types ‘C’:
Seq=42, ACK=79, data = ‘C’.
- Host B to Host A: ACK receipt and echo back ‘C’: Seq=79, ACK=43, data = ‘C’.
- Host A to Host B: ACK the echo: Seq=43, ACK=80. - Piggybacking: Data and ACKs can be sent in the same packet.
Flow Control and the Sliding Window
- Definition: Procedures to restrict the amount of data a sender can transmit before waiting for an acknowledgement. This prevents the sender from overwhelming the receiver's buffer.
- The Problem: If the network delivers data faster than the application layer removes it from the socket buffer, the buffer overflows.
- Mechanism: Sliding Window:
- The receiver provides an Advertised Window (
rwnd) in the TCP header.
- For a window size n, the sender can transmit n bytes without an ACK.
- The window "slides" forward as ACKs are received.
- ACK Clocking:
- Short RTT → quick ACKs → window slides quickly → high throughput.
- Long RTT → slow ACKs → window slides slowly → low throughput.
Sliding Window Analysis and Network Efficiency
- Scenario for Calculation:
- Bandwidth = 1 Mbps=1,000,000 bits/sec
- RTT = 100 ms=0.1 sec
- Packet size = 1000 bytes=8000 bits
- Step 1: Bandwidth-Delay Product (BDP):
- Determines how much data should be in transit to keep the pipe full.
- BDP=1,000,000×0.1=100,000 bits
- Step 2: Convert to Packets:
- 8000 bits/packet100,000 bits=12.5 packets
- Step 3: Efficiency Results:
- If window size ≥13: Full link utilization (Throughput = 1 Mbps).
- If window size < BDP: Pipe is underutilized.
- Stop-and-Wait (Window = 1):
- Throughput=0.1 sec8000 bits=80,000 bps (8% efficiency).
Acknowledgement Strategies
- Cumulative ACK: An ACK for sequence n implies receipt of all bytes up to n−1. "Next expected is n."
- Negative ACKs (NACKs): Explicitly indicate which packet did not arrive.
- Selective ACKs (SACKs): Indicate which packets have arrived, even if they are out of order (e.g., if packets 1, 3, and 4 arrive, SACK specifies 3 and 4 were received despite 2 being lost).