Computer Networks · Unit 5 · 6 hrs
Transport Layer
Exam-focused notes for Transport Layer (Computer Networks, CSC263): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Transport Layer in short
This chapter covers the transport layer: what it is responsible for, the two main transport protocols and how they differ, connection models, how the network keeps itself from becoming congested, how traffic can be smoothed to a manageable rate, how competing flows are scheduled, and how a specific application on a specific host is actually addressed.
What this unit covers
- Introduction, Functions and Services
- Transport Protocols: TCP, UDP and Their Comparisons
- Connection Oriented and Connectionless Services
- Congestion Control: Open Loop & Closed Loop, TCP Congestion Control
- Traffic Shaping Algorithms: Leaky Bucket & Token Bucket
- Queuing Techniques for Scheduling
- Introduction to Ports and Sockets, Socket Programming
Traffic Shaping Algorithms
2080 · 5 marks
What is socket programming? Explain token bucket algorithm with an example. [5]
2080.1 · 5 marks
What is the difference between port and socket? Explain leaky bucket algorithm with example. [5]
Show solved answerHide answer
Port vs Socket and Leaky Bucket Algorithm
Part 1: Difference Between Port and Socket
| Feature | Port | Socket |
|---|---|---|
| Definition | A port is a logical number assigned to identify a specific process or service on a host | A socket is a combination of an IP address and a port number |
| Purpose | Identifies a specific application/service on a machine | Identifies both the machine (via IP) and the service (via port) on a network |
| Representation | Just a number (e.g., 80, 443, 21) | Represented as IP:Port (e.g., 192.168.1.1:80) |
| Scope | Local to a single machine | Used for end-to-end communication across a network |
| Communication | Cannot alone establish communication | Acts as one endpoint of a two-way communication link between two programs running on the network |
| Example | Port 80 (HTTP), Port 21 (FTP) | 192.168.1.5:80 |
A socket is one endpoint of a two-way communication link between two programs running on the network.
Part 2: Leaky Bucket Algorithm
Definition
The Leaky Bucket Algorithm is used to control the rate of data transmission in a network. It is implemented as a single server queue with constant service time. The key idea is:
- Input rate can vary (bursty traffic)
- Output rate remains constant
- If the bucket (buffer) overflows, packets are discarded
It converts bursty traffic into fixed-rate (smooth) traffic by averaging the data rate.
How It Works
Incoming packets (variable rate)
|
v
[ BUCKET / BUFFER ]
|
v
Outgoing packets (constant rate)
- Packets arrive at irregular/bursty intervals and enter the bucket (queue).
- The bucket leaks (outputs) packets at a fixed constant rate.
- If the bucket is full, any new incoming packet is dropped/discarded.
- This ensures the network receives a smooth, uniform flow of data.
Example
Suppose:
- Bucket size (buffer capacity) = 10 packets
- Output rate = 2 packets per second
| Time (sec) | Packets Arriving | Bucket Before | Packets Sent | Packets Dropped | Bucket After |
|---|---|---|---|---|---|
| 1 | 5 | 0 | 2 | 0 | 3 |
| 2 | 6 | 3 | 2 | 0 | 7 |
| 3 | 8 | 7 | 2 | 3 | 10 |
| 4 | 1 | 10 | 2 | 0 | 9 |
| 5 | 0 | 9 | 2 | 0 | 7 |
- At time 3: 7 (existing) + 8 (arriving) = 15, but bucket size is only 10, so 3 packets are dropped.
- Output is always a constant 2 packets/sec, regardless of how many arrive.
Advantages
- Prevents network congestion by smoothing out bursty traffic.
- Ensures a constant output rate for downstream devices.
Disadvantage
- Bursty traffic that exceeds bucket size leads to packet loss.
Transport Protocols
2080 · 10 marks
Explain TCP header with a neat diagram. Highlight on its uses.[10]
Show solved answerHide answer
TCP Header - Explanation with Diagram
Introduction
TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol defined in RFC 793. It provides end-to-end reliable data delivery, flow control, error control, and congestion control between two communicating hosts. The TCP header is attached to the data segment before passing it down to the network layer.
TCP Header Diagram
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HLEN | Resv |U|A|P|R|S|F| Window Size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options (if any) | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Flags: U=URG, A=ACK, P=PSH, R=RST, S=SYN, F=FIN
Minimum Header Size = 20 bytes
Detailed Explanation of Each Field
1. Source Port (16 bits)
- Identifies the port number of the sending application on the source host.
- Port numbers range from 0 to 65535.
- Example: A web browser may use ephemeral port 49200 as source port.
- Use: Helps the receiving end identify which application sent the data, enabling multiplexing.
2. Destination Port (16 bits)
- Identifies the port number of the receiving application on the destination host.
- Example: Port 80 for HTTP, Port 443 for HTTPS, Port 21 for FTP.
- Use: Directs the incoming segment to the correct application process (demultiplexing).
3. Sequence Number (32 bits)
- Indicates the byte number of the first byte of data in the current segment.
- During connection establishment (SYN), it carries the Initial Sequence Number (ISN).
- Use: Ensures ordered delivery of data. The receiver uses this to reassemble segments in the correct order.
4. Acknowledgment Number (32 bits)
- Valid only when the ACK flag is set.
- Contains the sequence number of the next byte the receiver expects to receive.
- Use: Confirms receipt of data and provides reliable, error-free delivery. Supports cumulative acknowledgment.
5. Header Length / HLEN (4 bits)
- Specifies the length of the TCP header in 32-bit words.
- Minimum value = 5 (20 bytes), Maximum value = 15 (60 bytes).
- Use: Tells the receiver where the header ends and the actual data begins, since the Options field makes the header variable in length.
6. Reserved (6 bits)
- These bits are reserved for future use and must be set to zero.
- Use: Ensures backward compatibility for future protocol extensions.
7. Control Flags (6 bits)
Each flag is 1 bit and serves a specific purpose:
| Flag | Name | Use |
|---|---|---|
| URG | Urgent | Indicates urgent data is present; Urgent Pointer field is valid |
| ACK | Acknowledgment | Acknowledgment Number field is valid |
| PSH | Push | Receiver should pass data to application immediately without buffering |
| RST | Reset | Abruptly terminates/resets the connection |
| SYN | Synchronize | Used during connection establishment (3-way handshake) to synchronize sequence numbers |
| FIN | Finish | Used during connection termination; sender has no more data to send |
8. Window Size (16 bits)
- Specifies the number of bytes the sender is willing to accept from the receiver (receive buffer size).
- Maximum window size = 65535 bytes.
- Use: Implements flow control using the sliding window mechanism. Prevents the sender from overwhelming the receiver with too much data.
9. Checksum (16 bits)
- Covers the entire TCP segment (header + data) plus a pseudo-header (source IP, destination IP, protocol, TCP length).
- Calculated by the sender and verified by the receiver.
- Use: Provides error detection. If the checksum does not match, the segment is discarded.
10. Urgent Pointer (16 bits)
- Valid only when the URG flag is set.
- Points to the last byte of urgent data within the segment.
- Use: Allows TCP to send out-of-band urgent data (e.g., interrupt signals) that must be processed immediately by the receiving application.
11. Options (Variable, 0 to 40 bytes)
- Carries optional parameters negotiated when the connection is opened, such as the maximum segment size, the window scale factor, selective acknowledgment permission and timestamps.
- Present only when HLEN is greater than 5, which is how the header grows from 20 bytes to at most 60 bytes.
- Use: Lets TCP extend its behaviour beyond the fixed part of the header, for example by agreeing on a larger window or on a segment size that avoids fragmentation.
12. Padding (Variable)
- Zero bits appended after the options so that the header ends on a 32-bit word boundary.
- Use: Keeps the header length an exact multiple of 4 bytes so that the value in HLEN remains meaningful.
Uses of the TCP Header
| Purpose | Fields that provide it |
|---|---|
| Process to process delivery | Source Port, Destination Port |
| Ordered delivery and reassembly | Sequence Number |
| Reliability and retransmission | Acknowledgment Number, ACK flag |
| Connection setup and release | SYN, ACK, FIN, RST flags |
| Flow control | Window Size |
| Error detection | Checksum |
| Priority (out-of-band) data | URG flag, Urgent Pointer |
| Header extension | HLEN, Options, Padding |
Conclusion
Every field in the TCP header exists to support one of the guarantees TCP makes. The port numbers deliver the segment to the correct process, the sequence and acknowledgment numbers together with the checksum make delivery reliable and in order, the control flags manage the life of the connection, and the window size keeps a fast sender from overwhelming a slow receiver. This is why the header is 20 bytes at minimum and can reach 60 bytes once options are negotiated.
2079 · 5 marks
Why TCP is called a connection-oriented and reliable protocol? Differentiate TCP with UDP. [5]
2080.1 · 10 marks
Explain TCP header with a neat diagram. Highlight on its uses.[10]
Show solved answerHide answer
TCP Header - Explanation with Diagram
Introduction
TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol. It ensures that data is delivered accurately and in order between two communicating hosts. The TCP header contains all the control information necessary to manage this reliable communication.
TCP Header Diagram
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |Reserv.|U|A|P|R|S|F| |
|Offset | (6) |R|C|S|S|Y|I| Window Size |
| (4) | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options (if any) | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Minimum TCP Header Size = 20 bytes (without options)
Detailed Explanation of Each Field
1. Source Port (16 bits)
- Identifies the port number of the sending application on the source host.
- Port numbers range from 0 to 65535.
- Example: A web browser may use port 1025 as source port.
Use: Helps the receiving host know which application sent the data, enabling proper reply routing.
2. Destination Port (16 bits)
- Identifies the port number of the receiving application on the destination host.
- Example: HTTP uses port 80, HTTPS uses port 443, FTP uses port 21.
Use: Directs the incoming segment to the correct application/process on the destination machine.
3. Sequence Number (32 bits)
- Indicates the position (byte number) of the first byte of data in this segment within the overall data stream.
- During connection establishment (SYN), it carries the Initial Sequence Number (ISN).
Use: Enables the receiver to reorder segments that arrive out of order and detect missing data.
4. Acknowledgment Number (32 bits)
- When the ACK flag is set, this field contains the next sequence number the sender of the acknowledgment expects to receive.
- It acknowledges all bytes received up to (but not including) this number.
Use: Provides reliable delivery by confirming receipt of data and requesting the next expected byte.
5. Data Offset / Header Length (4 bits)
- Specifies the length of the TCP header in 32-bit words.
- Minimum value is 5 (20 bytes), maximum is 15 (60 bytes).
Use: Tells the receiver where the actual data begins in the TCP segment.
6. Reserved (6 bits)
- These bits are reserved for future use and must be set to zero.
7. Control Flags (6 bits)
Each flag is 1 bit and serves a specific control purpose:
| Flag | Full Name | Use |
|---|---|---|
| URG | Urgent | Indicates urgent pointer field is significant |
| ACK | Acknowledgment | Acknowledgment number is valid |
| PSH | Push | Receiver should pass data to application immediately |
| RST | Reset | Resets the connection abruptly |
| SYN | Synchronize | Used during connection establishment (3-way handshake) |
| FIN | Finish | Used to terminate a connection gracefully |
Use: These flags control the state of the TCP connection - establishment, data transfer, and termination.
8. Window Size (16 bits)
- Specifies the number of bytes the sender is willing to accept from the receiver (receive buffer size).
- Maximum window size = 65,535 bytes (can be scaled using options).
Use: Implements flow control - prevents the sender from overwhelming the receiver by sending too much data at once.
9. Checksum (16 bits)
- A 16-bit error-detection field computed over the TCP header, data, and a pseudo-header (containing source IP, destination IP, protocol, and TCP length).
Use: Ensures data integrity - detects any corruption that may have occurred during transmission.
10. Urgent Pointer (16 bits)
- Valid only when the URG flag is set.
- Points to the last byte of urgent data within the segment.
Use: Allows TCP to send out-of-band (priority) data that should be processed immediately by the receiving application.
11. Options (Variable, 0 to 40 bytes)
- Used for optional parameters that are negotiated when the connection is set up, such as the maximum segment size, the window scale factor, selective acknowledgment permission, and timestamps.
- Present only when the data offset is greater than 5, which is why the header can grow from 20 bytes up to 60 bytes.
Use: Lets TCP extend its behaviour beyond the fixed 20-byte header, for example by agreeing on a larger window or a segment size that avoids fragmentation.
12. Padding (Variable)
- Extra zero bits added after the options so that the header ends on a 32-bit word boundary.
Use: Keeps the header length an exact multiple of 4 bytes, so the value carried in the data offset field remains valid.
Uses of the TCP Header
| Purpose | Fields that provide it |
|---|---|
| Process to process delivery | Source Port, Destination Port |
| Ordered delivery and reassembly | Sequence Number |
| Reliability and retransmission | Acknowledgment Number, ACK flag |
| Connection setup and teardown | SYN, ACK, FIN, RST flags |
| Flow control | Window Size |
| Error detection | Checksum |
| Priority data | URG flag, Urgent Pointer |
| Header extension | Data Offset, Options, Padding |
Conclusion
Every field of the TCP header exists to support one of the guarantees TCP makes. The port numbers deliver the segment to the right process, the sequence and acknowledgment numbers together with the checksum make the delivery reliable and in order, the flags manage the life of the connection, and the window size keeps a fast sender from overwhelming a slow receiver. This is why the minimum header is 20 bytes and can grow to 60 bytes when options are negotiated.
Congestion Control
2078 · 5 marks
What is open-loop congestion control? Compare it with closed-loop congestion control. [5]
Make Unit 5 stick
Practice CSC263 with flashcards & quizzes