The distance-vector routing algorithm is used in computer networking to determine the best path for data to take through the network. It can be tricky to understand, and working out examples by hand is cumbersome, so I built a basic simulator to use as a teaching aid with my undergraduate networking students.

Distance-vector routing uses a decentralized algorithm in which nodes (routers) share distance estimates with each other to eventually find the minimal-distance route between all pairs of nodes in the system. This simulator shows the steps that the algorithm takes, assuming all nodes send and receive messages at the same time on each iteration. It’s a bit ugly, but it works.

If you find bugs or have questions, you can email me. The source code is available in this site’s Git repository.

Instructions

  1. Enter a network graph definition. Each line represents an edge (link) and is of the format n1,n2,d1,d2, where n1 and n2 are the names of the start and end nodes (routers), respectively, and d1 and d2 are the distances from n1 to n2 and from n2 to n1, respectively. If the edge only goes in one direction, the trailing ,d2 may be omitted. Note that this syntax allows specifying two separate edges with different distances and directions on the same line. (A sample definition is pre-populated.)
  2. Click the Start button. Starting will show the initial distance vectors for each node, formatted as a table. The entries show the current estimated distance from the row node to the column node for each node. The first hop node is also shown in parentheses. (For example, if row a, column c had the entry 7 (b), that would mean that node a estimates that it can get to node c with distance 7 by first going to node b.) Starting also renders a preview of the graph with Mermaid, which you can hide by clicking on the Graph preview text.
  3. Use the Next button to step through the iterations of the algorithm, or use the Finish button to run the algorithm until it converges. Entries that change from one step to the next are shown in purple, italic text.
  4. At any point after starting, you can tweak the graph definition and click the Update button to simulate link changes.
  5. To start over, simply enter a new graph definition and press Start again.
Illustrative examples
  • Basic (3 nodes): See how a lower weight, longer (in hops) path is eventually chosen.

    Use the following graph definition:

    a,b,4,4
    b,c,2,2
    a,c,9,9
    
  • Basic (4 nodes): See how a lower weight, longer (in hops) path is eventually chosen.

    Use the following graph definition:

    a,b,7,7
    a,c,3,3
    b,d,2,2
    c,d,1,1
    
  • Link cost decrease: See how the news of a link cost decrease spreads quickly.

    Run the simulator to completion with the following graph definition:

    a,b,4,4
    b,c,2,2
    a,c,9,9
    

    Then modify the graph definition and press Update:

    a,b,1,1
    b,c,2,2
    a,c,9,9
    
  • Link cost increase: See how the news of a link cost increase can cause routing loops and the count-to-infinity problem.

    Run the simulator to completion with the following graph definition and no poisoned reverse:

    a,b,1,1
    b,c,2,2
    a,c,9,9
    

    Then modify the graph definition and press Update:

    a,b,15,15
    b,c,2,2
    a,c,9,9
    
  • Link cost increase with poisoned reverse (3 nodes): See how poisoned reverse can prevent routing loops and the count-to-infinity problem when a link’s cost increases.

    Run the simulator to completion with the following graph definition and poisoned reverse enabled:

    a,b,1,1
    b,c,2,2
    a,c,9,9
    

    Then modify the graph definition and press Update:

    a,b,15,15
    b,c,2,2
    a,c,9,9
    
  • Link cost increase with poisoned reverse (4 nodes): See that poisoned reverse doesn’t always prevent routing loops and count-to-infinity.

    Run the simulator to completion with the following graph definition and poisoned reverse enabled:

    a,b,1,1
    a,c,10,10
    c,b,2,2
    b,d,1,1
    c,d,3,3
    

    Then modify the graph definition and press Update:

    a,b,50,50
    a,c,10,10
    c,b,2,2
    b,d,1,1
    c,d,3,3
    


Graph preview

Output

Click the Start button above to get started.