Vous êtes sur la page 1sur 110

Chapter 12

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

TCP/IP protocol suite

TCP provides a set of services. What are those services?


TCP/IP Protocol Suite

TCP provides a process-to-process communication service


using port numbers.

Table 12.1 Well-known ports used by TCP

TCP/IP Protocol Suite

Figure 12.2

TCP/IP Protocol Suite

Stream delivery

Figure 12.4

TCP segments

TCP provides a stream delivery service. It breaks up the da


stream into segments of variable size. Each segment receiv
a header and is handed off to the IP layer.
** Because the sending and the receiving processes
may not necessarily write or read data
at the same rate, TCP needs buffers for storage.

TCP/IP Protocol Suite

Figure 12.4

TCP services and features

TCP can create a full-duplex service. Data can flow in


both
directions at the same time; buffers on each side hold
the
data to be transmitted and sent.
TCP provides a connection-oriented service: the two
TCPs
establish a connection, data is exchanged, and the
connection is
terminated.
TCP provides a reliable service.
Furthermore, TCP has a number of features.
All bytes transferred are numbered by TCP. The
numbering
starts with a random value (0->2^32 -1).
*there are two fields called the sequence number and
the Suite
TCP/IP Protocol

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

The value in the sequence number field of a


segment defines the number of the first data
byte contained in that segment.
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.

TCP/IP Protocol Suite

Figure 12.4

TCP services and features

TCP also provides


1.flow control,
2.error control, and
3.Congestion control.
We will examine each of these shortly.
Before we do, lets examine the TCP header a little more
closely.
The TCP packet is called a segment (but most people just
call it a packet).

TCP/IP Protocol Suite

Figure 12.5

TCP segment format (packets in TCP are called segments)

Window size set by receiver with max = 65,535 bytes


TCP/IP Protocol Suite

10

Figure 12.6

Control field

More on these bits later.

TCP/IP Protocol Suite

11

Figure 12.7
checksum

TCP/IP Protocol Suite

Pseudoheader added to the TCP datagram to calculate

12

Note:
The inclusion of the checksum in TCP
is mandatory.

TCP/IP Protocol Suite

13

Figure 12.8

TCP/IP Protocol Suite

Encapsulation and decapsulation

14

12.4 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.
The topics discussed in this section include:
Connection Establishment
Data Transfer
Connection Termination
Connection Reset

TCP/IP Protocol Suite

15

Figure 12.9

Connection establishment using three-way handshaking

A server tells
its TCP that it
is ready to make
a connection this is called a
passive open.

TCP/IP Protocol Suite

Should this be 8001?


No , because it is SYN segment
Cannot carrying data

rwnd is the
receiver window
size, as we will
see later.

Note: SYN bit


is set in first
packet; 8000
chosen randomly
16

A SYN segment cannot carry data, but it


consumes one sequence number.

A SYN + ACK segment cannot carry


data, but does consume one
sequence number.
An ACK segment, if carrying no data,
consumes no sequence number.

TCP/IP Protocol Suite

17

SYN flooding attack

Bad person -> large number of SYN


segments (with fake IP addresses) to a
server ->server allocates the necessary
resources (e.g. TCB tables and setting
timers) -> server sends SYN+ACK
segments to fake clients which are lost.
If the number of SYN segments is large,
the server eventually runs out of
resources and may crash.
To counter these attacks, some servers
postpone resource allocation until the
entire connection is set up using a
cookie.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

19

Can also send Urgent data by setting the


URG bit. The sending TCP creates a
segment and inserts the urgent data at
the beginning of the segment (the
segment can also contain normal data).
For example, you want to send a Ctrl-C
to stop. In this case, Urgent Pointer =
last urgent byte + 1. When the
receiving TCP receives a segment with
the URG bit set, it extracts the urgent
data from the segment using the value
of URG pointer and delivers it out of
order to the receiving application
program.
TCP/IP Protocol Suite

20

Figure 12.11 Connection termination using three-way handshaking

A FIN segment consumes one sequence number if


it does not carry data. So should third segment be
seq: x+1?
* a FIN segment can include the last chunk of data
sent
TCP/IP Protocol
Suite by the client

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

Using the Reset flag (RST), one can:


Deny a request for a connection
Abort a current connection
Terminate an idle connection

TCP/IP Protocol Suite

23

12.5 STATE TRANSITION DIAGRAM


To keep track of all the different events happening during connection
establishment, connection termination, and data transfer, the TCP
software is implemented as a finite state machine. .

The topics discussed in this section include:


Scenarios

TCP/IP Protocol Suite

24

Table 12.3 States for TCP

TCP/IP Protocol Suite

25

Figure 12.13

TCP/IP Protocol Suite

State transition diagram

26

Client states

Server states

TCP/IP Protocol Suite

27

Figure 12.14

TCP/IP Protocol Suite

Connection establishment and termination

28

Note:
The common value for MSL is
between 30 seconds and 1 minute.
Maximum segment lifetime
(MSL).

TCP/IP Protocol Suite

29

Figure 12.15

TCP/IP Protocol Suite

Connection termination using three-way handshake

30

Figure 12.16

TCP/IP Protocol Suite

Simultaneous open

31

Figure 12.17

TCP/IP Protocol Suite

Simultaneous close

32

Figure 12.18

TCP/IP Protocol Suite

Denying a connection

33

Figure 12.19

TCP/IP Protocol Suite

Aborting a connection

34

12.6 FLOW CONTROL

Flow control regulates the amount of data a source can send before
receiving an acknowledgment from the destination.

The topics discussed in this section include:


Sliding Window Protocol
Silly Window Syndrome

TCP/IP Protocol Suite

35

Figure 12.20

Sliding window

rwnd is the receiver window size; cwnd is the congestion


window size

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

40

Figure 12.21

Example 5

Next, 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.
TCP/IP Protocol Suite

41

Figure 12.22

Example 6

Next, 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.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

43

Figure 12.24

TCP/IP Protocol Suite

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

To avoid shrinking the sender window, the receiver


must wait until more space is available in its buffer.

Window shutdown

The receiver can temporarily shut down the


window by sending an rwnd of 0, if the
receiver does not want to receive any data
from the sender for a while.
The sender does not actually shrink the
size of the window, but stops sending data
until a new advertisement has arrived.
Even when the window is shut down by an
order from the receiver, the sender can
always send a segment with one byte of
data (probing) to prevent a deadlock.

TCP/IP Protocol Suite

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

Silly Window Syndrome

Silly Window Syndrome (Slow sender or receiver)- 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.
Very wasteful!

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

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 receiv
tells the sender to stop (window size = 0).

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.

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 spac
available. Adv -> reduces traffic. Disadv -> the senders timer
end before it receives an ACK.
TCP/IP Protocol Suite

49

12.7 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.
The topics discussed in this section include:
Checksum
Acknowledgment
Acknowledgment Type
Retransmission
Out-of-Order Segments
Some Scenarios

TCP/IP Protocol Suite

50

TCP Error Control

TCP supports basic error control.


It uses a 16-bit arithmetic checksum, similar to the ones
we have already seen.
TCP uses the ACK message to confirm receipt of segments.
There is a number of basic rules pertaining to ACKs:
Rule 1: When one ends sends data, it must piggyback the
ACK for any data received. (Example in just a moment)
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.
TCP/IP Protocol Suite

51

Figure 12.25

TCP/IP Protocol Suite

Normal operation

52

TCP Error Control

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. (Example
on previous slide)
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, which we will see shortly.
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 received. (Example on next slide)
Rule 6: If a duplicate segment arrives, receiver immediately
sends an ACK. This solves some problems when an ACK
itself is lost. (Example on next slide)
TCP/IP Protocol Suite

53

Figure 12.26

TCP/IP Protocol Suite

Lost segment

54

TCP Error Control

Furthermore, a retransmission will occur if the retransmission


timer (RTO) expires, or three duplicate ACKs arrive in order.
(For RTO example, see previous slide.)
(For three ACKs, see next slide.)

TCP/IP Protocol Suite

55

Figure 12.27

TCP/IP Protocol Suite

Three ACKs in a row, fast retransmission

56

Figure 12.28 Lost acknowledgment

TCP/IP Protocol Suite

57

Figure 12.29

TCP/IP Protocol Suite

Lost acknowledgment corrected by resending a segment

58

Delayed segment

Delayed TCP segment are treated the


same way as lost or corrupted segments
by the receiver.
The delayed segment may arrive after it
has been resent (a duplicate segment)

Duplicate segment

When a segment arrives that contains a


sequence number less than the
previously acknowledged bytes, it is
discarded.

TCP/IP Protocol Suite

59

Note:
ACK segments do not consume
sequence numbers and are not
acknowledged.

TCP/IP Protocol Suite

60

Note:
In modern implementations, a
retransmission occurs if the
retransmission timer expires or three
duplicate ACK segments have arrived.

TCP/IP Protocol Suite

61

Note:
No retransmission timer is set for an
ACK segment.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

63

Note:
The receiver TCP delivers only ordered
data to the process.

TCP/IP Protocol Suite

64

Note:
Lost acknowledgments may create
deadlock if they are not properly
handled.

TCP/IP Protocol Suite

65

Deadlock created by lost


ACK

Receiver -> rwnd = 0 -> ACK (if it


has no data to send)
ACK -> lost (problem)
Deadlock -> each end is waiting for a
response from the other end and
nothing is happening.
Solution -> Persistence timer is used
(discussed later)

TCP/IP Protocol Suite

66

12.8 CONGESTION CONTROL


Congestion control refers to the mechanisms and techniques to keep the
load below the capacity.
Congestion in a network may occur if the load on the
network (number of packets sent to the network) is
greater than the capacity of the network (the
number of packets a network can handle).
Congestion in a network or internetwork occurs
because routers and switches have queues

TCP/IP Protocol Suite

67

Figure 12.30

TCP/IP Protocol Suite

Router queues

68

Figure 12.31

Packet delay and network load

Propagatio
n delay +
processing
delay

TCP/IP Protocol Suite

69

Figure 12.32

TCP/IP Protocol Suite

Throughput versus network load

The reason is the


discarding of packets by
the routers

70

Congestion control mechanisms

refers to techniques and mechanisms


that can either prevent congestion,
before it happens, or remove
congestion, after it has happened

open-loop congestion control (prevention)


and closed loop congestion control (removal)

TCP/IP Protocol Suite

71

Open-loop congestion control

Retransmission policy

Acknowledgment policy

The retransmission policy and the retransmission timers must


be designed to optimize efficiency and at the same time
prevent congestion

If the receiver does not acknowledge every packet it receives, it


may slow down the sender and help prevent congestion

Discard policy

In audio transmission, if the policy is to discard less sensitive


packets when congestion is likely, the quality of sound is still
preserved and congestion is prevented

TCP/IP Protocol Suite

72

Closed-loop congestion control

Back pressure

Choke point

informing the previous upstream router to reduce the


rate of outgoing packets
is a packet sent by a router to the source to inform it of
congestion
is similar to ICMPs source quench packet

Implicit signaling
Detecting an implicit signal warning of congestion and
slow down its sending rate. Ex) receiving delayed ACK

Explicit signaling

Router experiencing congestion can send an explicit


signal by setting a bit in a packet to the sender or the
receiver

TCP/IP Protocol Suite

73

TCP Congestion Control

Actual window size = minimum (rwnd, cwnd)


TCPs general policy for handling congestion is based
on
three phases: slow start, congestion avoidance and
congestion detection.
Slow start algorithm - cwnd starts at 1. With each ACK
received, cwnd doubles. So second time cwnd = 2, then
4, then 8, etc.
The cwnd value does not increase forever. cwnd stops
when it equals ssthresh (slow start threshold), which
has a max size of 65,535.
When cwnd equals ssthresh, slow start stops and
additive
phase begins. Additive phase increases the cwnd by 1
TCP/IP Protocol
Suite
each
time an ACK is received.

74

Figure 12.33

TCP/IP Protocol Suite

Slow start, exponential increase

75

Figure 12.34

TCP/IP Protocol Suite

Congestion avoidance, additive increase

76

TCP Congestion Control, Congestion detection

What happens if congestion occurs?


1. If an RTO timer times out, there is probably congestion.
So cut the threshold in half,
set cwnd back to 1,
and
restart the slow start phase again.
2.If three ACKs in a row are received, there may be
congestion. So
cut the threshold in half,
set cwnd to the value of the threshold, and
restart the avoidance phase.

TCP/IP Protocol Suite

77

Figure 12.35

TCP/IP Protocol Suite

TCP congestion policy summary

78

Figure 12.36

TCP/IP Protocol Suite

Congestion example

79

12.9 TCP TIMERS


To perform its operation smoothly, most TCP implementations use at
least four timers:
Retransmission Timer
Persistence Timer
Keepalive Timer
TIME-WAIT Timer

TCP/IP Protocol Suite

80

Retransmission Timer

To retransmit a lost segment, TCP employs a retransmission


timer that handles the retransmission time-out (RTO), the
waiting time for an ACK of a segment.

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.

TCP/IP Protocol Suite

81

Retransmission Timer

The first value we need to know is the round


trip time (RTT) of sending a segment and then getting
the ACK.
To calculate RTT, we could use the RTT Measured value
(simply time ACK received minus time packet sent),
but this value varies greatly on todays Internet.
So instead, we will calculate RTT Smoothed.
First time: RTT Smoothed = RTT Measured

After that:
RTT Smoothed = (1-a) x RTT Smoothed + a x RTT Measured
where a normally is set to 1/8.

TCP/IP Protocol Suite

82

Retransmission Timer

Most implementations also use the RTT Deviation.


First time: RTT Deviation = RTT Measured / 2
After that:
RTT Deviation = (1-b) x RTT Deviation +
b x |Smoothed RTT - Measured RTT|
Where b usually equals 1/4.
Finally, RTO = RTT Smoothed + 4 x RTT Deviation

TCP/IP Protocol Suite

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

2. When the SYN+ACK segment arrives, RTTM is measured and is equal to


1.5 seconds. The next slide shows the values of these variables:
TCP/IP Protocol Suite

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

3.When the first data segment is sent, a new RTT measurement


starts. Note that the sender does not start an RTT measurement
when it sends the ACK segment, because it does not consume a
sequence number and there is no time-out. No RTT
measurement starts for the second data segment because a
measurement is already in progress.
RTTM = 2.5
RTTS = 7/8 (1.5) + 1/8 (2.5) = 1.625
RTTD = 3/4 (0.75) + 1/4 |1.625 2.5| = 0.78

TYPO HERE IN BOOK!!

RTO = 1.625 + 4 (0.78) = 4.74


TCP/IP Protocol Suite

85

Figure 12.38

TCP/IP Protocol Suite

Example 10

86

Karns Algorithm

When the sending TCP receives an ACK for a segment, is this


the ACK for the original segment, or for the retransmitted
segment?
Depending upon which one you choose can affect the
calculation of your RTO timer.
So Karn says do not consider the round trip time of a
retransmitted segment in the calculation of the new RTT.
Do not update the value of RTT until you send a segment
and receive an ACK without the need for retransmission.

TCP/IP Protocol Suite

87

Exponential Backoff

What is the value of RTO if a retransmission occurs?


Most TCP implementations use an exponential backoff
strategy.
The value of RTO is doubled for each retransmission.
See the next slide for an example of this.

TCP/IP Protocol Suite

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).

TCP/IP Protocol Suite

89

Figure 12.39

TCP/IP Protocol Suite

Example 11

90

Persistence Timer

What if a receiver sends you a window size of 0?


You stop transmitting until you receive an ACK with a new window siz
What happens if this ACK is lost? Deadlock occurs.
When the sending TCP receives an acknowledgment with
a window size of zero, the persistence timer is started.
When persistence timer goes off, the sending TCP sends
a special segment called a probe.
The probe alerts the receiving TCP that the acknowledgment
was lost and should be resent.

If a response is not received, the sender continues sending the


probe segments and doubling, and resetting the value of the
persistence timer until the value reaches a threshold (usually 60 seco

After that sender sends one probe segment every 60s until the windo
is reopened.
TCP/IP Protocol Suite

91

The Other Timers

Keepalive Timer

If two sides transfer data and then go silent, is the connectio


still valid? Or did it die somehow?

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.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

93

Figure 12.40

TCP/IP Protocol Suite

Options

94

Figure 12.43

Maximum-segment-size option

This option (set during connection establishment) defines


the maximum size of the data field within a segment.
Max size is 65,536 bytes; default is 536 bytes.

TCP/IP Protocol Suite

95

Figure 12.44

Window-scale-factor option

In case a window size of 16 bits (65,536 bytes) is not big


enough, you can set the window-scale factor.

The new window size if found by first raising 2 to the numbe


specified in the window scale factor, then this result is
multiplied by the value of the window size in the header.

For example, if window size in header is already set at 32,768


and scale factor = 3, then 2^3 * 32768 = 262,144 bytes.
This can only be set during connection establishment.
TCP/IP Protocol Suite

96

Figure 12.45

Timestamp option

Can use this option to calculate round trip time RTT.

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

98

Example 12

(Continued)

The receivers function is more involved. It keeps track of the


last acknowledgment sent (12000). When the first segment
arrives, it contains the bytes 12000 to 12099. The first byte is
the same as the value of lastack. It then copies the timestamp
value (4720) into the tsrecent variable. The value of lastack is
still 12000 (no new acknowledgment has been sent). When the
second segment arrives, since none of the byte numbers in this
segment include the value of lastack, the value of the
timestamp field is ignored. When the receiver decides to send
an accumulative acknowledgment with acknowledgment
12200, it changes the value of lastack to 12200 and inserts the
value of tsrecent in the echo reply field. The value of tsrecent
will not change until it isreplaced by a new segment that
carries byte 12200 (next segment).
TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

100

Figure 12.46

TCP/IP Protocol Suite

Example 12

The time-stamp option can also be used


for PAWS (protection against wrapped
101
sequence numbers)

SACK-permitted

Used only during connection


establishment.
The host that sends the SYN segment
adds this option to show that it can
support the SACK option.
If the other end, in its SYN + ACK
segment, also includes this option,
then the two ends can use the SACK
option during data transfer.

TCP/IP Protocol Suite

102

SACK

Is used during data transfer only if both


ends agree.
The option includes a list for blocks
arriving out-of-order.
Each block occupies two 32 bit numbers
that define the beginning and the end
of the blocks.
A SACK option cannot define more than
4 blocks.
The first block can be used to report the
duplicates. This is used only if the
implementation allows this feature.

TCP/IP Protocol Suite

103

Figure 12.47

TCP/IP Protocol Suite

SACK (Selective Acknowledgment)

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

TCP/IP Protocol Suite

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

TCP/IP Protocol Suite

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.

TCP/IP Protocol Suite

109

Figure 12.50

TCP/IP Protocol Suite

Example 15

110

Vous aimerez peut-être aussi