Unit 3
Unit 3
3.0 INTRODUCTION
The internet work environment consists of hosts connected to networks that are in
turn interconnected via gateways. Such networks are based on packet switching
technology. The active elements that produce and consume messages are the
processes. Therefore, such communication can be viewed as an inter-process
communication.
3.1 OBJECTIVES
Our objective is to introduce you to the basic concepts of Transport layer Protocols.
On successful completion of this unit, you should be able to:
• have a reasonable understanding of the Transmission Control Protocol
architecture;
• understand the role and use of port numbers;
• describe the operation of Transmission Control Protocol and its header format;
• describe the role and meaning of User Datagram Protocol (UDP); and
• describe the role and meaning of Internet Control Message Protocol (ICMP).
Ports
When a process starts up, it registers a port number with the protocol stack. The port
numbers are specified by a 16-bit number i.e., the overall available set of port
numbers are 216, ranging from 0 to 65535. The various categories of ports are as
under:
61
TCP/IP Protocols 1) Well Known Ports: The Port numbers in the range 0-1023 are called ‘Well
Known Ports’. These port numbers are assigned to the server side of an
application and are already reserved for specific applications by IANA (Internet
Assigned Number Authority). Some of these port numbers and their associated
application are given in Table 1.
Port
Protocol Application Port No Protocol Application
Nos.
23 TCP TELNET 110 TCP POP3
25 TCP SMTP 161 UDP SNMP
37 UDP TIME 179 TCP BGP
43 TCP WHOIS 443 TCP HTTPS
53 TCP/UDP DNS 68 UDP BOOTPC
67 UDP BOOTPS 69 UDP TFTP
2) Registered Ports: Port numbers in the range 1024-49151 are called Registered
Ports. These port numbers have been publicly defined as a convenient service for
the Internet community to help them avoid vendor conflicts.
3) Dynamic and/or Private Ports: The remaining port numbers in the range
49152-65535, are called Dynamic and/or Private Ports and can be used freely by
any client or server application.
Remember, only one process per protocol can listen on a given port i.e., two different
processes, one using UDP and another TCP can both listen on port number XXX.
However, two processes using the same transport protocol cannot listen on the same
port number.
In order to establish a connection between two end machines i.e., providing the
process-to-process delivery of messages, we need an identifier called socket. It
contains the combination of IP address of the machine along with the port number of
the process running on it. For example, suppose IP address of the machine is
171.10.20.1 and a process running on it is assigned a port number of 4534, then the
socket contains (171.10.20.1, 4544). Thus, a socket uniquely identifies the process
from the set of processes running on a machine.
In the client server model, a pair of sockets is required i.e., one for the client (client
IP address, client port number) and another for the server (server IP address, server
port number).
62
In order to deliver some information to a specific destination, we need an address for Transport Layer Protocols
correspondence. Similarly, at the data link layer, medium access control addresses
(MAC) are employed for addressing. Correspondingly, at the network layer, Internet
Protocol IP addresses are required. In the same way, the transport layer uses the port
numbers for addressing between two processes. These port numbers are just a way of
labelling the packets. When the transport layer receives a message from an
application, first of all, it registers a temporary port number for the application
process and subsequently assigns it. Thereafter, it sends the data to the designated
destination application program that would be running on another port number. In
Figure 1, the client server model has been illustrated, wherein, whenever a client
process starts up, a port number is assigned, say 3000 and the server process is
assigned port number of 100. These assigned port numbers are put on each packet
transmitted between these processes.
It may be noted that IP addresses and port numbers play different roles in
communication networks. The IP address simply identifies the destination machine
from the network, while the port number identifies the particular process running on
that destination machine.
There are two types of protocols at the transport layer as shown in Figure.2.
1) Transmission Control Protocol (TCP)
2) User Datagram Protocol (UDP).
1) Stream data transfer: With stream data transfer, TCP delivers an unstructured
stream of bytes identified by sequence numbers. This service benefits
applications because they do not have to chop data into blocks before handing it
off to TCP. Instead, TCP groups bytes into segments and passes them to IP for
delivery.
Process 1 Process 2
… Port m … … Port n …
IP IP
Unreliable IP
datagram
Host A Host B
64
Transport Layer Protocols
Source Port address Destination Port address
16 bits 16 bits
Sequence Number
32 bits
Acknowledgement Number
32 bits
1) Source Port Number: This is a 16-bit number which defines the source port
number for a particular application program that is sending the TCP segments.
5) Header Length: The HLEN field consists of 4 bits. It indicates the length of the
TCP header. The length of the TCP header can be between 20 bytes to 60 bytes
i.e., HLEN field can have binary values ranging from 0101-1111 (5 to 15, 32 bit
words) (5 x 4 =20, 15 x 4 =60).
6) Reserved: This 6 bit field is reserved for future use. The value set in this field
must be zero.
65
TCP/IP Protocols 7) Control Flags: This field contains six different control flags that can control
certain aspects of the TCP connection such as connection establishment,
connection termination and flow control. The flags include:
a) Urgent Pointer URG: When set, the ACK indicates that the current segment
contains urgent (or high-priority) data and that the Urgent Pointer field value
is valid.
b) Acknowledgement (ACK): When set, indicates that the value contained in
the Acknowledgement Number field is valid. This bit is usually set, except
during the first message during connection establishment.
c) Push (PSH): PSH is used when the transmitting application wants to force
TCP to immediately transmit the data that is currently buffered to the
application without waiting for the buffer to fill. It is useful for transmitting
small units of data.
d) Reset (RST): When set, RST immediately terminates the end-to-end TCP
connection.
e) Synchronize (SYN): SYN is set in the initial segments used to establish a
connection, indicating that the segments carry the initial sequence number.
f) Finish (FIN): FIN is set to request normal termination of the TCP connection
in the direction this segment is travelling. Complete closure of the connection
requires one FIN segment in each direction.
8) Window Size: The window size 16 bits field is used for flow control. It contains
in bytes, the size of the window that the receiver has to maintain i.e., the value of
the receive window size. It is basically the number of transmitted bytes that the
sender of this segment is willing to accept from the receiver.
9) Checksum: This is a 16-bit field that provides bit error detection for the segment
(including the header and data).
10) Urgent Pointer: Urgent data is information that has been marked as high-priority
by a higher layer application. The data sent under high-priority usually bypasses
the normal TCP buffering and is placed in a segment between the header and
normal data. When the URG flag of control flag is set, then the urgent pointer 16-
bit number indicates the position of the first octet of non-priority data in the
segment.
11) Options: The option field contains 40 bytes of optional information about
connection establishment. The maximum segment size (MSS) is the most
commonly used option and if absent, defaults to an MSS of 536. Another option
is Selective Acknowledgement (SACK), which allows out-of-sequence segments
to be accepted by a receiver. The further discussion about options is beyond the
scope of this book.
Characteristics of TCP
The basic characteristics of TCP are as follows:
1) It employs a connection-oriented service for communication.
2) It is a reliable source of communication i.e. guarantees delivery of messages.
3) It splits the messages into segments and keeps track of the order (sequence) of
segments.
4) It employs the checksums for detecting any errors in data as well as the TCP
header.
66
Transport Layer Protocols
3.3.2 TCP Connection Establishment and Termination
A connection is a requirement of a reliable data delivery service. It is set up before
the actual data exchange takes place. The connection is used to acknowledge the
receipt of packets and retransmit those that are lost.
Host A B
Segment X: SYN
Send Segment X Sequence Number: 1000
With SYN flag Ack Number: Nil Receive SYN
set segment
67
TCP/IP Protocols
3.3.4 TCP Connection Termination
There is a saying that, “all good things must come to an end” and so it is with TCP
connections. After the exchange of data between the source and destination nodes,
either of them can close the connection. Thus, after the user has sent all its data and
wishes to close the TCP connection, four segments are required to completely close a
connection gracefully from both directions. The connection termination phases are
discussed below:
1) The initiator (source) sends a segment with the FIN flag set. For example, in
Figure 6, Host A sends a segment named X, with FIN flag set, initial sequence
number is 2000 and acknowledgement number is Nil.
2) Upon receipt (destination) of the segment, the recipient issues an ACK segment,
in order to confirm the receipt of the initiator. The acknowledgement number is 1
plus the sequence number received from the initiator i.e. from the FIN segment.
For example, in Figure 6, Host B, after receiving the segment, sends a segment
named Y, ACK flag set, initial sequence number assigned to the segment is 4000
and ack no. is 2001(sequence number of segment sent by host A plus 1).
3) If the recipient (destination) still has some data to send to the initiator (source), it
sends the data. Otherwise, the recipient (destination) sends a request for
termination of connection from its side by sending a segment with FIN flag set.
Host A B
For example, in Figure 6, in case Host B too wishes to disconnect, it sends another
segment named Z, with FIN flag set, sequence number assigned to the segment is
4001(sequence number of the last segment sent by B plus 1) and acknowledgement
number is 2001(sequence number of segment sent by host A plus 1).
4) On receipt of this segment, the initiator sends an ACK segment, to confirm the
FIN segment from the recipient (destination). For example, in Figure 6, Host A,
after receiving the segment, sends a segment named W, with ACK flag set,
sequence number assigned to the segment is 2001(the first segment sent by A had
a sequence number of 1000) and acknowledgement number is 4002(the last
sequence number of segment sent by host B plus 1).
Another method of closing the connection can be done by requesting the resetting of
connection i.e., a host machine can send a segment with the RST bit set which will
convey the other machine to immediately terminate the connection. Apart from
68
connection establishment and connection termination, flow control, error control and Transport Layer Protocols
congestion control are few other responsibilities being performed by TCP.
In order to speed up the communication, the source can send the complete message at
a given instance without waiting for acknowledgement to arrive from the receiver.
However, such a situation can cause adverse effects at the receiver side. In such
situations, TCP sends data in accordance with sliding window protocol – a Flow
Control Mechanism.
112 111 110 109 108 107 106 105 104 103
Still empty Stored in the buffer but not sent sent but still unacknowledged sent and acknowledged
,,,,,,,,,,,,,,,,,,,,,,,,,
Initially a window size is negotiated between the end terminals especially from the
receiving side, while establishing a connection. Since TCP provides a byte-stream
connection, sequence numbers are assigned to each byte in the stream. TCP divides
this contiguous byte stream into TCP segments to transmit them. Therefore, the
window principle is used at the byte level, that is, the segments sent and
acknowledgements received will carry byte-sequence numbers and the window size is
expressed as a number of bytes.
There are mainly two windows that are maintained i.e., one by the sender and another
one by the receiver. The receiver window stores information about the various bytes
received by its buffer but are still unconsumed and the other empty locations of the
buffer.
With the help of these windows, a maximum limit on the number of bytes that can be
sent by the sender to the receiver is decided, depending upon the total number of
bytes that can be stored in the receiver’s buffer at that particular instance. Thus, the
mechanism of sliding window helps in controlling the flow of packets.
Out-of-Order segment
As IP is a connectionless service, IP datagrams might arrive out of order. The TCP in
turn assures that the receiver does not acknowledge the received out of order segment
until and unless it receives all those expected segments which precede it as shown in
Figure 8.
69
TCP/IP Protocols
Host A B
Segment Y:
Sequence Number: 1900 Receives an out of order segment
Number of bytes sent are: 100 Does not acknowledge
Duplicate Segment
If the receiver receives a duplicate segment, it simply discards that segment, as a TCP
segment with the same sequence number has already arrived.
Corrupted Segments
Whenever a segment gets corrupted, it is simply discarded by the destination and has
to be retransmitted by the source as shown in Figure 9.
Host A B
Segment X
Sequence Number: 2000
Number of bytes sent are: 400
Segment Z:
Sequence Number: 4001
Ack Number: 2401
Segment Y:
Sequence Number: 2401
Number of bytes sent are: 100
Segment Y: Lost
Sequence Number: 2401
Number of bytes sent are: 100
Retransmitted
Lost Acknowledgements
An acknowledgement for a segment can be lost in between. However, in TCP, the
functioning of acknowledgement is as follows: An acknowledgement is a
confirmation that everything up to the bytes specified by the acknowledgement
70
number in TCP header has been received. Thus, a latest acknowledgement overrides Transport Layer Protocols
the previous reached /lost acknowledgements as shown in Figure 10.
Host A B
Segment X
Sequence Number: 2000
Number of bytes sent are: 400
Segment Y:
Sequence Number: 2401
Number of bytes sent are: 100
Segment Z: ACK
Sequence Number: 4001
Ack Number: 2401
Lost
Segment Z: ACK
Sequence Number: 4001
Ack Number: 2501
UDP Header
The UDP packets are termed as User Datagrams and the header part of the user
datagram has a fixed size of 8 bytes as shown in Figure 11.
1) Source Port Number: A 16-bit number which defines the source port number
for a particular application program that is sending the UDP datagrams.
2) Destination Port Number: A 16-bit number that defines the destination port
number for a particular application program that is receiving the UDP datagrams.
72
3) Length: The 16-bit field denotes the size of UDP header combined with payload Transport Layer Protocols
data. It can range between 0 to 65,535 bytes.
4) Checksum: This is 16-bit field that provides detection of errors over the entire
user datagram.
Characteristics of UDP
The basic characteristics of UDP are as follows:
1. UDP is a connectionless service.
2. It adds no non-reliable flow control to IP.
3. It serves as a multiplex/demultiplexer for sending and receiving datagrams.
4. The communication ends (end terminals) need not be synchronized.
5. There is no provision for acknowledgement of datagrams.
Applications of UDP
The standard applications using UDP include:
• Trivial File Transfer Protocol (TFTP)
• Domain Name System (DNS) name server
• Remote Procedure Call (RPC) used by the Network File System (NFS)
• Simple Network Management Protocol (SNMP).
3) Which of the following field (s) is/are required for ordering the packets?
a) Sequence Number
b) Acknowledgement Number
c) Checksum
d) All of the above
…………………………………………………………………………………...
3.5 SUMMARY
This unit provides a complete overview of TCP. We have learnt that the data
link layer provides node-to-node (intermediate), network layer provides host-to-host
and transport layer provides process-to-process communication. The transport layer
uses TCP and UDP protocols. TCP is a reliable, connection-oriented service, while
UDP is an unreliable and connectionless service. As real communication takes place
between two application programs, each process should be assigned a unique port
number for identifying the various processes running on the same machine. There are
three types of port numbers: well known, registered and dynamic ports. The
combination of IP address and port number is called a socket address. The size of
UDP header is 8 bytes and TCP header requires 20-60 bytes. The TCP employs error
control, flow control and congestion control mechanisms. A three-way handshake is
required for TCP connection establishment. The TCP connection termination requires
four steps. The next unit of this course covers the application layer protocols and their
role in TCP/IP.
74
Transport Layer Protocols
75