Advanced Network Section 8
Advanced Network Section 8
Academic year
Routing protocol goal: determine “good” paths (equivalently, routes), from sending hosts to receiving host, through
network of routers
path: sequence of routers packets traverse from given initial source host to final destination host
“good”: least “cost”, “fastest”, “least congested”
Graph abstraction: link costs
Dijkstra’s algorithm
• gives forwarding table for that node p(v): predecessor node along
iterative: after k iterations, know path from source to v
N': set of nodes whose least-
least cost path to k destinations cost-path definitively known
Dijkstra’s algorithm example
B C D E
Step N' D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E)
0 A 4,A 2,A ∞ ∞
1
2
3
4
5
Dijkstra’s algorithm example
B C D E
Step N' D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E)
0 A 4,A 2,A ∞ ∞
2
3
4
Dijkstra’s algorithm example
B C D E
Step N' D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E)
0 A 4,A 2,A ∞ ∞
1 AC 3,C
3,C X 7,C
6,C
2 ACB X
X
5,B 6,B
3
4
5
Dijkstra’s algorithm example
B C D E
Step N' D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E)
0 A 4,A 2,A ∞ ∞
1 AC 3,C
3,C X 7,C
6,C
2 ACB X
X
5,B 6,B
3 X X X 6,B
ACBD
4
Dijkstra’s algorithm example
B C D E
Step N' D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E)
0 A 4,A 2,A ∞ ∞
1 AC 3,C
3,C X 7,C
6,C
2 ACB X
X
5,B 6,B
3
X X X 6,B
ACBD
4 ACBDE
Distance vector algorithm
Distance Vector Routing (DVR) Protocol is a method used by routers to find the best
path for data to travel across a network. Each router keeps a table that shows the shortest
distance to every other router, based on the number of hops (or steps) needed to reach
them. Routers share this information with their neighbors, allowing them to update their
tables and find the most efficient routes. This protocol helps ensure that data moves
quickly and smoothly through the network.
Distance vector
algorithm
Based on Bellman-Ford (BF) equation (dynamic programming):
Bellman-Ford equation
Consider a graph with 5 vertices and 9 edges, where each edge has a weight:
•Vertices: A, B, C, D, E
•Edges with weights:
•A → B: weight 4
•A → C: weight 2
•B → D: weight 2
•B → E: weight 4
•B → C: weight 3
•C → E: weight 5
•C → B: weight 1
•C → D: weight 4
•E → D: weight -5
Initialization: Set the distance to the
source vertex (say vertex A) to 0 and
all other vertices to infinity:
Distance[A] = 0
Distance[B] = ∞
Distance[C] = ∞
Distance[D] = ∞
Distance[E] = ∞
Relax all edges (V - 1) times: Here, V = 5 (the number of vertices), so we
will repeat the process 4 times.
First Iteration:
A → B: Distance[A] + 4= 0 + 4 = 4. So, Distance[B] = 4.
A → C: Distance[A] + 2 = 0 + 2 = 2. So, Distance[C] = 2.
B → D: Distance[B] + 2 = 4 + 2 = 6. So, Distance[D] = 6.
B → C: Distance[B] + 3 = 4 + 3 = 7, but Distance[C] = 2, so no update.
B → E: Distance[B] + 3 = 4 + 3 = 7. So, Distance[E] = 7.
C→ D: Distance[C] + 4 = 2 + 4 = 6. but Distance[D] =6 ,so no update.
C→ E: Distance[C] + 5 = 2 + 5 = 7. but Distance[E] =7 ,so no update.
C→ B: Distance[C] +1= 2 + 1 = 3. So, Distance[B] = 3.
E → D: Distance[E] + -5= 7-5= 2, but Distance[D] = 6, so update
Distance[D]=2.
After the first iteration, the distances are:
Distance[A] = 0
Distance[B] = 3
Distance[C] = 2
Distance[D] = 2
Distance[E] = 7
second Iteration:
A → B: Distance[A] + 3= 0 + 3 = 3. So, Distance[B] = 3.
A → C: Distance[A] + 2 = 0 + 2 = 2. So, Distance[C] = 2.
B → D: Distance[B] + 2 = 3 + 2 = 5. but, Distance[D] = 2.
B → C: Distance[B] + 3 = 3 + 3 = 6, but Distance[C] = 2, so no update.
B → E: Distance[B] + 3 = 3 + 3 = 6. So, Distance[E] = 6.
C→ D: Distance[C] + 4 = 2 + 4 = 6. but Distance[D] =2 ,so update.
C→ E: Distance[C] + 5 = 2 + 5 = 7. but Distance[E] =6 ,so no update.
C→ B: Distance[C] +1= 2 + 1 = 3. but, Distance[B] = 3 ,so no update.
E → D: Distance[E] + -5= 6-5= 1, but Distance[D] = 2, so update
Distance[D]=1.
After the second iteration, the distances are:
Distance[A] = 0
Distance[B] = 3
Distance[C] = 2
Distance[D] = 1
Distance[E] = 6
third Iteration:
A → B: Distance[A] + 4= 0 + 4 = 4. but Distance[B] = 3 so update it.
A → C: Distance[A] + 2 = 0 + 2 = 2. So, Distance[C] = 2.
B → D: Distance[B] + 2 = 3 + 2 = 5. but Distance[D] = 1 so update it
B → C: Distance[B] + 3 = 3 + 3 = 6, but Distance[C] = 2, so no update.
B → E: Distance[B] + 3 = 3 + 3 = 6. but Distance[E] = 6 so no update.
C→ D: Distance[C] + 4 = 2 + 4 = 6. but Distance[D] =1 ,so no update.
C→ E: Distance[C] + 5 = 2 + 5 = 7. but Distance[E] =6 ,so no update.
C→ B: Distance[C] +1= 2 + 1 = 3. but Distance[B] = 3 ,so no update .
E → D: Distance[E] + -5= 6-5= 1, but Distance[D] = 1, so no update
After the third iteration, the distances are:
Distance[A] = 0
Distance[B] = 3
Distance[C] = 2
Distance[D] = 1
Distance[E] = 6
Fourth Iteration:
A → B: Distance[A] + 4= 0 + 4 = 4. but Distance[B] = 3 so update it.
A → C: Distance[A] + 2 = 0 + 2 = 2. So, Distance[C] = 2.
B → D: Distance[B] + 2 = 3 + 2 = 5. but Distance[D] = 1 so update it
B → C: Distance[B] + 3 = 3 + 3 = 6, but Distance[C] = 2, so no update.
B → E: Distance[B] + 3 = 3 + 3 = 6. but Distance[E] = 6 so no update.
C→ D: Distance[C] + 4 = 2 + 4 = 6. but Distance[D] =1 ,so no update.
C→ E: Distance[C] + 5 = 2 + 5 = 7. but Distance[E] =6 ,so no update.
C→ B: Distance[C] +1= 2 + 1 = 3. but Distance[B] = 3 ,so no update .
E → D: Distance[E] + -5= 6-5= 1, but Distance[D] = 1, so no update
After the fourth iteration, the distances are:
Distance[A] = 0
Distance[B] = 3
Distance[C] = 2
Distance[D] = 1
Distance[E] = 6
Conclusion
The Bellman-Ford algorithm successfully calculates
the shortest paths from vertex A to all other
vertices, even with negative weight edges, and
detects any negative weight cycles (none in this
case).