CS162 Operating Systems and Systems Programming Lecture 16 Flow Control DNS March 28 2011 Ion Stoica http inst eecs berkeley edu cs162 TCP Flow Control TCP stream oriented protocol Sender sends a stream of bytes not packets e g no need to tell TCP how much you send Receiver reads a stream of bytes TCP flow control Sliding window protocol at byte not packet level Go back N TCP Tahoe Reno New Reno Selective acknowledgement TCP Sack Receiver tells sender how many more bytes it can receive without overflowing its buffer i e AdvertisedWindow The ack nowledgement contains sequence number N of next byte the receiver expects i e receiver has received all bytes in sequence up to and including N 1 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 2 TCP Flow Control Sending Application Receiving Application TCP layer OS TCP layer IP layer IP layer TCP IP implemented by OS Kernel TCP and application run in different processes Cannot do context switching on sending receiving every packet At 1Gbps it takes 12 usec to send an 1500 bytes and 0 8usec to send an 100 byte packet Need buffers to match 3 28 Sending app with sending TCP Receiving TCP with receiving app Ion Stoica CS162 UCB Spring 2011 Lec 16 3 TCP Flow Control Sending Application Receiving Application TCP layer OS TCP layer IP layer IP layer Three pairs of producer consumer s sending app sending TCP sending TCP receiving TCP receiving TCP receiving app How is mutual exclusion implemented 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 4 TCP Flow Control Sending Application TCP layer OS Receiving Application 500 bytes IP layer TCP layer IP layer Example assumptions Maximum IP packet size 100 bytes Size of the receiving buffer MaxRcvBuf 500bytes Use circular buffers i e N s byte is stored at N mod MaxRcvBuf in the buffer Recall ack indicates the next expected byte in sequence not the last received byte 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 5 TCP Flow Control Sending Application LastByteWritten 1 LastByteRead 1 LastByteAcked 1 LastByteSent 1 3 28 Receiving Application LastByteRcvd 1 NextByteExpected 0 LastByteWritten last byte written by the sending app LastByteSent last byte sent by the sender LastByteAcked last byte acked at the sender LastByteRcvd last byte received at receiver NextByteExpected last in sequence byte expected by receiver LastByteRead last byte read by the receiving app Ion Stoica CS162 UCB Spring 2011 Lec 16 6 TCP Flow Control Sending Application LastByteWritten 349 Receiving Application LastByteRead 1 0 349 LastByteAcked 1 LastByteSent 1 LastByteRcvd 1 NextByteExpected 0 Sending app sends 350 bytes Recall we assume IP only accepts packets no larger than 100 bytes 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 7 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 0 0 100 349 349 99 LastByteAcked 0 LastByteSent 99 0 99 3 28 LastByteRead 0 0 99 LastByteRcvd 99 NextByteExpected 100 Data 0 99 0 99 Sender sends first packet i e first 100 bytes Ion and receiver gets the packet Stoica CS162 UCB Spring 2011 Lec 16 8 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 0 100 349 99 LastByteAcked 99 LastByteSent 99 0 100 3 28 LastByteRead 0 0 99 Ack 100 LastByteRcvd 99 NextByteExpected 100 Data 0 99 0 99 Receiver gets first ack note ack indicates next byte expected by receiver Receiver no longer needs to keep first 100 bytes Ion Stoica CS162 UCB Spring 2011 Lec 16 9 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 100 300 100 349 299 349 LastByteAcked 99 LastByteSent 299 0 99 100 199 100 299 3 28 LastByteRead 0 0 100 99 199 Ack 100 LastByteRcvd 199 NextByteExpected 200 Data 0 99 Data 100 199 Data 200 299 Send next two packets rd Stoica CS162 UCB Spring 2011 3Ion packet is lost 100 199 Lec 16 10 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 200 300 299 349 LastByteRead 0 0 199 LastByteAcked 199 LastByteSent 299 0 99 100 199 100 299 200 299 3 28 Ack 100 Ack 200 LastByteRcvd 199 NextByteExpected 200 Data 0 99 Data 100 199 Data 200 299 nd Ack for 2 packet Ion Stoica CS162 UCB Spring 2011 100 199 Lec 16 11 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 200 300 200 349 299 349 LastByteRead 0 0 199 LastByteAcked 199 LastByteSent 349 0 99 100 199 100 299 200 299 200 349 200 349 3 28 Ack 100 Ack 200 300 349 LastByteRcvd 349 NextByteExpected 200 Data 0 99 Data 100 199 Data 200 299 Data 300 349 Ack 200 Send 4th packet 200 349 Ion Stoica CS162 Spring 2011 Still ack 2nd UCB packet 100 199 100 199 300 349 Lec 16 12 TCP Flow Control Receiving Application Sending Application LastByteWritten 349 LastByteRead 0 200 349 0 199 LastByteAcked 199 LastByteSent 349 0 99 100 199 100 299 200 299 300 349 300 349 3 28 Ack 100 Ack 200 300 349 NextByteExpected 200 LastByteRcvd 349 Data 0 99 Data 100 199 Data 200 299 Data 300 349 Ack 200 Ion Stoica CS162 UCB Spring 2011 100 199 100 199 300 349 Lec 16 13 TCP Flow Control Receiving Application Sending Application 0 199 LastByteWritten 349 LastByteRead 199 300 349 200 349 LastByteAcked 199 LastByteSent 349 0 99 100 199 100 299 200 299 300 349 300 349 3 28 Ack 100 Ack 200 NextByteExpected 200 LastByteRcvd 349 Data 0 99 Data 100 199 Data 200 299 Data 300 349 Ack 200 Ion Stoica CS162 UCB Spring 2011 100 199 100 199 300 349 Lec 16 14 TCP Flow Control Sending Application Receiving Application LastByteWritten 349 LastByteRead 199 300 349 200 349 LastByteAcked 199 LastByteSent 349 NextByteExpected 200 LastByteRcvd 349 AdvertisedWindow number of bytes the receiver can receive AdvertisedWindow MaxRcvBuffer LastByteRcvd LastByteRead Sender window number of bytes the sender can send Sender window AdvertisedWindow LastByteSent LastByteAcked MaxSendBuffer LastByteWritten LastByteAcked 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 15 What if Receiving App Stops Receiving Data LastByteRead stops advancing receiving buffer eventually fills with undelivered data i e LastByteRcvd MaxRcvBuffer LastByteRead AdvertisedWindow 0 Sending TCP stops sending data as AdvertisedWindow 0 LastByteSent and LastByteAcked stop advancing Sending TCP buffer fills in when LastByteWritten LastByteAcked MaxSendBuffer Sending app stops sending data when sending TCP buffer fills in 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 16 Retransmission Timeout If haven t received ack by timeout retransmit packet after last acked packet How to set timeout 3 28 Ion Stoica CS162 UCB Spring 2011 Lec 16 17 Timing
View Full Document
Unlocking...