Encapsulation
The data portion of a packet at level (N-1) carries the whole packet
(data and header and maybe trailer) from level N. The concept is called
encapsulation. Level (N-1) is not aware of which part
of the encapsulated packet is data and which part is the header or
trailer. For level (N-1), the whole packet coming from level N is
treated as one integral unit.
Layers in OSI
Model
Physical Layer
This layer coordinates the functions required to carry a bit stream
over a physical medium.

Physical layer concerned with the followings:
- Physical characteristics of interface and medium
- Representation of bits
- Data rate / Transmission rate ~> The number of bits sent each
second. In short, physical layer defines the duration of a bit, which is
how long it lasts.
- Synchronization of bits ~> The sender and the receiver clocks
must be synchronized at the bit level.
- Line configuration ~> This layer is concerned with the connection
of devices to the media.
- In a point-to-point configuration ~> 2 devices are
connected through a dedicated link.
- In a multi-point configuration ~> A link is shared among
several devices.
- Physical topology ~> This layer also concerned with how devices
are connected to make a network.
- Transmission mode ~> This layer also defines the direction of
transmission between 2 devices:
- Simplex ~> Only one device can send; the other
can only receive. It is a one-way communication. For example,
radio broadcasting, television broadcasting, monitor output, etc.
- Half-duplex ~> 2 devices can send and receive,
but not at the same time. For example, walkie-talkie, USB, browsing the
internet, etc.
- Full-duplex ~> 2 devices can send and receive at
the same time. For example, video calls, audio calls, live chats,
etc.
Data Link
Layer
It makes the physical layer appear error-free to the upper
layer.

The data link layer is responsible for moving frames from
one hop (node) to the next.
Responsibilities of data link layer are:
- Physical addressing ~> There are 2 scenarios.
- Inside network ~> If sender and receiver are on the same network,
then data link layer adds a header to the frame to define the sender
and/or receiver of the frame.
- Outside network ~> If receiver is not present in the network,
then the gateway devices address will be the destination address.
- Flow control ~> If the rate at which the data are absorbed by the
receiver is less than the rate at which data are produced in the sender,
the data link layer imposes a flow control mechanism to avoid
overwhelming the receiver.
- Error control ~> For a reliable data transfer, data link layer
adds an error control mechanism to detect and re-transmit or lost
frames. It also uses a mechanism to recognize duplicate frames. This
error control is achieved through a trailer added to
the end of the frame.
- Access control ~> When 2 or more devices are connected to the
same link (network), data link layer protocols are necessary to
determine which device has control over the link at any given time.

In this figure, in every hop the source and destination addresses is
different.
Network Layer
The network layer is responsible for the source-to-destination
delivery of a packet, possibly across multiple networks
(links). If 2 systems are connected to the same link, there is usually
no need for a network layer. However, if 2 devices systems are attached
to different networks (links) with connecting device between the
networks (links), there is often a need for the network layer to
accomplish source-to-destination delivery.

Other responsibilities of the network layer includes:
- Logical addressing ~> The physical addressing implemented by the
data link layer handles the addressing problem locally.
If a packet passes the network boundary, we need another addressing
system to help distinguish the source and destination systems. The
network layer adds a header to the packet coming from the upper
layer.
- Routing
The network layer is responsible for
source-to-destination delivery.
Transport
Layer
Transport layer is responsible for
process-to-process delivery.
A process is an application program running on a
host. Whereas the network layer oversees source-to-destination delivery
of individual packets, it doesn’t recognize any relationship between
those packets. It treats each one independently, as though each
piece belonged to a separate message, whether or not it does. On the
other hand, transport layer ensures that the whole message arrives
intact and in order.

Other responsibilities of transport layer:
- Service-point addressing ~> Source-to-destination not only means
delivery from one computer to the next but also from a specific
process (running program) on one computer to a specific
process (running program) on the other. The transport layer
header must therefore include a type of address called a
service-point address (also called port
address). So we can say,
- Network layer ~> Correct computer.
- Transport layer ~> Correct process on that computer
- Segmentation and reassembly ~> A message is divided into
transmittable segments, with each segment containing a sequence
number. These numbers enable the transport layer to reassemble the
message correctly upon arriving at the destination and to identify and
replace packets that were lost in transmission.
- Connection control ~> The transport layer can be either
connectionless (UDP) or connection oriented (TCP).
- Flow control ~> Flow control at this layer is performed
end-to-end rather than across a single link.

Session Layer
The session layer is the network dialog controller. It
establishes, maintains, and synchronizes the interaction among
communicating systems.
The session layer is responsible for dialog control and
synchronization.
Responsibilities of the session layer includes:
- Dialog control ~> This layer allows 2 systems to enter into a
dialog. It allows the communication between two processes to take place
in either half duplex (one way at a time) or full
duplex (two ways at a time) mode.
- Synchronization ~> This layer allows a process to add
checkpoints (synchronization points) to a
stream of data.

Let’s say, we are sending a file of 2000 pages, it is advisable to
insert checkpoints after every 100 pages to ensure that each 100-page
unit is received and acknowledged independently. Now if a crash
happens during transmission of page 552, the only pages that need to be
resent after system recovery are pages 501 to 552.
Presentation
Layer
This layer is concerned with the syntax and
semantics of the info exchanged between 2 systems.

Other responsibilities are:
- Translation ~> The processes (running programs) in 2 systems are
usually exchanging info in the form of character string,
number, and so on. The info must be changed to bit
stream, before being transmitted. As different computers use
different encoding systems, this layer is responsible for
interoperability between these different encoding methods.
- The presentation layer at the sender changes the info from its
sender-dependent format into a common
format.
- The presentation layer at the receiving machine changes the
common format into its
receiver-dependent format.
- Encryption ~> Encryption and decryption of data is done in this
layer
- Compression ~> Data compression reduces the number of bits
contained in the info. Data compression becomes particularly important
in the transmission of multimedia such as text, audio, and video.
Application
Layer
This layer provides user interfaces and support for services such as
email, remote file access and transfer, shared database management and
other types of distributed info services.

The above figure shows only 3 application services.
- X.400 ~> Message-handling services
- X.500 ~> Directory services
- FTAM ~> File transfer, access, and management services
Services provided by the application layer are:
- Network virtual terminal ~> A software version of a physical
terminal, and it allows a user to log on a remote host. To do so, the
application creates a software emulation of a terminal at the remote
host. The user’s computer talks to the software terminal which, in turn,
talks to the host, and vice versa. The remote host believes it is a
communicating with one of its own terminals and allows the user to log
on.
- FTAM ~> This layer allows a user to access files in a remote host
(to make changes/ read data), to retrieve files from a remote computer
for use in the local computer, and to manage or control files in a
remote computer locally.
- Mail services ~> This application provides the basis for e-mail
forwarding and storage.
- Directory service ~> This application provides distributed
database sources and access for global info about various objects and
services.