The Transport layer
The transport layer is responsible for the delivery
of a message from one process to another.
❑ Service-point addressing
❑ Segmentation and reassembly
❑ Connection control
❑ Flow control
❑ Error control
Transmission
Control Protocol
2
TCP/IP protocol suite
3
TCP Services -
Provides a connection oriented,reliable,full duplex,byte
stream service.
TCP provides end to end reliability using Checksum , positive
acknowledgements , time out , end to end flow control .
TCP also handles
Establishment and termination of connection between
processes.
Sequencing of data that might reach the destination out of
order.
4
TCP/IP Protocol Suite 5
Socket Addresses
A transport-layer protocol in the TCP suite needs both the IP address
and the port number, at each end, to make a connection. The
combination of an IP address and a port number is called a socket
address. The client socket address defines the client process uniquely
just as the server socket address defines the server process uniquely .
To use the services of transport layer in the Internet, we need a pair of
socket addresses: the client socket address and the server socket
address. These four pieces of information are part of the network-layer
packet header and the transport-layer packet header. The first
header contains the IP addresses; the second header contains the port
numbers.
Well-known ports used by TCP
Stream delivery
TCP, on the other hand, 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. TCP creates an environment in
which the two processes seem to be connected by an imaginary
“tube” that carries their bytes across the Internet. This imaginary
environment is depicted in Figure . The sending process produces
(writes to) the stream and the receiving process consumes (reads
from) it.
Sending and receiving buffers
Sending and Receiving Buffers
Because the sending and the receiving processes may not
necessarily write or read data at the same rate, TCP needs
buffers for storage. There are two buffers, the sending buffer and
the receiving buffer, one for each direction. We will see later that
these buffers are also necessary for flow- and error-control
mechanisms used by TCP. One way to implement a buffer is to
use a circular array of 1-byte locations as shown in Figure. For
simplicity, we have shown two buffers of 20 bytes each; normally
the buffers are hundreds or thousands of bytes, depending on the
implementation. We also show the buffers as the same size,
which is not always the case. The figure shows the movement of
the data in one direction. At the sender, the buffer
has three types of chambers. The white section contains empty
chambers that can be filled by the sending process (producer).
The colored area holds bytes that have been sent but not yet
acknowledged. The TCP sender keeps these bytes in the buffer
until it receives an acknowledgment. The shaded area contains
bytes to be sent by the sendingTCP.
However, TCP may be able to send only part of this shaded
section. This could be due to the slowness of the receiving
process or to congestion in the network. Also note that, after the
bytes in the colored chambers are acknowledged, the chambers
are recycled and available for use by the sending process. This is
why we show a circular buffer.
The operation of the buffer at the receiver is simpler. The circular
buffer is divided into two areas (shown as white and colored). The
white area contains empty chambers to be filled by bytes received
from the network. 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.
TCP segments
Segments
Although buffering handles the disparity between the speed of the
producing and consuming processes, we need one more step
before we can send data. The network layer, as a service provider
for TCP, needs to send data in packets, not as a stream of bytes.
At the transport layer, TCP groups a number of bytes together into
a packet called a segment.
TCP adds a header to each segment (for control purposes) and
delivers the segment to the network layer for transmission. The
segments are encapsulated in an IP datagram and transmitted.
This entire operation is transparent to the receiving process. Later
we will see that segments may be received out of order, lost or
corrupted, and resent. All of these are handled by the TCP
receiver with the receiving application process unaware of TCP’s
activities. Figure shows how segments are created from the bytes
in the buffers.
TCP segment format
Source port address – This is a 16 bit field that
defines a 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 a port number of the application program
in the host that is receiving the segment.
Sequence number –This 32 bit defines the number
assigned to the first bite of the data contained in this
segment. Since TCP is a stream transport protocol,
each byte to be transmitted is numbered. The
sequence number tells the destination which byte in
this sequence comprises the first byte in this
[Link] connection establishment each party
uses a random number generator to creat an initial
sequence number which is usually different in each
direction.
Acknowledgment number-This 32 bit field defines
the bite number that the receiver of the segment is
expecting to receive from the other party.
If the receiver of the segment has received byte
number n from the other party, it defines n+1 as the
acknowledgment number. Acknowledgment and data
can be piggybacked togather.
Header length- This 4 bit field indicates the number
of 4 byte word in the TCP [Link] length of the
header can be between 20 and 60 bytes.
Reserved – This is a 6 bit field reserved for future
use.
Control – This field defines 6 different control bitsor
flags .
Control field
Description of flags in the control field
I
Window size – This field defines the size of the window,
in bytes, that the other party must maintain. Length of
this field is 16 bits. That means the maximum size of the
window is 65535 bytes. This value is normally referred to
as the receiving window and is determined by the
receiver.
The sender must obey the receiver in this case.
Checksum –This 16 bit field contains the checksum used
to check the Errors in the header.
Urgent Pointer – This 16 bit field which is valid only if
the urgent pointer 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.
Options – There can be up to 40 bytes of optional 19
Pseudoheader added to the TCP datagram
The inclusion of the checksum in TCP is mandatory.
Encapsulation and decapsulation
To send a message from one process to another, the transport
layer protocol encapsulates and decapsulates messages .
A TCP Connection --
TCP is connection-oriented. A connection-oriented
transport protocol establishes a virtual path between the
source and destination. All of the segments belonging to
a message are then sent over this virtual path. A
connection-oriented transmission requires three phases:
connection establishment, data transfer, and connection
termination.
Connection Establishment
Data Transfer
Connection Termination
Connection Reset
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. This implies that each party must initialize
communication and get approval from the other party before any data
are transferred.
Three-Way Handshaking
The connection establishment in TCP is called three-way
handshaking. In our example, an application program, called the client,
wants to make a connection with another application program, called the
server, using TCP as the transport-layer protocol.
The process starts with the server. The server program tells its TCP that
it is ready to accept a connection. This request is called a passive open.
Although the server TCP is ready to accept a connection from any
machine in the world, it cannot make the connection itself.
The client program issues a request for an active open. A client that
wishes to connect to an open server tells its TCP to connect to a
particular server. TCP can now start the three-way handshaking
process, as shown in Figure .
Connection establishment using three-way handshaking
A SYN segment cannot carry data, but it consumes one sequence
number.
A SYN + ACK segment cannot carry data, but does consume one
sequence number.
1. The client sends the first segment, a SYN segment, in which
only the SYN flag is set. This segment is for synchronization of
sequence numbers. The client in our example chooses a random
number as the first sequence number and sends this number to
the server. This sequence number is called the initial sequence
number (ISN). Note that this segment does not contain an
acknowledgment number. It does not define the window size
either; a window size definition makes sense only when a
segment includes an acknowledgment. The segment can also
include some options that we discuss later in the chapter. Note
that the SYN segment is a control segment and carries
no data. However, it consumes one sequence number because it
needs to be acknowledged. We can say that the SYN segment
carries one imaginary byte.
The server sends the second segment, a SYN + ACK segment
with two flag bits set as: SYN and ACK. This segment has a dual
purpose. First, it is a SYN segment for communication in the other
direction. The server uses this segment to initialize a sequence
number for numbering the bytes sent from the server to the client.
The server also acknowledges the receipt of the SYN segment
from the client by setting the ACK flag and displaying the next
sequence number it expects to receive from the client. Because
the segment contains an acknowledgment, it also needs to define
the receive window size, rwnd (to be used by the client), as we will
see in the flow control section. Since this segment is playing the
role of a SYN segment, it needs to be acknowledged. It, therefore,
consumes one sequence number.
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. Note that the ACK
segment does not consume any sequence numbers if it does not
carry data, but some implementations allow this third
segment in the connection phase to carry the first chunk of data
from the client. In this case, the segment consumes as many
sequence numbers as the number of data bytes.
Data transfer
Data Transfer
After connection is established, bidirectional data transfer can
take place. The client and server can send data and
acknowledgments in both directions. We will study the
rules of acknowledgment later in the chapter; for the moment, it is
enough to know that data traveling in the same direction as an
acknowledgment are carried on the same segment. The
acknowledgment is piggybacked with the data.
Connection termination using three-way
handshaking
The FIN segment consumes one sequence number if it does not
carry data.
The FIN + ACK segment consumes one sequence number if it
does not carry data.
Half-close
States for TCP
TCP/IP Protocol Suite 33
Options --
The TCP header can have up to 40 bytes of optional information.
Options convey additional information to the destination or align
other options.
End-of-option option
EOP can be used only once.
35
No-operation option
NOP can be used more than once.
36
Maximum-segment-size option
The value of MSS is determined during connection establishment
and does not change during the connection.
Window-scale-factor option
The value of the window scale factor can be determined only during connection
establishment; it does not change during the connection.
window scale factor
New window size =Window size defined in the header * 2
Timestamp option
One application of the timestamp option is the calculation of
round trip time (RTT).
The timestamp option can also be used for PAWS Protection
against wrapped sequence numbers.
SACK - Selective acknoledgment -
SACK Permitted option can only be used during connection establishment
User Datagram
Protocol
Position of UDP in the TCP/IP protocol suite
UDP versus IP
Port numbers
IP addresses versus port numbers
Well-known ports used with UDP
Socket address
User datagram format
UDP packets are called user datagrams and have a fixed-size header of 8
bytes.
UDP checksum calculation is different from the one for IP and ICMP.
Here the checksum includes three sections: a pseudo header, the UDP
header, and the data coming from the application layer.
❑ 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. If the source host is the client (a client sending a request), the
port number, in most cases, is an ephemeral port number requested by the process
and chosen by the UDP software running on the source host. If the source host is
the server (a server sending a response), the port number, in most cases, is a well-
known port number.
❑ Destination port number. This is the port number used by the process
running on the destination host. It is also 16 bits long. If the destination host is the
server (a client sending a request), the port number, in most cases, is a well-known
port number. If the destination host is the client (a server sending a response), the
port number, in most cases, is an ephemeral port number. In this case, the server
copies the ephemeral port number it has received in the request packet.
❑ Length. This is a 16-bit field that defines the total length of the user datagram,
header plus data. The 16 bits can define a total length of 0 to 65,535 bytes.
However, the total length needs to be much less because a UDP user datagram is
stored in an IP datagram with the total length of 65,535 bytes. The length field in a
UDP user datagram is actually not necessary. A user datagram is encapsulated in
an IP datagram. There is a field in the IP datagram that defines the total length.
There is another field in the IP datagram that defines the length of the header. So
if we subtract the value of the second field from the first, we can deduce the length
of the UDP datagram that is encapsulated in an IP datagram.
Pseudoheader for checksum calculation
Encapsulation and decapsulation
Encapsulation
When a process has a message to send through UDP, it passes the message to
UDP along with a pair of socket addresses and the length of data. UDP receives
the data and adds the UDP header. UDP then passes the user datagram to IP
with the socket [Link] adds its own header, using the value 17 in the
protocol field, indicating that the data has come from the UDP protocol. The IP
datagram is then passed to the data link layer. The data link layer receives the
IP datagram, adds its own header (and possibly a trailer), and passes it to the
physical layer. The physical layer encodes the bits into electrical or optical
signals and sends it to the remote machine.
Decapsulation
When the message arrives at the destination host, the physical layer decodes
the signals into bits and passes it to the data link layer. The data link layer uses
the header (and the trailer) to check the data. If there is no error, the header
and trailer are dropped and the datagram is passed to IP. The IP software does
its own checking. If there is no error, the header is dropped and the user
datagram is passed to UDP with the sender and receiver IP addresses. UDP
uses the checksum to check the entire user datagram. If there is no error, the
header is dropped and the application data along with the sender socket
address is passed to the process. The sender socket address is passed to the
process in case it needs to respond to the message received.
Multiplexing and DE multiplexing
Transmission Control Protocol User Datagram Protocol
TCP is a connection-oriented protocol. Connection- UDP is the Datagram oriented protocol. This is because
orientation means that the communicating devices there is no overhead for opening a connection,
should establish a connection before transmitting data maintaining a connection, and terminating a
and should close the connection after transmitting the connection. UDP is efficient for broadcast and multicast
data. type of network transmission.
TCP is reliable as it guarantees the delivery of data to The delivery of data to the destination cannot be
the destination router. guaranteed in UDP.
TCP provides extensive error checking mechanisms. It
UDP has only the basic error checking mechanism
is because it provides flow control and
using checksums.
acknowledgment of data.
Sequencing of data is a feature of Transmission Control
There is no sequencing of data in UDP. If the order is
Protocol (TCP). this means that packets arrive in-order
required, it has to be managed by the application layer.
at the receiver.
TCP is comparatively slower than UDP. UDP is faster, simpler, and more efficient than TCP.
Retransmission of lost packets is possible in TCP, but There is no retransmission of lost packets in the User
not in UDP. Datagram Protocol (UDP).
TCP has a (20-60) bytes variable length header. UDP has an 8 bytes fixed-length header.
TCP is heavy-weight. UDP is lightweight.
TCP doesn’t support Multicasting and Broadcasting. UDP supports Multicasting and Broadcasting.
UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and
TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet.
VoIP.