Title: CS492B Project
1CS492B Project 2 TCP Tutorial 1
2CS244a An Introduction to Computer Networks
- Handout 6 The Transport Layer, User Datagram
Protocol (UDP) , and Transmission Control
Protocol (TCP)
Nick McKeown Professor of Electrical Engineering
and Computer Science, Stanford
University nickm_at_stanford.edu http//www.stanford.
edu/nickm
3Outline
- The TCP Protocol
- TCP Characteristics
- TCP Connection setup
- TCP Segments
- TCP Sequence Numbers
- TCP Sliding Window
- ACK Policy
- Timeouts and Retransmission
- (Congestion Control and Avoidance)
4TCP Characteristics
- TCP is connection-oriented.
- TCP provides a stream-of-bytes service.
- TCP is reliable
- Acknowledgements indicate delivery of data.
- Checksums are used to detect corrupted data.
- Sequence numbers detect missing, or mis-sequenced
data. - Corrupted data is retransmitted after a timeout.
- Mis-sequenced data is re-sequenced.
- (Window-based) Flow control prevents over-run of
receiver. - TCP uses congestion control to share network
capacity among users. Well study this in the
next lecture.
5TCP is connection-oriented
(Active) Client
(Passive) Server
(Active) Client
(Passive) Server
Syn
Fin
Syn Ack
(Data ) Ack
Ack
Fin
Ack
TIME_WAIT
CLOSED
Connection Setup 3-way handshake
Connection Close/Teardown 2 x 2-way handshake
6TCP supports a stream of bytes service
Host A
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
Host B
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
7which is emulated using TCP segments
Host A
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
- Segment sent when
- Segment full (MSS bytes),
- Not full, but times out, or
- Pushed by application.
TCP Data
TCP Data
Host B
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
8The TCP Segment Format
TCP Hdr
TCP Data
0
15
31
Src port
Dst port
Sequence
Ack Sequence
Flags
Window Size
HLEN 4
RSVD 6
URG
ACK
PSH
RST
SYN
FIN
Checksum
Urg Pointer
(TCP Options)
TCP Data
9Sequence Numbers
Host A
ISN (initial sequence number)
Sequence number 1st byte
TCP HDR
TCP Data
Ack sequence number next expected byte
TCP HDR
TCP Data
Host B
10Initial Sequence Numbers
(Active) Client
(Passive) Server
Syn ISNA
Syn Ack ISNB
Ack
Connection Setup 3-way handshake
11TCP Window
- Pipelining
- Retransmission
- Flow control
- (Congestion control)
12TCP Sliding Window
- How much data can a TCP sender have outstanding
in the network? - How much data should TCP retransmit when an error
occurs? Just selectively repeat the missing data? - How does the TCP sender avoid over-running the
receivers buffers?
13TCP Sliding Window
Window Size
Outstanding Un-ackd data
Data OK to send
Data not OK to send yet
Data ACKd
ACK
- Retransmission policy is Go Back N.
- Current window size is advertised by receiver
- (usually 4k 8k Bytes when connection set-up).
14TCP Sliding Window
Round-trip time
Window Size
Host A
Host B
ACK
ACK
(1) RTT gt Window size
15Delayed ACK
- Data types in TCP segment
- Bulk data (FTP, Email, News, HTTP) 90
- Interactive data (Telnet, Rlogin) 10
- one key-stroke generates one segment, carrying
only 1 byte. - 90 of Telnet Rlogin packets carry less than 10
bytes of user data - TCP can be silly without any optimization!
16Delayed ACK
Event in-order segment arrival, no
gaps, everything else already ACKed in-order
segment arrival, no gaps, one delayed ACK
pending out-of-order segment arrival 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
send duplicate ACK, indicating seq. of next
expected byte immediate ACK if segment
starts at lower end of gap
17TCP Retransmission and Timeouts
Round-trip time (RTT)
Retransmission TimeOut (RTO)
Guard Band
Host A
Estimated RTT
Data1
Data2
ACK
ACK
Host B
TCP uses an adaptive retransmission timeout
value Congestion Changes in Routing
RTT changes frequently
18TCP Retransmission and Timeouts
- Picking the RTO is important
- Pick a values thats too big and it will wait too
long to retransmit a packet, - Pick a value too small, and it will unnecessarily
retransmit packets. - The original algorithm for picking RTO
- EstimatedRTT ? EstimatedRTT (1 - ?)
SampleRTT - RTO 2 EstimatedRTT
- Characteristics of the original algorithm
- Variance is assumed to be fixed.
- But in practice, variance increases as congestion
increases.
19TCP Retransmission and Timeouts
- Newer Algorithm includes estimate of variance in
RTT - Difference SampleRTT - EstimatedRTT
- EstimatedRTT EstimatedRTT (?Difference)
- Deviation Deviation ?( Difference -
Deviation ) - RTO ? EstimatedRTT ? Deviation
- ? ? 1
- ? ? 4
20TCP Retransmission and TimeoutsKarns Algorithm
Host A
Host B
Host A
Host B
Retransmission
Retransmission
Wrong RTT Sample
Wrong RTT Sample
Problem How can we estimate RTT when packets
are retransmitted? Solution On retransmission,
dont update estimated RTT (and double RTO).