Dx(y) is an estimation of the least-cost path from x to y
The distance vector, Dx, maintains a list of estimates for each node in the graph: [Dx(y):y∈N], where N is the set of all destinations.
Each node, x knows the cost, c(x,v) to each neighbor v, its distance vector, and its neighbors’ distance vectors.
In the algorithm, each node periodically sends its own distance vector estimates to its neighbors. When it receives a new estimate, it can update its own distance vector and if it changes, update its own neighbors. The distance estimates for any node will eventually converge to the actual least cost, dx(y).
The algorithm is iterative and asynchronous: each local iteration is called by either a local link cost change or a DV update message from its neighbor.
The algorithm is distributed: each node notifies its neighbors only when its DV changes, and each node only knows the next hop, not the entire path.
Hence, each node is in one of three state:
Wait for change in local link cost, or message from a neighbor
distance_vector = []
neighbor_distance_vectors = {}
definit():
for y in destinations:
distance_vector[y] = cost(self, y) # Infinity if not a neighborfor w in neighbors:
neighbor_distance_vectors[w] = [INFINITY for y in destinations]
send(w, distance_vector)
whileTrue:
get_update_or_link_cost_change()
for y in destinations:
distance_vector[y] = min([cost(self, v) + neighbor_distance_vectors[v][y] for v in neighbors])
if change_occurred:
for y in neighbors:
send(y, distance_vector)
Good news travels fast: if a link cost is lowered, this change propagates through the network quickly.
However, there is an issue when a link cost increases. For example, assume x→z>x→y→z. If the link cost from x→y increases such that the new best path from x to y is x→z→y, an issue will occur as the algorithm is asynchronous: z still thinks the best path from z to y is z→x→y. Hence, it will generate a routing loop: x→z→x→z….
Initial state: link costs of c(x,y)=1, c(y,z)=2, c(z,x)=20.
x
y
z
x
0
1
3 (y)
y
1
0
2
z
3 (y)
2
0
At t0, y detects c(x,y)=40. y thinks the best route to x is now through z:
So z tells w that Dz(x)=∞ and w tells y that Dw(x)=∞; they lie to the node they rely on for routing, ensuring they do not send requests back to them.
At t0, y detects cost(x,y)=60 and recalculates its vector table: Dy(x) is the minimum of:
cost(y,z)+Dz(x)=3+6=9
cost(y,x)+Dx(x)=60+0=60
cost(y,w)+Dw(x)=1+∞
Hence, Dy(x)=9 (through z). Now, y notifies w that Dy(x)=9 and z that Dy(x)=∞.
Now w recomputes Dw(x):
cost(w,y)+Dy(x)=1+9=10
cost(w,z)+Dz(x)=1+∞
Hence, Dw(x)=10 (through y). Now, w notifies z that Dw(x)=10 and y that Dw(x)=∞.
Now, z recomputes Dz(x):
cost(z,w)+Dw(x)=1+10=11
cost(z,y)+Dy(x)=3+∞
cost(z,x)+Dx(x)=50+0
Hence, Dz(x)=11 (through w). Now z notifies y that Dz(x)=11 and w that Dz(x)=∞.
Now, y recomputes Dy(x):
cost(y,z)+Dz(x)=3+11=14
cost(y,x)+Dx(x)=60+0=60
cost(y,w)+Dw(x)=1+∞
Hence, Dy(x)=14 (through z). The process repeats.
The computed path from y to x is thus y→z→w→y→…; a routing loop occurs.
To fix this, RIP limits the maximum cost of a path is limited to 15.