Module - 5 - Transport Layer
Module - 5 - Transport Layer
Client/Server Paradigm
The most common method of achieving Process-to-Process delivery is Client/Server
Paradigm.
A process on the local host, called a client needs service from a process usually on the
remote host, called a server.
Both Client & Server have the same name.
Local Host, Local Process, Remote
Host, Remote Process must be defined for
communication.
Addressing
To choose among the multiple processes running on the Host, Port numbers are
required.
The destination port number is needed for delivery, and source port number is
needed forreply.
In the Internet model, the port numbers are 16-bit integers: 0 to 65535.
The client process defines itself with a port number, chosen randomly, called
EPHEMERAL(temporary) port number.
The server process must also define itself with a port number, but not chosen
randomly.The server uses the Universal port numbers called WELL-KNOWN port numbers.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 1
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
IANA ranges
WELL-KNOWN ports:
The ports ranging from 0 to 1023 are assigned and controlled by IANA.
REGISTERED ports:
The ports ranging from 1024 to 49, 151 are not assigned or controlled by
IANA. They can only be registered with IANA to prevent duplication.
DYNAMIC ports:
The ports ranging from 49, 152 to 65,535 are neither controlled nor
registered. They can be used by any process. These are the Ephemeral ports.
Socket addresses
A Transport layer protocol needs a pair of socket addresses: the Client socket
address andthe Server socket address.
The IP header contains the IP address & the UDP or TCP contains the port numbers.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 2
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Decapsulation happens at the receiver site. 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.
Multiplexing:
Many-to-one relationship at the sender site.
Protocol accepts messages from different processes, differentiated by their
assigned portnumbers.
Adds the header, & passes the packet to the network layer.
De-multiplexing:
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 3
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Pushing or Pulling
Delivery of items from a producer to a consumer can occur in one of two ways:
1. Pushing and
2. Pulling.
Pushing:
If the sender delivers items whenever they are produced-without a prior request from the
consumer-the delivery is referred to as pushing.
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.
Pulling:
If the producer delivers the items after the consumer has requested them, the delivery is
referred to as pulling.
When the consumer pulls the items, it requests them when it is ready. In this case, there is
no need for flow control.
Receiver process
The last delivery, however, is normally a pulling delivery; the transport layer waits until
the application-layer process asks for messages.
Figure below shows that we need at least two cases of flow control:
1. From the sending transport layer to the sending application layer and
2. From the receiving transport layer to the sending transport layer.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 4
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Buffers
A buffer is a set of memory locations that can hold packets at the sender and receiver.
Flow control can be implemented normally using two buffers: one at the sending
transportlayer and the other at the receiving transport layer.
The flow control communication can occur by sending signals from the consumer
to the producer.
➢ When the buffer of the sending transport layer is full, it informs the application layer to
stop passing chunks of messages. When there are some vacancies, it informs the
application layer that it can pass message chunks again.
➢ When the buffer of the receiving transport layer is full, it informs the sending transport
layer to stop sending packets. When there are some vacancies, it informs the sending
transport layer that it can send packets again.
Error Control
Reliability of transport layer can be achieved to add error control services to the transport layer.
Error control at the transport layer is responsible for
1. Detecting and discarding corrupted packets.
2. Keeping track of lost and discarded packets and resending them.
3. Recognizing duplicate packets and discarding them.
4. Buffering out-of-order packets until the missing packets arrive.
Sequence Numbers
The packets are numbered sequentially during the transmission are called sequence number.
Sliding Window
The buffer is represented as a set of slices, called the sliding window that occupies part of the
circle at any time.
At the sender site, when a packet is sent, the corresponding slice is marked. When
all theslices are marked, it means that the buffer is full and no further messages can be
accepted from the application layer.
When an acknowledgment arrives, the corresponding slice is unmarked.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 5
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
If some consecutive slices from the beginning of the window are unmarked, the window
slides over the range of the corresponding sequence numbers to allow more free slices at
the end of the window.
Congestion control
Congestion control refers to the mechanisms and techniques that control the congestion and keep
the load below the capacity.
Reliable Vs Unreliable
Reliable:
Reliable protocol guarantees successful data transmission by implementing flow & error control
mechanisms.
Unreliable:
Doesn’t guarantee successful data transmission. It doesn’t implement any error or flow control
mechanism.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 6
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Connectionless service:
The source process needs to divide its message into chunks of data of the size acceptable by the
transport layer and deliver them to the transport layer one by one.
When a chunk arrives from the application layer, the transport layer encapsulates it in a packet
and sends it.
➢ In Figure shows that at the client site, the three chunks of messages are delivered to the client
transport layer in order (0, 1, and 2).
➢ Because of the extra delay in transportation of the second packet, the delivery of messages at
the server is not in order (0, 2, 1).
➢ If these three chunks of data belong to the same message, the server process may have
received a strange message.
➢ Since there is no numbering on the packets, the receiving transport layer has no idea that one
of the messages has been lost.
➢ It just delivers two chunks of data to the server process.
➢ The above two problems arise from the fact that the two transport layers do not coordinate
with each other.
➢ The receiving transport layer does not know when the first packet will come or when all of the
packets have arrived.
➢ No flow control, error control, or congestion control can be effectively implemented in a
connectionless service.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 7
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Connection-Oriented Service
The client and the server first need to establish a logical connection between them. The data
exchange can only happen after the connection establishment. After data exchange, the connection
needs to be torn down.
A connection is first established b/w the sender and the receiver, data are
transferred andthen the connection is released.
Ex: TCP, SCTP
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 8
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
TRANSPORT-LAYER PROTOCOLS
The TCP/IP protocol uses a transport-layer protocol that is either a modification or a combination
of some of these protocols.
❖ Simple Protocol
❖ Stop-and-Wait Protocol
❖ Go-Back-N Protocol (GBN)
❖ Selective-Repeat Protocol
Simple Protocol
Our first protocol is a simple connectionless protocol with neither flow nor error control.
The receiver can never be overwhelmed with incoming packets. Figure shows the layout for this
protocol.
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.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 9
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Stop-and-wait Protocol
The Stop-and-Wait protocol is a connection-oriented protocol that provides 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, need to add a checksum to each data packet.
At the receiver site; If its checksum is incorrect, the packet is corrupted and silently
discarded.
Every time the sender sends a packet, it starts a timer and keeps a copy of the packet.
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 waseither lost or corrupted.
One packet and one acknowledgment can be in the channels at any time.
Sender
The sender is initially in the ready state, but it can move between the ready and blocking state.
The variable S is initialized to 0.
Ready state.
When the sender is in this state, it is only waiting for one event to occur.
If a request comes from the application layer, the sender creates a packet
with thesequence number set to S.
A copy of the packet is stored, and the packet is sent. The sender then starts the
only timer.The sender then moves to the blocking state.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 10
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Blocking state.
When the sender is in this state, three events can occur:
a) If an error-free ACK arrives with the ackNo related to the next packet to be sent, which
means ackNo = (S + 1) modulo 2, then the timer is stopped. The window slides, S = (S + 1)
modulo 2. Finally, the sender moves to the ready state.
b) If a corrupted ACK or an error-free ACK with the ackNo ≠ (S + 1) modulo 2 arrives, the
ACK is discarded.
c) If a time-out occurs, the sender resends the only outstanding packet and restarts the
timer.
Receiver
The receiver is always in the ready state. Three events may occur:
a) If an error-free packet with seqNo = R arrives, the message in the packet is delivered to the
application layer. The window then slides, R = (R + 1) modulo 2. Finally an ACK with
ackNo = R is sent.
b) If an error-free packet with seqNo ≠ R arrives, the packet is discarded, but an ACK with
ackNo = R is sent.
c) If a corrupted packet arrives, the packet is discarded.
The Stop-and-Wait protocol is very inefficient, there is no pipelining because a sender must wait
for a packet to reach the destination and be acknowledged before the next packet can be sent.
The key to Go-back-N is that can send several packets before receiving acknowledgments, but the
receiver can only buffer one packet. Sender keeps a copy of the sent packets until the
acknowledgments arrive.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 11
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
The send window is an imaginary box covering the sequence numbers of the data
packetsthat can be in transit or can be sent.
The maximum size of the window is 2m – 1.
The send window at any time divides the possible sequence numbers into four
regions.
➢ The first region, left of the window, defines the sequence numbers belonging to
packets that are already acknowledged.
➢ The second region, defines the range of sequence numbers belonging to the packets
that have been sent, waiting for acknowledgement.
➢ The third range, defines the range of sequence numbers for packets waiting to sent
➢ Finally, the fourth region, right of the window, defines sequence numbers that
cannot be used until the window slides.
Figure shows how a send window can slide one or more slots to the right when an
acknowledgment arrives from the other end.
In the figure, an acknowledgment with ackNo = 6 has arrived. This means that the receiver is
waiting for packets with sequence number 6.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 12
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
The receiver is always looking for the arrival of a specific packet. Any packet arriving
out of order is discarded and needs to be resent.
Figure shows the sequence numbers to the left of the window belong to the packets
alreadyreceived and acknowledged
The sequence numbers to the right of this window define the packets that cannot b e
received.
The receive window slides only one slot at a time. When a correct packet is received,
the window slides, Rn = (Rn + 1) modulo 2m.
Sender
The sender starts in the ready state, but thereafter it can be in one of the two states: ready or
blocking. The two variables are normally initialized to 0 (Sf = Sn = 0).
Ready state
Four events may occur when the sender is in ready state.
a) If a request comes from the application layer, the sender creates a packet with the
sequence number set to Sn. A copy of the packet is stored, and the packet is sent. The
sender also starts the only timer if it is not running. The value of Sn is now incremented,
(Sn = Sn + 1) modulo 2m. If the window is full, Sn = (Sf + Ssize) modulo 2m, the sender goes
to the blocking state.
b) If an error-free ACK arrives with ackNo related to one of the outstanding packets, the
sender slides the window (set Sf = ackNo), and if all outstanding packets are acknowledged
(ackNo = Sn), then the timer is stopped. If all outstanding packets are not acknowledged,
the timer is restarted.
c) If a corrupted ACK or an error-free ACK with ackNo not related to the outstanding packet
arrives, it is discarded.
d) If a time-out occurs, the sender resends all outstanding packets and restarts the timer.
Blocking state
Three events may occur in this case:
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 13
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
a. If an error-free ACK arrives with ackNo related to one of the outstanding packets, the
sender slides the window (set Sf = ackNo) and if all outstanding packets are acknowledged
(ackNo = Sn), then the timer is stopped. If all outstanding packets are not acknowledged,
the timer is restarted. The sender then moves to the ready state.
b. If a corrupted ACK or an error-free ACK with the ackNo not related to the outstanding
packets arrives, the ACK is discarded.
c. If a time-out occurs, the sender sends all outstanding packets and restarts the timer.
Receiver
The receiver is always in the ready state. The only variable, Rn, is initialized to 0. Three events
may occur:
a. If an error-free packet with seqNo = Rn arrives, the message in the packet is delivered to
the application layer. The window then slides, Rn = (Rn + 1) modulo 2m. Finally an ACK is
sent with ackNo = Rn.
b. If an error-free packet with seqNo outside the window arrives, the packet is discarded, but
an ACK with ackNo = Rn is sent.
c. If a corrupted packet arrives, it is discarded.
This protocol is inefficient if the underlying network protocol loses a lot of packets. Each time a
single packet is lost or corrupted, the sender resends all outstanding packets, even though some of
these packets may have been received safe and sound but out of order.
Selective-Repeat Protocol
The name implies, resends only selective packets, those that are actually lost. The
Selective-Repeat protocol also uses two windows: a send window and a receive window. The
send window maximum size can be 2m−1 and receiver window is same as send window.
The Selective-Repeat protocol allows as many packets as the size of the receive
window to arrive out of order and be kept until there is a set of consecutive packets to be
delivered to the application layer.
To emphasize that in a reliable protocol the receiver never delivers packets out of
order to the application layer.
Figure shows the receive window in Selective-Repeat. Those slots inside the window
thatare shaded define packets that have arrived out of order and are waiting for the earlier
transmitted packet to arrive before delivery to the application layer.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 14
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Selective-Repeat uses one timer for each outstanding packet. When a timer expires, only the
corresponding packet is resent.
Sender
The sender starts in the ready state, but later it can be in one of the two states: ready or blocking.
The following shows the events and the corresponding actions in each state.
Ready state.
Four events may occur in this case:
a. If a request comes from the application layer, the sender creates a packet with the
sequence number set to Sn. A copy of the packet is stored, and the packet is sent. If the
timer is not running, the sender starts the timer. The value of Sn is now incremented, Sn =
(Sn + 1) modulo 2m. If the window is full, Sn = (Sf + Ssize) modulo 2m, the sender goes to
the blocking state.
b. If an error-free ACK arrives with ackNo related to one of the outstanding packets, that
packet is marked as acknowledged. If the ackNo = Sf, the window slides to the right until
the Sf points to the first unacknowledged packet (all consecutive acknowledged packets are
now outside the window). If there are outstanding packets, the timer is restarted;
otherwise, the timer is stopped.
c. If a corrupted ACK or an error-free ACK with ackNo not related to an outstanding packet
arrives, it is discarded.
d. If a time-out occurs, the sender resends all unacknowledged packets in the window and
restarts the timer.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 15
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Blocking state.
Three events may occur in this case:
a. If an error-free ACK arrives with ackNo related to one of the outstanding packets, that
packet is marked as acknowledged. In addition, if the ackNo = Sf, the window is slid to the
right until the Sf points to the first unacknowledged packet (all consecutive acknowledged
packets are now outside the window). If the window has slid, the sender moves to the
ready state.
b. If a corrupted ACK or an error-free ACK with the ackNo not related to outstanding packets
arrives, the ACK is discarded.
c. If a time-out occurs, the sender resends all unacknowledged packets in the window and
restarts the timer.
Receiver
The receiver is always in the ready state. Three events may occur:
a. If an error-free packet with seqNo in the window arrives, the packet is stored and an
ACK with ackNo = seqNo is sent. In addition, if the seqNo = Rn, then the packet and all
previously arrived consecutive packets are delivered to the application layer and the
window slides so that the Rn points to the first empty slot.
b. If an error-free packet with seqNo outside the window arrives, the packet is discarded,
but an ACK with ackNo = Rn is returned to the sender. This is needed to let the sender
slide its window if some ACKs related to packets with seqNo < Rn was lost.
c. If a corrupted packet arrives, the packet is discarded.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 16
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
UDP
UDP is an 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
TCP is a reliable connection-oriented protocol that can be used in any application where reliability
is important.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 17
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Total Length:
It is 16-bit long, defines the total length of the user datagram plus data.
16-bits can define a total length of 0 to 65,535 bytes, but the total length needs to
be muchless, because a udp datagram is stored in a ip datagram with a total length of 65,535
bytes.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 18
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Checksum:
Checksum includes three sections: a pseudo header, the UDP header, and the data from the
application layer
Used to detect the errors over the entire datagram.
Calculation & inclusion of the checksum in a user datagram is optional.
If the checksum is not calculated, the field is filled with 1s.
UDP operation:
Connectionless service:
There is no connection establishment and no connection termination.
Each user datagram is an independent datagram, there is no relationship between the
datagrams even if they are coming from the same source process and destined for the same
process.
This means that user datagrams can travel on different paths.
The user datagrams are not numbered
Queuing
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 19
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Queues at server:
At the server site, a server asks for incoming and outgoing queues using its well-
known port number, when it starts running.
The queues remain open as long as the server process is running.
Incoming queue:
When a message arrives for a server, udp sends the received user datagram to the end of the
incoming queue.
All the incoming messages for one particular server process, whether coming from
the same or a different client, are sent to the same queue.
If there is no such queue, udp discards the user datagram and asks icmp to send a
port unreachable message to the client.
An incoming queue can overflow, in case, the udp drops the user datagram and
sends theport unreachable message to the client.
Use of UDP
UDP is suitable for a process that requires simple request-response
communication withlittle concern for flow and error control.
UDP is suitable for a process with internal flow and error control mechanisms. Ex. –
TFTP.
It is a suitable transport protocol for multicasting.
UDP is used for management processes such as SNMP.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 20
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
UDP is used for some route updating protocols such as Routing Information Protocol
(RIP).
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 21
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
TCP SERVICES:
i) Process–to–process communication:
TCP provides process-to-process communication using the port numbers.
ii) Stream Delivery Service:
TCP is a stream-oriented protocol – allows sending process to deliver data as a
stream of bytes and allows the receiving process to obtain data as a stream of bytes.
TCP Services
Sending and Receiving buffers:
Because the sending & receiving processes may not write or read data at the same
speed,TCP needs buffers for storage.
Two buffers for sending and receiving.
One way to implement a buffer is to use a circular array of 1-byte locations.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 22
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
SEGMENTS:
The IP layer, as a service provider for TCP, needs to send data in packets, not as a
stream of bytes.
At the transport layer, TCP groups a number of bytes together into a packet called a
Segment.
TCP adds a header to each segment and delivers to the IP layer.
The segments are encapsulated in the IP datagram and transmitted.
v) Reliable service:
It uses an acknowledgement mechanism to check the safe and sound arrival of data.
TCP Features:
i) Numbering system:
BYTE NUMBER:
The bytes of the data being transferred in each connection are numbered by TCP. *
thenumbering starts with a randomly generated number.
SEQUENCE NUMBER
After the bytes have been numbered, TCP assigns a sequence number to each
segment thatis being sent.
The sequence number for each segment is the number of the first byte carried in that
segment.
ACKNOWLEDGEMENT NUMBER
Each party uses an acknowledgement number to confirm the bytes it has received,
i.e.,acknowledgement number defines the number of the next byte it expects to receive.
The acknowledgement numbers are cumulative.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 23
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
The segment consists of a 20- to 60- byte header, followed by data from the application process.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 24
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Flag Description
URG The value of the urgent pointer field is valid.
ACK The value of the acknowledgment field is valid.
PSH Push the data.
RST The connection must be reset.
SYN Synchronize sequence numbers during connection.
FIN Terminate the connection.
TCP CONNECTION
TCP transmits data in full-duplex mode. When two TCPs in two machines are connected, they are
able to send segments to each other simultaneously. This implies that each party must initialize
communication and get approval from the other party before any data are transferred.
A connection-oriented transport protocol establishes a virtual path between the
source anddestination.
All the segments belonging to a message are then sent over this virtual path.
Using a single virtual pathway for the entire message facilitates the acknowledgement
process as well as transmission of damaged or lost frames.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 25
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Connection Establishment
The client wants to make a connection with another application program, called
the server,using TCP as the transport-layer protocol.
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. 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 an open server tells its TCP to connect to a particular server.
TCP can now start the three-way handshaking process, as shown in Figure.
Three-Way Handshaking
The connection establishment in TCP is called three-way handshaking.
The three steps in this phase are as follows.
A SYN segment cannot carry data, but it consumes one sequence number.
A SYN 1 ACK segment cannot carry data, but it does consume one sequence number.
An ACK segment, if carrying no data, consumes no sequence number.
Data Transfer
After connection is established, bidirectional data transfer can take place.
The client and server can send data and acknowledgments in both directions.
Pushing Data
The sending TCP uses a buffer to store the stream of data coming from the sending
application program.
The sending TCP can select the segment size.
The receiving TCP also buffers the data when they arrive and delivers them to the
application program when the application program is ready or when it is convenient for
the receiving TCP. This type of flexibility increases the efficiency of TCP.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 26
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Connection Termination
Either of the two parties involved in exchanging data (client or server) can close the
connection.
Most implementations today allow two options for connection termination: three-way
handshaking and four-way handshaking with a half-close option.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 27
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
1. In this situation, the client TCP, after receiving a close command from the client process, sends
the first segment, a FIN segment in which the FIN flag is set. Note that a FIN segment can
include the last chunk of data sent by the client or it can be just a control segment as shown in
the figure. If it is only a control segment, it consumes only one sequence number because it
needs to be acknowledged.
2. The server TCP, after receiving the FIN segment, informs its process of the situation and sends
the second segment, a FIN + ACK segment, to confirm the receipt of the FIN segment from the
client and at the same time to announce the closing of the connection in the other direction.
This segment can also contain the last chunk of data from the server. If it does not carry data, it
consumes only one sequence number because it needs to be acknowledged.
3. The client TCP sends the last segment, an ACK segment, to confirm the receipt of the FIN
segment from the TCP server. This segment contains the acknowledgment number, which is
one plus the sequence number received in the FIN segment from the server. This segment
cannot carry data and consumes no sequence numbers.
Half-Close
In TCP, one end can stop sending data while still receiving data. This is called a half
close.
Either the server or the client can issue a half-close request.
It can occur when the server needs all the data before processing can begin.
Figure shows an example of a half-close. The data transfer from the client to the
serverstops.
The client half-closes the connection by sending a FIN segment.
The server accepts the half-close by sending the ACK segment.
The server, however, can still send data. When the server has sent all of the
processed data,it sends a FIN segment, which is acknowledged by an ACK from the client.
After half-closing the connection, data can travel from the server to the
client andacknowledgments can travel from the client to the server.
The client cannot send any more data to the server.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 28
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Windows in TCP
TCP uses two windows (send window and receive window) for each direction of data transfer,
which means four windows for a bidirectional communication.
Send Window
Figure shows an example of a send window. The window size is 100 bytes; the send window size
is dictated by the receiver (flow control) and the congestion in the underlying network
(congestion control). The figure shows how a send window opens, closes, or shrinks.
The send window in TCP is similar to the one used with the Selective-Repeat protocol, but with
some differences:
1. One difference is the nature of entities related to the window. The window size in SR is the
number of packets, but the window size in TCP is the number of bytes. Although actual
transmission in TCP occurs segment by segment, the variables that control the window are
expressed in bytes.
2. The second difference is that, in some implementations, TCP can store data received from the
process and send them later, but we assume that the sending TCP is capable of sending
segments of data as soon as it receives them from its process.
3. Another difference is the number of timers. The theoretical Selective-Repeat protocol may use
several timers for each packet sent, but as mentioned before, the TCP protocol uses only one
timer.
Receive Window
Figure shows an example of a receive window. The window size is 100 bytes. The figure also
shows how receive window opens and closes; in practice, the window should never shrink.
There are two differences between the receive window in TCP and the one we used for SR.
1. The first difference is that TCP allows the receiving process to pull data at its own pace. This
means that part of the allocated buffer at the receiver may be occupied by bytes that have been
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 29
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
received and acknowledged, but are waiting to be pulled by the receiving process. The receive
window size is then always smaller than or equal to the buffer size, as shown in Figure 24.18.
The receive window size determines the number of bytes that the receive window can accept
from the sender before being overwhelmed (flow control). In other words, the receive window
size, normally called rwnd, can be determined as:
2. The second difference is the way acknowledgments are used in the TCP protocol. Remember
that an acknowledgement in SR is selective, defining the uncorrupted packets that have been
received. The major acknowledgment mechanism in TCP is a cumulative acknowledgment
announcing the next expected byte to receive (in this way TCP looks like GBN, discussed
earlier). The new version of TCP, however, uses both cumulative and selective
acknowledgments.
Some Scenarios
Scenarios that occur during the operation of TCP as
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 30
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Normal Operation
Lost segment
Fast Transmission
Normal Operation
The first scenario shows bidirectional data transfer between two systems as shown
in Figure.
The client TCP sends one segment; the server TCP sends three.
The figure shows which rule applies to each acknowledgment.
At the server site, only rule 1 applies. There are data to be sent, so the segment
displays thenext byte expected.
When the client receives the first segment from the server, it does not have any
more datato send; it needs to send only an ACK segment.
However, according to rule 2, the acknowledgment needs to be delayed for 500 ms
to seeif any more segments arrive.
When the ACK-delaying timer matures, it triggers an acknowledgment. This is
because theclient has no knowledge of whether other segments are coming; it cannot delay
the acknowledgment forever.
When the next segment arrives, another ACK delaying timer is set.
However, before it matures, the third segment arrives. The arrival of the third
segmenttriggers another acknowledgment based on rule 3.
It has not shown the RTO timer because no segment is lost or delayed.
Lost Segment
In this scenario, a lost or corrupted segment is treated the same way by the receiver.
A lost segment is discarded somewhere in the network; a corrupted segment is
discardedby the receiver itself. Both are considered lost.
Figure shows a situation in which a segment is lost.
In our scenario, the sender sends segments 1 and 2, which are acknowledged
immediately by an ACK (rule 3). Segment 3, however, is lost.
The receiver receives segment 4, which is out of order. The receiver stores the data
in thesegment in its buffer but leaves a gap to indicate that there is no continuity in the data.
The receiver immediately sends an acknowledgment to the sender displaying the
next byteit expects (rule 4).
The sender TCP keeps one RTO timer for the whole period of connection.
When the third segment times out, the sending TCP resends segment 3, which
arrives thistime and is acknowledged properly (rule 5).
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 31
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Fast Retransmission
In this scenario, Each time the receiver receives a subsequent segment, it triggers n
a
acknowledgment (rule 4).
The sender receives four acknowledgments with the same value (three duplicates).
Although the timer has not matured, the rule for fast retransmission requires that
segment3, the segment that is expected by all of these duplicate acknowledgments, be resent
immediately.
After resending this segment, the timer is restarted.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 32
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Congestion Window
➢ The size of the send window is controlled by the receiver using the value of rwnd, which is
advertised in each segment traveling in the opposite direction.
➢ The use of this strategy guarantees that the receive window is never overflowed with the
received bytes (no end congestion).
➢ There is no congestion at the other end, but there may be congestion in the middle.
➢ TCP needs to worry about congestion in the middle because many segments lost may
seriously affect the error control.
➢ More segment loss means resending the same segments again, resulting in worsening the
congestion, and finally the collapse of the communication.
➢ TCP is an end-to-end protocol that uses the service of IP. The congestion in the router is in
the IP territory and should be taken care of by IP.
➢ TCP cannot ignore the congestion in the network; it cannot aggressively send segments to
the network. The result of such aggressiveness would hurt the TCP itself, as we mentioned
before.
➢ TCP cannot be very conservative, either, sending a small number of segments in each time
interval, because this means not utilizing the available bandwidth of the network.
➢ TCP needs to define policies that accelerate the data transmission when there is no
congestion and decelerate the transmission when congestion is detected.
➢ To control the number of segments to transmit, TCP uses another variable called a
congestion window, cwnd, whose size is controlled by the congestion situation in the
network (as we will explain shortly). The cwnd variable and the rwnd variable together
define the size of the send window in TCP.
➢ The first is related to the congestion in the middle (network); the second is related to the
congestion at the end. The actual size of the window is the minimum of these two.
➢ Lost acknowledgments may create deadlock if they are not properly handled.
➢ Actual window size 5 minimum (rwnd, cwnd)
Congestion Detection
The TCP sender uses the occurrence of two events as signs of congestion in the network: time-out
and receiving three duplicate ACKs.
Time-out
➢ If a TCP sender does not receive an ACK for a segment or a group of segments before the
time-out occurs, it assumes that the corresponding segment or segments are lost and the
loss is due to congestion.
➢ Another event is the receiving of three duplicate ACKs.
➢ Recall that when a TCP receiver sends a duplicate ACK, it is the sign that a segment has
been delayed, but sending three duplicate ACKs is the sign of a missing segment, which can
be due to congestion in the network.
➢ However, the congestion in the case of three duplicate ACKs can be less severe than in the
case of time-out.
➢ When a receiver sends three duplicate ACKs, it means that one segment is missing, but
three segments have been received. The network is either slightly congested or has
recovered from the congestion.
➢ A very interesting point in TCP congestion is that the TCP sender uses only one feedback
from the other end to detect congestion: ACKs.
➢ The lack of regular, timely receipt of ACKs, which results in a time-out, is the sign of a
strong congestion; the receiving of three duplicate ACKs is the sign of a weak congestion in
the network.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 33
Computer Communication Networks -15EC64 Module - 5 – Transport Layer
Congestion Policies
TCP’s general policy for handling congestion is based on three algorithms: slow start, congestion
avoidance, and fast recovery. We first discuss each algorithm before showing how TCP switches
from one to the other in a connection.
Prepared by Sivaprakash.C & Aruna R, Dept. of ECE, Sri Sairam College of Engineering, Anekal. 34