0% found this document useful (0 votes)
8 views59 pages

Transport Layer Protocols Explained

Uploaded by

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

Transport Layer Protocols Explained

Uploaded by

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

Computer Networks

Lecture 03- Transport Layer Protocols


Salma Abdelmonem
With adoptions from Kurose JF, Ross KW. Computer
networking: A top-down approach. Harlow, England Boston:
Pearson; 2019. (8th edition).
Table of contents 01 Introduction

02 UDP

03 TCP
Transport Layer

Layer Function Example

5 Application HTTP, FTP, SMTP, and all


others
4 Transport TCP, UDP – reliability &
flow
3 Network IP, routing

2 Data Link MAC addressing, framing

1 Physical Cables, signals, voltage


levels
Transport Layer

• Provides, from the application


layer’s perspective, a logical end-
to-end communication between
processes as if they are directly
connected.
• Unit of transmission: Transport
Layer Segment.
• A segment is constructed by
breaking the application messages
into smaller chunks and adding a
transport-layer header.
This Photo by Unknown Author is licensed under CC BY-NC
Transport Layer Protocols

Before we start with the transport layer protocols:


• The network layer protocols (IPv4/6) operate on a
best-effort basis, meaning there is no guarantee for
the delivery, order, or integrity of packets.
• The minimal services required by transport layer
protocols are to provide process-to-process data
delivery (ports) and error checking.
Transport Layer Protocols

• UDP is an unreliable service; it does not guarantee that


data sent by one process will arrive intact, or arrive at
all. ( It is like sending a postcard, no notification if it
arrived, lost, or damaged.)
• TCP is a reliable, connection-oriented protocol that
ensures data is delivered accurately and in order. (It’s
like making a phone call, both parties confirm the
connection, and every word is heard in sequence.)
Sockets

• A socket is like a doorway between the transport layer


and an application process.
• It allows data to flow in and out of a specific program
(e.g., browser, FTP client).
• It’s not a physical thing; it’s a software structure
created by the operating system.
Client-Side Sockets

• When an application wants to send data (like loading a


webpage), it asks the OS to create a socket.
• The OS assigns:
• A source IP address
• A source port number, usually, a random high number from 1024 to
65535, as 0–1023 are well-known port numbers (e.g., HTTP = 80, FTP =
21).
• This socket is used to send and receive data for that session.
• Then, the socket is closed.
Server-Side Sockets

• The server creates sockets in advance and binds them to


well-known port numbers (like 80 for HTTP).
• It listens for incoming connections.
• When a client connects, the server creates a new socket for
that specific connection.
• This is done for privacy and scalability, allowing states to
keep data for each client’s session and process sessions in
parallel.
Socket Multiplexing

At the sender side:


• Multiple applications (e.g., browser, FTP client, Telnet) send data.
• The transport layer collects data from each socket, adds header
info (like port numbers), and sends it to the network layer.
• This is multiplexing: combining multiple data streams into one.
• Analogy: Like Ann collecting letters from siblings and handing
them to the mail carrier.
Socket Demultiplexing

At the receiver side:


• The transport layer receives segments from the network
layer.
• It reads the destination port number in each segment.
• Then it routes the data to the correct socket, which
connects to the right application.
• Analogy: Like Bill sorting incoming mail and delivering each
letter to the correct sibling.
Multiplexing & Demultiplexing in the
Transport Layer
User Datagram Protocol
(UDP)
User Datagram Protocol (UDP)

UDP does not:


• Establish a connection before sending data.
• Retransmit lost packets.
• Reorder out-of-sequence packets.
• Confirm delivery.
UDP is fast and lightweight, which makes it perfect for:
• Live video/audio streaming.
• Online gaming.
• DNS lookups.
User Datagram Protocol (UDP)

• UDP provides a
connectionless service.
• The user datagrams travel on
a different path on the way to
the destination.
• The damaged segments are
discarded or provided to the
application layer with a
warning.
[Link]
UDP sockets communication

[Link]
by-creating-both-server-and-client-machine-7026ddca1913
UDP sockets communication

• UDP is Like
sending and
receiving postcards.
Each message must
include the
recipient's address,
and you might get
messages from
different people.
User Datagram Protocol (UDP)

The UDP segment contains:


• 8-byte header equally split into:
• Source port.
• Destination port.
• Length (header + data)
• Checksum [1’s complement of the sum
of all the 16-bit words in the segment]
• Data.
• No sequence numbers, no
acknowledgments.
Transmission Control
Protocol (TCP)
Transmission Control Protocol (TCP)

• Converts IP’s unreliable


delivery into reliable,
ordered data transfer.
• A connection-oriented
network that establishes a
logical path between the
source and destination.
[Link]
TCP sockets communication

[Link]
TCP sockets communication

• TCP is Like a phone


call. Once
connected, you just
talk and listen, no
need to specify who
you're talking to
each time.
Transmission Control Protocol (TCP)

Features:
1. Reliable Data Transfer (Ensures all
data arrives correctly and in order)
2. Flow Control (Reorder,
Retransmission, Prevents sender
from overwhelming receiver)
3. Congestion Control (Adjusts
sending rate based on network
load)
[Link]
TCP segment structure

• Header length: This 4-bit field


indicates the number of 4-byte
words in the TCP header.
• The length of the header can be
between 20 and 60 bytes.
• Window Size: tells the sender
how much data the receiver is
willing to accept. It’s crucial for
flow control and avoiding buffer
overflow

[Link]
TCP segment structure

• Control flags: 6 different


control bits or flags.
• URG: Urgent pointer
• ACK: Acknowledgment
• PSH: Push function: deliver data
to the application immediately.
• RST: Reset the connection.
• SYN: Synchronize sequence
numbers
• FIN: Finish the connection.

[Link]
1- Reliable Data Transfer

Sequence numbers (32-bit):


• TCP chooses an arbitrary number between 0 and
232 − 1 for the number of the first byte (initial
sequence number ISN).
• The next segment’s SN = previous SN + previous
segment’s length in bytes.
1- Reliable Data Transfer

Acknowledgment numbers
(32-bit):
• For a received segment
with SN, provide an ACK
number = the next
expected SN.

[Link]
2- Flow Control

• Sliding window protocols: using transmission and receiving


windows.
• If a segment arrives out of order, TCP holds it until the missing
segments arrive.
• Implements cumulative acknowledgments.
• TCP retransmits only the missing segment.
• Use this simulation to visualize it: [Link]
window-simulator/[Link]
2- Flow Control

• There are two windows:


one at the sender, which
sends data and waits for
acknowledgments, and
the other at the receiver,
which waits for data and
sends acknowledgments.
[Link]
wdabm6QhnnPnsz3IO
2- Flow Control

• The window is not


shifted to the right
unless the left-most
backet/ack inside it is
received.

[Link]
2- Flow Control

• If multiple correct data


frames are received,
we can send one
cumulative ack (for
the last one)
indicating the correct
reception of them all.

OIP.mu20TQ49M7ai9ji9KVLYFwHaFj
(474×355)
2- Flow Control

• If a segment is
damaged or lost, we
keep silent.
• Then, for any out of
order received packet,
we send the next
expected ack .
[Link]
eW00ADSVekF4C2VXn
2- Flow Control

• For each segment sent:


• Start timer and wait for acknowledgment
• Retransmit if timer expires
• TCP uses an adaptive retransmission algorithm because
internet delays are so variable
• Round trip time of each connection is recomputed every
time an acknowledgment arrives.
• Timeout value is adjusted accordingly.
2- Flow Control

• How should the most recent round trip sample (RTS) effect the
round trip time (RTT)?
New RTT = (a * RTT) + ((1-a) * RTS)
• a=0
• a=1
• TCP should not update the RTT for retransmitted segments
• How should RTT be used to compute timeout?
Timeout = b * RTT
• b=1
• b>1
2- Flow Control – most important rules

1. If a segment is damaged and discarded, the receiver does


not send an ACK for it; instead, it relies on a timeout from the
sender.
2. If a segment is lost, the receiver won’t acknowledge it;
instead, it sends duplicate ACKs for the last successfully
received segment.
3. When the sender receives three duplicate ACKs, it assumes a
segment is missing. It retransmits the lost segment
immediately, without waiting for a timeout.
2- Flow Control – most important rules

4. Receiver Advertises Window: The receiver monitors its buffer


space and advertises its window size to the sender,
indicating how much data it can accept.
5. Sender Respects Window: The sender complies with the
advertised window size, ensuring it does not send more data
than the receiver can handle.
6. Data Transmission: The sender transmits packets within the
limits of the advertised window. Data is segmented and
acknowledged by the receiver upon successful reception.
2- Flow Control – most important rules

7. Window Updates: As the receiver processes data and frees up


buffer space, it sends window update notifications to inform the
sender of the new capacity.
8. Zero Window Condition: If the receiver’s buffer is full, it advertises
a window size of zero, halting the sender’s data transmission until
an updated window size is provided.
9. Persistence Timer: To prevent deadlock ( window update gets lost)
during a zero-window condition, the sender activates a persistence
timer, sending periodic probes to prompt the receiver for an
updated window size.
Persistence Timer

1. Receiver advertises Window = 0


2. Sender sets a persistence timer
3. When the timer expires, the sender sends a 1-byte probe segment.
This segment has no new data, just a valid sequence number.
4. The receiver responds with an ACK and updated window size (if
buffer space is available).
5. If the window is still zero, the sender restarts the timer and tries
again later.
• This keeps the connection alive and avoids indefinite waiting
3- Congestion Control

• Endpoints cannot know the details of where in the


internet congestion has occurred or why.
• Congestion will usually lengthen delays.
• TCP’s response to lengthened delays (by retransmission)
can cause congestion collapse.
• Instead, TCP must reduce transmission rates when
congestion occurs.
3- Congestion Control

So, to stop the network from becoming overwhelmed with too


much data, which can cause delays and packet loss.
1. The sender maintains a separate congestion window
(CWND), which limits the amount of unacknowledged data it
can send into the network.
2. Starts small and increases gradually with acknowledgments.
3. The sender infers congestion from packet loss and reduces
the CWND accordingly.
3- Congestion Control

• Augment the TCP transmission window with a


congestion window:
Window=min(receiver advertisement, congestion window)
• Upon loss of a segment reduce the congestion window by
half (down to a minimum of one segment)
• Upon receiving acks grow the congestion window
exponentially (doubles).
Let’s practice TCP rules

• File Transfer from Server to client


• Server wants to send a large file to Client over TCP.
• Max Segment Size = 1000 bytes, initial advertised
window = 4000 bytes.
• Segments:
S1, S2, S3, S4, S5, S6…
Let’s practice TCP rules

• Server sends:
• S1 (Seq=1000), S2 (Seq=2000), S3 (Seq=3000), S4
(Seq=4000)
• Client receives all almost at the same time and sends:
• ACK=5000 (acknowledging up to S4)
Let’s practice TCP rules

• S5 (Seq=5000) arrives but is corrupted (checksum fails).


• Client:
discards it silently.
• Server:
• waits… no ACK…
• If no more data is sent:
• timeout triggers retransmission of S5.
Let’s practice TCP rules

• S6 (Seq=6000) is lost in transit.


• Client receives S7 (Seq=7000), but since S6 is
missing, it sends:
• ACK=6000
• Then again for S8, S9… → Client sends
• Duplicate ACKs for 6000
Let’s practice TCP rules

• Server receives 3 duplicate ACKs for 6000 , it


• immediately retransmits S6.
Let’s practice TCP rules

• Client’s buffer fills up. It sends:


• ACK=10000, Window=0
Let’s practice TCP rules

• Server starts a persistence timer. After interval, it sends a


probe:
• 1-byte segment with Seq=10000
• Client has freed up two segments slots and responds:
• ACK=10001, Window=2000
• Server can send segments
• S10,S11
Let’s practice TCP rules

• If the client receiver’s window (rwnd) = 4000 bytes.


• But the cpngestion window is cwnd = 1 MSS (slow start).
• Then the server would send …
• 1 segment only
• After ack is received
• The cwnd is increased to two (doubled) and server would
send up to 2 segments.
TCP- Start Connection Steps

1. The client initiates the


connection by sending a segment
with the SYN flag set + ISN.
2. The server responds with a
segment that has both SYN and
ACK flags set = ISN+1.
3. The client sends a final segment
with the ACK flag set = server
ISN+1.
4. Connection is now established,
and data transfer can begin.
[Link]
TCP- End Connection Steps
• Applications should close a connection when they have no more
data to transmit
• Connection can be closed in either one or both directions
• Site 1 finishes transmitting data and waits for ACK from site 2
• Site 1 transmits a segment with the FIN bit set
• Site 2 acknowledges the FIN segment
• Site 2 notifies the application that no more data is coming
• Data can still be transmitted from site 2 to site 1
• Site 1 will still receive and acknowledge data from site 2
• Eventually, site 2 will finish transmitting and close its connection
• Both endpoints delete record of the connection
TCP- End Connection Steps
Site 1 Network Site 2
(app closes connection)
Send FIN
seq=x
Receive FIN
Send ACK x+1
(inform application)
Receive ACK

(app closes connection)


Send FIN seq=y

Receive FIN &


Send ACK y+1
Receive ACK
TCP Connection Reset
• Applications normally close connections
• Sometimes abnormal conditions arise that break a
connection
• Broken connections can be reset:
• Site 1 sends a segment with the RST bit set
• Site 2 receives segment and aborts the connection
• Transfers in both directions cease immediately
• Resources for the connection are released
• Applications programs are informed
TCP Connection Reset
• Use Cases:
• Rejecting invalid or unexpected connections: If a server
receives a packet for a closed port, it sends a TCP RST.
• Forcefully closing a broken or malicious connection: For
example, if a client sends malformed data or violates protocol
rules.
• Recovering from desynchronization: If sequence numbers are
off or the connection state is corrupted.
• Technical Note:
• RST doesn’t wait for FIN/ACK. It’s immediate and final.
• Often used in firewalls or intrusion detection systems to block
traffic
TCP Urgent Data

• TCP provides a mechanism to handle urgent data when you need to notify
the receiver of an urgent event without waiting for normal stream
processing.
• Like in telnet-style applications when sending an interrupt signal (like
Ctrl+C) to abort a command.
• Upon receiving it , the OS passes the urgent data to the application via
special APIs
• Sender:
• Sets urgent bit in segment header
• Puts urgent data at the beginning of the data field
• Sets urgent pointer to the end of the urgent data
TCP PSH

• The TCP PSH (Push) flag is set by the sender to tell the receiver:
“Deliver this data to the application immediately, don’t wait to
fill the buffer.”
• Examples:
• Small or complete messages: Often set when sending short messages (e.g., chat,
HTTP request) that should be processed immediately.
• End of stream or logical unit: If the sender finishes a logical unit of data (like a
full command or line), it may set PSH to flush it through.

• Different from URG: PSH is about timely delivery to the


application, not priority or interruption.
TCP Summary

• Connection-oriented: establishes a reliable link before data


transfer.
• Ensures ordered, error-free, and complete delivery.
• Uses a three-way handshake to initiate communication.
• Stream-based: treats data as a continuous byte stream.
• Includes flow control.
• Suitable for applications needing reliability (e.g., web, email, file
transfer)
UDP Summary

• Connectionless: sends data without setup or confirmation.


• No guarantee of delivery, order, or integrity.
• Message-based: each datagram is independent.
• Lightweight and fast, with minimal overhead.
• No flow control.
• Ideal for time-sensitive apps (e.g., video streaming,
gaming, DNS).
TCP sockets vs. UDP sockets

Feature TCP UDP


Connection Requires a connection Connectionless; no connect()
(via connect() needed
Transmit send() and recv() sendto() and recvfrom()
data
through
Destination Implicit (set during Explicit (passed in each sendto()
Info connect()) call)
Sent data Stream of bytes Message-based (each datagram is
type discrete)
Rec. return Bytes sent/received Bytes sent/received +
values sender/receiver address
Reliability Reliable, ordered, error- Unreliable, unordered, no
checked retransmission

You might also like