Module 6
Transport layer
Contents
•Transport layer services
•The Internet Transport Protocol: User Datagram Protocol (UDP)
•The Internet Transport Protocol: Transmission Control Protocol (TCP)
• Introduction to TCP
• TCP Service Model
• TCP Protocol
• TCP Segment Header
• TCP Connection Establishment
• Transactional TCP (Data transfer)
• TCP Connection Release
• Flow control
• Modeling TCP Connection Management
• TCP timer management
• TCP Congestion Control
Transport layer services
• Transport layer is located between the network layer and the application layer & is
responsible for providing services to the application layer by taking the services
from the network layer
• The primary duty of a transport-layer protocol is to provide process-to-process
communication
• Network layer is responsible for communication at the computer level
(host-to-host communication)
• A network layer protocol can deliver the message only to the destination computer
• However, this is an incomplete delivery
• The message still needs to be handed to the correct process
• This is where a transport layer protocol takes over
• A transport layer protocol is responsible for delivery of the message to the appropriate
process
Transport layer services (Contd..)
• The most common way of seeing process-to-process communication is through
the client-server paradigm
• A process on the local host, called a client, needs services from a process usually
on the remote host, called a server
• Operating systems today support both multiuser and multiprogramming
environments
• A remote computer can run several server programs at the same time, just as several local
computers can run one or more client programs at the same time
• The local host and the remote host are defined using IP addresses
• To define the processes, we need second identifiers called port numbers
• In the TCP/IP protocol suite, the port numbers are integers between 0 and 65,535
Types of port numbers
Sr. No. Type Range Description
1. Well-known 0-1023 1. These are assigned and controlled by Internet Corporation for
ports Assigned Names and Numbers (ICANN)
2. These are universally accepted port numbers normally assigned to
servers
2. Registered ports 1024-49151 1. These are not assigned or controlled by ICANN
2. However, these can only be registered with ICANN to prevent
duplication
3. These are also called as ephemeral port number
3. Dynamic ports 49152-65535 1. These are neither controlled nor registered
2. They can be used as temporary or private port numbers
• A transport-layer protocol in the TCP suite needs both the IP address and the port number, at each end,
to make a connection
• The combination of an IP address and a port number is called a socket address
• The client socket address defines the client process uniquely just as the server socket address defines
the server process uniquely
• To use the services of transport layer on the Internet, we need a pair of socket addresses: the client
socket address and the server socket address
• These four pieces of information are part of the network-layer packet header and the transport-layer
packet header [Link]
Transport layer protocols
•User Datagram Protocol
•Transmission Control Protocol
User Datagram Protocol (UDP)
• UDP, a connectionless protocol, is located between application layer and IP layer
• Responsibilities of UDP:
• Creating process-to-process communication
• UDP uses port numbers to ensure this
• Doesn’t ensure flow control but ensures error control to some extent
• If UDP detects an error, it silently drops the packet
• Enables communication with minimum no. of overheads
• If a process wants to send a small message and does not care about reliability, it can use UDP
• Sending a message using UDP takes much less interaction between the sender and receiver than using TCP
• Connectionless services
• Each user datagram is an independent datagram
• There is no relationship between the different user datagrams even if they are coming from the same
source process and going to the same destination program
• There is no connection establishment and connection termination
• Each datagram can travel on a different path
• Congestion control
• UDP does not provide congestion control
• It assumes that packets sent are small and sporadic and cannot create congestion in the network
User Datagram Protocol: Header format
• UDP packets are also called as
user datagrams
• A UDP packet has a fixed-size
header of 8 bytes
User Datagram Protocol:
Source port number
Header format
Destination port number
• This port number is used by the process running on the • This port number is used by the process running on the
source host destination host
• It is 16 bits long • It is also 16 bits long
• The port number can range from 0 to 65,535 • If the destination host is a server (a client sending a
• If the source host is a client (a client sending a request), request), the port number is typically a well-known port
the port number is typically an ephemeral(temporary) number
port number requested by the process • If the destination host is a client (a server sending a
• If the source host is a server (a server sending a response), the port number is typically an ephemeral port
response), the port number is typically a well-known number
port number • Here, the server copies the ephemeral port number it has
received in the request packet
Total length Checksum
• It defines the total length of the user datagram: header + • Checksum helps detect errors over the entire user datagrams
data • Checksum includes three sections: a pseudoheader, UDP header
• The length field in a UDP user datagram is not and the data coming from the application layer
necessary • Pseudoheader is a part of the IP header
• There is already a field in the IP datagram that defines
the total length
• There is another field in the IP datagram that defines the
length of the header
• So UDP length can be obtained as follows,
User Datagram Protocol:
Header format
• Important points to remember:
• The protocol field is added to ensure that the
packet belongs to UDP and not TCP
• The value of protocol field for UDP is 17
• If this value changes during transmission,
the checksum calculation at the receiver
will detect it and UDP drops the packet.
It will not be delivered to the wrong
protocol
• The sender of a UDP packet can choose to not
calculate the checksum
• In that case, the value sent for the
checksum field is all 0s to show that the
checksum is not calculated
• In situations that the sender decides to
calculate the checksum, but it happens that the
result is all 0s, the checksum is changed to all
1s before the packet is sent
• i.e. the sender compliments the sum two
times
Transmission Control Protocol (TCP): Service model
• TCP, unlike UDP is a stream-oriented protocol
• In UDP, a process sends messages wherein UDP adds its own header to each of its messages
forming a user datagram
• TCP allows the sending process to deliver data as a stream of bytes and allows the receiving
process to obtain data as a stream of bytes
• TCP creates an environment in which the two processes seem to be connected by an imaginary tube that
carries their bytes across the internet
• The sending process produces the stream of bytes while the receiving process consumes it
• Because the sending and receiving processes may not necessarily write or read data at the same
rate, TCP uses buffers for storage
• Buffering helps handle the disparity between the speed of the producing and consuming
processes
• The sending buffer comprises of empty chambers, bytes sent but not acknowledged and bytes to be
sent
• The receiving buffer comprises of only empty chambers to be filled and received bytes that can be read
• At the transport layer, TCP groups a number of bytes together to form a segment which the
TCP delivers to IP for transmission
• Segments may be received out of order, lost, corrupted and accordingly resent
• All of these are handled by the TCP sender with the receiving application process unaware of TCP’s
Transmission Control Protocol (TCP): Service model
Properties of reliable stream delivery: TCP Protocol
• TCP provides reliability using error control
• Error control includes mechanisms for:
• Detecting and resending corrupted segments
• Resending lost segments
• Storing out-of-order segments until missing segments arrive
• Detecting and discarding duplicated segments
• Properties of achieving reliable stream delivery:
• Through checksum
• Through acknowledgement
• Through retransmission
Transmission Control Protocol: Header format
• A TCP packet is called as a segment
• A segment consists of a header of 20 to 60 bytes
followed by data from the application program
Transmission Control Protocol: Header format
• Sequence number: This 32-bit field defines the number assigned to the first byte
of data contained in this segment. The sequence number tells the destination
which byte in this sequence is the first byte in the segment
• Acknowledgement number: This 32-bit field defines the byte number that the
receiver of the segment is expecting to receive from the other party
• Flags: The flag bits enable flow control, connection establishment and
termination, connection abortion, and the mode of data transfer in TCP
• Window size: This field defines the window size of the sending TCP in bytes.
Note that the length of this field is 16 bits, which means that the maximum size of
the window is 65,535 bytes. This value is normally referred to as the receiving
window (rwnd) and is determined by the receiver.
• Urgent pointer. This 16-bit field, which is valid only if the urgent flag is set, is
used when the segment contains urgent data. It defines a value that must be
added to the sequence number to obtain the number of the last urgent byte in
the data section of the segment.
Transmission
Control Protocol:
Header format
• TCP uses a 16-bit checksum
that is mandatory in every
segment for which
pseudoheader details are used
• The value of protocol field for
TCP is 6
TCP: Connections
• TCP is a connection-oriented protocol
• It establishes a virtual path between the source and destination
• Using a single virtual path for the entire message, TCP facilitates the acknowledgement
process as well as retransmission of damaged or lost frames
• A TCP connection is virtual not physical
• TCP uses the services of IP to deliver individual segments to the receiver, but it
controls the connection itself
• If a segment is lost or corrupted, it is retransmitted
• IP is unaware of retransmission
• If a segment arrives out of order, TCP holds it until the missing segments arrive
• IP is unaware of reordering
TCP Connection Establishment
• TCP transmits data in full-duplex mode wherein the connection establishment in
TCP is called three-way handshaking
• Steps involved:
• The process starts with the server
• The server program tells its TCP that it is ready to accept a connection
• This request is called passive open
• Although the server TCP is ready to accept a connection from any machine in the world, it cannot make
the connection itself
• The client program issues a request for an active open
• A client that wishes to connect to open server tells its TCP to connect to a particular server
• TCP can now start the three-way handshaking
[Link] sends SYN (synchronize) request to server.
Three-way handshaking [Link] sends ACK back.
This is the actual "3-way handshake".
[Link] replies with SYN-ACK (acknowledge).
“p Please push this data to the application immediately."
TCP Connection
(Contd..)
• Connection establishment is
followed by data transfer
• The client and server can send
data and acknowledgements
in both direction
• Data travelling in the same
direction as an
acknowledgement can be
carried on the same segment
• The data segment sent by the
client have the PSH flag set
so that the server TCP tries to
deliver data to the server
process as soon as they are
received
TCP Connection
Release
• Data transfer is followed by
connection termination (or
release) that also follows the
typical three-way
handshaking
TCP Flow control
TCP Connection release
Connection release
To release a connection, either party can send a TCP segment with
the FIN bit set, which means that it has no more data to transmit
When both directions have been shut down, the connection is
released
When the FIN is acknowledged, that direction is shut down
for new data
Data may continue to flow indefinitely in the other direction,
however
Normally, four TCP segments are needed to release a connection:
one FIN and one ACK for each direction
However, it is possible for the first ACK and the second
FIN to be contained in the same segment, reducing the total count
to three
Just as with telephone calls in which both people say goodbye and
hang up the phone simultaneously, both ends of a TCP connection
may send FIN segments at the same time. These are each
acknowledged in the usual way, and the connection is shut down
TCP Connection release and connection management (Contd..)
Solid lines are for client, dotted lines are for server
TCP timer management
• Retransmission of segments is the heart of error control in TCP
• When a segment is sent, it is stored in a queue until it is acknowledged
• When the retransmission timer expires or when the sender receives 3 duplicate
ACKs for the first segment in the queue, the segment is retransmitted
• Sending TCP maintains one Retransmission time-out (RTO) for each connection
• When the timer times out, TCP sends the segment in front of the queue and restarts the timer
(to resend the packet once again)
• The value of RTO is dynamic in TCP and is always updated based on the round-trip time
(RTT) of segments
• RTT is the time needed for a segment to reach a destination and for an acknowledgment to be received
TCP timer management (Contd…)
• To retransmit lost segments, TCP employs one retransmission timer (for the whole
connection period)
• This timer handles the RTO which is the waiting time (set) for an
acknowledgement of a segment
• Rules for defining the value of retransmission timer:
• 1. When TCP sends the segment in front of the queue, it starts the timer
• 2. When RTO expires, TCP resends the first segment which is in front of the queue, and
restarts the timer
• 3. When segments are cumulatively acknowledged, the segment is purged from the
queue
• 4. If the queue is empty, TCP stops the timer; otherwise, TCP restarts the timer
TCP timer management (Contd…)
• To calculate the RTO, one needs to calculate the round-trip time (RTT)
• RTT in TCP is calculated step-by-step using the following parameters
• Measured RTT (RTTM)
• Smoothed RTT (RTTS)
• RTT Deviation (RTTD)
• Measured RTT (RTTM)
• Measured RTT is the time actually taken to send a segment and receive an acknowledgement for it
• Smoothed RTT (RTTS)
• RTTM is likely to change for each round trip.
• Most implementations use a smoothed RTT called RTTS which is a weighted average of RTTM
• RTT deviation (RTTD)
• By how much does RTTM or RTTS deviate on an average is indicated by RTTD
• The value of new RTO is based on the smoothed round-trip and its deviation
TCP timer management (Contd…)
• Formulae:
Smoothed RTT:
• After first measurement: RRTS = RTTM
• After each measurement: The value of α is implementation-dependent,
RRTS = (1-α) RRTS+αRTTM but it is normally set to 1/8
RTT deviation:
• After first measurement: RRTD = RTTM/2
• After each measurement: The value of β is also implementation-dependent,
but is usually is set to 1/4
RRTD = (1-β)RRTD+βmod(RRTS - RTTM)
Retransmission time-out:
• Original: initialRTO (Will be given)
• After any measurement: RTO= RRTs + 4RRTd
TCP Congestion Control
• Congestion in a network may occur if the load on the n/w i.e. the no. of packets sent to
the n/w is greater than the capacity of the n/w i.e. the no. of packets a n/w can handle
• Congestion in a n/w occurs because routers and switches have buffers that hold packets
before and after processing
• The packet is put in appropriate o/p queue and waits to be sent
• These queues are finite, so it is possible for more packets to arrive at a router than the
router can buffer
• Congestion control refers to techniques and mechanisms that can either prevent
congestion, before it happens, or remove congestion, after it has happened
• There are two types of congestion control techniques followed by TCP
• Open-loop congestion control
• Closed-loop congestion control
TCP Congestion Control
• Open-loop congestion control
• Here, policies are applied to prevent congestion before it happens
• Congestion control, here, is handled by either the source or the destination
• Different policies adopted are:
• Retransmission policy
• Window policy Refer Forouzan, pg. 385
• Acknowledgement policy
• Closed-loop congestion control
• This mechanism tries to alleviate congestion after it happens
• The size of the window at the sender’s end can be flexible
• One factor that can determine the sender window size is the congestion in the network
• The sending transport layer can monitor the congestion in the network by watching lost packets and use a
strategy to decrease window size if the congestion is increasing and vice versa
Congestion window in TCP
• Congestion control in TCP is based on both open-loop and closed-loop
mechanisms
• In flow control, it’s the receiver that dictates to the sender the size of the sender’s
window
• However, if the network cannot deliver data as fast as it is created by the sender, it must tell
the sender to slow down
• In other words, in addition to the receiver, the network is the second entity that determines the size
of the sender’s window
• The sender thus has 2 pieces of info.: the receiver-advertised window size (rwnd)
and the congestion window size (cwnd)
• The actual size of the sender window is the minimum of these two