Docsity

Dijkstra's Algorithm: Shortest Path Finding in a Graph, Slides of Computer Networks

Partial preview of the text

Download Dijkstra's Algorithm: Shortest Path Finding in a Graph and more Slides Computer Networks in PDF only on Docsity!

Distance Vector Routing

How Distance-Vector (DV) works

Each router maintains its shortest distance to every

destination via each of its neighbors

via B via C to B to C to D

From node A

Neighbor

(next-hop)

Destinations dist

C (A, D): shortest

distance from A to D via C

A

How Distance-Vector (DV) works

How does A initialize its dist() table and DV?

via B via C to B?? to C?? to D??

From node A

A

min dist to B? to C? to D?

Aโ€™s DV

How Distance-Vector (DV) works

A

B

C

Link costs

How does A initialize its dist() table and DV?

How Distance-Vector (DV) works

Each router sends its DV to its immediate neighbors

via B via C

to B c (A,B) โˆž

to C โˆž c (A,C) to D โˆž โˆž

From node A

A

B

C

mindist to B c(A,B) to C c(A,C) to D โˆž

Aโ€™s DV

mindist to B 5 to C 6 to D 2

How Distance-Vector (DV) works

Routers process received DVs

A

B

C

Aโ€™s DV

mi n to B 5 to C 6 to D 2 via A via C

to A 5 โˆž

to C 15 1 to D โˆž โˆž

From node B Bโ€™s DV

mindist to A 5 to C 1 to D โˆž

Distance Vector Routing

  • Each router knows the links to its neighbors
  • Each router has provisional โ€œshortest pathโ€ to every other router -- its distance vector (DV)
  • Routers exchange this DV with their neighbors
  • Routers look over the set of options offered by their neighbors and select the best one
  • Iterative process converges to set of shortest paths

Distance Vector

  • c(i,j): link cost from node i to j
  • distZ(A,V): shortest dist. from A to V via Z
  • mindist(A,V): shortest dist. from A to V 0 At node A 1 Initialization: 2 for all destinations V do 3 if V is neighbor of A 4 distV( A, V ) = mindist(A,V) = c( A,V ); 5 else 6 distV( A, V ) = mindist(A,V) = โˆž; 7 send mindist( A, * ) to all neighbors loop: 8 wait (until A sees a link cost change to neighbor V /* case 1 / 9 or until A receives mindist(V,) from neighbor V ) /* case 2 / 10 if (c( A , V ) changes by ยฑ d ) / ๏ƒœ case 1 / 11 for all destinations Y do 12 distV( A,Y ) = distV( A,Y ) ยฑ d 13 else / ๏ƒœ case 2: / 14 for all destinations Y do 15 distV( A,Y ) = c( A,V ) + mindist( V, Y ); 16 update mindist( _A,_ ) 15 if (there is a change in mindist(A, *)) 16 send mindist( A, * ) to all neighbors 17 forever

Example: Initialization via B via C to A - - to B 2 โˆž to C โˆž 7 to D โˆž โˆž

A C

B D

from Node A via A via C via D to A 2 โˆž โˆž to B - - - to C โˆž 1 โˆž to D โˆž โˆž 3 from Node B from Node C via A via B via D to A 7 โˆž โˆž to B โˆž 1 โˆž to C - - - to D โˆž โˆž 1 via B via C to A โˆž โˆž to B 3 โˆž to C โˆž 1 to D - - from Node D min dist to A 0 to B 2 to C 7 to D โˆž min dist 0 2 7 โˆž min dist 2 0 1 3 min dist โˆž 3 1 0 min dist 7 1 0 1

Example: C sends update to A via B via C to A - - to B 2 โˆž to C โˆž 7 to D โˆž โˆž from Node A via A via C via D to A 2 โˆž โˆž to B - - - to C โˆž 1 โˆž to D โˆž โˆž 3 from Node B from Node C via A via B via D to A 7 โˆž โˆž to B โˆž 1 โˆž to C - - - to D โˆž โˆž 1 via B via C to A โˆž โˆž to B 3 โˆž to C โˆž 1 to D - - from Node D min dist 0 2 7 โˆž min dist โˆž 3 1 0 min dist 7 1 0 1

A C

B D

min dist 2 0 1 3

Example: C sends update to A via B via C to A - - to B 2 8 to C โˆž 7 to D โˆž 8 from Node A min dist 0 2 7 โˆž

A C

B D

min dist 7 1 0 1

Example: C sends update to A via B via C to A - - to B 2 8 to C โˆž 7 to D โˆž 8 from Node A min dist 0 2 7 8

A C

B D

Example: now B sends update to A via A via C via D to A 2 โˆž โˆž to B - - - to C โˆž 1 โˆž to D โˆž โˆž 3 from Node B from Node C via A via B via D to A 7 โˆž โˆž to B โˆž 1 โˆž to C - - - to D โˆž โˆž 1 via B via C to A โˆž โˆž to B 3 โˆž to C โˆž 1 to D - - from Node D min dist โˆž 3 1 0 min dist 7 1 0 1

A C

B D

min dist 2 0 1 3 via B via C to A - - to B 2 8 to C โˆž 7 to D โˆž 8 from Node A min dist 0 2 7 (^8) docsity.com

Example: now B sends update to A via A via C via D to A 2 โˆž โˆž to B - - - to C โˆž 1 โˆž to D โˆž โˆž 3 from Node B from Node C via A via B via D to A 7 โˆž โˆž to B โˆž 1 โˆž to C - - - to D โˆž โˆž 1 via B via C to A โˆž โˆž to B 3 โˆž to C โˆž 1 to D - - from Node D min dist โˆž 3 1 0 min dist 7 1 0 1

A C

B D

min dist 2 0 1 3 via B via C to A - - to B 2 8 to C 3 7 to D 5 8 from Node A min dist 0 2 7 8 Make sure you know why this is 5, not 4!