Вы находитесь на странице: 1из 183

Module 3

Transmission
Control Protocol
(TCP)
Types of data deliveries
PositionofTCPinTCP/IPprotocolsuite
TCP
SERVICES
Stream delivery

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.
Stream delivery
TCP,issteamorientedprotocol.

In UDP(message oriented protocol), a process (an


application program) sends a chunk of bytes to UDP for
delivery.

UDP adds its own header to this chunk of data, which is


now called a user datagram, and delivers it to IP for
transmission. The process may deliver several chunks of
datatotheUDP,butUDPtreatseachchunkindependently
withoutseeinganyconnectionbetweenthem.
Sending and receiving
buffers
Thesendingandthereceivingprocessesmaynotproduce
andconsumedataatthesamespeed.TCPneedsbuffers
forstorage.

There are two buffers, the sending buffer and the


receivingbuffer,foreachdirection.

Onewaytoimplementabufferistouseacirculararray
of1bytelocations.
Figure 15.3 Sending and receiving buffers

Stream of bytes
At the sender, the buffer has
three chambers.
The white section contains
empty chambers that can be
filled by the sending process
(producer).
The colored area holds bytes that
The shaded have been sent but not yet
area contains acknowledged.
bytes to be The TCP sender keeps these
bytes in the buffer until it
sent by the receives an acknowledgment.
sending TCP.
TCP segments
TCP groups a number of bytes together into a
packet called a segment.
TCP adds a header to each segment and delivers
the segment to the IP layer for transmission.
The segments are encapsulated in an IP
datagram and transmitted.
The segments are not necessarily the same size.
In reality segments carry hundreds, if not
thousands, of bytes.
Figure 15.4 TCP segments

Segment N Segment 1
H H
Providing Reliability with Acknowledgments and Retransmissions

Sender Network Receiver

Send packet 1

Receive packet 1
Send ACK 1

Receive ACK 1

Send packet 2

Receive packet 2

Send ACK 2

Receive ACK 2
Packet Loss

Sende Network Receiver


r
Send
packet 1

(Timeout)
Send
packet 1
Receive
packet 1
Send ACK 1

Receive
ACK 1
ACK Delayed

Sende Network Receiver


r
Send
packet 1 Receive
packet 1
Send ACK 1
(Timeout)
Send
packet 1

Receive Receive
ACK 1 packet
(Discard)
1
Send ACK 1

Receive
(Discard)
ACK 1
TCP segment format
Header
Source port address: This is a 16-bit field that defines the
port number of the application program in the host that is
sending the segment.

Destination port address: receiving the segment.

Sequence number: defines the number assigned to the


first byte of data contained in this segment (range 2 32). To
ensure connectivity, each byte to be transmitted is
numbered. The sequence number tells the destination
which bytes in this sequence comprises the first byte in the
segment.
Header
Acknowledgment number: This 32-bit field defines the
byte number that the sender of the segment is expecting
to receive from the other party. If the byte numbered x has
been successful received, x+1 is the acknowledgment
number.

Header length: This 4-bit field indicates the number of 4-


byte words in the TCP header. The length of the header
can be between 20 and 60 bytes. Therefore, the value of
this field can be between 5 (5x4 = 20) and 15 (15x4 =60).

Reserved:This is a 6-bit field reserved for future use.


Control field

This field defines 6 different control bits or flags which


can be set at a time. These bits enable flow control,
connection establishment and termination, and the
mode of data transfer in TCP.
Figure 3 Control field

20
TCP header fields
Flagbits:
URG: Urgentpointerisvalid
Ifthebitisset,thefollowingbytescontainanurgent
messageintherange:
SeqNo<=urgentmessage<=SeqNo+urgentpointer
ACK:AcknowledgementNumberisvalid
PSH:PUSHFlag
Notificationfromsendertothereceiverthatthereceiver
shouldpassalldatathatithastotheapplication.
Normallysetbysenderwhenthesendersbufferisempty

21
TCP header fields

Flagbits:
RST:Resettheconnection
Theflagcausesthereceivertoresettheconnection
ReceiverofaRSTterminatestheconnectionandindicates
higherlayerapplicationaboutthereset
1 => Tells the receiver to abort the conn.
SYN:Synchronizesequencenumbers
Sentinthefirstpacketwheninitiatingaconnection
FIN:Senderisfinishedwithsending
Usedforclosingaconnection
BothsidesofaconnectionmustsendaFIN

22
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.
Pseudoheader added to the TCP segment (Checksum)
Note

The use of the checksum in TCP is


mandatory.
Urgent Pointer:
Only valid if URG flag is set

TCP is a stream-oriented protocol. This means that the data is


presented from the application program to TCP as a stream of
bytes.

Each byte of data has a position in the stream. However, there are
occasions in which an application program needs to send urgent
bytes, some bytes that need to be treated in a special way by the
application at the other end.

The solution is to send a segment with the URG bit set. The
sending application program tells the sending TCP that the piece
of data is urgent.

The sending TCP creates a segment and inserts the urgent data at
the beginning of the segment. The rest of the segment can contain
normal data from the buffer.
TCP segment format

The unit of data transfer between


two devices using TCP is a segment.
The segment consist of a 20- to 60-
byte header, followed by data from
the application program.
The header is 20 bytes if there are
no options and up to 60 bytes if it
contains options.
TCP
Features
To provide the services mentioned in the
previous section, TCP has several
features

Numbering System
Flow Control
Error Control
Congestion Control
Byte Number

Note

The bytes of data being transferred in


each connection are numbered by TCP.

The numbering starts with an arbitrarily


generated number between 0 and 232
1.
Example 15.1
Suppose a TCP connection is transferring a file of
5,000 bytes. The first byte is numbered 10,001.
What are the sequence numbers for each
segment if data are sent in five segments, each
carrying 1,000 bytes?

Solution
The following shows the sequence number for
each segment:
Example

ImagineaTCPconnectionistransferring
a file of 6000 bytes. The first byte is
numbered10010.Whatarethesequence
numbersforeachsegmentifdataissentin
five segments with the first four segments
carrying 1,000 bytes and the last segment
carrying2,000bytes?
The following shows the sequence number for
eachsegment:
Segment1 10,010(10,010to11,009)
Segment211,010(11,010to12,009)
Segment3 12,010(12,010to13,009)
Segment4 13,010(13,010to14,009)
Segment514,010(14,010to16,009)
Note

After the bytes have been numbered,


TCP assigns a sequence number to
each segment that is being sent. The
sequence number for each segment is
the number of the first byte of data
carried in that segment.
Note

The value of the acknowledgment field


in a segment defines the number of the
next byte a party expects to receive.

The acknowledgment number is


cumulative.

Example:The acknowledgement for a segment


with sequence numbers 0-1500 is AckNo=1501
Sequence Numbers and Acknowledgments in
TCP
An acknowledgment is a
confirmation of delivery of data
When a TCP receiver wants to
acknowledge data, it
writes a sequence number in

the AckNo field, and


sets the ACK flag

IMPORTANT: An acknowledgment
confirms receipt for all
unacknowledged data that has
a smaller sequence number
than given in the AckNo field

Example: AckNo=5 confirms delivery


for 1,2,3,4 (but not 5).

36
37
unacknowledged data with a smaller sequence number

100
ACK
o= 9 0
SeqN s
te
10 by
An acknowledgment confirms the receipt of all
TCP has cumulative acknowledgements:

o= 8 0
SeqN s
Cumulative Acknowledgements

te
10 by 0
o= 7
SeqN s
70
te ACK
10 by
o= 6 0
SeqN s
te
10 by
o= 5 0
SeqN s
te
10 by
o= 4 0
SeqN s 40
te ACK
10 by
o=30
SeqN s
te
10 by
o=20
SeqN s 20
te
10 by ACK
o=10
SeqN s 10
e
10 byt
ACK
o=0
Se q N s
te
10 by

B
A
Consider hosts A and B communicating over a TCP connection.
Assume that the initial sequence number for each of A and B is 0.

Assume that all segments sent between A and B have 20 byte


headers.

A sends B a segment with a 20 byte payload, B responds with a


segment with a 30 byte payload and then another segment with a 40
byte payload, and finally A responds with a segment with a 50 byte
payload.

Give the value of the sequence number field and acknowledgement


number fields for each segment.
Figure 15.8 Encapsulation

TCP
Application-layer data
header

IP
header

Frame
header

TCP payload
IP payload
Data-link layer payload
A TCP CONNECTION
TCP is connection-oriented. A connection-oriented transport
protocol establishes a virtual path between the source and
destination. All of the segments belonging to a message are
then sent over this virtual path.

A connection-oriented transmission requires three phases:


(1) connection establishment
(2) data transfer
(3) connection termination.

40
Connection establishment
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.
Three- Way Handshaking
The connection establishment in TCP is called three way
handshaking.

For eg, an application program, called 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 is
called a request for a passive open.
Although a server TCP is ready to accept any
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 that it needs to be connected to that particular
server. TCP can now start the three-way handshaking
process
Three-step connection establishment
TCP Connection
Establishment
The server must be ready to accept connections, that is passive
open.
The client issues a request for active open.

(1) The client first sends a SYN segment, in which only SYN flag is
set. A SYN segment cannot carry data, but it consumes one
sequence number. The sequence number is called the initial
(2) After the server receives the SYN segment, it sends a SYN+ACK
sequence number (ISN).
segment back .The segment has 2 flag bits set: SYN and ACK, and
also contains receiver window size which indicates the maximal
number of bytes can be sent. A SYN+ACK segment cannot carry
data, but does consume one sequence number.

(3) After receiving SYN+ACK, the client sends an ACK segment to


the server. The ACK segment, if carrying no data, consume no
sequence number.

Now the TCP connection has been established.

45
TCP Connection
Establishment
TCP uses a three-way handshake to open a connection:
(1) ACTIVE OPEN: Client sends a segment with
SYN bit set *
port number of client

initial sequence number (ISN) of client

(2) PASSIVE OPEN: Server responds with a segment with


SYN bit set *

initial sequence number of server

ACK for ISN of client

(3) Client acknowledges by sending a segment with:


ACK ISN of server(* counts as one byte)

46
Three-Way Handshake

aida.poly.edu mng.poly.edu

47
Figure 15.9 Connection establishment using three-way handshake

Passive
Active open
open

Connection
opened

Means no data !
seq: 8001 if piggybacking
Figure 15.10 Data Transfer

Send
request

Receive

Send
request

Receive

Send
request

Connection Termination
Figure 15.11 Connection termination using three-way handshake
Note

The FIN + ACK segment consumes one


sequence number if it does
not carry data.
Figure 15.12 Half-Close

In TCP, one end can


stop sending data
while still receiving
data, this called Half-
close.

The client sends FIN


segment to the
server, & the server
sends an ACK back.

The data is still


sending from the
server to the client.
The server sends
a FIN segment when
all data are sent. The
client sends anACK
segment back. The
connection is closed.
This process called
155STATETRANSITIONDIAGRAM

To keep track of all the different events


happening during connection
establishment, connection termination,
and data transfer, TCP is specified as the
finite state machine.
Figure 15.13 State transition diagram

client server
SYN

SYN +ACK

ACK

data

ack

FIN

ACK
FIN

ACK
Note

The state marked as ESTBLISHED


in the FSM is in fact two different
sets of states that the client
and server undergo to transfer data.
Figure 15.14 Transition diagram for connection and half-close termination
Figure 15.15 Time-line diagram for Figure 15.14

1. Enough time for an ACK to


be lost and a new FIN to
arrive. If during the TIME-
WAIT state, a new FIN
arrives, the client sends a
new ACK and restarts the
2MSL timer
2. To prevent a duplicate
segment from one
connection appearing in the
next one, TCP requires that
incarnation cannot take
place unless 2MSL amount
of time has elapsed.
Another solution: the ISN of
the incarnation is greater
than the last seq. # used in
the previous connection.
Figure 15.16 Transition diagram for a common scenario
Figure 15.17 Time line for a common scenario

X
Figure 15.18 Simultaneous open
Figure 15.19 Simultaneous close

ex
Figure 15.20 Denying a connection
Figure 15.21 Aborting a connection
TCP Module Algorithm
Transmission Control Block TCBs
Timers
Main Module
Input Processing Module
Output Processing Module

McGraw-Hill The McGraw-Hill Companies, Inc., 2000


Figure 15.52 TCBs

The main module is invoked by an arriving TCP segment,


a time out event or a message from an application program
66
Figure 15.53 TCB

67
68
69
70
71
72
73
74
75
What is
Flow/Congestion/Error
Flow Control: Algorithms to prevent that the sender
Control ? overruns the receiver with information?
Congestion Control: Algorithms to prevent that the sender
overloads the network

Error Control: Algorithms to recover or conceal the


effects from packet losses

The goal of each of the control mechanisms is different.

But the implementation is combined


WINDOWSINTCP

TCP uses two windows (send window and


receive window) for each direction of data
transfer, which means four windows for a
bidirectional communication.
FLOW CONTROL
Flow control regulates the amount of data a source can send before
receiving an acknowledgment from the destination.

--The flow control protocol must not be too slow (cant let sender send 1
byte and wait for acknowledgement)
The flow control protocol must make sure that receiver does not get
overwhelmed with data (cant let sender send all of its data without
worrying about acknowledgements)

TCP uses sliding window protocol for flow control.


In this method, a host uses a window for outbound communication
(sending data). The window span the portion of the buffer containing
bytes received from the process. The bytes inside the window are the
bytes that can be in transit; they can be sent without worrying about
acknowledgement.
TCP sliding windows are byte oriented.
Note

A sliding window is used to make


transmission more efficient as well as
to control the flow of data so that the
destination does not become
overwhelmed with data. .
window_size

acknowledged sent can be sent


outside window
80
Senderbuffer

Sender could sent everything up to and including byte 211 but this
could overflow the receiver and force retransmission

The sender must adjust itself to the number of locations available at the
receiver
window_size

acknowledged sent can be sent


outside window
81
Receiverwindow

Next byte to be consuming by destination process is 194

Receiver expects byte 200 (was sent but not received)

How many more bytes can receiver store? 7 (13 6)

Receiver Window is 7
Senderbufferandsenderwindow

Flow control is achieved if the sender creates a window with a size less than
or equal to the receiver window

Sender windows contains bytes sent and not acked and those that can be
sent

Ex: Sender Windows size = Receiver Window size = 7


Only 4 more bytes can be sent (203-206) because 3 sent already

207-211 cannot be considered for sending until news from recvr


Slidingthesenderwindow

Sender sends 203-204

Sender Window can slide;

Buffer positions 200-202 recycled


Expandingthesenderwindow

If the receiving process consumes faster than it receives, size of receiving


window expands(buffer has more free locations)

Situation can be relayed to sender and the Sender can expand its window
size

Here receiver has acked 2 bytes 203-204(expecting byte 205) and set win
size = 10

Sender has sent 205-209 and added 212-215 and set window size to 10 like
receiver
Shrinkingthesenderwindow

If receiving process consumes data slower than it receives, receiving


windows shrinks
Received informs sender to reduce Sender Window Size

If receiver had buffer size = 10, received 5 (205-209) and consumed 1


(205),
Means number of free location is reduced to 6(10-5+1) Receiver Window
now 6

It acks bytes 205 to 209(expecting 210) but informs sender to shrink


window size and not to send more than 6 bytes

If the sender has already send 2 more bytes when it receives the news and
has received 3 more bytes from sending process, then the window will be
Closing Sender Window
Occurs when receiver buffer totally
full
Receiver Window size is 0
Relayed to sender who closes window
Left and right window boundaries overlap
Sender cannot send until receiver
announces a nonzero window value
InTCP,thesenderwindow
sizeistotallycontrolled
bythereceiverwindowvalue.
However,theactualwindowsize
canbesmallerifthereis
congestioninthenetwork.
SomePointsaboutTCPsSlidingWindows:
1.Thesourcedoesnothavetosenda
fullwindowsworthofdata.
2.Thesizeofthewindowcanbeincreased
ordecreasedbythedestination.
3.Thedestinationcansendan
acknowledgmentatanytime.
Flow Control: Two Approaches

Stop-and-go Sliding Window


Example 2

What is the value of the receiver window (rwnd) for host A if


the receiver, host B, has a buffer size of 5,000 bytes and 1,000
bytes of received and unprocessed data?

Solution
The value of rwnd = 5,000 1,000 = 4,000. Host B can receive
only 4,000 bytes of data before overflowing its buffer. Host B
advertises this value in its next segment to A.
Figure 7 Sliding window

Congestion window size


Example

The sender has sent bytes up to 202. We assume that cwnd is 20


(in reality this value is thousands of bytes). The receiver has
sent an acknowledgment number of 200 with an rwnd of 9
bytes (in reality this value is thousands of bytes). The size of
the sender window is the minimum of rwnd and cwnd or 9
bytes. Bytes 200 to 202 are sent, but not acknowledged. Bytes
203 to 208 can be sent without worrying about
acknowledgment. Bytes 209 and above cannot be sent.
Figure 8 Example

cwnd rwnd
Example
the server receives a packet with an acknowledgment value of 202 and
an rwnd of 9. The host has already sent bytes 203, 204, and 205. The
value of cwnd is still 20. Show the new window.

Solution
the size of the window has not been changed. The
acknowledgment value, 202, declares that bytes 200 and 201
have been received and the sender needs not worry about
them; the window can slide over them.
Example
the sender receives a packet with an acknowledgment value
of 206 and an rwnd of 12. The host has not sent any new
bytes. The value of cwnd is still 20. Show the new window.

Solution
The value of rwnd is less than cwnd, so the size of the
window is 12. Figure shows the new window. Note that the
window has been opened from the right by 7 and closed from
the left by 4; the size of the window has increased.
6. A window holds bytes 2001 to 5000. The next byte to be sent is 3001.
Draw a figure to show the situation of the window after the following
events.
(a) An ACK segment with the acknowledgement number 2500 and
window size advertisement 4000 is received.
(b) A segment carrying 1000 bytes is sent.
6.
Silly Window Syndrome
Serious problems can arise in the sliding
window operation when:
Sending application creates data slowly, or
Receiving applications consumes data
slowly (or both)
sender initiated silly window syndrome is
solved with Nagles algorithm
receiver initiated silly window syndrome is
solved with delayed ACKs
Silly Window Syndrome

Silly Window Syndrome - What if TCP sends segments that are


only 1 byte long? You would have 40 bytes of header, 1 byte of
data, for a total of 41 bytes.

TCP should wait until it has more data before it sends a 1-byte
segment. But how long should it wait to assemble data?

Nagles Algorithm:

1.The sending TCP sends the first piece of data it receives from
the sending application even if it is only 1 byte.

2. After sending the first segment, the sending TCP


accumulates data in the output buffer and waits until either the
receiving TCP sends an ack or until enough data has
accumulated to fill a maximum-size segment. At this time, the
sending TCP can send the segment.

3. Step 2 is repeated for the rest of the transmission.


Figure 12.24 Silly Window Syndrome

Silly Window Syndrome - What happens if the receiving TCP has a buffer
size of 1000 bytes and the sending TCP has just sent 1000 bytes. The
receiving buffer is now full so the receiver tells the sender to stop (window
size = 0).

The receiver now reads 1 byte of data, processes it, and sends a window
size of 1 (because now there is one space in the input buffer). The sender
gets the window size and sends 1 byte. This procedure continues.

Clarks Solution - Acknowledge receipt right away, but dont change the
window size until you have at least half the buffer space available.

Or, delay the ack until there is a decent amount of buffer space available.

105
ERROR CONTROL
TCP provides reliability using error control, which detects corrupted,
lost, out-of-order, and duplicated segments.

Error control in TCP is achieved through the use of the checksum,


acknowledgment, and time-out.

Error control includes a mechanism for detecting corrupted segments,


lost segments, out-of-order segments and duplicated segments.

Checksum is used to detect the corrupted segments.


TCP Error Control

TCP supports basic error control.

It uses a 16-bit arithmetic checksum

TCP uses the ACK message to


confirm receipt of segments.

There are a number of basic rules


pertaining to ACKs:

Rule 1: When one ends sends data,


it must piggyback the ACK for any
data received

Rule 2: If a receiver has no data to


send and a segment arrives, do not
ACK it immediately. Wait until two
segments arrive, then ACK. Or wait
500 ms after the first segment then
ACK.

107
Figure 12.25 Normal operation

Rule 3: When a segment arrives with an expected sequence number and


the previous in-order segment has not been ACKed, the receiver
immediately sends an ACK.

108
TCP Error Control

Rule 4: When a
segment arrives with a
sequence number
higher than expected,
the receiver
immediately sends an
ACK announcing the
sequence number it
expected. This leads to
fast retransmission

Rule 5: When a missing


segment arrives, the
receiver sends an ACK
segment to announce
the sequence number
expected. This informs
the receiver that
segments reported
missing have been 109
Lost acknowledgment corrected by resending a segment

Rule 6: If a duplicate segment arrives, receiver


immediately sends an ACK. This solves some
problems when an ACK itself is lost
Three ACKs in a row, fast retransmission

Furthermore, a retransmission will occur if the retransmission timer (RTO)


expires, or three duplicate ACKs arrive in order.

111
Retransmission
The heart of the error control mechanism is the
retransmission of segments.
TCP maintains a Retransmission Timer for each
connection
The timer is started during a transmission. A timeout
causes a retransmission
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 three duplicate ACKs for the first
segment in the queue, that segment is retransmitted.
TCP Congestion Control

(a) A fast network feeding a low capacity receiver.


(b) A slow network feeding a high-capacity receiver.
CONGESTIONCONTROL

Congestion control refers to the mechanisms and


techniques to keep the load below the capacity.

The sender has two pieces of information: the


receiver-advertised window size and the
congestion window size.

The actual size of the window is the minimum of


these two
Actual window size = minimum (rwnd,
cwnd)
Figure 14 Router queues

he routers/switches have queues-buffers that hold packets before and


ter processing.
the rate of the packet arrival is higher than the packet processing rate,
e input queues may overflow.
the packet depart rate is less than the packet processing rate, the
utput queue may be overflowed.
ome packets in the overflowed queues are dropped, indicating congestio
the Internet.
Packet delay and throughput vs. network load

Throughput is number of packets passing through the network


in unit of time
Congestion Policy
TCPs general policy for handling congestion is based on
three phases: slow start, congestion avoidance, and
congestion detection.

In the slow start phase, the sender starts with a slow rate of
transmission, but increases the rate rapidly to reach a
threshold.

When the threshold is reached, the rate of increase is


reduced. Finally if ever congestion is detected, the sender
goes back to the slow start or congestion avoidance phase,
based on how the congestion is detected.
Slow start, exponential increase
The slow start algorithm is based on the idea that the size of congestion
window (cwnd) starts with one maximum segment size MSS.

1
cwnd TCP has a slow
RTT start phase. In
2 this phase, the
cwnd size of the
congestion
RTT window
4 increases
cwnd exponentially
until it reaches a
threshold.
RTT
8

cwnd
Slow Start Example
CWND is incremented by 1 for each received ACK (exponential
increase)
In practice: in Slow Start, the CWND doubles in each
RTT (Round Trip Time)

for each ACK, the cwnd is increased by only 1 MSS. Hence, if three
segments are acknowledged accummlatively, the size of the cwnd
increases by only 1 MSS, not 3 MSS
Why Call it Slow Start ?
The original version of TCP suggested that the
sender transmit as much as the Advertised Window
permitted.
Routers may not be able to cope with this burst of
transmissions.
Slow start is slower than the above version --
ensures that a transmission burst does not happen
at once.
Figure 17 Congestion avoidance, additive increase

After the cwnd reaches the threshold, the size of the congestion
window increases additively until the congestion is detected

Start cwnd=1
After 1 RTT cwnd=2
After 2 RTTs cwnd =3
.

In other words, the increase is based on RTT, not on the number of


arrived
Congestion avoidance, additive increase
Note

In the congestion avoidance algorithm


the size of the congestion window
increases additively until
congestion is detected.
If CWND >= SSTHRESH, TCP is in
the so-called Congestion Avoidance
phase
In other words, the CWND increases
by 1 in each RTT(linear increase)
Slow Start/Congestion
Avoidance Example
Assume that ssthresh = 8
Cwnd (in segments)

ssthres
h

Roundtrip times
Congestion Detection: Multiplicative Decrease
If congestion occurs, the congestion window size must be
decreased.
The only way a sender can guess that congestion has
occurred is the need to retransmit a segment. This is a
major assumption made by TCP.
Retransmission is needed to recover a missing packet which
is assumed to have been dropped (i.e., lost) by a router that
had so many incoming packets, that had to drop the missing
segment
Congestion Detection: Multiplicative
Decrease

retransmission can occur in one of


two cases:
when the RTO timer times out
when three duplicate ACKs are
received.

In both cases, the size of the threshold is


dropped to half (multiplicative
decrease)
1. If a time-out occurs, there is a stronger
possibility of congestion; a segment has probably
been dropped in the network and there is no
news about the following sent segments. In this
case TCP reacts strongly:

a. It sets the value of the threshold to half of the


current window size.
b. It reduces cwnd back to one segment.
c. It starts the slow start phase again.
2. If three duplicate ACKs are received, there is a weaker
possibility of congestion; a segment may have been
dropped but some segments after that have arrived
safely
since three duplicate ACKs are received. This is called

fast transmission and fast recovery. In this case, TCP has


a weaker reaction as shown below:
a. It sets the value of the threshold to half of the

current window size.


b. It sets cwnd to the value of the threshold


c. It starts the congestion avoidance phase.
TCP Congestion policy summary
Figure 15.37 Congestion example

maximum window size is initially 32 segments. The threshold is


initially set to 16 segments
In the slow start phase the window size starts from 1 and grows
exponentially until it reaches the threshold.
After reaching the threshold, the congestion avoidance (additive
increase) procedure allows the window size to increase linearly
until a time-out occurs or the maximum window size is reached.
The window size was 20 when the time-out happened so the new
threshold is now 10.
Congestion Control
The sender has two additional parameters:
Congestion Window (cwnd) Initial value is 1 MSS
(=maximum segment size) counted as bytes
Slow-start threshold Value (ssthresh) Initial
value is the advertised window size)

Congestion control works in two modes:


Slow start (cwnd < ssthresh)
Congestion avoidance (cwnd >= ssthresh)
Consider the plot below that shows the congestion
window size of a sender using TCP Reno. Answer the
following questions.
TCPTIMERS

To perform its operation smoothly, most


TCP implementations use at least four
timers
Retransmission Timer
Persistence Timer
Keepalive Timer
TIME-WAIT Timer
TCP timers
Retransmission Timer
When a segment is sent, a retransmission timer is
started.
1. When TCP sends the segment in front of the
sending queue, it starts the timer.
2. When the timer expires, TCP resends the first
segment in front of the queue, and restarts the
timer.
3. When a segment (or segments) are cumulatively
acknowledged, the segment (or segments) are
purged from the queue.
4. If the queue is empty, TCP stops the timer;
otherwise, TCP restarts the timer.
Persistence Timer
It is designed to prevent the following deadlock.

The receiver sends an acknowledgement with a window


size of 0, telling the sender to wait. Later, the receiver
updates the window, but the packet with the update is
lost. Now the sender and the receiver are each waiting
for the other to do something.

When the persistence timer goes off, the sender


transmits a probe to the receiver. The response to the
probe gives the window size. If it is still 0, the
persistence timer is set again and the cycle repeats. If it
is nonzero, data can now be sent.
Keep-alive Timer
When a connection has been idle for a long time,
the keep-alive timer may go off to cause one side
to check whether the other side is still there.
Suppose that a client opens a TCP connection to a
server, transfers some data, and becomes silent.
Perhaps the client has crashed. In this case, the
connection remains open forever.
The time-out is usually 2 hours. If the server does
not hear from the client after 2 hours, it sends a
probe segment. If there is no response after 10
probes, each of which is 75 s apart, it assumes that
the client is down and terminates the connection.
Timed Wait Timer
It runs for twice the maximum packet
lifetime to make sure that when a
connection is closed, all packets created
by it have died off.
Example
When employing slow start (cwnd=1 at
time t=0), at what time (in ms) is cwnd >
20KB? Assume a RTT of 20ms and
maximum segment size of 1500 Bytes.
Calculation of RTO (1)
Smoothed RTT: RTTS
Original No value
After 1st measurement RTTS = RTTM
2nd RTTS = (1-)*RTTS + *RTTM
RTT Deviation : RTTD
Original No value
After 1st measurement RTTD = 0.5*RTTM
2nd RTTD = (1-)*RTTD + *|RTTS - RTTM|
Calculation of RTO (2)
Retransmission Timeout (RTO)
Original Initial value
After any measurement
RTO = RTTS + 4RTTD
Example 10 (page 322)
= 1/8
= 1/4
Example 15.3
Let us give a hypothetical example. Figure 15.39
shows part of a connection. The figure shows the
connection establishment and part of the data
transfer phases.
1. When the SYN segment is sent, there is no
value for RTTM, RTTS, or RTTD. The value of RTO
is set to 6.00 seconds. The following shows the
value of these variable at this moment:

2. When the SYN+ACK segment arrives, RTTM is


measured and is equal to 1.5 seconds.
Example 15.3 Continued
3. When the first data segment is sent, a new RTT
measurement starts. No RTT measurement
starts for the second data segment because a
measurement is already in progress. The
arrival of the last ACK segment is used to
calculate the next value of RTTM. Although the
last ACK segment acknowledges both data
segments (cumulative), its arrival finalizes the
value of RTTM for the first segment. The values
of these variables are now as shown below.
Figure 15.39 Example 15.3
Note

TCP does not consider the RTT of a


retransmitted segment in its
calculation of a new RTO.
Example 15.4
Figure 15.40 is a continuation of the previous
example. There is retransmission and Karns
algorithm is applied.

The first segment in the figure is sent, but lost.


The RTO timer expires after 4.74 seconds. The
segment is retransmitted and the timer is set to
9.48, twice the previous value of RTO. This time
an ACK is received before the time-out. We wait
until we send a new segment and receive the ACK
for it before recalculating the RTO (Karns
algorithm).
Figure 15.40 Example 15.4
1511OPTIONS

The TCP header can have up to 40 bytes of


optional information. Options convey
additional information to the destination
or align other options. We can define two
categories of options: 1-byte options and
multiple-byte options. The first category
contains two types of options: end of
option list and no operation. The second
category, in most implementations,
contains five types of options: maximum
segment size, window scale factor,
timestamp, SACK-permitted, and SACK
Figure 15.41 Options
Figure 15.42 End-of-option option
Note

EOP can be used only once.


Figure 15.43 No-operation option
Note

NOP can be used more than once.


Figure 15.44 Minimum-segment-size option
Note

The value of MSS is determined during


connection establishment and does
not change during the connection.
Figure 15.45 Window-scale-factor option
Note

The value of the window scale factor


can be determined only during
connection
establishment; it does not change
during the connection.
Figure 15.46 Timestamp option
Note

One application of the timestamp option


is the calculation of round-trip
time (RTT).
Example 15.5
Figure 15.47 shows an example that calculates
the round-trip time for one end. Everything must
be flipped if we want to calculate the RTT for the
other end.
Figure 15.47 Example 15.5
Note

The timestamp option can also be used


for PAWS.
Figure 15.48 SACK
Example 15.6
Let us see how the SACK option is used to list
out-of-order blocks. In Figure 15.49 an end has
received five segments of data.
Figure 15.49 Example 15.6
Example 15.7
Figure 15.50 shows how a duplicate segment can
be detected with a combination of ACK and SACK.
In this case, we have some out-of-order segments
(in one block) and one duplicate segment. To
show both out-of-order and duplicate data, SACK
uses the first block, in this case, to show the
duplicate data and other blocks to show out-of-
order data. Note that only the first block can be
used for duplicate data. The natural question is
how the sender, when it receives these ACK and
SACK values, knows that the first block is for
duplicate data (compare this example with the
previous example). The answer is that the bytes
in the first block are already acknowledged in the
ACK field; therefore, this block must be a
duplicate.
Figure 15.50 Example 15.7
Example 15.8
Figure 15.51 shows what happens if one of the
segments in the out-of-order section is also
duplicated. In this example, one of the segments
(4001:5000) is duplicated.

The SACK option announces this duplicate data


first and then the out-of-order block. This time,
however, the duplicated block is not yet
acknowledged by ACK, but because it is part of
the out-of-order block (4001:5000 is part of
4001:6000), it is understood by the sender that it
defines the duplicate data.
Figure 15.51 Example 15.8
1512TCPPACKAGE

The TCP header can have up to 40 bytes of


optional information. Options convey
additional information to the destination
or align other options. We can define two
categories of options: 1-byte options and
multiple-byte options. The first category
contains two types of options: end of
option list and no operation. The second
category, in most implementations,
contains five types of options: maximum
segment size, window scale factor,
timestamp, SACK-permitted, and SACK
TopicsDiscussedintheSection
Transmission Control Block TCBs
Timers
Main Module
Input Processing Module
Output Processing Module
Figure 15.52 TCBs
Figure 15.53 TCP/IP protocol suite

Вам также может понравиться