Network Layer
Network Layer
o Routing: When a packet reaches the router's input link, the router will move the packets
to the router's output link. For example, a packet from S1 to R1 must be forwarded to the
next router on the path to S2.
o Logical Addressing: The data link layer implements the physical addressing and network
layer implements the logical addressing. Logical addressing is also used to distinguish
between source and destination system. The network layer adds a header to the packet
which includes the logical addresses of both the sender and the receiver.
o Internetworking: This is the main role of the network layer that it provides the logical
connection between different types of networks.
o Fragmentation: The fragmentation is a process of breaking the packets into the smallest
individual data units that travel through different networks.
For example, the router with a header field value of 0111 arrives at a router, and then router
indexes this header value into the forwarding table that determines the output link interface is 2.
The router forwards the packet to the interface 2. The routing algorithm determines the values that
are inserted in the forwarding table. The routing algorithm can be centralized or decentralized.
Services Provided by the Network Layer
o Guaranteed delivery: This layer provides the service which guarantees that the packet will
arrive at its destination.
o Guaranteed delivery with bounded delay: This service guarantees that the packet will be
delivered within a specified host-to-host delay bound.
o In-Order packets: This service ensures that the packet arrives at the destination in the
order in which they are sent.
o Guaranteed max jitter: This service ensures that the amount of time taken between two
successive transmissions at the sender is equal to the time between their receipt at the
destination.
o Security services: The network layer provides security by using a session key between the
source and destination host. The network layer in the source host encrypts the payloads of
datagrams being sent to the destination host. The network layer in the destination host
would then decrypt the payload. In such a way, the network layer maintains the data
integrity and source authentication services.
Network Addressing
o Network Addressing is one of the major responsibilities of the network layer.
o Network addresses are always logical, i.e., software-based addresses.
o A host is also known as end system that has one link to the network. The boundary
between the host and link is known as an interface. Therefore, the host can have only one
interface.
o A router is different from the host in that it has two or more links that connect to it. When
a router forwards the datagram, then it forwards the packet to one of the links. The
boundary between the router and link is known as an interface, and the router can have
multiple interfaces, one for each of its links. Each interface is capable of sending and
receiving the IP packets, so IP requires each interface to have an address.
o Each IP address is 32 bits long, and they are represented in the form of "dot-decimal
notation" where each byte is written in the decimal form, and they are separated by the
period. An IP address would look like 193.32.216.9 where 193 represents the decimal
notation of first 8 bits of an address, 32 represents the decimal notation of second 8 bits
of an address.
o In the above figure, a router has three interfaces labeled as 1, 2 & 3 and each router
interface contains its own IP address.
o Each host contains its own interface and IP address.
o All the interfaces attached to the LAN 1 is having an IP address in the form of 223.1.1.xxx,
and the interfaces attached to the LAN 2 and LAN 3 have an IP address in the form of
223.1.2.xxx and 223.1.3.xxx respectively.
o Each IP address consists of two parts. The first part (first three bytes in IP address) specifies
the network and second part (last byte of an IP address) specifies the host in the network.
Classful Addressing
An IP address is 32-bit long. An IP address is divided into sub-classes:
o Class A
o Class B
o Class C
o Class D
o Class E
In the above diagram, we observe that each class have a specific range of IP addresses. The class of
IP address is used to determine the number of bits used in a class and number of networks and
hosts available in the class.
Class A
In Class A, an IP address is assigned to those networks that contain a large number of hosts.
In Class A, the first bit in higher order bits of the first octet is always set to 0 and the remaining 7
bits determine the network ID. The 24 bits determine the host ID in any network.
Class B
In Class B, an IP address is assigned to those networks that range from small-sized to large-sized
networks.
In Class B, the higher order bits of the first octet is always set to 10, and the remaining14 bits
determine the network ID. The other 16 bits determine the Host ID.
Class C
In Class C, the higher order bits of the first octet is always set to 110, and the remaining 21 bits
determine the network ID. The 8 bits of the host ID determine the host in a network.
Class D
In Class D, an IP address is reserved for multicast addresses. It does not possess subnetting. The
higher order bits of the first octet is always set to 1110, and the remaining bits determines the host
ID in any network.
Class E
In Class E, an IP address is used for the future use or for the research and development purposes. It
does not possess any subnetting. The higher order bits of the first octet is always set to 1111, and
the remaining bits determines the host ID in any network.
A 0 8 24 27 224 0.0.0.0 to
127.255.255.255
Routing
o A Router is a process of selecting path along which the data can be transferred from
source to the destination. Routing is performed by a special device known as a router.
o A Router works at the network layer in the OSI model and internet layer in TCP/IP model
o A router is a networking device that forwards the packet based on the information
available in the packet header and forwarding table.
o The routing algorithms are used for routing the packets. The routing algorithm is nothing
but a software responsible for deciding the optimal path through which packet can be
transmitted.
o The routing protocols use the metric to determine the best path for the packet delivery.
The metric is the standard of measurement such as hop count, bandwidth, delay, current
load on the path, etc. used by the routing algorithm to determine the optimal path to the
destination.
o The routing algorithm initializes and maintains the routing table for the process of path
determination.
Metrics are the network variables used to determine the best route to the destination. For some
protocols use the static metrics means that their value cannot be changed and for some other
routing protocols use the dynamic metrics means that their value can be assigned by the system
administrator.
o Hop count: Hop count is defined as a metric that specifies the number of passes through
internetworking devices such as a router, a packet must travel in a route to move from
source to the destination. If the routing protocol considers the hop as a primary metric
value, then the path with the least hop count will be considered as the best path to move
from source to the destination.
o Delay: It is a time taken by the router to process, queue and transmit a datagram to an
interface. The protocols use this metric to determine the delay values for all the links along
the path end-to-end. The path having the lowest delay value will be considered as the
best path.
o Bandwidth: The capacity of the link is known as a bandwidth of the link. The bandwidth is
measured in terms of bits per second. The link that has a higher transfer rate like gigabit is
preferred over the link that has the lower capacity like 56 kb. The protocol will determine
the bandwidth capacity for all the links along the path, and the overall higher bandwidth
will be considered as the best route.
o Load: Load refers to the degree to which the network resource such as a router or
network link is busy. A Load can be calculated in a variety of ways such as CPU utilization,
packets processed per second. If the traffic increases, then the load value will also be
increased. The load value changes with respect to the change in the traffic.
o Reliability: Reliability is a metric factor may be composed of a fixed value. It depends on
the network links, and its value is measured dynamically. Some networks go down more
often than others. After network failure, some network links repaired more easily than
other network links. Any reliability factor can be considered for the assignment of
reliability ratings, which are generally numeric values assigned by the system
administrator.
Types of Routing
Routing can be classified into three categories:
o Static Routing
o Default Routing
o Dynamic Routing
Static Routing
o No Overhead: It has ho overhead on the CPU usage of the router. Therefore, the cheaper
router can be used to obtain static routing.
o Bandwidth: It has not bandwidth usage between the routers.
o Security: It provides security as the system administrator is allowed only to have control
over the routing to a particular network.
o For a large network, it becomes a very difficult task to add each route manually to the
routing table.
o The system administrator should have a good knowledge of a topology as he has to add
each route manually.
Default Routing
o Default Routing is a technique in which a router is configured to send all the packets to
the same hop device, and it doesn't matter whether it belongs to a particular network or
not. A Packet is transmitted to the device for which it is configured in default routing.
o Default Routing is used when networks deal with the single exit point.
o It is also useful when the bulk of transmission networks have to transmit the data to the
same hp device.
o When a specific route is mentioned in the routing table, the router will choose the specific
route rather than the default route. The default route is chosen only when a specific route
is not mentioned in the routing table.
Dynamic Routing
o All the routers must have the same dynamic routing protocol in order to exchange the
routes.
o If the router discovers any change in the condition or topology, then router broadcast this
information to all other routers.
Advantages of Dynamic Routing:
o It is easier to configure.
o It is more effective in selecting the best route in response to the changes in the condition
or topology.
ARP
Note: MAC address: The MAC address is used to identify the actual device.
IP address: It is an address used to locate a device on the network.
o The device will first look at its internet list, called the ARP cache to check whether an IP
address contains a matching MAC address or not. It will check the ARP cache in command
prompt by using a command arp-a.
o If ARP cache is empty, then device broadcast the message to the entire network asking
each device for a matching MAC address.
o The device that has the matching IP address will then respond back to the sender with its
MAC address
o Once the MAC address is received by the device, then the communication can take place
between two devices.
o If the device receives the MAC address, then the MAC address gets stored in the ARP
cache. We can check the ARP cache in command prompt by using a command arp -a.
In the above screenshot, we observe the association of IP address to the MAC address.
o Dynamic entry: It is an entry which is created automatically when the sender broadcast its
message to the entire network. Dynamic entries are not permanent, and they are removed
periodically.
o Static entry: It is an entry where someone manually enters the IP to MAC address
association by using the ARP command utility.
RARP
Error Reporting
ICMP protocol reports the error messages to the sender.
o Destination unreachable
o Source Quench
o Time Exceeded
o Parameter problems
o Redirection
There are two ways when Time Exceeded message can be generated:
Sometimes packet discarded due to some bad routing implementation, and this causes the
looping issue and network congestion. Due to the looping issue, the value of TTL keeps on
decrementing, and when it reaches zero, the router discards the datagram. However, when the
datagram is discarded by the router, the time exceeded message will be sent by the router to the
source host.
When destination host does not receive all the fragments in a certain time limit, then the received
fragments are also discarded, and the destination host sends time Exceeded message to the source
host.
o Parameter problems: When a router or host discovers any missing value in the IP
datagram, the router discards the datagram, and the "parameter problem" message is sent
back to the source host.
o Redirection: Redirection message is generated when host consists of a small routing
table. When the host consists of a limited number of entries due to which it sends the
datagram to a wrong router. The router that receives a datagram will forward a datagram
to a correct router and also sends the "Redirection message" to the host to update its
routing table.
IGMP
o The IGMP protocol is used by the hosts and router to support multicasting.
o The IGMP protocol is used by the hosts and router to identify the hosts in a LAN that are
the members of a group.
o IGMP is a part of the IP layer, and IGMP has a fixed-size message.
o The IGMP message is encapsulated within an IP datagram.
Where,
Type: It determines the type of IGMP message. There are three types of IGMP message:
Membership Query, Membership Report and Leave Report.
Maximum Response Time: This field is used only by the Membership Query message. It
determines the maximum time the host can send the Membership Report message in response to
the Membership Query message.
Checksum: It determines the entire payload of the IP datagram in which IGMP message is
encapsulated.
Group Address: The behavior of this field depends on the type of the message sent.
o For Membership Query, the group address is set to zero for General Query and set to
multicast group address for a specific query.
o For Membership Report, the group address is set to the multicast group address.
o For Leave Group, it is set to the multicast group address.
IGMP Messages
o This message is sent by a router to all hosts on a local area network to determine
the set of all the multicast groups that have been joined by the host.
o It also determines whether a specific multicast group has been joined by the
hosts on a attached interface.
o The group address in the query is zero since the router expects one response
from a host for every group that contains one or more members on that host.
o The host responds to the membership query message with a membership report
message.
o Membership report messages can also be generated by the host when a host
wants to join the multicast group without waiting for a membership query
message from the router.
o Membership report messages are received by a router as well as all the hosts on
an attached interface.
o Each membership report message includes the multicast address of a single
group that the host wants to join.
o IGMP protocol does not care which host has joined the group or how many hosts
are present in a single group. It only cares whether one or more attached hosts
belong to a single multicast group.
o The membership Query message sent by a router also includes a "Maximum
Response time". After receiving a membership query message and before
sending the membership report message, the host waits for the random amount
of time from 0 to the maximum response time. If a host observes that some other
attached host has sent the "Maximum Report message", then it discards its
"Maximum Report message" as it knows that the attached router already knows
that one or more hosts have joined a single multicast group. This process is
known as feedback suppression. It provides the performance optimization, thus
avoiding the unnecessary transmission of a "Membership Report message".
o Leave Report
When the host does not send the "Membership Report message", it means that the host
has left the group. The host knows that there are no members in the group, so even when
it receives the next query, it would not report the group.
Routing algorithm
o In order to transfer the packets from source to the destination, the network layer must
determine the best route through which packets can be transmitted.
o Whether the network layer provides datagram service or virtual circuit service, the main
job of the network layer is to provide the best route. The routing protocol provides this
job.
o The routing protocol is a routing algorithm that provides the best path from the source to
the destination. The best path is the path that has the "least-cost path" from source to the
destination.
o Routing is the process of forwarding the packets from source to the destination but the
best route to send the packets is determined by the routing algorithm.
Flooding: In case of flooding, every incoming packet is sent to all the outgoing links except the
one from it has been reached. The disadvantage of flooding is that node may contain several
copies of a particular packet.
Random walks: In case of random walks, a packet sent by the node to one of its neighbors
randomly. An advantage of using random walks is that it uses the alternative routes very efficiently.
What is congestion?
A state occurring in network layer when the message traffic is so heavy that it slows down
network response time.
Effects of Congestion
As delay increases, performance decreases.
If delay increases, retransmission occurs, making situation worse.
Imagine a bucket with a small hole in the bottom.No matter at what rate water enters the
bucket, the outflow is at constant rate.When the bucket is full with water additional water
entering spills over the sides and is lost.
Similarly, each network interface contains a leaky bucket and the following steps are
involved in leaky bucket algorithm:
1. When host wants to send packet, packet is thrown into the bucket.
2. The bucket leaks at a constant rate, meaning the network interface transmits packets at
a constant rate.
3. Bursty traffic is converted to a uniform traffic by the leaky bucket.
4. In practice the bucket is a finite queue that outputs at a finite rate.
Token bucket Algorithm
The leaky bucket algorithm has a rigid output design at an average rate independent of
the bursty traffic.
In some applications, when large bursts arrive, the output is allowed to speed up. This
calls for a more flexible algorithm, preferably one that never loses information.
Therefore, a token bucket algorithm finds its uses in network traffic shaping or rate-
limiting.
It is a control algorithm that indicates when traffic should be sent. This order comes
based on the display of tokens in the bucket.
The bucket contains tokens. Each of the tokens defines a packet of predetermined size.
Tokens in the bucket are deleted for the ability to share a packet.
When tokens are shown, a flow to transmit traffic appears in the display of tokens.
No token means no flow sends its packets. Hence, a flow transfers traffic up to its peak
burst rate in good tokens in the bucket.
The leaky bucket algorithm enforces output pattern at the average rate, no matter how
bursty the traffic is. So in order to deal with the bursty traffic we need a flexible algorithm so
that the data is not lost. One such algorithm is token bucket algorithm.
Steps of this algorithm can be described as follows:
In figure (A) we see a bucket holding three tokens, with five packets waiting to be
transmitted. For a packet to be transmitted, it must capture and destroy one token. In figure
(B) We see that three of the five packets have gotten through, but the other two are stuck
waiting for more tokens to be generated.
Ways in which token bucket is superior to leaky bucket: The leaky bucket algorithm
controls the rate at which the packets are introduced in the network, but it is very
conservative in nature. Some flexibility is introduced in the token bucket algorithm. In the
token bucket, algorithm tokens are generated at each tick (up to a certain limit). For an
incoming packet to be transmitted, it must capture a token and the transmission takes place
at the same rate. Hence some of the busty packets are transmitted at the same rate if
tokens are available and thus introduces some amount of flexibility in the system.
IPv4 vs IPv6
What is IP?
An IP stands for internet protocol. An IP address is assigned to each device connected to a
network. Each device uses an IP address for communication. It also behaves as an identifier as this
address is used to identify the device on a network. It defines the technical format of the packets.
Mainly, both the networks, i.e., IP and TCP, are combined together, so together, they are referred to
as a TCP/IP. It creates a virtual connection between the source and the destination.
We can also define an IP address as a numeric address assigned to each device on a network. An IP
address is assigned to each device so that the device on a network can be identified uniquely. To
facilitate the routing of packets, TCP/IP protocol uses a 32-bit logical address known as
IPv4(Internet Protocol version 4).
An IP address consists of two parts, i.e., the first one is a network address, and the other one is a
host address.
o IPv4
o IPv6
What is IPv4?
IPv4 is a version 4 of IP. It is a current version and the most commonly used IP address. It is a 32-bit
address written in four numbers separated by 'dot', i.e., periods. This address is unique for each
device.
The above example represents the IP address in which each group of numbers separated by
periods is called an Octet. Each number in an octet is in the range from 0-255. This address can
produce 4,294,967,296 possible unique addresses.
In today's computer network world, computers do not understand the IP addresses in the standard
numeric format as the computers understand the numbers in binary form only. The binary number
can be either 1 or 0. The IPv4 consists of four sets, and these sets represent the octet. The bits in
each octet represent a number.
Each bit in an octet can be either 1 or 0. If the bit the 1, then the number it represents will count,
and if the bit is 0, then the number it represents does not count.
Now, we will see how to obtain the binary representation of the above IP address, i.e., 66.94.29.13
To obtain 94, we put 1 under 64, 16, 8, 4, and 2 as the sum of these numbers is equal to 94, and
the remaining bits will be zero. Therefore, the binary bit version of 94 is 01011110.
To obtain 29, we put 1 under 16, 8, 4, and 1 as the sum of these numbers is equal to 29, and the
remaining bits will be zero. Therefore, the binary bit version of 29 is 00011101.
To obtain 13, we put 1 under 8, 4, and 1 as the sum of these numbers is equal to 13, and the
remaining bits will be zero. Therefore, the binary bit version of 13 is 00001101.
Drawback of IPv4
Currently, the population of the world is 7.6 billion. Every user is having more than one device
connected with the internet, and private companies also rely on the internet. As we know that IPv4
produces 4 billion addresses, which are not enough for each device connected to the internet on a
planet. Although the various techniques were invented, such as variable- length mask, network
address translation, port address translation, classes, inter-domain translation, to conserve the
bandwidth of IP address and slow down the depletion of an IP address. In these techniques, public
IP is converted into a private IP due to which the user having public IP can also use the internet.
But still, this was not so efficient, so it gave rise to the development of the next generation of IP
addresses, i.e., IPv6.
What is IPv6?
IPv4 produces 4 billion addresses, and the developers think that these addresses are enough, but
they were wrong. IPv6 is the next generation of IP addresses. The main difference between IPv4
and IPv6 is the address size of IP addresses. The IPv4 is a 32-bit address, whereas IPv6 is a 128-bit
hexadecimal address. IPv6 provides a large address space, and it contains a simple header as
compared to IPv4.
It provides transition strategies that convert IPv4 into IPv6, and these strategies are as follows:
o Dual stacking: It allows us to have both the versions, i.e., IPv4 and IPv6, on the same
device.
o Tunneling: In this approach, all the users have IPv6 communicates with an IPv4 network
to reach IPv6.
o Network Address Translation: The translation allows the communication between the
hosts having a different version of IP.
This hexadecimal address contains both numbers and alphabets. Due to the usage of both the
numbers and alphabets, IPv6 is capable of producing over 340 undecillion (3.4*10 38) addresses.
IPv6 is a 128-bit hexadecimal address made up of 8 sets of 16 bits each, and these 8 sets are
separated by a colon. In IPv6, each hexadecimal character represents 4 bits. So, we need to convert
4 bits to a hexadecimal number at a time
Address format
The above diagram shows the address format of IPv4 and IPv6. An IPv4 is a 32-bit decimal address.
It contains 4 octets or fields separated by 'dot', and each field is 8-bit in size. The number that each
field contains should be in the range of 0-255. Whereas an IPv6 is a 128-bit hexadecimal address. It
contains 8 fields separated by a colon, and each field is 16-bit in size.
Differences between IPv4 and IPv6
Ipv4 Ipv6
In the network layer of the OSI model or the Internet Protocol Suite (TCP/IP), point-
to-point networks can be implemented using various technologies and protocols.
Here's how point-to-point communication works at the network layer:
.
Addressing: Each node in a point-to-point network is typically assigned a unique
network layer address. In the context of IP networks, this is often an IP address. These
addresses are used to identify the source and destination of data packets as they
traverse the network.
.
.
Routing: In a point-to-point network, routing decisions are relatively straightforward
since there are only two nodes involved. Typically, a routing table or routing protocol
is used to determine the path that packets should take from the source node to the
destination node. In many cases, this path consists of a single link or hop.
.
.
Encapsulation: When a node in a point-to-point network sends a data packet to
another node, the packet is encapsulated with appropriate network layer headers.
These headers include information such as the source and destination addresses, as
well as any other necessary control information.
.
.
Transmission: The encapsulated packet is then transmitted over the physical link
connecting the two nodes. This could be a wired connection, such as a point-to-point
leased line, or a wireless connection, such as a point-to-point microwave link.
.
.
Decapsulation: When the packet reaches the destination node, it is decapsulated,
meaning that the network layer headers are removed. The node then processes the
packet based on the information contained within.
.
Point-to-Point Protocol (PPP): A data link protocol used to establish a direct connection between two
nodes over various physical media, such as serial cables, DSL lines, or dial-up connections.
Point-to-Point Protocol over Ethernet (PPPoE): A network protocol used to encapsulate PPP frames
within Ethernet frames, commonly used in DSL connections.
Virtual Private Networks (VPNs): VPNs can be implemented as point-to-point connections between
two network nodes, typically using tunneling protocols like IPsec or SSL/TLS to create secure
communication channels over public networks.