Transmission Control Protocol (TCP)
Previous Lecture (4):
-
Reliable transmission
-
Data link protocol
-
ARQ
-
Sliding window
Today (lecture 6):
Intro to TCP
Connection establishment
more on sliding windows
TCP flow control
TCP Characteristics
Byte Stream
Provides the upper layer with a continuous byte stream. The application
need not worry about creating or sending packets. TCP numbers all
the packets (sequence number) and makes sure that they are sent to the
upper layer in the correct order.
Duplex Connection
Bi-directional streams. Hosts can send data to each other at the same time.
Client and server are both sender and receiver.
Reliable
Takes care of error recovery. Application sees loss-less channels.
Flow Control
Indirectly determines the rate at which data should be sent. Helps
to prevent network congestion.
Connection Establishment: Three-Way Handshake
-
Client sends SYN packet to server.
-
Server acknowledges SYN packet received from client and sends a new SYN
packet to client.
-
Client acknowledges SYN packet received from server.
SYN packet
-
Flag in TCP header signaling the beginning of a connection.
-
Contains first sequence number to be used in the connection
Ack
-
Attached to data packet traveling in the reverse direction.
-
In TCP, the ack field contains the next packet expected by the receiver.
The SYN flag is used to indicate that a sender is ready to transmit
data. The acknowledgment is used to indicate that the receiver is
ready to accept data. Since a TCP connection is bi-directional, two SYNs
and two ACKs must be sent. However, the server SYN and the client ACK share
the same packet. So we just need 3 packets (three-way handshake)
to establish a TCP connection.
Connection Termination
-
Each direction of the connection is terminated separately.
-
A FIN packet is sent by the side who wants to tear down the connection.
-
An ACK is sent back by the other side.
Since each direction of the TCP connection can be closed at different
times, the two FINs and two ACKs required to tear down the TCP connection
may all travel in different packets. Therefore, up to four packets can
be sent during this final phase of the TCP connection.
TCP Sliding Window
A duplex TCP connection uses up to four sliding windows. A sender
window and receiver window is needed for both the client-to-server connection
and the server-to-client connection.
For now, we only need to focus on one of the two directional connections.
Both the sender and receiver sliding windows in TCP inherit much of the
functionality of the generic
sliding windows presented in lecture 4. However TCP introduces some
novelties.
Receiver Window
-
Similar function as before: manage buffer to receive incoming data.
-
Still use NFE, LFA, RWS(rcv_wnd).
-
Also keeps track of bytes read by application LastByteRead.
-
Send acks to sender.
Novelty : Receiver adds rcv_wnd (receiver window
size) to the ack it sends to the source.
For some reason, the ack field in TCP contains the next sequence
number expected at the receiver rather than the sequence number of the
acked packet.
Sender Window
-
Similar function as before: limit the amount of data in the network.
-
Still use LAR (snd_una - 1), LFS (snd_nxt - 1), SWS (snd_wnd).
-
Also keeps track of bytes written by the application LastByteWritten.
Novelty : Sender sets snd_wnd dynamically for flow control
purposes.
rcv_wnd and snd_wnd stand for receiver and sender window respectively.
snd_una
stands for smallest unacked sequence number, and snd_nxt stands
for the next
sequence number to be sent. These last two variables differ from
the corresponding terminology used by the textbook (LAR and LFS) by one.
Sender Window Size: snd_wnd
-
snd_wnd is set to the minimum of rcv_wnd and snd_cwnd.
-
rcv_wnd is the receiver window size value received in the last acknowledgment.
-
snd_cwnd is the congestion window size. It is constantly readjusted
by the sender depending on the congestion status of the network.
-
Under ideal conditions, snd_cwnd should be equal to the delay-bandwidth
product.
The limit imposed by rcv_wnd guarantees that the receiver buffer
will not overflow.
The limit imposed by snd_cwnd attempts to guarantee that the
network buffers will not overflow.
TCP Flow Control
To Prevent Congestion
-
Bandwidth used < bandwidth available.
-
Data in network < delay-bandwidth product.
Since the amount of data transiting the network is limited by snd_wnd,
setting snd_wnd to be always less than the delay-bandwidth product will
ensure
that there is no congestion in the network.
Problem: It is extremely hard for TCP to accurately measure
the delay-bandwidth product of a connection. The bandwidth as well as the
delay can be constantly
changing, and packets might get lost due to factors that have nothing
to do with congestion.
Solution: Introduce a congestion window snd_cwnd that
is continuously updated using feedback from the network. snd_cwnd
tries to approximate itself to the new delay-bandwidth product
at each instant of time.
A larger snd_cwnd will allow the sender to use more bandwidth.
If RTT is the round-trip delay product, the maximum rate at which
the sender can transmit data is snd_cwnd/RTT.
Delay-Bandwidth Product Estimation
-
Additive increase: increment snd_cwnd slowly when acks are
received on time. This indicates that there is no congestion on the network,
and therefore the sender is allowed to increase snd_cwnd in order
to send more data.
-
Multiplicative decrease: decrease snd_cwnd quickly when packet
loss is detected. This indicates that there might be congestion in the
network, and therefore the sender is forced to rapidly decrease snd_cwnd
in order to use less bandwidth and avoid congestion.
This conservative approach tends to underestimate the delay-bandwidth product.
This might lead to some bandwidth under-utilization, but it is always preferable
to network congestion.
TCP Tahoe
Original TCP flow control algorithm. Proposed by Van Jacobson in 1988.
-
Initialize variables ssthresh and snd_cwnd. (snd_cwnd
= 1).
-
If snd_cwnd < ssthresh, increment snd_cwnd
by 1 every time an ack is received. (slow start phase)
-
If snd_cwnd > ssthresh, increment snd_cwnd by
1/snd_cwnd every time an ack is received. (congestion avoidance
phase)
-
If a packet is lost, set sshthresh to snd_cwnd/2 and set snd_cwnd
to 1.