Unit IV - Network Layer
Unit IV - Network Layer
Network layer is the third layer in the OSI model of computer networks. It’s main function is to transfer network
packets from the source to the destination. It is involved both at 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 deliver the packet to the
data link layer so that it can further be sent to the receiver. At the destination, the datagram is decapsulated, the
packet is extracted and delivered to the corresponding transport layer.
Features :
Main responsibility of Network layer is to carry the data packets from the source to the destination without
changing or using it.
If the packets are too large for delivery, they are fragmented i.e., broken down into smaller packets.
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 as routing).
The source and destination addresses are added to the data packets inside the network layer.
The services which are offered by the network layer protocol are as follows:
Packetizing –
The process of encapsulating the data received from upper layers of the network(also called as 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.
Network address – It identifies a network on internet. Using this, we can find range of addresses in the network and
total possible number of hosts in the network.
Mask – It is a 32-bit binary number that gives the network address in the address block when AND operation is
bitwise applied on the mask and any IP address of the block.
Class A – 255.0.0.0
Class B – 255.255.0.0
Class C – 255.255.255.0
Example : Given IP address 132.6.17.85 and default class B mask, find the beginning address (network address).
Solution : The default mask is 255.255.0.0, which means that the only the first 2 bytes are preserved and the other 2
bytes are set to 0. Therefore, the network address is 132.6.0.0.
Subnetting: Dividing a large block of addresses into several contiguous sub-blocks and assigning these sub-blocks to
different smaller networks is called subnetting. It is a practice that is widely used when classless addressing is done.
Classless Addressing
To reduce the wastage of IP addresses in a block, we use sub-netting. What we do is that we use host id bits as net id
bits of a classful IP address. We give the IP address and define the number of bits for mask along with it (usually
followed by a ‘/’ symbol), like, 192.168.1.1/28. Here, subnet mask is found by putting the given number of bits out of
32 as 1, like, in the given address, we need to put 28 out of 32 bits as 1 and the rest as 0, and so, the subnet mask
would be 255.255.255.240.
Classful Address
The first addressing system to be implemented as part of the Internet Protocol was Classful Addressing. In the year
1981, the Classful addressing network architecture was first used on the Internet. The Classful addressing system was
superseded by a Classless addressing scheme with the introduction of Classless Inter-Domain Routing (CIDR) in
1993.
The IP address comprises up of 32 bits and is split into four sections separated by dots: part 1, part 2, part 3, and
part 4.
The IP address is made up of four parts, each of which is eight bits long (1 byte).
Further, the 4 parts of the IP address is divided into parts: a network ID and a Host ID.
Types of Classful Address
Class A, Class B, Class C, Class D, and Class E are the five varieties of Classful addresses. In IPv4, this
classification is known as Classful addressing or IP address classes.
The first three classes, Class A, B, and C, are used for "public addressing", in which communication is always one-to-
one between source and destination. It implies that when data is transmitted from a source, it will only be sent to a
single network host.
The reserved categories include Class D and Class E, with Class D being utilized for multicast and Class E being
saved for future usage exclusively.
In IPv4, the Network ID is the first part of Class A, B, and C, while the Host ID is the remaining second portion.
The Host ID always indicates the number of hosts or nodes in a certain network, whereas the Network ID always
identifies the network in a specific place.
In Class A, B, and C, the address space is split into a certain number of IP address blocks. It also specifies the
maximum number of hosts in a network.
Network and Host part in Classful Addressing
The first octet or byte of an IP address is part of the network ID (short for Net-ID), while the next three octets or three
bytes are part of the host ID in Class A. (in short, host-ID).
The network ID takes up the first two octets or two bytes in Class B, whereas the host ID takes up the remaining two
octets or two bytes.
In Class C, the first three octets or bytes are dedicated to the network ID, while the last octet or byte is dedicated to the
host ID.
Classless Addressing
Classless Inter-Domain Routing (CIDR) is another name for classless addressing. This addressing type aids in the
more efficient allocation of IP addresses. This technique assigns a block of IP addresses based on specified conditions
when the user demands a specific amount of IP addresses. This block is known as a "CIDR block", and it contains the
necessary number of IP addresses.
When allocating a block, classless addressing is concerned with the following three rules.
Rule 1 − The CIDR block's IP addresses must all be contiguous.
Rule 2 − The block size must be a power of two to be attractive. Furthermore, the block's size is equal to the number
of IP addresses in the block.
Rule 3 − The block's first IP address must be divisible by the block size.
For example, assume the classless address is 192.168.1.35/27.
The network component has a bit count of 27, whereas the host portion has a bit count of 5. (32-27)
The binary representation of the address is: (00100011 . 11000000 . 10101000 . 00000001).
(11000000.10101000.00000001.00100000) is the first IP address (assigns 0 to all host bits), that is, 192.168.1.32
(11000000.10101000.00000001.00111111) is the most recent IP address (assigns 1 to all host bits), that is,
192.168.1.63
The IP address range is 192.168.1.32 to 192.168.1.63.
Difference Between Classful and Classless Addressing
Classful addressing is a technique of allocating IP addresses that divides them into five categories. Classless
addressing is a technique of allocating IP addresses that is intended to replace classful addressing in order to reduce IP
address depletion.
The utility of classful and classless addressing is another distinction. Addressing without a class is more practical and
helpful than addressing with a class.
The network ID and host ID change based on the classes in classful addressing. In classless addressing, however, there
is no distinction between network ID and host ID. As a result, another distinction between classful and classless
addressing may be made.
Supernetting:
Supernetting is the procedure to combine the small networks into larger space. In subnetting, Network addresses’s
bits are increased. on the other hand, in supernetting, Host addresses’s bits are increased. Subnetting is implemented
via Variable-length subnet masking, While supernetting is implemented via Classless interdomain routing.
VLSM
VLSM stands for Variable Length Subnet Mask where the subnet design uses more than one mask in the same
network which means more than one mask is used for different subnets of a single class A, B, C or a network. It is
used to increase the usability of subnets as they can be of variable size. It is also defined as the process of subnetting
of a subnet.
If the administrator has IP 192.168.1.0/24, department wise IPs can be allocated by following these steps:
For each segment select the block size that is greater than or equal to the actual requirement which is the sum of host
addresses, broadcast addresses and network addresses. Make a list of subnets possible:
The highest IP available has to be allocated to highest requirement it gets 192.168.1.0/25 which has 126 valid
addresses that can easily be available for 120 hosts. The subnet mask used is 255.255.255.128
The next segment requires an IP to handle 50 hosts. The IP subnet with network number 192.168.1.128/26 is the next
highest which can be assigned to 62 hosts thus fulfilling the requirement of development department. The subnet mask
used is 255.255.255.192
Similarly the next IP subnet 192.168.1.192/27 can fulfill the requirements of the accounts department as it has 30 valid
hosts IP which can be assigned to 26 computers. The mask used is 255.255.255.224
The last segment requires 5 valid hosts IP which can be fulfilled by the subnet 192.168.1.224/29 which has the mask
as 255.255.255.248 is chosen as per the requirement. The IP with the mask 255.255.255.240 could be chosen but it has
14 valid host IPs and the requirement is less in comparison so the one that is comparable with the requirement is
chosen.
NAT
To access the Internet, one public IP address is needed, but we can use a private IP address in our private network.
The idea of NAT is to allow multiple devices to access the Internet through a single public address. To achieve this,
the translation of a private IP address to a public IP address is required. Network Address Translation (NAT) is a
process in which one or more local IP address is translated into one or more Global IP address and vice versa in
order to provide Internet access to the local hosts. Also, it does the translation of port numbers i.e. masks the port
number of the host with another port number, in the packet that will be routed to the destination. It then makes the
corresponding entries of IP address and port number in the NAT table. NAT generally operates on a router or
firewall.
Network Address Translation (NAT) working –
Generally, the border router is configured for NAT i.e the router which has one interface in the local (inside)
network and one interface in the global (outside) network. When a packet traverse outside the local (inside)
network, then NAT converts that local (private) IP address to a global (public) IP address. When a packet enters the
local network, the global (public) IP address is converted to a local (private) IP address.
If NAT runs out of addresses, i.e., no address is left in the pool configured then the packets will be dropped and an
Internet Control Message Protocol (ICMP) host unreachable packet to the destination is sent.
Introduction to ICMP, ARP, RARP IPv6 (IPv6 Datagram format, comparison with IPv4, and transition from IPv4
toIPv6).
The ICMP stands for Internet Control Message Protocol. It is a network layer protocol. It is used for error handling in
the network layer, and it is primarily used on network devices such as routers. As different types of errors can exist in
the network layer, so ICMP can be used to report these errors and to debug those errors.
For example, some sender wants to send the message to some destination, but the router couldn't send the message to
the destination. In this case, the router sends the message to the sender that I could not send the message to that
destination.
The IP protocol does not have any error-reporting or error-correcting mechanism, so it uses a message to convey the
information. For example, if someone sends the message to the destination, the message is somehow stolen between
the sender and the destination. If no one reports the error, then the sender might think that the message has reached the
destination. If someone in-between reports the error, then the sender will resend the message very quickly.
ARP stands for Address Resolution Protocol, which is used to find the MAC address of the device from its known IP
address. This means, the source device already knows the IP address but not the MAC address of the destination
device. The MAC address of the device is required because you cannot communicate with a device in a local area
network (Ethernet) without knowing its MAC address. So, the Address Resolution Protocol helps to obtain the MAC
address of the destination device.
he purpose of ARP is to convert the 32-bit logical address (IPv4 address) to the 48-bit physical address (MAC
address). This protocol works between layer 2 and layer 3 of the OSI model. The MAC address resides at layer 2,
which is also known as the data link layer and IP address resides at layer 3, this layer is also known as the network
layer.
RARP stands for Reverse Address Resolution Protocol. If the host wants to know its IP address, then it broadcast
the RARP query packet that contains its physical address to the entire network. A RARP server on the network
recognizes the RARP packet and responds back with the host IP address. The protocol which is used to obtain the IP
address from a server is known as Reverse Address Resolution Protocol. The message format of the RARP protocol
is similar to the ARP protocol. Like ARP frame, RARP frame is sent from one machine to another encapsulated in the
data portion of a frame.
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).
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.
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.
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:
Dual stacking: It allows us to have both the versions, i.e., IPv4 and IPv6, on the same device.
Tunneling: In this approach, all the users have IPv6 communicates with an IPv4 network to reach IPv6.
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*1038) 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