Transport Layer Responsibilities

The fourth layer of OSI model is called Transport Layer. This layer is responsible for end-to-end connectivity, Process to process delivery, error control, flow control etc. It is also called as an end-to-end layer because it provides a point-to-point connection rather than hop-to-hop, between the source host and destination host to transport the services reliably. The unit of data encapsulation in Transport Layer is a segment.
The protocols used by Transport Layer to improve its functionalities are TCP(Transmission Control Protocol), UDP( User Datagram Protocol), DCCP(Datagram Congestion Control Protocol), SCTP (Stream Control Transmission Protocol) etc.
Different responsibilities of a Transport Layer are following:

Process to process delivery

The data link layer is responsible for delivery of frames between two neighboring nodes over a link. Data Link Layer requires the MAC address (48 bits address contained inside the Network Interface Card of every host machine) of source-destination hosts to correctly deliver a frame. This is called node-to-node delivery. The network layer is responsible for delivery of datagrams between two hosts. The Network layer requires the IP address for right routing of packets, in a similar way and this is called host-to-host delivery.

Communication on the Internet is not defined as the exchange of data between two nodes or between two hosts. Real communication takes place between two processes. So that we need process-to-process delivery.
The transport layer is responsible for process-to-process delivery. The delivery of a packet, part of a message, from one process to another.

But, at any moment, several processes may be running on the source host and several on the destination host. To complete the delivery, we need a mechanism to deliver data from one of these processes running on the source host to the corresponding process running on the destination host.
The port number is the mechanism which made it possible to deliver the segments of data correctly amongst the multiple processes running on a particular host. A port number is a 16-bit address used to identify any client-server program uniquely.The figure illustrates the data delivery over a network. 

flow control 

End-to-end Connection between hosts

End-to-end connection happening between two applications (maybe you and your friend using a messenger like skype or any other). It doesn’t care what’s in the middle, it just considers that the two ends are taking with one another. It generally is a Layer 4 responsibility.
For end-to-end connection layer 4 generally uses TCP and UDP protocols. TCP is a secure and connection- orientated protocol which uses a handshake to establish a connection between two end- hosts. TCP ensures reliable delivery of data and is used in many applications.
On the other hand, UDP is a stateless and unreliable protocol which ensures best-effort delivery. It is suitable for the applications which have little concern with flow or error control and requires to send a bulk of data like video conferencing. It is an often used in multicasting protocols.

Multiplexing and Demultiplexing

Gathering data from several application processes of the sender, enveloping that data with a header and sending them as a whole to the intended receiver is called as multiplexing. Multiplexing allows the real-time use of different applications over a network which is running on a host. The transport layer provides this mechanism which enables us to send packet streams from various applications simultaneously over a network.
Transport layer accepts these data packets from different processes differentiated by their port numbers and passes them to network layer after adding proper headers. in the same way; Delivering received segments at the receiver side to the correct app layer processes is called as demultiplexing. Demultiplexing is required at the receiver side to obtain the data coming from various processes. Transport receives the segments of data from network layer and delivers it to the appropriate process running on the receiver’s machine.

Congestion Control

Congestion occurring in network layer when the message traffic is so heavy and too many that it slows down network response time. Due to heavy and many sources over a network attempt to send data and the router buffers start overflowing due to which loss of packets occurs. As a result retransmission of packets from the sources increases the congestion further. In this situation, Transport layer provides Congestion Control in different ways. It uses open-loop congestion control to prevent the congestion and closed-loop congestion control to remove the congestion in a network once it occurred. TCP provides AIMD- additive increase multiplicative decrease, leaky bucket technique for congestion control.

Data integrity and Error correction

The transport layer is responsible for checking errors in the messages coming from application layer by using error detection codes; computing checksums; it checks whether the received data is free of errors and uses the ACK and NACK services to inform; the sender if the data arrives or not and checks for the integrity of data.

Flow control

The transport layer provides a flow control mechanism between the source and destination. The flow control ensures the rate at which a sender is transmitting is in proportion to the receiver’s receiving capabilities.
Flow control is utilized in data communications to manage the flow of data/packets among two different nodes; especially in cases where the sending device can send data much faster than the receiver can take in.

TCP prevents the data loss due to a fast sender and slow receiver by imposing flow control techniques. It uses the method of sliding window protocol which is accomplished; by the receiver by sending a window back to the sender informing the size of data it can receive.