Unit 4 - Network Layer
Unit 4 - Network Layer
UNIT-4
NETWORK LAYER
✓Syllabus
Loopi Network Layer: Introduction to forwarding
ng
and routing, Network Service models, Virtual
and Datagram networks, study of router, IP
protocol and addressing in the Internet, Routing
algorithms, Broadcast and Multicast routing
2
✓Outline
Loopin
g
application
transport
networ
dkata link
● To deliver segment from
physical
network network
sending to receiving
data link
network
data link
data link
physical physical host/router.
physical network
data link
network
data link
● On sending side, it
physical physical
encapsulated segments into
network
data link
network
data link
datagrams.
physical
n twork
data link
physical
● On receiving side, it delivers
e
physical
application
segments to transport layer.
network
data link network
transport
network
● Network layer protocols in
physical data link
network
data link
data link
physical physical every host and router.
physical
● Router examines header fields
in all IP datagrams passing
through it.
KEY FUNCTION OF NETWORK LAYER
Role of the network layer is simple - to move packets from a
sending host to a receiving host.
Two important network layer functions can be
identified:
1. Forwarding
⚫ When a packet arrives at a router’s input link, the router
12 22 32
1 3
2
VC number
interface
number
forwarding table in router:
Incoming interface Incoming VC # Outgoing interface Outgoing VC#
1 12 3 22
2 63 1 18
3 7 2 17
1 97 3 87
… … … …
application application
transport 5. data flow
transport
network begins 6. receive data
4. call connected
network
data link 3. accept call data link
physical physical
1. initiate call 2. incoming
call
DATAGRAM NETWORK
In connectionless service, packets are injected into the
subnet individually and routed independently of each other.
No advance setup is needed. The packets are frequently
called datagrams and the subnet is called a datagram
subnet.
Only directly-connected lines can be used.
application application
transport transport
network 1. send datagrams 2. receive datagrams network
data link data link
physical physical
DATAGRAM NETWORK VS. VIRTUAL CIRCUIT NETWORK
lookup,
link forwarding
line layer switch
termination protocol fabric
(receive)
queueing
memory
input output
port (e.g., memory port (e.g.,
Ethernet)
Ethernet)
System Bus
datagram
switch buffer link
line
fabric layer
termination
protocol
queueing
(send)
172 16 254 1
1 1 0
Fix
Very first four bits of the first octet in Class D IP addresses are set
to 1110, giving a range of:
19.49
IP ADDRESSING SUMMARY
Size Default sub
Size of Total
Leadi of netwo Number of Addresses net CIDR
rest bit addresses Start
Class ng rk networks per End address mask in dot notati
field address
bits number network in class -decimal on
bit field notation
223.1.2.0/24
223.1.3.1 223.1.3.2
223.1.3.0/24
With dynamic addressing, a device can have a different IP
address every time it connects to the network.
In some systems, the device's IP address can even change
while it is still connected.
It allows reuse of addresses (only hold address while
connected “on”).
It also support mobile users who want to join network.
DHCP CLIENT SERVER INTERACTION
DHCP server: 223.1.2.5 DHCP discover arriving
src : 0.0.0.0, 68 client
Broadcast: is there a
dest.:
DHCP server out there?
255.255.255.255,67
yiaddr: 0.0.0.0
transaction ID: 654
DHCP offer
src: 223.1.2.5, 67
Broadcast: I’m a DHCP
dest: 255.255.255.255, 68
server!
yiaddrr:Here’s an IP
223.1.2.4
address youID:can
transaction 654 use
lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255,
Broadcast: 67
OK. I’ll take
yiaddrr: 223.1.2.4
that IP address!
transaction ID: 655
lifetime: 3600 secs
DHCP
ACK
src: 223.1.2.5, 67
Broadcast: OK. 68
dest: 255.255.255.255,
yiaddrr: 223.1.2.4
You’ve got that IP
transaction ID: 655
address!
lifetime: 3600 secs
NETWORK ADDRESS TRANSLATION (NAT)
NAT is a method that is used to translate Private IP addresses to
Public IP addresses.
rest of local network
Internet (e.g., home network)
10.0.0/24 10.0.0.1
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
2) Route Calculation
Each node uses Dijkstra's algorithm on the graph to calculate
the optimal routes to all nodes.
The Link state routing algorithm is also known as Dijkstra's
algorithm which is used to find the shortest path from one
node to every other node in the network.
The Dijkstra's algorithm is an iterative, and it has the property
that after kth iteration of the algorithm, the least cost paths are
well known for k destination nodes.
Notations:
c( i , j): Link cost from node i to node j. If i and j nodes are not
directly linked, then c(i , j) = ∞.
D(v): It defines the cost of the path from source code to
destination v that has the least cost currently.
P(v): It defines the previous node (neighbor of v) along with
current least cost path from source to v.
N: It is the total number of nodes available in the network.
Algorithm
Disadvantage:
Heavy traffic is created in Link state routing due to Flooding. Flooding can
cause an infinite looping, this problem can be solved by using Time-to-leave
field.
DISTANCE VECTOR ALGORITHM
Distance-vector (DV) algorithm is iterative, asynchronous, and
distributed.
It is distributed in that each node receives some information
from one or more of its directly attached neighbours, performs a
calculation, and then distributes the results of its calculation
back to its neighbours.
It is iterative. So, process continues on until no more
information is exchanged between neighbours.
The algorithm is asynchronous. It does not require all of the
nodes to operate with each other.
The Distance vector algorithm is a dynamic algorithm.
It is mainly used in ARPANET, and RIP.
Each router maintains a distance table known as Vector.
Three Keys to understand the working of Distance Vector
Routing Algorithm
Knowledge about the whole network: Each router shares its
knowledge through the entire network. The Router sends its
collected knowledge about the network to its neighbors.
Routing only to neighbors: The router sends its knowledge
about the network to only those routers which have direct
links. The router sends whatever it has about the network
through the ports. The information is received by the router and
uses the information to update its own routing table.
Information sharing at regular intervals: Within 30 seconds,
the router sends the information to the neighboring routers.
Let dx(y) be the cost of the least-cost path from node x to node
y.
The least costs are related by Bellman-Ford equation,
dx(y) = minv{c(x,v) + dv(y)}
where the minv is the equation taken for all x neighbors.
After traveling from x to v, if we consider the least-cost path
from v to y, the path cost will be c(x,v)+dv(y).
The least cost from x to y is the minimum of c(x,v)+dv(y) taken
over all neighbors.
With the Distance Vector Routing algorithm, the node x
contains the following routing information:
○ For each neighbor v, the cost c(x,v) is the path cost from x
to directly attached neighbor, v.
○ The distance vector x, i.e., Dx = [ Dx(y) : y in N ],
containing its cost to all destinations, y, in N.
○ The distance vector of each of its neighbors, i.e.,
Dv = [ Dv(y) : y in N ] for each neighbor v of x.
Distance vector routing is an asynchronous algorithm in which
node x sends the copy of its distance vector to all its neighbors.
When node x receives the new distance vector from one of its
neighboring vector, v, it saves the distance vector of v and uses
the Bellman-Ford equation to update its own distance vector.
Algorithm
EXAMPLE
Step 1:
Each router prepares its routing table using its local knowledge.
At router A,
At router B,
At router C,
At router D,
Step 2:
● Each router exchanges its distance vector obtained in Step 1
with its neighbors.
● After exchanging the distance vectors, each router prepares a
new routing table.
At router A,
Router A receives distance vectors from its neighbors B and D.
Cost of reaching destination B from router A = min { 2+0 , 1+7 } =
2 via B.
Cost of reaching destination C from router A = min { 2+3 , 1+11 } =
5 via B.
Cost of reaching destination D from router A = min { 2+7 , 1+0 } =
1 via D.
Thus, the new routing table at router A is-
At router B,
Router B receives distance vectors from its neighbors A, C and D.
Cost of reaching destination A from router B = min { 2+0 , 3+∞ ,
7+1 } = 2 via A.
Cost of reaching destination C from router B = min { 2+∞ , 3+0 ,
7+11 } = 3 via C.
Cost of reaching destination D from router B = min { 2+1 , 3+11 ,
7+0 } = 3 via A.
Thus, the new routing table at router B is-
At router C,
Router C receives distance vectors from its neighbors B and D.
Cost of reaching destination A from router C = min { 3+2 , 11+1 } =
5 via B.
Cost of reaching destination B from router C = min { 3+0 , 11+7 } =
3 via B.
Cost of reaching destination D from router C = min { 3+7 , 11+0 } =
10 via B.
Thus, the new routing table at router C is-
At router D,
Router D receives distance vectors from its neighbors A, B and C.
Cost of reaching destination A from router D = min { 1+0 , 7+2 ,
11+∞ } = 1 via A.
Cost of reaching destination B from router D = min { 1+2 , 7+0 ,
11+3 } = 3 via A.
Cost of reaching destination C from router D = min { 1+∞ , 7+3 ,
11+0 } = 10 via B.
Thus, the new routing table at router D is-
Step 3:
● Each router exchanges its distance vector obtained in Step 2
with its neighboring routers.
● After exchanging the distance vectors, each router prepares a
new routing table.
At router A,
Router A receives distance vectors from its neighbors B and D.
Cost of reaching destination B from router A = min { 2+0 , 1+3 } =
2 via B.
Cost of reaching destination C from router A = min { 2+3 , 1+10 } =
5 via B.
Cost of reaching destination D from router A = min { 2+3 , 1+0 } =
1 via D.
Thus, the new routing table at router A is-
At router B,
Router B receives distance vectors from its neighbors A, C and D.
Cost of reaching destination A from router B = min { 2+0 , 3+5 ,
3+1 } = 2 via A.
Cost of reaching destination C from router B = min { 2+5 , 3+0 ,
3+10 } = 3 via C.
Cost of reaching destination D from router B = min { 2+1 , 3+10 ,
3+0 } = 3 via A.
Thus, the new routing table at router B is-
At router C,
Router C receives distance vectors from its neighbors B and D.
Cost of reaching destination A from router C = min { 3+2 , 10+1 } =
5 via B.
Cost of reaching destination B from router C = min { 3+0 , 10+3 } =
3 via B.
Cost of reaching destination D from router C = min { 3+3 , 10+0 } =
6 via B.
Thus, the new routing table at router C is-
At router D,
Router D receives distance vectors from its neighbors A, B and C.
Cost of reaching destination A from router D = min { 1+0 , 3+2 ,
10+5 } = 1 via A.
Cost of reaching destination B from router D = min { 1+2 , 3+0 ,
10+3 } = 3 via A.
Cost of reaching destination C from router D = min { 1+5 , 3+3 ,
10+0 } = 6 via A.
Thus, the new routing table at router D is-
149