36
EEC-484/584 EEC-484/584 Computer Networks Computer Networks Lecture 16 Lecture 16 Wenbing Zhao Wenbing Zhao [email protected] [email protected] (Part of the slides are based on Drs. Kurose & (Part of the slides are based on Drs. Kurose & Ross’s slides for their Ross’s slides for their Computer Networking Computer Networking book, book, and and on materials supplied by on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Dr. Louise Moser at UCSB and Prentice-Hall)

EEC-484/584 Computer Networks Lecture 16 Wenbing Zhao [email protected] (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

EEC-484/584EEC-484/584Computer NetworksComputer Networks

Lecture 16Lecture 16

Wenbing ZhaoWenbing Zhao

[email protected]@ieee.org(Part of the slides are based on Drs. Kurose & Ross’s slides (Part of the slides are based on Drs. Kurose & Ross’s slides

for their for their Computer Networking Computer Networking book, and book, and on materials supplied by on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall)Dr. Louise Moser at UCSB and Prentice-Hall)

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

22

OutlineOutline

• TCP– Connection management– Reliable data transfer– Flow control– TCP transmission policy– Congestion control

• Reminder: Quiz 4– MW session: 11/27 Monday 2-4pm– TTh session: 11/28 Tuesday 4-6pm

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

33

TCP Connection ManagementTCP Connection Management

TCP sender, receiver establish “connection” before exchanging data segments

• Initialize TCP variables:– Sequence numbers– Buffers, flow control info (e.g. RcvWindow)

• Client: connection initiator Socket clientSocket = new

Socket("hostname","port number"); • Server: contacted by client Socket connectionSocket = welcomeSocket.accept();

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

44

TCP Connection ManagementTCP Connection Management

Three way handshake:

Step 1: client host sends TCP SYN segment to server

– specifies initial sequence number

– no data

Step 2: server host receives SYN, replies with SYN/ACK segment

– server allocates buffers

– specifies server initial sequence number

Step 3: client receives SYN/ACK, replies with ACK segment, which may contain data

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

55

TCP Connection ManagementTCP Connection Management

Three way handshake:• SYN segment is considered

as 1 byte• SYN/ACK segment is also

considered as 1 byte

client

SYN (seq=x)

server

SYN/ACK (seq=y, ACK=x+1)

ACK (seq=x+1, ACK=y+1)

connect accept

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

66

TCP Connection ManagementTCP Connection Management

Closing a connection:

client closes socket: clientSocket.close();

Step 1: client end system sends TCP FIN control segment to

server

Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN.

client

FIN

server

ACK

ACK

FIN

close

close

closed

tim

ed w

ait

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

77

TCP Connection ManagementTCP Connection Management

Step 3: client receives FIN, replies with ACK.

– Enters “timed wait” - will respond with ACK to received FINs

Step 4: server, receives ACK. Connection closed.

Note: with small modification, can handle simultaneous FINs

client

FIN

server

ACK

ACK

FIN

closing

closing

closed

tim

ed w

ait

closed

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

88

TCP Reliable Data TransferTCP Reliable Data Transfer• TCP creates rdt

service on top of IP’s unreliable service

• Pipelined segments• Cumulative acks• TCP uses single

retransmission timer

• Retransmissions are triggered by:– timeout events– duplicate acks

• Initially consider simplified TCP sender:– ignore duplicate acks– ignore flow control,

congestion control

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

99

TCP Sender Events:TCP Sender Events:Data rcvd from app:• Create segment with

sequence number• seq # is byte-stream

number of first data byte in segment

• start timer if not already running (think of timer as for oldest unacked segment)

• expiration interval: TimeOutInterval

Timeout:• retransmit segment that

caused timeout• restart timer

Ack rcvd:• If acknowledges

previously unacked segments– update what is known to

be acked– start timer if there are

outstanding segment

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1010

TCP: Retransmission ScenariosTCP: Retransmission ScenariosHost A

Seq=100, 20 bytes data

ACK=100

timepremature timeout

Host B

Seq=92, 8 bytes data

ACK=120

Seq=92, 8 bytes data

Seq=

92

tim

eout

ACK=120

Host A

Seq=92, 8 bytes data

ACK=100

loss

tim

eout

lost ACK scenario

Host B

X

Seq=92, 8 bytes data

ACK=100

time

Seq=

92

tim

eout

SendBase= 100

SendBase= 120

SendBase= 120

Sendbase= 100

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1111

TCP Retransmission ScenariosTCP Retransmission Scenarios

Host A

Seq=92, 8 bytes data

ACK=100

loss

tim

eout

Cumulative ACK scenario

Host B

X

Seq=100, 20 bytes data

ACK=120

time

SendBase= 120

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1212

TCP ACK GenerationTCP ACK Generation

Event at Receiver

Arrival of in-order segment withexpected seq #. All data up toexpected seq # already ACKed

Arrival of in-order segment withexpected seq #. One other segment has ACK pending

Arrival of out-of-order segmenthigher-than-expect seq. # .Gap detected

Arrival of segment that partially or completely fills gap

TCP Receiver action

Delayed ACK. Wait up to 500msfor 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 thatsegment starts at lower end of gap

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1313

TCP Flow ControlTCP Flow Control• Receive side of TCP

connection has a receive buffer:

• Speed-matching service: matching the send rate to the receiving app’s drain rate

• App process may be slow at reading from buffer

Flow control:sender won’t overflow

receiver’s buffer bytransmitting too much,

too fast

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1414

TCP Flow ControlTCP Flow Control

(Suppose TCP receiver discards out-of-order segments)

Spare room in buffer= RcvWindow

= RcvBuffer-[LastByteRcvd - LastByteRead]

• Rcvr advertises spare room by including value of RcvWindow in segments

• Sender limits unACKed data to RcvWindow– guarantees receive

buffer doesn’t overflow

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1515

TCP Transmission PolicyTCP Transmission Policy

• Window management not directly tied to ACKs– The sender can send new segments only if the

receiver has room to receive them

• What if the receiver’s window drops to 0 ?– Sender may not normally send segments with two

exceptions– Exception 1: urgent data may be sent, e.g., to allow

user to kill process running on the remote machine– Exception 2: sender may send a 1-byte segment to

make the receiver re-announce the next byte expected and window size

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1616

TCP Transmission PolicyTCP Transmission Policy

• Window management not directly tied to ACKs

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1717

TCP Transmission PolicyTCP Transmission Policy

• Nagle’s algorithm– To address the 1-byte-at-a-time sender

problem

• Clark’s algorithm– To address the 1-byte-at-a-time receiver

problem

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1818

1-byte-at-a-time Sender Problem1-byte-at-a-time Sender Problem• Sender sends 1 byte (e.g., typed one character in an editor)• A segment of 1 byte is sent to the remote machine (41-byte

IP packet)• Remote machine acks immediately (40-byte IP packet)• Editor (in remote machine) program reads the received 1

byte, a windows update segment is sent to user (40-byte IP packet)

• Editor program echoes the 1 byte received to the user terminal (41-byte IP packet)

• In all, 162 bytes of bandwidth used, 4 segments are sent for each character typed

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

1919

Nagle’s AlgorithmNagle’s Algorithm• When sender application passes data to TCP one

byte at a time– Send first byte – Buffer the rest until first byte ACKed– Then send all buffered bytes in one TCP segment– Start buffering again until all ACKed

• Implemented widely in TCP, can be disabled/enabled by using socket options

• For some application, it is necessary to disable the Nagle’s algorithm, e.g., X Windows program over Internet, to avoid erratic mouse movement, etc.

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2020

Silly Window SyndromeSilly Window Syndrome• When receiver application accepts data from TCP 1 byte at

a time

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2121

Clark’s AlgorithmClark’s Algorithm

• Receiver should not send window update until – It can handle max segment size it advertised when

connection established, or, – Its buffer is half empty, whichever is smaller

• Sender should wait until – It has accumulated enough space in window to send full

segment, or, – One containing at least half of receiver’s buffer size

• Nagle’s algorithm and Clark’s algorithm are complementary

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2222

Principles of Congestion ControlPrinciples of Congestion Control

Congestion:• Informally: “too many sources sending too much

data too fast for network to handle”• Different from flow control!• Manifestations:

– lost packets (buffer overflow at routers)– long delays (queueing in router buffers)

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2323

Approaches towards Congestion ControlApproaches towards Congestion Control

End-end congestion control:

• no explicit feedback from network

• congestion inferred from end-system observed loss, delay

• approach taken by TCP

Network-assisted congestion control:

• routers provide feedback to end systems– single bit indicating

congestion (SNA, DECbit, TCP/IP ECN, ATM)

– explicit rate sender should send at

Two broad approaches towards congestion control

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2424

TCP Congestion Control: TCP Congestion Control: Additive Increase, Multiplicative DecreaseAdditive Increase, Multiplicative Decrease

• Approach: increase transmission rate (window size), probing for usable bandwidth, until loss occurs– Additive increase: increase cwnd by 1 MSS every RTT until loss detected– Multiplicative decrease: cut cwnd in half after loss

Saw toothbehavior: probing

for bandwidth

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2525

TCP Congestion ControlTCP Congestion Control

• Sender limits transmission: LastByteSent-LastByteAcked cwnd

• Roughly,

• cwnd is dynamic, function of perceived network congestion

How does sender perceive congestion?

• loss event = timeout or 3 duplicate acks

• TCP sender reduces rate (cwnd) after loss event

three mechanisms:– AIMD– slow start– conservative after

timeout events

rate = cwnd

RTT Bytes/sec

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2626

TCP Slow StartTCP Slow Start

• When connection begins, cwnd = 1 MSS– Example: MSS = 500 bytes

& RTT = 200 msec– Initial rate = 20 kbps

• Available bandwidth may be >> MSS/RTT– Desirable to quickly ramp

up to respectable rate

• When connection begins, increase rate exponentially fast until first loss event

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2727

TCP Slow StartTCP Slow Start• When connection

begins, increase rate exponentially until first loss event:– Double cwnd every RTT– Done by incrementing cwnd for every ACK received

• Summary: initial rate is slow but ramps up exponentially fast

Host A

one segment

RTT

Host B

time

two segments

four segments

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2828

Congestion AvoidanceCongestion AvoidanceQ: When should the

exponential increase switch to linear?

A: When cwnd gets to 1/2 of its value before timeout

Implementation:• Variable Threshold • At loss event, Threshold is

set to 1/2 of cwnd just before loss event

How to increase cwnd linearly:cwnd (new) = cwnd + mss*mss/cwnd

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

2929

Congestion ControlCongestion Control

• After 3 duplicated ACKs:– cwnd is cut in half– window then grows linearly

• But after timeout event:– cwnd instead set to 1 MSS– window then grows

exponentially– to a threshold, then grows

linearly

3 dup ACKs indicates

network capable of delivering some segments timeout indicates a “more alarming” congestion scenario

Philosophy:

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3030

Summary: TCP Congestion ControlSummary: TCP Congestion Control

• When cwnd is below Threshold, sender in slow-start phase, window grows exponentially

• When cwnd is above Threshold, sender is in congestion-avoidance phase, window grows linearly

• When a triple duplicate ACK occurs, Threshold set to cwnd/2 and cwnd set to Threshold

• When timeout occurs, Threshold set to cwnd/2 and cwnd is set to 1 MSS

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3131

TCP Sender Congestion ControlTCP Sender Congestion Control

State Event TCP Sender Action Commentary

Slow Start (SS)

ACK receipt for previously unacked data

CongWin = CongWin + MSS,

If (CongWin > Threshold) set state to “Congestion Avoidance”

Resulting in a doubling of CongWin every RTT

CongestionAvoidance (CA)

ACK receipt for previously unacked data

CongWin = CongWin+ MSS * (MSS/CongWin)

Additive increase, resulting in increase of CongWin by 1 MSS every RTT

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3232

TCP Sender Congestion ControlTCP Sender Congestion Control

State Event TCP Sender Action Commentary

SS or CA Loss event detected by triple duplicate ACK

Threshold = CongWin/2, CongWin = Threshold,Set state to “Congestion Avoidance”

Fast recovery, implementing multiplicative decrease. CongWin will not drop below 1 MSS.

SS or CA Timeout Threshold = CongWin/2, CongWin = 1 MSS,Set state to “Slow Start”

Enter slow start

SS or CA Duplicate ACK

Increment duplicate ACK count for segment being acked

CongWin and Threshold not changed

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3333

TCP Congestion ControlTCP Congestion Control

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3434

ExerciseExercise

• Suppose that the TCP congestion window is set to 18 KB and a timeout occurs. How big will the window be if the next four transmission bursts are all successful? Assume that the maximum segment size is 1 KB.

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3535

ExerciseExerciseSegment#

Action VariablesSend Receive Comment cwnd ssthresh

Timeout 18KB -

Retransmit 1024 9216

1 1:1025(1024) 1024 9216

2 ACK 1025 Slow start 2048 9216

3 1025:2049(1024) 2048 9216

4 2049:3073(1024) 2048 9216

5 ACK 2049 Slow start 3072 9216

6 ACK 3073 Slow start 4096 9216

7 3073:4097(1024) 4096 9216

8 4097:5121(1024) 4096 9216

9 5121:6145(1024) 4096 9216

10 6145:7169(1024) 4096 9216

11 ACK 4097 Slow start 5120 9216

12 ACK 5121 Slow start 6144 9216

13 ACK 6145 Slow start 7168 9216

14 ACK 7169 Slow start 8192 9216

Spring Semester 2006Spring Semester 2006 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao

3636

Exercise Problem #3Exercise Problem #315 7169:8193(1024) 8192 9216

16 8193:9217(1024) 8192 9216

17 9217:10241(1024) 8192 9216

18 10241:11265(1024) 8192 9216

19 11265:13313(1024) 8192 9216

20 12289:14337(1024) 8192 9216

21 14337:15361(1024) 8192 9216

22 15361:16385(1024) 8192 9216

23 ACK 8193 Slow start 9216 9216

24 ACK 9217 Slow start 10240 9216

25 ACK 10241Cong. Avoid.New cwnd =

cwnd + mss*mss/cwnd10342 9216

26 ACK 11265 Cong. Avoid. 10443 9216

27 ACK 13313 Cong. Avoid. 10543 9216

28 ACK 14337 Cong. Avoid. 10642 9216

29 ACK 15361 Cong. Avoid. 10740 9216

30 ACK 16385 Cong. Avoid. 10837 9216