Last time: Transport 1 � transport layer services � multiplexing/demultiplexing � connectionless transport: UDP � principles of reliable data transfer � timer � sequence number � acknowledgement � negative acknowledgement � window, pipelining � sliding window protocols � go-back-N � selective repeat 16/4-07 Datakommunikation - Jonny Pettersson, UmU Transport 2 � connection-oriented transport: TCP � reliable transfer � flow control � connection management � principles of congestion control � TCP congestion control 16/4-07 Datakommunikation - Jonny Pettersson, UmU Transmission Control Protocol(TCP) � Definierar säker överföring i TCP/IP Internet genom att bland annat definiera � Formen på paket och ackar � Funktioner som kan användas för att se till att data anländer korrekt � Hur TCP skiljer på flera mottagare inom en maskin � Hur kommunikationen initieras och avslutas � VIKTIGT! � TCP är ett protokoll, ej en mjukvara 16/4-07 Datakommunikation - Jonny Pettersson, UmU 1
Vad TCP måste klara � Koppla ihop många olika maskiner � Behov av explicit upp- och nedkoppling � Hantera varierande RTT � Behov av adaptiv timeout för omsändning � Hantera långa fördröjningar i nätet � Behov av hantering av sent anländande paket � TTL � Hantera olika kapaciteter hos mottagare � Behov av att kunna anpassa till olika noders resurser � Hantera olika nätverkskapaciteter � Behov av att hantera trafikstockningar på nätet 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP - Överblick RFCs: 793, 1122, 1323, 2018, 2581 � Kopplingsorienterat � Full duplex � Byte-stream � Flow control: Så sändaren inte dränker mottagaren � app skriver bytes � TCP sänder segment � Congestion control: Så sändaren inte dränker � app läser bytes � Pipeline nätverket Application process Application process Write Read … bytes … bytes TCP TCP Send buffer Receive buffer … Segment Segment Segment Transmit segments 16/4-07 Datakommunikation - Jonny Pettersson, UmU När skickas segment? � Tre sätt att trigga en sändning � MSS (Maximum Segment Size), oftast lika med MTU (Maximum Transfer Unit) för lokala nätverket � Push operation från applikationen � Timeout 16/4-07 Datakommunikation - Jonny Pettersson, UmU 2
Portar och kopplingar � TCP använder portar på ett mer komplicerat sätt än UDP � Flera kopplingar per port � TCP identifierar kopplingar som par av kommunikationspunkter � < SrcPort , SrcIPAddr , DesPort , DesIPAddr > 16/4-07 Datakommunikation - Jonny Pettersson, UmU Välkända TCP portar � 7 - Echo � 9 - Discard � 21 - FTP � 25 - SMTP � 79 - Finger 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP segment structure 32 bits URG: urgent data counting source port # dest port # (generally not used) by bytes sequence number of data ACK: ACK # (not segments!) acknowledgement number valid head not rcvr window size U A P R S F PSH: push data now len used # bytes (generally not used) checksum ptr urgent data rcvr willing to accept RST, SYN, FIN: Options (variable length) connection estab (setup, teardown commands) application data (variable length) Internet Checksum (TCP header + data + pseudo header) 16/4-07 3
TCP seq. #’s and ACKs Seq. #’s: Host B Host A � byte stream “number” of first User S e q byte in segment’s = 4 types 2 , A C K = 7 9 , d a data ‘C’ t a = ‘ C ’ host ACKs ACKs: receipt of ’ ‘C’, echoes � seq # of next byte ‘ C = t a d a , 4 3 back ‘C’ K = expected from C A 9 , = 7 q S e other side � cumulative ACK host ACKs Q: how receiver handles receipt S e q = of echoed 4 3 out-of-order segments , A C K = 8 0 ‘C’ � A: TCP spec doesn’t say, - up to implementor time simple telnet scenario 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP reliable data transfer � TCP creates rdt � Retransmissions are service on top of IP’s triggered by: unreliable service � timeout events � Pipelined segments � duplicate acks � Initially consider � Cumulative acks simplified TCP sender: � TCP uses single � ignore duplicate acks retransmission timer � ignore flow control, congestion control 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP sender events: data rcvd from app: timeout: � Create segment with � retransmit segment seq # that caused timeout � seq # is byte-stream � restart timer number of first data Ack rcvd: byte in segment � If acknowledges � start timer if not previously unacked already running (think segments of timer as for oldest � update what is known to unacked segment) be acked � expiration interval: � start timer if there are outstanding segments TimeOutInterval 16/4-07 Datakommunikation - Jonny Pettersson, UmU 4
NextSeqNum = InitialSeqNum SendBase = InitialSeqNum TCP loop (forever) { sender switch(event) event: data received from application above (simplified) create TCP segment with sequence number NextSeqNum if (timer currently not running) start timer pass segment to IP Comment: NextSeqNum = NextSeqNum + length(data) • SendBase-1: last cumulatively event: timer timeout ack’ed byte retransmit not-yet-acknowledged segment with Example: smallest sequence number • SendBase-1 = 71; start timer y= 73, so the rcvr wants 73+ ; event: ACK received, with ACK field value of y if (y > SendBase) { y > SendBase, so SendBase = y that new data is if (there are currently not-yet-acknowledged segments) acked start timer } } /* end of loop forever */ TCP ACK generation [RFC 1122, RFC 2581] Event at Receiver TCP Receiver action Arrival of in-order segment with Delayed ACK. Wait up to 500ms expected seq #. All data up to for next segment. If no next segment, send ACK expected seq # already ACKed Arrival of in-order segment with Immediately send single cumulative expected seq #. One other ACK, ACKing both in-order segments segment has ACK pending Arrival of out-of-order segment Immediately send duplicate ACK, higher-than-expect seq. # . indicating seq. # of next expected byte Gap detected Immediately send ACK, provided that Arrival of segment that partially or completely fills gap segment starts at lower end of gap 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP: retransmission scenarios Host A Host A Host B Host B S e S e q = q = 9 2 9 2 , 8 , 8 b y b y t e t e s d s d a t a t Seq=92 timeout a a S e q = 1 0 0 , 2 0 b y t e s timeout d a ACK=100 t a ACK=100 X ACK=120 loss S e q S e = 9 q = Sendbase 2 , 9 2 8 , 8 b y b t e s y t e d s d a t a a t = 100 a Seq=92 timeout SendBase = 120 ACK=120 ACK=100 SendBase SendBase = 100 = 120 time time premature timeout lost ACK scenario 5
TCP retransmission scenarios (more) Host A Host B S e q = 9 2 , 8 b y t e s d a t a ACK=100 timeout S e q = 1 0 0 , 2 0 b y t e s d a t a X loss SendBase ACK=120 = 120 time Cumulative ACK scenario 16/4-07 Datakommunikation - Jonny Pettersson, UmU TCP Flow Control flow control receiver: explicitly informs sender of sender won’t overrun (dynamically changing) receiver’s buffers by transmitting too much, amount of free buffer space too fast � RcvWindow field in TCP segment RcvBuffer = size or TCP Receive Buffer sender: keeps the amount RcvWindow = amount of spare room in Buffer of transmitted, unACKed data less than most recently received RcvWindow receiver buffering 16/4-07 Datakommunikation - Jonny Pettersson, UmU Tillförlitlig och ordnad leverans Sending application Receiving application TCP TCP LastByteWritten LastByteRead LastByteAcked LastByteSent NextByteExpected LastByteRcvd Sändaren Mottagaren LastByteAcked ≤ LastByteSent LastByteRead < NextByteExpected LastByteSent ≤ LastByteWritten NextByteExpected ≤ LastByteRcvd Buffrar mellan LastByteAcked och + 1 Buffrar mellan LastByteRead och LastByteWritten LastByteRcvd 16/4-07 Datakommunikation - Jonny Pettersson, UmU 6
Flow Control - Mottagaren Sending application Receiving application TCP TCP LastByteWritten LastByteRead LastByteAcked LastByteSent NextByteExpected LastByteRcvd � Hos mottagaren � LastByteRcvd - LastByteRead ≤ RcvBuffer � RcvWindow = RcvBuffer - ( LastByteRcvd - LastByteRead ) 16/4-07 Datakommunikation - Jonny Pettersson, UmU Flow Control - Sändaren Sending application Receiving application TCP TCP LastByteWritten LastByteRead LastByteAcked LastByteSent NextByteExpected LastByteRcvd � Hos sändaren � LastByteSent - LastByteAcked ≤ RcvWindow � EffectiveWindow = RcvWindow - ( LastByteSent - LastByteAcked ) � LastByteWritten - LastByteAcked ≤ MaxSendBuffer 16/4-07 Datakommunikation - Jonny Pettersson, UmU Flow Control � Om RcvWindow = 0 � Hur får sändaren reda på att den kan sända igen? � Egentligen ska inga paket skickas � Men, sändaren fortsätter att skicka 1-byte data • Får reda på när RcvWindow ändras • Smart sender/dumb receiver 16/4-07 Datakommunikation - Jonny Pettersson, UmU 7
Recommend
More recommend