End-to-End Protocols: Larry L. Peterson and Bruce S. Davie
End-to-End Protocols: Larry L. Peterson and Bruce S. Davie
Chapter 5
End-to-End Protocols
2
Chapter 5
2 main protocols
Simple Demultiplexer (UDP)
Reliable Byte Stream (TCP)
3
Chapter 5
End-to-end Protocols
Common properties that a transport protocol can be expected
to provide
Guarantees message delivery
receiver
Allows the receiver to apply flow control to the sender
4
Chapter 5
End-to-end Protocols
Typical limitations of the network on which transport
protocol will operate
Drop messages
Reorder messages
5
Chapter 5
Simple Demultiplexer (UDP)
Simplest protocol in transport layer that extends host-to-host
delivery service of the underlying network into a process-to-
process communication service is called UDP(User Datagram
Protocol)
The next issue is how a process learns the port for the process to
which it wants to send a message.
7
Chapter 5
Once a client has contacted a server, the server knows the
client’s port (it was contained in the message header) and can
reply to it.
The real problem, therefore, is how the client learns the server’s
port in the first place. A common approach is for the server to
accept messages at a well-known port.
8
Chapter 5
Well-known ports used with UDP
9
Chapter 5
TCP Well-known port numbers
10
Chapter 5
UDP Packet Format
11
Chapter 5
Source port number:
This is the port number used by the process running on the
source host. It is 16 bits long, which means that the port
number can range from 0 to 65,535.
12
Chapter 5
Destination port number:
This is the port number used by the process running on the
destination host. It is also 16 bits long.
13
Chapter 5
Length:
This is a 16-bit field that defines the total length of the user
datagram, header plus data.
Checksum:
This field is used to detect errors over the entire user datagram
(header plus data).
14
Chapter 5
Simple Demultiplexer (UDP)
15
Chapter 5
UDP does not implement flow control or reliable/ordered
delivery.
16
Chapter 5
UDP Operations
In UDP, a process (an application program) sends messages,
with predefined boundaries, to UDP for delivery.
UDP adds its own header to each of these messages and delivers
them to IP for transmission.
17
Chapter 5
Reliable Byte Stream (TCP)
In contrast to UDP, Transmission Control Protocol (TCP)
offers the following services
Reliable
Connection oriented
Byte-stream service
CP will deliver segments to the applications in order and
without error, lost, or duplicates.
18
Chapter 5
TCP establishes a virtual connection.
TCP connection ensures that the receiving process is
available and ready before the data is sent.
19
Chapter 5
Stream Delivery Service
TCP, allows the sending process to deliver data as a stream of
bytes and allows the receiving process to obtain data as a stream
of bytes.
The sending process produces (writes to) the stream of bytes, and
the receiving process consumes (reads from) them.
20
Chapter 5
Sending and Receiving Buffers
Because the sending and the receiving processes may not write
or read data at the same speed, TCP needs buffers for storage.
There are two buffers, the sending buffer and the receiving
buffer, one for each direction.
21
Chapter 5
22
Chapter 5
At the sending site, the buffer has three types of chambers.
The gray area holds bytes that have been sent but not yet
acknowledged.
23
Chapter 5
After the bytes in the gray chambers are acknowledged, the
chambers are recycled and available for use by the sending process.
The operation of the buffer at the receiver site is simpler.
The circular buffer is divided into two areas (shown as white and
colored).
The colored sections contain received bytes that can be read by the
receiving process.
When a byte is read by the receiving process, the chamber is
recycled and added to the pool of empty chambers.
24
Chapter 5
Segments:
The IP layer, as a service provider for TCP, needs to send data
in packets, not as a stream of bytes.
Full-Duplex Communication:
TCP offers full-duplex service, in which data can flow in both
directions at the same time.
Each TCP then has a sending and receiving buffer, and
segments move in both directions.
27
Chapter 5
Connection-Oriented Service:
TCP, unlike UDP, is a connection-oriented protocol.
28
Chapter 5
Reliable Service:
TCP is a reliable transport protocol.
It uses an acknowledgment mechanism to check the safe and
sound arrival of data.
29
Chapter 5
TCP Segment Format
30
Chapter 5
Minimum header length is 20 bytes and the maximum is 60
bytes when there are options .
Source port address : This is a 16-bit field that defines the port
number of the application program in the host that is sending
the segment.
Destination port address : This is a 16-bit field that defines the
port number of the application program in the host that is
receiving the segment.
Sequence number: This 32-bit field defines the number
assigned to the first byte of data contained in this segment.
31
Chapter 5
Acknowledgment number: This 32-bit field defines the byte
number that the receiver of the segment is expecting to receive
from the other party.
32
Chapter 5
Header length: This 4-bit field indicates the number of 4-byte
words in the TCP header. The length of the header can be
between 20 and 60 bytes.
33
Chapter 5
34
Chapter 5
Window size: This field defines the size of the window, in bytes,
that the other party must maintain.
Checksum: This 16-bit field contains the checksum for error
detection.
Urgent pointer: This l6-bit field, which is valid only if the
urgent flag is set, is used when the segment contains urgent
data.
It defines the number that must be added to the sequence
number to obtain the number of the last urgent byte in the data
section of the segment.
Options: There can be up to 40 bytes of optional information
in the TCP header.
35
Chapter 5
Flow control VS Congestion control
Flow control involves preventing senders from overrunning the
capacity of the receivers.
Congestion control involves preventing too much data from being
injected into the network, thereby causing switches or links to
become overloaded.
36
Chapter 5
End-to-end Issues(TCP Issues)
The heart of TCP is the sliding window algorithm
37
Chapter 5
End-to-end Issues
TCP needs a mechanism using which each side of a connection
will learn what resources(how much buffer space) the other side is
able to apply to the connection. This is flow control issue.
TCP needs a mechanism using which the sending side will learn
the capacity of the network.
38
Chapter 5
A TCP Connection
TCP is connection-oriented.
39
Chapter 5
Connection Establishment
TCP transmits data in full-duplex mode.
When two TCPs in two machines are connected, they are able to
send segments to each other simultaneously.
40
Chapter 5
Three-Way Handshaking
The connection establishment in TCP is called three-way
handshaking.
The process starts with the server. The server program tells
its TCP that it is ready to accept a connection. This is called a
request for a passive open.
41
Chapter 5
Although the server TCP is ready to accept any
connection from any machine in the world, it cannot
make the connection itself.
42
Chapter 5
43
Chapter 5
First Step
The client sends the first segment, a SYN segment, in which
We can say that the SYN segment carries no real data.
A SYN segment cannot carry data, but it consumes one
sequence number.
44
Chapter 5
Second Step
The server sends the second segment, a SYN +ACK
segment, with 2 flag bits set: SYN and ACK.
45
Chapter 5
Third step
The client sends the third segment. This is just an ACK
segment.
It acknowledges the receipt of the second segment with the
ACK flag and acknowledgment number field.
46
Chapter 5
Data Transfer
After connection is established, bidirectional data transfer
can take place.
The client and server can both send data and
acknowledgments.
47
Chapter 5
48
Chapter 5
After connection is established , the client sends 2000 bytes
of data in two segments.
49
Chapter 5
The data segments sent by the client have the PSH (push)
flag set so that the server TCP knows to deliver data to the
server process as soon as they are received.
The segment from the server, on the other hand, does not
set the push flag.
Pushing Data
The sending TCP uses a buffer to store the stream of data
coming from the sending application program.
The sending TCP can select the segment size.
50
Chapter 5
The receiving TCP also buffers the data when they arrive
and delivers them to the application program when the
application program is ready or when it is convenient for
the receiving TCP.
51
Chapter 5
Connection Termination
Any of the two parties involved in exchanging data (client or
server) can close the connection, although it is usually initiated
by the client.
Three way and four way handshaking techniques are available.
Three-way Handshaking:
First step
command from the client process, sends the first segment, a FIN
segment in which the FIN flag is set.
52
Chapter 5
Note that a FIN segment can include the last chunk of data
sent by the client, or it can be just a control segment.
53
Chapter 5
This segment can also contain the last chunk of data from the
server.
If it does not carry data, it consumes only one sequence
number.
Third Step
The client TCP sends the last segment, an ACK segment, to
confirm the receipt of the FIN segment from the TCP server.
54
Chapter 5
55
Chapter 5
Sliding Window Revisited
TCP’s variant of the sliding window algorithm, which serves
several purposes:
(1) it guarantees the reliable delivery of data,
(3) it enforces flow control between the sender and the receiver.
56
Chapter 5
Rather than having a fixed-size sliding window, the receiver
advertises a window size to the sender.
57
Chapter 5
Reliable and Ordered Delivery
TCP on the sending side maintains a send buffer.
This buffer is used to store data that has been sent but not yet
acknowledged, as well as data that has been written by the
sending application, but not transmitted.
This buffer holds data that arrives out of order, as well as data
that is in the correct order but that the application process has
not yet had the chance to read.
58
Chapter 5
Sliding Window Revisited
Relationship between TCP send buffer (a) and receive buffer (b).
59
Chapter 5
At the sending side, three pointers are maintained into the send
buffer, each with an obvious meaning:
LastByteAcked ≤ LastByteSent
LastByteSent ≤ LastByteWritten
60
Chapter 5
At the receiving side, similar three pointers are maintained into
the receive buffer, each with an obvious meaning:
LastByteRead, NextByteExpected, and LastByteRcvd.
61
Chapter 5
Note that bytes to the left of LastByteRead need not be buffered
because they have already been read by the local application
process.
Flow Control
The size of the window sets the amount of data that can be sent
without waiting for acknowledgment from the receiver.
62
Chapter 5
TCP on the receive side must keep,
LastByteRcvd− LastByteRead ≤ MaxRcvBuffer
to avoid overflowing its buffer.
63
Chapter 5
Triggering Transmission
Issue : how TCP decides to transmit a segment.
If we ignore the possibility of flow control—that is, we assume the
window is wide open, as would be the case when a connection first
starts—then TCP has three mechanisms to trigger the
transmission of a segment.
MSS is usually set to the size of the largest segment TCP can send
without causing the local IP to fragment.
64
Chapter 5
The second thing that triggers TCP to transmit a segment is
that the sending process has explicitly asked it to do so.
65
Chapter 5
Silly Window Syndrome (SWS) is a problem that can arise in
poor implementations of TCP when the receiver is only able to
accept a few bytes at a time or when the sender transmits data in
small segments repeatedly.
66
Chapter 5
Nagle's algorithm:
It is a means of improving the efficiency of TCP/IP networks by
reducing the number of packets that need to be sent over the
network.
To reduce the no of small packets, the TCP sender needs to wait
until the receiver buffer size is equal to MSS.
67
Chapter 5
Nagle introduced an elegant self-clocking solution-a clock-
based timer—ACK.
The idea is that as long as TCP has any data in flight, the
sender will eventually receive an ACK.
68
Chapter 5
When the application produces data to send
if both the available data and the window ≥ MSS
send a full segment
else
if there is unACKed data in flight
buffer the new data until an ACK arrive
else
send all the new data now
69
Chapter 5
In other words, it’s always OK to send a full segment if the
window allows.
70
Chapter 5
Adaptive Retransmission
TCP guarantees the reliable delivery of data, it retransmits each
segment if an ACK is not received in a certain period of time.
71
Chapter 5
Original Algorithm
A simple algorithm for computing a timeout value between a
pair of hosts.
Every time TCP sends a data segment, it records the time.
When an ACK for that segment arrives, TCP reads the time
again, and then takes the difference between these two times as
a SampleRTT.
72
Chapter 5
EstimatedRTT = α ×EstimatedRTT+(1−α)×SampleRTT
The parameter α is used to smoothen Estimated RTT
(represents changes in the RTT).
Karn/Partridge Algorithm
In other words, whenever a segment is retransmitted and then
73
Chapter 5
74
Chapter 5
if you assume that the ACK is for the original transmission but it
was really for the second, then the SampleRTT is too large(a),
while if you assume that the ACK is for the second transmission
but it was actually for the first, then the SampleRTT is too small
(b).
Each time TCP retransmits, it sets the next timeout to be twice the
last timeout, rather than basing it on the last EstimatedRTT.
75
Chapter 5
Jacobson/Karels Algorithm
The Karn/Partridge algorithm was designed to fix some of the
The main problem with the original computation is that it does not
take the variance of the sample RTTs into account.
If the variation among samples is small, then the Estimated RTT
can be better trusted and there is no reason for multiplying this
estimate by 2 to compute the timeout.
76
Chapter 5
A large variance in the samples suggests that the timeout value
should not be too tightly coupled to the EstimatedRTT.
Timeout Calculation:
Difference = SampleRTT−EstimatedRTT
EstimatedRTT = EstimatedRTT+(δ ×Difference)
Deviation = Deviation+δ(|Difference| − Deviation)
77
Chapter 5
TCP then computes the timeout value as a function of both
EstimatedRTT and Deviation as follows:
78
Chapter 5
TCP Congestion Control
The essential strategy of TCP is to send packets into the network
without a reservation and then to react to observable events that
occur.
Once a given source has this many packets in transit, it uses the
arrival of an ACK as a signal that one of its packets has left the
network, and that it is therefore safe to insert a new packet into
the network without adding to the level of congestion.
79
Chapter 5
Three independent mechanisms
Additive Increase/Multiplicative Decrease
Slow Start
80
Chapter 5
TCP is modified such that the maximum number of bytes of
unacknowledged data allowed is now the minimum of the
congestion window and the advertised window.
81
Chapter 5
This involves decreasing the congestion window when the level
of congestion goes up and increasing the congestion window
when the level of congestion goes down.
82
Chapter 5
TCP interprets timeouts as a sign of congestion and reduces the
rate at which it is transmitting.
83
Chapter 5
Additional losses cause CongestionWindow to be reduced to 4,
then 2, and finally to 1 packet.
84
Chapter 5
Packets in transit during additive increase, with one packet being added each
RTT.
85
Chapter 5
It works as follows:
86
Chapter 5
87
Chapter 5
AIMD operation can be represented as a sawtooth pattern.
88
Chapter 5
Slow Start
The additive increase mechanism just described is the right
approach to use when the source is operating close to the
available capacity of the network, but it takes too long to ramp up
a connection when it is starting from scratch.
89
Chapter 5
Upon receiving the corresponding two ACKs, TCP increments
CongestionWindow by 2—one for each ACK—and next sends
four packets.
90
Chapter 5
91
Chapter 5
There are actually two different situations in which slow start
runs.
92
Chapter 5
The second situation in which slow start is used is a bit more
subtle; it occurs when the connection goes dead while waiting for
a timeout to occur.
93
Chapter 5
The source will instead receive a single cumulative ACK that
reopens the entire advertised window, but as explained above,
the source then uses slow start to restart the flow of data
rather than dumping a whole window’s worth of data on the
network all at once.
94
Chapter 5
95
Chapter 5
Fast Retransmit and Fast Recovery
The mechanisms described so far were part of the original
proposal to add congestion control to TCP.
96
Chapter 5
Fast retransmit is a heuristic that sometimes triggers the
retransmission of a dropped packet sooner than the regular
timeout mechanism.
97
Chapter 5
Thus, when a packet arrives out of order—that is, TCP cannot
yet acknowledge the data the packet contains because earlier
data has not yet arrived—TCP resends the same
acknowledgment it sent the last time.
When the sending side sees a duplicate ACK, it knows that the
other side must have received a packet out of order, which
suggests that an earlier packet might have been lost.
98
Chapter 5
Since it is also possible that the earlier packet has only been
delayed rather than lost, the sender waits until it sees some
number of duplicate ACKs and then retransmits the missing
packet.
99
Chapter 5
100
Chapter 5
In this example, the destination receives packets 1 and 2, but
packet 3 is lost in the network.
When the sender sees the third duplicate ACK for packet 2—
the one sent because the receiver had gotten packet 6—it
retransmits packet 3.
101
Chapter 5
When the fast retransmit mechanism signals congestion, rather
than drop the congestion window all the way back to one
packet and run slow start, it is possible to use the ACKs that
are still in the pipe to clock the sending of packets.
102
Chapter 5
Trace of TCP with fast retransmit. Colored line =
CongestionWindow; solid bullet = timeout; hash marks = time
when each packet is transmitted; vertical bars = time when a
packet that was eventually retransmitted was first transmitted.
103