Vous êtes sur la page 1sur 22

Chapter 3

Transport Layer
Computer Networking: A
Top Down Approach
4th edition.
Jim Kurose, Keith Ross
Addison-Wesley, July
2007.

Last Lecture
Selective Repeat (SR)
TCP
Segment Structure
Sequence Numbers
Acknowledgements

Todays Lecture
TCP Reliable Delivery
Is TCP Go-Back N or Selective
Repeat?

TCP Segment Structure


URG: urgent data
ACK?
PSH?
RST, SYN, FIN:
connection estab
(setup, teardown
commands)
Same as in UDP
To negotiate maximum
segment size etc.

source port #
dest port #
sequence number
acknowledgement number

head not
len used

UA P R S F Receive window
Urg data pointer
checksum

Options (variable length)


application
data
(variable length)

Used in
implementing
a reliable
data transfer
Used for
flow control

TCP Sequence Numbers and ACKs


Sequence Numbers:
Sequence nos. are over the stream of transmitted
bytes and not over the series of transmitted
segments
Sequence no. is the byte stream number of first
byte in segments data
Example:

Host A wants to send data to Host B


File consisting of 500,000 bytes, MSS is 1,000 bytes
First byte of stream is numbered zero
TCP constructs 500 segments out of data stream
First segment gets sequence number --- 0
Second segment gets sequence number----1000
Third segment gets sequence number------2000 and so on

TCP Sequence Numbers


Imagine a TCP connection is transferring a file of

6000 bytes. The first byte is numbered 10010. What


are the sequence numbers for each segment if data is
sent in five segments with the first four segments
carrying 1,000 bytes and the last segment carrying
2,000 bytes?

TCP Sequence Numbers


The following shows the sequence number for
each segment:
Segment 1 10,010

(10,010 to 11,009)

Segment 2 11,010

(11,010 to 12,009)

Segment 3 12,010

(12,010 to 13,009)

Segment 4 13,010

(13,010 to 14,009)

Segment 5 14,010

(14,010 to 16,009)

TCP ACKs
Acknowledgement Numbers:

The acknowledgement no that hosts A puts in its segment is


the sequence no of the next byte host A is expecting from
host B.

Example
Host A receives all bytes numbered 0 through 535 from B
Host A puts 536 in the acknowledgment number field of the
segment it sends to B
TCP acknowledges bytes up to first missing bytes in the stream
Cumulative Acknowledgement
How receiver handles out-of-order segments?
TCP RFCs do not impose any rules
Two choices
o The receiver discards out of order segments
o Keeps out of order bytes and waits for missing bytes to fill

TCP Sequence Numbers and ACKs


Example:
Host A sends a
character to Host B,
which echoes it back to
Host A.
Starting Sequence no
for client and server are
42 and 79.
Piggybacking:
Acknowledgement of
client to server data is
carried by segment of
server to client data

Host B

Host A
User
types
C

Seq=4
2, AC
K

C
79, A
=
q
e
S

host ACKs
receipt
of echoed
C

=79, d

K= 4

ata =
C

ta =
3, da

host ACKs
receipt of
C, echoes
back C

Piggybacked
Seq=4
3,

ACK=8
0

time

TCP Flow Control


Eliminate the possibility of sender overflowing
receivers buffer by transmitting too much, too
fast.
Sender maintains a variable receive window

Gives the sender an idea of how much free space is


available at receiver
Example
Host A is sending a large file to host B
Host B allocates a receive buffer and denotes size by
RcvBuffer
LastByteRead
The number of the last byte read from buffer by
process in Host B
LastByteRcvd:
The number of last byte that has been placed in buffer
at B

TCP Flow Control


RcvWindow is set to the amount of spare room in the buffer
RcvWindow= RcvBuffer - [LastByteRcvd - LastByteRead]

Host B informs Host A about how much spare room it has in


the connection buffer.

Places RcvWindow in the receive window field of every segment

Host A keeps track of two variables

TCP Flow Control


LastByteSent LastByteAcked

It is the amount of unacknowledged data that A has sent


into the connection

LastByteSent LastByteAcked

RcvWindow

Keeping the unacknowledged data less than the value of


RcvWindow

Suppose RcvWindow=0

Host B advertises RcvWindow=0 to Host A


Suppose Host B has nothing to send to host A
TCP specification require Host A to send one byte of data
Persistence Timer?

TCP Reliable Data Transfer


TCP creates reliable data transfer service on top of

IPs unreliable service


TCP uses single retransmission timer, even if there
are multiple unacknowledged segments (RFC 2988)
Uses cumulative acknowledgements
Retransmissions are triggered by:

Timeout
Duplicate Acks ( will see shortly)

Initially consider simplified TCP sender:


Ignore Duplicate Acks
Ignore Flow control

TCP Sender Events:


(1) Data Rcvd from
Application Layer
Create segment with
sequence number.
Sequence number is bytestream number of first data
byte in segment.
Start timer if not already
running.
Expiration Interval:
Will study in next lecture

(2) Timeout:
Retransmit segment
Restart timer
(3)Ack Received:
If acknowledges previously
unACked segments
Update what is known
to be ACKed
Start timer if there
are outstanding
segments

NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
loop (forever) {
switch(event)
event: data received from application above
create TCP segment with sequence number NextSeqNum
if (timer currently not running)
start timer
pass segment to IP
NextSeqNum = NextSeqNum + length(data)
event: timer timeout
retransmit not-yet-acknowledged segment with
smallest sequence number
start timer
event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
} /* end of loop forever */

TCP
Sender
(Simplified)

TCP: Retransmission Scenarios


Host A

tes da
t

=100
K
C
A

loss
Seq=9
2, 8 b
y

tes da
t

=1 0 0
ACK

SendBase
= 100
time

Seq=92 timeout

timeout

Seq=9
2, 8 b
y

Seq=9
2, 8 b
ytes d
ata
Seq=
100,
20 by
tes d
ata
0
=10 120
K
AC ACK=

Seq=9
2, 8 b
y

Sendbase
= 100
SendBase
= 120
SendBase
= 120

Lost ACK Scenario

Host B

Host A

Host B

tes da
t

20
K=1
C
A

time

Premature Timeout

TCP Retransmission Scenarios


Host A

timeout

Seq=9
2, 8 b
y

SendBase
= 120

Host B
tes da
t

= 1 00
Seq=1
K
C
A
00, 20
bytes
data

loss
=1 2 0
AC K

time
Cumulative ACK scenario

TCP ACK Generation


Event at Receiver
Arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed

[RFC 1122, RFC 2581]

TCP Receiver action


Delayed ACK. Wait up to 500ms
for next in order segment. If no next
segment, send ACK

Arrival of in-order segment with Immediately send single cumulative


ACK, ACKing both in-order segments
expected seq #. One other
Inorder segment has ACK pending
Arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected

Immediately send duplicate ACK,


indicating seq. # of next expected byte

Fast Retransmit
Time-out period often

relatively long:

long delay before


resending lost packet

Detect lost segments

via duplicate ACKs.

Sender often sends


many segments back-toback
If segment is lost,
there will likely be many
duplicate ACKs.

If sender receives 3 ACKs

for the same data, it


supposes that segment after
ACKed data was lost:

Fast Retransmit: resend


segment before timer
expires

Host A

Host B

timeout

r es en

d 2 nd

segme

nt

time
Resending a Segment after Triple Duplicate ACK

Fast Retransmit Algorithm:


event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
else {
increment count of duplicate ACKs received for y
if (count of duplicate ACKs received for y ==3) {
resend segment with sequence number y
}

Fast Retransmit

Go-Back N or Selective Repeat


GBN Protocol
TCP acknowledgements are cumulative and out of order
segments are not individually acked.
Difference

Buffering of correctly received packets


GBN transmits all packets after the lost packet
TCP only the missing packet

Selective Repeat
Buffering of out of order packets
TCP SACK (RFC 2018) allows to ACK out of order packets
selectively rather than cumulatively
Difference

Timer with every packet

Hybrid of Go-Back N and Selective Repeat

Vous aimerez peut-être aussi