0% found this document useful (0 votes)
14 views78 pages

Transport Layer Overview in Networking

The document provides an overview of the transport layer in computer networks, detailing its role in process-to-process communication and the establishment of logical connections between applications on different hosts. It discusses key concepts such as port numbers, socket addresses, flow control, error control, and the differences between connectionless (UDP) and connection-oriented (TCP) services. Additionally, it covers mechanisms like multiplexing, demultiplexing, and the finite state machine (FSM) in transport-layer protocols.

Uploaded by

mouriyaaa18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views78 pages

Transport Layer Overview in Networking

The document provides an overview of the transport layer in computer networks, detailing its role in process-to-process communication and the establishment of logical connections between applications on different hosts. It discusses key concepts such as port numbers, socket addresses, flow control, error control, and the differences between connectionless (UDP) and connection-oriented (TCP) services. Additionally, it covers mechanisms like multiplexing, demultiplexing, and the finite state machine (FSM) in transport-layer protocols.

Uploaded by

mouriyaaa18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BCS502 | COMPUTER NETWORKS

MODULE-4

Chapter: -01- Introduction to Transport Layer

INTRODUCTION

❖ Position of Transport Layer: Sits between the application layer (above) and
the network layer (below).
❖ Process-to-Process Communication: Enables communication directly
between applications on two hosts (one local, one remote).
❖ Logical Connection: The transport layer creates a "virtual" or logical
connection that allows application layers on separate devices to communicate as
if they were directly linked.
❖ Global Reach: Communication is possible across the globe, with applications
assuming a direct link.
❖ Transport Layer Example: Illustrated by the example of two hosts – Alice’s in
Sky Research and Bob’s in Scientific Books – communicating as if directly
connected.
❖ End System Reliance: Only the two end systems (like Alice's and Bob's
computers) use the transport layer; intermediate devices, like routers, only use
the lower three layers (physical, data link, and network layers).

Page 1
BCS502 | COMPUTER NETWORKS

Transport Layer Position and Role: It provides services to the application layer
above it and receives services from the network layer below.

Process-to-Process Communication: A key responsibility of the transport layer,


which ensures that messages are delivered to the correct application process on the
receiving host, unlike the network layer, which only manages host-to-host
communication.

Page 2
BCS502 | COMPUTER NETWORKS

Client-Server Paradigm: Process-to-process communication often follows this


paradigm, where a client process on the local host communicates with a server
process on a remote host.

Port Numbers:

• Ephemeral Ports: Used by client processes, typically above 1023, for short-
lived communication.
• Well-Known Ports: Assigned to server processes to standardize and
simplify connections (e.g., port 13 for a daytime server).

Page 3
BCS502 | COMPUTER NETWORKS

IP Address and Port Roles:

• IP Address: Identifies the destination host on the network.


• Port Number: Identifies the specific process on the host.

Page 4
BCS502 | COMPUTER NETWORKS

Socket Addresses:

• A socket address combines an IP address and a port number, uniquely


identifying client and server processes.
• Both client and server socket addresses are essential for transport-layer
communication, included in network and transport-layer headers.

Encapsulation and Decapsulation:

• Encapsulation: At the sender, the transport layer adds a header to the


message to create a packet, which includes the sender and receiver socket
addresses.
• Decapsulation: At the receiver, the transport layer removes the header and
delivers the message to the correct application-layer process, passing the
sender’s address for possible responses.

Multiplexing and Demultiplexing:

• Multiplexing: The transport layer at the sender collects messages from


multiple sources, combining them for transmission.
• Demultiplexing: At the receiver, the transport layer separates incoming
packets, delivering each to the correct process.

Page 5
BCS502 | COMPUTER NETWORKS

Flow Control:

• Ensures that the message production and consumption rates are balanced,
preventing data loss if the receiver cannot process messages as fast as they
arrive.

Pushing and Pulling:

• Pushing: The sender pushes items to the receiver as they’re produced,


possibly requiring flow control to prevent overload.

Page 6
BCS502 | COMPUTER NETWORKS

• Pulling: The receiver requests items when ready, avoiding the need for flow
control as the consumer controls the data flow.

Flow Control at the Transport Layer:

• Involves four entities: the sender process, sender transport layer, receiver
transport layer, and receiver process.
• The sender process produces messages and pushes them to the sender
transport layer, which packages these into packets and pushes them to the
receiver.
• The receiver transport layer decapsulates packets and delivers messages to
the receiver process, typically via pulling.

Page 7
BCS502 | COMPUTER NETWORKS

Flow Control Mechanisms:

• Sender to Sender Transport Layer: The sender transport layer signals the
application to pause/resume sending if its buffer is full or has vacancies.
• Receiver to Sender Transport Layer: The receiver transport layer signals
the sender to pause/resume sending based on buffer capacity.

Buffers:

• Buffers at both sender and receiver sides help manage message flow and
avoid overload.
• Communication of buffer status between sender and receiver helps prevent
data loss and maintains smooth message delivery.

Error Control:

• Provides reliability despite an unreliable underlying network layer by


managing:
1. Corrupted Packets: Detecting and discarding damaged packets.
2. Lost or Discarded Packets: Tracking and resending as needed.
3. Duplicate Packets: Identifying and discarding redundant packets.
4. Out-of-Order Packets: Buffering until missing packets arrive for
ordered delivery.
• Error control occurs between the sender and receiver transport layers,
independent of the application layer.

Page 8
BCS502 | COMPUTER NETWORKS

Sequence Numbers:

• Used to track packets, ensuring accurate resending, duplicate detection, and


proper ordering.
• Sequence numbers are added to each packet’s header and typically wrap
around if the numbering reaches its maximum limit (e.g., if limited to 4 bits,
numbering goes from 0 to 15 and then wraps around).

Acknowledgment (ACK):

o Positive acknowledgments (ACKs) signal successful packet receipt.


o The sender uses a timer: if no ACK is received before expiration, it resends the
packet, assuming it’s lost.
o The receiver discards corrupted packets, discards or stores out-of-order packets,
and discards duplicate packets.

Combination of Flow and Error Control:

o Flow control uses buffers at both sender and receiver sites.


o Error control uses sequence numbers and ACKs for tracking packet status.
o Numbered Buffers: Both flow and error control use numbered buffers where:
▪ The sender assigns a sequence number to each packet using the next
available buffer location.
▪ The receiver stores packets based on their sequence number and sends
ACKs to the sender.

Page 9
BCS502 | COMPUTER NETWORKS

Sliding Window:

o Represents a set of sequence numbers as a circular buffer, handling packets in a


range within a buffer’s sequence.
o At the sender, each sent packet marks a slice. When ACKs arrive, the
corresponding slices are cleared.
o If consecutive slices are unmarked, the window slides forward, allowing new
packets to enter the buffer.
o The sliding window helps manage the buffer, preventing overload and ensuring
orderly transmission.

Page 10
BCS502 | COMPUTER NETWORKS

Congestion Control:

o Congestion happens when the packet load exceeds network capacity.


o Causes of Congestion: Routers and switches with input/output queues can
overload if packets arrive faster than they can be processed.
o Impact: Congestion in the network layer impacts the transport layer, as seen by
delays or packet loss.
o TCP’s Role: TCP includes its own congestion control mechanisms to manage
congestion effects when there’s no control at the network layer.

Connectionless Service:

o Independence of Packets: Each packet (or chunk of data) is treated


individually, with no dependency on others.
o No Coordination: The transport layer sends packets independently, leading to
possible issues:
▪ Out-of-Order Delivery: Since packets travel independently, they may
arrive out of order.
▪ Packet Loss: If a packet is lost, the receiving side won’t detect it due
to the lack of sequence numbers or error-checking controls.
o Lack of Control Mechanisms:

Page 11
BCS502 | COMPUTER NETWORKS

▪ Flow, error, and congestion control are generally ineffective because of


the lack of connection and state tracking.
o Example Scenario: A client sending three message chunks (packets) to a
server may have these arrive in an incorrect order or lose one, resulting in
incomplete or distorted data for the receiver.

Connection-Oriented Service:

o Establishment of a Logical Connection: Requires a setup phase where the


client and server establish a logical connection.
o Three Phases:
1. Connection Establishment: The client and server agree on a connection to
track packet ordering and state.
2. Data Transfer: Packets are sent sequentially, with dependencies managed
to ensure order and reliability.
3. Connection Tear-Down: The connection is closed after data transmission
completes.

Page 12
BCS502 | COMPUTER NETWORKS

o End-to-End Control: Only the two hosts (client and server) are involved,
without requiring router involvement.
o Support for Control Mechanisms:
▪ Flow Control: Manages data rate between sender and receiver.
▪ Error Control: Handles detection and retransmission of lost or
corrupted packets.
▪ Congestion Control: Mitigates network congestion by adjusting the
flow.
o Examples: Common transport-layer protocols like TCP (Transmission Control
Protocol) utilize connection-oriented services to ensure reliable and ordered data
transmission.

Page 13
BCS502 | COMPUTER NETWORKS

FSM in Transport-Layer Protocols

1. FSM Basics:
o States: Represent specific conditions in the protocol, like "closed," "open-
wait," or "established."
o Events: External inputs or conditions that trigger state transitions, such as
receiving a request or acknowledgment.
o Actions: The specific steps taken in response to an event, such as sending
an acknowledgment or request.
o Initial State: The starting point, often the "closed" state for connection-
oriented protocols.

Page 14
BCS502 | COMPUTER NETWORKS

2. FSM for Connectionless Protocols:


o Single State (Established): In connectionless protocols, only one state
(often "established") is needed. Both sender and receiver stay in this state,
ready to send and receive data packets without formal connection setup or
teardown.
3. FSM for Connection-Oriented Protocols:
o Connection-oriented protocols require multiple states to establish, manage,
and close a connection.
o Key States:
▪ Closed State: The initial state where no connection exists.
▪ Open-Wait-I & Open-Wait-II: Intermediate states where
connection setup is in progress. For example, in Open-Wait-I, one
side is waiting for an acknowledgment after sending a connection
request.
▪ Established State: The state where a full bidirectional connection
is established, allowing data and acknowledgments to be
exchanged.
▪ Close-Wait-I & Close-Wait-II: Intermediate states for
connection termination, where each side confirms the closure
sequentially.
▪ Closed State (again): The end state once both sides
acknowledge the connection has ended.

Example State Transitions in Connection-Oriented FSM

1. Connection Establishment:
o Closed → Open-Wait-I: The machine sends an open request packet
after receiving a connection request from the local process.
o Open-Wait-I → Open-Wait-II: Upon receiving an acknowledgment
from the other end, it progresses to Open-Wait-II.

Page 15
BCS502 | COMPUTER NETWORKS

o Open-Wait-II → Established: With a bidirectional connection request


and acknowledgment exchange, the FSM enters the Established state.
2. Data Transfer:
o While in the Established state, data packets and acknowledgments are
exchanged freely between the two transport layers.
3. Connection Termination:
o Established → Close-Wait-I: When a close request is received, the
machine sends a close request to the other end and transitions to Close-
Wait-I.
o Close-Wait-I → Close-Wait-II: After the acknowledgment is received,
it moves to Close-Wait-II and waits for the other end’s close request.
o Close-Wait-II → Closed: Upon receiving the final close request and
acknowledgment, the FSM returns to the Closed state.

Page 16
BCS502 | COMPUTER NETWORKS

Chapter: -02 - Transport-Layer Protocols

INTRODUCTION

Page 17
BCS502 | COMPUTER NETWORKS

Port Numbers

1. End-to-End Communication:
o Port numbers provide a way to establish communication directly between
applications or services, such as a web browser and a web server, by
addressing data packets to specific processes on a device.
2. Multiplexing and Demultiplexing:
o Multiplexing allows multiple applications on a single host to share the
same transport-layer protocol, each identified by its unique port number.
o Demultiplexing enables the transport layer at the receiving end to direct
incoming packets to the correct application, based on the destination port
number.

Standardized Port Numbers

There are some well-known port numbers associated with common applications
and protocols. Here’s a sample of common port numbers for each transport-layer
protocol:

• HTTP: Port 80 (TCP)


• HTTPS: Port 443 (TCP)
• FTP: Port 21 (TCP)
• SMTP (for sending emails): Port 25 (TCP)
• DNS: Port 53 (UDP)
• DHCP: Port 67 and 68 (UDP)

These port numbers are standardized, meaning they are recognized by servers and
clients worldwide, allowing applications and services to communicate seamlessly
across networks.

Page 18
BCS502 | COMPUTER NETWORKS

User Datagram Protocol (UDP)

The User Datagram Protocol (UDP) is a connectionless and unreliable


transport protocol.

Unlike TCP, UDP does not establish a connection before sending data and does not
guarantee delivery, order, or error checking, making it lightweight and efficient.
Here’s an overview of UDP’s structure, benefits, and use cases:

Why Use UDP?

Despite its lack of reliability, UDP is advantageous in scenarios where:

1. Minimal Overhead: UDP’s simplicity means there’s little protocol overhead. It’s
ideal for applications that prioritize low latency over guaranteed delivery.
2. Small, Quick Messages: When sending small, time-sensitive data (like DNS
queries), UDP is more efficient as it skips the connection setup that TCP requires.
Page 19
BCS502 | COMPUTER NETWORKS

3. Broadcast and Multicast Support: UDP can broadcast to multiple clients


without needing individual connections, useful in real-time applications like live
video streams.

UDP Datagram Structure

A UDP datagram consists of a fixed-size header (8 bytes) followed by data. The 8-


byte header includes:

• Source Port (16 bits): The port number on the sender’s end.
• Destination Port (16 bits): The port number on the receiver’s end.
• Length (16 bits): Specifies the total length of the datagram, including
header and data. The maximum length is 65,535 bytes, but IP limits this
slightly lower.
• Checksum (16 bits): An optional field that provides minimal error-checking
for the data integrity.

Use Cases for UDP

UDP is well-suited for:

• DNS (Domain Name System): Queries are brief and can tolerate
occasional packet loss.
• Streaming Media: Video and audio streams favor speed, even if some data
loss occurs.
• Online Games: Many games use UDP for fast data transmission, favoring
real-time updates over reliability.

Page 20
BCS502 | COMPUTER NETWORKS

UDP Services Overview

The User Datagram Protocol (UDP), as a connectionless transport protocol,


offers a range of basic but valuable services for process-to-process communication.
Here’s an outline of the services and functionality UDP provides:

Page 21
BCS502 | COMPUTER NETWORKS

Process-to-Process Communication:

o UDP enables process-to-process (rather than host-to-host) communication


through socket addresses, which are a combination of IP addresses and port
numbers.

Connectionless Services:

o UDP treats each packet (or user datagram) as independent, without


maintaining any connection. This means:
▪ Packets are not numbered or acknowledged.
▪ There is no connection establishment or termination phase.
▪ Each datagram could take a different path to the destination.
o Limitation: Since each datagram must be independent, each message sent
should be small enough to fit within a single datagram (up to 65,507 bytes due
to IP and UDP header limitations).

Flow Control:

o No flow control is provided in UDP. The receiving application may experience


overflow if it cannot process incoming datagrams quickly enough.

Error Control:

o UDP’s error control is limited to an optional checksum. If a packet is corrupted,


UDP discards it without notifying the sender, so there’s no retransmission. This
lack of error control makes UDP lightweight and fast, but less reliable.

❖ Checksum Calculation:

▪ UDP’s checksum is calculated over a pseudoheader (part of the IP header),


the UDP header, and the data.

Page 22
BCS502 | COMPUTER NETWORKS

▪ The pseudoheader helps ensure the datagram isn’t delivered to the wrong
host or protocol by including the IP and protocol fields.

❖ Checksum Inclusion Rules:

▪ If checksum calculation is skipped, the field is set to all 0s.


▪ If the calculated checksum equals 0, it’s changed to all 1s before being
sent.

Congestion Control:

o UDP does not manage congestion. Its packets are assumed to be small and
sporadic, a feature originally intended to keep them from congesting the
network. However, modern UDP applications for video and audio streaming can
sometimes defy this assumption.

Encapsulation and Decapsulation:

o UDP handles messages by encapsulating them into packets with headers and
decapsulating incoming packets to retrieve the data for the application layer.

Page 23
BCS502 | COMPUTER NETWORKS

Queuing:

o Ports and Queues: Each process using UDP is allocated a port and typically has
queues associated with it. Most implementations create both incoming and
outgoing queues, while some only have incoming queues.

Multiplexing and Demultiplexing:

o Multiplexing allows multiple processes to use UDP simultaneously by mapping


each to its port, while demultiplexing ensures incoming packets are directed to
the correct process based on the port number.

UDP vs. Generic Simple Protocol

UDP is very similar to a basic connectionless protocol, with the main difference being
the optional checksum for error detection. In UDP, if a packet is corrupted, it’s
discarded without notification, aligning with UDP’s focus on simplicity and efficiency.

UDP Applications and Features

Although UDP lacks many of the reliability features found in protocols like TCP, it is
ideal for specific applications where low latency and minimal overhead are prioritized
over reliability.

Connectionless Service

Independence of Packets: Each UDP packet (user datagram) is treated


independently, without maintaining any relationship between packets. This
independence reduces the need for establishing and closing connections, saving time
and resources.

Page 24
BCS502 | COMPUTER NETWORKS

Advantages:

o Lower Overhead: In a connectionless setup, fewer packets are exchanged,


reducing overhead. For instance, only two packets may be needed in a simple
request-response scenario, compared to nine in a TCP-based connection-oriented
protocol.
o Reduced Delay: With no connection establishment or teardown, the application
can achieve faster round-trip times, which is crucial for time-sensitive
applications.

Disadvantages:

o Unreliability: Since each packet is independent, there’s no built-in mechanism


to ensure packet delivery, order, or duplicate handling. This might be unsuitable
for applications where data accuracy is paramount.

Applications Where UDP is Preferred

Applications that Tolerate Some Loss: For applications that prioritize speed over
reliability, occasional data loss is acceptable.

Examples of Typical UDP Applications:

o Domain Name System (DNS): DNS uses UDP for queries as it needs a quick
request-response mechanism and tolerates occasional packet loss.
o Streaming Services (e.g., audio, video): Real-time streaming apps use UDP
because small losses in data do not severely impact the user experience, and the
low latency of UDP is more beneficial than the guaranteed delivery of TCP.
o Voice over IP (VoIP): Like streaming, VoIP applications need low latency to
maintain real-time communication, and occasional data loss is manageable.
o Simple Network Management Protocol (SNMP): SNMP, used for network
management and monitoring, also uses UDP to ensure prompt responses without
the delays associated with TCP connections.

Page 25
BCS502 | COMPUTER NETWORKS

Chapter: -03- Transmission Control Protocol

Transmission Control Protocol

Transmission Control Protocol (TCP) is a connection-oriented, reliable


transport-layer protocol widely used for Internet communication due to its
robustness in handling data transmission.

TCP Services

Before discussing TCP in detail, let us explain the services offered by TCP to the pro
cesses at the application layer.

Connection-Oriented Service:

o TCP establishes a connection between sender and receiver before data


transmission. This includes setup, data transfer, and teardown phases, ensuring
data flows smoothly in both directions.

Process-to-Process Communication:

o Like UDP, TCP uses port numbers to establish a link between application
processes at the transport layer.

Stream Delivery Service:

o TCP allows data to flow as a continuous stream of bytes, unlike UDP, which
transmits discrete packets. TCP segments this stream into packets (segments),
which are handled by the network layer.
o This stream delivery provides the impression of a direct "pipe" between
communicating applications.

Page 26
BCS502 | COMPUTER NETWORKS

Buffered Transmission:

o TCP uses sending and receiving buffers to manage differences in the rates at
which processes produce or consume data. The sender buffer stores bytes until
they are acknowledged by the receiver.
o Buffers also allow retransmissions and maintain efficient data flow despite delays
or network congestion.

Page 27
BCS502 | COMPUTER NETWORKS

Segmentation:

o Data streams are divided into manageable segments, each with a header for
control information.
o Segments might vary in size, typically containing hundreds to thousands of bytes,
and are encapsulated in IP packets for transmission.

Reliability Mechanisms:

o TCP ensures data integrity using several techniques:


▪ Checksums detect errors.
▪ Acknowledgments and retransmissions help recover lost or corrupted
segments.
▪ TCP combines Go-Back-N (GBN) and Selective Repeat (SR)
protocols, allowing for reliable data recovery and handling multiple in-
transit segments.
▪ Timers ensure timely retransmission if acknowledgments are delayed.

TCP's combination of connection-oriented service, reliability mechanisms, and


buffered stream handling makes it the preferred protocol for applications needing
reliable data transfer, such as web browsing, email, and file transfers.

Page 28
BCS502 | COMPUTER NETWORKS

Full-Duplex Communication

TCP (Transmission Control Protocol) provides full-duplex communication, enabling


data to flow simultaneously in both directions between the sender and receiver.
Each endpoint in a TCP connection maintains its own sending and receiving buffers,
allowing for efficient bidirectional data transfer.

Multiplexing and Demultiplexing

Multiplexing: At the sender's side, TCP combines data streams from multiple
application processes into a single stream of segments. This allows efficient use of
network resources by sharing the same connection.

Demultiplexing: At the receiver's side, TCP separates the incoming segments and
directs them to the appropriate application process based on the destination port
numbers. Each connection between a pair of processes requires a unique socket,
ensuring that data from different connections does not mix.

Connection-Oriented Service

TCP is fundamentally a connection-oriented protocol, which entails the following


three phases for communication between two processes (e.g., process A at site A
and process B at site B):

1. Connection Establishment:
o A logical connection is established through a handshake process, typically
using the three-way handshake method:
▪ Process A sends a SYN (synchronize) segment to Process B.
▪ Process B responds with a SYN-ACK (synchronize-acknowledge)
segment.
▪ Process A sends an ACK (acknowledge) segment back to Process B,
completing the connection setup.
2. Data Exchange:
Page 29
BCS502 | COMPUTER NETWORKS

o After the connection is established, data can be exchanged in both directions.


Each process can send and receive segments independently, maintaining the
stream-oriented nature of TCP.
3. Connection Termination:
o When the data transfer is complete, the connection must be terminated
gracefully. This is typically done using a four-way handshake:
▪ One process sends a FIN (finish) segment to indicate it has finished
sending data.
▪ The other process acknowledges with an ACK, then sends its own
FIN segment.
▪ The first process acknowledges this FIN with an ACK, and the
connection is closed.

Reliable Service

TCP guarantees reliable data delivery through several mechanisms:

• Acknowledgment: Each segment sent must be acknowledged by the receiver.


If an acknowledgment is not received within a specified timeout period, the
sender retransmits the segment.
• Error Detection: TCP segments include a checksum to verify data integrity. If a
segment is found to be corrupted, it is discarded, and the sender is notified to
retransmit.
• In-Order Delivery: TCP ensures that segments are delivered in the order they
were sent. If segments arrive out of order, TCP buffers them and delivers them
in the correct sequence to the receiving application.

Through these features, TCP provides a robust and reliable means of communication
over the Internet, making it suitable for applications that require guaranteed delivery
of data.

Page 30
BCS502 | COMPUTER NETWORKS

TCP Features

To provide its reliable and ordered services, TCP incorporates several key features:

Numbering System

TCP does not use a segment number field in its header. Instead, it employs two
key fields: the sequence number and the acknowledgment number, which
refer to byte numbers rather than segment numbers.

Byte Numbering

• Byte Tracking: TCP assigns a unique number to every byte (or octet)
transmitted within a connection. This numbering is maintained independently
for each direction (sender to receiver and vice versa).
• Starting Point: The numbering can start from any arbitrary value between 0
and 232 -1. For instance, if the first byte's number is 1057, the subsequent
bytes are numbered consecutively up to 7056 if a total of 6000 bytes are
sent.

Sequence Number

• Initial Sequence Number (ISN): The first segment sent in a TCP


connection has a sequence number known as the ISN, which is a randomly
chosen number. This randomness helps prevent certain types of attacks.
• Subsequent Sequence Numbers: Each subsequent segment's sequence
number is calculated as the sequence number of the previous segment plus
the number of bytes it carries. For control segments that do not carry any
user data, they are treated as carrying one imaginary byte to maintain
consistency.

Page 31
BCS502 | COMPUTER NETWORKS

Acknowledgment Number

• Full Duplex Communication: Since TCP allows both parties to send and
receive data simultaneously, each party maintains its own byte numbering.
• Acknowledgment Mechanism: The acknowledgment number is used to
confirm receipt of data. It indicates the next byte the receiving party expects
to receive.
• Cumulative Acknowledgment: This means that if a party uses a specific
acknowledgment number, say 5643, it has successfully received all bytes up
to, but not including, byte number 5643. This does not imply that the party
has received exactly 5642 bytes, as the starting byte number can vary.

TCP Segment

In the context of TCP, a packet is referred to as a segment. The structure of a TCP


segment is designed to facilitate reliable communication over the network.

Format of a TCP Segment

The format of a TCP segment includes a header followed by the application data.
The header can range from 20 to 60 bytes in length, depending on whether it
includes optional fields.

Page 32
BCS502 | COMPUTER NETWORKS

Key Fields in the TCP Header

Here are the key fields found in a TCP segment header:

1. Source Port Address (16 bits):


o Defines the port number of the application program in the host sending
the segment.
2. Destination Port Address (16 bits):
o Defines the port number of the application program in the host receiving
the segment.
3. Sequence Number (32 bits):
o Indicates the byte number of the first byte of data in the segment. TCP
numbers each byte in the stream to maintain order. The initial sequence
number (ISN) is randomly generated during connection establishment.
4. Acknowledgment Number (32 bits):

Page 33
BCS502 | COMPUTER NETWORKS

o Indicates the byte number the receiver expects next. If a receiver has
successfully received byte number x, it sends x + 1 as the acknowledgment
number. This field can be used together with data in a process called
piggybacking.
5. Header Length (4 bits):
o Indicates the number of 32-bit words in the TCP header. The length can
range from 20 bytes (5 words) to 60 bytes (15 words).
6. Control (6 bits):
o Defines various control flags (bits) used for flow control, connection
establishment, termination, and data transfer modes. The flags include
SYN, ACK, FIN, RST, PSH, and URG. Multiple flags can be set
simultaneously.

7. Window Size (16 bits):


o Specifies the size of the sender's buffer in bytes. This field helps control
flow; the maximum value is 65,535 bytes. It indicates how much data the
sender is allowed to transmit before needing an acknowledgment.
8. Checksum (16 bits):
o Contains a checksum value used for error detection. The checksum is
mandatory for TCP segments and follows a calculation similar to that used
in UDP. The pseudoheader (which includes source and destination IP
addresses and the protocol number) is also used in the checksum
calculation.

Page 34
BCS502 | COMPUTER NETWORKS

9. Urgent Pointer (16 bits):


o Used when the urgent flag is set, indicating that the segment contains
urgent data. This field specifies a value to be added to the sequence
number to find the last byte of urgent data in the segment.
10. Options (variable length, up to 40 bytes):
o Optional information can be included in the TCP header, allowing for
additional features like maximum segment size (MSS), timestamps, and
window scaling.

Encapsulation

• A TCP segment encapsulates the data received from the application layer and
is placed within an IP datagram. The IP datagram is then encapsulated in a
frame at the data-link layer for transmission over the network.

Page 35
BCS502 | COMPUTER NETWORKS

TCP Connection Overview

TCP (Transmission Control Protocol) is a connection-oriented protocol, meaning it


establishes a logical connection between the source and destination before any data
transmission occurs.

This connection ensures that all segments belonging to a message are sent reliably
over a single logical pathway, facilitating acknowledgment and retransmission
processes for any lost or damaged frames.

Logical vs. Physical Connection

Although TCP relies on IP, which is a connectionless protocol, TCP connections are
logical, not physical.

This means that while TCP controls the connection and manages the reliability of
data transmission, it uses the services of IP to deliver individual segments.

TCP is responsible for retransmissions, ordering segments, and ensuring data


integrity, while IP does not maintain any information about the state of the
connection.

Phases of TCP Connection Establishment

The establishment of a TCP connection involves three phases: connection


establishment, data transfer, and connection termination.

Connection Establishment: Three-Way Handshaking

TCP uses a process called three-way handshaking to establish a connection. This


process involves the following steps:

Page 36
BCS502 | COMPUTER NETWORKS

SYN Segment (Client to Server):

o The client initiates the connection by sending a SYN segment to the server.
o This segment has the SYN flag set and includes an Initial Sequence Number
(ISN) chosen by the client.
o This segment does not have an acknowledgment number or window size defined,
as it is purely for synchronization and does not carry data. However, it consumes
one sequence number, as it is acknowledged by the server.

SYN + ACK Segment (Server to Client):

o Upon receiving the SYN segment, the server responds with a SYN + ACK
segment. This segment has both the SYN and ACK flags set. The server uses
this segment to:
▪ Initialize its own sequence number for sending data back to the client.
▪ Acknowledge the receipt of the client's SYN segment by setting the
acknowledgment number to the client's ISN + 1.

Page 37
BCS502 | COMPUTER NETWORKS

▪ Define the receive window size (rwnd), which indicates how much data
the server can accept from the client.
o Like the SYN segment, this segment also consumes one sequence number
because it needs acknowledgment.

ACK Segment (Client to Server):

o Finally, the client sends an ACK segment back to the server. This segment has
the ACK flag set and acknowledges the receipt of the server's SYN + ACK
segment by including the acknowledgment number corresponding to the server's
sequence number + 1.
o If this ACK segment does not carry any data, it does not consume any sequence
numbers. However, some implementations may allow this segment to carry data,
in which case it would consume as many sequence numbers as the number of
bytes sent.

Three-Way Handshaking Process

• Step 1: Client sends SYN to server (establishing its sequence number).


• Step 2: Server responds with SYN + ACK (establishing its sequence number
and acknowledging the client).
• Step 3: Client sends ACK to server (acknowledging the server’s SYN + ACK).

This three-step process successfully establishes a reliable, logical connection


between the client and server, allowing for the subsequent transfer of data.

Each party is now able to send and receive data in both directions, benefiting from
the reliability and order guarantees that TCP provides.

Page 38
BCS502 | COMPUTER NETWORKS

SYN Flooding Attack

The SYN flooding attack is a type of denial-of-service (DoS) attack that targets
the TCP connection establishment process, specifically the three-way handshake
mechanism.

This attack exploits the way TCP allocates resources when it receives SYN segments
from clients.

How SYN Flooding Works

Malicious SYN Segments: An attacker sends a large number of SYN segments


to a TCP server, spoofing the source IP addresses in these segments. This
creates the illusion that the requests are coming from multiple clients.
Resource Allocation by the Server: Upon receiving each SYN segment, the
server allocates resources, such as creating a Transmission Control Block
(TCB) and setting timers for each connection request, assuming these are
legitimate clients attempting to establish a connection.
Lost SYN + ACK Segments: The server responds to each SYN request by
sending a SYN + ACK segment back to the (fake) clients. However, because
these IP addresses are faked, the SYN + ACK segments are not received, leading
to unacknowledged requests.
Resource Exhaustion: As the server waits for the final acknowledgment from
the fake clients, its allocated resources start to pile up. If the volume of SYN
requests is sufficiently high, the server can exhaust its resources, preventing it
from accepting valid connection requests from legitimate clients.

Denial of Service Implications

SYN flooding attacks fall under the category of denial of service (DoS) attacks,
where the attacker overloads the system with service requests, rendering it unable
to respond to legitimate requests.

Page 39
BCS502 | COMPUTER NETWORKS

Mitigation Strategies

Several strategies can be employed to mitigate the effects of SYN flooding attacks:

• Rate Limiting: Implement limits on the number of connection requests a


server will accept from a single source IP address over a specified period.
• SYN Cookies: This method involves postponing resource allocation until the
server can verify the connection request is valid. The server responds with a
SYN + ACK segment that contains a cookie based on the SYN request,
allowing it to validate the acknowledgment when received.
• Source Address Filtering: The server can be configured to drop or ignore
SYN requests that originate from suspicious or unwanted IP addresses.

Data Transfer in TCP

After a TCP connection is successfully established, bidirectional data transfer can


occur between the client and server. Here’s how it works:

• Bidirectional Communication: Both the client and server can send data
and acknowledgments simultaneously. Data and acknowledgments are often
combined in the same segment, known as piggybacking.

Example of Data Transfer

1. Data Segments: After the connection is established, the client might send
2,000 bytes of data in two segments. The server then sends 2,000 bytes in
one segment back to the client.
2. Acknowledgment Segments: The first three segments from the client
carry both data and acknowledgment information, while the last segment
might carry only an acknowledgment, indicating that there is no additional
data to send.
3. PSH Flag: In the segments sent by the client, the PSH (push) flag can be
set to instruct the server’s TCP to deliver the received data to the application
Page 40
BCS502 | COMPUTER NETWORKS

layer immediately. In contrast, the server’s response may not set this flag,
allowing it to buffer the data until it is ready for processing.

Pushing Data

In scenarios where immediate data transfer and response are crucial (e.g.,
interactive applications), TCP provides the capability to push data:

Page 41
BCS502 | COMPUTER NETWORKS

• Immediate Sending: The sending application can request a push operation,


allowing TCP to create a segment and send it immediately, rather than waiting
for the segment buffer to fill.
• PSH Bit: The sending TCP sets the PSH bit in the segment to indicate that the
receiving TCP should deliver the data as soon as it arrives, rather than buffering
it. This changes the behavior of TCP from a byte-oriented to a chunk-oriented
protocol for that segment.

Urgent Data in TCP

TCP is designed as a stream-oriented protocol, meaning it treats data as a


continuous stream of bytes, where each byte has a specific position within that
stream.

However, there are situations where certain bytes need to be prioritized and
processed urgently. TCP provides a mechanism to handle such urgent data through
the URG flag.

Sending Urgent Data

1. Setting the URG Flag: When an application program needs to send urgent
data, it signals to the TCP layer by marking that segment with the URG bit set.
2. Urgent Pointer: The urgent data is placed at the beginning of the segment,
followed by regular data. The TCP header includes an urgent pointer field that
specifies the end of the urgent data. For instance, if the sequence number of the
segment is 15,000 and the urgent pointer indicates 200, the urgent data spans
from byte 15,000 to byte 15,200.
3. Delivery to Application: Although TCP delivers all bytes in order (including
both urgent and nonurgent data), it notifies the application program about the
presence of urgent data, allowing the application to handle it appropriately.

Page 42
BCS502 | COMPUTER NETWORKS

Important Note

It's crucial to understand that TCP's handling of urgent data is not synonymous with
priority service or out-of-band data. Instead, it allows the sender to mark certain
bytes in the stream for special treatment at the receiver's end, but the receiving TCP
still delivers data sequentially.

Connection Termination

In TCP, either party (client or server) can initiate the connection termination
process, though it is typically started by the client. There are two primary methods
for connection termination:

1. Three-Way Handshaking
2. Four-Way Handshaking with Half-Close Option

Three-Way Handshaking for Termination

This is the most common method employed for terminating a TCP connection:

1. Client Sends FIN: The client sends a segment with the FIN (Finish) flag set,
indicating its intention to close the connection. This segment can either carry the
last chunk of data or be a control segment. If it’s purely a control segment, it
consumes one sequence number for acknowledgment.
2. Server Acknowledges and Sends FIN: Upon receiving the FIN segment, the
server acknowledges it by sending a FIN + ACK segment. This segment
confirms the receipt of the client’s FIN segment and indicates that it will also
close the connection in the other direction. Similar to the previous step, if it does
not contain data, it consumes one sequence number.
3. Client Sends ACK: The client responds with an ACK segment to acknowledge
the server's FIN. This segment carries the acknowledgment number, which is one
more than the sequence number received in the server's FIN segment. An ACK

Page 43
BCS502 | COMPUTER NETWORKS

segment in this context does not consume any sequence numbers if it does not
carry data.

Half-Close Option

A half-close allows one end of the connection to stop sending data while still being
able to receive data. This scenario can occur in various situations, such as when a
server needs all incoming data before processing it.

Example of Half-Close

1. Client Sends Data: The client sends data to the server, indicating that it has
finished sending by sending a FIN segment.
2. Server Acknowledges Half-Close: The server accepts the half-close by
sending an ACK segment, indicating it acknowledges the client's closure of
the connection for sending data.

Page 44
BCS502 | COMPUTER NETWORKS

3. Server Continues to Send Data: The server can still send data to the
client. After it has finished processing the incoming data, it will send a FIN
segment to close the connection in the server-to-client direction.
4. Final Acknowledgment: The client acknowledges this final FIN with an
ACK segment, completing the half-close process.

After a half-close, the client can no longer send data to the server, but data can still
flow in the opposite direction.

This mechanism is useful in applications where the complete data transfer is


necessary before processing can begin, such as in sorting operations, where all data
must be received before any processing occurs.

TCP State Transition Diagram

TCP is modeled as a finite state machine (FSM) to track the various states during
connection establishment, data transfer, and termination.

This FSM consists of different states represented by rounded rectangles, with


transitions indicated by directed lines.

Each transition is labeled with two strings: the input (what TCP receives) and the
output (what TCP sends).

Page 45
BCS502 | COMPUTER NETWORKS

States and Transitions

Here's a breakdown of the main states in TCP along with the typical transitions:

1. CLOSED: The initial state. The connection does not exist.


2. LISTEN: The server is ready to accept connections but is not yet connected.
3. SYN-SENT: The client has sent a SYN segment to initiate a connection.
4. SYN-RCVD: The server has received a SYN segment and sent back a SYN +
ACK.
5. ESTABLISHED: A connection has been successfully established, allowing
bidirectional data transfer.

Page 46
BCS502 | COMPUTER NETWORKS

6. FIN-WAIT-1: The client has initiated a connection termination by sending a


FIN segment.
7. FIN-WAIT-2: The client has received an ACK for its FIN segment and is
waiting for a FIN from the server.
8. TIME-WAIT: The client waits for twice the maximum segment lifetime
(2MSL) after sending the last ACK to ensure the server receives it.
9. CLOSE-WAIT: The server has received a FIN segment and is waiting for a
close command from its application.
10. LAST-ACK: The server sends a FIN segment after receiving a passive close
command and is waiting for the last ACK from the client.

Page 47
BCS502 | COMPUTER NETWORKS

Page 48
BCS502 | COMPUTER NETWORKS

Scenarios

Let’s illustrate the TCP state transitions using a typical scenario where a client
establishes a connection with a server, transfers data, and then terminates the
connection.

Client Connection Establishment

1. Active Open: The client issues an active open command, sending a SYN
segment.
o State Transition: CLOSED → SYN-SENT
2. SYN + ACK Reception: The server responds with a SYN + ACK segment.
o State Transition: SYN-SENT → ESTABLISHED
3. ACK Sent: The client acknowledges the server's SYN + ACK by sending an
ACK.
o State Transition: ESTABLISHED (remains in this state for data
transfer)

Data Transfer

• Data is exchanged between the client and server while remaining in the
ESTABLISHED state. Acknowledgments are sent as data is transmitted.

Connection Termination (Client Side)

1. Active Close: When the client has no more data to send, it sends a FIN
segment.
o State Transition: ESTABLISHED → FIN-WAIT-1
2. ACK Reception: The client receives an ACK for its FIN segment.
o State Transition: FIN-WAIT-1 → FIN-WAIT-2
3. FIN Reception: The client receives a FIN segment from the server and
sends back an ACK.
o State Transition: FIN-WAIT-2 → TIME-WAIT

Page 49
BCS502 | COMPUTER NETWORKS

4. Timer Expiration: After waiting for 2MSL seconds, the client moves to the
CLOSED state.
o State Transition: TIME-WAIT → CLOSED

Connection Termination (Server Side)

1. Passive Open: The server remains in the LISTEN state until it receives a
SYN segment.
o State Transition: LISTEN → SYN-RCVD
2. ACK Reception: The server sends a SYN + ACK and waits for an ACK from
the client.
o State Transition: SYN-RCVD → ESTABLISHED
3. FIN Reception: Upon receiving the FIN from the client, the server sends an
ACK and transitions to the CLOSE-WAIT state.
o State Transition: ESTABLISHED → CLOSE-WAIT
4. Passive Close: The server receives a close command from its process and
sends a FIN segment.
o State Transition: CLOSE-WAIT → LAST-ACK
5. Final ACK Reception: The server receives the final ACK from the client and
transitions to the CLOSED state.
o State Transition: LAST-ACK → CLOSED

Page 50
BCS502 | COMPUTER NETWORKS

Page 51
BCS502 | COMPUTER NETWORKS

TCP Windows: Overview

In TCP (Transmission Control Protocol), windows play a critical role in controlling


data flow, managing how much data can be sent before requiring an
acknowledgment. This mechanism helps ensure efficient data transmission while
preventing overwhelming the receiver and managing network congestion. TCP uses
four windows in total: two for each direction of communication (send and receive).

Send Window

The send window determines how much data the sender can transmit without
waiting for an acknowledgment.

Characteristics of the Send Window:

1. Dynamic Size: The size of the send window can vary based on the receiver's
buffer capacity and network conditions (congestion control).

Page 52
BCS502 | COMPUTER NETWORKS

2. Window Management: The send window can open, close, or shrink based on
the sender's state and the receiver's ability to process incoming data. If the
receiver's buffer is full, the sender must reduce its send window accordingly.
3. Byte-Oriented: Unlike some other protocols (e.g., Selective Repeat), which use
packet-based windows, TCP's window size is measured in bytes. This means the
sender can send a continuous stream of data, optimizing bandwidth.

Example of Send Window:

• In a simplified scenario where the send window size is set to 100 bytes, the
sender can transmit 100 bytes of data before waiting for an acknowledgment.
If the sender receives an acknowledgment for the first segment, it can
continue to send more data within the constraints of the window size.

Receive Window

Page 53
BCS502 | COMPUTER NETWORKS

The receive window manages how much data the receiver can accept at any given
time. This is critical for flow control, ensuring that the sender does not overwhelm
the receiver with data it cannot process.

Characteristics of the Receive Window:

1. Variable Size: The receive window size can change dynamically based on the
receiver’s buffer status. It is calculated as:

This means the receiver must keep track of how much data has been received
but not yet processed.

2. Cumulative Acknowledgment: Unlike the Selective Repeat (SR) protocol,


which uses selective acknowledgments, TCP predominantly uses cumulative
acknowledgments. This means that the receiver acknowledges all bytes up to the
next expected byte, allowing the sender to understand what has been
successfully received.
3. Implementation Flexibility: In some TCP implementations, data may be
buffered at the receiver and sent later, allowing for efficient data management.

Example of Receive Window:

• If the receiver has a buffer size of 100 bytes and has already acknowledged
40 bytes, the current receive window would allow an additional 60 bytes to be
received: rwnd=100 (buffer size)−40 (acknowledged bytes)=60 bytes

Key Differences Between TCP Windows and Selective Repeat Protocol


Windows

1. Window Size Measurement:


o TCP: Size is measured in bytes, allowing for a continuous stream of data.

Page 54
BCS502 | COMPUTER NETWORKS

o SR: Size is measured in packets.


2. Acknowledge Mechanism:
o TCP: Uses cumulative acknowledgment (with options for selective
acknowledgment in newer versions).
o SR: Uses selective acknowledgment.
3. Data Handling:
o TCP: The sending TCP may send segments as soon as they are available.
o SR: Typically sends packets immediately without storing them for later.
4. Timer Management:
o TCP: Uses a single timer for managing retransmissions.
o SR: May use multiple timers, one for each packet sent.

Flow Control in TCP

Flow control is a crucial mechanism in TCP (Transmission Control Protocol) that


ensures the rate of data transmission between a sender (producer) and a receiver
(consumer) is balanced.

By managing how much data can be sent before receiving an acknowledgment, TCP
prevents overwhelming the receiver, maintaining efficient communication.

Page 55
BCS502 | COMPUTER NETWORKS

Concepts of Flow Control

1. Separation of Concerns: TCP separates flow control from error control. In this
context, we focus solely on flow control, assuming an error-free communication
channel.
2. Unidirectional vs. Bidirectional Communication: While we often discuss
flow control in unidirectional terms (data flowing from the sender to the
receiver), TCP operates in a bidirectional manner. However, understanding the
unidirectional flow simplifies the discussion.
3. Data Transfer Paths:
o Data flows from:
▪ Sender Process to Sending TCP (Path 1)
▪ Sending TCP to Receiving TCP (Path 2)
▪ Receiving TCP to Receiving Process (Path 3)
o Flow control feedback flows back from:
▪ Receiving TCP to Sending TCP (Path 4)
▪ Sending TCP to Sending Process (Path 5)

Most implementations do not provide flow control feedback from the receiving
application to the receiving TCP; instead, the receiving process pulls data
when it is ready.

4. Control of Data Flow: The sending TCP controls the sending process, while the
receiving TCP controls the sending TCP. This allows the receiving side to dictate
how much data the sender can transmit based on its ability to process incoming
data.

Opening and Closing Windows

The primary mechanism for flow control in TCP is the adjustment of window sizes.
Each TCP connection has a fixed buffer size determined during connection

Page 56
BCS502 | COMPUTER NETWORKS

establishment, but the effective window sizes can change as data is sent and
acknowledged.

Receive Window Management:

• Window Closure: The receive window closes (moves its left wall to the
right) when new bytes arrive, indicating the next expected byte.
• Window Opening: The receive window opens (moves its right wall to the
right) when the receiving process pulls data from the buffer. In practice, the
receive window should not shrink (the right wall does not move to the left).

Send Window Management:

• Window Closure: The send window closes when new acknowledgments


from the receiver allow it to do so (i.e., when the receiver indicates it can
accept more data).
• Window Opening: The send window opens when the advertised receive
window size (rwnd) allows it to do so.
• Window Shrinking: The send window shrinks if the conditions for opening
do not occur.

Flow Control Scenario

The following example illustrates how flow and window management work in a
simple unidirectional data transfer scenario from a client to a server.

1. Connection Establishment:
o SYN Segment: The client sends a SYN segment to the server,
indicating its initial sequence number (seqNo = 100). The server
allocates a buffer size (e.g., 800 bytes) and sets its receive window
size (rwnd = 800).

Page 57
BCS502 | COMPUTER NETWORKS

2. Acknowledgment from Server:


o The server responds with an ACK + SYN segment (ackNo = 101),
acknowledging the receipt of the SYN and indicating that it expects
bytes starting from 101. The server confirms a buffer size of 800 bytes.
3. Client Sends Data:
o After establishing the window size, the client pushes 200 bytes of data
(bytes 101 to 300) and sends a segment to the server.
o The client’s window reflects that 200 bytes are sent but waiting for
acknowledgment.

Page 58
BCS502 | COMPUTER NETWORKS

4. Server Acknowledges Data:


o The server acknowledges receipt of bytes 101 to 300 and advertises a
new receive window size (rwnd = 600). The client purges the
acknowledged bytes from its window.
5. Client Sends More Data:
o The client sends another segment containing 300 bytes (seqNo = 301).
The server stores the bytes, but its receive window is now reduced due
to processing.
6. Server Sends Acknowledgment:
o The server acknowledges the receipt of the 300 bytes and announces
its new receive window size (rwnd = 400). The client adjusts its
window accordingly.
7. Receive Window Adjustment:
o The server pulls 100 bytes of data, and its window closes from the left
by 300 bytes but opens from the right by 100 bytes, resulting in a
reduced window size of 400 bytes.
8. Final Window Adjustment:
o The server processes another 200 bytes and increases its window size
to 600. The client receives this update and adjusts its window size
accordingly.

Shrinking of Windows

In TCP flow control, while the receive window remains static (i.e., it cannot shrink),
the send window can shrink based on the receiver's feedback regarding its receive
window size (rwnd).

However, some implementations avoid allowing the send window to shrink to


prevent complications. The critical condition to prevent the shrinking of the send
window is: new ackNo+new rwnd≥last ackNo+last rwnd

Page 59
BCS502 | COMPUTER NETWORKS

This condition ensures that the right wall of the send window does not move to the
left, maintaining a consistent flow of data. This relationship must hold true as long
as the last sent and acknowledged bytes are less than the new acknowledged bytes.

Window Shutdown

TCP allows a receiver to temporarily shut down the window by advertising an rwnd
of 0. This indicates to the sender that it should stop sending data until the receiver is
ready to accept more.

Although the sender's window does not technically shrink, it effectively pauses data
transmission until the receiver can accommodate new data.

Notably, even when the window is set to 0, the sender is permitted to send a 1-byte
segment to probe the connection, ensuring that it does not lead to a deadlock.

Page 60
BCS502 | COMPUTER NETWORKS

Silly Window Syndrome

Silly Window Syndrome occurs when the sending or receiving application programs
process data too slowly, leading to the transmission of small segments, which can
significantly reduce network efficiency.

Sender-Generated Syndrome

When the sending application sends data in tiny increments (e.g., 1 byte at a time),
the TCP may create segments with minimal payload.

For example, if the sending TCP sends segments of 1 byte, the total overhead for
each segment (including TCP and IP headers) becomes disproportionately high.

To mitigate this, Nagle's algorithm can be employed:

1. The sender sends the first piece of data immediately.


2. After sending the first segment, it accumulates data until either an
acknowledgment is received or sufficient data has been gathered to fill a
maximum-sized segment.
3. This cycle repeats, balancing the speed of the application and the efficiency of
the network.

Receiver-Generated Syndrome

The receiving application can also cause a silly window syndrome if it consumes data
slowly.

For instance, if a receiving application processes data one byte at a time while the
sending application transmits larger blocks, the receiver may frequently advertise a
window size of 1 byte.

This leads to the sender sending segments of only 1 byte, exacerbating efficiency
problems.

Page 61
BCS502 | COMPUTER NETWORKS

Solutions to Receiver-Generated Syndrome:

1. Clark’s Solution: The receiver acknowledges received segments but only


announces a window size of zero until it can accommodate a full-sized segment
or at least half of its buffer is free.
2. Delayed Acknowledgment: The receiver waits before acknowledging a
segment, ensuring that the acknowledgment only occurs when there is sufficient
space in the buffer. This reduces the likelihood of small segment transmissions
while also minimizing network traffic.

TCP Error Control

TCP (Transmission Control Protocol) provides reliable communication by ensuring all


data is delivered to the application layer in the correct order, without any corruption,
loss, or duplication. TCP uses three primary mechanisms to maintain this reliability:

1. Checksum:
o Each TCP segment contains a mandatory 16-bit checksum to verify data
integrity.
o If a checksum is invalid, the segment is discarded by the receiver and treated
as lost.
2. Acknowledgment (ACK):
o TCP uses ACKs to confirm receipt of data segments. Control segments that
carry no data are also acknowledged.
o Different types of acknowledgments are used:
▪ Cumulative Acknowledgment (ACK): Acknowledges all bytes up to
the next expected byte. If segments are received out of order, they are
ignored until the expected segment arrives.
▪ Selective Acknowledgment (SACK): Provides additional feedback on
out-of-order or duplicated segments. SACK is optional and is
implemented as an option at the end of the TCP header.z

Page 62
BCS502 | COMPUTER NETWORKS

3. Timeout:
o If an acknowledgment is not received within a specified time, the segment is
retransmitted.

Generating Acknowledgments

Acknowledgments are generated based on specific rules:

1. Piggybacking: If the receiver has data to send back, it includes an ACK with the
next expected sequence number.
2. Delayed ACK: If there’s only one in-order segment with no more data to send,
the receiver delays sending an ACK to reduce network traffic.
3. Immediate ACK: If the received segment is in order, and there are
unacknowledged segments, the receiver sends an ACK immediately.
4. Out-of-order ACK: If a segment arrives with an out-of-order sequence number,
an ACK is sent for the next expected sequence.
5. Handling Missing and Duplicate Segments: When a missing or duplicate
segment arrives, the receiver sends an ACK to confirm the next expected in-order
segment.

Retransmission Mechanisms

Retransmission ensures reliability if segments are lost or delayed:

1. Retransmission After RTO:


o TCP maintains a dynamic retransmission timeout (RTO) for each connection.
If the timer expires without an ACK, the segment with the smallest sequence
number is retransmitted.
o The RTO value is adjusted based on the round-trip time (RTT).
2. Fast Retransmission (Three Duplicate ACKs):
o If the sender receives three duplicate ACKs for a specific segment, TCP
immediately retransmits the missing segment, skipping the timeout. This

Page 63
BCS502 | COMPUTER NETWORKS

technique, known as "fast retransmission," reduces delays caused by waiting


for the timer to expire.

Handling Out-of-Order Segments

• TCP stores out-of-order segments temporarily and flags them until the
missing segments arrive. Only when the missing data arrives does TCP deliver
data in order to the application layer, ensuring ordered delivery.

FSM (Finite State Machines) for Data Transfer in TCP

Sender-Side FSM

• The sender-side FSM for TCP, similar to Selective Repeat (SR) protocol but
adjusted for TCP’s requirements, operates with:
o Fast Retransmission: Resending segments after three duplicate
ACKs.
o Window Size Adjustment: The window size is dynamically adjusted
based on the receiver’s available window (rwnd).

Page 64
BCS502 | COMPUTER NETWORKS

Receiver-Side FSM

• The receiver-side FSM for TCP is similar to SR but includes TCP-specific


differences:
o ACK Delaying: ACKs may be delayed in certain situations in
unidirectional communication.
o Duplicate ACKs: These are sent to trigger fast retransmission by the
sender when out-of-order segments are received.

TCP and Protocol Comparisons

• TCP’s cumulative ACK and out-of-order segment handling are close to SR, but
with cumulative acknowledgments, TCP can also resemble Go-Back-N (GBN).
• When SACK is used, TCP behaves more like the SR protocol.

Page 65
BCS502 | COMPUTER NETWORKS

Some Scenarios

In TCP error control, different scenarios illustrate how the protocol handles various
transmission issues. Each TCP segment is visually represented as a rectangle in
these scenarios, with specific details:

• Data Segment: If a segment carries data, it is labeled with the range of


byte numbers it contains, along with the acknowledgment (ACK) field showing
the expected next byte.
• ACK-only Segment: If a segment only serves as an acknowledgment, it
appears in a smaller rectangle with just the acknowledgment number
displayed.

By studying these scenarios, we can see TCP’s reliability mechanisms in action,


including how it manages lost segments, retransmissions, and cumulative
acknowledgments to ensure smooth data delivery across the network.

Normal Operation

Page 66
BCS502 | COMPUTER NETWORKS

• In a bidirectional data transfer, data segments are acknowledged according to


specific rules.
• Example: When a client and server exchange data, the server includes ACKs with
data segments if it has data to send (rule 1).
• If the client only needs to acknowledge without sending data, it delays the ACK
for 500 ms (rule 2) unless more data arrives in the meantime.
• Immediate ACKs are triggered by out-of-order arrivals to minimize unnecessary
retransmissions.

Lost Segment

• When a segment is lost in transit, possibly due to network congestion, it is


either dropped by a router or discarded due to corruption.
• Example: The receiver notices the gap and requests the next expected byte,
storing any subsequent segments in a buffer until the missing segment
arrives. The sender resends the lost segment after the retransmission timer
expires, and it’s acknowledged upon receipt (rule 5).

Page 67
BCS502 | COMPUTER NETWORKS

Fast Retransmission

• Used when RTO (Retransmission Timeout) values are high to avoid


unnecessary delays. This feature is triggered by receiving multiple duplicate
ACKs indicating a missing segment.
• Example: If the sender receives three duplicate ACKs, it immediately
retransmits the missing segment before the RTO timer expires. The timer
then restarts, reducing delay in data recovery.

Delayed Segment

• Due to IP’s connectionless nature, segments might reach the destination with
varied delays, sometimes resulting in timeouts and retransmissions.
• Example: If a segment arrives late after being retransmitted, it’s treated as a
duplicate and discarded by the receiver.

Page 68
BCS502 | COMPUTER NETWORKS

Duplicate Segment

• Duplicate segments can occur if a delayed segment triggers a retransmission


from the sender.
• Example: When the receiver gets a duplicate segment with an already
received sequence number, it discards it and sends an ACK for the next
expected byte, ensuring continuity without delivering the same data twice.

Automatically Corrected Lost ACK

Page 69
BCS502 | COMPUTER NETWORKS

• TCP’s cumulative acknowledgment mechanism automatically handles lost


ACKs by covering multiple segments with one cumulative ACK.
• Example: If an ACK is lost, the next ACK covers it, acknowledging all
segments received up to that point.
• If the next ACK is delayed too long or doesn’t arrive (e.g., if it’s the last ACK),
the RTO timer triggers a retransmission.

Deadlock Due to Lost ACK (Zero Window Deadlock)

• A deadlock can occur if an acknowledgment carrying a nonzero window size


(rwnd) is lost, especially after a window shut-down request.
• Example: The sender stops sending data when rwnd is zero, waiting for a
signal to resume.
• If the receiver updates rwnd but the ACK with a nonzero window is lost, both
ends may enter a deadlock.
• A persistence timer helps prevent this by retransmitting to clear the deadlock
after a delay.

TCP Congestion Control

TCP congestion control involves various policies to manage data flow in the network
efficiently, adapting to congestion levels dynamically.

Congestion Window (cwnd)

• The congestion window (cwnd) is a TCP sender-controlled variable that limits


the amount of data that can be sent in the network to prevent intermediate
routers from becoming congested.
• The actual window size for sending is the minimum of cwnd and the receiver
window (rwnd), ensuring that TCP avoids overwhelming both the receiving
end and the network in the middle.

Page 70
BCS502 | COMPUTER NETWORKS

Congestion Detection

• TCP detects congestion using two signals:


o Timeouts: If an ACK is not received before a timeout, TCP assumes
network congestion.
o Three Duplicate ACKs: Receipt of three duplicate ACKs (four ACKs
with the same acknowledgment number) signals a lost segment due to
possible mild congestion.

Congestion Control Algorithms

• TCP’s congestion control involves three main algorithms: Slow Start,


Congestion Avoidance, and Fast Recovery.

Slow Start (Exponential Increase)

• Starts with cwnd = 1 Maximum Segment Size (MSS).

Page 71
BCS502 | COMPUTER NETWORKS

• For every ACK received, cwnd doubles, leading to exponential growth until a
threshold (thresh) is reached.
• This aggressive growth quickly increases data flow but transitions to
congestion avoidance upon reaching the thresh.

Congestion Avoidance (Additive Increase)

• To prevent congestion, growth slows to an additive increase (1 MSS per


round-trip time).
• If cwnd reaches thresh or congestion is detected, growth becomes linear,
increasing by one MSS for each ACK after the entire window is acknowledged.

Page 72
BCS502 | COMPUTER NETWORKS

Fast Recovery

• Initiated after receiving three duplicate ACKs (suggesting mild congestion).


• Instead of restarting from a cwnd of 1 (as in Slow Start), TCP incrementally
increases cwnd to continue sending data, helping reduce the transmission
gap.

Policy Transitions

• Taho TCP: Utilizes only Slow Start and Congestion Avoidance. If congestion is
detected (timeout or duplicate ACKs), sthresh is halved, and cwnd resets to 1.
• Reno TCP: Adds Fast Recovery, treating timeout as severe congestion but
treating duplicate ACKs as mild congestion.
• New Reno TCP: Optimizes Fast Recovery further, especially when multiple
segments are lost in a single window.

These mechanisms enable TCP to balance network utilization and congestion control,
optimizing data transfer while avoiding overloading network routers and links.

Page 73
BCS502 | COMPUTER NETWORKS

Congestion Control Mechanisms in TCP

Slow Start (SS):

o The congestion window (cwnd) begins at a small size (usually 1 MSS).


o It grows exponentially by one MSS for each received ACK until it hits a
predefined threshold (ssthresh), indicating a more cautious congestion
avoidance phase is needed.

Congestion Avoidance (CA):

o Once the cwnd reaches ssthresh, it grows linearly rather than


exponentially.
o For each round-trip time (RTT), cwnd increases additively to avoid
overloading the network.

Fast Recovery (FR):

o When three duplicate ACKs are received (indicating light congestion),


cwnd is reduced but starts from a higher point, just below the previous
value (in Reno and NewReno TCP). This state enables faster recovery
compared to restarting from a single MSS.

TCP Versions and Their FSM (Finite State Machines)

Taho TCP

• Slow Start and Congestion Avoidance Only:


o The ssthresh is set to a high initial value.
o When a timeout or three duplicate ACKs occur, Taho TCP cuts cwnd by
half, resets cwnd to 1 MSS, and re-enters Slow Start.

Page 74
BCS502 | COMPUTER NETWORKS

Example 24.9 (Taho TCP)

• TCP starts with a ssthresh of 16 MSS, and cwnd at 1 MSS.


• After three RTTs, congestion occurs, ssthresh is halved to 4 MSS, and cwnd is
reset to 1 MSS, restarting Slow Start.
• It transitions to Congestion Avoidance at 4 MSS, then experiences another
congestion event (duplicate ACKs) at 12 MSS.
• The process repeats, halving ssthresh and resetting cwnd.

Reno TCP

Adds Fast Recovery:

o Treats timeouts and duplicate ACKs differently.

Page 75
BCS502 | COMPUTER NETWORKS

o Upon receiving three duplicate ACKs, Reno TCP enters Fast Recovery,
maintaining cwnd higher than in Taho, at ssthresh + 3 MSS. This prevents
starting from 1 MSS and enables faster recovery.

Example 24.10 (Reno TCP)

• Similar to Example 24.9, but at RTT 13, when three duplicate ACKs arrive:
o ssthresh is set to 6 MSS, cwnd to ssthresh + 3 = 9 MSS, and Fast
Recovery begins.
o After two more duplicate ACKs, the arrival of a non-duplicate ACK moves
Reno TCP to Congestion Avoidance, and cwnd is reduced to 6 MSS.

NewReno TCP

Enhanced Fast Recovery:

Page 76
BCS502 | COMPUTER NETWORKS

o Checks for additional lost segments beyond the first duplicate ACK trigger.
o If multiple segments are lost, NewReno continues retransmissions until all
lost segments are acknowledged, preventing excessive duplicate ACKs.

Additive Increase, Multiplicative Decrease (AIMD)

• This describes the pattern for cwnd:


o Additive Increase: cwnd = cwnd + (1 / cwnd) for each ACK received.
o Multiplicative Decrease: When congestion is detected, cwnd is halved,
resulting in the sawtooth pattern in cwnd changes over time.

Page 77
BCS502 | COMPUTER NETWORKS

TCP Throughput Calculation

Page 78

You might also like