E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
1
EE 586 Communication andSwitching Networks
Lecture 22
October 17, 2012
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Announcements
Quiz 2/3 redo: out tonight by midnight and due in24 hours
Open book and must be done in 45 minutes
(modified by Cheung for EE586; based on K&R original)
2
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Overview
Segment structure
RTT Estimation
Reliable data transfer
Flow control
Connection management
Congestion control
(modified by Cheung for EE586; based on K&R original)
3
TCP: Transmission Control Protocol
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
3-4
underline_base
TCP sender (simplified)
wait
for
event
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
create segment, seq. #: NextSeqNum
pass segment to IP (i.e., send)
NextSeqNum = NextSeqNum + length(data)
if (timer currently not running)
    start timer
 
data received from application above
retransmit not-yet-acked segmentwith smallest seq. #
start timer
timeout
if (y > SendBase) {
    SendBase = y
    /* SendBase–1: last cumulatively ACKed byte */
    if (there are currently not-yet-acked segments)
         start timer
       else stop timer
     }
ACK received, with ACK field value y
Simplified because…
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
3-5
underline_base
TCP sender (simplified)
wait
for
event
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
create segment, seq. #: NextSeqNum
pass segment to IP (i.e., send)
NextSeqNum = NextSeqNum + length(data)
if (timer currently not running)
    start timer
 
data received from application above
retransmit not-yet-acked segmentwith smallest seq. #
start timer
timeout
if (y > SendBase) {
    SendBase = y
    /* SendBase–1: last cumulatively ACKed byte */
    if (there are currently not-yet-acked segments)
         start timer
       else stop timer
     }
ACK received, with ACK field value y
Simplified because…
No duplicate ACKs
No flow ctrl
No congestion ctrl
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-6
TCP: retransmission scenarios
lost ACK scenario
Host B
Host A
Seq=92, 8 bytes of data
ACK=100
Seq=92, 8 bytes of data
X
timeout
ACK=100
Host B
Host A
underline_base
desktop_computer_stylized_medium
desktop_computer_stylized_medium
desktop_computer_stylized_medium
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-7
TCP: retransmission scenarios
lost ACK scenario
Host B
Host A
Seq=92, 8 bytes of data
ACK=100
Seq=92, 8 bytes of data
X
timeout
ACK=100
premature timeout
Host B
Host A
Seq=92, 8 bytes of data
ACK=100
Seq=92,  8
bytes of data
timeout
ACK=120
Seq=100, 20 bytes of data
ACK=120
SendBase=100
SendBase=120
SendBase=120
SendBase=92
underline_base
desktop_computer_stylized_medium
desktop_computer_stylized_medium
desktop_computer_stylized_medium
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-8
TCP: retransmission scenarios
X
cumulative ACK
Host B
Host A
Seq=92, 8 bytes of data
ACK=100
Seq=120,  15 bytes of data
timeout
Seq=100, 20 bytes of data
ACK=120
underline_base
desktop_computer_stylized_medium
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-9
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
arrival of in-order segment with
expected seq #. One other
segment has ACK pending
arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
arrival of segment that
partially or completely fills gap
TCP receiver action
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-10
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
arrival of in-order segment with
expected seq #. One other
segment has ACK pending
arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
arrival of segment that
partially or completely fills gap
TCP receiver action
delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-11
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
arrival of in-order segment with
expected seq #. One other
segment has ACK pending
arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
arrival of segment that
partially or completely fills gap
TCP receiver action
delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
immediately send single cumulative
ACK, ACKing both in-order segments
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-12
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
arrival of in-order segment with
expected seq #. One other
segment has ACK pending
arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
arrival of segment that
partially or completely fills gap
TCP receiver action
delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
immediately send single cumulative
ACK, ACKing both in-order segments
immediately send duplicate ACK,
indicating seq. # of next expected byte
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-13
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
arrival of in-order segment with
expected seq #. One other
segment has ACK pending
arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
arrival of segment that
partially or completely fills gap
TCP receiver action
delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
immediately send single cumulative
ACK, ACKing both in-order segments
immediately send duplicate ACK,
indicating seq. # of next expected byte
immediate send ACK, provided that
segment starts at lower end of gap
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-14
TCP fast retransmit
time-out period oftenrelatively long:
long delay beforeresending lost packet
detect lost segmentsvia duplicate ACKs.
sender often sendsmany segments back-to-back
if segment is lost, therewill likely be manyduplicate ACKs.
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-15
TCP fast retransmit
time-out period oftenrelatively long:
long delay beforeresending lost packet
detect lost segmentsvia duplicate ACKs.
sender often sendsmany segments back-to-back
if segment is lost, therewill likely be manyduplicate ACKs.
if sender receives 3ACKs for same data
(triple duplicate ACKs),
resend unackedsegment with smallestseq #
likely that unackedsegment lost, so dontwait for timeout
TCP fast retransmit
(triple duplicate ACKs),
underline_base
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-16
X
fast retransmit after sender
receipt of triple duplicate ACK
Host B
Host A
Seq=92, 8 bytes of data
ACK=100
timeout
ACK=100
ACK=100
ACK=100
TCP fast retransmit
underline_base
Seq=100, 20 bytes of data
Seq=100, 20 bytes of data
desktop_computer_stylized_medium
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-17
TCP flow control
application
process
TCP socket
receiver buffers
TCP
code
IP
code
application
OS
receiver protocol stack
application may
remove data from
TCP socket buffers ….
… slower than TCP
receiver is delivering
(sender is sending)
from sender
underline_base
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-18
TCP flow control
application
process
TCP socket
receiver buffers
TCP
code
IP
code
application
OS
receiver protocol stack
application may
remove data from
TCP socket buffers ….
… slower than TCP
receiver is delivering
(sender is sending)
from sender
receiver controls sender, sosender wont overflowreceivers buffer by transmittingtoo much, too fast
flow control
underline_base
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-19
TCP flow control
underline_base
Dark upward diagonal
buffered data
free buffer space
rwnd
RcvBuffer
TCP segment payloads
to application process
receiver advertises freebuffer space by includingrwnd value in TCP headerof receiver-to-sendersegments
RcvBuffer size set viasocket options (typical defaultis 4096 bytes)
many operating systemsautoadjust RcvBuffer
sender limits amount ofunacked (in-flight) data toreceiverrwnd value
guarantees receive bufferwill not overflow
receiver-side buffering
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-20
underline_base
Connection Management
before exchanging data, sender/receiver handshake:
agree to establish connection (each knowing the other willingto establish connection)
agree on connection parameters
connection state: ESTAB
connection variables:
seq # client-to-server
         server-to-client
rcvBuffer size
   at server,client
 
application
network
connection state: ESTAB
connection Variables:
seq # client-to-server
          server-to-client
rcvBuffer size
   at server,client
 
application
network
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-21
Q: will 2-way handshakealways work innetwork?
variable delays
retransmitted messages(e.g. req_conn(x)) due tomessage loss
message reordering
cansee other side
Alice
Bob
2-way handshake:
Lets talk
OK
ESTAB
ESTAB
choose x
req_conn(x)
ESTAB
ESTAB
acc_conn(x)
underline_base
Agreeing to establish a connection
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-22
underline_base
Agreeing to establish a connection
2-way handshake failure scenarios:
retransmit
req_conn(x)
ESTAB
req_conn(x)
half open connection!
(no client!)
clientterminates
server
forgets x
connection
x completes
retransmit
req_conn(x)
ESTAB
req_conn(x)
data(x+1)
retransmit
data(x+1)
accept
data(x+1)
choose x
req_conn(x)
ESTAB
ESTAB
acc_conn(x)
desktop_computer_stylized_medium
clientterminates
ESTAB
choose x
req_conn(x)
ESTAB
acc_conn(x)
data(x+1)
accept
data(x+1)
connection
x completes
server
forgets x
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-23
underline_base
TCP 3-way handshake
SYNbit=1, Seq=x
choose init seq num, x
send TCP SYN msg
ESTAB
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
choose init seq num, y
send TCP SYNACK
msg, acking SYN
ACKbit=1, ACKnum=y+1
received SYNACK(x)
indicates server is live;
send ACK for SYNACK;
this segment may contain
client-to-server data
received ACK(y)
indicates client is live
SYNSENT
ESTAB
SYN RCVD
client state
LISTEN
server state
LISTEN
desktop_computer_stylized_medium
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-24
underline_base
TCP: closing a connection
client, server each close their side of connection
send TCP segment with FIN bit = 1
respond to received FIN with ACK
on receiving FIN, ACK can be combined with ownFIN
simultaneous FIN exchanges can be handled
E l e c t r i c a l    &   C o m p u t e r
Department of
Electrical & Computer Engineering
Transport Layer
3-25
underline_base
FIN_WAIT_2
CLOSE_WAIT
FINbit=1, seq=y
ACKbit=1; ACKnum=y+1
ACKbit=1; ACKnum=x+1
 wait for server
close
can still
send data
can no longer
send data
LAST_ACK
CLOSED
TIMED_WAIT
 timed wait
for 2*max
segment lifetime
CLOSED
TCP: closing a connection
FIN_WAIT_1
FINbit=1, seq=x
can no longer
send but can
 receive data
clientSocket.close()
client state
server state
ESTAB
ESTAB
desktop_computer_stylized_medium