Professional Documents
Culture Documents
Network Protocol 5
Network Protocol 5
Lecture - 5
Challenges of Reliable Data Transfer
2
TCP Support for Reliable Delivery
• Checksum
– Used to detect corrupted data at the receiver
– …leading the receiver to drop the packet
• Sequence numbers
– Used to detect missing data
– ... and for putting the data back in order
• Retransmission
– Sender retransmits lost or corrupted data
– Timeout based on estimates of round-trip time
– Fast retransmit algorithm for rapid retransmission
3
Protocol Data Units (PDU)
• At each layer, protocols are used to communicate.
• Control information is added to user data at each
layer
• Transport layer may fragment user data
• Each fragment has a transport header added
– Destination
– Sequence number
– Error detection code
• This gives a transport protocol data unit
Initial Sequence Number (ISN)
5
TCP Three-Way Handshake
6
Establishing a TCP Connection
A B
SYN
SYN A
CK Each host
tells its ISN
ACK to the other
Data host.
Data SYN (synchronize sequence number)
Timeout
within some time period
ACK
• Simplest ARQ protocol
– Stop and wait Time
– Send a packet, stop and wait
until ACK arrives
8
Reasons for Retransmission
Timeout
Timeout
ACK K
AC
Packe
Packe Packe t
t t
Timeout
Timeout
Timeout
ACK
ACK ACK
11
Sliding Window
• Allow a larger amount of data “in flight”
– Allow sender to get ahead of the receiver
– … though not too far ahead
Sending process Receiving process
TCP TCP
Last byte written Last byte read
Suppose that host A is sending a large file to host B over a TCP connection. Host B
allocates a receive buffer to this connection; denote its size by RcvBuffer. From time to
time, the application process in host B reads from the buffer. Define the following
variables:
LastByteRead = the number of the last byte in the data stream read from the buffer by the
application process in B.
LastByteRcvd = the number of the last byte in the data stream that has arrived from the
network and has been placed in the receive buffer at B.
Because TCP is not permitted to overflow the allocated buffer, we
must have:
How does the connection use the variable RcvWindow to provide the flow control
service?
Host B informs host A of how much spare room it has in the connection buffer by
placing its current value of RcvWindow in the window field of every segment it
sends to A. Initially host B sets RcvWindow = RcvBuffer.
Note that to pull this off, host B must keep track of several connection-specific
variables.
Host A in turn keeps track of two variables, LastByteSent and
LastByteAcked, which have obvious meanings.
Note that the difference between these two variables, LastByteSent -
LastByteAcked, is the amount of unacknowledged data that A has sent
into the connection.
By keeping the amount of unacknowledged data less than the value of
RcvWindow, host A is assured that it is not overflowing the receive
buffer at host B. Thus host A makes sure throughout the connection's
life that LastByteSent - LastByteAcked <= RcvWindow.
There is one minor technical problem with this scheme. To see this, suppose host B's receive
buffer becomes full so that RcvWindow = 0.?
Fast Retransmission
Timeout is Inefficient
• Timeout-based retransmission
– Sender transmits a packet and waits until timer expires
– … and then retransmits from the lost packet onward
Tearing Down the Connection
B
SYN A
FIN A
ACK
ACK
ACK
SYN
FIN
FIN
Data
C
CK
K
A
time