Chapter 5 Peer-to-Peer Protocols and Data Link Layer PRT I: Peer-to-Peer Protocols Peer-to-Peer Protocols and Service Models RQ Protocols and Reliable Data Transfer Flow Control Timing Recovery TCP Reliable Stream Service & Flow Control
Chapter 5 Peer-to-Peer Protocols and Data Link Layer PRT II: Data Link Controls Framing Point-to-Point Protocol High-Level Data Link Control Link Sharing Using Statistical Multiplexing
Chapter Overview Peer-to-Peer protocols: many protocols involve the interaction between two peers Service Models are discussed & examples given Detailed discussion of RQ provides example of development of peer-to-peer protocols Flow control, TCP reliable stream, and timing recovery Data Link Layer Framing PPP & HDLC protocols Statistical multiplexing for link sharing
Chapter 5 Peer-to-Peer Protocols and Data Link Layer Peer-to-Peer Protocols and Service Models
Peer-to-Peer Protocols n + 1 peer process SDU n peer process n 1 peer process PDU n + 1 peer process SDU n peer process n 1 peer process Peer-to-Peer processes execute layer-n protocol to provide service to layer-(n+1) Layer-(n+1) peer calls layer-n and passes Service Data Units (SDUs) for transfer Layer-n peers exchange Protocol Data Units (PDUs) to effect transfer Layer-n delivers SDUs to destination layer-(n+1) peer
Service Models The service model specifies the information transfer service layer-n provides to layer-(n+1) The most important distinction is whether the service is: Connection-oriented Connectionless Service model possible features: rbitrary message size or structure Sequencing and Reliability Timing, Pacing, and Flow control Multiplexing Privacy, integrity, and authentication
Connection-Oriented Transfer Service Connection Establishment Connection must be established between layer-(n+1) peers Layer-n protocol must: Set initial parameters, e.g. sequence numbers; and llocate resources, e.g. buffers Message transfer phase Exchange of SDUs Disconnect phase Example: TCP, PPP n + 1 peer process send n + 1 peer process receive SDU Layer n connection-oriented service SDU
Connectionless Transfer Service No Connection setup, simply send SDU Each message send independently Must provide all address information per message Simple & quick Example: UDP, IP n + 1 peer process send n + 1 peer process receive SDU Layer n connectionless service
Message Size and Structure What message size and structure will a service model accept? Different services impose restrictions on size & structure of data it will transfer Single bit? Block of bytes? Byte stream? Ex: Transfer of voice mail = 1 long message Ex: Transfer of voice call = byte stream (a) 1 voice mail= 1 message = entire sequence of speech samples 1 call = sequence of 1-byte messages (b)
Segmentation & Blocking To accommodate arbitrary message size, a layer may have to deal with messages that are too long or too short for its protocol Segmentation & Reassembly: a layer breaks long messages into smaller blocks and reassembles these at the destination Blocking & Unblocking: a layer combines small messages into bigger blocks prior to transfer 1 long message 2 or more short messages 2 or more blocks 1 block
Reliability & Sequencing Reliability: re messages or information stream delivered error-ee and without loss or duplication? Sequencing: re messages or information stream delivered in order? RQ protocols combine error detection, retransmission, and sequence numbering to provide reliability & sequencing Examples: TCP and HDLC
Pacing and Flow Control Messages can be lost if receiving system does not have sufficient buffering to store arriving messages If destination layer-(n+1) does not retrieve its information fast enough, destination layer-n buffers may overflow Pacing & Flow Control provide backpressure mechanisms that control transfer according to availability of buffers at the destination Examples: TCP and HDLC
Timing pplications involving voice and video generate units of information that are related temporally Destination application must reconstruct temporal relation in voice/video units Network transfer introduces delay & jitter Timing Recovery protocols use timestamps & sequence numbering to control the delay & jitter in delivered information Examples: RTP & associated protocols in Voice over IP
Multiplexing Multiplexing enables multiple layer-(n+1) users to share a layer-n service multiplexing tag is required to identify specific users at the destination Examples: UDP, IP
Privacy, Integrity, & uthentication Privacy: ensuring that information transferred cannot be read by others Integrity: ensuring that information is not altered during transfer uthentication: verifying that sender and/or receiver are who they claim to be Security protocols provide these services and are discussed in Chapter 11 Examples: IPSec, SSL
End-to-End vs. Hop-by-Hop service feature can be provided by implementing a protocol end-to-end across the network across every hop in the network Example: Perform error control at every hop in the network or only between the source and destination? Perform flow control between every hop in the network or only between source & destination? We next consider the tradeoffs between the two approaches
Error control in Data Link Layer (a) (b) Packets Data link layer Physical layer 1 Frames Physical layer entity Packets Data link layer Physical layer 1 2 3 2 1 Medium 1 2 3 2 1 2 B 1 B Data Link operates over wire-like, directly-connected systems Frames can be corrupted or lost, but arrive in order Data link performs error-checking & retransmission Ensures error-ee packet transfer between two systems 2 Data link layer entity 3 Network layer entity
Error Control in Transport Layer Transport layer protocol (e.g. TCP) sends segments across network and performs end-to-end error checking & retransmission Underlying network is assumed to be unreliable End system Messages Transport layer Network layer Data link layer Physical layer Network layer Data link layer Physical layer Segments Network layer Data link layer Physical layer Messages Transport layer Network layer Data link layer Physical layer End system B Network
Segments can experience long delays, can be lost, or arrive out-of-order because packets can follow different paths across network End-to-end error control protocol more difficult C 1 2 3 2 1 End System α End System β 4 3 2 1 1 2 3 2 1 Medium 1 2 3 2 1 1 2 3 4 B 2 1 Network 3 Network layer entity 4 Transport layer entity
End-to-End pproach Preferred Hop-by-hop Data Data Data Data 1 2 3 4 5 CK/ NK CK/ NK CK/ NK CK/ NK Hop-by-hop cannot ensure E2E correctness Faster recovery End-to-end CK/NK Simple inside the network 1 2 3 4 5 Data Data Data Data More scalable if complexity at the edge
Chapter 5 Peer-to-Peer Protocols and Data Link Layer RQ Protocols and Reliable Data Transfer
utomatic Repeat Request (RQ) Purpose: to ensure a sequence of information packets is delivered in order and without errors or duplications despite transmission errors & losses We will look at: Stop-and-Wait RQ Go-Back N RQ Selective Repeat RQ Basic elements of RQ: Error-detecting code with high error coverage CKs (positive acknowledgments NKs (negative acknowlegments) Timeout mechanism
Stop-and-Wait RQ Transmit a ame, wait for CK Packet Timer set after each ame transmission Transmitter (Process ) Information ame Control ame Receiver (Process B) Error-ee packet Header Information packet CRC Header CRC Information ame Control ame: CKs
Need for Sequence Numbers (a) Frame 1 lost B Frame 0 CK Time-out Frame 1 Frame 1 CK Frame 2 Time (b) CK lost B Frame 0 CK Time-out Frame 1 CK Frame 1 CK Frame 2 Time In cases (a) & (b) the transmitting station acts the same way But in case (b) the receiving station B accepts ame 1 twice Question: How is the receiver to know the second ame is also ame 1? nswer: dd ame sequence number in header S last is sequence number of most recent transmitted ame
Sequence Numbers (c) Premature Time-out B Time-out Frame 0 Frame CK 0 CK Frame 1 Frame 2 Time The transmitting station misinterprets duplicate CKs Incorrectly assumes second CK acknowledges Frame 1 Question: How is the receiver to know second CK is for ame 0? nswer: dd ame sequence number in CK header R next is sequence number of next ame expected by the receiver Implicitly acknowledges receipt of all prior ames
1-Bit Sequence Numbering Suffices 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 S last Timer R next Transmitter S last Receiver B R next Global State: (S last, R next ) (0,0) Error-ee ame 0 (0,1) arrives at receiver CK for ame 1 arrives at transmitter Error-ee ame 1 arrives at receiver (1,0) (1,1) CK for ame 0 arrives at transmitter
Stop-and-Wait RQ Transmitter Ready state wait request om higher layer for packet transfer When request arrives, transmit ame with updated S last and CRC Go to Wait State Wait state Wait for CK or timer to expire; block requests om higher layer If timeout expires retransmit ame and reset timer If CK received: If sequence number is incorrect or if errors detected: ignore CK If sequence number is correct (R next = S last +1): accept ame, go to Ready state Receiver lways in Ready State Wait for arrival of new ame When ame arrives, check for errors If no errors detected and sequence number is correct (S last =R next ), then accept ame, update R next, send CK ame with R next, deliver packet to higher layer If no errors detected and wrong sequence number discard ame send CK ame with R next If errors detected discard ame
pplications of Stop-and-Wait RQ IBM Binary Synchronous Communications protocol (Bisync): character-oriented data link control Xmodem: modem file transfer protocol Trivial File Transfer Protocol (RFC 1350): simple protocol for file transfer over UDP
Stop-and-Wait Efficiency First ame bit enters channel Last ame bit enters channel Channel idle while transmitter waits for CK CK arrives t B t First ame bit arrives at receiver Last ame bit arrives at receiver Receiver processes ame and prepares CK 10000 bit ame @ 1 Mbps takes 10 ms to transmit If wait for CK = 1 ms, then efficiency = 10/11= 91% If wait for CK = 20 ms, then efficiency =10/30 = 33%
Stop-and-Wait Model t 0 = total time to transmit 1 ame t proc B t prop ame t f time t proc t ack t prop t 0 = 2t = 2t prop prop + 2t + 2t proc proc + t + f n f R + t ack na + R bits/info ame bits/ck ame channel transmission rate
S&W Efficiency on Error-ee channel Effective transmission rate: R 0 eff bits for header & CRC number of information bits delivered to destination = = total time required to deliver the information bits n f t 0 n o, Transmission efficiency: η 0 = R eff R = n f n t0 R o = 1+ n n a f + n 1 n 2( t o f prop + t n f proc ) R. Effect of ame overhead Effect of CK ame Effect of Delay-Bandwidth Product
Example: Impact of Delay- Bandwidth Product n f =1250 bytes = 10000 bits, n a =n o =25 bytes = 200 bits 2xDelayxBW Efficiency 1 ms 200 km 10 ms 2000 km 100 ms 20000 km 1 sec 200000 km 1 Mbps 10 3 10 4 10 5 10 6 88% 49% 9% 1% 1 Gbps 10 6 10 7 10 8 10 9 1% 0.1% 0.01% 0.001% Stop-and-Wait does not work well for very high speeds or long propagation delays
S&W Efficiency in Channel with Errors Let 1 P f = probability ame arrives w/o errors vg. # of transmissions to first correct arrival is then 1/ (1 P f ) If 1-in-10 get through without error, then avg. 10 tries to success vg. Total Time per ame is then t 0 /(1 P f ) η SW = R eff R = n t 0 f n o 1 P R f = 1+ n n a f + n 1 n 2( t o f prop + t n f proc ) R (1 P f ) Effect of ame loss
Example: Impact Bit Error Rate n f =1250 bytes = 10000 bits, n a =n o =25 bytes = 200 bits Find efficiency for random bit errors with p=0, 10-6, 10-5, 10-4 1 P f = (1 p) n f e n f p for large n f and small p 1 P f Efficiency 1 Mbps & 1 ms 0 10-6 10-5 10-4 1 0.99 0.905 0.368 88% 86.6% 79.2% 32.2% Bit errors impact performance as n f p approach 1
Go-Back-N Improve Stop-and-Wait by not waiting! Keep channel busy by continuing to send ames llow a window of up to W s outstanding ames Use m-bit sequence numbering If CK for oldest ame arrives before window is exhausted, we can continue transmitting If window is exhausted, pull back and retransmit all outstanding ames lternative: Use timeout
Go-Back-N RQ Go-Back-4: 4 ames are outstanding; so go back 4 0 1 2 3 4 5 6 3 4 5 6 7 8 9 Time B C K 1 C K 2 C K 3 out of sequence ames C K 4 C K 5 C K 6 C K 7 C K 8 C K 9 R next 0 1 2 3 3 4 5 6 7 8 9 Frame transmission are pipelined to keep the channel busy Frame with errors and subsequent out-of-sequence ames are ignored Transmitter is forced to go back when window of 4 is exhausted
Window size long enough to cover round trip time Stop-and-Wait RQ 0 Time-out expires 0 1 Time B Receiver is looking for R next =0 C K 1 Go-Back-N RQ 0 1 2 Four ames are outstanding; so go back 4 3 0 1 2 3 4 5 6 Time B Receiver is looking for R next =0 Out-ofsequence ames C K 1 C K 2 C K 3 C K 4 C K 5 C K 6
Go-Back-N with Timeout Problem with Go-Back-N as presented: If ame is lost and source does not have ame to send, then window will not be exhausted and recovery will not commence Use a timeout with each ame When timeout expires, resend all outstanding ames
Go-Back-N Transmitter & Receiver Frames transmitted and CKed Timer Timer Timer Transmitter Send Window... S last S recent S last +W s -1 Buffers S last S last +1... S recent... S last +W s -1 oldest un- CKed ame most recent transmission max Seq # allowed Receiver Frames received Receive Window R next Receiver will only accept a ame that is error-ee and that has sequence number R next When such ame arrives R next is incremented by one, so the receive window slides forward by one
Sliding Window Operation Transmitter Send Window... m-bit Sequence Numbering Frames transmitted and CKed S last S recent S last +W s -1 2 m 1 0 1 Transmitter waits for error-ee CK ame with sequence number S last When such CK ame arrives, S last is incremented by one, and the send window slides forward by one S last send window i + W s 1 i + 1 i 2
Maximum llowable Window Size is W s = 2 m -1 M = 2 2 = 4, Go-Back - 4: Transmitter goes back 4 0 1 2 3 0 1 2 3 Time B C K 1 R next 0 1 2 3 0 C K 2 C K 3 C K 0 Receiver has R next = 0, but it does not know whether its CK for ame 0 was received, so it does not know whether this is the old ame 0 or a new ame 0 M = 2 2 = 4, Go-Back-3: 0 1 2 Transmitter goes back 3 0 1 2 Time B C K 1 C K 2 R next 0 1 2 3 C K 3 Receiver has R next = 3, so it rejects the old ame 0
CK Piggybacking in Bidirectional GBN Transmitter Receiver S B recent RB next S recent R next Receiver Transmitter Receive Window B Receive Window R next Send Window... R B next B Send Window... S last S last +W s -1 Timer Timer Timer Timer Buffers S last S last +1... S recent... S last +W s -1 Note: Out-ofsequence error-ee ames discarded after R next examined S B last S B last +W B s -1 Buffers Timer S B last Timer S B last +1... Timer S B recent... Timer S B last +W B s -1
pplications of Go-Back-N RQ HDLC (High-Level Data Link Control): bitoriented data link control V.42 modem: error control over telephone modem links
Required Timeout & Window Size T out T proc T prop T f T f T prop Timeout value should allow for: Two propagation times + 1 processing time: 2 T prop + T proc ame that begins transmission right before our ame arrives T f Next ame carries the CK, T f W s should be large enough to keep channel busy for T out
Required Window Size for Delay-Bandwidth Product Frame = 1250 bytes =10,000 bits, R = 1 Mbps 2(t prop + t proc ) 2 x Delay x BW Window 1 ms 1000 bits 1 10 ms 10,000 bits 2 100 ms 100,000 bits 11 1 second 1,000,000 bits 101
Efficiency of Go-Back-N GBN is completely efficient, if W s large enough to keep channel busy, and if channel is error-ee ssume P f ame loss probability, then time to deliver a ame is: t f if first ame transmission succeeds (1 P f ) The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. T f + W s t f /(1-P f ) if the first transmission does not succeed P f t η GBN GBN = t f (1 Pf n f no tgbn = R ) + P f { t f s Wst f + 1 P no 1 n f = 1+ ( W 1) P f f } = t f (1 P f + ) P f W t s f 1 P f and Delay-bandwidth product determines W s
Example: Impact Bit Error Rate on GBN n f =1250 bytes = 10000 bits, n a =n o =25 bytes = 200 bits Compare S&W with GBN efficiency for random bit errors with p = 0, 10-6, 10-5, 10-4 and R = 1 Mbps & 100 ms 1 Mbps x 100 ms = 100000 bits = 10 ames Use W s = 11 Efficiency 0 10-6 10-5 10-4 S&W 8.9% 8.8% 8.0% 3.3% GBN 98% 88.2% 45.4% 4.9% Go-Back-N significant improvement over Stop-and-Wait for large delay-bandwidth product Go-Back-N becomes inefficient as error rate increases
Selective Repeat RQ Go-Back-N RQ inefficient because multiple ames are resent when errors or losses occur Selective Repeat retransmits only an individual ame Timeout causes individual corresponding ame to be resent NK causes retransmission of oldest un-acked ame Receiver maintains a receive window of sequence numbers that can be accepted Error-ee, but out-of-sequence ames with sequence numbers within the receive window are buffered rrival of ame with R next causes window to slide forward by 1 or more
B 0 Time 1 2 3 4 5 6 2 C K 1 8 9 7 10 11 12 C K 2 N K 2 C K 7 C K 8 C K 9 C K 1 0 C K 1 1 C K 1 2 C K 2 C K 2 C K 2 Selective Repeat RQ
Selective Repeat RQ Transmitter Send Window... Receiver Receive Window Frames transmitted and CKed S last S recent S last + W s -1 Frames received R next R next + W r -1 Timer Buffers S last Buffers R next + 1 Timer S last + 1 R next + 2 Timer... S recent...... R next + W r - 1 max Seq # accepted S last + W s - 1
Send & Receive Windows Transmitter Receiver 2 m -1 0 1 2 m -1 0 1 S last send window i + W s 1 i + 1 Moves k forward when CK arrives with R next = S last + k k = 1,, W s -1 i 2 j + W r 1 R next receive window Moves forward by 1 or more when ame arrives with Seq. # = R next i 2 j
What size W s and W r allowed? Example: M=2 2 =4, W s =3, W r =3 Send Window Frame 0 resent {0,1,2} {1,2} {2} {.} 0 1 2 0 Time Receive Window B CK1 CK2 CK3 {0,1,2} {1,2,3} {2,3,0} {3,0,1} Old ame 0 accepted as a new ame because it falls in the receive window
W s + W r = 2 m is maximum allowed Example: M=2 2 =4, W s =2, W r =2 Send Window {0,1} {1} {.} 0 1 Frame 0 resent 0 Time Receive Window B CK1 {0,1} {1,2} CK2 {2,3} Old ame 0 rejected because it falls outside the receive window
Why W s + W r = 2 m works Transmitter sends ames 0 to Ws-1; send window empty ll arrive at receiver ll CKs lost Transmitter resends ame 0 Receiver window starts at {0,, W r } Window slides forward to {W s,,w s +W r -1} Receiver rejects ame 0 because it is outside receive window 2 m -1 0 1 2 m -1 0 1 S last 2 W s +W r -1 2 send window W s -1 receive window R next W s
pplications of Selective Repeat RQ TCP (Transmission Control Protocol): transport layer protocol uses variation of selective repeat to provide reliable stream service Service Specific Connection Oriented Protocol: error control for signaling messages in TM networks
Efficiency of Selective Repeat ssume P f ame loss probability, then number of transmissions required to deliver a ame is: t f / (1-P f ) The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. η SR = t f n f R n o /(1 P f ) = (1 n n o f )(1 P f )
Example: Impact Bit Error Rate on Selective Repeat n f =1250 bytes = 10000 bits, n a =n o =25 bytes = 200 bits Compare S&W, GBN & SR efficiency for random bit errors with p=0, 10-6, 10-5, 10-4 and R= 1 Mbps & 100 ms Efficiency 0 10-6 10-5 10-4 S&W 8.9% 8.8% 8.0% 3.3% GBN 98% 88.2% 45.4% 4.9% SR 98% 97% 89% 36% Selective Repeat outperforms GBN and S&W, but efficiency drops as error rate increases
Comparison of RQ Efficiencies ssume n a and n o are negligible relative to n f, and L = 2(t prop +t proc )R/n f =(W s -1), then Selective-Repeat: Go-Back-N: η η SR GBN no = ( 1 Pf )(1 ) (1 Pf ) n 1 Pf = 1+ ( W 1) P Stop-and-Wait: (1 P ηsw = n 2( t a 1+ + n f S f prop ) + t n f f f 1 Pf = 1+ LP proc ) R f 1 Pf 1+ L For P f 0, SR & GBN same For P f 1, GBN & SW same
RQ Efficiencies Efficiency RQ Efficiency Comparison 1.5 1 0.5 0-9 -8-7 -6-5 -4-3 -2-1 10-9 10-8 10-7 10-6 10-5 10-4 10-3 10-2 10-1 - LOG(p) p Delay-Bandwidth product = 10, 100 Selective Repeat Go Back N 10 Stop and Wait 100 Go Back N 100 Stop and Wait 10
Chapter 5 Peer-to-Peer Protocols and Data Link Layer Flow Control
Flow Control Transmitter Information ame buffer fill Receiver Control ame Receiver has limited buffering to store arriving ames Several situations cause buffer overflow Mismatch between sending rate & rate at which user can retrieve data Surges in ame arrivals Flow control prevents buffer overflow by regulating rate at which source is allowed to send information
X ON / X OFF Information ame threshold Transmitter Receiver Transmit X OFF Transmit Time on off off on B Time 2T prop Threshold must activate OFF signal while 2 T prop R bits still remain in buffer
Window Flow Control t cycle Return of permits Time B Sliding Window RQ method with W s equal to buffer available Transmitter can never send more than W s ames CKs that slide window forward can be viewed as permits to transmit more Can also pace CKs as shown above Return permits (CKs) at end of cycle regulates transmission rate Problems using sliding window for both error & flow control Choice of window size Interplay between transmission rate & retransmissions TCP separates error & flow control Time
Chapter 5 Peer-to-Peer Protocols and Data Link Layer Timing Recovery
Timing Recovery for Synchronous Services Synchronous source sends periodic information blocks Network output not periodic Network pplications that involve voice, audio, or video can generate a synchronous information stream Information carried by equally-spaced fixed-length packets Network multiplexing & switching introduces random delays Packets experience variable transfer delay Jitter (variation in interpacket arrival times) also introduced Timing recovery re-establishes the synchronous nature of the stream
Introduce Playout Buffer Packet rrivals Packet rrivals Playout Buffer Packet Playout Packet Playout Sequence numbers help order packets T max Delay first packet by maximum network delay ll other packets arrive with less delay Playout packet uniformly thereafter
Playout clock must be synchronized to transmitter clock Time Send times rrival times Playout times Receiver too slow; buffer fills and overflows T playout time Time Receiver too fast buffer starvation Time Receiver speed just right Many late packets T playout time T playout time
Clock Recovery Timestamps inserted in packet payloads indicate when info was produced t 4 t 3 t 2 t 1 Timestamps + - Buffer for information blocks Error signal dd Smoothing filter Counter djust equency Playout command Recovered clock Counter attempts to replicate transmitter clock Frequency of counter is adjusted according to arriving timestamps Jitter introduced by network causes fluctuations in buffer & in local clock
Synchronization to a Common Clock Transmitter Receiver f s M Network M f r M=#ticks in local clock In time that net clock does N ticks f n /f s =N/M N ticks f n N ticks Δf=f n -f s =f n -(M/N)f n f r =f n -Δf Network clock Clock recovery simple if a common clock is available to transmitter & receiver E.g. SONET network clock; Global Positioning System (GPS) Transmitter sends Δf of its equency & network equency Receiver adjusts network equency by Δf Packet delay jitter can be removed completely
Example: Real-Time Protocol RTP (RFC 1889) designed to support realtime applications such as voice, audio, video RTP provides means to carry: Type of information source Sequence numbers Timestamps ctual timing recovery must be done by higher layer protocol MPEG2 for video, MP3 for audio
Chapter 5 Peer-to-Peer Protocols and Data Link Layer TCP Reliable Stream Service & Flow Control
TCP Reliable Stream Service pplication Layer writes bytes into send buffer through socket pplication layer Transport layer Write 45 bytes Write 15 bytes Write 20 bytes TCP transfers byte stream in order, without errors or duplications Segments pplication Layer reads bytes om receive buffer through socket Read 40 bytes Read 40 bytes Transmitter Send buffer CKs Receive buffer Receiver
TCP RQ Method TCP uses Selective Repeat RQ Transfers byte stream without preserving boundaries Operates over best effort service of IP Packets can arrive with errors or be lost Packets can arrive out-of-order Packets can arrive after very long delays Duplicate segments must be detected & discarded Must protect against segments om previous connections Sequence Numbers Seq. # is number of first byte in segment payload Very long Seq. #s (32 bits) to deal with long delays Initial sequence numbers negotiated during connection setup (to deal with very old duplicates) ccept segments within a receive window
Transmitter Send Window S last + W a -1......... Receiver Receive Window R last R last + W R 1 octets transmitted & CKed S last S last + W s 1 S recent R next R new S last oldest unacknowledged byte S recent highest-numbered transmitted byte S last +W a -1 highest-numbered byte that can be transmitted S last +W s -1 highest-numbered byte that can be accepted om the application R last highest-numbered byte not yet read by the application R next next expected byte R new highest numbered byte received correctly R last +W R -1 highest-numbered byte that can be accommodated in receive buffer
TCP Connections TCP Connection One connection each way Identified uniquely by Send IP ddress, Send TCP Port #, Receive IP ddress, Receive TCP Port # Connection Setup with Three-Way Handshake Three-way exchange to negotiate initial Seq. # s for connections in each direction Data Transfer Exchange segments carrying data Graceful Close Close each direction separately
Three Phases of TCP Connection Host SYN, Seq_no = x Host B Three-way Handshake SYN, Seq_no = y, CK, ck_no = x+1 Seq_no = x+1, CK, ck_no = y+1 Data Transfer FIN, Seq_no = w Graceful Close CK, ck_no = w+1 Data Transfer FIN, Seq_no = z CK, ck_no = z+1
1st Handshake: Client-Server Connection Request Initial Seq. # om client to server SYN bit set indicates request to establish connection om client to server
2 nd Handshake: CK om Server CK Seq. # = Init. Seq. # + 1 CK bit set acknowledges connection request; Clientto-Server connection established
2nd Handshake: Server-Client Connection Request Initial Seq. # om server to client SYN bit set indicates request to establish connection om server to client
3 rd Handshake: CK om Client CK Seq. # = Init. Seq. # + 1 CK bit set acknowledges connection request; Connections in both directions established
TCP Data Exchange pplication Layers write bytes into buffers TCP sender forms segments When bytes exceed threshold or timer expires Upon PUSH command om applications Consecutive bytes om buffer inserted in payload Sequence # & CK # inserted in header Checksum calculated and included in header TCP receiver Performs selective repeat RQ functions Writes error-ee, in-sequence bytes to receive buffer
Data Transfer: Server-to-Client Segment 12 bytes of payload Push set 12 bytes of payload carries telnet option negotiation
Graceful Close: Client-to-Server Connection Client initiates closing of its connection to server
Graceful Close: Client-to-Server Connection CK Seq. # = Previous Seq. # + 1 Server CKs request; clientto-server connection closed
Flow Control TCP receiver controls rate at which sender transmits to prevent buffer overflow TCP receiver advertises a window size specifying number of bytes that can be accommodated by receiver W = W R (R new R last ) TCP sender obliged to keep # outstanding bytes below W (S recent - S last ) W Send Window S last + W -1......... Receive Window W S last S last + W s 1 S recent R last R new R last + W R 1
TCP window flow control Host Host B Seq_no = 1, ck_no = 2000, Win = 2048, No Data t 0 t 1 t 2 Seq_no = 2000, ck_no = 1, Win = 1024, Data = 2000-3023 Seq_no = 3024, ck_no = 1, Win = 1024, Data = 3024-4047 Seq_no = 1, ck_no = 4048, Win = 512, Data = 1-128 t 3 t 4 Seq_no = 4048, ck_no = 129, Win = 1024, Data = 4048-4559
TCP Retransmission Timeout TCP retransmits a segment after timeout period Timeout too short: excessive number of retransmissions Timeout too long: recovery too slow Timeout depends on RTT: time om when segment is sent to when CK is received Round trip time (RTT) in Internet is highly variable Routes vary and can change in mid-connection Traffic fluctuates TCP uses adaptive estimation of RTT Measure RTT each time CK received: τ n t RTT (new) = α t RTT (old) + (1 α) τ n α = 7/8 typical
RTT Variability Estimate variance σ 2 of RTT variation Estimate for timeout: t out = t RTT + k σ RTT If RTT highly variable, timeout increase accordingly If RTT nearly constant, timeout close to RTT estimate pproximate estimation of deviation d RTT (new) = β d RTT (old) + (1-β) τ n - t RTT t out = t RTT + 4 d RTT