So welcome back guys
In this module, we will going to discuss the application layer
so the application, the topmost layer of the tcp/ip stack and
We will discuss how to implement our own application in the application layer of the tcp/ip stack
So application layer is the topmost layer in the tcp/ip stack or the OSI model
It is a layer at which the packet journey starts on sending machine and ends on destination machine
Application layer lies outside the operating system or kernel
So we have already discussed that the data link layer
The network layer and the transport layer are the part of the tcp/ip stack
But application layer is not the part of tcp/ip stack
but actually it resides on the top of the tcp/ip stack and
All three layers that is the transport network and data link layer are the part of operating system
Right, they run in the kernel mode
That is they are implemented inside the operating system where where as applications runs on the top of the operating system
Right applications do not run in kernel mode
So the user space program that we write in our day-to-day life are all examples of applications
The tcp client server program that you wrote were also an example of application programs
Running in application layer of tcp/ip stack. right?
so whatever C programs that you have written so far are all examples of
application programs
One network application program that you are using right now is the browser itself which is making use of
application layer protocol
HTTP
So HTTP is a protocol which makes your browsing possible
The application program which we are using right now while browsing this course is the browser
So browser is an example of network application program
other examples of network application programs that we have already discussed in this course is
ICMP protocol. so you remember the ping utility
Works on ICMP protocol. So ICMP is an application layer protocol and the application which is using
ICMP protocol is a ping application which is used to
To test the reach ability of a certain IP address on the network
So in this module we will learn how to write our own application program which have its own application headers
Right. So this is the goal of this module
So remember our old tcp/ip stack
Right, so we will going to see how to implement custom application protocol
That is we will going to write our own application protocols
So just like other layers of tcp/ip stack, our application protocol will also have its own application header
So you see that the transport layer protocol has their own headers like TCP header and UDP header
The IP layer protocol that is the IP protocol has its own header called IP header and the data link layer
protocol like ARP protocol or
Ethernet protocol have their own headers, right?
So we discussed that the ARP protocol has header
Which defines two type of messages the ARP broadcast request and ARP reply message and the Ethernet protocol has its own header called
Ethernet header which encodes the destination and source MAC address and makes the l2 routing possible
So you can see that all the layers of the tcp/ip stack have their own set of headers then why not the application
Layer have its own set of headers?
So we will going to write an application protocol which will have its own set of header
So our application protocol will have its own sub messages type as well. for example
ICMP protocol has two types of sub messages, which is called ICMP echo request and
ICMP echo reply
Similarly the ARP protocol had two types of messages the ARP broadcast request and ARP reply message
Similarly, we will going to write our own application protocol which will have its own sub messages
So guys there are three ways to implement your application protocol in
Tcp/ip stack either you implement your application protocol on top of transport layer
This is one way of implementing application protocol
The second way of implementing application protocol is on the top of network layer in the tcp/ip stack
The network layer is the IP layer and a third way of implementing
The application protocol is directly on top of the data link layer protocol that is directly over the l2 layer of the tcp/ip
Stack. so let us try to understand what we mean when we say that you can implement
Application layer protocol on top of transport layer or network layer or data link layer protocol. Let us see. What does that mean?
So guys let us discuss the scenario when application protocol is run
on top of the transport layer protocol in the tcp/ip stack
So on the right hand side
You can see the tcp/ip stack which has three layers the transport layer, IP layer and the data link layer
Right. So when I say that you can run your application protocol on the top of transport layer protocol
It means that you can run your application protocol here in the tcp/ip stack
That is the application is running on top of the transport layer
Right the underlying layer in this scenario below the application is the transport layer itself
So the example of one such application is the HTTP web server
So HTTP web server is an application protocol which runs at the application layer on top of the tcp protocol
right
So when you run your application on the top of the transport layer protocol in the tcp/ip stack
It means the underlying protocol is the transport layer protocol, which could be UDP protocol or TCP protocol
Right, the two most commonly used transport layer protocols are UDP and TCP protocols
application needs to listen on TCP or UDP port number
so when your transport layer will receive a packet it has to identify that which
Application running above it is interested in that packet
Right. So transport layer identifies that using port numbers
So application so when you run the application on top of the transport layer protocol the application needs to listen on a port number
Which is TCP port number if the transport layer protocol is a TCP protocol being used
Or it is a UDP port number if the transport layer protocol being used is a UDP protocol
So TCP and UDP protocol will take the responsibility for packet transmission between
sending and receiving
process
so sending process may be running somewhere on the sending machine in the network and
The receiving process may be running somewhere on the receiving machine in the network. So
Remember the transport layer protocol is concerned with the transmission of the packet between sending and receiving
processes
the network layer on the other hand will take the responsibility for packet transmission from source machine to destination machine and
Finally the data link layer will take the responsibility for packet transmission hop by hop in the network.
So it means that all the underlying layers that is the transport layer, the IP layer and the data link layer
Will do their jobs as usual
So when your application is running on top of the transport layer in the tcp/ip stack,
that is your application is running in the application layer the packet that is generated by the application will suppose to have
The data link layer header, the IP header, the transport header as well as the application
header so you can see because your
Application is running at the application layer and all the layers of the tcp/ip stack are functioning as usual
Below the application layer when the packet generated by the application
traverses down the tcp/ip stack on the sending machine all the layers in the tcp/ip stack will
append their own headers to the packet
So the packet generated by applications running on top of the transport layer protocol will have Mac header
will have IP header, will have transport header and will have its own application header
So the message somewhat looks like this
So you can see that the Mac header contains the destination MAC address as well as source MAC address the type field contains the identifier
Which identifies the protocol running above the data link layer.
so this is a constant value which means 0800 and
it means that the protocol running above the data link layer is the IP protocol and
IP protocol has its header called IP header
IP header has the source IP address the destination IP address and the protocol field of the IP header
Identifies the protocol running on the running in that transport layer
so if the protocol field is 6 it means the transport layer protocol is TCP and if the protocol
Value in the IP header is 17, it means that the transport layer protocol is UDP
So these are actually the reserved values 6 for TCP and 17 for UDP. Right? And then
In the packet there is a transport header which has the source port number and destination port number. it could be
TCP header or it could be UDP header depending on the protocol value in the IP header and
Finally the last header in the packet is the application data. The application actual data is the last part of the packet
So you can see when the application runs on the top of the tcp/ip stack that is above the transport layer
The packet generated by the application will have headers corresponding to all the layers of the tcp/ip stack
Right. So going forward the second method of
Running the application is directly on top of the network layer in the tcp/ip stack
So here in this diagram, you can see that you are running the application in the application layer
But your application layer is running on top of the IP layer. There is no transport layer
There is no transport layer
right, so
What does that mean?
it means that when there is no transport layer protocol it means
There is no tcp or UDP
protocol, which is responsible for
packet transmission from source process to destination process
Right and when your application runs on the top of the IP layer?
That is the network layer of the tcp/ip stack. Then your application has to define its own protocol value X and
This protocol value X will go in the protocol field of the IP header
so remember in the previous example, this value was either 6 or
17 depending whether the transport layer protocol is TCP or UDP
But since there is no transport layer right now
So the x value has to be defined by the application itself
so remember that every layer in the tcp/ip stack has to encode some
Information to tell that what is the next layer running above it.
so going by that principle the IP layer has to provide the information to identify the application running on the
Running in the application layer. So that identification is now done by the
protocol field value
Right. So let's say that if I define the protocol field value say X is equal to
255 it means that your application layer protocol is assigned the protocol
number
255
so any packet which comes with the IP header which comes with the protocol value as
255 in the IP header, the receiving machine will going to hand over that
packet to the application which which corresponds to protocol number 255
Right when we will be discussing the code
To implement our own application protocol then you will understand it better
So have patience
Network layer takes the responsibility for packet transmission form source machine to destination machine
so this is the basic job of the network layer and
Network layer takes the responsibility to hand over the packet to the application based on the protocol field value X
So remember when your application was running on the top of the transport layer in the previous scenario,
The transport layer identified the correct application
To which the packet has to be handed over
That application was identified using port number but now there is no transport layer
So it is the responsibility of the IP layer to identify the correct application
Running in the application layer
To which it can handover the packet
So that correct application is identified using protocol value in the IP header of the packet
right and
As usual datalink layer takes the responsibility for packet transmission hop by hop.
So you can see
That there is no transport layer in this example because we are running our application directly on top of the IP layer protocol
there is no transport layer header in the packet, so
the packet that is generated by such applications will have Mac header will have IP header and
Directly will have application header. There will be no transport header
Why there will be no transport header because the transport layer is not being used as simple as that
So you can see here that when we run the application directly on the top of the
IP layer and when there is no transport layer
It means we cannot make use of any benefits that is provided by the transport layer protocols
For example, we have a TCP protocol which provides us several benefits for example recovery mechanism
Right, for example
Congestion control
In the network and there are other benefits that is provided by the TCP protocol
So since in this example, we are not using transport layer protocol at all. Therefore any of the benefits provided by the transport protocol
Cannot be harnessed by running application directly on top of the IP layer
So going forward the third way that we can run
Our application protocol is directly on top of the data link layer protocol
So when we run our application directly on the top of the data link layer protocol
You can see that there is no transport layer protocol. There is no network layer either and
because there is no network layer the packet can never be subjected to l3 routing and
Data link layer takes the responsibility for packet transmission from source machine to destination machine
Remember the source and destination machine have to be present in the same subnet
Because data link layer cannot route the packet from source machine to destination machine present in different subnets
So data link layer is still doing its job
So all machines in the same subnet are neighbors of each other has data link layer is still doing its hop by hop work.
So you can see that when you run an application on the top of the data link layer directly
There is no transport layer
There is no IP layer and therefore the packet that is generated by such
Applications will not have IP header will not have transport header
Now the question arises that when the application do not have IP header
It means the packet generated by the application do not have source IP addresses and destination IP addresses
So when the packet doesn't have its destination IP address
It means the packet doesn't know where it is going
Right using the destination IP address field only we find the destination machine in the network
But in this case, there is no IP header. It means there is no destination IP address. So where is actually packet going?
Right. So let us discuss this in a bit detail on the next slide
So yes, it is possible to have the packet without l3 header
So when sending machine A needs to send a packet to destination machine D
A already knows that D is in its own local subnet
Right. So this type of
Packet can only be delivered from machine A to machine D
provided that the machine A and D are present in the same subnets. the
Reason is that that the packet do not have IP header and such a type of packets cannot be l3 routed
between subnets
So remember so remember L3 routing was done by l3 routers using IP header
So packet can be delivered to B using l2 routing alone
So it's not B. It's D
and
When we say l2 routing it means based on only MAC addresses
So when the source machine and destination machine are present in the same subnet, it is not compulsory to add IP header to the packet
Right, but even if you add the IP header, there is no harm
There is no harm. But if you omit the IP header then also there is no harm
So you can see in this diagram suppose the Machine A wants to send the packet to the Machine C
You can see that the machine A and C both are present in the same subnet
right, so A
can always send the packet to the Machine C using l2 routing only and
That is the reason that in order to send the packet from machine A to machine C, the only required thing is the MAC header
Because Mac header will contain the destination MAC address which will identify
The Machine C and the source MAC address
So when the source machine and destination machine are present in the same subnet
there is no need for the packet to ever cross the l3 router boundary and
Therefore there is no need for the IP header in the packet
So that is the reason when it is pre decided that the destination machine of the packet is in the same subnet
You can always generate a packet with only mac header and the application header
So in this example the source MAC address is MA that is the MAC address of the source machine A and the destination MAC
Address is the MAC address of the machine D
That is D is the destination so both the machines that is A and D are present in the same subnet
So they can communicate and exchange data with each other with packets having only Mac headers