14 -TCP
14 -TCP
Dr Samayveer Singh
Dept. of Computer Science and
Engineering
National Institute of Technology
Jalandhar, Punjab, India
[email protected]
NITJ 1
TCP (Transmission Control Protocol) is a reliable, connection-oriented, stream-
TCP Services based, and full-duplex transport layer protocol. It ensures accurate and in-
order delivery of data from one process to another over a network.
✓ Process-to-Process Communication
✓ Stream Delivery Service Full-Duplex Communication
✓ Full-Duplex Communication
two-way data transfer.
2. Both hosts can send and
receive data independently at
the same time.
✓ Connection-Oriented Service
1. Separate buffers and
sequence numbers for each
direction.
2. Common in applications like
Feature Description
-----------------------------------------------------------------------------------------------
**Connection-oriented** Requires a handshake before data transfer. 1. Multiplexing: Multiple processes on a host use TCP
**Reliable** Uses ACKs, retransmissions, timers, etc. simultaneously.
**Full-duplex** Data flows in both directions simultaneously.
**Byte-stream** Data sent as a stream, not message-by-message. 2. Demultiplexing: TCP identifies the correct receiving
**Flow control** Uses a **sliding window** to avoid overwhelming receiver. process using port numbers.
**Congestion control** Regulates sending rate based on network congestion.
**Port addressing** Uses source/destination ports for process communication. 3. Each TCP connection is uniquely identified by 4-tuple:
Figure 1 shows the relationship of TCP to the other protocols in the TCP/IP
protocol suite. TCP lies between the application layer and the network
layer, and serves as the intermediary between the application programs and
the network operations.
2. The receiver doesn’t know where one message ends and another begins.
Example:
If sender writes: [Hello][World]
Receiver may get: [He][lloW][orld]
Stream of bytes
Segment N Segment 1
H H
Solution
The following shows the sequence number for each
segment:
✓ Format
✓ Encapsulation
This field holds the next expected byte from the sender.
Used to acknowledge received data.
Tells the sender how
many bytes it can send
Used for flow control.
before waiting for an ACK.
(start connection)
IP
header
Frame
header
TCP payload
IP payload
Data-link layer payload
Passive Open
Initial Sequence No. (choosen randomly by the client) means the server is
set to wait (listen)
seq: 8000 for connection
requests from
clients, rather than
UAPRS F 15000 (server’s
initiating them.
ISN)
SYN
seq: 15000 8001 (client’s
ISN + 1)
ack: 8001
nd: 5000
rwnd = 5000
U A P R S F rw (receiver
window size =
SYN + ACK buffer space)
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
Connection Termination
✓ In flow control balances the rate a producer creates data with the
rate a consumer can use the data.
✓ TCP separates flow control from error control. In this section, we
discuss flow control, ignoring error control.
✓ We temporarily assume that the logical channel between the
sending and receiving TCP is error-free.
✓ Figure shows unidirectional data transfer between a sender and a
receiver; bidirectional data transfer can be deduced from
unidirectional one.
2
Segements are pushed
4
Flow control feedback
• Next figure shows the reason for the mandate in window shrinking.
• Part a of the figure shows values of last acknowledgment and rwnd.
• Part b shows the situation in which the sender has sent bytes 206 to
214.
• Bytes 206 to 209 are acknowledged and purged. The new
advertisement, however, defines the new value of rwnd as 4, in which
210 + 4 < 206 + 12 (new ackno+rwnd >= last ackno+rwnd).
• When the send window shrinks, it creates a problem: byte 214 which
has been already sent is outside the window.
• The relation discussed before forces the receiver to maintain the
right-hand wall of the window to be as shown in part a because the
receiver does not know which of the bytes 210 to 217 has already
been sent.
• One way to prevent this situation is to let the receiver postpone its
feedback until enough buffer locations are available in its window.
• In other words, the receiver should wait until more bytes are
consumed by its process. Once a window is advertised, the receiver cannot shrink it (i.e., it cannot reduce the
allowed byte range).
Silly Window Syndrome is a problem that arises due to poor implementation of TCP.
It degrades the TCP performance and makes the data transmission extremely
inefficient. The problem is called so because:
2. The window size shrinks to such an extent that the data being transmitted is
smaller than TCP Header.
Why Is It a Problem?
After receiving the acknowledgement, sender should send the buffered data in one
TCP segment. Then, sender should buffer the data again until the previously sent
data gets acknowledged. Only send the next segment when:
You receive an ACK, or
You have a maximum segment size (MSS) worth of data.
TCP/IP Protocol Suite 45
Silly Window Syndrome
Cause-2: Receiver window accepting one byte of data repeatedly –
Suppose consider the case when the receiver is unable to process all the
incoming data.
In such a case, the receiver will advertise a small window size. The
process continues and the window size becomes smaller and smaller. A
stage arrives when it repeatedly advertises window size of 1 byte. This
makes receiving process slow and inefficient. The solution to this problem
is Clark’s Solution.
Buffer overflows,
✓ Congestion Policy
Packet drops,
Retransmissions,
Increased delays.
Grows exponentially:
Congestion Avoidance
Linear growth:
How is it calculated?
❖ Sender starts the persistent timer on receiving an ACK from the receiver with
a zero window size.
❖ When persistent timer goes off, sender sends a special segment to the
receiver.
❖ This special segment is called as probe segment and contains only 1 byte of
new data.
❖ Response sent by the receiver to the probe segment gives the updated
window size.
❖ If the updated window size is non-zero, it means data can be sent now.
❖ If the updated window size is still zero, the persistent timer is set again and
the cycle repeats.
❖ TCP uses a keep alive timer to prevent long idle TCP connections.
✓ Each time server hears from the client, it resets the keep alive timer to 2
hours.
✓ If server does not hear from the client for 2 hours, it sends 10 probe
segments to the client.
✓ These probe segments are sent at a gap of 75 seconds.
✓ If server receives no response after sending 10 probe segments,
it assumes that the client is down.
✓ Then, server terminates the connection automatically.
✓ Sender starts the time wait timer after sending the ACK for the second
FIN segment.
✓ It allows to resend the final acknowledgement if it gets lost.
✓ It prevents the just closed port from reopening again quickly to some
other application.
✓ It ensures that all the segments heading towards the just closed port are
discarded.
✓ The value of time wait timer is usually set to twice the lifetime of a TCP
segment.
Purpose:
Ensures all duplicate segments are flushed from the network before fully closing a connection.