5 Transport Layer

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.

Transport Layer: notes

Introduction, Functions and Services

The transport layer provides services to the application layer above it and draws on services from the network layer below it, and it is responsible for the end-to-end delivery of a complete message between processes, not just between hosts. Its data unit is the segment.

Its core functions are segmentation and reassembly (breaking a message from the session layer into smaller units at the sender, and reassembling them at the receiver), service point (port) addressing (making sure a message reaches the correct process, not just the correct host), flow control and error control performed end to end (so the complete message arrives intact even if individual links along the way are imperfect), and connection control: a connectionless transport treats every segment as an independent unit, while a connection-oriented transport sets up a connection with the destination's transport layer before any data is sent.

Beyond these functions, the transport layer is responsible for several concrete services. Process-to-process delivery uses a 16-bit port number to route a segment to the correct process among the many that may be running on one host. End-to-end connections between hosts are built mainly using TCP and UDP. Multiplexing lets several applications on one host share the network simultaneously, and demultiplexing separates incoming data back out to the correct application at the receiver. Congestion control manages the situation where too many sources try to push data through the network at once, causing router buffers to overflow. Data integrity and error correction uses error-detecting codes together with acknowledgment (ACK) and negative-acknowledgment (NACK) signalling to confirm whether data arrived correctly.

Transport Protocols: TCP and UDP

Transmission Control Protocol (TCP)User Datagram Protocol (UDP)
Connection modelConnection-orientedConnectionless
ReliabilityReliable, guarantees deliveryBest-effort, no delivery guarantee
Error checkingExtensive, with flow control and acknowledgmentBasic, checksum only
OrderingSequenced, in-order deliveryNo sequencing guarantee
BroadcastingNot supportedSupported
Overhead / speedHigher overhead, slowerLower overhead, faster and simpler
Typical useHTTP, HTTPS, FTP, SMTP, TelnetDNS, DHCP, TFTP, SNMP, RIP, VoIP

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

2081 · 5 marks

Explain the working mechanism of token bucket. [5]

The Token Bucket algorithm is a traffic shaping mechanism that controls the amount and rate of traffic sent to the network. Unlike the leaky bucket, it allows variable output rate depending on the size of the burst, making it more flexible. --- - A bucket holds tokens up to a maximum capacity b -...

Open this answer on its own page →

2080 · 5 marks

What is socket programming? Explain token bucket algorithm with an example. [5]

--- Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket (node) listens on a particular port at an IP address, while the other socket reaches out to form a connection. - The server creates a listener socket and waits for incoming connections....

Open this answer on its own page →

2080.1 · 5 marks

What is the difference between port and socket? Explain leaky bucket algorithm with example. [5]

Show solved answer

Port vs Socket and Leaky Bucket Algorithm


Part 1: Difference Between Port and Socket

FeaturePortSocket
DefinitionA port is a logical number assigned to identify a specific process or service on a hostA socket is a combination of an IP address and a port number
PurposeIdentifies a specific application/service on a machineIdentifies both the machine (via IP) and the service (via port) on a network
RepresentationJust a number (e.g., 80, 443, 21)Represented as IP:Port (e.g., 192.168.1.1:80)
ScopeLocal to a single machineUsed for end-to-end communication across a network
CommunicationCannot alone establish communicationActs as one endpoint of a two-way communication link between two programs running on the network
ExamplePort 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)
  1. Packets arrive at irregular/bursty intervals and enter the bucket (queue).
  2. The bucket leaks (outputs) packets at a fixed constant rate.
  3. If the bucket is full, any new incoming packet is dropped/discarded.
  4. 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 ArrivingBucket BeforePackets SentPackets DroppedBucket After
150203
263207
3872310
4110209
509207
  • 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.
Open this answer on its own page →

Transport Protocols

2080 · 10 marks

Explain TCP header with a neat diagram. Highlight on its uses.[10]

Show solved 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:

FlagNameUse
URGUrgentIndicates urgent data is present; Urgent Pointer field is valid
ACKAcknowledgmentAcknowledgment Number field is valid
PSHPushReceiver should pass data to application immediately without buffering
RSTResetAbruptly terminates/resets the connection
SYNSynchronizeUsed during connection establishment (3-way handshake) to synchronize sequence numbers
FINFinishUsed 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

PurposeFields that provide it
Process to process deliverySource Port, Destination Port
Ordered delivery and reassemblySequence Number
Reliability and retransmissionAcknowledgment Number, ACK flag
Connection setup and releaseSYN, ACK, FIN, RST flags
Flow controlWindow Size
Error detectionChecksum
Priority (out-of-band) dataURG flag, Urgent Pointer
Header extensionHLEN, 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.

Open this answer on its own page →

2079 · 5 marks

Why TCP is called a connection-oriented and reliable protocol? Differentiate TCP with UDP. [5]

TCP is called a connection-oriented protocol because before any data is transmitted between two devices, a connection must be established between the sender and the receiver. This is done through a process known as the three-way handshake: 1. SYN - The client sends a synchronization request to th...

Open this answer on its own page →

2080.1 · 10 marks

Explain TCP header with a neat diagram. Highlight on its uses.[10]

Show solved 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:

FlagFull NameUse
URGUrgentIndicates urgent pointer field is significant
ACKAcknowledgmentAcknowledgment number is valid
PSHPushReceiver should pass data to application immediately
RSTResetResets the connection abruptly
SYNSynchronizeUsed during connection establishment (3-way handshake)
FINFinishUsed 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

PurposeFields that provide it
Process to process deliverySource Port, Destination Port
Ordered delivery and reassemblySequence Number
Reliability and retransmissionAcknowledgment Number, ACK flag
Connection setup and teardownSYN, ACK, FIN, RST flags
Flow controlWindow Size
Error detectionChecksum
Priority dataURG flag, Urgent Pointer
Header extensionData 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.

Open this answer on its own page →

Congestion Control

2078 · 5 marks

What is open-loop congestion control? Compare it with closed-loop congestion control. [5]

Congestion is a situation in which too many sources over a network attempt to send data and the router buffers start overflowing, causing packet loss and degraded performance. Congestion control refers to the mechanisms and techniques used to keep the network load below its capacity. --- In open-...

Open this answer on its own page →