Chap 12 Modified PP2003
Chap 12 Modified PP2003
Transmission
Control Protocol
Objectives
Upon completion you will be able to:
Be able to name and understand the services offered by TCP
Understand TCPs flow and error control and congestion control
Be familiar with the fields in a TCP segment
Understand the phases in a connection-oriented connection
Understand the TCP transition state diagram
Be able to name and understand the timers used in TCP
Be familiar with the TCP options
TCP/IP Protocol Suite
Figure 12.1
Figure 12.2
Stream delivery
Figure 12.4
TCP segments
Figure 12.4
Example 2
Suppose a TCP connection is transferring a file of 5000 bytes.
The first byte is numbered 10001. What are the sequence
numbers for each segment if data is sent in five segments, each
carrying 1000 bytes?
Solution
The following shows the sequence number for each segment:
Segment 1 Sequence Number: 10,001 (range: 10,001 to 11,000)
Segment 2 Sequence Number: 11,001 (range: 11,001 to 12,000)
Segment 3 Sequence Number: 12,001 (range: 12,001 to 13,000)
Segment 4 Sequence Number: 13,001 (range: 13,001 to 14,000)
Segment 5 Sequence Number: 14,001 (range: 14,001 to 15,000)
TCP/IP Protocol Suite
Figure 12.4
Figure 12.5
10
Figure 12.6
Control field
11
Figure 12.7
checksum
12
Note:
The inclusion of the checksum in TCP
is mandatory.
13
Figure 12.8
14
15
Figure 12.9
A server tells
its TCP that it
is ready to make
a connection this is called a
passive open.
rwnd is the
receiver window
size, as we will
see later.
17
18
Figure 12.10
Data transfer
Notice how the ACK
and
SEQ # are
piggybacked.
Push flag means
deliver
the data to the
receiver
as soon as it is
received
(dont put it in a
buffer
and hold until you
have
enough bytes for a
complete segment).
This feature is
usually
ignored.
19
20
21
Figure 12.12
Half-close
y-1
Client is finished,
but Server is not yet
finished. So Server
ACKs the Clients FIN,
but does not signal its
own FIN just yet.
x+1
x+1
z+1
TCP/IP Protocol Suite
22
Connection Reset
23
24
25
Figure 12.13
26
Client states
Server states
27
Figure 12.14
28
Note:
The common value for MSL is
between 30 seconds and 1 minute.
Maximum segment lifetime
(MSL).
29
Figure 12.15
30
Figure 12.16
Simultaneous open
31
Figure 12.17
Simultaneous close
32
Figure 12.18
Denying a connection
33
Figure 12.19
Aborting a connection
34
Flow control regulates the amount of data a source can send before
receiving an acknowledgment from the destination.
35
Figure 12.20
Sliding window
36
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.
TCPs sliding windows are byte
oriented.
TCP/IP Protocol Suite
37
Example 3
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.
38
Example 4
What is the size of the window for host A if the value of rwnd is
3,000 bytes and the value of cwnd is 3,500 bytes?
Solution
The size of the window is the smaller of rwnd and cwnd, which
is 3,000 bytes.
39
Example 5
Figure 12.21 shows an unrealistic example of a sliding
window. 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 yet acknowledged.
Bytes 203 to 208 can be sent without worrying about
acknowledgment. Bytes 209 and above cannot be sent.
40
Figure 12.21
Example 5
41
Figure 12.22
Example 6
42
Figure 12.23
Example 7
Assume the sender has sent bytes 206 to 209. The senders
window shrinks accordingly.
Now the sender receives a packet with an acknowledgment
value of 210 and an rwnd of 5. The value of cwnd is still 20.
Show the new window.
43
Figure 12.24
Example 8
44
Example 9
How can the receiver avoid shrinking the window in the
previous example?
Solution
The receiver needs to keep track of the last acknowledgment
number and the last rwnd. If we add the acknowledgment
number to rwnd we get the byte number following the right
wall. If we want to prevent the right wall from moving to the
left (shrinking), we must always have the following
relationship.
new ack + new rwnd last ack + last rwnd
or
new rwnd (last ack + last rwnd) new ack
TCP/IP Protocol Suite
45
Window shutdown
46
Note:
Some points about TCPs sliding windows:
The size of the window is the lesser of rwnd and cwnd.
The source does not have to send a full windows
worth of data.
The window can be opened or closed by the receiver,
but should not be shrunk.
The destination can send an acknowledgment at any
time as long as it does not result in a shrinking window.
The receiver can temporarily shut down the window;
the sender, however, can always send a segment of one
byte after the window is shut down.
TCP/IP Protocol Suite
47
Figure 12.24
TCP should wait until it has more data before it sends a 1-byt
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 accumula
data in the output buffer and waits until either the receiving
TCP sends 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.
TCP/IP Protocol Suite
48
Figure 12.24
The receiver now reads 1 byte of data, processes it, and send
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.
Or, delay the ack until there is a decent amount of buffer spac
available. Adv -> reduces traffic. Disadv -> the senders timer
end before it receives an ACK.
TCP/IP Protocol Suite
49
50
51
Figure 12.25
Normal operation
52
53
Figure 12.26
Lost segment
54
55
Figure 12.27
56
57
Figure 12.29
58
Delayed segment
Duplicate segment
59
Note:
ACK segments do not consume
sequence numbers and are not
acknowledged.
60
Note:
In modern implementations, a
retransmission occurs if the
retransmission timer expires or three
duplicate ACK segments have arrived.
61
Note:
No retransmission timer is set for an
ACK segment.
62
Note:
Data may arrive out of order and be
temporarily stored by the receiving TCP,
but TCP guarantees that no out-of-order
segment is delivered to the process.
63
Note:
The receiver TCP delivers only ordered
data to the process.
64
Note:
Lost acknowledgments may create
deadlock if they are not properly
handled.
65
66
67
Figure 12.30
Router queues
68
Figure 12.31
Propagatio
n delay +
processing
delay
69
Figure 12.32
70
71
Retransmission policy
Acknowledgment policy
Discard policy
72
Back pressure
Choke point
Implicit signaling
Detecting an implicit signal warning of congestion and
slow down its sending rate. Ex) receiving delayed ACK
Explicit signaling
73
74
Figure 12.33
75
Figure 12.34
76
77
Figure 12.35
78
Figure 12.36
Congestion example
79
80
Retransmission Timer
If an ACK is received before the timer goes off, toss the timer.
If timer goes off before ACK is received, segment is
retransmitted and timer is reset.
To calculate the RTO value, well need a couple other values.
81
Retransmission Timer
After that:
RTT Smoothed = (1-a) x RTT Smoothed + a x RTT Measured
where a normally is set to 1/8.
82
Retransmission Timer
83
Example
10
Let us give a hypothetical example. Figure 12.38 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 RTT M , RTTS , or
RTTD . The value of RTO is initially set to 6.00 seconds. The following
shows the value of these variables at this moment:
RTTM =
RTTS =
RTTD =
RTO = 6.00
84
Example 10
(continued)
RTTM = 1.5
RTTD = 1.5 / 2 = 0.75
RTTS = 1.5
RTO = 1.5 + 4 x 0.75 = 4.5
85
Figure 12.38
Example 10
86
Karns Algorithm
87
Exponential Backoff
88
Example
11
Figure 12.39 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).
89
Figure 12.39
Example 11
90
Persistence Timer
After that sender sends one probe segment every 60s until the windo
is reopened.
TCP/IP Protocol Suite
91
Keepalive Timer
Each time a server hears something from the other side, set
the Keepalive Timer to say, 2 hours. If the server doesnt
hear anything within 2 hours, it sends a probe.
No response after 10 probes (each of which is 75s apart)?
Then terminate the connection.
TIME-WAIT Timer
The time-wait timer (2 MSL) is used during connection termination.
92
12.10 OPTIONS
The TCP header can have up to 40 bytes of optional information.
Options convey additional information to the destination or align other
options.
93
Figure 12.40
Options
94
Figure 12.43
Maximum-segment-size option
95
Figure 12.44
Window-scale-factor option
96
Figure 12.45
Timestamp option
97
Example
12
Figure 12.46 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.
The sender simply inserts the value of the clock (for example,
the number of seconds past from midnight) in the timestamp
field for the first and second segment. When an
acknowledgment comes (the third segment), the value of the
clock is checked and the value of the echo reply field is
subtracted from the current time. RTT is 12 s in this scenario.
98
Example 12
(Continued)
99
Example 12
(Continued)
Note that as the example shows, the RTT calculated is the time
difference between sending the first segment and receiving the
third segment. This is actually the meaning of RTT: the time
difference between a packet sent and the acknowledgment
received. The third segment carries the acknowledgment for
the first and second segments.
100
Figure 12.46
Example 12
SACK-permitted
102
SACK
103
Figure 12.47
104
Example
13
Let us see how the SACK option is used to list out-of-order blocks. In
Figure 12.48 an end has received five segments of data.
The first and second segments are in consecutive order. An accumulative
acknowledgment can be sent to report the reception of these two segments.
Segments 3, 4, and 5, however, are out of order with a gap between the
second and third and a gap between the fourth and the fifth. An ACK and a
SACK together can easily clear the situation for the sender. The value of
ACK is2001, which means that the sender need not worry about bytes 1 to
2000. The SACK has two blocks. The first block announces that bytes 4001
to 6000 have arrived out of order. The second block shows that bytes 8001
to 9000 have also arrived out of order. This means that bytes 2001 to 4000
and bytes 6001 to 8000 are lost or discarded. The sender can resend only
these bytes.
TCP/IP Protocol Suite
105
Figure 12.48
Example 13
106
Example
14
The example in Figure 12.49 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.
TCP/IP Protocol Suite
107
Figure 12.49
Example 14
108
Example
15
The example in Figure 12.50 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 outof-order block (4001:5000 is part of 4001:6000), it is
understood by the sender that it defines the duplicate data.
109
Figure 12.50
Example 15
110