3. 3
Ports, End-points, & Connections
• Thus, an end-point is represented by (IP address,Port)
• Ports can be re-used between transport protocols
• A connection is (SRC IP address, SRC port, DST IP address,
DST port)
• Same end-point can be used in multiple connections
IP Layer
TCP UDP
http ftp email zoom
IP address
Protocol ID
A1 A2 A3
Transport
Port
4. 4
Active and Passive Open
• How do applications initiate a connection?
• One end (server) registers with the TCP layer instructing it to
“accept” connections at a certain port
• The other end (client) initiates a “connect” request which is
“accept”-ed by the server
5. 5
Connection Establishment & Termination
• 3-way handshake used
for connection
establishment
• Randomly chosen
sequence number is
conveyed to the other
end
• Similar FIN, FIN+ACK
exchange used for
connection termination
SYN
SYN+ACK
ACK
DATA
Server does passive open
Accept connection request
Send acceptance
Start connection
Active open
Send connection
request
7. 7
Fundamental Mechanism
• Simple stop and go protocol
• Timeout based reliability (loss
recovery)
data
retx
ack
data
ack
data
Sliding Window Protocol: 1 2 3 4 5 6 7 8 9 10 11 12 ….
• Multiple unacknowledged packets!
8. 8
Congestion Control
• Slow Start
• Start with W=1
• For every ACK, W=W+1
• Congestion Avoidance (linear
increase)
• For every ACK,
• W = W+1/W
• Congestion Control
(multiplicative decrease)
• ssthresh = W/2
• W = 1
Alternative: Fall to W/2 and start
congestion avoidance directly
10. Anatomy of a TCP Connection’s Lifetime
ssthresh1
ssthresh2
C
cw=1
cwL
cwL/2
Window
Time
1 slow-start
2
congestion
avoidance
3
multiplicative
decrease
4 loss recovery
11. 11
Flow Control
• Prevent sender from overwhelming the receiver
• Receiver in every ACK advertises the available buffer space at
its end
• Window calculation
• MIN(congestion control window, flow control window)
12. 12
Sequencing
• Byte sequence numbers
• TCP receiver buffers out of
order segments and
reassembles them later
• Starting sequence number
randomly chosen
during connection
establishment
• Why?
3
1
2
3
4
3
3
4
1 given to app
2 given to app
Loss
4 buffered (not given to app)
3 & 4 given to app
4 discarded
13. 13
TCP Segment Format
HL
16 bit SRC Port 16 bit DST Port
32 bit sequence number
32 bit ACK number
16 bit window size
resvd flags
16 bit urgent pointer
16 bit TCP checksum
Options (if any)
Data
Flags: URG, ACK,
PSH, RST, SYN,
FIN
14. 14
TCP Flavors
• TCP-Tahoe
• W=1 adaptation on congestion
• TCP-Reno
• W=W/2 adaptation on fast retransmit, W=1 on timeout
• TCP-newReno
• TCP-Reno + intelligent fast recovery
• TCP-Vegas, TCP-SACK
15. 15
TCP Tahoe
• Slow-start
• Congestion control upon time-out or DUP-ACKs
• When the sender receives 3 duplicate ACKs for the
same sequence number, sender infers a loss
• Congestion window reduced to 1 and slow-start
performed again
• Simple
• Congestion control too aggressive
16. 16
TCP Reno
• Tahoe + Fast re-transmit
• Packet loss detected both through timeouts, and
through DUP-ACKs
• Sender reduces window by half, the ssthresh is
set to half of current window, and congestion
avoidance is performed (window increases only by
1 every round-trip time)
• Fast recovery ensures that pipe does not become
empty
• Window cut-down to 1 (and subsequent slow-
start) performed only on time-out
17. 17
TCP New-Reno
• TCP-Reno with more intelligence during fast
recovery
• In TCP-Reno, the first partial ACK will bring the
sender out of the fast recovery phase
• Results in timeouts when there are multiple losses
• In TCP New-Reno, partial ACK is taken as an
indication of another lost packet (which is
immediately retransmitted).
• Sender comes out of fast recovery only after all
outstanding packets (at the time of first loss) are
ACKed
18. 18
TCP SACK
• TCP (Tahoe, Reno, and New-Reno) uses
cumulative acknowledgements
• When there are multiple losses, TCP Reno and
New-Reno can retransmit only one lost packet per
round-trip time
• What about TCP-Tahoe?
• SACK enables receiver to give more information to
sender about received packets allowing sender to
recover from multiple-packet losses faster
19. 19
TCP SACK (Example)
• Assume packets 5-25 are transmitted
• Let packets 5, 12, and 18 be lost
• Receiver sends back a CACK=5, and SACK=(6-11,13-17,19-
25)
• Sender knows that packets 5, 12, and 18 are lost and
retransmits them immediately
20. 20
Other TCP flavors
• TCP Vegas
• Uses round-trip time as an early-congestion-feedback mechanism
• Reduces losses
• TCP FACK
• Intelligently uses TCP SACK information to optimize the fast recovery
mechanism further
21. 21
User Datagram Protocol (UDP)
• Simpler cousin of TCP
• No reliability, sequencing, congestion control, flow
control, or connection management!
• Serves solely as a labeling mechanism for
demultiplexing at the receiver end
• Use predominantly by protocols that do no require
the strict service guarantees offered by TCP (e.g.
real-time multimedia protocols)
• Additional intelligence built at the application layer
if needed
22. 22
UDP Header
Src Port Dst Port
Checksum
Length
Length: length of header
+ data (min = 8)
24. Appropriate Window Size
• Many stacks use a default window size of 16KB
• Too small for many wireless environments where delay is large
• Use window-scaling
• Scale factor exchanged during start-up with SYN messages
• Scale factor a power of 2
25. Increased Initial Window Size
• TCP, by default, starts with a window size of 1
• This is problematic in two ways:
• Slow start slows down due to delayed ACK timer
• For thin connections, efficiency is compromised
• Set the initial congestion window to 4 (instead of 1 MSS)
26. Limited Transmit
• Fast retransmit and recovery kick in only after 3 DUPACKs
• What if there are fewer than 3 DUPACKs
• Limited transmit allows sender to transmit new packets even for the
first two DUPACKs
27. SACK
• Random wireless losses are typically recovered by link layer
retransmissions
• However, if link layer ARQ does not recover packets, random packet
losses can be exposed to the TCP sender
• SACK allows for faster loss recovery under such conditions
28. ECN
• ECN requires explicit congestion notification from routers
• Enables connection to avoid loss regime by preemptively reacting to
congestion
• Makes connection more efficient
29. Timestamp option
• TCP, by default, measures RTT sample only once per congestion
window
• Too coarse for a changing RTT scenario
• Timestamps allow for RTT to be measured in a fine-grained manner
• More reliable estimate of RTT
30. Header Compression
• TCP header fields can be compressed due to redundancy between
packets
• However, in a wireless network where packet losses are typical,
compression can backfire as the loss of an “anchor” packet will
render all subsequent packets useless
• Header compression should hence be turned OFF
31. 31
Puzzle
• Prison with 31 prisoners on death row
• Warden tells the prisoners:
• I will isolate all of you into independent cells tonight
• Every morning from tomorrow, I will pick one of you randomly (say X)
and walk you to a switch room
• The switch room has 2 switches, both initially in the OFF position
• The prisoner X is given the option of manipulating the switches
• The prisoner may also choose to say “all prisoners have visited the
switch room”
• If the prisoner is correct, all prisoners will be let free, otherwise all of
them will be put to death
• What is the strategy that the prisoners should employ?