# Routing 101: Routing Algorithms

1. Routing Algorithms Within Routing Protocols
2. Summary
3. Q&amp;A
• Print
Improve the performance of your network by implementing the best routing protocols. Learn how routing algorithms work for a better understanding of routing protocols and the concepts behind why some protocols work better in certain situations.
This chapter is from the book

## Introduction

Hour 3 will focus primarily on routing algorithms. The routing algorithm is a formula that is stored in the router's memory. The routing algorithm your protocol uses is a major factor in the performance of your routing environment. The purpose of the routing algorithm is to make decisions for the router concerning the best paths for data.

Think of the routing algorithm as the traffic officer of the router. In the same way that traffic officers guide and shape the way cars drive through busy intersections, routing algorithms make decisions concerning the path data will take from one network to another.

The router uses the routing algorithm to compute the path that would best serve to transport the data from the source to the destination. However, you cannot directly choose the algorithm that your router uses. Rather, the routing protocol you choose for your network determines which algorithm you will use. For example, whereas the routing protocol RIP may use one type of routing algorithm to help the router move data, the routing protocol OSPF uses another.

You are learning about routing algorithms in this lesson as a prerequisite to future lessons on routing protocols. Knowing how routing algorithms work will give you a better understanding of routing protocols and the concepts behind why some protocols work better in certain situations. Many of the differences between particular routing protocols are directly related to differences in their routing algorithms.

The routing algorithm a protocol uses cannot be changed or altered. If the algorithm a particular protocol uses does not favor your networking environment, the only way to change it is to change routing protocols.

Because the routing algorithm has so much impact on the overall performance of your network, you should research the algorithms each protocol uses before deciding which to implement on your network.

There are two major categories of routing algorithms that can be used by routing protocols—distance vector or link-state. When we begin to discuss routing protocols, you will find that the protocols are either distance vector or link-state. This convention is a direct result of the type of routing algorithm used by the protocol. Therefore, every routing protocol labeled "distance vector" uses the distance vector algorithm; conversely, every link-state protocol uses the link-state algorithm.

Note

The particulars of your network, such as the number of computers, the number of routers, and the existence (or lack) of a WAN will determine which type of algorithm you choose for your environment.

The next section will briefly discuss the relationship formed between routing protocols and their algorithms. Routing protocols provide information to routing algorithms in the form of variables or metrics. Routing algorithms, on the other hand, provide routing protocols with the best path for the router to send data.

## Routing Algorithms Within Routing Protocols

Many properties separate routing protocols from each other. Characteristics such as the speed with which they operate, the way they conduct updates, and the information they gather to perform their job make routing protocols unique. However, one feature that routing protocols share with one another is their routing algorithm. While many different routing protocols are available for you to use on your network, they all utilize one of only two different algorithms.

The major job of the routing protocol is to provide the information needed by the routing algorithm to compute its decisions. This is where many protocols differ. The information provided to the algorithm (thereby affecting the calculation) can be different from protocol to protocol. A good way to illustrate this is to think of the routing algorithm as an Internet search engine, and you as the routing protocol. Let's say that you want the best place to get information about Cisco routers. You type the word "routers" into the search engine. The search engine processes your input and returns a myriad of results. Eventually you will reach the Cisco home page.

Using the same search engine, you could have entered the keywords "Cisco routers." This search would have produced a more direct result. Although the search engine (routing algorithm) did not change, the product of the formula was directly affected by the information that was given to it. Whereas some routing protocols will supply general information to an algorithm, others will be more specific. Knowing how the algorithm will react in these situations will help you choose the algorithm (and consequently, the protocol) that is best for you.

The routing protocol gathers certain information about networks and routers from the surrounding environment. This information is stored within a routing table in the router's memory. The routing algorithm is run against the information within this table to calculate the "best" path from one network to another.

The information contained within the table is plugged into the routing algorithm. Calculating the new values within the formula then generates a sum. The result of this calculation is used to determine where to send information in a particular scenario. For example, Table 3.1 illustrates a sample routing table for a fictitious routing environment.

Note

The information being passed to the routing algorithm within the routing table is gathered by the routing protocol through a process known as a routing update. A network or routing engineer will assign this information to each router. Then, through a series of updates, each router will tell the other what information it has. Eventually, an entire routing table will be built. You will learn more about how routing updates work as we examine each routing protocol.

#### Table 3.1 A Fictitious Routing Table

 Router Link Metric Router A to Router B 2 Router B to Router C 3 Router A to Router C 6 Router C to Router D 5

Note

This scenario has been simplified to make a discussion of routing algorithms possible without focusing on one particular protocol.

Our sample routing algorithm states that the best path to any destination is the one that has the lowest metric value. When Router A is presented with a packet bound from Router C, the routing table immediately shows two possible paths to choose from. The first choice is to send the packet from Router A directly over the link to Router C. The second option is to send the packet from Router A to Router B and then on to Router C. The routing algorithm is used to determine which option is best. Figure 3.1 illustrates the network that Router A and Router C belong to. (Notice how the routers and metrics in the figure correspond to the routing table information in Table 3.1.)

Figure 3.1 A sample network.

Whereas some routing protocols might only provide one metric to the routing algorithm, others might provide up to ten. As we cover each routing protocol, we will discuss what metrics they gather for the routing algorithm to use. On the other hand, whereas two protocols might both send only one metric to the algorithm, the origin of that metric might differ from protocol to protocol. One routing protocol might give an algorithm the single metric of cost, but that cost could represent something different than another protocol using the same metric.

The algorithm in our example states that the best path is the one with the lowest metric value. Therefore, by adding the metric numbers associated with each possible link, we see that the route from Router A to Router B to Router C has a metric value of 5, while the direct link to Router C has a value of 6. The algorithm selects the A-B-C path and sends the information along.

Note

A metric is a number used as a standard of measurement for the links of a network. Each link is assigned a metric to represent anything from monetary cost to use the line, to the amount of available bandwidth.

Although simplistic, this example demonstrates just how routing algorithms function as the true decision engine within the router. The specific information that is stored within the routing table, and how the algorithm uses it, depends on the protocol. Let's examine the differences between these two algorithmic types.

### Distance Vector Algorithms

Distance vector algorithms are similar to the simple algorithm used in Table 3.1. A distance vector algorithm uses metrics known as costs to help determine the best path to a destination. The path with the lowest total cost is chosen as the best path.

When a router utilizes a distance vector algorithm, different costs are gathered by each router. These costs can be completely arbitrary, administrator-assigned numbers, such as five. Although the number five might not be of any significance to an outside observer, the administrator might have assigned it to a particular link to represent the reliability of that link.

Costs can also be dynamically gathered values, such as the amount of delay experienced by routers when sending packets over one link as opposed to another. All the costs (assigned and otherwise) are compiled and placed within the router's routing table. All the costs gathered are then used by the algorithm to calculate a best path for any given network scenario.

Although there are many resources that will offer complex mathematical representations of what distance vector algorithms are and how they compute their decisions, the core concept remains the same—by adding the metrics for every optional path on a network, you will come up with at least one best path. The formula for this is as follows:

`M(i,k) = min [M(i,t) + M(t,k)]`

This formula states that the best path between two networks (M(i,k)) can be found by finding the lowest (min) value of paths between all network points. Let's look again at the routing information in Table 3.1. Plugging this information into the formula, we see that the route from A to B to C is still the best path:

`5(A,C) = min[2(A,B) + 3(B,C)]`

Whereas the formula for the direct route A to C looks like this:

`6(A,C) = min[6(A,C)]`

This example illustrates how distance vector algorithms use the information passed to them to make informed routing decisions. Do not spend too much time memorizing the algorithm, as you will rarely see it in the real world. The algorithms used by routers and routing protocols are not configurable, nor can they be modified.

Another major difference between distance vector algorithms and link state protocols (covered in the next section) is that when distance vector routing protocols update each other, all or part of the routing table (depending on the type of update) is sent from one router to another. By this process, each router is exposed to the information contained within the other router's tables, thus giving each router a more complete view of the networking environment and enabling them to make better routing decisions. The process of router updates is described in more detail in the next section.

Examples of distance vector algorithms include RIP and BGP, two of the more popular protocols in use today. Other popular protocols such as OSPF are examples of protocols which use the link state routing algorithm.

Link-state algorithms work within the same basic framework that distance vector algorithms do in that they both favor the path with the lowest cost. However, link-state protocols work in a somewhat more localized manner. Whereas a router running a distance vector algorithm will compute the end-to-end path for any given packet, a link-state protocol will compute that path as it relates to the most immediate link. That is, where a distance vector algorithm will compute the lowest metric between Network A and Network C, a link-state protocol will compute it as two distinct paths, A to B and B to C.

This process is best for larger environments that might change fairly often. Link-state algorithms enable routers to focus on their own links and interfaces. Any one router on a network will only have direct knowledge of the routers and networks that are directly connected to it (or, the state of its own links). In larger environments, this means that the router will use less processing power to compute complicated paths.

The router simply needs to know which one of its direct interfaces will get the information where it needs to go the quickest. The next router in line will repeat the process until the information reaches its destination.

Another advantage to such localized routing processes is that protocols can maintain smaller routing tables. Because a link-state protocol only maintains routing information for its direct interfaces, the routing table contains much less information than that of a distance vector protocol that might have information for multiple routers.