Network Layer (Classless Addressing, Routing Algorithms)
Network Layer (Classless Addressing, Routing Algorithms)
1
Classless Addressing
To overcome address depletion and give more organizations access to
the Internet, classless addressing was designed and implemented.
There are no classes here, but the addresses are still granted in blocks.
Address Blocks
The size of the block (the number of addresses) varies based on the
nature and size of the network. For example,
Households may be given only two addresses;
Large organizations may be given thousands of addresses.
The ISP, may be given thousands or hundreds of thousands based on the
number of customers it may serve.
Classless Addressing: Restrictions
To simplify the handling of addresses, the Internet authorities impose three
restrictions on classless address blocks:
1. The addresses in a block must be contiguous, one after another.
2. The number of addresses in a block must be a power of 2 (I, 2, 4, 8, ... ).
3
11001101 00010000 00100101 00100000
= 3,440,387,360
4
Mask
A better way to define a block of addresses is to select any address in the
block and the mask.
A mask is a 32-bit number in which the n leftmost bits are 1s and the 32 - n
rightmost bits are 0s.
In classless addressing the mask for a block can take any value from 0 to 32.
Example: 205.16.37.39/28
5
Mask
The address and the /n notation completely define the whole block
(the first address, the last address, and the number of addresses).
First Address: The first address in the block can be found by setting the
(32 - n) rightmost bits in the binary notation of the address to 0s.
If we set (32 - 28) = 4 rightmost bits to 1, we get the last address of the block
11001101 00010000 00100101 00011111 or 205.16.37.47
7
Another way to find first, last and number of
addresses in the block
By representing the mask as a 32-bit binary number.
The number
This of addresses
is particularly usefulcan be found
when by complementing
we write a program tothe mask,
find interpreting
these pieces ofit
as a decimal number,
information. and adding
In Example, 1 to
already it.
discussed, the /28 can be represented as
Mask complement: 000000000 00000000 00000000 00001111
11111111 11111111
Number 11111111
of addresses: 11110000 (twenty-eight 1s and four 0s)
15 + 1 =16
The first address can be found by ANDing the given addresses with the mask
205.16.37.32
The last address can be found by ORing the given addresses with the
complement of the mask.
205.16.37.47
8
Network Addresses
When an organization is given a block of addresses, the organization is free to
allocate the addresses to the devices that need to be connected to the
Internet.
The first address in a block is normally not assigned to any device; it is used as
the network address that represents the organization to the rest of the world.
Mostly it is used by routers to direct the message sent to the organization from
the outside world. The organization network is connected to the Internet via a
router.
9
Hierarchy
Like our telephone network, IP addresses also have levels of Hierarchy.
022-27771000 (area code, operator code, exchange office code and phone
number)
An IP address can define only two levels of hierarchy when not subnetted
The prefix is common to all addresses in the network; the suffix changes
from one device to another.
10
Three-Levels of Hierarchy: Subnetting
An organization that is granted a large block of addresses may want to
create clusters of networks (called subnets) and divide the addresses
between the different subnets.
The rest of the world still sees the organization as one entity; however,
internally there are several subnets.
All messages are sent to the router address that connects the organization
to the rest of the Internet; the router routes the message to the
appropriate subnets.
The organization has its own mask; each subnet must also have its own.
11
Example: subnet
Suppose an organization is given the block 17.12.40.0/26, which
contains 64 addresses. The organization has three offices and needs to
divide the addresses into three subblocks of 32, 16, and 16 addresses.
12
Example: subnet
We can find the new masks by using the following rules:
1. Suppose the mask for the first subnet is n1, then 232- n1 must be 32,
i.e. 25 = 32; which means that n1 = 32 - 5 = 27.
2. Suppose the mask for the second subnet is n2, then 232- n2 must be 16,
i.e. 24 = 16; which means that n2 = 32 – 4 = 28.
3. Suppose the mask for the third subnet is n3, then 232- n3 must be 16,
i.e. 24 = 16; which means that n3 = 32 – 4 = 28.
This means that we have the masks 27, 28, 28 with the
organization mask being 26.
Figure shows one configuration for the above scenario.
13
Configuration and addresses in a subnetted network
14
Example with 3 level hierarchy
15
Example 1
An organization is granted the block 211.17.180.0/24.The administrator
wants to create 32 subnets.
a. Find the subnet mask.
b. Find the number of addresses in each subnet.
c. Find the first and last addresses in subnet 1.
d. Find the first and last addresses in subnet 32.
16
211.17.180.0/24
a. Possible subnets: 32;
25 = 32; Extra 1s = 5; Mask: /29 (24 + 5)
d. Subnet 32: To find the first address in subnet 32, we need to add 248 (31 × 8) in
base 256 (0.0.0.248) to the first address in subnet 1. We have 211.17.180.0 +
0.0.0.248 or 211.17.180.248. Now we can calculate the last address in subnet 32
as we did for the first address.
First address in subnet 32: 211 . 17 . 180 . 248
Number of addresses: 0 . 0 . 0 . 7
17 Last address in subnet 32: 211 . 17 . 180 . 255
Example 2
An organization is granted the block 130.56.0.0/16. The administrator
wants to create 1024 subnets.
a. Find the subnet mask.
b. Find the number of addresses in each subnet.
c. Find the first and last addresses in subnet 1.
d. Find the first and last addresses in subnet 1024.
19
More Levels of Hierarchy
The structure of classless addressing does not restrict the number of
hierarchical levels.
A national ISP can divide a granted large block into smaller blocks and
assign each of them to a regional ISP.
A regional ISP can divide the block received from the national ISP into
smaller blocks and assign each one to a local ISP.
A local ISP can divide the block received from the regional ISP into smaller
blocks and assign each one to a different organization.
Finally, an organization can divide the received block and make several
subnets out of it.
Address Allocation
How are the blocks allocated?
Each ISP, in turn, divides its assigned block into smaller subblocks and grants
the subblocks to its customers.
b. The second group has 128 customers; each needs 128 addresses.
Design the subblocks and find out how many addresses are still available
after these allocations.
22
Group 1
For this group, each customer needs 256 addresses. This means that 8 (log2
256) bits are needed to define each host. The prefix length is then 32 − 8 =
24. The addresses are
1st Customer: 190.100.0.0/24 190.100.0.255/24
2nd Customer: 190.100.1.0/24 190.100.1.255/24
. . .
. . .
64th Customer: 190.100.63.0/24 190.100.63.255/24
23
Group 2
For this group, each customer needs 128 addresses. This means that 7 (log2
128) bits are needed to define each host. The prefix length is then 32 − 7 =
25. The addresses are
Group 3
For this group, each customer needs 64 addresses. This means that 6 (log2
64) bits are needed to each host. The prefix length is then 32 − 6 = 26. The
addresses are
25
IPV4 Protocol: Packet Structure
Internet Protocol being a layer-3 protocol (OSI) takes data Segments from
layer-4 (Transport) and divides it into packets.
IP packet encapsulates data unit received from above layer and add to its
own header information.
26
IPV4 Protocol: Header
27
IPV4 Protocol: Header
Version: It is a 4 bit field that indicates the IP version used. It is 4.
Header length: It is a 4 bit field that contains the length of the IP header. It
helps in knowing from where the actual data begins. [20 bytes, 60 bytes]. The
value lies in the range [5, 15]
Type of service: is a 8 bit field that is used for Quality of Service (QoS). It
provides 3 bits to signal priority and 3 bits to signal whether a host cared
more about delay, throughput, or reliability. 2 bits are used to carry
explicit congestion notification information.
Total length: It is a 16 bit field that contains the total length of the datagram
(in bytes). Total length = Header length + Payload length. Maximum total
length of datagram = Maximum value of 16 bit word = 65535 bytes
Identification field: It is needed to allow the destination host to determine
which packet a newly arrived fragment belongs to. All the fragments of a
packet contain the same Identification value.
28
IPV4 Protocol: Header
Flags − As required by the network resources, if IP Packet is too large to
handle, these ‘flags’ tells if they can be fragmented or not. The first bit is always
set to 0. The second bit is called the DF (Don't Fragment) bit and indicates that
this packet should not be fragmented. The third bit is called the MF (More
Fragments) bit and is set on all fragmented packets except the last one.
Fragment Offset − This offset tells the exact position of the fragment in the
original IP Packet.
Time to Live − To avoid looping in the network, every packet is sent with
some TTL value set, which tells the network how many routers (hops) this
packet can cross. At each hop, its value is decremented by one and when the
value reaches zero, the packet is discarded.
Protocol − Tells the Network layer at the destination host, to which Protocol
this packet belongs to, i.e. the next level Protocol. For example protocol
number of ICMP is 1,TCP is 6 and UDP is 17.
29
IPV4 Protocol: Header
Header Checksum − This field is used to keep checksum value of entire
header which is then used to check if the packet is received error-free.
Source Address − 32-bit address of the Sender (or source) of the packet.
Options − This is optional field, which is used if the value of IHL is greater
than 5. These options may contain values for options such as Security,
Record Route,Time Stamp, etc.
30
Network Address Translation (NAT)
To access the Internet, one public IP address is needed, but we can use a
private IP address in our private network.
The idea of NAT is to allow multiple devices to access the Internet through
a single public address.
To achieve this, the translation of a private IP address to a public IP address
is required.
Network Address Translation (NAT) is a process in which one or more
local IP address is translated into one or more Global IP address and vice
versa in order to provide Internet access to the local hosts.
Also, it does the translation of port numbers i.e. masks the port number of
the host with another port number, in the packet that will be routed to the
destination.
It then makes the corresponding entries of IP address and port number in
the NAT table. NAT generally operates on a router or firewall.
31
Private IP Addresses
Every class of IP, (A, B & C) has some addresses reserved as Private IP
addresses.
These IPs can be used within a network, campus, company and are private
to it.
These addresses cannot be routed on the Internet, so packets containing
these private addresses are dropped by the Routers.
IP Range Mask
= 224
= 220
= 216
33
Address Translation
All 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.
34
IPV6
Despite all short-term solutions, address depletion is still a long-term
problem for the Internet. This and other problems in the IP protocol itself
have been the motivation for IPv6.
An IPv6 address is 128 bits long.
35
IPv6 address in binary and hexadecimal colon notation
36
Example
Expand the address 0:15::1:12:1213 to its original.
0:15:0:0:0:1:12:1213
37
Features of IPV6
Larger address space: 128 bits and 32 bits in IPv4
38
Features of IPV6
No more NAT (Network Address Translation)
Auto-configuration
39
40
Ipv4 Ipv6
After a data packet leaves its source, it can choose among the many
different paths to reach its destination.
Routing algorithm mathematically computes the best path, i.e. “least – cost
path” that the packet can be routed through.
43
Types of Routing algorithms
Static or Non-adaptive Routing:
Construct a static routing table to determine the path through which packets
are to be sent. The static routing table is constructed based upon the routing
information stored in the routers when the network is booted up.
Shortest path routing (Dijkstra’s Algorithm [dike-strah])
Simple and easy to understand.
Metric for a shortest path: distance, bandwidth, average traffic, communication cost,
mean queue length, measured delay, ….
Dynamic or Adaptive Routing
Makes routing decisions dynamically depending on the network conditions. It
constructs the routing table depending upon the network traffic and topology.
They try to compute the optimized route depending upon the hop count,
transit time and distance.
Distance Vector Routing.
44
Dijkstra’s Algorithm
An algorithm that is used for finding the shortest distance, or path, from
starting node to target node in a weighted graph is known as Dijkstra’s
Algorithm.
Dijkstra's algorithm makes use of weights of the edges for finding the path
that minimizes the total distance (weight) among the source node and all
other nodes.
45
Dijkstra’s Algorithm
1. Mark the source node with a current distance of 0 and the rest nodes
with infinity.
2. Now, fix the source node as the current node
3. For the current node, analyse all of its unvisited neighbours and measure
their distances by adding the current distance of its own to the weight of
the edge that connects to its neighbour node.
4. Compare the recently measured distance with the current distance
assigned to the neighbouring node and make it as the new current
distance of the neighbouring node,
5. After that, consider all of the unvisited neighbours of the current node,
mark the current node as visited,
6. If the destination node has been marked visited then stop, an algorithm
has ended
7. Else, choose the unvisited node that is marked with the least distance, fix
it as the new current node, and repeat the process again from step 3.
46
(∞, - ) (∞, - )
(∞, - ) (∞, - )
(0) (∞, - )
(∞, - ) (∞, - )
47
48
49
50
51
52
53
54
55
Distance Vector Routing
Operates by having each router maintain a table (i.e., a vector) giving the
best known distance to each destination and which link to use to get there.
It was the original ARPANET routing algorithm and was also used in the
Internet under the name RIP.
Each node shares its routing table with its immediate neighbors periodically
and when there is a change.
56
Distance Vector Routing
Information kept by DV router -
Each router has an ID
Link cost associated with each link connected to a router (static or dynamic).
Intermediate hops
For this each node can send a message to the immediate neighbors and find
the distance between itself and these neighbors.
Figure shows the initial tables for each node. The distance for any entry that is
not a neighbor is marked as infinite (unreachable).
58
Updating
When a node receives a two-column table from a neighbor, it needs to
update its routing table. Updating takes in three steps:
1. The receiving node needs to add the cost between itself and the sending node
to each value in the second column. Example, if node C claims that its distance
to E is x, and the distance between A and C is y, then the distance between A
and E, via C, is (x + y).
2. The receiving node needs to add the name of the sending node to each row as
the third column if the receiving node uses information from any row. The
sending node is the next node in the route.
3. The receiving node needs to compare each row of its old table with the
corresponding row of the modified version of the received table.
a. If the next-node entry is different, the receiving node chooses the row with the
smaller cost.
59
Distance Vector Routing
The table for node A shows how we can reach any node from this node. For
example, the least cost to reach node E is 6. The route passes through C.
60
In this example, delay is used as a metric.
Suppose that J has measured or estimated its delay to its neighbors, A, I, H,
and K, as 8, 10, 12, and 6 msec, respectively. What is the J’s new table?
J to A Min(8+0, 10+24,
12+20, 6+21) = 8 (A)
J to B Min(8+12, 10+36,
12+31, 6+28)
= 20 that is through A
J to G Min(8+18, 10+31,
12+6, 6+31)
= 18 that is through H
Two-Node Loop Instability or count to infinity
Instability is the major problem,
which means that a network
using this protocol can become
unstable.
62
Three-Node Instability
63
Distance Vector routing
Advantages
It is simpler to configure and maintain than link state routing.
Disadvantages of
It is slower to converge.
It is at risk from the count-to-infinity problem.
It creates more traffic since updates take place on a periodic basis and if
there are changes in the network topology, so bandwidth-wasting
broadcasts occur.
For larger networks, distance vector routing results in larger routing tables
since each router must know about all other routers. This can also lead to
congestion on WAN links.
64
Link State Routing
Link state routing is a technique in which each router shares the
knowledge of its neighborhood with every other router in the
internetwork.
Flooding: Each router sends the information to every other router on the
internetwork except its neighbors. This process is known as Flooding. Every
router that receives the packet sends the copies to all its neighbors. Finally, each
and every router receives a copy of the same information.
65
Link State Routing
The idea behind link state routing is fairly simple and can be stated as five
parts. Each router must do the following things to make it work:
4. Send this packet to and receive packets from all other routers.
Then Dijkstra’s algorithm can be run at each router to find the shortest
path to every other router.
66
Link State Routing
Learning about the Neighbors
When a router is booted, its first task is to learn who are its neighbors.
The router on the other end is expected to send back a reply giving its name.
67
Link State Routing
Setting Link Costs
The link state routing algorithm requires each link to have a distance or
cost metric for finding shortest paths.
If the network is geographically spread out, the delay of the links may be
factored into the cost so that paths over shorter links are better choices.
The most direct way to determine this delay is to send over the line a
special ECHO packet that the other side is required to send back
immediately.
By measuring the round-trip time and dividing it by two, the sending router
can get a reasonable estimate of the delay.
68
Link State Routing
Building Link State Packets
The packet starts with the identity of the sender, followed by a sequence
number, age of the packet, a list of neighbors and the cost to each neighbor.
Example:
69
Link State Routing
Building the link state packets is easy. The hard part is determining when to
build them.
70
Link State Routing
Distributing the Link State Packets
It is the trickiest part of the algorithm. All of the routers must get all of the
link state packets quickly and reliably.
If different routers are using different versions of the topology, the routes they
compute can have inconsistencies such as loops, unreachable machines…
Use flooding to distribute the link state packets to all routers.
To keep the flood in check, each packet contains a sequence number that is
incremented for each new packet sent.
Routers keep track of all the (source router, sequence) pairs they see.
When a new link state packet comes in, it is checked against the list of packets
already seen.
If it is new, it is forwarded on all lines except the one it arrived on.
If it is a duplicate, it is discarded.
If a packet with a sequence number lower than the highest one seen so far ever arrives, it is
71 rejected as being outdated.
Link State Routing
This algorithm has a few problems, but they are manageable.
First, if the sequence numbers wrap around, confusion will reign. The
solution here is to use a 32-bit sequence number. With one link state
packet per second, it would take 137 years to wrap around, so this
possibility can be ignored.
Second, if a router ever crashes, it will lose track of its sequence number. If
it starts again at 0, the next packet it sends will be rejected as a duplicate.
72
Link State Routing
The solution to all these problems is to include the age of each packet after
the sequence number and decrement it once per second.
When the age hits zero, the information from that router is discarded.
Normally, a new packet comes in, say, every 10 sec, so router information
only times out when a router is down (or six consecutive packets have
been lost, an unlikely event).
The Age field is also decremented by each router during the initial flooding
process, to make sure no packet can get lost and live for an indefinite
period of time (a packet whose age is zero is discarded).
73
Link State Routing
Some refinements to this algorithm make it more robust.
When a link state packet comes in to a router for flooding, it is not queued
for transmission immediately.
Instead, it is put in a holding area to wait a short while in case more links
are coming up or going down.
If another link state packet from the same source comes in before the first
packet is transmitted, their sequence numbers are compared.
To guard against errors on the links, all link state packets are acknowledged.
74
Fig. (b) the packet buffer for router B in Fig.(a).
75
Link State Routing
Computing the New Routes
Once a router has accumulated a full set of link state packets, it can
construct the entire network graph because every link is represented.
The shortest-path computations may then find different paths from router
A to B than from router B to A.
Now Dijkstra’s algorithm can be run locally to construct the shortest paths
to all possible destinations.
The results of this algorithm tell the router which link to use to reach each
destination.This information is installed in the routing tables, and normal
operation is resumed.
76
Link state routing concept
77
78
Link State Routing has two phases:
Reliable Flooding
Initial state: Each node knows the cost of its neighbors.
Final state: Each node knows the entire graph.
Route Calculation
Each node uses Dijkstra's algorithm on the graph to calculate
the optimal routes to all nodes.
The Link state routing algorithm uses Dijkstra's algorithm
which is used to find the shortest path from one node to every
other node in the network.
79
In this figure, source vertex is A.
Step Node B C D E F
1 A 2, A 5, A 1, A ∞ ∞
2 AD 2, A 4, D 2, D ∞
3 ADE 2, A 3, E 4, E
4 ADEB 3, E 4, E
5 ADEBC 4, E
6 ADEBCF
80
Derive the routing table for router 3
81
Consider the network of the given figure. Distance vector
routing is used, and the following vectors have just come
in to router C: from B: (5, 0, 8, 12, 6, 2); from D: (16, 12, 6,
0, 9, 10); and from E: (7, 6, 3, 9, 0, 4). The cost of the links
from C to B, D, and E, are 6, 3, and 5, respectively. What is
C’s new routing table? Give both the outgoing line to use
and the cost.
82