7 Transmission Control Protocol (TCP)
7 Transmission Control Protocol (TCP)
(TCP)
Chapter 15
TCP/IP Protocol Suite
2
TCP Services
Process-to-process communication
Stream delivery service
Connection-oriented service
Reliable service
Error control
Flow control
Congestion control
3
Stream Delivery Service
Segment N Segment 1
H H
Stream of bytes
4
TCP Segment Format
5
Control Field
6
TCP Checksum
7
TCP Connection Establishment
Three-way handshaking
Passive
Active open
open seq: 8000
UAPRS F
SYN
seq: 15000
Connection ack: 8001
opened nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
See RFC 793
8
TCP Data Transfer
seq: 8001
Send
request ack: 15001
UAPRS F
Data Receive
bytes: 8001-9
000
Connection Termination
9
Pushing Data and Urgent Data
Pushing
Send immediately, not to wait for window to fill
Set push bit PSH
Deliver as soon as possible, not to wait for data
Urgent
Insert urgent data at beginning of segment
Set urgent bit URG
Urgent pointer defines end of urgent data
Inform receiving application to take action
10
TCP Connection Termination
Three-way handshaking
12
TCP Connection Reset: Denying a Connection
13
TCP Connection Reset: Aborting a Connection
14
Windows in TCP
15
Send Window
2
Segements are pushed
4
Flow control feedback
18
Example of Flow Control
19
Shrinking of Windows
20
Example of Flow Control
Last
New
21
Example of Flow Control
Last
New
22
Example of Flow Control
Last
New
23
Shrinking of Windows – Example
Send
210
Send
24
Window Shutdown
25
Silly Window Syndrome
26
Solution to Syndrome Created by Sender
Nagle’s Algorithm:
1. Send first segment even if it is only 1 byte
2. Accumulate data in output buffer and wait
until receiving acknowledgement or enough
data filled maximum-size segment
3. Repeat step 2 for rest of transmission
27
Solution to Syndrome Created by Receiver
Clark’s Solution
Send acknowledgement but announce
rwnd=0 until enough space for maximum-
size segment or half of receive buffer empty
Delayed Acknowledgement
Delay sending acknowledgement until decent
space available in incoming buffer
Not delayed more than 500 ms
28
Congestion Control
29
Slow Start: Exponential Increase
Sender starts with cwnd = 1 MSS (maximum segment size)
cwnd size increases by 1 MSS for each acknowledged segment
cwnd size increases exponentially until it reaches threshold
1
cwnd
RTT
2
cwnd
RTT
4
cwnd
RTT
8
cwnd 30
Congestion Avoidance: Additive Increase
When cwnd size reaches threshold, congestion avoidance begins
cwnd size increases by 1 MSS when whole window acknowledged
cwnd size increases additively until congestion detected
31
Congestion Detection: Multiplicative Decrease
32
Congestion Example
33
TCP Timers
34
Retransmission Timer
Karn’s Algorithm
Do not consider RTT of retransmitted segment
Do not update RTT until you send segment and receive ACK
TCP uses exponential backoff strategy:
RTOnew = 2 x RTO
35
Retransmission Timer – Example
0.8125 4.875
36
Karn’s Algorithm – Example
0.8125 4.875
4.875 = 9.75
9.75
1.203 6.73
37
Persistence Timer
38
Keepalive Timer
39
TIME-WAIT Timer
40
TCP Options
41
End-of-Option (EOP) Option
42
No-Operation (NOP) Option
43
Maximum-Segment-Size (MSS) Option
44
Window-Scale-Factor Option
45
Timestamp Option
46
Timestamp Option – Measuring RTT
47
SACK-Permitted and SACK Options
48
SACK-Permitted and SACK Options
49
SACK Option – Reporting Out-of-Order
50
SACK Option – Reporting Out-of-Order and Duplicate
51
SACK Option – Reporting Duplicate of Out-of-Order
52