Unit 6jfbvb

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Unit 6.

Network Layer
o The Network Layer is the third layer of the OSI model.
o It handles the service requests from the transport layer and further forwards
the service request to the data link layer.
o The network layer translates the logical addresses into physical addresses
o It determines the route from the source to the destination and also manages
the traffic problems such as switching, routing and controls the congestion
of data packets.
o The main role of the network layer is to move the packets from sending host
to the receiving host.

The main functions performed by the network layer are:

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.

IPv4 Header Format


IPv4: IPv4 is a connectionless protocol used for packet-switched networks. It
operates on a best-effort delivery model, in which neither delivery is guaranteed,
nor proper sequencing or avoidance of duplicate delivery is assured. Internet
Protocol Version 4 (IPv4) is the fourth revision of the Internet Protocol and a
widely used protocol in data communication over different kinds of networks.
IPv4 is a connectionless protocol used in packet-switched layer networks, such as
Ethernet. It provides a logical connection between network devices by providing
identification for each device. There are many ways to configure IPv4 with all
kinds of devices – including manual and automatic configurations – depending on
the network type. IPv4 is defined and specified in IETF publication RFC 791.
IPv4 uses 32-bit addresses for Ethernet communication in five classes: A, B, C, D
and E. Classes A, B and C have a different bit length for addressing the network
host. Class D addresses are reserved for multicasting, while class E addresses are
reserved for military purposes. IPv4 uses 32-bit (4-byte) addressing, which gives
232 addresses. IPv4 addresses are written in the dot-decimal notation, which
comprises of four octets of the address expressed individually in decimal and
separated by periods, for instance, 192.168.1.5.
IPv4 Datagram Header Size of the header is 20 to 60 bytes.

IPv4 Datagram Header

VERSION: Version of the IP protocol (4 bits), which is 4 for IPv4


HLEN: IP header length (4 bits), which is the number of 32 bit words in the
header. The minimum value for this field is 5 and the maximum is 15.
Type of service: Low Delay, High Throughput, Reliability (8 bits)
Total Length: Length of header + Data (16 bits), which has a minimum value 20
bytes and the maximum is 65,535 bytes.
Identification: Unique Packet Id for identifying the group of fragments of a
single IP datagram (16 bits)
Flags: 3 flags of 1 bit each : reserved bit (must be zero), do not fragment flag,
more fragments flag (same order)
Fragment Offset: Represents the number of Data Bytes ahead of the particular
fragment in the particular Datagram. Specified in terms of number of 8 bytes,
which has the maximum value of 65,528 bytes.
Time to live: Datagram’s lifetime (8 bits), It prevents the datagram to loop
through the network by restricting the number of Hops taken by a Packet before
delivering to the Destination.
Protocol: Name of the protocol to which the data is to be passed (8 bits)
Header Checksum: 16 bits header checksum for checking errors in the datagram
header
Source IP address: 32 bits IP address of the sender
Destination IP address: 32 bits IP address of the receiver
Option: Optional information such as source route, record route. Used by the
Network administrator to check whether a path is working or not.

IPv6 Header Format

Version (4-bits): Indicates version of Internet Protocol which contains bit


sequence 0110.
Traffic Class (8-bits): The Traffic Class field indicates class or priority of IPv6
packet which is similar to Service Field in IPv4 packet. It helps routers to handle
the traffic based on the priority of the packet. If congestion occurs on the router
then packets with the least priority will be discarded.
As of now, only 4-bits are being used (and the remaining bits are under research),
in which 0 to 7 are assigned to Congestion controlled traffic and 8 to 15 are
assigned to Uncontrolled traffic.
Flow Label (20-bits): Flow Label field is used by a source to label the packets
belonging to the same flow in order to request special handling by intermediate
IPv6 routers, such as non-default quality of service or real-time service. In order
to distinguish the flow, an intermediate router can use the source address, a
destination address, and flow label of the packets. Between a source and
destination, multiple flows may exist because many processes might be running
at the same time. Routers or Host that does not support the functionality of flow
label field and for default router handling, flow label field is set to 0. While
setting up the flow label, the source is also supposed to specify the lifetime of the
flow.
Payload Length (16-bits): It is a 16-bit (unsigned integer) field, indicates the
total size of the payload which tells routers about the amount of information a
particular packet contains in its payload. The payload Length field includes
extension headers(if any) and an upper-layer packet. In case the length of the
payload is greater than 65,535 bytes (payload up to 65,535 bytes can be indicated
with 16-bits), then the payload length field will be set to 0 and the jumbo payload
option is used in the Hop-by-Hop options extension header.
Next Header (8-bits): Next Header indicates the type of extension header(if
present) immediately following the IPv6 header. Whereas In some cases it
indicates the protocols contained within upper-layer packets, such as TCP, UDP.
Hop Limit (8-bits): Hop Limit field is the same as TTL in IPv4 packets. It
indicates the maximum number of intermediate nodes IPv6 packet is allowed to
travel. Its value gets decremented by one, by each node that forwards the packet
and the packet is discarded if the value decrements to 0. This is used to discard
the packets that are stuck in an infinite loop because of some routing error.
Source Address (128-bits): Source Address is the 128-bit IPv6 address of the
original source of the packet.
Destination Address (128-bits): The destination Address field indicates the IPv6
address of the final destination(in most cases). All the intermediate nodes can use
this information in order to correctly route the packet.
Extension Headers: In order to rectify the limitations of the IPv4 Option Field,
Extension Headers are introduced in IP version 6. The extension header
mechanism is a very important part of the IPv6 architecture. The next Header
field of IPv6 fixed header points to the first Extension Header and this first
extension header points to the second extension header and so on.

Difference Between IPv4 and IPv6


IPv4 IPv6

IPv4 has a 32-bit address


IPv6 has a 128-bit address length
length

It Supports Manual and


It supports Auto and renumbering address
DHCP address
configuration
configuration

In IPv4 end to end,


In IPv6 end-to-end, connection integrity is
connection integrity is
Achievable
Unachievable

It can generate The address space of IPv6 is quite large it can


4.29×109 address space produce 3.4×1038 address space

Address representation of
Address Representation of IPv6 is in hexadecimal
IPv4 is in decimal

Fragmentation performed
In IPv6 fragmentation is performed only by the
by Sender and forwarding
sender
routers
IPv4 IPv6

In IPv4 Packet flow


In IPv6 packet flow identification are Available
identification is not
and uses the flow label field in the header
available

In IPv4 checksum field is


In IPv6 checksum field is not available
available

IPv4 has a header of 20- IPv6 has a header of 40 bytes fixed


60 bytes.

IPv4 can be converted to


Not all IPv6 can be converted to IPv4
IPv6

IPv4 consists of 4 fields


IPv6 consists of 8 fields, which are separated by a
which are separated by
colon (:)
addresses dot (.)

IPv4’s IP addresses are


divided into five different
classes. Class A , Class IPv6 does not have any classes of the IP address.
B, Class C, Class D ,
Class E.

Example of Example of IPv6:


IPv4: 66.94.29.13 2001:0000:3238:DFE1:0063:0000:0000:FEFB

Classful Addressing
An IP address is an address having information about how to reach a specific host,
especially outside the LAN. An IP address is a 32-bit unique address having an
address space of 232.
Generally, there are two notations in which the IP address is written, dotted
decimal notation and hexadecimal notation.
Dotted Decimal Notation

Dotted Decimal Notation

Classful Addressing
The 32-bit IP address is divided into five sub-classes. These are:
 Class A
 Class B
 Class C
 Class D
 Class E
Each of these classes has a valid range of IP addresses. Classes D and E are
reserved for multicast and experimental purposes respectively. The order of bits in
the first octet determines the classes of the IP
address. The IPv4 address is divided into two parts:
 Network ID
 Host ID
The class of IP address is used to determine the bits used for network ID and host
ID and the number of total networks and hosts possible in that particular class.
Each ISP or network administrator assigns an IP address to each device that is
connected to its network.
Classful Addressing

Class A
IP addresses belonging to class A are assigned to the networks that contain a large
number of hosts.
 The network ID is 8 bits long.
 The host ID is 24 bits long.
The higher-order bit of the first octet in class A is always set to 0. The remaining
7 bits in the first octet are used to determine network ID. The 24 bits of host ID are
used to determine the host in any network. The default subnet mask for Class A is
255.x.x.x. Therefore, class A has a total of:
 2^24 – 2 = 16,777,214 host ID
IP addresses belonging to class A ranges from 1.0.0.0 – 126.255.255.255.

Class A
Class B
IP address belonging to class B is assigned to networks that range from medium-
sized to large-sized networks.
 The network ID is 16 bits long.
 The host ID is 16 bits long.
The higher-order bits of the first octet of IP addresses of class B are always set to
10. The remaining 14 bits are used to determine the network ID. The 16 bits of host
ID are used to determine the host in any network. The default subnet mask for class
B is 255.255.x.x. Class B has a total of:
 2^14 = 16384 network address
 2^16 – 2 = 65534 host address
IP addresses belonging to class B ranges from 128.0.0.0 – 191.255.255.255.

Class B

Class C
IP addresses belonging to class C are assigned to small-sized networks.
 The network ID is 24 bits long.
 The host ID is 8 bits long.
The higher-order bits of the first octet of IP addresses of class C is always set to
110. The remaining 21 bits are used to determine the network ID. The 8 bits of host
ID are used to determine the host in any network. The default subnet mask for class
C is 255.255.255.x. Class C has a total of:
 2^21 = 2097152 network address
 2^8 – 2 = 254 host address
IP addresses belonging to class C range from 192.0.0.0 – 223.255.255.255.
Class C

Class D
IP address belonging to class D is reserved for multi-casting. The higher-order bits
of the first octet of IP addresses belonging to class D is always set to 1110. The
remaining bits are for the address that interested hosts recognize.
Class D does not possess any subnet mask. IP addresses belonging to class D range
from 224.0.0.0 – 239.255.255.255.

Class D

Class E
IP addresses belonging to class E are reserved for experimental and research
purposes. IP addresses of class E range from 240.0.0.0 – 255.255.255.254. This
class doesn’t have any subnet mask. The higher-order bits of the first octet of class
E are always set to 1111.

Class E

Range of Special IP Addresses


169.254.0.0 – 169.254.0.16 : Link-local addresses
127.0.0.0 – 127.255.255.255 : Loop-back addresses
0.0.0.0 – 0.0.0.8: used to communicate within the current network.
Rules for Assigning Host ID
Host IDs are used to identify a host within a network. The host ID is assigned based
on the following rules:
 Within any network, the host ID must be unique to that network.
 A host ID in which all bits are set to 0 cannot be assigned because this host ID
is used to represent the network ID of the IP address.
 Host ID in which all bits are set to 1 cannot be assigned because this host ID is
reserved as a broadcast address to send packets to all the hosts present on that
particular network.
Rules for Assigning Network ID
Hosts that are located on the same physical network are identified by the network
ID, as all host on the same physical network is assigned the same network ID. The
network ID is assigned based on the following rules:
 The network ID cannot start with 127 because 127 belongs to the class A
address and is reserved for internal loopback functions.
 All bits of network ID set to 1 are reserved for use as an IP broadcast address
and therefore, cannot be used.
 All bits of network ID set to 0 are used to denote a specific host on the local
network and are not routed and therefore, aren’t used.

Classless Addressing: Solving Problem


if given IP address =201.20.31.65 then find out the following parts
Find the class of given IP?
Find the network ID?
Find first and last Host ID and Network IP?
Find broadcast IP addressing?
Important Points-

Point-01:

For any given IP Address,


 If the range of first octet is [1, 126], then IP Address belongs to class A.
 If the range of first octet is [128, 191], then IP Address belongs to class B.
 If the range of first octet is [192, 223], then IP Address belongs to class C.
 If the range of first octet is [224, 239], then IP Address belongs to class D.
 If the range of first octet is [240, 254], then IP Address belongs to class E.

Point-02:
For any given IP Address,

 IP Address of its network is obtained by setting all its Host ID part bits to 0.

Point-03:

For any given IP Address,


 Direct Broadcast Address is obtained by setting all its Host ID part bits to 1.

Point-04:

 For any given IP Address, limited Broadcast Address is obtained by setting all its bits to 1.
 For any network, its limited broadcast address is always 255.255.255.255

Pause

Point-05:

 Class D IP Addresses are not divided into Net ID and Host ID parts.
 Class E IP Addresses are not divided into Net ID and Host ID parts.

PRACTICE PROBLEMS BASED ON IP ADDRESS IN NETWORKING-

Problem-01:

For the following IP Addresses-

1. 1.2.3.4
2. 10.15.20.60
3. 130.1.2.3
4. 150.0.150.150
5. 200.1.10.100
6. 220.15.1.10
7. 250.0.1.2
8. 300.1.2.3
Identify the Class, Network IP Address, Direct broadcast address and Limited broadcast address of each IP
Address.

Solution-

Part-A:

Given IP Address is-


1.2.3.4

 IP Address belongs to class A


 Network IP Address = 1.0.0.0
 Direct Broadcast Address = 1.255.255.255
 Limited Broadcast Address = 255.255.255.255

Part-B:

Given IP Address is-


10.15.20.60

 IP Address belongs to class A


 Network IP Address = 10.0.0.0
 Direct Broadcast Address = 10.255.255.255
 Limited Broadcast Address = 255.255.255.255

Part-C:

Given IP Address is-


130.1.2.3

 IP Address belongs to class B


 Network IP Address = 130.1.0.0
 Direct Broadcast Address = 130.1.255.255
 Limited Broadcast Address = 255.255.255.255
Part-D:

Given IP Address is-


150.0.150.150

 IP Address belongs to class B


 Network IP Address = 150.0.0.0
 Direct Broadcast Address = 150.0.255.255
 Limited Broadcast Address = 255.255.255.255

Part-E:

Given IP Address is-


200.1.10.100

 IP Address belongs to class C


 Network IP Address = 200.1.10.0
 Direct Broadcast Address = 200.1.10.255
 Limited Broadcast Address = 255.255.255.255

Part-F:

Given IP Address is-


220.15.1.10

 IP Address belongs to class C


 Network IP Address = 220.15.1.0
 Direct Broadcast Address = 220.15.1.255
 Limited Broadcast Address = 255.255.255.255

Part-G:

Given IP Address is-


250.0.1.2

 IP Address belongs to class E


 Network IP Address = Not available
 Direct Broadcast Address = Not available
 Limited Broadcast Address = Not available

Part-H:

Given IP Address is-


300.1.2.3

 This is not a valid IP Address.


 This is because for any given IP Address, the range of its first octet is always [1, 254].
 First and Last IP Addresses are reserved.

Problem-03:

A host with IP Address 200.100.1.1 wants to send a packet to all the hosts in the same network.
What will be-
1. Source IP Address
2. Destination IP Address

Solution-

1. Source IP Address = IP Address of the sender = 200.100.1.1


2. Destination IP Address = Limited Broadcast Address = 255.255.255.255

Problem-04:

How many bits are allocated for Network ID and Host ID in 23.192.157.234 address?

Solution-

Given IP Address belongs to class A.


Thus,
 Number of bits reserved for Network ID = 8
 Number of bits reserved for Host ID = 24

Questions of Classful IP Addressing


The question is, if the given IP address = 201.20.31.65, then find out the following parts.

Part 1: Find the Class of the given IP.

Solution: The first Octet of the given IP address exists in between the range of Class C (192 –
223). So, the given IP belongs to class C.

Part 2: Find the Subnet Mask of the given IP.

Solution: After checking the class of the given IP. A subnet mask can be found by putting all octet-bits
of network ID to “255” and Host bits to “0”. So, the Class C subnet mask is 255.255.255.0.

Part 3: Find the Network ID.

Solution: To find the network ID, Perform AND operation of the given IP with Subnet mask in
binary. It will provide the network ID where that particular IP exists. So, the network ID will
be 201.20.31.0.

Part 4: Find the First and Last IP address of the given Network IP.

Solution: We know that there are two IPs for each network, which are reserved. As the Network ID is
201.20.31.0. So, the first IP address will be 201.20.31.0, which is reserved for network identification.
The last IP address is 201.20.31.255, which is reserved for direct broadcasting.

Part 5: Find the first and Last Host ID of the given Network IP.

Solution: Due to the reservation of two Hosts, the Network ID is 201.20.31.0. So, the first host IP
address will be 201.20.31.1, and the Last host IP address will be 201.20.31.254.

Part 6: Find the Limited broadcast IP address.

Solution: Replacing all octets of IP address to 255 (decimal) is called Limited broadcast IP
addressing. So, Limited broadcast address = 255.255.255.255.
Part 7: Find the Direct broadcast IP addressing.

Solution: Replacing the Host-bits-octets to 255 of a given IP is called direct broadcast IP addressing.
So, direct broadcast IP addressing = 201.20.31.255.
IPv4 Datagram Header Numerical
Question: A datagram of 3000 bytes (20 bytes of IP header + 2980 bytes IP payload)
reached the router and must be forwarded to link with MTU (maximum transmission unit) of
500 bytes. How many fragments will be granted? Also, write MF, offset, and total length
values for all.

After the fragmentation of the datagram into fragments (packets), each fragment will carry the same
header size, which is the same as the original datagram. So, in this question, 20 bytes will be the
compulsory part of each fragment.

As the limit of a link is 500 bytes to transfer, in which 20 bytes is the header size. So, 480 bytes
of payload can transfer in each fragment.

Total Number of Fragments

The total number of fragments can be calculated by considering a ceiling value of the following
formula.

Total fragment = Total payload to transfer/ Payload in each fragment

So, Total fragment = 2980 / 480 = 7

Descriptive diagram in given below


Total Length

Total length is the combination of all fragmented payloads. Adding the payload of each fragment will
always equal the size of the original payload. As

Total length of payload = 480+480+480+480+480+480+100 = 2980.

Note: Header length will remain the same 20 bytes at the receiving end. So, 20+2980 bytes = 3000
bytes. It was the original datagram of 3000 bytes.

More Fragments (MF)

MF value may be 0 or 1.

 When MF bit value is 0 then It tells to the receiver that the current datagram-fragment is the last
fragment and no more segment will appear of same datagram.

 When MF bit value is 1 then it tells more fragments are still to come after this fragment.

Fragment Offset

It uses a scaling factor of 8. Fragment offset can be calculated by using the following formula

Fragment offset for a given fragmented IP datagram = Number of data (payload) bytes ahead of it / 8

 At fragment F1, no byte has already been transferred. So fragment offset = 0/8 B = 0
 At fragment F2, 480 bytes of F1 are already transferred. So fragment offset = 480/8 B = 60

 At fragment F3, 480 bytes of F1 and F2 are already transferred. So fragment offset = 480*2/8 B =120

 At fragment, F4, 480 bytes of F1, F2, and F3 are already transferred. So fragment offset = 480*3/8 B
=180

 At fragment F5, 480 bytes of F1,F2,F3 and F4 is already transferred. So fragment offset = 480*4/8 B
=240

 At fragment F6, 480 bytes of F1,F2,F3,F4 and F5 is already transferred. So fragment offset = 480*5/8 B
=300

At fragment F7, 480 bytes of F1,F2,F3,F4,F5 and F6 is already transferred. So fragment offset =
480*6/8 B =360

You might also like