Network Layer
Network Layer
Module 4
IPV4 ADDRESSES
• The identifier used in the IP layer of the TCP/IP protocol suite to identify the
connection of each device to the Internet is called the Internet address or 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.
• IPv4 addresses are unique in the sense that each address defines one, and only
one, connection to the Internet.
• If a device has two connections to the Internet, via two networks, it has two IPv4
addresses.
• IPv4 addresses are universal in the sense that the addressing system must be
accepted by any host that wants to be connected to the Internet.
Address Space
• A protocol like IPv4 that defines addresses has an address space.
• An address space is the 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 232
or 4,294,967,296 (more than four billion).
Notation
• There are three common notations to show an IPv4 address
• Binary notation (base 2), dotted-decimal notation (base 256), and hexadecimal notation (base 16).
• In binary notation, an IPv4 address is displayed as 32 bits.
• To make the address more readable, one or more spaces are usually inserted between each octet (8
bits).
• To make the IPv4 address more compact and easier to read, it is usually written in decimal form with a
decimal point (dot) separating the bytes.
• This format is referred to as dotted-decimal notation.
• Note that because each byte (octet) is only 8 bits, each number in the dotted-decimal notation is
between 0 and 255.
• We sometimes see an IPv4 address in hexadecimal notation. Each hexadecimal digit is equivalent to
four bits.
• This means that a 32-bit address has 8 hexadecimal digits. This notation is often used in network
programming
Notation
• A 32-bit IPv4 address is divided into two parts.
• The first part of the address, called the prefix, defines
the network;
• the second part of the address, called the suffix, defines
the node
• A prefix can be fixed length or variable length.
• The network identifier in the IPv4 was first designed as
a fixed-length prefix.
• This scheme, which is now obsolete, is referred to as
classful addressing.
• The new scheme, which is referred to as classless
addressing, uses a variable-length network prefix
Classful Addressing
• When the Internet started, an IPv4 address was designed with a fixed-
length prefix, but to accommodate both small and large networks,
three fixed-length prefixes were designed instead of one (n = 8, n =
16, and n = 24).
• The whole address space was divided into five classes (class A, B, C, D,
and E)
Classful Addressing
Classful Addressing
Address Depletion
• The reason that classful addressing has become obsolete is address depletion.
• Since the addresses were not distributed properly, the Internet was faced with the problem of the addresses
being rapidly used up, resulting in no more addresses available for organizations and individuals that needed to
be connected to the Internet.
• To understand the problem, let us think about class A. This class can be assigned to only 128 organizations in the
world, but each organization needs to have a single network (seen by the rest of the world) with 16,777,216
nodes (computers in this single network).
• Since there may be only a few organizations that are this large, most of the addresses in this class were wasted
(unused).
• Class B addresses were designed for midsize organizations, but many of the addresses in this class also remained
unused.
• Class C addresses have a completely different flaw in design.
• The number of addresses that can be used in each network (256) was so small that most companies were not
comfortable using a block in this address class.
• Class E addresses were almost never used, wasting the whole class.
Subnetting and Super-netting
• To alleviate address depletion, two strategies were proposed and, to some
extent, implemented: subnetting and super-netting.
• In subnetting, a class A or class B block is divided into several subnets.
• Each subnet has a larger prefix length than the original network.
• For example, if a network in class A is divided into four subnets, each subnet
has a prefix of nsub = 10.
• At the same time, if all of the addresses in a network are not used, subnetting
allows the addresses to be divided among several organizations.
• This idea did not work because most large organizations were not happy
about dividing the block and giving some of the unused addresses to smaller
organizations.
Subnetting
Subnetting and Super-netting
• While subnetting was devised to divide a large block into smaller ones,
super-netting was devised to combine several class C blocks into a larger
block to be attractive to organizations that need more than the 256
addresses available in a class C block.
• This idea did not work either because it makes the routing of packets more
difficult.
Classless Addressing
• Class privilege was removed from the distribution to compensate for the address
depletion.
• In 1996, the Internet authorities announced a new architecture called classless
addressing.
• In classless addressing, variable-length blocks are used that belong to no classes.
• We can have a block of 1 address, 2 addresses, 4 addresses, 128 addresses, and
so on.
• In classless addressing, the whole address space is divided into variable length
blocks.
• The prefix in an address defines the block (network); the suffix defines the node
(device).
Classless Addressing
• Unlike classful addressing, the prefix length in classless addressing is variable.
• We can have a prefix length that ranges from 0 to 32.
• The size of the network is inversely proportional to the length of the prefix.
• A small prefix means a larger network; a large prefix means a smaller network.
• We need to emphasize that the idea of classless addressing can be easily
applied to classful addressing.
• An address in class A can be thought of as a classless address in which the
prefix length is 8.
• An address in class B can be thought of as a classless address in which the
prefix is 16, and so on
Classless Addressing
• Prefix Length: Slash Notation
• Since the prefix length is not inherent in the address, we need to
separately give the length of the prefix.
• In this case, 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 Inter-Domain Routing or CIDR
Classless Addressing
A classless address is given as 167.199.170.82/27. We can find the above three pieces of information as follows.
The number of addresses in the network is 232 − n = 25 = 32 addresses.
Classless Addressing
20.35
IPv4 datagram format
20.36
Version Number.
• The 4-bit version number (VER) field defines the version of the IPv4 protocol, which, obviously, has the
value of 4.
Header Length.
• The 4-bit header length (HLEN) field defines the total length of the datagram header in 4-byte words.
• The IPv4 datagram has a variable-length header.
• When a device receives a datagram, it needs to know when the header stops and the data, which is
encapsulated in the packet, starts.
• However, to make the value of the header length (number of bytes) fit in a 4-bit header length, the total
length of the header is calculated as 4-byte words. The total length is divided by 4 and the value is inserted
in the field. The receiver needs to multiply the value of this field by 4 to find the total length.
Service type or differentiated services
20.38
Types of service
20.39
Default types of service
20.40
Differentiated services
20.41
Total length
• field defines the total length of the datagram including the header.
Time-to-live
• Due to some malfunctioning of routing protocols a datagram may be circulating in the Internet, visiting some
networks over and over without reaching the destination.
• This may create extra traffic in the Internet.
• The 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 field and encapsulated data
Protocol values
20.43
Header checksum
• IP is not a reliable protocol
• it does not check whether the payload carried by a datagram is corrupted during the
transmission.
• IP puts the burden of error checking of the payload on the protocol that owns the payload,
such as UDP or TCP.
• The datagram header, however, is added by IP, and its error-checking is the responsibility of
IP.
• Errors in the IP header can be a disaster.
• For example, if the destination IP address is corrupted, the packet can be delivered to the
wrong host.
Example of checksum calculation in IPv4
20.45
Example 1
Solution
There is an error in this packet. The 4 leftmost bits (0100)
show the version, which is correct. The next 4 bits (0010)
show an invalid header length (2 × 4 = 8). The minimum
number of bytes in the header must be 20. The packet has
been corrupted in transmission.
20.46
Example 2
Solution
The HLEN value is 8, which means the total number of
bytes in the header is 8 × 4, or 32 bytes. The first 20 bytes
are the base header, the next 12 bytes are the options.
20.47
Example 3
Solution
The HLEN value is 5, which means the total number of
bytes in the header is 5 × 4, or 20 bytes (no options). The
total length is 40 bytes, which means the packet is
carrying 20 bytes of data (40 − 20).
20.48
Example 4
Solution
To find the time-to-live field, we skip 8 bytes. The time-to-
live field is the ninth byte, which is 01. This means the
packet can travel only one hop. The protocol field is the
next byte (02), which means that the upper-layer protocol
is IGMP.
20.49
Identification, Flags, and Fragmentation Offset
• When a datagram is fragmented, the value in the identification field is copied into all fragments.
• In other words, all fragments have the same identification number, which is also the same as the original
datagram.
• The identification number helps the destination in reassembling the datagram.
• It knows that all fragments having the same identification value should be assembled into one 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.
Fragmentation example
20.53
Detailed fragmentation example
20.54
Example 5
Solution
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
non-fragmented packet is considered the last fragment.
20.55
Example 6
Solution
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).
20.56
Example 7
Solution
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.
20.57
Taxonomy of options in IPv4
20.58
IPv6
• The network layer protocol in the TCP/IP protocol suite
is currently IPv4.
• Although IPv4 is well designed, data communication has
evolved since the inception of IPv4 in the 1970s.
• The main reason for migration from IPv4 to IPv6 is the
small size of the address space in IPv4.
• An IPv6 address is 128 bits or 16 bytes (octets) long,
four times the address length in IPv4.
• The address space of IPv6 contains 2128 addresses
20.59
IPv6 datagram header and payload
20.60
Format of an IPv6 datagram
20.61
❑ Version.
The 4-bit version field defines the version number of the IP. For IPv6, the value is 6.
❑ 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. A flow label can be used to speed up the processing of a packet by a router. When a router
receives a packet, instead of consulting the forwarding table and going through a routing algorithm
to define the address of the next hop, it can easily look in a flow label table for the next hop.
❑ Payload length.
The 2-byte payload length field defines the length of the IP datagram excluding the header. Note
that IPv4 defines two fields related to the length: header length and total length. In IPv6, the length
of the base header is fixed (40 bytes); only the length of the payload needs to be defined.
❑ Next header.
The next header is an 8-bit field defining the type of the first extension 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
❑ Hop limit.
The 8-bit hop limit field serves the same purpose as the TTL field in IPv4.
Next header codes for IPv6 Priorities for congestion-controlled traffic
20.63
Network Address Resolution (NAT)
• A technology that can provide the mapping between the private and universal addresses is Network Address
Translation (NAT).
• The technology allows a site to use a set of private addresses for internal communication and a set of global
Internet addresses (at least one) for communication with the rest of the world.
• The site must have only one connection to the global Internet through a NAT-capable router that runs NAT
software