CORNELL CS 5190 - Lecture 5 Transport: TCP mechanics

Unformatted text preview:

CS519: Computer NetworksLecture 5, Part 2: Mar 8, 2004Transport: TCP mechanics (RFCs: 793, 1122, 1323, 2018, 2581)CS519TCP as seen from above the socket| The TCP socket interface consists of:z Commands to start the connection• connect(), listen(), accept()z Commands to send to and receive from the connection• read(), write()z Commands to end the connection• close(), • (but also read(), write()!)CS519TCP as a “marked” stream| Think of TCP as having “start-of-stream” and an “end-of-stream” tagsz EOS means “no more data will be sent”z And, “you got all the data that was sent”CS519TCP as a “marked” stream| connect(), listen(), generate the “SOS” (TCP SYN)| accept() signals reception of the “SOS”| close() generates the “EOS” (TCP FIN)| read()==0 signals reception of the “EOS”| A connection can end without an “EOS”z read()==-1 or write()==-1z In this case, some sent bytes may not have been receivedCS519TCP “keepalive”| A TCP connection can stay “up” forever even without sending any packetsz Indeed, if one end crashes silently, the other end won’t notice until it sends a packetz Sometime called a half-open connection| TCP implementations have a “keepalive” optionz Settable through sockopts()CS519TCP “keepalive”| Periodically sends a TCP packet with no data| The other end responds with an ACK if it is alive| If not, the other end is declared down, and a pending read() is returned with -1| This is not part of the TCP spec per se| This can just as well be done at the application layerCS519Some TCP issues we’ll look at| TCP uses a sliding window as we saw with link protocols| However, TCP must content with different issuesz Round trip may vary • (so don’t know how best to fill the pipe)z The network may be congested• (so may need to go even slower than receive window allows)z Packets may not arrive in orderz A TCP connection has to synchronize the beginning and end (SOS and EOS)CS519TCP bytes and “segments”Application processWritebytesTCPSend bufferSegmentSegment SegmentTransmit segmentsApplication processReadbytesTCPReceive buffer………CS519TCP Header (segment)Source port Destination portSequence numberAcknowledgementAdvertised windowHdr lenFlags0Checksum Urgent pointerOptions (variable)DataFlags:SYNFINRESETPUSHURGACKCS519Connection Establishment (with Initial Sequence Numbers)Connection Setup3-way handshake(Active)Client(Passive)ServerSyn +ISNASyn + Ack +ISNBAckCS519Connection terminate| Connection establish is fairly straightforward| Connection terminate is more complexz Because both sides must fully closez One side can close while the other still sends the last of its dataz Or both can close at onceCS519TCP Connection terminateClosing a connection:client closes socket:clientSocket.close();Step 1: client end system sends TCP FIN control segment to serverStep 2: server receives FIN, replies with ACK. Closes connection, sends FIN. clientFINserverACKACKFINclosecloseclosedtimed waitCS519TCP Connection TerminateclientFINserverACKACKFINclosecloseclosedtimed waitStep 3: client receives FIN, replies with ACK. z 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.CS519CLOSEDLISTENSYN_RCVD SYN_SENTESTABLISHED: data transfer!CLOSE_WAITLAST_ACKCLOSINGTIME_WAITFIN_WAIT_2FIN_WAIT_1Passive open CloseSend/SYNSYN/SYN + ACK/ACK/SYN + ACKACKClose/FINFIN/ACKClose/FINFIN/ACKACK + FIN/ACKTimeout after two segment lifetimesFIN/ACKACKACKACKClose/FINCloseCLOSEDActive open/SYNSYN/SYN+ACK/Typical Client TransitionsTypical Server TransitionsCS519TIME_WAIT state| On client, Wait 2 times Maximum Segment Lifetime (2 MSL)z Provides protection against delayed segments from an earlier incarnation of a connection being interpreted as for a new connection| Maximum time segment can exist in the network before being discardedz Time-To-Live field in IP is expressed in terms of hops not timez TCP estimates it as 2 minutesCS519TIME_WAIT state| During this time, combination of client IP and port, server IP and port cannot be reusedz Some implementations say local port cannot be reused at all while it is involved in time wait state even to establish a connection to different destIP/port comboCS519TCP advertised window (the receive window)| In TCP, the receiver sends its receive window to the senderz Note that both ends are both sender and receiverz The receiver sends its receive window with every ACK| The sender sets its send window to that of the receive window| Therefore, we only really speak of one window, the send windowCS519TCP advertised window| Why does the TCP receiver need to convey its receive window, whereas in the link-layer sliding window, we didn’t need that?CS519TCP advertised window| Why does the TCP receiver need to convey its receive window, whereas in the link-layer sliding window, we didn’t need that?| ANS: because the TCP layer can ACK data even though the application hasn’t read itCS519TCP advertised windowCS519TCP flow controlCS519TCP retransmission mechanism originally Go-back-N| Say sender sends bytes 1000 – 1499, in 5 100-byte packets| Receiver ACKs up to 1100| Sender knows that receiver missed packet 1100-1199, but doesn’t know about other three packets| Sender “goes back” to 1100, and starts retransmitting everything| It may therefore resend received packetsz Lots of them, if the pipe is long and fatCS519Later TCP added Selective Acknowledgement (SACK)| Use TCP option space during ESTABLISHED state to send “hints” about data received ahead of acknowledged data| TCP option that says SACK enabled on SYN => “I am a SACK enabled sender, receiver feel free to send selective ack info”| Normal ACK field still authoritative!| SACK usage is growing, but still not universalCS519SACK Details| Format:+--------+--------+| Kind=5 | Length |+--------+--------+--------+--------+| Left Edge of 1st Block |+--------+--------+--------+--------+| Right Edge of 1st Block |+--------+--------+--------+--------+| |/ . . . /| |+--------+--------+--------+--------+| Left Edge of nth Block |+--------+--------+--------+--------+| Right Edge of nth Block |+--------+--------+--------+--------+❒ TCP option 5❒ In 40 bytes of option


View Full Document

CORNELL CS 5190 - Lecture 5 Transport: TCP mechanics

Download Lecture 5 Transport: TCP mechanics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 5 Transport: TCP mechanics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 5 Transport: TCP mechanics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?