You are on page 1of 30

Chapter 4: Network Layer

r 4. 1 Introduction r 4.5 Routing algorithms


r 4.2 Virtual circuit and m Link state
datagram networks m Distance Vector
Hierarchical routing
r 4.3 What’s inside a
m

router r 4.6 Routing in the


r 4.4 IP: Internet
Internet
RIP
Protocol m
m OSPF
m Datagram format
m BGP
m IPv4 addressing
m ICMP r 4.7 Broadcast and
m IPv6 multicast routing

Network Layer 4-63


Interplay between routing, forwarding

routing algorithm

local forwarding table


header value output link
0100 3
0101 2
0111 2
1001 1

value in arriving
packet’s header
0111 1

3 2

Network Layer 4-64


Graph abstraction
5
3
v w 5
2
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) }

Remark: Graph abstraction is useful in other network contexts

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

Network Layer 4-65


Graph abstraction: costs
5
• c(x,x’) = cost of link (x,x’)
3
v w 5
2 - e.g., c(w,z) = 5
u 2 1 z
3 • cost could always be 1, or
1 2 inversely related to bandwidth,
x 1
y
or inversely related to
congestion
cost ( Wix ,YiZ ) Clu ,✗)tc( Xiylccy ,z )
=
= I -11+2=4

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

Question: What’s the least-cost path between u and z ?

Routing algorithm: algorithm that finds least-cost path

Network Layer 4-66


Routing Algorithm classification
Global or decentralized Static or dynamic?
information? Static:
Global:
r routes change slowly
r all routers have complete
topology, link cost info over time
r “link state” algorithms Dynamic:
Decentralized: r routes change more
r router knows physically- quickly
connected neighbors, link
m periodic update
costs to neighbors
r iterative process of m in response to link
computation, exchange of cost changes
info with neighbors
r “distance vector” algorithms

Network Layer 4-67


Chapter 4: Network Layer
r 4. 1 Introduction r 4.5 Routing algorithms
r 4.2 Virtual circuit and m Link state
datagram networks m Distance Vector
Hierarchical routing
r 4.3 What’s inside a
m

router r 4.6 Routing in the


r 4.4 IP: Internet
Internet
RIP
Protocol m
m OSPF
m Datagram format
m BGP
m IPv4 addressing
m ICMP r 4.7 Broadcast and
m IPv6 multicast routing

Network Layer 4-68


¥
#¥÷
A Link-State Routing Algorithm

Dijkstra’s algorithm Notation:


r net topology, link costs r c(x,y): link cost from node
known to all nodes x to y; = ∞ if not direct
m accomplished via “link neighbors
state broadcast”
r D(v): current value of cost
m all nodes have same info of path from source to
r computes least cost paths dest. v
from one node (‘source”) to
r p(v): predecessor node
all other nodes
along path from source to v
m gives forwarding table
for that node r N': set of nodes whose
least cost path definitively
r iterative: after k
known
iterations, know least cost
path to k dest.’s
Network Layer 4-69
→¥ :*:% .

Dijsktra’s Algorithm

if:# 1 Initialization:
2 N' = {u}
IN
:[ 3 for all nodes v

optiÉtr
:÷÷
4 if v adjacent to u "
5 then D(v) = c(u,v) D. (r ) )
"
=
Clair =

6 else D(v) = ∞ ☐ ( my = N
7 D (v
=
) a

8 Loop a
D Ch)
=

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-70


Dlv ) = win
{ DIVI , DIN) + else ,v ) }
at node u .
= min {2,11-2}
Dijkstra’s algorithm:Aexample =
min { 2,3 }
=
2

Step N' D(v),p(v) D(w),p(w) D(x),p(x) D(y),p(y) D(z),p(z)

1¥ytf-z.ae
0 u 2,u 5,u 1,u ∞ ∞
1 2,u 4,x 2,x a ∞
£
ux
2 uxy 2,u 3,y 4,y
3 33,yy 4,y
uxyv
,
,

4 uxyvw 4,y
5 uxyvwz

5 Dlw ) = min {5,1+3}--4


3 ☐ (D) = min {0,1-11} 2
v w
=

2 5


u 2
3
1 z Dtt) = min { 41 }=x to
1 2
N' x win
1
y Dlw) =
{4,2+1}--3
Network Layer 4-71
Dijkstra’s algorithm: example
Step
0
1
N'

ux
u _
D(v),p(v) D(w),p(w)
2,u
2,u
2,u
5,u
4,x
D(x),p(x)
1,u
D(y),p(y)

2,x
D(z),p(z)


4,y
2 uxy 3,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz

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

Network Layer 4-72


Dijkstra’s algorithm: example
t

-
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 ∞ ∞
2,u ∞
1 ux 4,x . 2,x
4,y
2 uxy 2,u 3,y
4,y

}
3 uxyv 3,y
4 uxyvw 4,y
5 uxyvwz

5 DAD = him { to
3
v w 5 D (7) = him
{0,2+2}=4
2
u 2 1 z
3
1 2
x 1
y

Network Layer 4-73


Dijkstra’s algorithm: example
Step 0
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

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

Network Layer 4-74


Dijkstra’s algorithm: 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

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

Network Layer 4-75


Dijkstra’s algorithm: example
t t t t
Step
0
1
0
N'
u
ux
t.se
D(v),p(v) D(w),p(w)
2,u
2,u
5,u
4,x
D(x),p(x)
1,u
D(y),p(y) D(z),p(z)

2,x !


2 2,u 3,y • 4,y
uxy A
3 uxyv 3,y 4,y
4
5
uxyvw
uxyvwz
4,y
%
-

want to find least cost


-

5 node 2-
path to .

3
v w 5
2 D G) =
4
u 2 1 z
← 1
3
2
x y
⑨ ⑥ 1
→ Minimum
⑨ 9 ② Tree
Network Layer 4-76

↳④→ →
⑨ spanning
Dijkstra’s algorithm: example (2)
Resulting shortest-path tree from u:

÷☐MsT
v w
u z
x y

Resulting forwarding table in u:


destination link ace

(u,v)

v -

x (u,x) #2
@y (u,x) 11=2
w (u,x)
8z (u,x) ¥+3
Network Layer 4-77
?⃝
Dijkstra’s algorithm, discussion
Algorithm complexity: n nodes
r each iteration: need to check all nodes, w, not in N
-

r n(n+1)/2 comparisons: O(n2)


r more efficient implementations possible: O(nlogn)
Oscillations possible:
r e.g., link cost = amount of carried traffic

1 A
1+e
In reality,
2+e A
link cost =f(traffic
A on link) A
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 Does0that lead
0 to a 1problem?
1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
Network Layer 4-78
Dijkstra’s algorithm, discussion
Algorithm complexity: n nodes
r each iteration: need to check all nodes, w, not in N
r n(n+1)/2 comparisons: O(n2)
r more efficient implementations possible: O(nlogn)
Oscillations possible:
r e.g., link cost = amount of carried traffic

1 A A A A
1+e 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 1 1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
Network Layer 4-79
Chapter 4: Network Layer
r 4. 1 Introduction r 4.5 Routing algorithms
r 4.2 Virtual circuit and m Link state
datagram networks m Distance Vector
Hierarchical routing
r 4.3 What’s inside a
m

router r 4.6 Routing in the


r 4.4 IP: Internet
Internet
RIP
Protocol m
m OSPF
m Datagram format
m BGP
m IPv4 addressing
m ICMP r 4.7 Broadcast and
m IPv6 multicast routing

Network Layer 4-80


Distance Vector Algorithm
Bellman-Ford Equation (dynamic programming)
Define
dx(y) := cost of least-cost path from x to y

④→④2
:

Then

.

④ ( Y)
dv
dx(y) = min {c(x,v) + dv(y) }
,

v dvz (Y )
dvz (4)
where min is taken over all neighbors v of x
{ ck.vi-dv.tn
":¥¥¥"-n
d
✗ (4)
= min Network Layer 4-81
' '
}
FEE
Bellman-Ford example

2
5

v 3
w 5
at#
Clearly, dv(z) = 5, dx(z) = 3, dw(z) = 3

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 that achieves minimum is next
hop in shortest path ➜ forwarding table
Network Layer 4-82
1) ✗ ( y) , YEN
Dv , Dvz ☐ v3

Distance Vector Algorithm


,

Du =
Dv , ( y ) , YEN
, '
r Dx(y) = estimate of least cost from x to y ④
r Distance vector: Dx = [Dx(y): y є N ]
r Node x knows cost to each neighbor v: c(x,v)
r Node x maintains Dx = [Dx(y): y є N ]
r Node x also maintains its neighbors’ distance
vectors
m For each neighbor v, x maintains
Dv = [Dv(y): y є N ]

Network Layer 4-83


Distance vector algorithm (4)
Basic idea:
r Each node periodically sends its own distance
vector estimate to neighbors
r When a node 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

r Under minor, natural conditions, the estimate Dx(y)


converge to the actual least cost dx(y)
¥190 's
TIME opy.ua ,
estimate

Network Layer 4-84


D×(v1 = 5
☐✗
at 9

Distance Vector Algorithm (5) 7

Iterative, asynchronous: Each node:


each local iteration caused
Duly 7=5/6
by:
r local link cost change wait for (change in local link
r DV update message from cost of msg from neighbor)
neighbor
Distributed: MY
recompute estimates of dist
r each node notifies
.

^
vector
neighbors only when its DV
changes if DV to any dest has
m neighbors then notify
changed, notify neighbors
their neighbors if
necessary

Does this mean a network flood


every time a link cost changes? Network Layer 4-85
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} Dx(z) = min{c(x,y) +
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
node x table = min{2+1 , 7+0} = 3
Iscost to
cost to cost to

E
x y z x y z x y z
x 0 2 7 x 0 2 3 x 0 2 3 ④ ¥In
from

from
y ∞∞ ∞ y 2 0 1

from
-

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

y 2 0 1 y 2 0 1 7
from

from
y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node z table
cost to cost to cost to
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 71 0 z 3 1 0 z 3 1 0
time
Network Layer 4-86
Distance Vector: link cost changes
Link cost changes: 1
r node detects local link cost change y
4 1
r updates routing info, recalculates
x z
distance vector 50
r if DV changes, notify neighbors Dy (a) =
4/1
At time t0, y detects the link-cost change, updates its DV,
and informs its neighbors.
“good 5/2
news ×J=
At time t1, z receives the update from y and updates its table.
It computes a new least cost to x and sends its neighbors its DV.
travels
.

fast” At time t2, y receives z’s update and updates its distance table.
y’s least costs do not change and hence y does not send any
-

message to z.

Network Layer 4-87


Distance Vector: link cost changes
by (a) = min
{ 60 ,
I +
Dz (a) }

60

x
4
y

50
1
Dzcx)

z
=

=D
win { 50 ,
Dyk)}
win {50,1+4}
I +

New DV update
from Y is

6
Dy (n)
=

What happens now ?


2- sends update
Dz (K) = 7

Network Layer 4-88


Distance Vector: link cost changes
Link cost changes:
60
r good news travels fast y
4 1
r bad news travels slow -
“count to infinity” problem! x z
50
r 44 iterations before
algorithm stabilizes: see
text
Poissoned reverse:
r If Z routes through Y to
get to X :
m Z tells Y its (Z’s) distance
to X is infinite (so Y won’t
route to X via Z)
r will this completely solve
count to infinity problem?
Network Layer 4-89
Tradeoffs

What will you recommend ?

Link State?
Distance Vector?

There is no right answer

Network Layer 4-90


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

→ Vc-1-129 on interface I
☒ so _:÷""""-


☒→ 17,21
10112,1511723

Chapter 4: Network Layer


11 13,14 ,
,

r 4. 1 Introduction r 4.5 Routing algorithms


r 4.2 Virtual circuit and m Link state
datagram networks m Distance Vector
Hierarchical routing
r 4.3 What’s inside a
m

router r 4.6 Routing in the


r 4.4 IP: Internet
Internet
RIP
Protocol m
m OSPF
m Datagram format
m BGP
m IPv4 addressing
m ICMP r 4.7 Broadcast and
m IPv6 multicast routing

Network Layer 4-92

You might also like