You are on page 1of 35

Computer and

Communication Networks
EE-357 -TE-54
By Dr Mir Yasir Umair
Assistant Professor, MCS, NUST
Network Layer
Routing Algorithms
Chapter 4: outline
4.1 introduction 4.5 routing algorithms
4.2 virtual circuit and datagram networks o link state
o distance vector
4.3 what’s inside a router
o hierarchical routing
4.4 IP: Internet Protocol
4.6 routing in the Internet
o datagram format
o RIP
o IPv4 addressing
o OSPF
o ICMP
o BGP
o IPv6
4.7 broadcast and multicast
routing

Network Layer 4-3


Interplay between routing, forwarding
routing algorithm determines
routing algorithm
end-end-path through network
forwarding table determines
local forwarding table
local forwarding at this router
dest address output link
address-range 1 3
address-range 2 2
address-range 3 2
address-range 4 1

IP destination address in
arriving packet’s header
1
3 2

Network Layer 4-4


Graph abstraction
5

v 3 w
2 5
u 2 1 z
3
1 2
x 1
y
graph: G = (N,E)

N = set of routers = { u, v, w, x, y, z }

E = set of links ={ (u,v), (u,x), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) }

aside: graph abstraction is useful in other network contexts, e.g.,


P2P, where N is set of peers and E is set of TCP connections

Network Layer 4-5


Graph abstraction: costs
5
c(x,x’) = cost of link (x,x’)
3 e.g., c(w,z) = 5
v w 5
2
u cost could always be 1, or
2
3
1 z inversely related to bandwidth,
1 2 or inversely related to
x 1
y
congestion

cost of path (x1, x2, x3,…, xp) = c(x1,x2) + c(x2,x3) + … + c(xp-1,xp)

key question: what is the least-cost path between u and z ?


routing algorithm: algorithm that finds that least cost path

Network Layer 4-6


Routing algorithm classification
Q: global or decentralized Q: static or dynamic?
information?
global: static:
• all routers have complete ❖ routes change slowly
topology, link cost info
• “link state” algorithms over time
decentralized: dynamic:
• router knows physically-
connected neighbors, link ❖ routes change more
costs to neighbors quickly
• iterative process of ▪ periodic update
computation, exchange of
info with neighbors ▪ in response to link cost
changes
• “distance vector”
algorithms

Network Layer 4-7


Chapter 4: outline
4.1 introduction 4.5 routing algorithms
4.2 virtual circuit and datagram networks o link state
o distance vector
4.3 what’s inside a router
o hierarchical routing
4.4 IP: Internet Protocol
4.6 routing in the Internet
o datagram format
o RIP
o IPv4 addressing
o OSPF
o ICMP
o BGP
o IPv6
4.7 broadcast and multicast
routing

Network Layer 4-8


A Link-State Routing Algorithm
Dijkstra’s algorithm notation:
• net topology, link costs • c(x,y): link cost from node x to y;
known to all nodes = ∞ if not direct neighbors
o accomplished via “link • D(v): current value of cost of
state broadcast”
o all nodes have same
path from source to dest. v
info • p(v): predecessor node along
• computes least cost path from source to v
paths from one node • N': set of nodes whose least cost
(‘source”) to all other path definitively known
nodes
o gives forwarding table
for that node
• iterative: after k
iterations, know least
cost path to k dest.’s

Network Layer 4-9


Dijsktra’s Algorithm
1 Initialization:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
6 else D(v) = ∞
7
8 Loop
9 find w not in N' such that D(w) is a minimum
10 add w to N'
11 update D(v) for all v adjacent to w and not in N' :
12 D(v) = min( D(v), D(w) + c(w,v) )
13 /* new cost to v is either old cost to v or known
14 shortest path cost to w plus cost from w to v */
15 until all nodes in N'

Network Layer 4-10


Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N' p(v) p(w) p(x) p(y) p(z)
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9

notes: 5 7
4
❖ construct shortest path tree by
tracing predecessor nodes 8
❖ ties can exist (can be broken u
3 w y z
arbitrarily) 2
3
7 4
v
Network Layer 4-11
Dijkstra’s algorithm: another example
Step N' D(v),p(v) D(w),p(w) D(x),p(x) D(y),p(y) D(z),p(z)
0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz

v 3 w
2 5
u 2 1 z
3
1 2
x 1
y

Network Layer 4-12


Dijkstra’s algorithm: example (2)
resulting shortest-path tree from u:

v w
u z
x y

resulting forwarding table in u:


destination link
v (u,v)
x (u,x)
y (u,x)
w (u,x)
z (u,x)
Network Layer 4-13
Dijkstra’s algorithm, discussion
algorithm complexity: n nodes
❖ each iteration: need to check all nodes, w, not in
N
❖ n(n+1)/2 comparisons: O(n2)
❖ more efficient implementations possible: O(nlogn)
oscillations possible:
❖ e.g., support link cost equals amount of carried
traffic:

1
A 1+e A A A
2+e 0 0 2+e 2+e 0
D 0 0 B D 1+e 1 B D B D 1+e 1 B
0 0
0 e 0 0
C 0 1 0
1 C C 1+e C
1
e
given these costs, given these costs, given these costs,
initially find new routing…. find new routing…. find new routing….
resulting in new costs resulting in new costs resulting in new costs
Network Layer 4-14
Practice Question

EE 451 Mobile Communications


Chapter 4: outline
4.1 introduction 4.5 routing algorithms
4.2 virtual circuit and datagram networks o link state
o distance vector
4.3 what’s inside a router
o hierarchical routing
4.4 IP: Internet Protocol
4.6 routing in the Internet
o datagram format
o RIP
o IPv4 addressing
o OSPF
o ICMP
o BGP
o IPv6
4.7 broadcast and multicast
routing

Network Layer 4-16


Distance vector algorithm
Bellman-Ford equation (dynamic programming)

let
dx(y) := cost of least-cost path from x to y
then
dx(y) = min
v
{c(x,v) + dv(y) }

cost from neighbor v to destination y


cost to neighbor v

min taken over all neighbors v of x


Network Layer 4-17
Bellman-Ford example
5
3
clearly, dv(z) = 5, dx(z) = 3, dw(z) = 3
v w 5
2
u 2 1 z B-F equation says:
3
1 2 du(z) = min { c(u,v) + dv(z),
x y
1 c(u,x) + dx(z),
c(u,w) + dw(z) }
= min {2 + 5,
1 + 3,
5 + 3} = 4
node achieving minimum is next
hop in shortest path, used in forwarding table
Network Layer 4-18
Distance vector algorithm
• Dx(y) = estimate of least cost from x to y
o x maintains distance vector Dx = [Dx(y): y є N ]
• node x:
o knows cost to each neighbor v: c(x,v)
o maintains its neighbors’ distance vectors. For each neighbor v, x
maintains
Dv = [Dv(y): y є N ]

Network Layer 4-19


Distance vector algorithm
key idea:
❖ from time-to-time, each node sends its own distance vector
estimate to neighbors
❖ when x receives new DV estimate from neighbor, it
updates its own DV using B-F equation:
Dx(y) ← minv{c(x,v) + Dv(y)} for each node y ∊ N

❖ under minor, natural conditions, the estimate Dx(y)


converge to the actual least cost dx(y)

Network Layer 4-20


Distance vector algorithm
iterative, asynchronous: each node:
each local iteration
caused by:
• local link cost change wait for (change in local link
cost or msg from neighbor)
• DV update message
from neighbor
distributed: recompute estimates
• each node notifies
neighbors only when
its DV changes if DV to any dest has
o neighbors then notify changed, notify neighbors
their neighbors if
necessary

Network Layer 4-21


Dx(z) = min{c(x,y) +
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)}
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
= min{2+1 , 7+0} = 3
node x cost to cost to
table x y z x y z
x 0 2 7 x 0 2 3

from
from
y ∞∞ ∞ y 2 0 1
z ∞∞ ∞ z 7 1 0

node y cost to
table x y z y
2 1
x ∞ ∞ ∞
x z
from

y 2 0 1 7
z ∞∞ ∞

node z cost to
table x y z
x ∞∞ ∞
from

y ∞∞ ∞
z 7 1 0
time
Network Layer 4-22
Dx(z) = min{c(x,y) +
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)}
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
= min{2+1 , 7+0} = 3
node x cost to cost to cost to
table x y z x y z x y z
x 0 2 7 x 0 2 3 x 0 2 3

from
from
y ∞∞ ∞ y 2 0 1

from
y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node y cost to cost to cost to
table x y z x y z x y z y
2 1
x ∞ ∞ ∞ x 0 2 7 x 0 2 3 x z
from

from
y 2 0 1 y 2 0 1 7

from
y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0

node z cost to cost to cost to


table x y z x y z x y z

x ∞∞ ∞ x 0 2 7 x 0 2 3
from

from
y 2 0 1 y 2 0 1
from

y ∞∞ ∞
z 7 1 0 z 3 1 0 z 3 1 0
time
Network Layer 4-23
Distance vector: link cost changes
link cost changes: 1
❖ node detects local link cost change y
4 1
❖ updates routing info, recalculates x z
distance vector 50
❖ if DV changes, notify neighbors

“good t0 : y detects link-cost change, updates its DV, informs its


news neighbors.
travels t1 : z receives update from y, updates its table, computes new
fast” least cost to x , sends its neighbors its DV.

t2 : y receives z’s update, updates its distance table. y’s least costs
do not change, so y does not send a message to z.

Network Layer 4-24


Distance vector: link cost changes
link cost changes: 60
❖ node detects local link cost change y
4 1
❖ bad news travels slow - “count to x z
infinity” problem! 50
❖ 44 iterations before algorithm
stabilizes: see text

Network Layer 4-25


Comparison of LS and DV algorithms
message complexity robustness: what happens if
• LS: with n nodes, E links, O(nE) router malfunctions?
msgs sent LS:
• DV: exchange between o node can advertise
neighbors only incorrect link cost
o convergence time varies o each node computes
only its own table
speed of convergence DV:
• LS: O(n2) algorithm requires o DV node can advertise
O(nE) msgs incorrect path cost
o may have oscillations o each node’s table used
• DV: convergence time varies by others
• error propagate thru
o may be routing loops network
o count-to-infinity problem

Network Layer 4-26


Chapter 4: outline
4.1 introduction 4.5 routing algorithms
4.2 virtual circuit and datagram networks o link state
o distance vector
4.3 what’s inside a router
o hierarchical routing
4.4 IP: Internet Protocol
4.6 routing in the Internet
o datagram format
o RIP
o IPv4 addressing
o OSPF
o ICMP
o BGP
o IPv6
4.7 broadcast and multicast
routing

Network Layer 4-27


Hierarchical routing
our routing study thus far - idealization
❖ all routers identical
❖ network “flat”
… not true in practice

scale: with 600 million administrative autonomy


destinations: ❖ internet = network of
• can’t store all dest’s networks
in routing tables! ❖ each network admin
• routing table exchange may want to control
would swamp links! routing in its own network

Network Layer 4-28


Hierarchical routing
• aggregate routers gateway router:
into regions, • at “edge” of its own
“autonomous AS
systems” (AS) • has link to router in
• routers in same AS run another AS
same routing protocol
o “intra-AS” routing protocol
o routers in different AS can
run different intra-AS routing
protocol

Network Layer 4-29


Interconnected ASes
3c
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b AS1
1d
❖ forwarding table
configured by both
Intra-AS Inter-AS
intra- and inter-AS
Routing
algorithm
Routing
algorithm
routing algorithm
▪ intra-AS sets entries for
Forwarding internal dests
table ▪ inter-AS & intra-AS sets entries
for external dests

Network Layer 4-30


Inter-AS tasks
❖ suppose router in AS1 AS1 must:
receives datagram 1. learn which dests are
destined outside of reachable through
AS1: AS2, which through
▪ router should forward packet
to gateway router, but which
AS3
one? 2. propagate this
reachability info to
all routers in AS1
3c job of inter-AS routing!
3a
3b
AS3 2c other
1c 2a networks
other 1a 2b
networks 1b AS2
AS1 1d
Network Layer 4-31
Example: setting forwarding table in router 1d
• suppose AS1 learns (via inter-AS protocol) that subnet x
reachable via AS3 (gateway 1c), but not via AS2
o inter-AS protocol propagates reachability info to all internal routers
• router 1d determines from intra-AS routing info that its interface
I is on the least cost path to 1c
o installs forwarding table entry (x,I)

3c
x
3a
3b
AS3 2c other
1c 2a networks
other 1a 2b
networks 1b AS2
AS1 1d
Network Layer 4-32
Example: choosing among multiple ASes
• now suppose AS1 learns from inter-AS protocol that subnet
x is reachable from AS3 and from AS2.
• to configure forwarding table, router 1d must determine
which gateway it should forward packets towards for dest x
o this is also job of inter-AS routing protocol!

3c
x
3a
3b
AS3 2c other
1c 2a networks
other 1a 2b
networks 1b AS2
AS1 1d
?
Network Layer 4-33
Example: choosing among multiple ASes
• now suppose AS1 learns from inter-AS protocol that subnet
x is reachable from AS3 and from AS2.
• to configure forwarding table, router 1d must determine
towards which gateway it should forward packets for dest x
o this is also job of inter-AS routing protocol!
• hot potato routing: send packet towards closest of two
routers.

use routing info determine from


learn from inter-AS hot potato routing: forwarding table the
from intra-AS
protocol that subnet choose the gateway interface I that leads
protocol to determine
x is reachable via that has the to least-cost gateway.
costs of least-cost
multiple gateways smallest least cost Enter (x,I) in
paths to each
of the gateways forwarding table

Network Layer 4-34


Thank you

You might also like