Module 4
Module 4
Module – 4
Network Layer
By Mr. A. Swaminathan VIT Chennai
IPv4 Addressing
Introduction
▪32-bit address
▪Unique
▪Universal
▪ Binary
▪ Dotted decimal
▪ Hexa decimal
Simple Task 2
▪Change the following IPv4 addresses from dotted-
decimal notation to binary notation.
a. 111.56.45.78
b. 221.34.7.82
Simple Task 4
Classful Addressing
Classful Addressing
▪ Concept of classes
▪ In classful addressing, the address space is divided into
five classes:
Class A
Ciass B
Class C
Class D
Class E
Mr. A. Swaminathan VIT Chennai
18
Classful Addressing ( Contd..)
▪ Since 2 bytes in class B define the class and the two leftmost bit
should be 10 (fixed), the next 14 bits can be changed to find the
number of blocks in this class.
▪ Therefore, class B is divided into 214 = 16,384 blocks
▪ Since 3 bytes in class C define the class and the three leftmost bits
should be 110 (fixed), the next 21 bits can be changed to find the
number of blocks in this class.
▪ Therefore, class C is divided into 221 = 2,097,152 blocks
addressing)
▪The number of addresses in the block, N, can be
found using N = 232_n.
▪To find the first address, we keep the n leftmost bits
and set the (32 - n) rightmost bits all to Os.
▪To find the last address, we keep the n leftmost bits
and set the (32 - n) rightmost bits all to Is.
Source: Data Communications and Networking – Behrouz A. Forouzan Mr. A. Swaminathan VIT Chennai
Subnetting 39
▪ Subnetting increases the length of the netid and decreases the length of
hostid.
▪ When we divide a network to s number of subnetworks, each of equal
numbers of hosts, we can calculate the subnetid for each subnetwork as
▪ n is the length of netid, nsub is the length of each subnetid, and s is the
number of subnets which must be a power of 2.
Subnetid ( Contd..)
Subnetid (Contd..)
Solution
We replace each group of 8 bits with its equivalent
decimal number (see Appendix B) and add dots for
separation.
Solution
Solution
NOTE:
In classful addressing, the address
space is divided into five classes:
A, B, C, D, and E.
NOTE:
NOTE:
NOTE:
NOTE:
We can see that the restrictions are applied to this block. The
addresses are contiguous. The number of addresses is a power of 2
(16 = 24). This block of IP addresses is represented by:
205.16.37.32/28
Source: Data Communications and Networking – Behrouz A. Forouzan Mr. A. Swaminathan VIT Chennai
62
Example 19.6
Solution
▪ The binary representation of the given address is
▪ 11001101 00010000 00100101 00100111
▪ If we set 32−28 rightmost bits to 0, we get
▪ 11001101 00010000 00100101 0010000 0
▪ or
205.16.37.32
▪ The block representation is 205.16.37.32/28
NOTES:
The last address in the block can be
found by setting the rightmost
32 − n bits to 1s.
NOTE:
Find
a. The first address
b. The last address
Mr. A. Swaminathan VIT Chennai
Example 19.9 (continued) 69
Solution
a. The first address can be found by ANDing the given
addresses with the mask. ANDing here is done bit by
bit. The result of ANDing 2 bits is 1 if both bits are 1s;
the result is 0 otherwise.
NOTE:
NOTE:
Each address in the block can be
considered as a two-level
hierarchical structure:
the leftmost n bits (prefix) define
the network;
the rightmost 32 − n bits define
the host.
Source: Data Communications and Networking – Behrouz A. Forouzan Mr. A. Swaminathan VIT Chennai
77
Figure 19.8 Three-level hierarchy in an IPv4 address
Solution
Figure 19.9 shows the situation.
Group 1
For this group, each customer needs 256 addresses.
This means that 8 (log2 256) bits are needed to define
each host. The prefix length is then 32 − 8 = 24. The
addresses are
Group 2
For this group, each customer needs 128 addresses. This
means that 7 (log2 128) bits are needed to define each
host. The prefix length is then 32 − 7 = 25. The addresses
are
1
S: 138.76.29.7, 5001
2 D: 128.119.40.186, 80 10.0.0.4
10.0.0.2
138.76.29.7 S: 128.119.40.186, 80
D: 10.0.0.1, 3345 4
S: 128.119.40.186, 80
D: 138.76.29.7, 5001 3 10.0.0.3
4: NAT router
3: Reply arrives changes datagram
dest. address: dest addr from
138.76.29.7, 5001 138.76.29.7, 5001 to 10.0.0.1, 3345
NOTE:
An IPv6 address is 128 bits long.
Mr. A. Swaminathan VIT Chennai
92
Classless addressing
▪ The prefix length in classless addressing play a very important role when
we need to extract the information about the block from a given address in
the block.
▪ In classful addressing, the netid length is inherent in the address. Given an
address, we know the class of the address that allows us to find the netid
length (8,16, or 24).
▪ In classless addressing, the prefix length cannot be found if we are given
only an address in the block. The given address can belong to a block with
any prefix length.
▪ Assume
N - the total number of addresses granted to the organization
n - the prefix length
Nsub - the assigned number of addresses to each subnetwork
nsub - The prefix length for each subnetwork
s - The total number of subnetworks
▪variable-length packet
– header and payload (data)
▪The header is 20 to 60 bytes in length and
contains information essential to routing and
delivery.
▪ Service Type
– In the original design of the IP header, this field was
referred to as type of service (TOS), which define how the
datagram should be handled.
▪ Total Length.
– This 16-bit field defines the total length (header plus
data) of the IP datagram in bytes.
Length of data = total length − (HLEN) × 4
▪ Identification, Flags, and Fragmentation Offset.
– These three fields are related to the fragmentation of
the IP datagram when the size of the datagram is larger than
the underlying network can carry.
Mr. A. Swaminathan VIT Chennai
IPv4 Packet Format (Contd..) 116
Identification
▪This 16-bit field identifies a datagram originating from
the source host.
▪The combination of the identification and source IP
address must uniquely define a datagram as it leaves
the source host.
▪To guarantee uniqueness, the IP protocol uses a
counter to label the datagrams.
Mr. A. Swaminathan VIT Chennai
IPv4 Packet Format (Contd..) 117
Flags:
▪ The first bit is reserved (not used).
▪ The second bit is called the do not fragment bit.
▪ If its value is 1, the machine must not fragment the datagram. If it cannot
pass the datagram through any available physical network, it discards the
datagram and sends an ICMP error message to the source host.
▪ If its value is 0, the datagram can be fragmented if necessary.
▪ The third bit is called the more fragment bit.
▪ If its value is 1, it means the datagram is not the last fragment; there are
more fragments after this one.
▪ If its value is 0, it means this is the last or only fragment
Source: Data Communications and Networking – Behrouz A. Forouzan
Mr. A. Swaminathan VIT Chennai
IPv4 Packet Format (Contd..) 118
Fragmentation offset:
▪Fragmentation offset:
Source: Data Communications and Networking – Behrouz A. Forouzan Mr. A. Swaminathan VIT Chennai
IPv4 Packet Format (Contd..) 120
Time-To-Live
▪ (TTL) field is used to control the maximum number of hops (routers)
visited by the datagram.
▪ When a source host sends the datagram, it stores a number in this field.
▪ This value is approximately two times the maximum number of routers
between any two hosts.
▪ Each router that processes the datagram decrements this number by one.
▪ If this value, after being decremented, is zero, the router discards the
datagram.
Protocol
▪ A datagram, for example, can carry a packet belonging to any
transport-layer protocol such as UDP or TCP.
Header Checksum
▪ Checksum in IP covers only the header not the data.
▪ First, the value of the checksum field is set to 0.
▪ The entire header is divided into 16-bit sections and added
together.
▪ The result (sum) is complemented and inserted into the
checksum field.
Receiver
▪ An IPv4 packet has arrived with the first 8 bits as (01000010)2 The receiver
discards the packet. Why?
▪ In an IPv4 packet, the value of HLEN is (1000)2. How many bytes of options
are being carried by this packet?
▪ In an IPv4 packet, the value of HLEN is 5, and the value of the total length
field is (0028)16. How many bytes of data are being carried by this packet?
▪ An IPv4 packet has arrived with the first few hexadecimal digits as shown.
How many hops can this packet travel before being dropped. The data
belong to what upper layer protocol.
(45000028000100000102…)16
Mr. A. Swaminathan VIT Chennai
References 127
▪ https://www.eecs.yorku.ca/course_archive/2015-
16/W/3214/CSE3214_10_PacketDelay_2016_posted.pdf
Mr. A. Swaminathan VIT Chennai