CSC: Principles of Computer Networks: Demultiplexing

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

CSC 525:

Principles of Computer Networks

Duties of Transport
• Demultiplexing:
– IP header points to protocol
– Transport header needs demultiplex further
• Port number
• well known ports and ephemeral ports
• Data reliability (if desired):
– UDP: checksum, but no data recovery
– TCP: checksum, sequence number, and data
recovery

TCP
• Services
– Point-to-point connection
– Guaranteed delivery of messages
– Same order as they’re sent
– Byte-stream, duplex
• Mechanisms
– Three-way handshaking
– Flow control
• Sender doesn’t overrun receiver
– Congestion control
• Sender doesn’t overrun the network (routers)

1
TCP Header
0 4 10 16 31
Source port Destination port
Sequence number
Acknowledgement
HdrLen Flags Advertised window
Checksum Urgent pointer

Options (variable)

• Sequence number, acknowledgement, and advertised window – used


by sliding-window based flow control
• Flags:
– SYN, FIN – establishing/terminating a TCP connection
– ACK – set when Acknowledgement field is valid
– URG – urgent data; Urgent Pointer says where non-urgent data starts
– PUSH – don’t wait to fill segment
– RESET – abort connection

Segment
• TCP breaks up the byte stream in segments.
– Limited to the Maximum Segment Size (default 536 bytes)
• Each segment has a sequence number.
– Indicates where it fits in the byte stream

13450 14950 16050 17550

seg 8 seg 9 seg 10

• IP might further break it up into packets.

TCP Connection Establishment


• Three-way handshaking
– Goal: agree on a set of parameters: the start
sequence number for each side

Client (initiator) Server

SYN, SeqN
um =x

=x+1
y and Ack
K, SeqNum =
SYN and AC

ACK, Ack
=y +1

2
Reliable Transfer w/ Sliding Window

• In order to optimize performance (throughput, fairness, …)


– How to set Retransmission Timer?
– How to set Window Size?
7

Keep the Pipe Full


Bandwidth
Latency
• Bandwidth-Delay product measures the capacity of the pipe.
• Ideally, send enough data to fill the pipe before requiring the
first ACK
• Set retransmission timer based on end-to-end delay
– Too short: spurious retransmission
– Too long: under-utilization
• Set window size based on available network capacity
– Too big: network congestion or receiver overflow
– Too small: under-utilization
– Affected by cross traffic
8

Setting Retransmission Timer


• Use exponential moving averaging based on
measurements.
A(n) = b*A(n- 1) + (1 – b)T(n)
D(n) = b*D(n-1) + (1 – b)*(T(n) – A(n))
Timeout(n) = A(n) +4D(n)

Question: Why not set timeout to average delay?

T(n) is current measured RTT, A(n) is estimated average


RTT, D(n) is estimated average deviation.

Karn’s algorithm for updating timer in case of retransmission


1. Measure T(n) only for original transmissions (not retransmission)
2. Double Timeout after timeout …
3. Reset Timeout for new packet when receive ACK
9

3
TCP Flow Control
• Make sure receiving end can handle data
• The receiver puts its available buffer size in
the TCP header as AdvertisedWindow.
• The sender should not send more data than
what AdvertisedWindow allows.

10

TCP Flow Control: Sender Side


Packet Sent Packet Received
Source Port Dest. Port Source Port Dest. Port
Sequence Number Sequence Number
Acknowledgment Acknowledgment
HL/Flags Window HL/Flags Window
D. Checksum Urgent Pointer D. Checksum Urgent Pointer

App write

acknowledged sent to be sent outside window

11

TCP Congestion Control


• Can the network handle the data rate?
– Finite bandwidth
– Finite buffer size

• Determined end-to-end: TCP is making


guesses about the available network capacity.

• Two papers:
– Good science vs. Great engineering
12

4
Dangers of Increasing Load
packet
knee cliff
• Knee – point after which loss

Throughput
– Throughput increases very
slow congestion
– Delay increases fast collapse

• Cliff – point after which Load


– Throughput starts to
Delay

decrease very fast to zero


(congestion collapse)
– Delay approaches infinity

Load
13

Control System Model

User 1 x1

x2
User 2 Σ Σxi>Xgoal
xn

User n
y

• Simple, yet powerful model


• Explicit binary signal of congestion
14

Possible Choices
& a + bI xi (t ) increase #
xi (t + 1) = % I "
$aD + bD xi (t ) decrease!

• Multiplicative increase, additive decrease


– aI=0, bI>1, a D<0, bD=1
• Additive increase, additive decrease
– aI>0, bI=1, a D<0, bD=1
• Multiplicative increase, multiplicative decrease
– aI=0, bI>1, a D=0, 0<bD<1
• Additive increase, multiplicative decrease
– aI>0, bI=1, a D=0, 0<bD<1
• Which one to use?

15

5
Multiplicative Increase, Additive
Decrease
• Fixed point at fairness
line
(bI (x1h+aD), bI (x2h+aD))
ba
x1h = x2 h = I D
1 ! bI (x1h,x2h)

• Fixed point is
User 2: x2

unstable! (x1h+aD,x2h+aD) optimal

overload
underload
efficiency
line

User 1: x1 16

Additive Increase, Additive Decrease

fairness
(x1h+aD+aI), line
x2h+aD+aI))
• Reaches stable
cycle, but does (x1h,x2h)
not converge to
User 2: x2

fairness (x1h+aD,x2h+aD)

efficiency
line

User 1: x1 17

Multiplicative Increase,
Multiplicative Decrease
fairness
line
(x1h,x2h)
• Reaches (bI b Dx1h,
stable cycle, bIb Dx2h)
but does not
User 2: x2

converge to
fairness (bd x 1h,bd x 2h)

efficiency
line

User 1: x1 18

6
Additive Increase,
Multiplicative Decrease
fairness
line
(x1h,x2h)
• Converges to (bDx1h+aI ,
bDx 2h+aI)
stable and fair
cycle
User 2: x2

(bDx1h,bDx2h)

efficiency
line

User 1: x1 19

TCP Congestion Control


• Maintain three variables:
– cwnd: congestion window
– flow_win: flow window; receiver advertised window
– ssthresh: threshold size (used to update cwnd)
For sending, use: win = min(flow_win, cwnd)

• Test the limit of the network


– when cwnd < ssthresh, increase cwnd quickly.
– when cwnd ≥ ssthresh, increase cwnd slowly

• If packet lost, have gone too far


– cut back drastically

• Additive Increase, Multiplicative Decrease (AIMD)


20

Slow Start Phase


• Goal: reach knee quickly
• Upon (re)starting a TCP connection:
– Set cwnd =1
– Each time a segment is acknowledged increment cwnd by
one,
cwnd += 1

• Slow Start is not actually slow


– After all segments in the window have been acked, cwnd has
been doubled over one RTT. That is, cwnd increases
exponentially over time.
– But slower than all at once.

21

7
Slow Start Example
• The congestion
window size grows segment 1
rapidly cwnd = 1
ACK 2

cwnd = 2 segment 2
segment 3

ACK 4
cwnd = 4 segment 4
• TCP will slow segment 5
down the increase segment 6
segment 7
of cwnd when
ACK8
cwnd = 8
cwnd >= ssthresh

22

Congestion Avoidance Phase


• Slow down “Slow Start”
• ssthresh is lower-bound guess about location of
knee

• If cwnd >= ssthresh then


each time a segment is acknowledged
increment cwnd by 1/cwnd, i.e, cwnd += 1/cwnd

• The effect is that, after a$ segments in the


window have been acknowledged (i.e., one RTT),
cwnd has been incremented by 1.

23

Example
cwnd = 1
• Assume that ssthresh = 8
cwnd = 2

14 cwnd = 4

12
Cwnd (in segments)

10
cwnd = 8
8 ssthresh
6
4
2 cwnd = 9
0
2
0

6
t=
t=

t=

t=

Roundtrip times
cwnd = 10

24

8
Retransmission Timeout (RTO)
• Upon a retransmission timeout
– Assume packet loss due to congestion
– Cut window size drastically

ssthresh = cwnd/2;
cwnd = 1;

25

Putting Everything Together


Initially:
while (next < unack + win)
cwnd = 1;
ssthresh = recvWin; transmit next packet;
New ack received:
if (cwnd < ssthresh) where win = min(cwnd,recvWin);
/* Slow Start*/
cwnd = cwnd + 1;
else
/* Congestion Avoidance */ unack next
seq #
cwnd = cwnd + 1/cwnd;
Timeout:
/* Multiplicative decrease */
ssthresh = cwnd/2; win

cwnd = 1;

26

cwnd

Timeout

Congestion
Avoidance

Slow Start

Time

27

9
Fast Retransmission

segment 1
• Don’t wait for cwnd = 1

window to drain ACK 2


cwnd = 2 segment 2
segment 3
ACK 3
• Resend a segment ACK 4
after 3 duplicate cwnd = 4 segment 4
segment 5
ACKs segment 6
ACK 4 segment 7
ACK 4
3 duplicate ACK 4
ACKs

28

Fast Recovery
• After a fast retransmission, set cwnd to cwnd/2
– i.e., don’t reset cwnd to 1

• But when RTO expires still do cwnd = 1

• Fast Retransmit and Fast Recovery


– Implemented by TCP Reno
– Most widely used version of TCP today

• Lesson: avoid RTOs at all costs!

29

Fast Retx and Fast Recovery


Initially:
cwnd = 1;
ssthresh = recvWin;

New ack received:


if (cwnd < ssthresh) /* slow start*/
cwnd = cwnd + 1;
else /* congestion avoidance */
cwnd = cwnd + 1/cwnd;

Loss detected:
ssthresh = cwnd/2; /* multiplicative decrease */
if (3 duplicated ACKs) /* fast retransmission */
cwnd = ssthresh; /* fast recovery*/
else
cwnd = 1;

30

10
Fast Retransmit and Fast Recovery
cwnd

Congestion
Avoidance
Slow Start

Time

• Retransmit after 3 duplicated acks


– prevent expensive timeouts
• No need to slow start again
• At steady state, cwnd oscillates around the
optimal window size.

31

Cooperation and Compatibility


• TCP assumes all flows employ TCP-like
congestion control
– TCP-friendly or TCP-compatible

• Selfish flows: can get all the bandwidth they


like

• If new congestion control algorithms are


developed, they must be TCP-friendly

32

Other Approaches
• Goals
– Throughput
– Fairness
– TCP-friendly
• Sender adaptation
– TCP Tahoe, Reno, Vegas, Westwood, …
• Router-assisted Approaches
– RED, REM
• Explicit Congestion Notification (ECN)

33

11

You might also like