 As we saw, routers need to compute the information in order to deliver a packet from the source to any destination in the network. And in order to do so, they exchange information with other routers on the network to create what are called routing tables. If we look at it a little more in detail, there are actually three types of routing mechanisms that are possible. One mechanism is called source-based routing wherein the entire route is specified at the source itself. There are some algorithms which work in this manner, such as dynamic source routing or DSR, but we will not be getting into details of these algorithms. Another mechanism is to specify the next hop to the route wherein each router has a picture of what are the links that is connected to and what are the hops to different destinations. This is called distance vector routing. A third mechanism is called link state routing wherein the routers only exchange information about the links. Instead of exchanging the entire routing table, all they do is they exchange information about the next hop or the links to which they are directly connected. And as the router gets the information of the links from all over the network, the router is able to create a topology or a picture of the network. Then the router uses this topology in order to determine what is the next hop for sending a given packet. This is a very commonly used mechanism in internet routing because it scales quite well and it is also robust to failures in the network. One example of such link state routing is called the open shortest path first algorithm or OSPF. Now let's look at an example of how the distance vector algorithm works. One basic idea is that each router has a routing table. The routing table is nothing but a vector of distances to every other router that it knows of in the network. So the question is how to find these distances? So very simple idea is used that the distance to the local network is 0, that is the first point. The second point is that when routers exchange tables, they look in their neighbors routing tables and they add the link cost to reach the neighbor. So for example, if A is connected to B which is connected to C, initially A knows only the route up to B and when it receives the update from B saying that B is connected to C with a cost of 1, E now knows that it can reach C with a cost of 2 because it can send the packet to B that is one cost and then B can forward it in turn to C that is a cost of 2. So this is the basic idea of how the routing table is constructed in a distance vector algorithm. Now using this table, the routers find the minimum distances to various destinations in the network. When are these routing tables updated? In order to update the routing table, the algorithm that is used is actually called the Bellman-Ford algorithm. It works iteratively and has three steps. The first step is simply waits for something to change. What can be the change? The change can either be local that some link that is connected to me as a router has gone down or the change can be that I received a packet from one of my neighbors, a routing table update from one of my neighbors. So once the change has happened then what the Bellman-Ford algorithm does is it says recompute the distance table based on the change. So if the link has gone down or if some change has happened in my link then I have to set that link cost to infinity and recompute the routing table. If I have received new information from my neighbor then I have to merge that neighbor's information into my current routing table. The third step is as a result of this if the least cost to any destination in the network has changed then I have to propagate this information to my own neighbors so that that information can be updated in all the routers in the network. So essentially the Bellman-Ford algorithm has three steps, one is to wait for some change to happen, second is as a result of the change if some recomputation has to be done it is done and third as a result of the recomputation if the information has to be repropagated through the network it is propagated. Now we will see an example of how this algorithm works in a typical network.