Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Introduction to Transport Layer

Before learning about the difference between transport layer and network layer,
let us first learn about computer networks and the OSI model in brief.

A computer network is a set of devices (computers) connected to exchange


information and resources such as files etc. The main goals of computer networks
are:

 Resource sharing (such as software sharing, program sharing, etc.)


 High Reliability (if one network link fails another can transfer the data).
 Cost Reduction (we can buy only required services from cloud services
like GCloud, AWS, Azure, etc.).
 Communication (acts as a communication medium between sender and
receiver).
 Load Sharing (a program may run on multiple machines).

The OSI model stands for Open Systems Interconnection model. The OSI model is
also known as the ISO-OSI model as it was developed by ISO (International
Organization for Standardization). It is a conceptual reference model that describes
the entire flow of information from one computer to the other computer. The OSI
model is a 7-layered model so it is also known as a 7-layered architecture model.
The basic idea behind the layered architecture is to divide the design into smaller
pieces. To reduce the design complexity, most networks are organized in a series
of layers. The network layer and transport layer are two of the seven layers of the
OSI model.

Now, let us discuss the transport layer briefly so that we can get a better
understanding of the topic i.e. difference between transport layer and network
layer.

The transport layer is the fourth layer of the OSI model which is responsible for
the process to process delivery of data. The main aim of the transport layer is to
maintain the order so that the data must be received in the same sequence as it was
sent by the sender. The transport layer provides two types of services namely -
connection-oriented and connection-less.

The functions provided by the transport layer are as follows:

 The transport layer maintains the order of data.


 It receives the data from the upper layer and converts it into smaller parts
known as segments.
 One of the major tasks of the transport layer is to add the port addressing
(addition of a port number to the header of the data). The port number is
added so that the data can be sent to the respective process only.
 The transport layer on the receiver's end reassembles the segments to form
the actual data.
 The transport layer also deals with flow control and error control.

Refer to the image below to see the basic transmission of data and working of the
transport layer.

The various protocols used in this layer are:

 TCP (Transmission Control Protocol),


 UDP (User Datagram Protocol), etc.

The various devices used in this layer are:

 Segments,
 Load Balancers, etc.

Introduction to Network Layer

The network layer is the third layer of the OSI model which provides
communication between hosts of different networks. The network layer divides the
data received from the transport layer in the form of packets. The network layer
provides two ways of communication namely - connection-oriented and
connection-less.

Note:

 In connection-oriented communication, a communication session is


established before any useful data can be transferred.
 In connection-less communication, the data can be transferred without
establishing any connection.

The functions provided by the network layer are as follows:

 Logical Addressing: The network layer adds the logical address i.e. IP
address (Internet Protocol address) if the packet crosses the network
boundary. It helps in the proper identification of devices on the network.
Hence, the network layer adds the source and destination address to the
header of the packet.
 Routing: Routing simply means determining the best (optimal) path out of
multiple paths from the source to the destination. So the network layer must
choose the best routing path for the data to travel.
 If many devices are connected on the same router then there is a change of
packet drop due as a router may not be able to handle all the requests. So,
the network layer controls the congestion on the network as well.

Refer to the image below to see the basic transmission of data and the working of
the network layer.

The various protocols used in this layer are:


 IPv4 (Internet Protocol version 4),
 IPv6 (Internet Protocol version 6),
 ICMP (Internet Control Message Protocol) etc.

The various devices used in this layer are:

 Routers,
 Brouters, etc.

Note: The network layer does not guarantee the delivery of packets to the
destination. There is no reliability guarantee as well.

Relation between Transport and Network Layer

Before learning the difference between transport layer and network layer, let us
understand how both these layers are interrelated.

As we know the layers of the OSI model are interrelated and the data is
transferred from one form to the other among the seven layers. The transport layer
is located just above the network layer. The network being the third layer takes the
data from the transport layer (i.e. fourth layer) and adds the network layer header
(as discussed above) to it. After adding the network layer header, the data gets
forwarded to the data link layer.

Note:- The transport layer, as well as the network layer, provides two types of
services namely - connection-oriented and connection-less.

Difference between Transport Layer and Network Layer

After discussing the transport layer, network layer, and their relation. Let us now
discuss some of the differences between transport layer and network layer.

Transport Layer Network Layer

The transport layer is the fourth layer of the The network layer is the third layer of
OSI model. the OSI model.
The network mainly deals with logical
The transport layer mainly deals with logical
communication between the hosts
communication between the processes
present on the same or different
running on different hosts.
network.
The network layer provides
The transport layer focuses on the process to
communication between hosts of
process the delivery of data.
different networks.
The transport layer receives the data from the The network layer divides the data
upper layer and converts it into smaller parts received from the transport layer in the
known as segments. form of packets.
The network layer adds the logical
The transport layer performs the port
address i.e. IP address (Internet
addressing i.e. the addition of a port number
Protocol address) if the packet crosses
to the header of the data.
the network boundary.
The network layer does not focus on
The transport layer maintains the order of
maintaining the order of the data
data.
packets
The transport layer deals with the process-to-
The network layer deals with host-to-
process communication or port-to-port
host communication.
communication.
The various protocols used in the transport The various protocols used in the
layer are TCP (Transmission Control network layer are IPv4, IPv6,
Protocol), UDP (User Datagram Protocol), ICMP (Internet Control Message
etc. Protocol), etc.
The various devices used in the
The various devices used in the transport are
network layer are Routers, Brouters,
Segments, Load Balancers, etc.
etc.
Overview of the Transport Layer in the Internet

One of these protocols is UDP(User Datagram Protocol), which provides an


unreliable, connections service to invoking application. The second of these
products is TCP(Tansmission Control Protocol), Which provides raliable,
Connection-orient service to the invoking application. When designing a network
application, the application developer must specify one of these two transport
protocols. As the application developer selects between UDP and TCP when
creating sockets.

To simplify terminology, when in an internet context, we refer to the transport-


layer paket as a segment. We mention, however, that the internet literature(for
exxample RFC’s) also refers to the transport layer packet for TCP as a segment
but often refers to packet for UDP as a datagram. But this same internet literature
also uses the term datagram for the network layer packet. For an intorductory
concepts on computer networking such as this, we believe that it is less confusing
to refer to both TCP and UDP packets as segments, and reserve the term datagram
for the network-layer packet.
Overview of the Transport Layer in the Internet
TCP on other hands, offers several additional services to the application. First and
foremost, it provides reliable data transfer. Using flow control, sequence
numbers, acknowledgements, and timers (techniques we’ll explore in detail in this
chapter), TCP ensures that data is deliver from sending process to receiving
process; correctly and in order. TCP thus coverts IP’s unreliable service between
and systems into reliable data transport service between processes. It also provides
terms into a reliable data transport service between processes. TCP also
provides consgeston control.

Multiplexing and Demultiplexing –


let’s now summarize the service models provided by UDP and TCP. The most
findamental responsiblity of UDP and TCP is to extend IP’s delivery services
between two end systems to a delivery service between two processes runnig on
the end systems. Extending host-to-client delivery to process-to-process delivery is
called tansport-layer multiplexing and demultiplexing. UDP and TCP also
provide integrity checking by including error-detection fields in their segments
header.

Multiplexing –
Gathering data from multiple application processes of the sender, enveloping that
data with a header, and sending them as a whole to the intended receiver is called
multiplexing.
Demultiplexing –
Delivering received segments at the receiver side to the correct app layer
processes is called demultiplexing.
Figure – Abstract view of multiplexing and demultiplexing
Multiplexing and demultiplexing are the services facilitated by the transport layer
of the OSI model.

Figure – Transport layer- junction for multiplexing and demultiplexing


There are two types of multiplexing and Demultiplexing :

1. Connectionless Multiplexing and Demultiplexing


2. Connection-Oriented Multiplexing and Demultiplexing
How Multiplexing and Demultiplexing is done –
For sending data from an application on the sender side to an application at the
destination side, the sender must know the IP address of the destination and port
number of the application (at the destination side) to which he wants to transfer
the data. Block diagram is shown below :
Figure – Transfer of packet between applications of sender and receiver
Let us consider two messaging apps that are widely used nowadays viz. Hike and
WhatsApp. Suppose A is the sender and B is the receiver. Both sender and
receiver have these applications installed in their system (say smartphone).
Suppose A wants to send messages to B in WhatsApp and hike both. In order to
do so, A must mention the IP address of B and destination port number of the
WhatsApp while sending the message through the WhatsApp application.
Similarly, for the latter case, A must mention the IP address of B and the
destination port number of the hike while sending the message.

Now the messages from both the apps will be wrapped up along with appropriate
headers(viz. source IP address, destination IP address, source port no, destination
port number) and sent as a single message to the receiver.
This process is called multiplexing.
At the destination, the received message is unwrapped and constituent messages
(viz messages from a hike and WhatsApp application) are sent to the appropriate
application by looking to the destination the port number.
This process is called demultiplexing. Similarly, B can also transfer the
messages to A.
Figure – Message transfer using WhatsApp and hike messaging application

User Datagram Protocol (UDP) is a Transport Layer protocol. UDP is a part of


the Internet Protocol suite, referred to as UDP/IP suite. Unlike TCP, it is
an unreliable and connectionless protocol. So, there is no need to establish a
connection prior to data transfer. The UDP helps to establish low-latency and
loss-tolerating connections establish over the network.The UDP enables process
to process communication.
Though Transmission Control Protocol (TCP) is the dominant transport layer
protocol used with most of the Internet services; provides assured delivery,
reliability, and much more but all these services cost us additional overhead and
latency. Here, UDP comes into the picture. For real-time services like computer
gaming, voice or video communication, live conferences; we need UDP. Since
high performance is needed, UDP permits packets to be dropped instead of
processing delayed packets. There is no error checking in UDP, so it also saves
bandwidth.
User Datagram Protocol (UDP) is more efficient in terms of both latency and
bandwidth.
UDP Header –
UDP header is an 8-bytes fixed and simple header, while for TCP it may vary
from 20 bytes to 60 bytes. The first 8 Bytes contains all necessary header
information and the remaining part consist of data. UDP port number fields are
each 16 bits long, therefore the range for port numbers is defined from 0 to
65535; port number 0 is reserved. Port numbers help to distinguish different user
requests or processes.
1. Source Port: Source Port is a 2 Byte long field used to identify the port
number of the source.
2. Destination Port: It is a 2 Byte long field, used to identify the port of the
destined packet.
3. Length: Length is the length of UDP including the header and the data. It is a
16-bits field.
4. Checksum: Checksum is 2 Bytes long field. It is the 16-bit one’s complement
of the one’s complement sum of the UDP header, the pseudo-header of
information from the IP header, and the data, padded with zero octets at the
end (if necessary) to make a multiple of two octets.
Notes – Unlike TCP, the Checksum calculation is not mandatory in UDP. No
Error control or flow control is provided by UDP. Hence UDP depends on IP and
ICMP for error reporting. Also UDP provides port numbers so that is can
differentiate between users requests.
Applications of UDP:
 Used for simple request-response communication when the size of data is less
and hence there is lesser concern about flow and error control.
 It is a suitable protocol for multicasting as UDP supports packet switching.
 UDP is used for some routing update protocols like RIP(Routing Information
Protocol).
 Normally used for real-time applications which can not tolerate uneven delays
between sections of a received message.
 UDP is widely used in online gaming, where low latency and high-speed
communication is essential for a good gaming experience. Game servers often
send small, frequent packets of data to clients, and UDP is well suited for this
type of communication as it is fast and lightweight.
 Streaming media applications, such as IPTV, online radio, and video
conferencing, use UDP to transmit real-time audio and video data. The loss of
some packets can be tolerated in these applications, as the data is
continuously flowing and does not require retransmission.
 VoIP (Voice over Internet Protocol) services, such as Skype and WhatsApp,
use UDP for real-time voice communication. The delay in voice
communication can be noticeable if packets are delayed due to congestion
control, so UDP is used to ensure fast and efficient data transmission.
 DNS (Domain Name System) also uses UDP for its query/response messages.
DNS queries are typically small and require a quick response time, making
UDP a suitable protocol for this application.
 DHCP (Dynamic Host Configuration Protocol) uses UDP to dynamically
assign IP addresses to devices on a network. DHCP messages are typically
small, and the delay caused by packet loss or retransmission is generally not
critical for this application.
 Following implementations uses UDP as a transport layer protocol:
 NTP (Network Time Protocol)
 DNS (Domain Name Service)
 BOOTP, DHCP.
 NNP (Network News Protocol)
 Quote of the day protocol
 TFTP, RTSP, RIP.
 The application layer can do some of the tasks through UDP-
 Trace Route
 Record Route
 Timestamp
 UDP takes a datagram from Network Layer, attaches its header, and sends it
to the user. So, it works fast.
 Actually, UDP is a null protocol if you remove the checksum field.
1. Reduce the requirement of computer resources.
2. When using the Multicast or Broadcast to transfer.
3. The transmission of Real-time packets, mainly in multimedia applications.
Advantages of UDP:
1. Speed: UDP is faster than TCP because it does not have the overhead of
establishing a connection and ensuring reliable data delivery.
2. Lower latency: Since there is no connection establishment, there is lower
latency and faster response time.
3. Simplicity: UDP has a simpler protocol design than TCP, making it easier to
implement and manage.
4. Broadcast support: UDP supports broadcasting to multiple recipients, making
it useful for applications such as video streaming and online gaming.
5. Smaller packet size: UDP uses smaller packet sizes than TCP, which can
reduce network congestion and improve overall network performance.
Disadvantages of UDP:
1. No reliability: UDP does not guarantee delivery of packets or order of
delivery, which can lead to missing or duplicate data.
2. No congestion control: UDP does not have congestion control, which means
that it can send packets at a rate that can cause network congestion.
3. No flow control: UDP does not have flow control, which means that it can
overwhelm the receiver with packets that it cannot handle.
4. Vulnerable to attacks: UDP is vulnerable to denial-of-service attacks, where an
attacker can flood a network with UDP packets, overwhelming the network and
causing it to crash.
5. Limited use cases: UDP is not suitable for applications that require reliable
data delivery, such as email or file transfers, and is better suited for applications
that can tolerate some data loss, such as video streaming or online gaming.
UDP PSEUDO HEADER:
 the purpose of using a pseudo-header is to verify that the UDP packet has
reached its correct destination
 the correct destination consist of a specific machine and a specific protocol
port number within that machine

UDP pseudo header

UDP pseudo header details:


 the UDP header itself specify only protocol port number.thus , to verify the
destination UDP on the sending machine computes a checksum that covers
the destination IP address as well as the UDP packet.
 at the ultimate destination, UDP software verifies the checksum using the
destination IP address obtained from the header of the IP packet that carried
the UDP message.
 if the checksum agrees, then it must be true that the packet has reached the
intended destination host as well as the correct protocol port within that host.
User Interface:
A user interface should allow the creation of new receive ports, receive
operations on the receive ports that returns the data octets and an indication of
source port and source address, and an operation that allows a datagram to be
sent, specifying the data, source and destination ports and address to be sent.
IP Interface:
 the UDP module must be able to determine the source and destination internet
address and the protocol field from internet header
 one possible UDP/IP interface would return the whole internet datagram
including the entire internet header in response to a receive operation
 such an interface would also allow the UDP to pass a full internet datagram
complete with header to the IP to send. the IP would verify certain fields for
consistency and compute the internet header checksum.
 The IP interface allows the UDP module to interact with the network layer of
the protocol stack, which is responsible for routing and delivering data across
the network.
 The IP interface provides a mechanism for the UDP module to communicate
with other hosts on the network by providing access to the underlying IP
protocol.
 The IP interface can be used by the UDP module to send and receive data
packets over the network, with the help of IP routing and addressing
mechanisms.
 The IP interface provides a level of abstraction that allows the UDP module to
interact with the network layer without having to deal with the complexities
of IP routing and addressing directly.
 The IP interface also handles fragmentation and reassembly of IP packets,
which is important for large data transmissions that may exceed the maximum
packet size allowed by the network.
 The IP interface may also provide additional services, such as support for
Quality of Service (QoS) parameters and security mechanisms such as IPsec.
 The IP interface is a critical component of the Internet Protocol Suite, as it
enables communication between hosts on the internet and allows for the
seamless transmission of data packets across the network.

UDP HEADER STRUCTURE (UDP Structure)

The UDP header consists of four fields each of 2 bytes in length –


 Source Port (16 bits) – This field identifies the sender’s port. Cleared to zero
if not used.
 Destination Port (16 bits) – This field identifies the receiver’s port.
 Length (16 bits) – The length in bytes of the UDP header and the
encapsulated data. The minimum value for this field is 8.
 Checksum (16 bits) – The checksum field may be used for error-checking of
the header and data. This field is optional in IPv4, and mandatory in IPv6.
The field carries all-zeros if unused. Needed with zero bytes at the end to
make a multiple of two bytes. If the checksum is cleared to zero, then the
checksum is disabled. If the computed checksum is zero, then this field must
be set to 0xFFFF
What is a checksum?
A checksum is a technique used to determine the authenticity of received data,
i.e., to detect whether there was an error in transmission.

Along with the data that needs to be sent, the sender uses an algorithm to calculate
the checksum of the data and sends it along. When the receiver gets the data, it
calculates the checksum of the received data using the same algorithm and
compares it with the transmitted checksum. If they both match, it means the
transmission was error-free.

The checksum technique

Examples

1) UDP Checksum

UDP is a transport layer protocol that enables applications to send and receive
data, especially when it is time-sensitive. UDP uses a checksum to detect whether
the received data has been altered.

The data being sent is divided into 16-bit chunks. These chunks are then added,
any generated carry is added back to the sum. Then, the 1’s complement of the
sum is performed and put in the checksum field of the UDP segment.

Suppose the data we want to send consists of the following three words:

0110011001100000
0101010101010101
1000111100001100

Adding the first two words:


0110011001100000
0101010101010101
_____________________________

1011101110110101

Then, adding the third word to this sum:

1011101110110101
1000111100001100
____________________________

0100101011000001

However, there is a carry out, which we need to add to the final sum again:
0100101011000001+1=
0100101011000010

Finally, we take the 1’s complement of the final sum, which in this case, becomes:
1011010100111101

At the receiver side, all the 16-bit data chunks are added again, with any overflow
being wrapped around. The checksum is also added to the final result. The answer
at the receiver’s side should consist of all ones. If a single bit is zero, it means an
error occurred during transmission.

In the example given above, the data would be added at the receiver’s side to get
0100101011000010, considering the data was transferred correctly. Then, the
receiver would add the checksum to it, which was 1011010100111101

0100101011000010
1011010100111101
____________________________
1111111111111111

All ones in the final result indicate that there were no problems. If, however,
during transmission, even a single bit of the data was altered, the sum would be
different; hence, the final result would consist of at least one zero. This way, the
error would be detected.

2) MD5 Algorithm

The MD5 is an algorithm used to find a 128-bit hash value of the data being sent.
This can also be used to check data integrity. Changing the data very slightly can
change this hash value. An example is:

The data to be transmitted:


The quick brown fox jumped over the lazy dog

MD5 hash value generated by the sender:


08a008a01d498c404b0c30852b39d3b8

Now, if the data was altered e.g., a period added at the end:
The quick brown fox jumped over the lazy dog.

The new MD5 value would be:


5c6ffbdd40d9556b73a21e63c3e0e904 , which is obviously completely different.

MD5 is used in the distribution packages of Unix-based operating systems. It is


also used by file servers so that, when users download a file, they can compare the
computed value to see if it was downloaded correctly.
Benefits of a checksum
There are many benefits of using a checksum, the major one being its simplicity
and ease of checking data corruption. However, checksum does not indicate
exactly where in the data there was a problem, nor does it provide any error
correction.

Principle Of Reliable Data Transfer Protocol

Transport Layer Protocols are central piece of layered architectures, these provides
the logical communication between application processes. These processes uses
the logical communication to transfer data from transport layer to network layer
and this transfer of data should be reliable and secure. The data is transferred in
the form of packets but the problem occurs in reliable transfer of data.
The problem of transferring the data occurs not only at the transport layer, but also
at the application layer as well as in the link layer. This problem occur when a
reliable service runs on an unreliable service, For example, TCP (Transmission
Control Protocol) is a reliable data transfer protocol that is implemented on top of
an unreliable layer, i.e., Internet Protocol (IP) is an end to end network layer
protocol.
Figure: Study of Reliable Data Transfer

In this model, we have design the sender and receiver sides of a protocol over a
reliable channel. In the reliable transfer of data the layer receives the data from the
above layer breaks the message in the form of segment and put the header on each
segment and transfer. Below layer receives the segments and remove the header
from each segment and make it a packet by adding to header.
The data which is transferred from the above has no transferred data bits corrupted
or lost, and all are delivered in the same sequence in which they were sent to the
below layer this is reliable data transfer protocol. This service model is offered by
TCP to the Internet applications that invoke this transfer of data.

Figure: Study of Unreliable Data Transfer

Similarly in an unreliable channel we have design the sending and receiving side.
The sending side of the protocol is called from the above layer to rdt_send() then it
will pass the data that is to be delivered to the application layer at the receiving
side (here rdt-send() is a function for sending data where rdt stands for reliable
data transfer protocol and _send() is used for the sending side).
On the receiving side, rdt_rcv() (rdt_rcv() is a function for receiving data where -
rcv() is used for receiving side), will be called when a packet arrives from the
receiving side of the unreliable channel. When the rdt protocol wants to deliver
data to the application layer, it will do so by calling deliver_data() (where
deliver_data() is a function for delivering data to upper layer).
In reliable data transfer protocol, we only consider the case of unidirectional data
transfer, that is transfer of data from the sending side to receiving side(i.e. only in
one direction). In case of bidirectional (full duplex or transfer of data on both the
sides) data transfer is conceptually more difficult. Although we only consider
unidirectional data transfer but it is important to note that the sending and
receiving sides of our protocol will needs to transmit packets in both directions, as
shown in above figure.
In order to exchange packets containing the data that is needed to be transferred
the both (sending and receiving) sides of rdt also need to exchange control packets
in both direction (i.e., back and forth), both the sides of rdt send packets to the
other side by a call to udt_send() (udt_send() is a function used for sending data to
other side where udt stands for unreliable data transfer protocol).

Pipelined Reliable Data Transfer Protocols

Protocol rdt3.0 is a functionally correct protocol, but it is doubtful that anyone


would be happy with its performance, especially in todays high-speed networks.

At the heart of rdt.3.0s performance problem is the fact that it is a stop-and-wait


protocol.

To appreciate the performance impact of this stop-and-wait behavior, look at an


idealized case of two hosts, one located on the West Coast of the United States
and the other located on the East Coast, as shown in Figure 2.

The speed-of-light round-trip propagation delay between these two end systems,
RTT, is approximately 30 milliseconds.

Suppose that they are connected by a channel with a transmission rate, R, of 1


Gbps (109 bits per second). With a packet size, L, of 1,000 bytes
(8,000 bits) per packet, including both header fields and data, the time required
to actually transmit the packet into the 1 Gbps link is

"Go-Back-N (GBN)" Figure 1(a) illustrates that with our stop-and-wait protocol,
if the sender begins sending the packet at t = 0, then at t = L/R = 8
microseconds, the last bit enters the channel at the sender side. The packet then
makes its 15-msec cross-country journey, with the last bit of the packet
emerging at the receiver at t = RTT/2 + L/R = 15.008 msec. Assuming for
simplicity that ACK packets are very small (so that we can ignore their
transmission time) and that the receiver can send an ACK as soon as the last bit
of a data packet is received, the ACK emerges back at the sender at t = RTT +
L/R = 30.008 msec. At this point, the sender can now transmit the next message.
Therefore, in 30.008 msec, the sender was sending for only 0.008 msec. If we
define the utilization of the sender (or the channel) as the fraction of time the
sender is actually busy sending bits into the channel, the analysis in "Go-Back-N
(GBN)" Figure 1(a) illustrates that the stop-and-wait protocol has a rather dismal
sender utilization, Usender, of

That is, the sender was busy only 2.7 hundredths of one percent of the time.
Viewed another way, the sender was able to send only 1,000 bytes in 30.008
milliseconds, an effective throughput of only 267 kbps - even though a 1 Gbps
link was available. Imagine the unhappy network manager who just paid a fortune
for a gigabit capacity link but manages to get a throughput of only 267 kilobits
per second. This is a graphic example of how network protocols can limit the
capabilities provided by the underlying
network hardware. Also, we have neglected lower-layer protocol-processing
times at the sender and receiver, as well as the processing and queuing delays
that would take place at any intermediate routers between the sender and
receiver. Including these effects would serve only to further increase the delay
and further accentuate the poor performance.

The solution to this specific performance problem is simple: Rather than


operate in a stop-and-wait manner, the sender is allowed to send multiple
packets without waiting for acknowledgments, as shown in Figure 2(b). "Go-
Back-N (GBN)" Figure 1(b) shows that if the sender is allowed to transmit three
packets before having to wait for acknowledgments, the utilization of the sender
is essentially tripled. Since the many in-transit sender-to-receiver packets can
be visualized as filling a pipeline, this technique is known as pipelining.
Pipelining has the following consequences for reliable data transfer protocols:
 The range of sequence numbers must be increased, since each in-transit
packet (not counting retransmissions) must have a unique sequence
number and there may be multiple, in-transit, unacknowledged packets.
 The sender and receiver sides of the protocols may have to buffer more
than one packet. Minimally, the sender will have to buffer packets that
have been transmitted but not yet acknowledged. Buffering of correctly
received packets may also be required at the receiver.
 The range of sequence numbers needed and the buffering requirements
will depend on the manner in which a data transfer protocol responds to
lost, corrupted, and overly delayed packets. Two basic approaches
toward pipelined error recovery can be identified: Go-Back- N and
selective repeat.

You should implement the Pipelined Reliable Data Transfer Protocols by using:
1. Go-Back-N and
2. Selective repeat.

GO – BACK N
Go-Back-N protocol, also called Go-Back-N Automatic Repeat reQuest, is a data
link layer protocol that uses a sliding window method for reliable and sequential
delivery of data frames. It is a case of sliding window protocol having to send
window size of N and receiving window size of 1.

Working Principle

Go – Back – N ARQ provides for sending multiple frames before receiving the
acknowledgment for the first frame. The frames are sequentially numbered and a
finite number of frames. The maximum number of frames that can be sent
depends upon the size of the sending window. If the acknowledgment of a frame
is not received within an agreed upon time period, all frames starting from that
frame are retransmitted.

The size of the sending window determines the sequence number of the outbound
frames. If the sequence number of the frames is an n-bit field, then the range of
sequence numbers that can be assigned is 0 to 2n−1. Consequently, the size of the
sending window is 2n−1. Thus in order to accommodate a sending window size
of 2n−1, a n-bit sequence number is chosen.

The sequence numbers are numbered as modulo-n. For example, if the sending
window size is 4, then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and
so on. The number of bits in the sequence number is 2 to generate the binary
sequence 00, 01, 10, 11.

The size of the receiving window is 1.

Sender Site Algorithm of Go-Back-N Protocol

begin
frame s; //s denotes frame to be sent
frame t; //t is temporary frame
S_window = power(2,m) – 1; //Assign maximum window size
SeqFirst = 0; // Sequence number of first frame in window
SeqN = 0; // Sequence number of Nth frame window
while (true) //check repeatedly
do
Wait_For_Event(); //wait for availability of packet
if ( Event(Request_For_Transfer)) then
//check if window is full
if (SeqN–SeqFirst >= S_window) then
doNothing();
end if;
Get_Data_From_Network_Layer();
s = Make_Frame();
s.seq = SeqN;
Store_Copy_Frame(s);
Send_Frame(s);
Start_Timer(s);
SeqN = SeqN + 1;
end if;
if ( Event(Frame_Arrival) then
r = Receive_Acknowledgement();
if ( AckNo > SeqFirst && AckNo < SeqN ) then
while ( SeqFirst <= AckNo )
Remove_copy_frame(s.seq(SeqFirst));
SeqFirst = SeqFirst + 1;
end while
Stop_Timer(s);
end if
end if
// Resend all frames if acknowledgement havn’t been received
if ( Event(Time_Out)) then
TempSeq = SeqFirst;
while ( TempSeq < SeqN )
t = Retrieve_Copy_Frame(s.seq(SeqFirst));
Send_Frame(t);
Start_Timer(t);
TempSeq = TempSeq + 1;
end while
end if
end

Receiver Site Algorithm of Go-Back-N Protocol

Begin
frame f;
RSeqNo = 0; // Initialise sequence number of expected frame
while (true) //check repeatedly
do
Wait_For_Event(); //wait for arrival of frame
if ( Event(Frame_Arrival) then
Receive_Frame_From_Physical_Layer();
if ( Corrupted ( f.SeqNo )
doNothing();
else if ( f.SeqNo = RSeqNo ) then
Extract_Data();
Deliver_Data_To_Network_Layer();
RSeqNo = RSeqNo + 1;
Send_ACK(RSeqNo);
end if
end if
end while
end

SELECTIVE REPEAT

he selective repeat protocol, is to allow the receiver to accept and buffer the
frames following a damaged or lost one. Selective Repeat attempts to
retransmit only those packets that are actually lost (due to errors) :
 Receiver must be able to accept packets out of order.
 Since receiver must release packets to higher layer in order, the receiver
must be able to buffer some packets.
Retransmission requests :
 Implicit – The receiver acknowledges every good packet, packets that are
not ACKed before a time-out are assumed lost or in error.Notice that this
approach must be used to be sure that every packet is eventually received.
 Explicit – An explicit NAK (selective reject) can request retransmission of
just one packet. This approach can expedite the retransmission but is not
strictly needed.
 One or both approaches are used in practice.
Selective Repeat Protocol (SRP) : This protocol(SRP) is mostly identical to
GBN protocol, except that buffers are used and the receiver, and the sender,
each maintains a window of size. SRP works better when the link is very
unreliable. Because in this case, retransmission tends to happen more
frequently, selectively retransmitting frames is more efficient than
retransmitting all of them. SRP also requires full-duplex link. backward
acknowledgements are also in progress.
 Sender’s Windows ( Ws) = Receiver’s Windows ( Wr).
 Window size should be less than or equal to half the sequence number in
SR protocol. This is to avoid packets being recognized incorrectly. If the
size of the window is greater than half the sequence number space, then if
an ACK is lost, the sender may send new packets that the receiver believes
are retransmissions.
 Sender can transmit new packets as long as their number is with W of all
unACKed packets.
 Sender retransmit un-ACKed packets after a timeout – Or upon a NAK if
NAK is employed.
 Receiver ACKs all correct packets.
 Receiver stores correct packets until they can be delivered in order to the
higher layer.
 In Selective Repeat ARQ, the size of the sender and receiver window must
be at most one-half of 2^m.

Figure – the sender only retransmits frames, for which a NAK is


receivedEfficiency of Selective Repeat Protocol (SRP) is same as GO-Back-
N’s efficiency :
Efficiency = N/(1+2a)
Where a = Propagation delay / Transmission delay
Buffers = N + N
Sequence number = N(sender side) + N ( Receiver Side)

if Tt(ack) :Transmission delay for acknowledgment , Tq: Queuing delay


and Tpro: Processing delay is mention
We know that the Efficiency (?),
=Useful time / Total cycle time
=Tt(data) /Tt(data) + 2*Tp + Tq + Tpro + Tt(ack)
Tt(data) : Transmission delay for Data packet
Tp : propagation delay for Data packet
Tq: Queuing delay
Tpro: Processing delay
Tt(ack): Transmission delay for acknowledgment
Above formula is applicable for any condition, if any of the things are not
given we assume it to be 0.

TCP Connection (A 3-way handshake)

Handshake refers to the process to establish connection between the client and
server. Handshake is simply defined as the process to establish a communication
link. To transmit a packet, TCP needs a three way handshake before it starts
sending data. The reliable communication in TCP is termed as PAR (Positive
Acknowledgement Re-transmission). When a sender sends the data to the
receiver, it requires a positive acknowledgement from the receiver confirming the
arrival of data. If the acknowledgement has not reached the sender, it needs to
resend that data. The positive acknowledgement from the receiver establishes a
successful connection.

Here, the server is the server and client is the receiver. The above diagram shows
3 steps for successful connection. A 3-way handshake is commonly known as
SYN-SYN-ACK and requires both the client and server response to exchange the
data. SYN means synchronize Sequence Number and ACK
means acknowledgment. Each step is a type of handshake between the sender
and the receiver.

The diagram of a successful TCP connection showing the three handshakes is


shown below:
The three handshakes are discussed in the below steps:

Step 1: SYN

SYN is a segment sent by the client to the server. It acts as a connection


request between the client and server. It informs the server that the client wants
to establish a connection. Synchronizing sequence numbers also helps
synchronize sequence numbers sent between any two devices, where the same
SYN segment asks for the sequence number with the connection request.

Step 2: SYN-ACK

It is an SYN-ACK segment or an SYN + ACK segment sent by the server. The


ACK segment informs the client that the server has received the connection
request and it is ready to build the connection. The SYN segment informs the
sequence number with which the server is ready to start with the segments.

Step 3: ACK

ACK (Acknowledgment) is the last step before establishing a successful TCP


connection between the client and server. The ACK segment is sent by the client
as the response of the received ACK and SN from the server. It results in the
establishment of a reliable data connection.

After these three steps, the client and server are ready for the data communication
process. TCP connection and termination are full-duplex, which means that the
data can travel in both the directions simultaneously.

TCP – SEGMENT STRUCTURE


TCP Segment structure –
A TCP segment consists of data bytes to be sent and a header that is added to
the data by TCP as shown:

The header of a TCP segment can range from 20-60 bytes. 40 bytes are for
options. If there are no options, a header is 20 bytes else it can be of upmost 60
bytes.
Header fields:

 Source Port Address –


A 16-bit field that holds the port address of the application that is sending
the data segment.

 Destination Port Address –


A 16-bit field that holds the port address of the application in the host that
is receiving the data segment.
 Sequence Number –
A 32-bit field that holds the sequence number, i.e, the byte number of the
first byte that is sent in that particular segment. It is used to reassemble the
message at the receiving end of the segments that are received out of order.

 Acknowledgement Number –
A 32-bit field that holds the acknowledgement number, i.e, the byte number
that the receiver expects to receive next. It is an acknowledgement for the
previous bytes being received successfully.

 Header Length (HLEN) –


This is a 4-bit field that indicates the length of the TCP header by a number
of 4-byte words in the header, i.e if the header is 20 bytes(min length of
TCP header), then this field will hold 5 (because 5 x 4 = 20) and the
maximum length: 60 bytes, then it’ll hold the value 15(because 15 x 4 =
60). Hence, the value of this field is always between 5 and 15.

 Control flags –
These are 6 1-bit control bits that control connection establishment,
connection termination, connection abortion, flow control, mode of transfer
etc. Their function is:
 URG: Urgent pointer is valid
 ACK: Acknowledgement number is valid( used in case of
cumulative acknowledgement)
 PSH: Request for push
 RST: Reset the connection
 SYN: Synchronize sequence numbers
 FIN: Terminate the connection
 Window size –
This field tells the window size of the sending TCP in bytes.

 Checksum –
This field holds the checksum for error control. It is mandatory in TCP as
opposed to UDP.

 Urgent pointer –
This field (valid only if the URG control flag is set) is used to point to data
that is urgently required that needs to reach the receiving process at the
earliest. The value of this field is added to the sequence number to get the
byte number of the last urgent byte.
Round Trip Time
RTT (Round Trip Time) also called round-trip delay is a crucial tool in
determining the health of a network. It is the time between a request for data
and the display of that data. It is the duration measured in milliseconds.
RTT can be analyzed and determined by pinging a certain address. It refers to
the time taken by a network request to reach a destination and to revert back to
the original source. In this scenario, the source is the computer and the
destination is a system that captures the arriving signal and reverts it back.

RTT(Round Trip Time) Measurement

What Are Common Factors that Affect RTT?


There are certain factors that can bring huge changes in the value of RTT. These
are enlisted below:
 Distance: It is the length in which a signal travels for a request to reach the
server and for a response to reach the browser,
 Transmission medium: The medium which is used to route a signal, which
helps in faster transfer of request is transmitted.
 Network hops: It is the time that servers take to process a signal, on
increasing the number of hops, RTT will also increase.
 Traffic levels: Round Trip Time generally increases when a network is
having huge traffic which results in that, for low traffic RTT will also be less.
 Server response time: It is the time taken by a server to respond to a request
which basically depends on the capacity of handling requests and also
sometimes on the nature of the request.

Applications of RTT
Round Trip Time refers to a wide variety of transmissions such as wireless
Internet transmissions and satellite transmissions. In Internet transmissions,
RTT may be identified by using the ping command. In satellite transmissions,
RTT can be calculated by making use of the Jacobson/Karels algorithm.

Advantages of RTT
Calculation of RTT is advantageous because:
1. It allows users and operators to identify how long a signal will take to
complete the transmission.
2. It also determines how fast a network can work and the reliability of the
network.
Example: Let us assume there are two users, one of which wants to contact the
other one. One of them is located in California while the other one is situated in
Germany. When the one in California makes the request, the network traffic is
transferred across many routers before reaching the server located in Germany.
Once the request reverts back to California, a rough estimation of the time taken
for this transmission could be made. This time taken by the transmitted request
is referred to as RTT. The Round Trip Time is a mere estimate. The path
between the two locations can change as the passage and network congestion
can come into play, affecting the total period of transmission.

RELIABLE DATA TRANSFER

(RDT) 1.0 works on a perfectly reliable channel, that is, it assumes that the
underlying channel has:
1. No bit errors and
2. No loss of packets
This transfer of data is shown by using FSM (finite state machine). In RDT
1.0, there is only one state each for sender and receiver.
Sender Side: When the sender sends data from the application
layer, RDT simply accepts data from the upper layer via
the rdt_send(data) event. Then it puts the data into a packet (via
the make_pkt(packet,data) event) and sends the packet into the channel using
the udp_send(packet) event.
RDT1.0: Sender side FSM

Receiving Side: On receiving data from the channel, RDT simply accepts data
via the rdt_rcv(data) event. Then it extracts the data from the packet (via the
extract(packet, data)) and sends the data to the application layer using
the deliver_data(data) event.

RDT1.0: Receiving Side FSM

No feedback is required by the receiving side as the channel is perfectly


reliable, that is, no errors are possible during the data transmission through the
underlying channel.

TCP Connection Management

The connection is established in TCP using the three-way handshake as discussed


earlier to create a connection. One side, say the server, passively stays for an
incoming link by implementing the LISTEN and ACCEPT primitives, either
determining a particular other side or nobody in particular.

The other side performs a connect primitive specifying the I/O port to which it
wants to join. The maximum TCP segment size available, other options are
optionally like some private data (example password).

The CONNECT primitive transmits a TCP segment with the SYN bit on and the
ACK bit off and waits for a response.

The sequence of TCP segments sent in the typical case, as shown in the figure
below −

When the segment sent by Host-1 reaches the destination, i.e., host -2, the
receiving server checks to see if there is a process that has done a LISTEN on the
port given in the destination port field. If not, it sends a response with the RST
bit on to refuse the connection. Otherwise, it governs the TCP segment to the
listing process, which can accept or decline (for example, if it does not look
similar to the client) the connection.

Call Collision

If two hosts try to establish a connection simultaneously between the same two
sockets, then the events sequence is demonstrated in the figure under such
circumstances. Only one connection is established. It cannot select both the links
because their endpoints identify connections.

Suppose the first set up results in a connection identified by (x, y) and the second
connection are also released up. In that case, only tail enter will be made, i.e., for
(x, y) for the initial sequence number, a clock-based scheme is used, with a clock
pulse coming after every 4 microseconds. For ensuring additional safety when a
host crashes, it may not reboot for sec, which is the maximum packet lifetime.
This is to make sure that no packets from previous connections are roaming
around.

TCP Congestion Control

TCP congestion control is a method used by the TCP protocol to manage data
flow over a network and prevent congestion. TCP uses a congestion window
and congestion policy that avoids congestion. Previously, we assumed that only
the receiver could dictate the sender’s window size. We ignored another entity
here, the network. If the network cannot deliver the data as fast as it is created
by the sender, it must tell the sender to slow down. In other words, in addition
to the receiver, the network is a second entity that determines the size of the
sender’s window

Congestion Policy in TCP


1. Slow Start Phase: Starts slow increment is exponential to the threshold.
2. Congestion Avoidance Phase: After reaching the threshold increment is by
1.
3. Congestion Detection Phase: The sender goes back to the Slow start phase
or the Congestion avoidance phase.

Slow Start Phase

Exponential increment: In this phase after every RTT the congestion window
size increments exponentially.
Example:- If the initial congestion window size is 1 segment, and the first
segment is successfully acknowledged, the congestion window size becomes 2
segments. If the next transmission is also acknowledged, the congestion window
size doubles to 4 segments. This exponential growth continues as long as all
segments are successfully acknowledged.
Initially cwnd = 1
After 1 RTT, cwnd = 2^(1) = 2
2 RTT, cwnd = 2^(2) = 4
3 RTT, cwnd = 2^(3) = 8
Congestion Avoidance Phase

Additive increment: This phase starts after the threshold value also denoted as
ssthresh. The size of cwnd(congestion window) increases additive. After each
RTT cwnd = cwnd + 1.
Example:- if the congestion window size is 20 segments and all 20 segments
are successfully acknowledged within an RTT, the congestion window size
would be increased to 21 segments in the next RTT. If all 21 segments are again
successfully acknowledged, the congestion window size would be increased to
22 segments, and so on.
Initially cwnd = i
After 1 RTT, cwnd = i+1
2 RTT, cwnd = i+2
3 RTT, cwnd = i+3

Congestion Detection Phase

Multiplicative decrement: If congestion occurs, the congestion window size is


decreased. The only way a sender can guess that congestion has happened is the
need to retransmit a segment. Retransmission is needed to recover a missing
packet that is assumed to have been dropped by a router due to congestion.
Retransmission can occur in one of two cases: when the RTO timer times out or
when three duplicate ACKs are received.
Case 1: Retransmission due to Timeout – In this case, the congestion possibility
is high.
(a) ssthresh is reduced to half of the current window size.
(b) set cwnd = 1
(c) start with the slow start phase again.
Case 2: Retransmission due to 3 Acknowledgement Duplicates – The
congestion possibility is less.
(a) ssthresh value reduces to half of the current window size.
(b) set cwnd= ssthresh
(c) start with congestion avoidance phase
Example
Assume a TCP protocol experiencing the behavior of slow start. At the 5th
transmission round with a threshold (ssthresh) value of 32 goes into the
congestion avoidance phase and continues till the 10th transmission. At the 10th
transmission round, 3 duplicate ACKs are received by the receiver and entered
into additive increase mode. Timeout occurs at the 16th transmission round. Plot
the transmission round (time) vs congestion window size of TCP segments.

Approaches to Congestion Control

There are some approaches for congestion control over a network which are
usually applied on different time scales to either prevent congestion or react to it
once it has occurred.

Let us understand these approaches step wise as mentioned below −

Step 1 − The basic way to avoid congestion is to build a network that is well
matched to the traffic that it carries. If more traffic is directed but a low-
bandwidth link is available, definitely congestion occurs.
Step 2 − Sometimes resources can be added dynamically like routers and links
when there is serious congestion. This is called provisioning, and which happens
on a timescale of months, driven by long-term trends.

Step 3 − To utilise most existing network capacity, routers can be tailored to


traffic patterns making them active during daytime when network users are using
more and sleep in different time zones.

Step 4 − Some of local radio stations have helicopters flying around their cities
to report on road congestion to make it possible for their mobile listeners to route
their packets (cars) around hotspots. This is called traffic aware routing.

Step 5 − Sometimes it is not possible to increase capacity. The only way to reduce
the congestion is to decrease the load. In a virtual circuit network, new
connections can be refused if they would cause the network to become congested.
This is called admission control.

Step 6 − Routers can monitor the average load, queueing delay, or packet loss. In
all these cases, the rising number indicates growing congestion. The network is
forced to discard packets that it cannot deliver. The general name for this is Load
shedding. The better technique for choosing which packets to discard can help to
prevent congestion collapse.

You might also like