Module 4
Transport Layer
Contents
Introduction
Process-to-process communication = Data transfer between specific programs running on computers, not just between the computers themselves.
Introduction
Introduction
Introduction
The transport layer communicates by helping data move reliably and efficiently between two devices.�
Transport-Layer Services
Transport-Layer Services
Transport-Layer Services
Flow control
Transport-Layer Services
User Datagram Protocol
Many applications are better suited for UDP for the following reasons:
1) Finer application-level control over what data is sent, and when:
Under UDP, as soon as an application process passes data to UDP, UDP will package the data inside a UDP segment and immediately pass the segment to the network layer(Source & destination port no, length and checksum)
2) No connection establishment:
TCP uses a three-way handshake to establish the connection before it starts to transfer data. UDP just sends the data without any formal preliminaries. Thus, UDP does not introduce any delay to establish a connection.
User Datagram Protocol
User Datagram Protocol
3) No connection state:
4) Small packet header overhead:
The TCP segment has 20 bytes of header overhead in every segment, whereas UDP has only 8 bytes of overhead.
Many applications are better suited for UDP for the following reasons:
User Datagram Protocol – Segment structure
UDP sends data in packets called user datagrams.� Each packet has a small header of 8 bytes, divided into 4 parts, each 2 bytes long.
User Datagram Protocol
The following is the content of a UDP header in hexadecimal format.
a. What is the source port number?
b. What is the destination port number?
c. What is the total length of the user datagram?
d. What is the length of the data?
e. Is the packet directed from a client to a server or
vice versa?
f. What is the client process?
UDP Packet Structure
A UDP packet = Header + Data
CB84000D001C001C
User Datagram Protocol
Solution
CB84000D001C001C
UDP Services
1. Process-to-Process Communication
UDP uses socket addresses (IP address + port number) to facilitate communication between specific processes.
2. Connectionless Services
No connection setup or termination.
Each datagram is independent and may take different paths.
Best for small messages (up to 65,507 bytes including headers).
3. No Flow Control
UDP does not manage data flow.
The sender might send messages faster than the receiver can handle, causing the receiver to become overloaded.
UDP Services
4. Error Control
Limited to a checksum for detecting errors.
No retransmission for lost or corrupted data;
faulty datagrams are discarded.
5. Checksum
UDP checksum helps detect errors in the data.
It checks three parts:
UDP Services
Why Include the Pseudoheader?
Optional Checksum
UDP Services
6. Congestion Control
UDP does not manage network congestion because it is connectionless.
It assumes packets are small and irregular, but this may not always be true (e.g., with real-time audio or video).
7. Encapsulation and Decapsulation
Encapsulation: UDP wraps data into packets (user datagrams) for sending.
Decapsulation: UDP unwraps received packets to extract the data.
UDP Services
8. Queuing
UDP uses queues for handling messages at ports:
Incoming queue: For messages arriving at the port.
Outgoing queue: For messages waiting to be sent (in some implementations).
9. Multiplexing and Demultiplexing
Multiplexing: Allows multiple processes to send data through a single UDP service.
Demultiplexing: Ensures the correct process receives the data by using port numbers.
UDP Services
Comparison with a Simple Protocol
A simple protocol means a protocol that is very basic and doesn’t do extra things like:
UDP is similar to a basic connectionless protocol but adds an optional checksum.
If the checksum detects corruption, the packet is discarded without notifying the sender.
Advantages of UDP
Disadvantages of UDP
Typical Applications
Connection-Oriented Transport: TCP
Connection-Oriented Transport: TCP
TCP Services
2. Stream Delivery Service: TCP ensures that the data is delivered in the correct order, without errors, and without duplication, providing a full-duplex, byte-stream communication between the sender and receiver.
sender and receiver, allowing seamless data flow.
TCP Services
3. Sending and Receiving Buffers
TCP uses buffers to manage data flow:
Sending Buffer: Holds data that is sent but not yet acknowledged.
Receiving Buffer: Stores incoming data until the receiving process reads it. Buffers use a circular array for efficient recycling of storage.
TCP Services
4. Segments
Data from the buffer is grouped into segments (packets) with added headers for control.
Segments can vary in size and may be lost or arrive out of order, but TCP handles these issues transparently.
TCP Services
5. Full-Duplex Communication
6. Multiplexing and Demultiplexing
TCP Services
7. Connection-Oriented Service: Communication happens in three steps:
This ensures reliable and ordered delivery.
8. Reliable Service
TCP Features
Numbering System
TCP uses byte numbers instead of segment numbers for tracking data.
The sequence number and acknowledgment number fields in the TCP header refer to byte numbers.
Sequence Numbers:
Acknowledgment Numbers:
TCP Features
Sequence Number
Example: Sending a file of 3000 bytes in 3 segments (1000 bytes each) starting with ISN = 10001:
Segment 1: 10001 (Bytes: 10001–11000)
Segment 2: 11001 (Bytes: 11001–12000)
Segment 3: 12001 (Bytes: 12001–13000)
Segement 1: Last byte = ISN + number of bytes − 1
Segment 2: First byte = last byte of previous segment + 1
= 11000 + 1 = 11001
TCP Features
Acknowledgement Number
TCP is full-duplex, meaning both sides can send and receive simultaneously.
The acknowledgement number tells the sender, "I’ve received all bytes up to this number - 1 safely.
The acknowledgement number is cumulative, meaning it confirms receipt of all prior data.
Example: If the receiver sends an acknowledgement number 5643, it means all bytes from the start up to 5642 have been received correctly.
TCP Segment Structure
The TCP segment
The TCP segment
The TCP segment consists
The TCP segment
URG: The Urgent Pointer helps the receiver identify data that should be processed immediately. A bit in the TCP header that, when set to 1, indicates the Urgent Pointer field is in use.
ACK: Confirms the receipt of data by acknowledging the next sequence number expected.
PSH (Push): Instructs the receiving system to push the data to the application layer immediately, rather than waiting to fill up the buffer.
RST (Reset): Used to reset the connection when an error is detected or an invalid segment is received.
SYN (Synchronize): Initiates a connection and synchronizes sequence numbers between sender and receiver.
FIN (Finish): Signals the intent to terminate the connection gracefully.
Phases of a TCP Connection
Connection Establishment (Three-Way Handshaking)
Phases of a TCP Connection
Connection Establishment (Three-Way Handshaking)
This involves the following steps:
Step 1: SYN
Step 2: SYN + ACK
Phases of a TCP Connection
Connection Establishment (Three-Way Handshaking)
Step 3: ACK
SYN Flooding Attack
Phases of a TCP Connection
Data Transfer
establishment, data and acknowledgments can flow in both directions. Acknowledgments can be piggybacked(Acknowledgments can be combined with outgoing data ) on data segments.
Phases of a TCP Connection
Data Transfer
The PSH (push) flag can be used when immediate delivery of data is required, bypassing normal buffering to ensure timely transmission and reception.
Urgent data, marked with the URG flag, signals that certain bytes need special attention by the receiving application. The urgent pointer shows where the urgent data ends in the segment.
Phases of a TCP Connection
TCP Connection Termination
Three-Way Handshaking: Step 1: The client sends a FIN segment to initiate termination. Step 2: The server replies with a FIN + ACK segment, acknowledging the FIN and signaling its intent to close the connection. Step 3: The client responds with an ACK, confirming the termination. | |
Phases of a TCP Connection
TCP Connection Termination
Half-Close:
Connection Reset:
Windows in TCP
TCP uses two types of windows for each direction of data transfer:
Each plays a crucial role in managing data flow, error recovery, and congestion control.
Send Window:
Windows in TCP
Send Window:
Windows in TCP
Receive Window:
I got bytes 1000–1500 and 2000–2500, but missed 1500–2000.
Windows in TCP
Receive Window:
Flow control
Flow control ensures the sender does not overwhelm the receiver by sending data faster than the receiver can process it. TCP achieves this by using a receive window (rwnd), which is a field in TCP headers that tells the sender how much more data the receiver can handle.
Flow control
In TCP flow control:
Data Paths (1, 2, and 3):
Flow Control Feedback (Paths 4 and 5):
Flow control
Opening and Closing Windows
Window adjustments:
Flow control
A Scenario
Flow control
A Scenario
Two windows – one way communication from the client to the server.
If communication is two-way (both client and server send and receive data), then there are four windows in total:
In the handshake method , each side shares its receive window size, not its send window size.
Flow control
Flow control
Connection Initiation (Three-Way Handshake):
Flow control
Data Transfer:
Flow control
Data Transfer:
Flow control Mechanism
Flow control Mechanism
Shrinking Behavior:
Relationship Rule:
Flow control Mechanism
Flow control Mechanism
Flow control
Silly Window Syndrome (SWS)
Flow control
SWS Caused by the Sender
Flow control
Benefit:
Flow control
SWS Caused by the Receiver
Flow control
Clark's Solution:
Delayed Acknowledgment:
Error control
TCP (Transmission Control Protocol) is a reliable transport-layer protocol designed to ensure data is delivered correctly and in order from the sender to the receiver.
It achieves reliability through error control mechanisms, which include
1. Checksum,
2. Acknowledgment, and
3. Retransmission strategies.
Error control
Checksum:
Error control
Acknowledgment (ACK):
Error control
Types of Acknowledgments:
Error control
Generating Acknowledgments:
Error control
Generating Acknowledgments:
Error control
Retransmission in TCP
Error control
Retransmission after Three Duplicate ACKs (Fast Retransmission):
Out-of-Order Segments:
Finite State Machines (FSMs) for TCP Data Transfer
Sender-Side FSM
Finite State Machines (FSMs) for TCP Data Transfer
Finite State Machines (FSMs) for TCP Data Transfer
Sender-Side FSM
Finite State Machines (FSMs) for TCP Data Transfer
Sender-Side FSM
Retransmitted Segment 3 arrives
Event | Receiver ACK | Duplicate Count |
Seg1 received | ACK 2 | — |
Seg2 received | ACK 3 | — |
Seg3 lost | — | — |
Seg4 received | ACK 3 | 1 |
Seg5 received | ACK 3 | 2 |
Seg6 arrives | ACK 3 | 3 → Retransmit |
Finite State Machines (FSMs) for TCP Data Transfer
Receiver-Side
Finite State Machines (FSMs) for TCP Data Transfer
Some Scenarios
1. Normal Operation: In this scenario, bidirectional data transfer occurs between the client and server, where the server sends three segments after receiving one from the client. The acknowledgment rules are as follows:
Some Scenarios
Normal Operation:
Some Scenarios
Normal Operation:
Rule 1 — Normal ACK after receiving data
Rule 2 — Delayed ACK (500 ms waiting time)
Rule 3 — Immediate ACK when new data arrives before timeout
Some Scenarios
2. Lost Segment (Figure 24.25):
The sender transmits segments 1 and 2, which are acknowledged immediately. However, segment 3 is lost (possibly discarded by a router).
The receiver then receives segment 4, which is out of order. It stores segment 4 but acknowledges the missing segment by sending an acknowledgment indicating the next expected byte (rule 4).
The sender's retransmission timer expires, and it retransmits segment 3, which is then acknowledged by the receiver (rule 5).
Some Scenarios
Lost Segment (Figure 24.25):
Some Scenarios
3. Fast Retransmission (Figure 24.26):
Some Scenarios
Some Scenarios
Some Scenarios
Some Scenarios
Deadlock
Solution (Persistence Timer):
TCP Congestion Control
Send Window Control
Intermediate Buffer Congestion
Impact of Congestion
TCP Congestion Control
TCP's Responsibility
Balanced Approach
TCP Congestion Control
Congestion Window (cwnd): Send Window Size=min(cwnd, rwnd)= min(8,5)= 5
Eg: Suppose the network can safely handle 8 KB of data (congestion window, cwnd = 8 KB).
The receiver has only 5 KB free in its buffer (receiver window, rwnd = 5 KB).
The sender can only send 5 KB at this time, because TCP takes the smaller of cwnd and rwnd.
This prevents network congestion and receiver buffer overflow.
Congestion Detection in TCP
Congestion Detection in TCP
Congestion Policies in TCP
TCP uses three main algorithms to handle congestion effectively:
slow start
congestion avoidance
fast recovery.
These algorithms adjust the size of the congestion window (cwnd) to ensure efficient data transmission without overwhelming the network.
Congestion Policies in TCP
Slow Start:
The sender begins with a congestion window (cwnd) size of 1 MSS (Maximum Segment Size).
If an ACK arrives, cwnd = cwnd + 1
Congestion Policies in TCP
Congestion Avoidance
If an ACK arrives, cwnd = cwnd + 1
Congestion Policies in TCP
Slow Start:
TCP assumes it’s close to the network’s limit - so it stops doubling and switches to Congestion Avoidance to prevent packet loss.
Congestion Avoidance
Congestion Policies in TCP
When 3 duplicate ACKs arrive:
TCP- Policy Transition
Taho TCP:
It is one of the earliest versions of Transmission Control Protocol (TCP) and focuses on reliable data delivery through simple congestion control mechanisms. It employs two main algorithms: Slow Start and Congestion Avoidance, ensuring efficient utilization of network resources while minimizing congestion.
Exponential Growth: Doubles cwnd every RTT until reaching ssthresh or congestion
Linear Growth: Size of cwnd changed to 1 MSS per RTT to avoid congestion.
TCP- Policy Transition
Taho TCP:
On detection:
TCP- Policy Transition
Taho TCP:
TCP- Policy Transition
Reno TCP
Reno TCP is an improved version of Taho TCP that introduces a new state called Fast Recovery, enabling more efficient handling of duplicate ACKs and distinguishing between minor and severe congestion events.
Time-out Handling: Severe congestion is indicated by a time-out.
TCP resets the cwnd to 1 MSS and moves to the Slow Start state.
TCP- Policy Transition
Reno TCP
Fast Recovery State: When the sender gets three duplicate ACKs, it means one packet got lost, but the connection is still working.
So, instead of going back to the beginning (like in Slow Start), the sender slightly increases its window to (cwnd) is increased to ssthresh + 3 MSS.
TCP- Policy Transition
Reno TCP
TCP- Policy Transition
Reno TCP
TCP- Policy Transition
New Reno TCP
NewReno TCP improves Reno by handling multiple lost segments in the same window more efficiently. It enhances Fast Recovery to process partial ACKs and avoid repeated duplicate ACKs.
Handling Multiple Segment Losses:
TCP- Policy Transition
New Reno TCP
Improved Fast Recovery: Stays in the Fast Recovery state until all segments from the congestion window are acknowledged.
TCP- Policy Transition
TCP Throughput
TCP- Policy Transition
TCP Throughput
TCP- Policy Transition
TCP Throughput
When considering Maximum Segment Size (MSS) in the TCP throughput formula, it accounts for the actual size of the data packets sent: