UNIT -3
Network Layer
11.1
Introduction to Network Layer
• Network layer is responsible for the host-to-host delivery of
datagrams.
• It provides services to the transport layer and receives services
from the data-link layer.
❑ Network-layer Services
✓ Packetizing
✓ Routing and Forwarding
✓ Other Services
• Error Control
• Flow Control
• Congestion Control
• Quality of Service
• Security
11.2
11.3
❑ Packetizing
▪ Packetizing
Encapsulating the payload (data received from upper layer) in a
network-layer packet at the source and decapsulating the payload
from the network-layer packet at the destination.
• The source host receives the payload from an upper-layer protocol,
adds a header that contains the source and destination addresses and
some other information that is required by the network-layer protocol
and delivers the packet to the data-link layer.
• The source is not allowed to change the content of the payload unless
it is too large for delivery and needs to be fragmented.
• The destination host decapsulates the packet, and delivers the payload
to the corresponding upper-layer protocol.
• If the packet is fragmented at the source or at routers along the path,
the network layer is responsible for waiting until all fragments arrive,
reassembling them, and delivering them to the upper-layer protocol.
11.4
• The routers in the path are not allowed to decapsulate the packets
they received unless the packets need to be fragmented.
• The routers are not allowed to change source and destination
addresses either.
• They just inspect the addresses for the purpose of forwarding the
packet to the next network on the path.
11.5
❑ Routing and Forwarding
➢ Routing
• The network layer is responsible for routing the packet from its
source to the destination.
• A physical network is a combination of networks (LANs and WANs)
and routers that connect them.
• The network layer is responsible for finding the best one among these
possible routes. The network layer needs to have some specific
strategies for defining the best route.
➢ Forwarding
• forwarding can be defined as the action applied by each router when
a packet arrives at one of its interfaces.
• The decision-making table a router normally uses for applying this
action is sometimes called the forwarding table and sometimes the
routing table.
11.6
• To make this decision, the router uses a piece of information in the
packet header, which can be the destination address or a label, to find
the corresponding output interface number in the forwarding table.
11.7
❑ Other Services
➢ Error Control:
• Although error control also can be implemented in the network
layer, the designers of the network layer in the Internet ignored this
issue for the data being carried by the network layer.
• One reason for this decision is the fact that the packet in the
network layer may be fragmented at each router, which makes error
checking at this layer inefficient.
• Internet uses an auxiliary protocol, ICMP, that provides some kind
of error control if the datagram is discarded.
➢ Flow Control
• It regulates the amount of data a source can send without
overwhelming the receiver.
• The network layer in the Internet, however, does not directly
provide any flow control.
11.8
➢ Congestion Control
• Congestion in the network layer is a situation in which too many
datagrams are present in an area of the Internet.
• Congestion may occur if the number of datagrams sent by source
computers is beyond the capacity of the network or routers.
➢ Quality of Service
• As the Internet has allowed new applications such as multimedia
communication (in particular real-time communication of audio and
video), the quality of service (QoS) of the communication has
become more and more important.
➢ Security
• To provide security for a connectionless network layer, we need to
have another virtual level that changes the connectionless service to a
connection-oriented service.
11.9
❑ PACKET SWITCHING
• Data communication switching techniques are divided into two
broad categories, circuit switching and packet switching.
• Packet switching is used at the network layer because the unit of
data at this layer is a packet.
• Circuit switching is mostly used at the physical layer;
• Packet-switched network can use two different approaches to route
the packets: the datagram approach and the virtual circuit
approach.
11.10
❑ Datagram Approach: Connectionless Service
• Network layer provides a connectionless service, each packet
traveling in the Internet is an independent entity; there is no
relationship between packets belonging to the same message.
• The switches in this type of network are called routers.
• A packet belonging to a message may be followed by a packet
belonging to the same message or to a different message.
• A packet may be followed by a packet coming from the same or
from a different source.
• Each packet is routed based on the information contained in its
header: source and destination addresses.
• The destination address defines where it should go; the source
address defines where it comes from.
11.11
❑ Datagram Approach: Connectionless Service
• The router in this case routes the packet based only on the
destination address. The source address may be used to send an
error message to the source if the packet is discarded.
11.12
❑ Datagram Approach: Connectionless Service
11.13
❑ Virtual-Circuit Approach: Connection-Oriented Service
• In a connection-oriented service (also called virtual-circuit
approach), there is a relationship between all packets belonging to a
message.
• Before all datagrams in a message can be sent, a virtual connection
should be set up to define the path for the datagrams.
• After connection setup, the datagrams can all follow the same path.
• In this type of service, not only must the packet contain the source
and destination addresses, it must also contain a flow label, a virtual
circuit identifier that defines the virtual path the packet should
follow.
• Each packet is forwarded based on the label in the packet.
11.14
11.15
• To create a connection-oriented service, a three-phase process is used:
setup, data transfer, and teardown.
• In the setup phase, the source and destination addresses of the sender
and receiver are used to make table entries for the connection-
oriented service.
• In the teardown phase, the source and destination inform the router to
delete the corresponding entries.
• Data transfer occurs between these two phases.
➢ Setup Phase:
• In the setup phase, a router creates an entry for a virtual circuit.
• Two auxiliary packets need to be exchanged between the sender
and the receiver: the request packet and the acknowledgment
packet.
Request packet:
• A request packet is sent from the source to the destination. This
auxiliary packet carries the source and destination addresses.
Acknowledgment Packet:
• A special packet, called the acknowledgment packet, completes
the entries in the switching tables.
11.17
11.18
11.19
➢ Data-Transfer Phase:
• After all routers have created their forwarding table for a specific
virtual circuit, then the network-layer packets belonging to one
message can be sent one after another.
➢ Teardown Phase:
• In the teardown phase, source A, after sending all packets to B,
sends a special packet called a teardown packet.
• Destination B responds with a confirmation packet.
• All routers delete the corresponding entries from their tables.
11.20
11.21
❑ Network-layer Performance
• The performance of a network can be measured in terms of delay,
throughput, and packet loss.
➢ Delay:
• The delays in a network can be divided into four types: transmission
delay, propagation delay, processing delay, and queuing delay.
1. Transmission Delay:
A sender needs to put the bits in a packet on the line one by one. If the
first bit of the packet is put on the line at time t1 and the last bit is put on
the line at time t2, transmission delay of the packet is (t2 − t1).
11.22
2. Propagation Delay:
Propagation delay is the time it takes for a bit to travel from point A to
point B in the transmission media.
3. Processing Delay:
The processing delay is the time required for a router or a destination
host to receive a packet from its input port, remove the header,
perform an error detection procedure, and deliver the packet to the
output port (in the case of a router) or deliver the packet to the upper-
layer protocol
11.23
4. Queuing Delay:
The queuing delay for a packet in a router is measured as the time a
packet waits in the input queue and output queue of a router.
Total Delay:
➢ Throughput:
It is defined as the number of bits passing through the point in a second,
which is actually the transmission rate of data at that point.
11.24
❑ IPV4 Addresses
• The identifier used 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.
• If a device has two connections to the Internet, via two networks, it
has two IPv4 addresses.
➢ 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
11.25
• IPv4 uses 32-bit addresses, which means that the address space is 232
or 4,294,967,296.
Notation:
• binary notation (base 2),
• dotted-decimal notation (base 256)
• hexadecimal notation (base 16).
• In binary notation an IPv4 address is displayed as 32 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.
11.26
• A 32-bit IPv4 address is also hierarchical, but divided only 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.
11.27
❑ Classful Addressing
• When the Internet started, an IPv4 address was designed with a fixed-
length prefix, later classful addressing was considered with three
fixed length group ( n=8, 16, 24).
• Address Depletion
• Subnetting and Supernetting
11.28
❑ 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).
• Prefix length in classless addressing is variable 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.
➢ Prefix Length: Slash Notation
• 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 interdomain routing or CIDR strategy.
➢ Extracting Information from an Address
1. The number of addresses in the block is found as N = 2
2. To find the first address, we keep the n leftmost bits and set the
(32 − n) rightmost bits all to 0s.
3. To find the last address, we keep the n leftmost bits and set the
(32 − n) rightmost bits all to 1s.
➢ Address Mask:
• The address mask is a 32-bit number in which the n leftmost bits are set
to 1s and the rest of the bits (32 − n) are set to 0s.
• A computer can easily find the address mask because it is the
complement of (232 – n -1).
• Different blocks can be found using below steps:
1. The number of addresses in the block N = NOT (mask) + 1.
2. The first address in the block = (Any address in the block) AND
(mask).
3. The last address in the block = (Any address in the block) OR
[(NOT (mask)].
➢ Caseless Addressing Also Uses:
• Network Address
• Block Allocation
• Subnetting
• Address Aggregation
➢ Special Addresses
• This-host Address
The only address in the block [Link]/32 is called the this-host
address.
• Limitted Broadcast Address
The block [Link]/32 is called the limited-broadcast
address.
• Loopback Address
The block [Link]/8 is called the loopback address.
• Private & Multicast Address
UNIT -3
Network Layer Protocols
11.33
Introduction
• Internet Protocol version 4 (IPv4): is responsible for
packetizing, forwarding, and delivery of a packet at the network
layer.
• Internet Control Message Protocol version 4 (ICMPv4): helps
IPv4 to handle some errors that may occur in the network-layer
delivery.
• Internet Group Management Protocol (IGMP): is used to help
IPv4 in multicasting.
• Address Resolution Protocol (ARP): is used to glue the network
and data-link layers in mapping network-layer addresses to link-
layer addresses.
11.34
❑ Internet Protocol version 4 (IPv4)
• IPv4 is an unreliable datagram protocol—a best-effort delivery
service.
• If reliability is important, IPv4 must be paired with a reliable
transport-layer protocol such as TCP.
• IPv4 is also 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.
Datagram Format
• Packets used by the IP are called datagrams. A datagram is a
variable-length packet consisting of two parts: header and payload
(data).
• The header is 20 to 60 bytes in length and contains information
essential to routing and delivery.
11.35
11.36
1. Version Number: The 4-bit version number (VER) field defines the
version of the IPv4 protocol.
2. 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.
3. Service Type: In the original design of the IP header, this field was
referred to as type of service (TOS), which defined how the
datagram should be handled.
4. Total Length: This 16-bit field defines the total length (header plus
data) of the IP datagram in bytes. A 16-bit number can define a total
length of up to 65,535.
11.37
5. 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.
6. Time-to-live: Due to some malfunctioning of routing protocols
(discussed later) 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.
7. Protocol: In TCP/IP, the data section of a packet, called the
payload, carries the whole packet from another protocol. A
datagram, for example, can carry a packet belonging to any
transport-layer protocol such as UDP or TCP.
11.38
8. 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.
9. Source and Destination Addresses. These 32-bit source and
destination address fields define the IP address of the source and
destination respectively.
10. Options: A datagram header can have up to 40 bytes of options.
Options can be used for network testing and debugging.
11. Payload: Payload, or data, is the main reason for creating a
datagram. Payload is the packet coming from other protocols that
use the service of IP.
11.39
❑ ICMPv4
• The IPv4 has no error-reporting or error-correcting mechanism.
• The IP protocol also lacks a mechanism for host and management
queries.
• ICMPv4 is designed to compensate for the above two deficiencies.
➢ Messages
• ICMP messages are divided into two broad categories: error-
reporting messages and query messages.
• The error-reporting messages report problems that a router or a host
(destination) may encounter when it processes an IP packet.
• The query messages, which occur in pairs, help a host or a network
manager get specific information from a router or another host.
11.40
• An ICMP message has an 8-byte header and a variable-size data
section.
• The first 4 bytes are common to all.
• The first field, ICMP type, defines the type of the message.
• The code field specifies the reason for the particular message type.
• The last common field is the checksum field. The rest of the header is
specific for each message type.
11.41
• The data section in error messages carries information for finding
the original packet that had the error.
• In query messages, the data section carries extra information based
on the type of query.
11.42
❑ Unicast Routing
• The goal of the network layer is to deliver a datagram from its
source to its destination or destinations.
• If a datagram is destined for only one destination (one-to-one
delivery), we have unicast routing. If the datagram is destined for
several destinations (one-to-many delivery), we have multicast
routing.
Least-Cost Routing
When an internet is modeled as a weighted graph, one of the ways to
interpret the best route from the source router to the destination router
is to find the least cost between the two.
11.43
❑ Routing Algorithms
✓ Distance-Vector Routing
✓ Link-State Routing
✓ Path-Vector Routing
➢ Distance-Vector Routing
• The distance-vector (DV) routing is used find the best route.
• In distance-vector routing, the first thing each node creates is its
own least-cost tree with the rudimentary information it has about its
immediate neighbors.
• The incomplete trees are exchanged between immediate neighbors
to make the trees more and more complete and to represent the
whole internet.
Bellman-Ford Equation
• The heart of distance-vector routing is the famous Bellman-Ford
equation.
• This equation is used to find the least cost (shortest distance)
between a source node, x, and a destination node, y, through some
intermediary nodes (a, b, c, . . .)
• when the costs between the source and the intermediary nodes and
the least costs between the intermediary nodes and the destination
are given. The following shows the general case in which Dij is the
shortest distance and cij is the cost between nodes i and j.
11.45
Distance Vectors
• A least-cost tree is a combination of least-cost paths from the root
of the tree to all destinations. These paths are graphically glued
together to form the tree.
• Distance-vector routing unglues these paths and creates a distance
vector, a one-dimensional array to represent the tree.
• A distance vector does not give the path to the destinations as the
least-cost tree does; it gives only the least costs to the destinations.
11.46
• Each node in an internet, when it is booted, creates a very
rudimentary distance vector with the minimum information the node
can obtain from its neighborhood.
• The node sends some greeting messages out of its interfaces and
discovers the identity of the immediate neighbors and the distance
between itself and each neighbor.
11.47
11.48
➢ Link-State Routing
• This method uses the term link-state to define the characteristic of a
link (an edge) that represents a network in the internet.
• In this algorithm the cost associated with an edge defines the state
of the link.
• Links with lower costs are preferred to links with higher costs; if the
cost of a link is infinity, it means that the link does not exist or has
been broken.
• The collection of states for all links is called the link-state
database (LSDB).
• There is only one LSDB for the whole internet; each node needs to
have a duplicate of it to be able to create the least-cost tree.
11.49
• The LSDB can be represented as a two-dimensional array(matrix) in
which the value of each cell defines the cost of the corresponding
link.
11.50
11.19
Formation of Least-Cost Trees
• To create a least-cost tree for itself, using the shared LSDB, each
node needs to run the famous Dijkstra Algorithm. This iterative
algorithm uses the following steps:
1. The node chooses itself as the root of the tree, creating a tree with a
single node, and sets the total cost of each node based on the information
in the LSDB.
2. The node selects one node, among all nodes not in the tree, which is
closest to the root, and adds this to the tree. After this node is added to
the tree, the cost of all other nodes not in the tree needs to be updated
because the paths may have been changed.
3. The node repeats step 2 until all nodes are added to the tree.
11.21
Least Cost Tree
11.20
➢ Path-Vector Routing
• Least-cost routing does not prevent a packet from passing through
an area when that area is in the least-cost path.
• Path-vector routing does not have the drawbacks of LS or DV
routing.
• The best route is determined by the source using the policy it
imposes on the route. In other words, the source can control the
path.
• In path-vector routing, the path from a source to all destinations is
also determined by the best spanning tree.
• If there is more than one route to a destination, the source can
choose the route that meets its policy best.
• One of the common policies uses the minimum number of nodes to
be visited (something similar to least-cost). Another common policy
is to avoid some nodes as the middle node in a route.
11.54
11.55
11.56
❑ IPv6 PROTOCOL
➢ Packet Format
11.57
• Each packet is composed of a base header followed by the payload.
• The base header occupies 40 bytes, whereas payload can be up to
65,535 bytes of information.
The description of fields:
❑ 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.
11.58
❑ 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.
11.59
❑ Source and destination addresses. The source address field is a 16-
byte (128-bit) Internet address that identifies the original source of the
datagram.
The destination address field is a 16-byte (128-bit) Internet address that
identifies the destination of the datagram.
❑ Payload. Compared to IPv4, the payload field in IPv6 has a different
format and meaning:
11.60
• The payload in IPv6 means a combination of zero or more extension
headers (options) followed by the data from other protocols (UDP,
TCP, and so on).
• The payload can have as many extension headers as required by the
situation.
• Each extension header has two mandatory fields, next header and
the length, followed by information related to the particular option.
• Note that each next header field value (code) defines the type of the
next header (hop-by-hop option, source routing option, . . .); the last
next header field defines the protocol (UDP, TCP, . . .) that is carried
by the datagram.
11.61