Network Layer Functions and Protocols
Network Layer Functions and Protocols
Module-3
Network Layer
It provides services to the transport layer and receives services from the
data-link layer.
Packetizing
Encapsulating the payload (data received from upper layer) into 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.
Network layer 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 receives the network-layer packet from its data-link
layer, 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.
Routing
Routing is the process of determining the optimal path for data packets to
travel from the source to the destination across a network. There is more
than one route from the source to the destination. The network layer is
responsible for finding the best one among these possible routes.
Forwarding
When a router receives a packet from one of its attached networks, it needs
to forward the packet to another attached network (in unicast routing) or
to some attached networks (in multicast routing).
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.
Forwarding Process
Error Control
The designers of the network layer in the Internet ignored this issue for the
data being carried by the network layer, 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.
The designers of the network layer, however, have added a checksum field
to the datagram to control any corruption in the header, but not in the
whole datagram.
The checksum may prevent any changes or corruptions in the header of the
datagram.
Internet uses an auxiliary protocol, ICMP, that provides some kind of error
control if the datagram is discarded or has some unknown information in
the header.
Flow Control
To control the flow of data, the receiver needs to send some feedback to
the sender to inform the latter that it is overwhelmed with data.
The network layer in the Internet, however, does not directly provide any
flow control.
Congestion Control
As more datagrams are dropped, the situation may become worse because,
due to the error control mechanism at the upper layers, the sender may
send duplicates of the lost packets.
Quality of Service
the quality of service (QoS) of the communication has become more and
more important.
Security
Packet Switching
The packets in this approach along with source and destination address
should have a flow label, a virtual circuit identifier (VCI) that defines
the virtual path the packet should follow.
A request packet is sent from the source to the destination. This auxiliary
packet carries the source and destination addresses. The process shown
below.
Router R3 receives the setup request packet. The same events happen here
as at router R1; three columns of the table are completed: in this case,
incoming port (1), incoming label (66), and outgoing port (3).
Router R4 receives the setup request packet. Again, three columns are
completed: incoming port (1), incoming label (22), and outgoing port (4).
Acknowledgment Packet
The source uses this as the outgoing label for the data packets to be sent
to destination B.
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.
The source computer uses the label 14, which it has received from router
R1 in the setup phase. Router R1 forwards the packet to router R3, but
changes the label to 66.
Router R3 forwards the packet to router R4, but changes the label to 22.
Finally, router R4 delivers the packet to its final destination with the label
77.
All the packets in the message follow the same sequence of labels, and the
packets arrive in order at the destination.
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.
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 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.
Address Space
Hierarchy in addressing
Classful Addressing
Classful addressing is an early method of IP address allocation that divided
the IP address space into several classes based on fixed lengths.
Class A
Network length, n = 8
First bit is reserved with a value 0
With remaining 7 bits we can have 27 = 128, networks in the world that
can have class A address.
Class B
Network length, n = 16
First 2 bit is reserved with a value 10
With remaining 14 bits we can have 214 = 16,384 networks in the world
that can have a class B address.
Class C
Network length, n = 24
First 3 bit is reserved with a value 110
With remaining 21 bits we can have 221 = 2,097,152 networks in the world
that can have a class B address.
Class D
It is not divided into prefix and suffix
Starts with 1110, used for multicast addressing
Class E
It is not divided into prefix and suffix
Starts with 1111, reserved for future use.
Address Depletion
Classful addressing has become obsolete, since the addresses were not
distributed properly.
Consider class A, it can be assigned to only 128 organizations in the world,
but each organization needs to have a single network with 16,777,216
nodes. Since there can be only few organizations that can have around
16,777,216 nodes most of the addresses in this class are wasted.
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.
Classless Addressing
In classless addressing, variable-length blocks are used that belong to no
classes. The prefix length in classless addressing is variable. The notation
used to represent classless addressing is known as slash notation or CIDR
(Classless Inter Domain Routing).
The last address can be found by keeping the first 27 bits and changing
the rest of the bits to 1s.
Address Mask
Another way to find the first and last addresses in the block is to use the
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.
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)]
Example:
A classless address is given as [Link]/27
Mask : [Link] : 11111111 11111111 11111111 11100000
Not(Mask) : 00000000 00000000 00000000 00000111
Not(Mask) + 1 : 00000000 00000000 00000000 00001000 = 32
To find first address
Lets take one address in the block as [Link]
[Link] : 101001011 11000111 10101010 01010010
Mask : 11111111 11111111 11111111 11100000
[Link] AND Mask we get
[Link] : 101001011 11000111 10101010 01000000
To find last address
[Link] : 101001011 11000111 10101010 01010010
Not Mask : 00000000 00000000 00000000 00011111
[Link]: 101001011 11000111 10101010 01011111
Network Address
From the destination address we can find network address the router
consults its forwarding table to find the corresponding interface from which
the packet should be sent out.
Designing Subnets
To guarantee the proper operation of the subnetworks following rules need
to be considered.
• The number of addresses in each subnetwork should be a power of
2.
• The prefix length for each subnetwork should be found using the
following formula: nsub = 32 − log2Nsub
• 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.
Example
An organization is granted a block of addresses with the beginning address
[Link]/24. The organization needs to have 3 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.
Solution :
There are 232 – 24 = 256 addresses in this block. The first address is
[Link]/24; the last address is [Link]/24. To satisfy the third
requirement, we assign addresses to subblocks, starting with the largest
and ending with the smallest one.
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 −log2128 = 25. The first address
in this block is [Link]/25; the last address is [Link]/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 − log264 = 26. The
first address in this block is [Link]/26; the last address is
[Link]/26.
Address Aggregation
When blocks of addresses are combined to create a larger block, routing
can be done based on the prefix of the larger block.
ICANN (Internet Corporation for Assigned Names and Numbers) 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.
Special Addresses
• This-host Address - The only address in the block [Link]/32 is called
the this-host address. It is used whenever a host needs to send an
IP datagram but it does not know its own address to use as the source
address.
• Limited-broadcast Address - The only address in the block
[Link]/32 is called the limited-broadcast address. It is
used whenever a router or a host needs to send a datagram to all
devices in a network.
• Loopback Address - The block [Link]/8 is called the loopback
address. A packet with one of the addresses in this block as the
destination address never leaves the host; it will remain in the host.
• Private Addresses - Four blocks are assigned as private addresses:
[Link]/8, [Link]/12, [Link]/16, and [Link]/16.
• Multicast Addresses - The block [Link]/4 is reserved for multicast
addresses.
field. If the tag field is 53, the value field defines one of the 8 message
types shown in below
Option format
DHCP Operation
This message is encapsulated in a UDP user datagram with the source port
set to 68 and the destination port set to 67. The user datagram is
encapsulated in an IP datagram with the source address set to [Link] (“this
host”) and the destination address set to [Link] (broadcast
address).
The DHCP server responds with a DHCPOFFER message in which the your
address field defines the offered IP address for the joining host and the
server address field includes the IP address of the server. The message also
includes the lease time for which the host can keep the IP address. This
message is encapsulated in a user datagram with the same port numbers,
but in the reverse order. The user datagram in turn is encapsulated in a
datagram with the server address as the source IP address, but the
destination address is a broadcast address.
The joining host receives one or more offers and selects the best of them.
The joining host then sends a DHCPREQUEST message to the server that
has given the best offer. The fields with known value are set. The message
is encapsulated in a user datagram with port numbers as the first message.
The user datagram is encapsulated in an IP datagram with the source
address set to the new client address, but the destination address still is
set to the broadcast address to let the other servers know that their offer
was not accepted.
Finally, the selected server responds with a DHCPACK message to the client
if the offered IP address is valid. If the server cannot keep its offer (for
example, if the address is offered to another host in between), the server
sends a DHCPNACK message and the client needs to repeat the process.
This message is also broadcast to let other servers know that the request
is accepted or rejected.
Well known ports (67 and 68) are used to indicate that the message is
DHCP message.
The server does not send all of the information that a client may need for
joining the network. DHCPACK contains pathname of a file in which the client
can find complete information such as the address of the DNS server. The client
can then use a file transfer protocol to obtain the rest of the needed information.
DHCP uses checksum for error detection. DHCP client uses timers and a
retransmission policy if it does not receive the DHCP reply to a request. DHCP
forces the client to use a random number to set its timers to prevent traffic jam.
Transition States
• When the DHCP client first starts, it is in the INIT state (initializing state).
• The client broadcasts a discover message.
• When it receives an offer, the client goes to the SELECTING state.
• While it is there, it may receive more offers.
• After it selects an offer, it sends a request message and goes to the
REQUESTING state.
• If an ACK arrives while the client is in this state, it goes to the BOUND
state and uses the IP address.
• When the lease is 50 percent expired, the client tries to renew it by moving
to the RENEWING state.
• If the server renews the lease, the client moves to the BOUND state again.
• If the lease is not renewed and the lease time is 75 percent expired, the
client moves to the REBINDING state.
• If the server agrees with the lease (ACK message arrives), the client moves
to the BOUND state and continues using the IP address; otherwise, the client
moves to the INIT state and requests another IP address.
Address Translation
• All of the outgoing packets go through the NAT router, which replaces the
source address in the packet with the global NAT address.
• All incoming packets also pass through the NAT router, which replaces the
destination address in the packet (the NAT router global address) with the
appropriate private address.
Translation Table
• The use of only one global address by the NAT router allows only one
private-network host to access a given external host.
• To remove this restriction, the NAT router can use a pool of global
addresses.
• For example, instead of using only one global address ([Link]), the
NAT router can use four addresses ([Link], [Link], [Link], and
[Link]).
• In this case, four private-network hosts can communicate with the same
external host at the same time because each pair of addresses defines a separate
connection.
Using Both IP Addresses and Port Addresses
• To allow a many-to-many relationship between private-network hosts and
external server programs, we need more information in the translation table.
• For example, suppose two hosts inside a private network with addresses
[Link] and [Link] need to access the HTTP server on external host
[Link].
• If the translation table has five columns, instead of two, that include the
source and destination port addresses and the transport-layer protocol, the
ambiguity is eliminated.
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: 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.
Service Type: It tells how the datagram should be handled.
Total Length: This 16-bit field defines the total length (header plus data) of the
IP datagram in bytes.
Length of data = total length − (HLEN) × 4
Identification, Flags, and Fragmentation Offset: These three fields are related
to the fragmentation of the IP datagram when the size of the datagram is larger
than the underlying network can carry.
Time-to-live : Due to some malfunctioning of routing protocols 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: It defines the higher-level protocol that uses the services of the IP layer.
An IP datagram can encapsulate data from several higher level protocols such as
TCP, UDP, ICMP, and IGMP.
Header checksum: It is used to detect error in the delivery of packet header.
Source and Destination Addresses: 32-bit source and destination address fields
define the IP address of the source and destination respectively.
Options: A datagram header can have up to 40 bytes of options. Options can be
used for network testing and debugging.
Payload: Payload is the packet coming from other protocols that use the service
of IP.
Unicast routing
In unicast routing, a packet is routed, hop by hop, from its source to its destination
by the help of forwarding tables. The source host needs no forwarding table
because it delivers its packet to the default router in its local network. The
destination host needs no forwarding table either because it receives the packet
from its default router in its local network. Only the routers that glue together the
networks in the internet need forwarding tables.
An Internet as a Graph
To find the best route, an internet can be modelled as a graph. A graph in computer
science is a set of nodes and edges (lines) that connect the nodes. To model an
internet as a graph, we can think of each router as a node and each network
between a pair of routers as an edge.
Least-Cost Routing
When an internet is modelled 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.
The best route between A and E is A-B-E, with the cost of 6. This means that each
router needs to find the least-cost route between itself and all the other routers to
be able to route a packet using this criterion.
Least-Cost Trees
If there are N routers in an internet, there are (N − 1) least-cost paths from each
router to any other router. This means we need N × (N − 1) least-cost paths for
the whole internet. If we have only 10 routers in an internet, we need 90 least-
cost paths. A better way to see all of these paths is to combine them in a least-cost
tree. A least-cost tree is a tree with the source router as the root that spans the
whole graph (visits all other nodes) and in which the path between the root and
any other node is the shortest.
ROUTING ALGORITHMS
Distance-Vector Routing
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
Distance-vector routing uses 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.
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-
Dept. of CSE Page 32 of 51 Vemana IT
BCS502 - COMPUTER NETWORKS Module 3 Notes
dimensional array to represent the tree and the corresponding distance vector.
The name of the distance vector defines the root, the indexes define the
destinations, and the value of each cell defines the least cost from the root to the
destination. 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.
Once the initial distance vector is created at a node it sends a copy of the vector
to all its immediate neighbors. After a node receives a distance vector from a
neighbor, it updates its distance vector using the Bellman-Ford equation (second
case).
repeat(forever) {
for(y = 1 to N) {
Count to Infinity
If a link is broken (cost becomes infinity), every other router should be aware of
it immediately, but in distance-vector routing, this takes some time. This problem
is referred to as count to infinity problem.
Two-Node Loop : One example of count to infinity is the two-node loop problem.
To understand the problem, let us look at the scenario, a system with three nodes.
At the beginning, both nodes A and B know how to reach node X.
But suddenly, the link between A and X fails. Node A changes its table.
If B sends its forwarding table to A before receiving A’s forwarding table. Node
A updates its forwarding table.
Now A sends its new update to B. Now B thinks that something has been changed
around A and updates its forwarding table.
Split Horizon
In this strategy, instead of flooding the table through each interface, each node
sends only part of its table through each interface.
If node B thinks that the optimum route to reach X is via A, it does not need to
advertise this piece of information to A.
Node A keeps the value of infinity as the distance to X. Later, when node A sends
its forwarding table to B, node B also corrects its forwarding table.
The system becomes stable after the first update: both node A and node B know
that X is not reachable.
Poison Reverse
Three-Node Instability
The two-node instability can be avoided using split horizon combined with poison
reverse. However, if the instability is between three nodes, stability cannot be
guaranteed.
Link-State Routing
Link-State Routing uses the term link-state to define the characteristic of a link
(an edge) that represents a network in the internet.
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.
To create a least-cost tree with this method, each node needs to have a complete
map of
the network, which means it needs to know the state of each link.
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.
To create a least-cost tree with this method, each node needs to have a complete
map of the network, which means it needs to know the state of each link. 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.
Now the question is how each node can create this LSDB that contains
information about the whole internet.
This can be done by a process called flooding. Each node can send some greeting
messages to all its immediate neighbors (those nodes to which it is connected
directly) to collect two pieces of information for each neighboring node: the
identity of the node and the cost of the link.
The combination of these two pieces of information is called the LS packet (LSP);
the LSP is sent out of each interface for our internet.
When a node receives an LSP from one of its interfaces, it compares the LSP with
the copy it may already have.
If the newly arrived LSP is older than the one it has (found by checking the
sequence number), it discards the newly arrived LSP. If it is newer or the first one
received, the node discards the old LSP (if there is one) and keeps the received
one.
It then sends a copy of it out of each interface except the one from which the
packet arrived.
After receiving all new LSPs, each node creates the comprehensive LSDB.
In the distance-vector routing algorithm, each router tells its neighbors what it
knows about the whole internet; in the link-state routing algorithm, each router
tells the whole internet what it knows about its neighbors.
To create a least-cost tree for itself, using the shared LSDB, each node needs to
run the famous Dijkstra Algorithm.
Dijkstra’s algorithm() {
Tree = {root}
for(y = 1 to N) {
if(y is the root)
D[y] = 0
else if(y is neighbor)
D[y]=c[root][y]
else
D[y]= ∞
}
}
repeat {
find a node w, with D[w] minimum among all nodes not in the Tree
Tree = Tree ∪ {w}
for(every node x, which is neighbor of w and not in the Tree) {
D[x] = min{D[x], (D[w]+c[x][w])}
}
}
In the distance-vector routing algorithm, each router tells its neighbors what it
knows about the whole internet; in the link-state routing algorithm, each router
tells the whole internet what it knows about its neighbors.
Path[y]=empty
}
Sendvector{Path[1],Path[2] .. Path[N] to all neighbors
repeat(forever) {
wait(for Pathw from a neighbor w)
for(y = 1 to N) {
if(Pathw includes myself)
discard the path
else
Path[y]=best{Path[y], (myself + Pathw[y]}
}
if(any change in the vector)
Sendvector{Path[1],Path[2] .. Path[N] to all neighbors
}
}
Unicast Routing Protocols
Routing Information Protocol (RIP)
It is based on distance-vector routing algorithm.
AS (Autonomous System) refers to a collection of IP networks and routers under
the control of a single entity (ISP).
RIP routers advertise the cost of reaching different networks. The cost is defined
between a router and the network in which the destination host is located.
The cost is defined as the number of hops, which means the number of networks
(subnets) a packet needs to travel through from the source router to the final
destination host.
In RIP, the maximum cost of a path can be 15, which means 16 is considered as
infinity.
Forwarding Tables
RIP implementation
RIP is implemented as a process that uses the service of UDP on the well-known
port number 520.
RIP is a routing protocol to help IP route its datagrams through the AS, the RIP
messages are encapsulated inside UDP user datagrams, which in turn are
encapsulated inside IP datagrams. In other words, RIP runs at the application
layer, but creates forwarding tables for IP at the network later.
RIP has gone through two versions: RIP-1 and RIP-2. The second version is
backward compatible with the first section.
RIP Messages
RIP has two types of messages: request and response. A request message is sent
by a router that has just come up
A response (or update) message can be either solicited or unsolicited.
A solicited
response message is sent only in answer to a request message, which has
information about the destination specified in the corresponding request message.
An unsolicited response message, on the other hand, is sent periodically, every 30
seconds or when there is a change in the forwarding table.
Forwarding Tables
Each OSPF router can create a forwarding table after finding the shortest-path
tree between itself and the destination using Dijkstra’s algorithm.
OSPF is implemented as a program in the network layer, using the service of the
IP for propagation.
An IP datagram that carries a message from OSPF sets the value of the protocol
field to 89. OSPF has two versions.
The hello message (type 1) is used by a router to introduce itself to the neighbors
and announce all neighbors that it already knows.
The database description message (type 2) is normally sent in response to the
hello message to allow a newly joined router to acquire the full LSDB.
The link state request message (type 3) is sent by a router that needs information
about a specific LS.
The link-state update message (type 4) is the main OSPF message used for
building the LSDB.
The link-state acknowledgment message (type 5) is used to create reliability in
OSPF.
Each autonomous system in this figure uses one of the two common intradomain
protocols, RIP or OSPF
Border router : The router at the edge of each AS which is connected to a router
at another AS
To enable each router to route a packet to any network in the internet,
Need to install a variation of BGP4, called external BGP (eBGP), on each border
router.
Need to install the second variation of BGP, called internal BGP (iBGP), on all
routers.
Border routers will be running three routing protocols (intradomain, eBGP, and
iBGP)
Other routers will be running two protocols (intradomain and iBGP).
Operation of External BGP (eBGP)
The two routers that run the BGP processes are called BGP peers or BGP
speakers.
Message number 1 is sent by router R1 and tells router R5 that N1, N2, N3, and
N4 can be reached through router R1
Router R5 can now add these pieces of
information at the end of its forwarding table.
For example, in an internet with five ASs, the administrator of AS1 can set the
local preference value of 400 to the path AS1 → AS2 →AS5, the value of 300
to AS1 → AS3 → AS5, and the value of 50 to AS1 → AS4 → AS5.
ATOMIC-AGGREGATE (type 6).
It is an optional attribute.
The destination prefix as not aggregate; it only defines a single destination
network
AGGREGATOR (type 7)
This is an optional transitive attribute
It emphasizes that the destination prefix is an aggregate.