You are on page 1of 8

Unit 10: Transport Layer

The transport layer is the fourth layer from the bottom in the OSI reference model. It is
responsible for message delivery from process running in source computer to the process running
in the destination computer. Transport layer does not perform any function in the intermediate
nodes. It is active only in the end systems. The various functions of transport layer are:

Establishing, Maintaining & Releasing Connection


Addressing
Data Transfer
Flow Control
Error Control
Congestion Control

Transport Layer Services

Transport layer protocols can provide two types of services:


1. Connection Oriented Service
2. Connectionless Service

Connection Oriented Service:


In connection oriented service, a connection is first established between sender and the
receiver.
Then, transfer of user data takes place.
At the end, connection is released.
The connection oriented service is generally reliable.
Transport layer protocols that provide connection oriented service are TCP and SCTP
(Stream Control Transmission Protocol).

Connectionless Service:
In the service, the packets are sent from sender to receiver without the establishment of
connection.
In such service, packets are not numbered.
The packets may be lost, corrupted, delayed or disordered.
Connectionless service is unreliable.
Transport layer protocol that provides this service is UDP
.
Addressing:
In order to deliver data from one process to another, address is required.
In order to deliver data from one node to another, MAC address is required. Such an
address is implemented at Data Link Layer and is called Physical Addressing.
In order to deliver data from one network to another, IP address is required. Such an
address is implemented at Network Layer and is called Logical Addressing.
Similarly, in order to deliver data from a process running on source to process running on
destination, transport layer defines the Service Point Address or Port Numbers.
.
Port Numbers:
Each communicating process is assigned a specific port number.
In order to select among multiple processes running on a destination host, a port number
is required.
The port numbers are 16 bit integers between 0 and 65,535.
Port numbers are assigned by Internet Assigned Number Authority (IANA).
IANA has divided the port numbers in three categories:
1. Well Known Ports: The ports ranging from 0 to 1023. For e.g.: HTTP: 80,
SMTP: 25, FTP: 21.
2. Registered Ports: The ports ranging from 1024 to 49,151. These are not
controlled by IANA.
3. Dynamic Ports: The ports ranging from 49,152 to 65,535. These can be used by
any process.

Socket Address:
Socket address is a combination of IP address and port number.
In order to provide communication between two different processes on different
networks, both IP address and port number, i.e. socket address is required

Transport layer defines two different protocols:


1. Transmission Control Protocol (TCP)
2. User Datagram Protocol (UDP)

Transmission Control Protocol (TCP)


TCP is the main protocol of the transport layer in packet switched networks. TCP provides a
connection-oriented, full-duplex, reliable, streamed delivery service using IP to transport
messages between two processes.
Reliability is ensured by:
Connection-oriented service
Flow control using sliding window protocol
Error detection using checksum
Error control using go-back-N ARQ technique
Congestion avoidance algorithms; multiplicative decrease and slow-start

The basic features or Characteristics of TCP are:


It provides efficient method for numbering different bytes of data.
It provides stream data transfer.
It offers reliability.
It provides efficient flow control.
It provides full duplex operation.
It provides multiplexing.
It provides connection oriented service.

TCP Segment
TCP segment is the unit of data transferred between two processes. Each TCP segment consists
of two parts:
1. Header Part
2. Data Part

Figure: The TCP datagram format

The TCP datagram format is shown in Figure. A brief explanation of the functions of different
fields is given below:
Source port (16 bits): It defines the port number of the application program in the host of
the sender.
Destination port (16 bits): It defines the port number of the application program in the
host of the receiver;
Sequence number (32 bits): It conveys the receiving host which octet in this sequence
comprises the first byte in the segment
Acknowledgement number (32 bits): This specifies the sequence number of the next octet
that receiver expects to receive.
HLEN (4 bits): This field specifies the number of 32-bit words present in the TCP header.
Control flag bits (6 bits):
o URG: Urgent pointer
o ACK: Indicates whether acknowledge field is valid
o PSH: Push the data without buffering
o RST: Resent the connection
o SYN: Synchronize sequence numbers during connection establishment
o FIN: Terminate the connection
Window (16 bits): Specifies the size of window
Checksum (16 bits): Checksum used for error detection.
User pointer (16 bits): Used only when URG flag is valid
Options: Optional 40 bytes of information

Operation of TCP
TCP is a connection oriented protocol. It establishes a virtual connection between the running
application programs (process) at the two communication end points. TCP uses port number for
this purpose. Each port number is relevant to an application. The stream of data is sent from the
process to the transport layer. TCP establishes a connection between the transport layers of the
transmitter and receiver stations. It then divides the stream of data into units called segments.
Segments are numbered and transmitted one by one. The TCP protocol at the receiver side
checks the arriving segments for error, loss, and duplication. It orders the segments, makes a
stream, and transfers the stream to the receiver side process. TCP provides stream delivery
service. Both the sender and the receiver processes deal with the stream of bytes and are not
aware of stream segmentation in the lower layers. After all segments are transmitted, TCP at the
transmitter side closes the connection.

Connection-oriented service
TCP performs data communication in full-duplex mode, that is both the sender and receiver
processes can send segments simultaneously. For connection establishment in full-duplex mode,
a four-way protocol can be used. However, the second and third steps can be combined to form a
three-way handshaking protocol with the following three steps as shown in figure.
Step 1: The client sends SYN segment, which includes, source and destination port
numbers, and an initialization sequence number (ISN), which is essentially the byte
number to be sent from the client to the server.
Step 2: The server sends a segment, which is a two-in-one segment. It acknowledges the
receipt of the previous segment and it also acts as initialization segment for the server.
Step3: The sends an ACK segment, which acknowledges the receipt of the second
segment.

Figure: Protocol for connection establishment


Similarly for connection termination, a four-way handshaking protocol is necessary for
termination of connection in both directions as shown in Figure. The four steps are as follows:
Step 1: The client sends a FIN segment to the server.
Step 2: The server sends an ACK segment indicating the receipt of the FIN segment and
the segment also acts as initialization segment for the server.
Step3: The server can still continue to send data and when the data transfer is complete it
sends a FIN segment to the client.
Step4: The client sends an ACK segment, which acknowledges the receipt of the FIN
segment sent by the server. Both the connections are terminated after this four-way
handshake protocol.

Figure: Protocol for connection termination

Application of TCP

Bandwidth Management
Error Control &and Flow Control
Multiplexing
Congestion Control
Timer Management
Crash Recovery
User Datagram protocol (UDP)

User Datagram Protocol (UDP) is a connectionless, unreliable transport protocol.


Like TCP, UDP also provides process to process communication.
Unlike TCP, it does not provide flow control and error control mechanisms.
It is connectionless; therefore, it transfers data without establishing a connection.

The various features or characteristics of UDP are:


It provides connectionless transport service.
It is unreliable.
It does not provide flow control and error control.
It is less complex and is simple than TCP, and easy to implement.
User datagram (packets) are not numbered

UDP Datagram
The UDP datagram format is shown in Figure. A brief description of different fields of the
datagram is given below:

Source port (16 bits): It defines the port number of the application program in the host of
the sender
Destination port (16 bits): It defines the port number of the application program in the
host of the receiver
Length: It provides a count of octets in the UDP datagram, minimum length = 8
Checksum: It is optional, 0 in case it is not in use

Operation of UDP

UDP serves the application layer and network layer like TCP, but with more ease. UDP uses port
number for application to application communication, but it does not establish a connection as
TCP does, so it is termed as connectionless. UDP sender transmits the data unit of the upper
layer process and does not care if the transmission is reliable. In other words, if the data unit gets
lost due to the congestion or duplicated in the path, UDP does not recognize it. UDP does not
deploy ACK, flow and congestion control. Thats why UDP is unreliable. There is minimal error
detection, and erroneous packets will be simply discarded. The beauty of UDP is its simplicity.
The only overhead that UDP adds to the packet is to establish process to process communication,
rather than a host to host communication of IP layer. Therefore, UDP is very suitable for small
message communications or applications that do not need strong reliability, such as client/server
request/reply or video conferencing. It can also be used in applications that have internal error
and flow control, such as Trivial File Transfer Protocol (TFTP).

UDP application

Here are few applications where UDP is used to transmit data:

Domain Name Services


Simple Network Management Protocol
Trivial File Transfer Protocol
Routing Information Protocol

Relationship between TCP & IP


TCP is the main protocol of the transport layer in packet switched networks. TCP and IP
protocols provide the basic structure of the Internet. These two protocols are complementary in
the sense that IP facilitates packet forwarding irrespective of reliable packet delivery, whereas
TCP is responsible for reliable packet delivery between applications. In the network layer, the
order of packets during transmission may change, because, different packets may reach a
destination on different routes. Moreover, some packets may be dropped due to the congestion
and/or long delay in a node on the path. TCP protocol compensates for some of these
deficiencies of the IP protocol, and controls the congestion in a network.

Overview of BSD Socket API

BSD Sockets generally relies upon client/server architecture. For TCP communications, one host
listens for incoming connection requests. When a request arrives, the server host will accept it, at
which point data can be transferred between the hosts. UDP is also allowed to establish a
connection, though it is not required. Data can simply be sent to or received from a host.

The Sockets API makes use of two mechanisms to deliver data to the application level: ports and
sockets. Ports and sockets are one of the most misunderstood concepts in sockets programming.

All TCP/IP stacks have 65,536 ports for both TCP and UDP. There is a full compliment of ports
for UDP (numbered 0-65535) and another full compliment, with the same numbering scheme,
for TCP. The two sets do not overlap. Thus, communication over both TCP and UDP can take
place on port 15 (for example) at the same time.

A port is not a physical interface - it is a concept that simplifies the concept of Internet
communications for humans. Upon receiving a packet, the protocol stack directs it to the specific
port. If there is no application listening on that port, the packet is discarded and an error may be
returned to the sender. However, applications can create sockets, which allow them to attach to a
port. Once an application has created a socket and bound it to a port, data destined to that port
will be delivered to the application. This is why the term socket is used - it is the connection
mechanism between the outside world (the ports) and the application. A common
misunderstanding is that sockets-based systems can only communicate with other sockets-based
systems. This is not true. TCP/IP or UDP/IP communications are handled at the port level - the
underlying protocols do not care what mechanisms exist above the port. Any Internet host can
communicate with any other, be it Berkeley Sockets, WinSock, or anything else. "Sockets" is
just an API that allows the programmer to access Internet functionality - it does not modify the
manner in which communications occur. Let us use the example of an office building to illustrate
how sockets and ports relate to each other. The building itself is analogous to an Internet host.
Each office represents a port, the receptionist is a socket, and the business itself is an application.
Suppose you are a visitor to this building, looking for a particular business. You wander in, and
get directed to the appropriate office. You enter the office, and speak with the receptionist, who
then relays your message to the business itself. If there is nobody in the office, you leave. To
rephrase the above in sockets terminology: A packet is transmitted to a host. It eventually gets to
the correct port, at which point the socket conveys the packet's data to the application. If there is
no socket at the destination port, the packet is discarded.