Networklayer PDF
Networklayer PDF
The network Layer is the third layer in the OSI model of computer networks. Its
main function is to transfer network packets from the source to the destination.
It is involved both the source host and the destination host. At the source, it
accepts a packet from the transport layer, encapsulates it in a datagram, and then
delivers the packet to the data link layer so that it can further be sent to the
receiver. At the destination, the datagram is decapsulated, and the packet is
extracted and delivered to the corresponding transport layer.
Features of Network Layer
1. The main responsibility of the Network layer is to carry the data
packets from the source to the destination without changing or using
them.
2. If the packets are too large for delivery, they are fragmented i.e.,
broken down into smaller packets.
3. It decides the route to be taken by the packets to travel from the source
to the destination among the multiple routes available in a network
(also called routing).
4. The source and destination addresses are added to the data packets
inside the network layer.
Services Offered by Network Layer
The services which are offered by the network layer protocol are as follows:
1. Packetizing
2. Routing
3. Forwarding
1. Packetizing
The process of encapsulating the data received from the upper layers of the
network (also called payload) in a network layer packet at the source and
decapsulating the payload from the network layer packet at the destination is
known as packetizing.
The source host adds a header that contains the source and destination address
and some other relevant information required by the network layer protocol to
the payload received from the upper layer protocol and delivers the packet to
the data link layer.
The destination host receives the network layer packet from its data link layer,
decapsulates the packet, and delivers the payload to the corresponding upper
layer protocol. The routers in the path are not allowed to change either the source
or the destination address. The routers in the path are not allowed to decapsulate
the packets they receive unless they need to be fragmented.
Packetizing
2. Routing
Routing is the process of moving data from one device to another device. These
are two other services offered by the network layer. In a network, there are a
number of routes available from the source to the destination. The network layer
specifies some strategies which find out the best possible route. This process is
referred to as routing. There are a number of routing protocols that are used in
this process and they should be run to help the routers coordinate with each other
and help in establishing communication throughout the network.
Routing
3. Forwarding
Forwarding is simply defined as the action applied by each router when a packet
arrives at one of its interfaces. When a router receives a packet from one of its
attached networks, it needs to forward the packet to another attached network
(unicast routing) or to some attached networks (in the case of multicast routing).
Routers are used on the network for forwarding a packet from the local network
to the remote network. So, the process of routing involves packet forwarding
from an entry interface out to an exit interface.
Forwarding
1. Error Control
2. Flow Control
3. Congestion Control
1. Error Control
Although it can be implemented in the network layer, it is usually not preferred
because the data packet in a network layer may be fragmented at each router,
which makes error-checking inefficient in the network layer.
2. Flow Control
It regulates the amount of data a source can send without overloading the
receiver. If the source produces data at a very faster rate than the receiver can
consume it, the receiver will be overloaded with data. To control the flow of
data, the receiver should send feedback to the sender to inform the latter that it
is overloaded with data.
There is a lack of flow control in the design of the network layer. It does not
directly provide any flow control. The datagrams are sent by the sender when
they are ready, without any attention to the readiness of the receiver.
3. Congestion Control
Congestion occurs when the number of datagrams sent by the source is beyond
the capacity of the network or routers. This is another issue in the network layer
protocol. If congestion continues, sometimes a situation may arrive where the
system collapses and no datagrams are delivered. Although congestion
control is indirectly implemented in the network layer, still there is a lack of
congestion control in the network layer.
Advantages of Network Layer Services
Packetization service in the network layer provides ease of
transportation of the data packets.
Packetization also eliminates single points of failure in data
communication systems.
Routers present in the network layer reduce network traffic by creating
collision and broadcast domains.
With the help of Forwarding, data packets are transferred from one
place to another in the network.
Disadvantages of Network Layer Services
There is a lack of flow control in the design of the network layer.
Congestion occurs sometimes due to the presence of too many
datagrams in a network that is beyond the capacity of the network or
the routers. Due to this, some routers may drop some of the datagrams,
and some important pieces of information may be lost.
Although indirect error control is present in the network layer, there is
a lack of proper error control mechanisms as due to the presence of
fragmented data packets, error control becomes difficult to
implement.
Prior to data
transmission, a
Connection No connection setup is
connection is
Establishment required.
established between
sender and receiver.
Provides reliable
Provides unreliable
delivery of packets by
delivery of packets and
Error Control detecting and
does not guarantee
retransmitting lost or
delivery or correctness.
corrupted packets.
Requires more
Requires less overhead overhead per packet
per packet because because each packet
Overhead connection setup and contains information
state maintenance are about its destination
done only once. address and other
routing information.
Conclusion
Another term for virtual circuits is connection-oriented switching.
Virtual circuit switching establishes a predetermined path before a
message is sent.
The path in virtual circuits is called a virtual circuit because it seems
to the user to be a dedicated physical circuit.
In datagram networks, sometimes referred to as packet-switching
technology, each packet—also known as a datagram—is regarded as
an autonomous entity. The switch uses the destination information
included in each packet to guide the packet to its intended location.
Reserving resources is not necessary in Datagram Networks since
there isn’t a specific channel for connection sessions. Packets now
have a header containing all of the data intended for the destination.
Datagram networks use first-come, first-serve (FCFS) scheduling to
manage resource distribution.
INSIDE A ROUTER -INPUT PROCESSING
========================================================
=Router is a networking device that fulfills the need for devices to share files
and forward data packets between devices over computer networks. Routers
perform some directing functions on the Internet so the data sent over the
internet, such as a web page in the form of data packets
Example: Let us understand this by a very general example, suppose, we search
for www.google.com in your web browser then this will be a request which will
be sent from system to the google`s server to serve that webpage, now the
request is nothing but a stream of packets don`t just go the google`s server
straightaway they go through a series of devices known as a router which
accepts this packets and forwards them to correct path and hence it reaches to
the destination server.
Below is the raw diagram showing the internal components of the router:
What is Switching?
Process of Switching
The switching process involves the following steps:
Frame Reception: The switch receives a data frame or packet from a
computer connected to its ports.
MAC Address Extraction: The switch reads the header of the data
frame and collects the destination MAC Address from it.
MAC Address Table Lookup: Once the switch has retrieved the
MAC Address, it performs a lookup in its Switching table to find a
port that leads to the MAC Address of the data frame.
Forwarding Decision and Switching Table Update: If the switch
matches the destination MAC Address of the frame to the MAC
address in its switching table, it forwards the data frame to the
respective port. However, if the destination MAC Address does not
exist in its forwarding table, it follows the flooding process, in which
it sends the data frame to all its ports except the one it came from and
records all the MAC Addresses to which the frame was delivered.
This way, the switch finds the new MAC Address and updates
its forwarding table.
Frame Transition: Once the destination port is found, the switch
sends the data frame to that port and forwards it to its target
computer/network.
Types of Switching
There are three types of switching methods:
Message Switching
Circuit Switching
Packet Switching
Datagram Packet Switching
Virtual Circuit Packet Switching
Routers are essential networking devices that direct the flow of data over a network.
Routers have one or more input and output interfaces which receive and transmit
packets respectively. Since the router’s memory is finite, a router can run out of
space to accommodate freshly arriving packets. This occurs if the rate of arrival of
the packets is greater than the rate at which packets exit from the router’s memory.
In such a situation, new packets are ignored or older packets are dropped. As part of
the resource allocation mechanisms, routers must implement some queuing
discipline that governs how packets are buffered or dropped when required.
Router queues are susceptible to congestion by virtue of the limited buffer memory
available to them. When the rate of ingress traffic becomes larger than the amounts
that can be forwarded on the output interface, congestion is observed. The potential
causes of such a situation mainly involve:
The default queuing scheme followed by most routers is FIFO. This generally
requires little or no configuration to be done on the server. All packets in FIFO are
serviced in the same order as they arrive in the router. On reaching saturation within
the memory, new packets attempting to enter the router are dropped (tail drop). Such
a scheme, however, is not apt for real-time applications, especially during
congestion. A real-time application such as VoIP, which continually sends packets,
may be starved during times of congestion and have all its packets dropped.
In Priority Queuing, instead of using a single queue, the router bifurcates the
memory into multiple queues, based on some measure of priority. After this, each
queue is handled in a FIFO manner while cycling through the queues one by one.
The queues are marked as High, Medium, or Low based on priority. Packets from
the High queue are always processed before packets from the Medium queue.
Likewise, packets from the Medium queue are always processed before packets in
the Normal queue, etc. As long as some packets exist in the High priority queue, no
other queue’s packets are processed. Thus, high priority packets cut to the front of
the line and get serviced first. Once a higher priority queue is emptied, only then is a
lower priority queue serviced.
Fig 2: Multiple sub-queues used in Priority Queuing Scheme
Control plane responsible about how packets Data plane responsible for moving
03.
should be forwarded. packets from source to destination.
Control plane packets are locally originated Data plane packets go through the
08.
by the router itself. router.
Control plane acts as a decision maker in data Data plane acts as a decision
09.
forwarding. implementer in data forwarding.
There are two types of network transmission techniques, circuit switched network
and packet switched network. Circuit Switch vs Packet Switch In circuit switched
network, a single path is designated for transmission of all the data packets. Whereas
in case of a packet-switched network, each packet may be sent through a different
path to reach the destination. In a circuit switched network, the data packets are
received in order whereas in a packet switched network, the data packets may be
received out of order. The packet switching is further subdivided into Virtual circuits
and Datagram.
In the ICMP packet format, the first 32 bits of the packet contain three fields:
Type (8-bit): The initial 8-bit of the packet is for message type, it provides a brief
description of the message so that receiving network would know what kind of
message it is receiving and how to respond to it. Some common message types are as
follows:
Type 0 – Echo reply
Type 3 – Destination unreachable
Type 5 – Redirect Message
Type 8 – Echo Request
Type 11 – Time Exceeded
Type 12 – Parameter problem
Code (8-bit): Code is the next 8 bits of the ICMP packet format, this field carries
some additional information about the error message and type.
Checksum (16-bit): Last 16 bits are for the checksum field in the ICMP packet
header. The checksum is used to check the number of bits of the complete message
and enable the ICMP tool to ensure that complete data is delivered.
The next 32 bits of the ICMP Header are Extended Header which has the work of
pointing out the problem in IP Message. Byte locations are identified by the pointer
which causes the problem message and receiving device looks here for pointing to the
problem.
The last part of the ICMP packet is Data or Payload of variable length. The bytes
included in IPv4 are 576 bytes and in IPv6, 1280 bytes.
ICMP in DDoS Attacks
In Distributed DOS (DDoS) attacks, attackers provide so much extra traffic to the
target, so that it cannot provide service to users. There are so many ways through
which an attacker executes these attacks, which are described below.
Whenever an attacker sends a ping, whose size is greater than the maximum allowable
size, oversized packets are broken into smaller parts. When the sender re-assembles
it, the size exceeds the limit which causes a buffer overflow and makes the machine
freeze. This is simply called a Ping of Death Attack. Newer devices have protection
from this attack, but older devices did not have protection from this attack.
Whenever the sender sends so many pings that the device on whom the target is done
is unable to handle the echo request. This type of attack is called an ICMP Flood
Attack. This attack is also called a ping flood attack. It stops the target computer’s
resources and causes a denial of service for the target computer.
Smurf Attack
Smurf Attack is a type of attack in which the attacker sends an ICMP packet with a
spoofed source IP address. These type of attacks generally works on older devices like
the ping of death attack.
Types of ICMP Messages
Type Code Description
3 – Destination
1 Destination host unreachable
Unreachable
5 – Redirect Message
Redirect the datagram for the Type of Service
2
and Network
9 – Router
0
Advertisement
Use to discover the addresses of operational
routers
10 – Router Solicitation 0
12 – Parameter
Problem 2 Bad length
ICMP will take the source IP from the discarded packet and inform the source by
sending a source quench message. The source will reduce the speed of transmission
so that router will be free from congestion.
Source Quench Message with Reduced Speed
When the congestion router is far away from the source the ICMP will send a hop-by-
hop source quench message so that every router will reduce the speed of transmission.
Parameter Problem
Whenever packets come to the router then the calculated header checksum should be
equal to the received header checksum then only the packet is accepted by the router.
Parameter Problem
ICMP will take the source IP from the discarded packet and inform the source by
sending a parameter problem message.
Time Exceeded Message
When some fragments are lost in a network then the holding fragment by the router
will be dropped then ICMP will take the source IP from the discarded packet and
informs the source, of discarded datagram due to the time to live field reaching zero,
by sending the time exceeded message.
Destination Un-reachable
The destination is unreachable and is generated by the host or its inbound gateway to
inform the client that the destination is unreachable for some reason.
Destination Un-reachable
There is no necessary condition that only the router gives the ICMP error message
time the destination host sends an ICMP error message when any type of failure (link
failure, hardware failure, port failure, etc) happens in the network.
Redirection Message
Redirect requests data packets are sent on an alternate route. The message informs a
host to update its routing information (to send packets on an alternate route).
Example: If the host tries to send data through a router R1 and R1 sends data on a
router R2 and there is a direct way from the host to R2. Then R1 will send a redirect
message to inform the host that there is the best way to the destination directly through
R2 available. The host then sends data packets for the destination directly to R2.
The router R2 will send the original datagram to the intended destination.
But if the datagram contains routing information then this message will not be sent
even if a better route is available as redirects should only be sent by gateways and
should not be sent by Internet hosts.
Internet Protocol version 6 (IPv6)
IPv6 was developed by Internet Engineering Task Force (IETF) to deal with the
problem of IPv4 exhaustion. IPv6 is a 128-bits address having an address space of
2128, which is way bigger than IPv4. IPv6 use Hexa-Decimal format separated by
colon (:) .
1. Unicast Address
Unicast Address identifies a single network interface. A packet sent to a unicast
address is delivered to the interface identified by that address.
2. Multicast Address
Multicast Address is used by multiple hosts, called as groups, acquires a multicast
destination address. These hosts need not be geographically together. If any packet is
sent to this multicast address, it will be distributed to all interfaces corresponding to
that multicast address. And every node is configured in the same way. In simple
words, one data packet is sent to multiple destinations simultaneously.
3. Anycast Address
Anycast Address is assigned to a group of interfaces. Any packet sent to an anycast
address will be delivered to only one member interface (mostly nearest host
possible).
0000 01 UA 1/64
0000 1 UA 1/32
0001 UA 1/16
010 UA 1/8
011 UA 1/8
100 UA 1/8
101 UA 1/8
110 UA 1/8
1110 UA 1/16
Prefix Allocation Fraction of Address Space
1111 0 UA 1/32
1111 10 UA 1/64
Note: In IPv6, all 0’s and all 1’s can be assigned to any host, there is not any
restriction like IPv4.
Global routing prefix: Global routing prefix contains all the details of Latitude and
Longitude. As of now, it is not being used. In Geography-based Unicast address
routing will be based on location.
Interface Id: In IPv6, instead of using Host Id, we use the term Interface Id.
IPv4 Compatible
IPv4 mapped
A link-local address is used for addressing a single link. It can also be used to
communicate with nodes on the same link. The link-local address always begins
with 1111111010 (i.e. FE80). The router will not forward any packet with Link-local
address.
2. Site local address:
Site local addresses are equivalent to a private IP address in IPv4. Likely, some
address space is reserved, which can only be routed within an organization. The first
10-bits are set to 1111111011, which is why Site local addresses always begin with
FEC0. The following 32 bits are Subnet IDs, which can be used to create a subnet
within the organization. The node address is used to uniquely identify the link;
therefore, we use a 48-bits MAC address here.
Advantages of IPv6 :
1. Realtime Data Transmission : Realtime data transmission refers to the process
of transmitting data in a very fast manner or immediately. Example : Live streaming
services such as cricket matches, or other tournament that are streamed on web
exactly as soon as it happens with a maximum delay of 5-6 seconds.
2. IPv6 supports authentication: Verifying that the data received by the receiver
from the sender is exactly what the sender sent and came through the sender only not
from any third party. Example : Matching the hash value of both the messages for
verification is also done by IPv6.
3. IPv6 performs Encryption: Ipv6 can encrypt the message at network layer even
if the protocols of application layer at user level didn’t encrypt the message which is
a major advantage as it takes care of encryption.
4. Faster processing at Router: Routers are able to process data packets of Ipv6
much faster due to smaller Base header of fixed size – 40 bytes which helps in
decreasing processing time resulting in more efficient packet transmission. Whereas
in Ipv4, we have to calculate the length of header which lies between 20-60 bytes.