Each router makes it own routing decision, independently of all other routers.
The decision the router made is based on its
This forwarding table is build by taking the best route from each
A router have different routing tables, for:
- connected networks (those that are configured on a router interface)
- static routes: routes that are manually added by the router administrator
- ospf: routes learned by the OSPF protocol (if applicable)
- bgp: routes learned by the BGP protocol (if applicable)
to build the forwarding table from those routing tables there's a specific process:
- take the route with the longest prefix first
- if there's 2 identical routes in different routing table, use the metric to choose the best one. There's a default metric for each protocol (table) which is different for each one (an admin may change those metrics)
So the best path chosen, is only chosen based on those information.
Of course each routing protocol has its own way to distribute route to the participating routers, trying to provide the best path to each router, but depending on the routing protocol used (for example EIGRP vs OSPF) you may end to different results.
I.E. if you build a complex topology and use OSPF, packets will take a certain path, and if you build the same topology with EIGRP instead, packets may take a different path.