How SPF works
In the link status routing protocol, Each router knows all the routers in the network and the links connected to these routers. In OSPF, this information is contained in the Link State notice (LSA); In ISIS, this information is included in the Link State group (LSP.
Once the router knows all other routers and their links, it runs the Dijkstra shortest routing priority algorithm to determine the shortest path from the router to other routers in the network.
This example describes how router A runs SPF to establish its own route table.
After each router in the network completes its own information flooding, all routers know the links between other routers and them. Therefore, the link status database (LSDB) on each vro is shown in the following table:
++ ++
Vro{ {neighbor, cost} pair
A {B, 5} {C, 10}
B {A, 5} {C, 3} {D, 8}
C {A, 10} {B, 3} {D, 4}
D {B, 8} {C, 4}
========================================================== ========================
Next, how does router A handle this information?
In SPF computing, each vro maintains two lists:
· A node list on the shortest path to the destination. This list is also called the PATH list or PATHS list ). The most important thing about the path list is that the list records the shortest path to the destination address.
· The Next Hop list may or may not be in the shortest path to the target address. This list is called the TENTatitve or TENT list.
Each list is a table consisting of {vro, distance, next hop} ({router, distance, next-hop}) from the current vro perspective.
Why is it a triple? You need to know the router to be reached in the PATH list and TENT list, so the first part of the productkey is undoubtedly the name of the router. In reality, the router name is often used instead of the text name. The next hop is the router that must pass through before reaching the node. The third part of the productkey, devicename, and devicesecret indicate the cost of reaching the node.
Why are names in all tables in big words? This is just a way of writing. They are not the first letter in upper case, but only in upper case. Most examples of SPF computing and many SPF-related debugging content are related to the content in the PATH and TENT lists.
It is easy to calculate the shortest path of each node. Each vro runs the following algorithms:
Step 1: Add yourself to the PATH list, and the distance is 0. The next hop is also your own. When running SPF, the router regards itself as "self" or root node, because this node is the root node of shortest-path tree.
Step 2: extract the newly entered node from the PATH list. This node is called a PATH node ). Find the neighbor list of the PATH node, add each neighbor in the list to the TENT list, and set the next hop to the PATH node, unless the neighbor is already in the TENT or PATH list and the cost is small. The nodes added to the TENT list are called TENT nodes. The cost of reaching the TENT node is set to the cost from the root node to the PATH node plus the sum of the cost from the PATH node to the TENT node. If the added node already exists in the TENT list, but the cost is high, the current node replaces the costly node.
Step 3: Find the lowest cost neighbor in the TENT list, add the neighbor to the PATH list, and repeat Step 2. If the TENT list is empty, stop.
For example:
For example, vroa A uses this method to create A route table.
Step 1: Add yourself to the PATH list. The distance is 0 and the next hop is your own. The database of vroa A is shown in the table.
Router A's PATH list and TENT list
++ ++
PATH list TENT list
{A, 0, 0} (empty)
========================================================== ============================
Step 2: extract the newly entered node from the PATH list. This node is called a PATH node ). Find the neighbor list of the PATH node, add each neighbor in the list to the TENT list, and set the next hop to the PATH node, unless the neighbor is already in the TENT or PATH list and the cost is small. If the added node already exists in the TENT list, but the cost is high, the current node replaces the costly node.
In this example, {B, 5, B} and {C, 10, C} are added to the TENT list, as shown in the table:
R: rgb (255, 0, 0); PATH list and TENT list after step 2 of FONT
++ ++
PATH list TENT list
{A, 0, 0} {B, 5, B}
{C, 10, C}
========================================================== ==================
Step 3: Find the lowest cost neighbor in the TENT list, add the neighbor to the PATH list, and repeat Step 2. If the TENT list is empty, stop.
{B, 5, B} is moved to the PATH list, because this is the shortest PATH to B. Because {C, 10, C} is the only other neighbor of router A, and the cost to C is higher than that to B, it is impossible to have a path that is less costly than B.
R: rgb (255, 0, 0); PATH list and TENT list after step 3 of FONT
++ ++
PATH list TENT list
{A, 0, 0} {C, 10, C}
{B, 5, B}
========================================================== ====================
Step 4: Repeat Step 2. This node is called a PATH node ). Find the neighbor list of the PATH node, add each neighbor in the list to the TENT list, and set the next hop to the PATH node, unless the neighbor is already in the TENT or PATH list and the cost is small. If the added node already exists in the TENT list, but the cost is high, the current node replaces the costly node.
Check the neighbor of vrob B. The link cost from router B to router C is 3, and from router B to router C is 8. Vroc C is added to the TENT list. The cost (from A to B) is 8. It is 5 (from "self" to B) after adding 3 (the cost from B to C), the next hop is B, and vrod D is added to the TENT table. The cost is 13, equal to 5 (from the root node to the cost of B) plus 8 (from B to D), the next hop is B. Because the cost from B to C is less than the cost of the path from C to C 10, the path with the cost of 10 is deleted from the TENT list.
R: rgb (255, 0, 0); PATH list and TENT list on router A after step 4 of FONT
++ ++
PATH list TENT list
{A, 0, 0} {C, 10, C}
{B, 5, B} {C, 8, B}
{D, 13, B}
========================================================== ================================
Step 5: Find the PATH with the lowest cost in the TENT list, add it to the PATH list, and repeat Step 2. If the TENT list is empty, stop. The PATH from {C, 8, B} to C is moved to the PATH list.
R: rgb (255, 0, 0); PATH list and TENT list on router A after step 5 of FONT
++ ++
PATH list TENT list
{A, 0, 0} {D, 13, B}
{B, 5, B}
{C, 8, B}
========================================================== ================================
Step 6: retrieve the newly added node from the PATH list, find the neighbor list of the PATH node, and add each neighbor in the list to the TENT list, unless the neighbor is already in the TENT or PATH list and the cost is small. If the added node already exists in the TENT list, but the cost is high, the current node replaces the costly node.
Under this rule, the price is 12 path from B to D (actually B-> C-> D) replaced the path from B-> D to D at the cost of 13.
R: rgb (255, 0, 0); PATH list and TENT list on router A after step 6 of FONT
++ ++
PATH list TENT list
{A, 0, 0} {D, 13, B}
{B, 5, B} {D, 12, B}
{C, 8, B}
========================================================== ====================
Step 7: Find the lowest cost neighbor in the TENT list, add it to the PATH list, and repeat Step 2. If the TENT list is empty, stop.
The PATH to D is moved to the PATH list.
R: rgb (, 0); PATH list and TENT list on vroa A after step 7 of FONT: the TENT list is empty
++ ++
PATH list TENT list
{A, 0, 0}
{B, 5, B}
{C, 8, B}
{D, 12, B}
========================================================== ====================
Step 8: Find the lowest cost neighbor in the TENT list, add it to the PATH list, and repeat Step 2. If the TENT list is empty, stop.
The TENT list is empty. Because D does not have a neighbor in the PATH list, it is stopped. Then, the PATH list becomes the route table of.
Route table of router
++ ++
Next Hop at node cost
A 0 self (self)
B 5 B (direct connection)
C 8 B
D 12 B
========================================================== ================
This is how the SPF algorithm works. The topology (based on the route table of vroa A) appears.
It can be seen that the traffic from vroa A never goes through the link from A to C or from B to D.
Two things are unexpected. First, the traffic passing through the B-to-D link only comes from.
Second, the link between router A and router C is useless because it costs 10 too much. In the actual network, such links are actually abolished due to expensive weights, unless other links in the network are invalid. The actual SPF implementation is more complicated than described here, but the main idea is introduced here.
From REX_IT_Lab blog