Transport Layer Comprehensive Exercises
Exercise 1: Fundamental Concepts
- Describe the main functions of the transport layer.
Approach
Group the functions into the five that matter: what the layer delivers to applications, how it addresses them, how it shares the medium between applications, what it does about errors, and what it does about rates.
Steps
- State end-to-end process communication.
- State transport layer addressing.
- State multiplexing and demultiplexing.
- State error detection and reliability.
- State flow control.
Answer
The main functions of the transport layer are:
-
End-to-end process communication:
- Provides a communication service for application layer processes
- Establishes a logical connection between the source and destination hosts
- Delivers data from the source process to the destination process
-
Transport layer addressing:
- Uses port numbers to identify processes on a host
- Implements communication between processes
- Supports multiplexing
-
Multiplexing and demultiplexing:
- Lets several application layer processes share the transport layer service
- Distributes received data to the matching application layer process
- Implements demultiplexing
-
Error detection and reliability:
- Detects errors introduced during transmission
- Ensures data is delivered intact, in order, and without duplication
- Provides a retransmission mechanism
-
Flow control:
- Prevents the sender from going so fast that the receiver’s buffer overflows
- Controls the rate of data transfer
- Keeps the network stable
- What does a port number do? Give some common ports.
Approach
State the four roles a port number plays, then list the ports that are actually worth memorising, grouped by the IANA range they belong to.
Steps
- State the four roles of a port number.
- List the well-known ports with their services.
- List the registered ports with their services.
- Close with the range boundaries.
Answer
The role of a port number:
- Process identification: uniquely identifies a process on a host
- Service differentiation: separates different network services
- Connection identification: identifies a connection in TCP
- Data dispatch: delivers data to the correct application process
Common ports:
Well-known ports (0-1023):
- 20/21: FTP (File Transfer Protocol)
- 22: SSH (Secure Shell)
- 23: Telnet (remote login)
- 25: SMTP (Simple Mail Transfer Protocol)
- 53: DNS (Domain Name System)
- 80: HTTP (Hypertext Transfer Protocol)
- 110: POP3 (Post Office Protocol)
- 143: IMAP (Internet Message Access Protocol)
- 443: HTTPS (HTTP over TLS)
Registered ports (1024-49151):
- 1433: Microsoft SQL Server
- 1521: Oracle Database
- 3306: MySQL Database
- 5432: PostgreSQL Database
- 6379: Redis
- 8080: HTTP Proxy
Exercise 2: The UDP Protocol
- What are the main differences between UDP and TCP?
Approach
Compare the two protocols on the dimensions that change application behaviour, then state which scenarios each one serves.
Steps
- Compare the connection model.
- Compare reliability.
- Compare flow control.
- Compare congestion control.
- Compare transmission efficiency.
- Compare latency.
- Compare the typical use.
Answer
The main differences are:
-
Connection model:
- UDP: connectionless, no connection has to be established beforehand
- TCP: connection-oriented, a connection has to be established first
-
Reliability:
- UDP: unreliable, makes no guarantee that packets arrive
- TCP: reliable, guarantees that data is transferred intact
-
Flow control:
- UDP: no flow control
- TCP: has flow control, which prevents the receiver from being overloaded
-
Congestion control:
- UDP: no congestion control
- TCP: has congestion control and adapts to the state of the network
-
Transmission efficiency:
- UDP: high efficiency, small protocol overhead
- TCP: lower efficiency, large protocol overhead
-
Latency:
- UDP: low latency, suitable for real-time applications
- TCP: higher latency, suitable for reliable transmission
-
Typical use:
- UDP: real-time applications, simple queries
- TCP: file transfer, web browsing
- Which application scenarios suit UDP?
Approach
Sort the scenarios by the property that makes UDP the right choice, and give a reason within each group.
Steps
- Identify the real-time applications and the loss each can absorb.
- Identify the simple query services.
- Identify the broadcast and multicast applications.
- Identify the applications with a strong real-time requirement.
- Identify the simple, efficient applications.
Answer
UDP suits the following application scenarios:
-
Real-time applications:
- Voice transmission: latency-sensitive, a small amount of loss is acceptable
- Video transmission: a strong real-time requirement, some loss is acceptable
- Online games: real-time interaction, a low latency requirement
-
Simple query services:
- DNS lookups: simple and fast, one request produces one response
- DHCP: automatic assignment of IP addresses over broadcast
- SNMP: network management and simple monitoring
-
Broadcast and multicast applications:
- Network broadcast: one-to-many communication
- Multicast applications: video conferencing, live streaming
- Service discovery: device discovery services
-
Applications with a strong real-time requirement:
- Online games: real-time interaction
- Streaming media: audio and video transmission
- Network monitoring: device status monitoring
-
Simple, efficient applications:
- Simple protocols: custom protocols
- Lightweight services: simple queries
- Ad hoc communication: one-off data transfers
Exercise 3: The TCP Protocol
- How does TCP achieve reliable transmission?
Approach
Describe the mechanisms in the order in which they act on a segment: numbering, acknowledging, retransmitting, windowing, and then the two control loops that protect the receiver and the network.
Steps
- Describe the sequence number mechanism.
- Describe the acknowledgement mechanism.
- Describe timeout and retransmission.
- Describe the sliding window.
- Describe flow control.
- Describe congestion control.
Answer
TCP achieves reliable transmission through the following mechanisms:
-
Sequence number mechanism:
- Every byte carries a unique sequence number
- It identifies the order of the segments
- It allows out-of-order segments to be reassembled
-
Acknowledgement mechanism:
- Cumulative acknowledgement: the acknowledgment number states the next byte expected
- Delayed acknowledgement: reduces network overhead
- Selective acknowledgement: acknowledges particular segments
-
Timeout and retransmission:
- The timeout is adjusted dynamically
- An exponential backoff algorithm is used
- A fast retransmit mechanism is available
-
Sliding window:
- The send window controls the sending rate
- The receive window controls the receiving capacity
- The window size is adjusted dynamically
-
Flow control:
- Stops the sender from going too fast
- Matches the sending and receiving rates
- Avoids overflowing the receiver’s buffer
-
Congestion control:
- The slow start algorithm
- The congestion avoidance algorithm
- Fast retransmit and fast recovery
- How do TCP flow control and TCP congestion control differ?
Approach
Treat the two as two control loops with different controlled objects: one protects the receiver, the other protects the network. Compare them across goal, object, mechanism, parameter, algorithm, scope, and trigger.
Steps
- Compare the control goal.
- Compare the controlled object.
- Compare the control mechanism.
- Compare the control parameter.
- Compare the control algorithm.
- Compare the scope of influence.
- Compare the trigger condition.
Answer
The main differences are:
-
Control goal:
- Flow control: prevents the receiver’s buffer from overflowing
- Congestion control: prevents the network from becoming congested
-
Controlled object:
- Flow control: end-to-end control
- Congestion control: control of the network as a whole
-
Control mechanism:
- Flow control: based on the receive window size
- Congestion control: based on the state of congestion in the network
-
Control parameter:
- Flow control: the window size advertised by the receiver
- Congestion control: the congestion window size
-
Control algorithm:
- Flow control: the sliding window mechanism
- Congestion control: algorithms such as slow start and congestion avoidance
-
Scope of influence:
- Flow control: affects a single connection
- Congestion control: affects the whole network
-
Trigger condition:
- Flow control: the receiver’s buffer is full
- Congestion control: network congestion, packet loss, and so on
Exercise 4: Connection Management
- What are the establishment and the release procedures for a TCP connection?
Approach
Write out the handshake and the teardown as segment exchanges, and after each step note the state each endpoint enters. The state transitions are what make the exchange correct, not the flags alone.
Steps
- Walk through the three segments of the handshake.
- Give the state transitions on both sides.
- Walk through the four segments of the teardown.
- Give the state transitions on both sides.
Answer
TCP connection establishment (the three-way handshake):
-
The first handshake:
- The client sends SYN=1, seq=x
- The client enters the SYN_SENT state
- The server, on receipt, enters the SYN_RCVD state
-
The second handshake:
- The server sends SYN=1, ACK=1, seq=y, ack=x+1
- The server acknowledges the client’s connection request
- The client, on receipt, enters the ESTABLISHED state
-
The third handshake:
- The client sends ACK=1, seq=x+1, ack=y+1
- The client acknowledges the server’s acknowledgement
- The server, on receipt, enters the ESTABLISHED state
TCP connection release (the four-way teardown):
-
The first teardown step:
- The client sends FIN=1, seq=u
- The client enters the FIN_WAIT_1 state
- The server, on receipt, enters the CLOSE_WAIT state
-
The second teardown step:
- The server sends ACK=1, ack=u+1
- The server acknowledges the client’s termination request
- The client, on receipt, enters the FIN_WAIT_2 state
-
The third teardown step:
- The server sends FIN=1, seq=v
- The server enters the LAST_ACK state
- The client, on receipt, enters the TIME_WAIT state
-
The fourth teardown step:
- The client sends ACK=1, ack=v+1
- The client waits 2MSL and then enters the CLOSED state
- The server, on receipt, enters the CLOSED state
- Why does establishing a TCP connection need three segments?
Approach
Answer the question by naming the failure each segment rules out: the first proves the client can send, the second proves the server can both send and receive, the third proves the client can receive. Then add the historical-connection and resource arguments.
Steps
- Explain the role of each of the three segments in confirming bidirectional communication.
- Explain how two segments would fail against historical connections.
- Explain the synchronisation of the initial sequence numbers.
- Explain the delay in allocating server resources.
- Explain the state confirmation.
Answer
A TCP connection needs the three-way handshake for these reasons:
-
Ensuring bidirectional communication:
- The first handshake: client → server, confirms the client can send
- The second handshake: server → client, confirms the server can send and receive
- The third handshake: client → server, confirms the client can receive
-
Preventing interference from historical connections:
- With only two segments, a historical connection could be mistaken for a new one
- The three-way handshake guarantees the uniqueness of the connection
- It avoids mixing up the data streams
-
Synchronising sequence numbers:
- Both the client and the server need to know the other’s initial sequence number
- This guarantees that data is transferred in order
- It prepares the ground for reliable transmission
-
Resource allocation:
- The server allocates resources only after the third handshake
- It avoids wasting resources
- It protects against SYN attacks
-
State confirmation:
- Both sides confirm that the connection is established
- Data transfer can begin
- The state machines transition correctly
Exercise 5: Applied Scenarios
- In a networked application, how do you choose between UDP and TCP?
Approach
Work from the requirements rather than from the protocols: list the requirement that pushes you towards UDP, then the requirement that pushes you towards TCP, and finish with the decision rule.
Steps
- List the cases that call for UDP.
- List the cases that call for TCP.
- State the decision rule in terms of latency and loss tolerance.
Answer
The cases that call for UDP:
-
A strong real-time requirement:
- Voice and video transmission
- Online games
- Real-time monitoring
-
A small amount of loss is acceptable:
- Real-time applications can tolerate a few lost packets
- The data can be resent quickly
- Integrity is not critical
-
Simple query services:
- DNS lookups
- DHCP services
- Simple status queries
-
Broadcast and multicast applications:
- Network broadcast
- Video conferencing
- Service discovery
The cases that call for TCP:
-
A strong reliability requirement:
- File transfer
- Mail transfer
- Database connections
-
Data integrity matters:
- No data may be lost
- The order has to be guaranteed
- Accuracy is critical
-
Large volumes of data:
- File downloads
- Database backups
- System image transfers
-
Interactive applications:
- Web browsing
- Remote login
- Online payment
- Which congestion control algorithms does TCP have, and what are their characteristics?
Approach
Describe each of the four algorithms by how it grows the window, then summarise what each one optimises for, and finish with the four parameters that the algorithms operate on.
Steps
- Describe slow start and the growth rule.
- Describe congestion avoidance and the growth rule.
- Describe fast retransmit and the trigger.
- Describe fast recovery and what it avoids.
- Summarise the characteristics.
- List the parameters.
Answer
The congestion control algorithms of TCP are:
-
Slow start:
- The initial cwnd is 1 MSS
- cwnd doubles on every ACK received
- Exponential growth, which probes the network capacity quickly
- It continues until ssthresh is reached
-
Congestion avoidance:
- Once cwnd reaches ssthresh it grows linearly
- One MSS is added per RTT
- Cautious growth, which avoids congestion
- It continues until congestion occurs
-
Fast retransmit:
- Retransmit immediately on three duplicate ACKs
- No need to wait for the timeout
- Fast recovery, which reduces latency
- It improves transmission efficiency
-
Fast recovery:
- After the retransmission, enter congestion avoidance
- Slow start is not entered
- A relatively high transmission rate is maintained
- It improves network utilisation
Characteristics:
- Slow start: probes quickly, but may cause congestion
- Congestion avoidance: grows cautiously, and avoids congestion
- Fast retransmit: responds quickly, and reduces latency
- Fast recovery: keeps the efficiency, and avoids a collapse in throughput
Parameters:
- cwnd: the congestion window size
- ssthresh: the slow start threshold
- RTT: the round-trip time
- MSS: the maximum segment size
