3rd - Unit - CN (1) - Master - Copy - 240412 - 140654
3rd - Unit - CN (1) - Master - Copy - 240412 - 140654
3rd - Unit - CN (1) - Master - Copy - 240412 - 140654
Unit-03
Network Layer
Syllabus: Point to point networks, logical addressing,
basic internetworking (IP, CIDR, ARP, RARP, DHCP,
ICMP), Routing, forwarding and delivery, static and
dynamic routing, routing algorithms and protocols,
congestion control algorithm, ipv6.
IPv4 addresses:
An IPv4 address is a 32-bit address that uniquely and universally defines the
connection of a device (for example, a computer or a router) to the
Internet.
IPv4 addresses are unique. They are unique in the sense that each address
defines one, and only one, connection to the Internet. Two devices on the
Internet can never have the same address at the same time. But by using
some strategies, an address may be assigned to a device for a time period
and then taken away and assigned to another device.
Address Space
A protocol such as IPv4 that defines addresses has an address space.
IPv4 uses 32-bit addresses, which means that the address space is 232 or
4,294,967,296 (more than 4 billion).
IPv4 Address Notations
a. Binary Notation
In binary notation, the IPv4 address is displayed as 32 bits. Each octet is
often referred to as a byte. So, it is common to hear an IPv4 address
referred to as a 32-bit address or a 4-byte address. The following is an
example of an IPv4 address in binary notation:
b. Dotted-Decimal Notation
To make the IPv4 address more compact and easier to read, Internet
addresses are usually written in decimal form with a decimal point (dot)
separating the bytes. The following is the dotted decimal notation of the
above address:
117.149.29.2
Example 1
We replace each group of 8 bits with its equivalent decimal number and add
dots for separation.
a. 129.11.11.239
b. 193.131.27.255
Example 2
Change the following IPv4 addresses from dotted-decimal notation to binary notation.
a. 111.56.45.78
b. 221.34.7.82
Solution
Classful Addressing
Classless Addressing
Classful Addressing
IPv4 addressing, at its inception, used the concept of classes. This architecture
is called classful addressing. A few important points about classful addressing
are given below:
If the address is given in binary notation, the first few bits can immediately tell
us the class of the address.
If the address is given in decimal-dotted notation, the first byte defines the
class.
Example 3
Solution
Fig 1.1 Shows number of blocks and block size for each class
Class A addresses were designed for large organizations with a large number
of attached hosts or routers.
Class C addresses were designed for small organizations with a small number
of attached hosts or routers.
Limitations of Classful Addressing
Ablock in class A address is too large for almost any organization. This means
most of the addresses in class A were wasted and were not used.
A block in class B is also very large, probably too large for many of the
organizations that received a class B block.
Class D addresses were designed for multicasting. Each address in this class is
used to define one group of hosts on the Internet. The Internet authorities
wrongly predicted a need for 268,435,456 groups. This never happened and
many addresses were wasted here too.
And lastly, the class E addresses were reserved for future use; only a few were
used, resulting in another waste of addresses.
These parts are of varying lengths, depending on the class of the address.
Below figure shows some netid and hostid bytes.
The netid is in color, the hostid is in white. Note that the concept does not
apply to classes D and E.
In class A, one byte defines the netid and three bytes define the hostid.
In class B, two bytes define the netid and two bytes define the hostid.
In class C, three bytes define the netid and one byte defines the hostid.
Mask
A mask (also called the subnet mask) is a 32-bit number made of contiguous 1s
followed by contiguous 0s. The masks for classes A, B, and C are shown in the
above table. This concept does not apply to classes D and E.
The mask can help us to find the netid and the hostid. For example, the mask
(default subnet mask) for a class A address has eight 1s, which means the first 8
bits of any address in class A define the netid; the next 24 bits define the hostid.
The last column of the above table shows the mask in the form /n where n
can be 8, 16, or 24 in classful addressing.
One solution that has alleviated the problem is the idea of classless addressing.
Classless Addressing
To overcome address depletion (exhaustion) and give more organizations access
to the Internet, classless addressing was designed and implemented. In this
scheme, there are no classes, but the addresses are still granted in blocks.
Address Blocks
The size of the block (the number of addresses) varies based on the nature and
size of the entity. For example, a household may be given only two usable
addresses; a large organization may be given thousands of addresses. An ISP, as
the Internet service provider, may be given thousands or hundreds of thousands
based on the number of customers it may serve.
Example 4
However, in classless addressing the mask for a block can take any value from
0 to 32. It is very convenient to give just the value of n preceded by a slash (CIDR
notation).
The address and the /n notation completely define the whole block (the first
address, the last address, and the number of addresses).
First Address: The first address in the block can be found by setting the 32 - n
rightmost bits in the binary notation of the address to 0s.
Last Address: The last address in the block can be found by setting the 32 - n
rightmost bits in the binary notation of the address to 1s.
Example 5
A block of addresses is granted to a small organization. We know that one of the
addresses is 205.16.37.39/28. What are the first and last addresses in the block?
The binary representation of the given address is 11001101 00010000 00100101 00100111.
First Address: The first address in the block can be found by setting the 32 - n
rightmost bits in the binary notation of the address to 0s.
11001101.00010000.00100101. 00100000
Last Address: The last address in the block can be found by setting the 32 - n
rightmost bits in the binary notation of the address to 1s.
11001101.00010000.00100101. 00101111
Class A addresses:
The first bit of a Class A address is always 0, and the next 7 bits
represent the network ID. The remaining 24 bits are used for the host
ID. This means that Class A addresses can support up to 126 different
networks and 16,777,214 hosts per network. The default subnet mask
for Class A networks is 255.0.0.0.
Class B addresses:
The first two bits of a Class B address are always 10, and the next 14
bits represent the network ID. The remaining 16 bits are used for the
host ID. This means that Class B addresses can support up to 16,384
different networks and 65,534 hosts per network. The default subnet
mask for Class B networks is 255.255.0.0.
Class C addresses:
The first three bits of a Class C address are always 110, and the next
21 bits represent the network ID. The remaining 8 bits are used for the
host ID. This means that Class C addresses can support up to 2,097,152
different networks and 254 hosts per network. The default subnet
mask for Class C networks is 255.255.255.0.
Class D addresses:
Class D addresses are used for multicast addresses, which means they
are used to send a message to multiple devices on a network. The first
four bits of a Class D address are always 1110.
Class E addresses:
Class E addresses are reserved for future use and are not currently
used for public networks. The first four bits of a Class E address are
always 1111.
Network Addresses
A very important concept in IP addressing is the network address. When an
organization is given a block of addresses, the organization is free to allocate the
addresses to the devices that need to be connected to the Internet.
The first address in the class, however, is normally (not always) treated as a
special address. The first address is called the network address and defines the
organization network.
It defines the organization itself to the rest of the world. Usually the first
address is the one that is used by routers to direct the message sent to the
organization from the outside.
Internetworking
Introduction
Computer networks refer to interconnected computing devices that
can exchange data with each other. The practice of creating,
maintaining, securing, and troubleshooting the network is called
computer networking. The compound word internetworking is made
of two different words, inter and networking, which implies
networking between two or more different networks. We need
routers or gateways to connect two different networks. The IPv4 is the
delivery mechanism used by the TCP/IP protocols. It is an unreliable
(no acknowledgement after delivering the packet.) and
connectionless (because IPv4 uses datagram approach of packet-
switching network, which does not reserve resources at routers)
datagram protocol. If reliability is important, IPv4 must be paired with
a reliable protocol such as TCP. Packets in the IPv4 layer (L3 of OSI
model) are called datagram, which contains information essential to
routing and delivery.
IPv4 Datagram Header Format
From top
First row:
1. VER (4 bits)
It defines the version of IP. Currently the version is 4 (IPv4).
4 in binary = 0100 [ The first 4 bits of all IPv4 packet must contain
0100.]
2. HLEN(4 bits)
It defines the total length of header. Using 4 bits, we can manage
any size of the header ranging from 20 to 60 bytes.
Example 6
3. Service type (8 bits) [ The name of this field has been renamed
by IETF. Now, it’s called Differentiated Services Code Point
(DSCP) and has different interpretation.]
The first 3 bits are called precedence bits used to define priority
of the datagram in issues such as congestion. This field has never
been used.
101 - CRITIC/ECP
011 - Flash
010 - Immediate
001 - Priority
000 - Routine
The next 3 bits are type of service (TOS):
Example 7
In an IPv4 packet, the value of HLEN is 5, and the value of the
total length field is 0x0028. How many bytes of data are being
carried by this packet?
Solution
The HLEN value is 5, which means the total number of bytes in
the header is 5 x 4 = 20 bytes. The total length is 40 bytes (
decima equivalent of 0x0028) , which means the packet is
carrying 20 bytes of data (40-20).
Second row [This row is used for fragmentation only.]:
Third row:
1. TTL ( 8 bits)
This field is used to control the maximum number of hops(routers)
visited by the datagram. Each router that processes the datagram,
decrements this number by 1. It means TTL field limits the lifetime
of a datagram.
2. Protocols (8 bits)
Used to define the higher-level protocols such as TCP,UDP, ICMP,
and IGMP.
3. Header checksum (16 bits)
Used to detect error.
Example 8
An IPv4 packet has arrived with the first few hexadecimal digits as
shown:
0x45000028000100000102…
How many hops can this packet travel before being dropped?
Solution:
0x = hexadecimal
To find the TTL filed, we skip 8 bytes ( 4 bytes of the first row + 4
bytes of the second row) because it is the first field in the third
row of the IP datagram. The TTL is the ninth byte, which is 01( hex
to binary[ (01)16= (00000001)2] = 1 in decimal). This means that the
packet can travel only one hope.
Fourth row and fifth row: Used to define source and destination IP
addresses.
Sixth row:
1. Options ( 0 to 40 bytes)
Options for diagnostic and testing purposes, such as providing a
way to measure packet delivery time or to trace the path of a
packet through the network.
Fragmentation
(Done at Routers)
If the application layer gives more than 65,495 bytes of data to the
transport layer, it’s the responsibility of the transport layer to divide it
into segments in such a way that one segment (65,515 bytes [
20(header)+ 65, 495]) should sit in at Network layer. But the problem
is that the data link layer can’t hold more than 1500 bytes of data in
the frame if underlying LAN is standard ethernet.
Sometimes, underlying LAN at data link layer is able to hold more than
what it gets from network layer if standard ethernet is not used.
Therefore, segmentation at transport layer is done very cleverly in
such a way that one segment should sit in at data link layer frame
without being fragmented at network layer in a LAN. It means that
fragmentation is not required in a LAN.
If a host in the first network wants to send a packet to all hosts present
in the second network having network address 40.0.0.0, then directed
broadcast address is 40. 255.255.255 [ network id part will be as it is +
all 1’s].
a. 255.255.255.255
b. 127.0.0.1
Solution:
Subnetting
Dividing a big network into two or more subnetworks is called
subnetting.
subnetting benefits:
Solution:
Note: Only hostid is used for subnetting.
netid= 24 bits
Subnet 1:
Note: Netid (24 bits) is constant.
0000010 =2
0000011 =3
.......
.......
0 1 1 1 1 1 1 1 =127
Subnet 2:
0000010 =130
0000011 =131
.......
.......
1 1 1 1 1 1 1 1 =255
Solution
Steps:
1. Borrow one bit from hostid to divide 256 addresses into two
parts.
2. Now divide the second part into two again using single bit
0000001 = 1
0000010 =2
0000011 =3
.......
.......
0 1 1 1 1 1 1 1 =127
Firs IP = 200.1.2.0 [ used as a network ID for the subnet-1]
0000001 = 129
0000010 =130
0000011 =131
.......
.......
10 1 1 1 1 1 1 =191
0000001 = 193
0000010 =194
0000011 =195
.......
.......
11 1 1 1 1 1 1 =255
n = mask (netid)
hostid = 32 – n
Solution:
We can use 7 bits (32-25) for subnetting. It means, we cannot change
even first bit from the last octet as that’s a part of network bits (25
bits, including first bit of the last octet).
As we have 7 bits in the hostid part, we can have 128 (27 ) addresses.
We need to divide it into two subnets having 64 addresses each.
Subnet -1
000001 = 1
000010 = 2
000011 = 3
......
......
00 1 1 1 1 1 1 =63
000001 = 65
000010 = 66
000011 = 67
......
......
01 1 1 1 1 1 1 =127
Example-12 ( VLSM)
Solution
Subnet-1
000001 = 1
000010 = 2
000011 = 3
......
......
00 1 1 1 1 1 1 =63
Subnet-02
00001 = 65
00010 = 66
00011 = 67
.....
.....
010 1 1 1 1 1 = 95
Subnet-03
00001 = 97
00010 = 98
00011 = 99
.....
.....
011 1 1 1 1 1 = 127
Example 13:
Design the subblock and give the slash notation for each
subblock.
Find out how many addresses are still available after these
allocations.
Solution:
The ISP has the first address 190. 100.0.0/16
Since, n= 16
Hostid= 32-16
Number of addresses = 232-16 = 65,536
[ In detail …]
First group
For this group, each customer needs 256 addresses. This means
that 8 bits are hostid (28 =256 addresses) and 24 bits are netid.
[The prefix length (netid)= 32 – 8 = 24]
Slash notation ( or CIDR notation) for this group is /24. [ 16+ 8 bits
from hostid part]
…………..
..………
Third group
For this group, each customer needs 64 addresses. This means
that 6 bits are hostid(26 =64).
The prefix length(netid/mask) = 26 (32-6)
……
Example 14
Note— Subnet mask ( 32 bits; all 1s followed by all 0s) = “1s” at the
place of Netid + subnetid and 0s at the place of hostid.
Since we have 11 bits for the host portion of the address, we can
calculate the number of hosts per subnet as follows:
2^11 - 2 = 2046
The "- 2" is because the first and last addresses in the subnet are
reserved for the network address and the directed broadcast
address respectively.
Therefore, the maximum number of hosts per subnet for this class B
network with a subnet mask of 255.255.248.0 is 2046.
IP address: 10110100.00011001.00010101.10101100
Performing the bitwise "AND" operation between the two gives us:
10110100.00011001.00000000.00000000
180.25.0.0
Therefore, the subnet address for the given IP address and subnet
mask is 180.25.0.0.
Example 16. An organization is granted the block 16.0.0.0/8. The
administrator wants to create 500 fixed-length subnets.
i. Find the subnet mask.
ii. Find the number of addresses in each subnet.
iii. Find the first and last addresses in subnet 1.
iv. Find the first and last addresses in subnet 500.
Solution
netid ( or blockid) = 8 bits
Subnet mask = netid (put all 1s here) + subnetid ( put all 1s here)
+ hostid ( put all 0s here)
00010000. 00000000. 0 - - - - - - -. - - - - - - - -
0000000. 00000000 [ starting from 0s ]
.
.
.
0 1111111. 11111111
As we have used all zeros at the place of subnetid part for the first
subnet, then for the second subnet it would be as follows:
0 0 0 0 0 0 0 0. 1
.
.
.
00010000. 11111001.1 - - - - - - -. - - - - - - - -
0000000. 00000000
……
1111111. 11111111
i. Number of hosts.
ii. Number of subnets in class A.
iii. Number of subnets in class B.
iv. Number of subnets in class C.
Netid Hostid
i. We know that all 1’s (contiguous) represents subnet mask,
and all 0’s (contiguous) represents host part.
Therefore, the number of hosts is 216 – 2.
ii. We know that the default subnet mask for the class A is
255.0.0.0, but in the given question 8 bits from the hostid
part is used for the subnetting. Therefore, the number of
subnets in the class A is 28.
iii. We know that the default subnet mask for the class B is
255.255.0.0, and the same is given in the question.
Therefore, only one subnet is possible which is by default.
iv. We know that the default subnet mask for the class C is
255.255.255.0, and given mask is 255.255.0.0. Therefore,
no subnet is possible.
Q. Mention valid IP addresses required in the below network.
Supernetting
Supernetting is a technique to combine several contiguous subnets
into one network. Supernetting reduces the number of entries in
routing tables, thereby improving routing efficiency and reducing the
size of routing tables in routers.
Subnet 1: 223.1.0.0/24
Subnet 2: 223.1.1.0/24
Subnet 3: 223.1.2.0/24
Subnet 4: 223.1.3.0/24
It is the 3rd layer protocol used by IPv4 devices within a local network to manage
membership in multicast groups. The primary purpose of IGMP is to allow hosts
to communicate their interest in receiving multicast traffic to nearby routers,
which can then forward multicast packets only to those segments of the
network where interested receivers reside.
Private IP addresses are defined in RFC 1918 and include the following
address ranges:
10.0.0.0 to 10.255.255.255 /8
NAT stands for network address translation. It’s a way to map multiple
local private addresses to a public IP address before transferring the
information. Organizations that want multiple devices to employ a
single public IP address use NAT, as do most home routers.
Fig. shows how NAT is used to map a private IP to public one
……………………………………………………………………………………
Delivery
The delivery of a packet to its destination is accomplished by using two
different methods of delivery, direct and indirect.
Direct delivery
It occurs when the source and destination of the packet are located
on the same network.
Indirect delivery
It occurs when the source and destination of the packet are located
on the different network.
Forwarding
Forwarding means to place the packet in its route to its destination. It
requires a host or a router to have a routing table. When a host has a
packet to send or when a router receives a packet to be forwarded, it
looks at this table (routing table) to find the route to the final
destination.
Forwarding techniques
1. RIP
2. OSPF
3. BGP
Routing Algorithms
1. Static (nonadaptive)
Static routing algorithm is a form of routing which occurs when a
router uses a manual configuration routing entry rather than dynamic
entry. Static algorithms cannot be used in the Internet having n
numbers of routers.
2. Dynamic (adaptive)
Dynamic algorithms, in contrast, change their routing decisions to
reflect changes in the topology, and usually the traffic as well. In the
Internet ( network of networks) , these algorithms are used by routing
protocols (RIP, OSPF, and BJP).
1 7 3
A 2 B
Step 2: Every node (router) shares its distance vector with its
immediate neighbors parallelly.
Step 3: Each node updates routing table parallelly after getting new
distance vectors from its immediate neighbors.
From B From D
2 1
0
7
3 11
7
0
IPv6 (IPng)
IPv6 addresses are 128-bit identifiers used to uniquely identify
interfaces and sets of interfaces on a network.
Examples:
2001:DB8:0:0: 8:800:200C:417A
may be represented as
2001:DB8::8:800:200C:417A a unicast address
Examples:
0:0:0: 0:0:0:13.1.68.3
or in compressed form:
::13.1.68.3
::FFFF:129.144.52.38
Note— The prefix length like IPv4 CIDR notation indicates the number
of bits in the address that are fixed and identifies the network portion
of the address.
ipv6-address/prefix-length
2001:0DB8:0000:CD30:0000:0000: 0000:0000/60
2001:0DB8:CD30: 0:0:0:0/60
2001:0DB8:0:CD30: :/60
The following are NOT legal representations of the above prefix:
2001:0DB8:0:CD3/60
Explanation: We may drop leading zeros only, but not trailing zeros,
within any 16-bit chunk of the address
2001:0DB8::CD30/60
Note— Like IPv4 CIDR prefix, when writing both a node (host) address
and a prefix of that node address (e.g., the node's subnet prefix), the
two can be combined as follows:
Note— Anycast addresses are taken from the unicast address spaces
(of any scope) and are not syntactically distinguishable from unicast
addresses. For example, if you are configuring a DNS server and you
want to use anycast for redundancy and load balancing, you would
assign the same anycast address to multiple DNS servers. When clients
send DNS queries to the anycast address, the queries will be
automatically routed to the closest DNS server, improving
performance and resilience.
Global Unicast Addresses
The block in the address space that is used for unicast (one-to-one)
communication between two hosts in the Internet (like public IP
addresses in IPv4) is called the global unicast address block. CIDR for
the block is 2000: :/3, which means that the three leftmost bits are the
same for all addresses in this block (001). The size of this block is 2125
bits, which is more than enough for Internet expansion for many years
to come. An address in this block is divided into three parts:
1. Global Routing Prefix— It is used to route the packet through the Internet to
the organization site, such as the ISP that owns the block. Since the first three
bits in this part are fixed (001), the rest of the 45 bits can be defined for up to
245 sites (a private organization or an ISP). The global routers in the Internet
route a packet to its destination site based on the value of global routing prefix.
Note— The Global Routing Prefix in IPv6 serves a similar purpose to the network
ID (netid) in IPv4. Both are used to identify the network portion of an IP address
and are used for routing purposes.
Traffic class— The 8-bit traffic class field is used to distinguish different payloads
with different delivery requirements. It replaces the type-of-service field in IPv4.
Flow label— The flow label is a 20-bit field that is designed to provide special
handling for a particular flow of data.
Payload length—The 2-byte payload length field defines the length of the IP
datagram excluding the header.
Next header— The next header is an 8-bit field defining the type of the first
external header (if present) or the type of the data that follows the base header
in the datagram. This field is similar to the protocol field in IPv4.
Hope limit—The 8-bit hop limit field serves the same purpose as the TTL field in
IPv4.