Cs3591cn Unit II
Cs3591cn Unit II
Cs3591cn Unit II
Networks Unit II –
Transport Layer
CS8591
UNIT II – Transport Layer
2
CS8591
Introduction
• The transport layer is located between the application layer and the network layer.
• It provides a process-to-process communication between two application layers, one at
the local host and the other at the remote host.
• Communication is provided using a logical connection, which means that the two
application layers, which can be located in different parts of the globe.
• Alice’s host in the Sky Research company creates a logical connection with Bob’s host
in the Scientific Books company at the transport layer.
• The two companies communicate at the transport layer as though there is a
real connection between them.
3
CS8591
Introduction
4
CS8591
Introduction: Transport Layer Services
1. Process-to-process Communication
• The first duty of a transport-layer protocol is to provide process-to-
process communication.
• A process is an application-layer entity (running program) that uses the services of the
transport layer.
• A transport-layer protocol is responsible for delivery of the message to the appropriate
process.
5
CS8591
Introduction: Transport Layer Services
2. Addressing: Port Numbers
• To define the processes, identifiers are needed, called port numbers.
• In the TCP/IP protocol suite, the port numbers are integers between 0 and 65,535 (16
bits).
ICANN Ranges
• Well-known Ports: The ports ranging from 0 to 1023 are assigned and controlled by
ICANN.
• Registered Ports: The ports ranging from 1024 to 49,151 are not assigned or controlled
by ICANN. They can only be registered with ICANN to prevent duplication.
• Dynamic ports: The ports ranging from 49,152 to 65,535 are neither controlled nor
registered. They can be used as temporary or private port numbers.
6
CS8591
Introduction: Transport Layer Services
2. Addressing: Port Numbers
Port numbers
7
CS8591
Introduction: Transport Layer Services
3. Encapsulation and Decapsulation
• To send a message from one process to another, the transport-layer protocol encapsulates
and decapsulates messages.
• When a process has a message to send, it passes the message to the transport layer along
with a pair of socket addresses and some other pieces of information.
• The transport layer receives the data and adds the transport-layer header.
• When the message arrives at the destination transport layer, the header is dropped and
the transport layer delivers the message to the process running at the application layer.
• The sender socket address is passed to the process in case it needs to respond to the
message received.
8
CS8591
Introduction: Transport Layer Services
4. Multiplexing and Demultiplexing
• Whenever an entity accepts items
from more than one source, this is
referred to as multiplexing (many
to one).
• Whenever an entity delivers items to
more than one source, this is
referred to as demultiplexing (one
to many).
• The transport layer at the source
performs multiplexing; the transport
layer at the destination performs
demultiplexing
9
CS8591
Introduction: Transport Layer Services
5. Flow Control
• Delivery of items from a producer to a consumer can occur in one of two ways: pushing
or pulling.
• Pushing: If the sender delivers items whenever they are produced without a prior
request from the consumer.
• Pulling: If the producer delivers the items after the consumer has requested them.
• When the producer pushes the items, the consumer may be overwhelmed and there is a
need for flow control, in the opposite direction, to prevent discarding of the items.
• When the consumer pulls the items, it requests them when it is ready. In this case, there
is no need for flow control.
10
CS8591
Introduction: Transport Layer Services
5. Flow Control
• Communication at the transport layer deals with four entities: sender process, sender
transport layer, receiver transport layer, and receiver process.
Buffers
• One of the solutions for flow control is normally to use two buffers.
• One at the sending transport layer and the other at the receiving transport layer.
• A buffer is a set of memory locations that can hold packets at the sender and
receiver.
11
CS8591
Introduction: Transport Layer Services
5. Error Control
• Reliability can be achieved to add error control services to the transport layer.
• Error control at the transport layer is responsible for
12
CS8591
Introduction: Transport Layer Services
6. Congestion Control
• Congestion in a network may occur if the load on the network (the number of packets
sent to the network) is greater than the capacity of the network (the number of packets a
network can handle).
• Congestion control refers to the mechanisms and techniques that control the congestion
and keep the load below the capacity.
14
CS8591
Introduction: Transport Layer Services
7. Connectionless and Connection Oriented Protocols
• In a connection-oriented service, the client and the server first need to establish a
logical connection between themselves.
• The data exchange can only happen after the connection establishment. After data
exchange, the connection needs to be torn down.
• Flow control, error control, and congestion control are implemented in a connection
oriented protocol.
15
CS8591
Transport Layer Protocols
1. Simple Protocol
• A simple connectionless protocol with neither flow nor error control.
• The receiver can never be overwhelmed with incoming packets.
• The transport layer at the sender gets a message from its application layer, makes a
packet out of it, and sends the packet.
• The transport layer at the receiver receives a packet from its network layer, extracts the
message from the packet, and delivers the message to its application layer.
• The transport layers of the sender and receiver provide transmission services for their
application layers.
16
CS8591
Transport Layer Protocols
2. Stop-and-Wait Protocol
• A connection-oriented protocol, which uses both flow and error control.
• Both the sender and the receiver use a sliding window of size 1.
• The sender sends one packet at a time and waits for an acknowledgment before
sending the next one.
• To detect corrupted packets, we need to add a checksum to each data packet.
• Every time the sender sends a packet, it starts a timer.
• If an acknowledgment arrives before the timer expires, the timer is stopped and the
sender sends the next packet.
• If the timer expires, the sender resends the previous packet, assuming that the packet was
either lost or corrupted.
17
CS8591
Transport Layer Protocols
3. Go-Back-N Protocol (GBN)
• To improve the efficiency of transmission, multiple packets must be in transition while
the sender is waiting for acknowledgment.
• The key to Go-back-N is that the sender can send several packets before receiving
acknowledgments, but the receiver can only buffer one packet.
• Sender must keep a copy of the sent packets until the acknowledgments arrive.
• The acknowledgment number is cumulative and defines the sequence number of the next
packet expected to arrive.
CS8591 19
Transport Layer Protocols
5. Bidirectional Protocols: Piggybacking
• Unidirectional Protocols: data packets flow in only one direction and acknowledgments
travel in the other direction.
• In real life, data packets are normally flowing in both directions: from client to server
and from server to client.
• A technique called piggybacking is used to improve the efficiency of the bidirectional
protocols.
• When a packet is carrying data from A to B, it can also carry acknowledgment feedback
about arrived packets from B; when a packet is carrying data from B to A, it can also
carry acknowledgment feedback about the arrived packets from A.
20
CS8591
Transport Layer Protocols
21
CS8591
Services
• UDP: Unreliable connectionless transport-layer protocol used for its simplicity and
efficiency in applications where error control can be provided by the application-layer
process.
• TCP: Reliable connection-oriented protocol that can be used in any application where
reliability is important.
• SCTP: A new transport-layer protocol that combines the features of UDP and TCP.
CS8591
Port Numbers
• To create a process-to-process communication, these protocols use port numbers to
accomplish.
• Port numbers provide end-to-end addresses at the transport layer and allow multiplexing
and demultiplexing.
CS8591
User Datagram Protocol
• A connectionless, unreliable transport protocol.
• It does not add anything to the services of IP except for providing process-to-process
communication.
• UDP is a very simple protocol using a minimum of overhead.
• If a process wants to send a small message and does not care much about reliability, it
can use UDP.
User Datagram
CS8591
User Datagram Protocol
User Datagram
• UDP packets, called user datagrams, have a fixed-size header of 8 bytes made of four
fields, each of 2 bytes (16 bits).
• Source Port Number: Port number of the source process.
• Destination Port Number: Port number of the destination process.
• Header: Total length of the UDP datagram
• Checksum: For error correction
• The total length of a UDP user datagram is stored in an IP datagram: 65,535 bytes.
CS8591
User Datagram Protocol
UDP Services
• Process-to-Process Communication: UDP provides process-to-process communication
using socket addresses, a combination of IP addresses and port numbers.
• Connectionless Services: User datagram sent by UDP is an independent datagram.
There is no connection establishment and no connection termination. Each user
datagram can travel on a different path.
• Flow Control: There is no flow control, and hence no window mechanism. The
receiver may overflow with incoming messages.
• Error Control: There is no error control mechanism in UDP except for the
checksum. The sender does not know if a message has been lost or duplicated. When the
receiver detects an error through the checksum, the user datagram is silently discarded.
• Congestion Control: It does not provide congestion control. UDP assumes that the
packets sent are small and sporadic and cannot create congestion in the network.
CS8591
User Datagram Protocol
UDP Services
• Encapsulation and Decapsulation: To send a message from one process to another, the
UDP protocol encapsulates and decapsulates messages.
• Queuing: In UDP, queues are associated with ports.
• Multiplexing and Demultiplexing: Several processes that may want to use the services
of UDP. To handle this situation, UDP multiplexes and demultiplexes.
• Checksum: UDP checksum calculation includes three sections: a pseudoheader, the
UDP header, and the data coming from the application layer.
CS8591
User Datagram Protocol
UDP Applications
• UDP Features:
– Connectionless Service
• Typical Applications:
– Suitable for a process that requires simple request-response communication with
little concern for flow and error control.
– Suitable for a process with internal flow- and error-control mechanisms.
– Used for some route updating protocols such as Routing Information Protocol (RIP).
– Used for interactive real-time applications that cannot tolerate uneven delay between
sections of a received message
CS8591
Transmission Control Protocol
• Connection-oriented, reliable protocol.
• TCP explicitly defines connection establishment, data transfer, and connection
teardown phases to provide a connection-oriented service.
• To ensure reliability, TCP uses checksum (for error detection), retransmission of lost
or corrupted packets, cumulative and selective acknowledgments, and timers.
CS8591
Transmission Control Protocol
TCP Services
• Process-to-Process Communication: TCP provides process-to-process communication using port
numbers.
• Stream Delivery Service: 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.
– Sending and Receiving Buffers: TCP needs buffers for storage. The sending buffer and the
receiving buffer, one for each direction.
– Segments: TCP groups a number of bytes together into a packet called a segment.
• Full-Duplex Communication: Data can flow in both directions at the same time.
• Multiplexing and Demultiplexing: TCP performs multiplexing at the sender and demultiplexing at
the receiver.
• Connection-Oriented Service: The two TCP’s establish a logical connection between them. Data are
exchanged in both directions. The connection is terminated.
• Reliable Service: TCP uses an acknowledgment mechanism to check the safe and sound arrival of
data.
CS8591
Transmission Control Protocol
TCP Features
• Numbering System: TCP software keeps track of the segments being transmitted or
received.
• Byte Number: The bytes of data being transferred in each connection are numbered by
TCP. The numbering starts with an arbitrarily generated number.
• Sequence Number: Defines the number assigned to the first data byte contained in
that segment.
• Acknowledgment Number: Defines the number of the next byte a party expects to
receive. The acknowledgment number is cumulative.
CS8591
Transmission Control Protocol
Segment
• A packet in TCP is called a segment.
• The segment consists of a header of 20 to 60 bytes, followed by data from the application
program.
CS8591
Transmission Control Protocol
Segment
• Source port address: A 16-bit field that defines the port number of the application
program in the host that is sending the segment.
• Destination port address: A 16-bit field that defines the port number of the application
program in the host that is receiving the segment.
• Sequence number: A 32-bit field defines the number assigned to the first byte of data
contained in this segment.
• Acknowledgment number: A 32-bit field defines the byte number that the receiver of the
segment is expecting to receive from the other party.
• Header length: A 4-bit field indicates the number of 4-byte words in the TCP header.
• Control: This field defines 6 different control bits or flags.
CS8591
Transmission Control Protocol
Segment
• Window size: This field defines the window size of the sending TCP in bytes. The
maximum size of the window is 65,535 bytes.
• Checksum: A 16-bit field for error detection and correction.
• Urgent pointer: A 16-bit field, which is valid only if the urgent flag is set, is used when
the segment contains urgent data.
• Options: Can be up to 40 bytes of optional information in the TCP header.
Encapsulation
• A TCP segment encapsulates the data received from the application layer.
• The TCP segment is encapsulated in an IP datagram, which in turn is encapsulated in a
frame at the data-link layer.
CS8591
Transmission Control Protocol
TCP Connection – Connection Establishment
• TCP transmits data in full-duplex mode.
• The connection establishment in TCP is called
three-way handshaking.
• The process starts with the server. The server
program tells its TCP that it is ready to accept
a
connection. This request is called a passive open.
• The client program issues a request for an active
open.
• A SYN segment cannot carry data, but it
consumes one sequence number.
• A SYN + ACK segment cannot carry data, but it
does consume one sequence number.
• An ACK segment, if carrying no data, consumes
no sequence number.
CS8591
Transmission Control Protocol
TCP Connection – Connection Termination
• The two parties involved in exchanging data (client or server) can close the connection, although it is
usually initiated by the client.
• Two options for connection termination: Three-way handshaking and Four-way handshaking with
a half-close option.
Three-Way Handshaking
• The FIN segment consumes one sequence number if it does not carry data.
• The FIN + ACK segment consumes only one sequence number if it does not carry data.
• An ACK segment, to confirm the receipt of the FIN segment from the TCP server.
CS8591
Transmission Control Protocol
TCP Connection – Connection Termination
Half-Close
• In TCP, one end can stop sending data while still receiving data.
• After half-closing the connection, data can travel from the server to the client and acknowledgments
can travel from the client to the server. The client cannot send any more data to the server.
CS8591
Transmission Control Protocol
TCP State Transition Diagram
CS8591
Transmission Control Protocol
Windows in TCP
• TCP Sliding Window provides,
– Reliable delivery of data,
CS8591
Transmission Control Protocol
Windows in TCP
Sending Side
• LastByteAck
ed ≤
LastByteSent
– Receiver
cannot
acknowle
dge a
byte that
has not
been sent.
• LastByteSent
≤
LastByteWri
tten
– TCP
cannot
send a
byte that
CS8591the
Transmission Control Protocol
TCP Flow Control
• Both sender and receiver buffer size is finite size, denoted by
MaxSendBuffer, MaxRcvBuffer.
• In sliding window, window size sets the amount of data that can be sent without waiting
for acknowledgement.
• Here receiver gives the maximum window size for the sender by advertising a window
that is no larger than the data that it can buffer.
• Receiver side must keep,
– LastByteRcvd – LastByteRead ≤ MaxRcvBuffer
CS8591
Transmission Control Protocol
TCP Flow Control
• Sender side must keep,
– LastByteSent – LastByteAcked ≤ AdvertisedWindow
– To avoid the overflow of the send buffer by local application process, sender must
make sure,
• LastByteWritten – LastByteAcked ≤ MaxSendBuffer
CS8591
Transmission Control Protocol
TCP Flow Control – Triggering Transmission
How does TCP decide to transmit a segment?
– TCP supports a byte stream abstraction.
CS8591
Transmission Control Protocol
TCP Flow Control – Nagle’s Algorithm
• If there is data to send but the window is open less than MSS, then we may want to wait some amount
of time before sending the available data.
• If we wait too long, then we hurt interactive applications like Telnet.
• If we don’t wait long enough, then we risk sending a bunch of tiny packets and falling into the silly
window syndrome.
– The solution is to introduce a timer and to transmit when the timer expires.
– This ACK can be treated like a timer firing, triggering the transmission of more data.
When the application produces data to send,
if both the available data and the window ≥ MSS
send a full segment
else if there is unACKed data in flight
buffer the new data until an ACK arrives
else
send all the new data now
CS8591
Transmission Control Protocol
TCP Error Control
• 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, and detecting and discarding
duplicated segments.
• Error control in TCP is achieved through the use of three simple tools:
1. Checksum: Each segment includes a checksum field, which is used to check for a corrupted segment.
3. Time-out: When the retransmission timer expires or when the sender receives three duplicate ACKs
for the first segment in the queue, that segment is retransmitted.
– Retransmission after RTO
CS8591
Transmission Control Protocol
TCP Congestion Control
• The idea of TCP congestion control is for each source to determine how much capacity
is available in the network, so that it knows how many packets it can safely have in
transit.
o Once a given source has this many packets in transit, it uses the arrival of an ACK
as a signal that one of its packets has left the network, and that it is therefore safe to
insert a new packet into the network without adding to the level of congestion.
o By using ACKs to pace the transmission of packets, TCP is said to be self-clocking.
CS8591
Transmission Control Protocol
TCP Congestion Control - Additive Increase/Multiplicative Decrease
• TCP maintains a new state variable for each connection, called CongestionWindow,
which is used by the source to limit how much data it is allowed to have in transit at a
given time.
• The congestion window is congestion control’s counterpart to flow control’s advertised
window.
• TCP is modified such that the maximum number of bytes of unacknowledged data
allowed is now the minimum of the congestion window and the advertised window.
CS8591
Transmission Control Protocol
TCP Congestion Control - Additive Increase/Multiplicative Decrease
• How does the source determine that the network is congested and that it should
decrease the congestion window?
– Based on the observation that the main reason packets are not delivered, and a timeout
results, is that a packet was dropped due to congestion. It is rare that a packet is
dropped because of an error during transmission.
– Therefore, TCP interprets timeouts as a sign of congestion and reduces the rate at
which it is transmitting.
– Specifically, each time a timeout occurs, the source sets CongestionWindow to half of
its previous value. This halving of the CongestionWindow for each timeout
corresponds to the “multiplicative decrease” part of AIMD.
– For example, suppose the CongestionWindow is currently set to 16 packets. If a loss
is detected, CongestionWindow is set to 8.
z
CS8591 51
Transmission Control Protocol
TCP Congestion Control - Additive Increase/Multiplicative Decrease
• How does the source determine that the network is congested and that it should
decrease the congestion window?
– Additional losses cause CongestionWindow to be reduced to 4, then 2, and finally to 1
packet.
– CongestionWindow is not allowed to fall below the size of a single packet, i.e.,
maximum segment size (MSS).
• Increase the congestion window to take advantage of newly available capacity in the
network.
• This is the “additive increase” part of AIMD, and it works as follows.
– Every time the source successfully sends a CongestionWindow’s worth of packets—
that is, each packet sent out during the last RTT has been ACKed—it adds the
equivalent of 1 packet to CongestionWindow.
CS8591
Transmission Control Protocol
TCP Congestion Control - Additive Increase/Multiplicative Decrease
• TCP does not wait for an entire window’s worth of ACKs to add 1 packet’s worth to the
congestion window, but instead increments CongestionWindow by a little for each ACK
that arrives.
• Specifically, the congestion window is incremented as follows each time an ACK arrives:
– Increment = MSS × (MSS/CongestionWindow)
– CongestionWindow += Increment
– That is, rather than incrementing CongestionWindow by an entire MSS bytes each
RTT, we increment it by a fraction of MSS every time an ACK is received.
– Assuming that each ACK acknowledges the receipt of MSS bytes, then that fraction is
MSS/CongestionWindow.
CS8591
Transmission Control Protocol
TCP Congestion Control – Slow Start
• Additive Increase / Multiplicative Decrease is only suitable for source, that is operating
close to the available capacity of the network, but it takes too long to ramp up a connection
when it is starting from scratch.
• Slowstart, which is used to increase the congestion window rapidly from a cold start.
• Slow start effectively increases the congestion window exponentially, rather than linearly.
– When the ACK for this packet arrives, TCP adds 1 to CongestionWindow and then
sends two packets.
– Upon receiving the corresponding two ACKs, TCP increments CongestionWindow by
2 - one for each ACK - and next sends four packets.
– The end result is that TCP effectively doubles the number of packets it has in transit
every RTT.
CS8591
Transmission Control Protocol
TCP Congestion Control - Slow Start
• Specifically, the source has a current (and useful) value of CongestionWindow; this is the
value of CongestionWindow that existed prior to the last packet loss, divided by 2 as a
result of the loss.
CS8591
Transmission Control Protocol
TCP Congestion Control - Slow Start
• This value used as the ―target‖ congestion window also called as CongestionThreshold.
• Slow start is used to rapidly increase the sending rate up to this value, and then additive
increase is used beyond this point.
CS8591
Transmission Control Protocol
TCP Congestion Control - Fast Retransmit and Fast Recovery
• The idea of fast retransmit is straightforward.
• Every time a data packet arrives at the receiving side, the receiver responds with an
acknowledgment, even if this sequence number has already been acknowledged.
• Thus, when a packet arrives out of order— that is, TCP cannot yet acknowledge the data
the packet contains because earlier data has not yet arrived—TCP resends the same
acknowledgment it sent the last time.
• This second transmission of the same acknowledgment is called a duplicate ACK.
• When the sending side sees a duplicate ACK, it knows that the other side must have
received a packet out of order, which suggests that an earlier packet might have been lost.
• Since it is also possible that the earlier packet has only been delayed rather than lost, the
sender waits until it sees some number of duplicate ACKs and then retransmits the missing
packet.
CS8591
Transmission Control Protocol
TCP Congestion Control - Fast Retransmit and Fast Recovery
• In practice, TCP waits until it has seen three duplicate ACKs before retransmitting the
packet.
• When the fast retransmit mechanism signals congestion, rather than drop the congestion
window all the way back to one packet and run slow start, it is possible to use the ACKs
that are still in the pipe to clock the sending of packets.
• This mechanism, which is called fast recovery, effectively removes the slow start phase
that happens between when fast retransmit detects a lost packet and additive increase
begins.
CS8591
Stream Control Transmission Protocol (SCTP)
• A new transport-layer protocol designed to combine some features of UDP and TCP in
an effort to create a better protocol for multimedia communication.
SCTP Services
• Process-to-Process Communication: It provides process-to-process communication
• Multiple Streams: It allows multistream service in each connection, which is called
association in SCTP terminology. If one of the streams is blocked, the other streams can
still deliver their data.
• Multihoming: The sending and receiving host can define multiple IP addresses in each
end for an association. In this fault-tolerant approach, when one path fails, another
interface can be used for data delivery without interruption.
• Connection-Oriented Service: A connection is called an association.
• Reliable Service: It uses an acknowledgment mechanism to check the safe and sound
arrival of data.
CS8591
Stream Control Transmission Protocol (SCTP)
SCTP Features
• Transmission Sequence Number (TSN): It is used to number the data chunks. TSNs are
32 bits long and randomly initialized between 0 and 232 - 1.
• Stream Identifier (SI): Each stream in SCTP needs to be identified using a stream
identifier (SI).
• Stream Sequence Number (SSN): SCTP defines each data chunk in each stream with a
stream sequence number (SSN).
CS8591
Stream Control Transmission Protocol (SCTP)
Packets
• SCTP is totally different: data are carried as data chunks, control information as control
chunks.
• Several control chunks and data chunks can be packed together in a packet.
CS8591
Stream Control Transmission Protocol (SCTP)
An SCTP Association – Association Establishment
• A connection in SCTP is called an association.
• No other chunk is allowed in a packet carrying an INIT or INIT ACK
chunk.
• A COOKIE ECHO or a COOKIE ACK chunk can carry data chunks.
CS8591
Stream Control Transmission Protocol (SCTP)
An SCTP Association – Data Transfer
• In SCTP, only data chunks consume TSNs; data chunks are the only chunks that are
acknowledged.
• The acknowledgment in SCTP defines the cumulative TSN, the TSN of the last data
chunk
received in order.
CS8591
Stream Control Transmission Protocol (SCTP)
An SCTP Association – Association Termination
• SCTP does not allow a ―half-closed‖
association
CS8591