KEMBAR78
Data Communication: NETWORKLAYER | PDF | Internet Protocols | Computer Network
0% found this document useful (0 votes)
18 views71 pages

Data Communication: NETWORKLAYER

Unit-3 covers the Network Layer of data communications, focusing on Internet Protocol Version 4 (IPv4) addressing, routing algorithms, and key functions such as logical addressing, routing, and packet forwarding. It discusses the transition from classful to classless addressing to address IP address depletion and introduces subnetting for efficient IP address utilization. The unit also explains the structure of IP addresses, including their hierarchical nature and the importance of CIDR (Classless Inter-Domain Routing).

Uploaded by

caxiya6991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views71 pages

Data Communication: NETWORKLAYER

Unit-3 covers the Network Layer of data communications, focusing on Internet Protocol Version 4 (IPv4) addressing, routing algorithms, and key functions such as logical addressing, routing, and packet forwarding. It discusses the transition from classful to classless addressing to address IP address depletion and introduces subnetting for efficient IP address utilization. The unit also explains the structure of IP addresses, including their hierarchical nature and the importance of CIDR (Classless Inter-Domain Routing).

Uploaded by

caxiya6991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Unit-3

AD42 Data Communications and Networking


Outline of Unit-3
• Network Layer: Internet Protocol Version 4
◦ IPv4 Addressing
◦ Main and Auxiliary protocols
• Routing Algorithms:
◦ Distance-Vector(DV) Routing
◦ Link-State Routing
◦ Unicast Routing Protocols
◦ Internet Structure
◦ Routing Information Protocol
◦ Open Shortest Path First
◦ Border Gateway Protocol version 4

2
The Network Layer is responsible for the logical addressing and
routing of data packets between devices across different
networks.

Key Functions of the Network Layer in TCP/IP:


• Logical Addressing (IP Addressing)
• Assigns unique IP addresses to devices in a network.
• IPv4 (32-bit) and IPv6 (128-bit) addressing are used.
• Routing
• Determines the best path for data to travel across interconnected networks.
• Routers use routing tables and protocols (such as OSPF, BGP) to forward packets.
• Packet Forwarding
•Transmits packets from source to destination across multiple networks.
•Uses IP headers to determine the next hop in the network path.
• Fragmentation and Reassembly
• If a packet is too large for a network’s MTU (Maximum Transmission Unit), it is
fragmented into smaller packets.
• Reassembled at the destination.
• Error Handling and Packet Lifetime (TTL - Time To Live)
• The TTL field in the IP header prevents infinite looping of packets by decreasing at
every hop.
• When TTL reaches zero, the packet is discarded.
Protocols Used in the Network Layer (TCP/IP Model)

• Internet Protocol (IP)


• Provides addressing and routing of packets.
• IPv4 and IPv6 are the main versions.
• Address Resolution Protocol (ARP)
• Resolves an IP address to a MAC address for local network communication.
• Internet Control Message Protocol (ICMP)
• Used for error reporting and diagnostics (e.g., ping, traceroute).
• Internet Group Management Protocol (IGMP)
• Supports multicast communication in IPv4.
How Data is Exchanged Within the Same Network vs.
Between Different Networks
1. Communication Within the Same Network (Handled by Data
Link Layer)
• Uses MAC addresses for direct communication.
• Switches forward frames based on MAC addresses.
• Uses ARP (Address Resolution Protocol) to find the MAC address of a device.
• No routing or IP address-based forwarding is needed.
🔹 Example: Your PC sends data to a printer in the same Wi-Fi network using
the MAC address.

2. Communication Between Different Networks (Handled by


Network Layer)
• Uses IP addresses to identify devices across networks.
• Routers forward packets based on IP addresses.
• IP fragmentation, routing, and error handling occur at this layer.
• ICMP (Internet Control Message Protocol) helps in network troubleshooting.
🔹 Example: Your PC sends a request to a website—the packet is routed across
multiple networks using IP.
What is an IP Address?
An IPv4 address is a 32-bit address that uniquely and
universally defines the connection of a host or a router to
the Internet. The IP address is the address of the
connection, not the host or the router, because if the
device is moved to another network, the IP address may be
changed.
Internet Protocol Version
• Two versions
◦ IP Version 4 (IPv4) - almost depleted
◦ IP Version 6 (IPv6)
• IPv4 address is a 32-bit address
◦ Unique - If a device has two connections to the Internet, via two
networks, it has two IPv4 addresses
◦ universal - the addressing system must be accepted by any host that
wants to be connected to the Internet

8
Address space
• Total number of addresses used by the protocol
• If a protocol uses b bits to define an address, the address
space is 2b because each bit can have two different
values (0 or 1).
• IPv4 uses 32-bit addresses, which means that the
address space is 2^32 or 4,294,967,296
(over 4 billion unique addresses).
• If there were no restrictions, more than 4 billion
devices could be connected to the Internet.

9
Notation
• binary notation (base 2) - displayed as 32 bit.
◦ To make the address more readable, one or more spaces are usually inserted
between each octet (8 bits).
◦ Each octet is often referred to as a byte
• dotted-decimal notation (base 256) - usually written in decimal form
with a decimal point (dot) separating the bytes
◦ each byte (octet) is only 8 bits, each number in the dotted-decimal notation is
between 0 and 255
• hexadecimal notation (base 16)
• Each hexadecimal digit is equivalent to 4 bits. This means that a 32-
bit address has eight hexadecimal digits

10
Hierarchy in Addressing
• Any communication network that involves delivery – have
addressing system in hierarchical
• 32-bit IPv4 address - hierarchical but is divided only into two parts
• Prefix-defines the network (n-bits)
◦ fixed length prefix -classful addressing - obsolete
• variable length prefix -classless addressing-
• Address (suffix) - defines the node - connection of a device to the
Internet (32-n bits)

11
Classful Addressing
•When the Internet started, an IPv4 address was designed with a
fixed-length prefix,to accommodate both small and large
networks, three fixed- length prefixes (n = 8, n = 16, and n = 24)
were designed instead of one.
• The whole address space was divided into five classes (classes
A, B, C, D, and E).

12
• An IP address belongs to a specific class based on its first byte.
• The network and host portions are fixed depending on the class.

• The first byte tells the network which class the IP belongs to.
• This helps in identifying network and host portions of the IP.
• Example:
• IP: 10.0.0.1 → First byte is 10 → Falls in Class A.
• IP: 172.16.5.20 → First byte is 172 → Falls in Class B.
• IP: 192.168.1.10 → First byte is 192 → Falls in Class C.
To determine the class of an IP address, you can use:
Binary Representation → Look at the prefix bits (0, 10, 110,
1110, 1111).
Decimal Representation → Check the first byte range (0-127,
128-191, etc.).
class A - the network length is 8 bits, but because the first bit,
which is 0, defines the class, we can have only 7 bits as the network
identifier. This means there are only 27 = 128 networks in the world
that can have a class A address.
class B - the network length is 16 bits, but because the first 2
bits,which are (10), define the class, we can have only 14 bits as the
network identifier. This means there are only 214 = 16,384 networks
in the world that can have a class B address.
class C - all addresses start with (110). In class C, the network
length is 24 bits, but because 3 bits define the class, we can have
only 21 bits as the network identifier. This means there are 221 =
2,097,152 networks in the world that can have a class C address.
Class D is not divided into prefix and suffix. It is used for multicast
Addresses.
class E - all addresses that start with 1111.
As in class D, class E is not divided into prefix and suffix and is used
as reserve.
Classes in Classful Addressing
Address Depletion
The classful addressing system led to inefficient IP address
allocation, causing rapid depletion of available addresses.
Class A was assigned to only 128 organizations, wasting
millions of addresses per network. Class B also suffered
from underutilization, while Class C had too few addresses
per network, making it impractical for many companies.
Class E was largely unused, further contributing to
inefficiency. To address this, a short-term solution called
classless addressing (CIDR) was introduced to eliminate
rigid classes and optimize allocation, while the long-term
solution was the transition to IPv6, which expanded the
address space significantly.

17
Address Wastage:
• Class A (16 million addresses per network) was too large for most
organizations, leading to massive unused IPs.
• Class B (65,536 addresses per network) also had waste, as many
organizations didn’t need that many addresses.
• Class C (256 addresses per network) was too small for growing
businesses.
Rapid IPv4 Address Exhaustion:
• The Internet grew fast, and with rigid classful addressing, IPs were
depleting quickly.
Scalability Issues:
• Classful networks had fixed network sizes, making it difficult to
allocate IPs based on actual needs.
Classless Addressing
• New architecture announced in 1996 by the Internet authorities
• use the same address space but change the distribution of addresses to provide a
fair share to each organization
• Motivation
◦ Solution to address depletion
◦ Manage Internet Service Providers (ISPs)
◦ During the 1990s, Internet Service Providers (ISPs) came into prominence
◦ An ISP is an organization that provides Internet access and services for
individuals, small businesses, and midsize organizations that do not want to
create an Internet site and become involved in providing Internet services (such
as electronic mail) for their employees.
◦ An ISP is granted a large range of addresses and then subdivides the addresses
(in groups of 1, 2, 4, 8, 16, and so on), giving a range of addresses to a
household or a small business
◦ connected via a dial-up modem, DSL, or cable modem to the ISP

19
Classless Addressing
• whole address space is divided into non overlapping
variable-length blocks - block of 20, 21, 22, …, 232 addresses
◦ restrictions - the number of addresses in a block needs to be a
power of 2
• An organization can be granted one block of addresses.
• prefix in an address defines the block (network)
• suffix defines the node (device)

20
Prefix Length: Slash Notation
• How to find the prefix length if an address is given?
• Because the prefix length is not inherent in the address,
we need to separately give the length of the prefix.
◦ the prefix length, n, is added to the address, separated by a slash.
• The notation is informally referred to as slash notation and
formally as classless interdomain routing (CIDR,
pronounced cider) strategy.

21
Extracting Information from an Address
• Given any address in the block, we normally like to know
three pieces of information about the block to which the
address belongs:
◦ the number of addresses
◦ the first address in the block -keep the n leftmost bits and set the
(32 − n) all bits to 0s
◦ the last address- keep the n le most bits and set the (32 − n)
rightmost bits all to 1s
• Because the value of prefix length, n, is given, we can
easily find these three pieces of information

22
Example 1

23
Network Address
• The preceding examples show that, given any address, we can find all
information about the block.
• The first address, the network address, is particularly important because it is
used in routing a packet to its destination network.
• For the moment, let us assume that an internet is made up of m
networks and a router with m interfaces.
◦ When a packet arrives at the router from any source host, the router needs to
know to which network the packet should be sent and from which interface the
packet should be sent out.
◦ When the packet arrives at the network, it reaches its destination host using
linklayer addressing
• After the network address has been found, the router consults its
forwarding table to find the corresponding interface from which the
packet should be sent out.
• The network address is actually the identifier of the network; each
network is identified by its network address.
24
Network Address

25
Block Allocation
• How are the blocks allocated?
• Global authority called the Internet Corporation for Assigned
Names and Numbers (ICANN)
• However, ICANN does not normally allocate addresses to
individual Internet users.
• It assigns a large block of addresses to an ISP (or a larger
organization that is considered an ISP in this case).

26
For the proper operation of the CIDR, two restrictions need
to be applied to the allocated block.
1. The number of requested addresses, N, needs to be a
power of 2. The reason is that N = 232-n or n = 32 − log2 N. If
N is not a power of 2, we cannot have an integer value for
n.
2. The requested block needs to be allocated where there
are a contiguous number of available addresses in the
address space
Example
• An ISP has requested a block of 1000 addresses. Because
1000 is not a power of 2, 1024 addresses are granted.
• The prefix length is calculated as n = 32 − log2 1024 = 22.
• An available block, 18.14.12.0/22, is granted to the ISP.

28
Problem : Finding the Number of Addresses in a CIDR
Block
Given: The IP address 192.168.1.0/26
Find: The number of IP addresses in this block.
Solution:
The number of IP addresses in a CIDR block is calculated as:
2(32−prefix length)
For /26, we calculate:
2(32−26)=26=64
Answer: The block contains 64 IP addresses.
All IPs within 192.168.1.0 - 192.168.1.63 belong
only to this subnet.
Subnetting
It is the process of dividing a large IP network into smaller,
more manageable sub-networks (subnets).
🔹 It improves IP address utilization, network efficiency,
and security.
🔹 Subnetting is used in both classful and classless
addressing, but it is more commonly associated with CIDR
(Classless Inter-Domain Routing).
Important Note:
When you use /8, /16, or /24 with classful IPs, it's
essentially just a way of writing the default subnet mask
for those classes. But when you use any other value (like
/27, /30, etc.), you're stepping into classless subnetting —
which gives more control and flexibility.
Example
A company has one network (192.168.1.0/24), but it wants
separate networks for:
• HR (50 users)
• IT (100 users)
• Finance (60 users)
Instead of using one big network, subnetting divides it into
smaller blocks like:

Now, traffic is isolated, security is improved, and IP


addresses are efficiently allocated.
Subnetting cont..
• Created more levels of hierarchy
• An organization (or an ISP) that is granted a range of addresses may divide the range into
several subranges and assign each subrange to a subnetwork (or subnet).
• N - total number of addresses granted to the organization
• n - prefix length
• Nsub- the assigned number of addresses to each subnetwork
• nsub - the prefix length for each subnetwork
• steps to guarantee the proper operation of the subnetworks
◦ The number of addresses in each subnetwork should be a power of 2.
◦ The prefix length for each subnetwork : nsub = 32 − log2 Nsub
◦ The starting address in each subnetwork should be divisible by the number of addresses
in that subnetwork - This can be achieved if we first assign addresses to larger
subnetworks.
• each subnetwork information (first and last address) – same process seen before

33
Example
• An organization is granted a block of addresses with the
beginning address 14.24.74.0/24. The organization needs
to have three subblocks of addresses to use in its three
subnets: one subblock of 10 addresses, one subblock of 60
addresses, and one subblock of 120 addresses. Design the
subblocks.
◦ There are 232–24 = 256 addresses in this block.
◦ The first address is 14.24.74.0/24;
◦ the last address is 14.24.74.255/24.
◦ To satisfy the third requirement, we assign addresses to subblocks,
starting with the largest and ending with the smallest one.

34
Example
• a. The number of addresses in the largest subblock, which requires 120 addresses, is not a
power of 2.
◦ We allocate 128 addresses.
◦ The subnet mask for this subnet can be found as n1 = 32 − log2 128 = 25.
◦ The first address in this block is 14.24.74.0/25;
◦ the last address is 14.24.74.127/25.
• b. The number of addresses in the second largest subblock, which requires 60 addresses, is
not a power of 2 either.
◦ We allocate 64 addresses
◦ The subnet mask for this subnet can be found as n2 = 32 − log2 64 = 26.
◦ The first address in this block is 14.24.74.128/26;
◦ the last address is 14.24.74.191/26.

35
Example
• c. The number of addresses in the smallest subblock, which
requires 10 addresses, is not a power of 2 either.
◦ allocate 16 addresses.
◦ The subnet mask for this subnet can be found as n3 = 32 − log2 16 = 28.
◦ The first address in this block is 14.24.74.192/28;
◦ the last address in this block is 14.24.74.207/28;
• If we add all addresses in the previous subblocks, the result is
208 addresses,
◦ means 48 addresses are left in reserve.
• The first address in this range is 14.24.74.208.
• The last address is 14.24.74.255.
• We don’t know about the prefix length yet.

36
Example

37
Address Aggregation
• One of the advantages of the CIDR strategy is address
aggregation (sometimes called address summarization or
route summarization).
• When blocks of addresses are combined to create a larger
block, routing can be done based on the prefix of the
larger block.it's a key principle in modern IP routing.
• ICANN assigns a large block of addresses to an ISP. Each ISP
in turn divides its assigned block into smaller subblocks
and grants the subblocks to its customers.

38
Address Aggregation
• Four small blocks of addresses are assigned to four
organizations by an ISP.
• The ISP combines these four blocks into one single block and
advertises the larger block to the rest of the world.
• Any packet destined for this larger block should be sent to this
ISP.
• It is the responsibility of the ISP to forward the packet to the
appropriate organization.
• a postal network - All packages coming from outside a country
are sent first to the capital and then distributed to the
corresponding destination.

39
Address Aggregation

40
Why routing can be done based on the prefix of larger block (Route
aggregation or supernetting).
→ It's a key principle in Modern IP Routing.
→ Prefix-based Routing
Here prefix represents one single large block that can represent multiple individual Networks.
→ Reduces Routing table size
This reduces memory usage and processing time in routers.
→ Simplifies Network management
It becomes easier to manage and implement rules at broader level (access control, firewall rules
or route advertisements are simplified).
→ Supports Hierarchical Routing
Where ISPs or organizations can advertise single aggregated route hiding subnets.
Main and Auxiliary Protocols
• The network layer in version 4 - one main protocol and
three auxiliary protocols
◦ The main protocol, Internet Protocol version 4 (IPv4)
◦ The Internet Control Message Protocol version 4 (ICMPv4)
◦ The Internet Group Management Protocol (IGMP)
◦ The Address Resolution Protocol (ARP)

42
Main and Auxiliary Protocols
Auxiliary protocol: Main protocol: responsible for
help IPv4 in packetizing, forwarding, and
multicasting delivery of a packet

Auxiliary protocol: glue the


Auxiliary protocol: helps IPv4
network and data-link layers in
to handle some errors that
mapping network-layer addresses
may occur in the network
to link-layer addresses
layer delivery

43
IPv4
IPv4 is a network layer protocol (Layer 3 of the OSI model).
•It is responsible for addressing and routing packets (called datagrams)
across networks.
•It uses IP addresses to identify source and destination hosts.
•It is a Unreliable datagram protocol.Which means
No guarantee of delivery: IPv4 does not ensure that a packet will reach its
destination.
No error correction: IPv4 only detects errors in the header (not in the
data) and discards the packet if there's an error. It does not attempt to fix
or resend it.
No sequencing: IPv4 does not ensure that packets will arrive in the same
order they were sent.
No acknowledgment: IPv4 does not notify the sender whether a packet
was delivered successfully or lost.
44
IPv4
• IPv4 is a connectionless protocol that uses the datagram
approach.
• This means that each datagram is handled independently,
and each datagram can follow a different route to the
destination
• This implies that datagrams sent by the same source to the
same destination could arrive out of order.
• IPv4 relies on a higher-level protocol to take care of all
these problems.

45
IPv4 Datagram Format
• First service provided by IPv4 – packetizing
Packetizing in IPv4 means:
Breaking up data into packets, adding IP headers, and preparing
it for transmission over the network.
It’s the first and foundational service IPv4 provides in the data
delivery process.
• Packets used by the IP are called datagrams.

46
How does IPv4 do packetizing?
When data reaches the network layer, IPv4:
• Adds an IPv4 header to the data segment (from transport
layer, like TCP/UDP).
• This header includes:
• Source and destination IP addresses
• Packet length
• Fragmentation info
• TTL (Time to Live), etc.
• The result is a datagram — the basic unit of data transmission
in IP.
A datagram is a variable-length packet consisting of
two parts:
◦ the header is 20 to 60 bytes in length and contains
information essential to routing and delivery
◦ first 20 bytes are essential and together are called the main header
◦ next 40 bytes include options and padding that may or may not be present
◦ It is customary in TCP/IP to show the header in 4-byte sections.
◦ payload (data).
◦ The header
IPv4 Datagram Format

49
IPv4 Datagram Format
• Version specifies the IP version.
• Header length (HLEN) specifies the length of the header
(including options and padding) in terms of 4-byte blocks. For
example, if the total header of a packet (including options and
padding) is 60B, HL=60B/4B=15 which is 1111 in binary.
Saves space in the header
• The HLen field is just 4 bits long.
• That means it can store a value from 0 to 15.
• If we used bytes, max would be only 15 bytes, which is too small!
• But using blocks of 4 bytes, we can represent:
15 × 4 = 60 bytes
Which is perfect, since the max IPv4 header size (with options) is 60
bytes.

50
• Type of service specifies the quality-of-service (QoS)
requirements of the packet, such as priority level,
delay,reliability, throughput, and cost.

• Total length specifies the total length of the packet in bytes,


• including the header and data. A total of 16 bits are assigned
to this field. Length of data = total length − (HLEN) × 4
• Helps to determine how much is really data and how much is padding
• Identification, flags, and fragment offset are used for
packet fragmentation and reassembly.
• Time to live specifies the maximum number of hops after which
a packet must be discarded.(how long a packet can "live" in the
network)
◦ value is approximately 2 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 specifies the protocol of packet in payload.


◦ A datagram can carry a packet from other protocols that directly use the
service of the IP, such as some routing protocols, any transport-layer
protocol or some auxiliary protocols.
◦ provides multiplexing at the source and demultiplexing at the destination

52
53
• Header checksum is a method of error detection
◦ the value of some fields, such as TTL, which are related to fragmentation and
options, may change from router to router, the checksum needs to be recalculated
at each router
• Source address and destination address are 32-bit fields specifying
the source address and the destination address, respectively.
• remain unchanged during the time the IP datagram travels from the
source host to the destination host.
• Options is a rarely used variable-length field to specify security level,
timestamp, type of route, record route.
• used for network testing and debugging
• Padding is used to make the header length a multiple of 4 bytes
when options are included and the total isn’t already aligned.

54
Let's say...
• An IPv4 packet includes some options.
• These options are 5 bytes long.
Now let’s calculate the total header length:
Main header = 20 bytes
Options = 5 bytes
Total = 25 bytes (not a multiple of 4)
• IPv4 requires the header to be a multiple of 4 bytes.
• 25 bytes is not divisible by 4, so we need to add 3 bytes
of padding to make it 28 bytes total.
Fragmentation
• Fragmentation is triggered because the Data Link Layer cannot
handle the full packet.
But the actual fragmentation is done by the Network Layer (IP).
• Datagram can travel through different networks.
• Each router decapsulates the IP datagram from the frame it
receives, processes it, and then encapsulates it in another
frame.
• The format and size of the received frame depend on the
protocol used by the physical network through which the frame
has just traveled.
• The format and size of the sent frame depend on the protocol
used by the physical network through which the frame is going
to travel.
• For example, if a router connects a LAN to a WAN, it receives a56
frame in the LAN format and sends a frame in the WAN format.
Maximum Transfer Unit (MTU)
• Each link-layer protocol has its own frame format.
• when a datagram is encapsulated in a frame, the total size
of the datagram must be less than this maximum size,
which is defined by the restrictions imposed by the
hardware and software used in the network

57
Fragmentation
• The value of the maximum transfer unit (MTU) differs from one
physical network protocol to another.
• For example, the value for a LAN is normally 1500 bytes, but for a
WAN it can be larger or smaller.
• need a mechanism that avoids requiring large buffers at
intermediate routers to store the fragments.
◦ To make the IP protocol independent of the physical network, the designers
decided to make the maximum length of the IP datagram equal to 65,535 bytes.
◦ This makes transmission more efficient if one day we use a link-layer protocol
with an MTU of this size.
◦ However, for other physical networks, we must divide the datagram to make it
possible for it to pass through these networks. This is called fragmentation.
◦ payload of the IP datagram is fragmented
◦ most parts of the header, with the exception of some options, must be copied by all fragments.

58
Fragmentation
• When a datagram is fragmented, each fragment has its own header
with most of the fields repeated, but some have been changed.
• A fragmented datagram may itself be fragmented if it encounters a
network with an even smaller MTU.
• A datagram can be fragmented by the source host or any router in
the path.
• The reassembly of the datagram, however, is done only by the
destination host, because each fragment becomes an
independent datagram.
• Whereas the fragmented datagram can travel through different
routes, and we can never control or guarantee which route a
fragmented datagram may take, all the fragments belonging to the
same datagram should finally arrive at the destination host.
• So it is logical to do the reassembly at the final destination.

59
Fragmentation
• The host or router that fragments a datagram must change the
values of three fields: flags, fragmentation offset, and total length.
• The rest of the fields must be copied.
• the value of the checksum must be recalculated regardless of
fragmentation.
• The identification field identifies a datagram originating from the
source host.
◦ Counter is initialized to a positive number
◦ When a datagram is fragmented, the value in the identification field is copied
into all fragments.
◦ identification number helps the destination in reassembling the fragments.
 The offset field indicates the position of a fragment in the sequence of
fragments making up the packet. The lengths of all the fragments, with the
exception of the last one, must be divisible by 8.

60
All fragments except the last one must have a data length divisible by 8 because the
Fragment Offset is in units of 8 bytes.
The last fragment can be any length (not necessarily divisible by 8).

Example:
Suppose we have a packet of 3000 bytes, and we need to fragment it
(ignoring header sizes for now):
• Let's say MTU allows 1000 bytes of data per fragment.
• So you split into:
• Fragment 1: Bytes 0–999 → Length = 1000 (divisible by 8)
• Fragment 2: Bytes 1000–1999 → Length = 1000 divisible by 8)
• Fragment 3: Bytes 2000–2999 → Length = 1000 (divisible by 8)
But if the packet had 3012 bytes:
• Fragment 1 = 1000
• Fragment 2 = 1000
• Fragment 3 = 1000
• Fragment 4 = 12 (not divisible by 8 — but okay because it’s the last
fragment)
Fragmentation
The 3-bit flags field defines three flags.
• The leftmost bit is reserved (not used).
• The second bit (D 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 (M 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.

62
• The "Fragment Offset" field tells where each fragment’s data belongs in the
original datagram.

• The 13-bit fragmentation offset field shows the relative position of this fragment
with respect to the whole datagram.
• It is the offset of the data in the original datagram measured in units of 8 bytes.
• Datagram with a data size of 4000 bytes (numbered 0 to 3999) fragmented into
three fragments.
• The first fragment carries bytes 0 to 1399. The offset for this datagram is 0/8 = 0.
• The second fragment carries bytes 1400 to 2799; the offset value for this fragment
is 1400/8 = 175.
• Finally, the third fragment carries bytes 2800 to 3999. The offset value for this
fragment is 2800/8 = 350.

63
explanation
Fragment 1
• Carries bytes 0 to 1399
• This fragment starts at byte 0
• Offset = 0 ÷ 8 = 0
So, Fragment Offset = 0
→ This means: "My data starts at the beginning of the original datagram."
Fragment 2
• Carries bytes 1400 to 2799
• This fragment starts at byte 1400
• Offset = 1400 ÷ 8 = 175
So, Fragment Offset = 175
→ This means: "My data starts at the 175th 8-byte block = byte 1400."
Fragment 3
• Carries bytes 2800 to 3999
• Starts at byte 2800
• Offset = 2800 ÷ 8 = 350
So, Fragment Offset = 350
→ This means: "My data starts at the 350th 8-byte block = byte 2800."
Fragmentation
• The original packet starts
at the client; the
fragments are
reassembled at the Server
• M bit set for all fragments
except the last
• the second fragment is
itself fragmented later
into two fragments of 800
bytes and 600 bytes, but
the offset shows the
relative position of the
fragments to the original
data.

65
Problems
1. An IP router with a Maximum Transmission Unit (MTU)
of 200 bytes has received an IP packet of size 520 bytes
with an IP header of length 20 bytes. The values of the
relevant fields in the IP header.

2. A datagram of size 3000B (20B header+2980B payload)


reached at the router and must be forwarded to the link
with MTU of 500B. How many fragments will be
generated and also write MF, offset and total length for
each fragment.
Fragmentation - example
• A packet has arrived with an M bit value of 0. Is this the
first fragment, the last fragment, or a middle fragment? Do
we know if the packet was fragmented?
◦ If the M bit is 0, it means that there are no more fragments; the
fragment is the last one.
◦ However, we cannot say if the original packet was fragmented or
not.
◦ A nonfragmented packet is considered the last fragment.

67
Fragmentation - example
• A packet has arrived with an M bit value of 1. Is this the
first fragment, the last fragment, or a middle fragment? Do
we know if the packet was fragmented?
◦ If the M bit is 1, it means that there is at least one more fragment.
◦ This fragment can be the first one or a middle one, but not the last
one.
◦ We don’t know if it is the first one or a middle one; we need more
information (the value of the fragmentation offset).

68
Fragmentation - example
• A packet has arrived with an M bit value of 1 and a
fragmentation offset value of 0. Is this the first fragment,
the last fragment, or a middle fragment?
◦ Because the M bit is 1, it is either the first fragment or a middle
one.
◦ Because the offset value is 0, it is the first fragment.

69
Fragmentation - example
• A packet has arrived in which the offset value is 100. What
is the number of the first byte? Do we know the number of
the last byte?
◦ To find the number of the first byte, we multiply the offset value by
8.
◦ This means that the first byte number is 800.
◦ We cannot determine the number of the last byte unless we know
the length of the data.

70
Fragmentation - example
• A packet has arrived in which the offset value is 100, the
value of HLEN is 5, and the value of the total length field is
100. What are the numbers of the first byte and the last
byte?
◦ The first byte number is 100 ×8 = 800.
◦ The total length is 100 bytes, and the header length is 20 bytes (5 ×
4), which means that there are 80 bytes in this datagram.
◦ If the first byte number is 800, the last byte number must be 879.

71

You might also like