Routing protocols are divided into two general groups: interior and exterior protocols. An interior protocol is a routing protocol used inside - interior to - an independent network system. In TCP/IP terminology, these independent network systems are called autonomous systems.  Within an autonomous system (AS), routing information is exchanged using an interior protocol chosen by the autonomous system's administration.
All interior routing protocols perform the same basic functions. They determine the "best" route to each destination, and they distribute routing information among the systems on a network. How they perform these functions, in particular, how they decide which routes are best, is what makes routing protocols different from each other. There are several interior protocols:
Of these protocols, we will discuss RIP and OSPF in detail. OSPF is widely used on routers. RIP is widely used on UNIX systems. We will start the discussion with RIP.
As delivered with most UNIX systems, Routing Information Protocol (RIP) is run by the routing daemon routed (pronounced "route" "d"). When routed starts, it issues a request for routing updates and then listens for responses to its request. When a system configured to supply RIP information hears the request, it responds with an update packet based on the information in its routing table. The update packet contains the destination addresses from the routing table and the routing metric associated with each destination. Update packets are issued in response to requests, as well as periodically to keep routing information accurate.
To build the routing table, routed uses the information in the update packets. If the routing update contains a route to a destination that does not exist in the local routing table, the new route is added. If the update describes a route whose destination is already in the local table, the new route is used only if it has a lower cost. The cost of a route is determined by adding the cost of reaching the gateway that sent the update to the metric contained in the RIP update packet. If the total metric is less than the metric of the current route, the new route is used.
RIP also deletes routes from the routing table. It accomplishes this in two ways. First, if the gateway to a destination says the cost of the route is greater than 15, the route is deleted. Second, RIP assumes that a gateway that doesn't send updates is dead. All routes through a gateway are deleted if no updates are received from that gateway for a specified time period. In general, RIP issues routing updates every 30 seconds. In many implementations, if a gateway does not issue routing updates for 180 seconds, all routes through that gateway are deleted from the routing table.
The routed statement is often used without any command-line arguments, but you may want to use the -q option. The -q option prevents routed from advertising routes. It just listens to the routes advertised by other systems. If your computer is not a gateway, you should probably use the -q option.
In the section on static routing we commented out the routed statement found in a startup file. If that statement is in your startup file, no other action is required to run RIP; just boot your system and RIP will run. Otherwise, add the routed command to your startup.
routed reads /etc/gateways at startup and adds its information to the routing table. routed can build a functioning routing table simply by using the RIP updates received from the RIP suppliers. However, it is sometimes useful to supplement this information with, for example, an initial default route or information about a gateway that does not announce its routes. The /etc/gateways file stores this additional routing information.
The most common use of the /etc/gateways file is to define an active default route, so we'll use that as an example. This one example is sufficient because all entries in the /etc/gateways file have the same basic format. On peanut , the following entry specifies almond as the default gateway:
net 0.0.0.0 gateway 172.16.12.1 metric 1 active
The entry starts with the keyword
Next is the keyword
Then comes the keyword
entries end with either the keyword
Our sample entry ends with the keyword
RIP is easy to implement and simple to configure. Perfect! Well, not quite. RIP has three serious shortcomings:
Nothing can be done to change the limited network diameter. A small metric is essential to reduce the impact of counting to infinity. However, limited network size is the least important of RIP's shortcomings. The real work of improving RIP concentrates on the other two problems, slow convergence and classful routing.
Features have been added to RIP to address slow convergence. Before discussing them we must understand how the "count-to-infinity" problem occurs. Figure 7.2 illustrates a network where a counting-to-infinity problem might happen.
Figure 7.2 shows that almond reaches subnet 3 through pecan and then through filbert . Subnet 3 is 2 hops away from almond and 1 hop away from pecan . Therefore pecan advertises a cost of 1 for subnet 3 and almond advertises a cost of 2, and traffic continues to be routed through pecan . That is, until something goes wrong. If filbert crashes, pecan waits for an update from filbert for 180 seconds. While waiting, pecan continues to send updates to almond that keep the route to subnet 3 in almond 's routing table. When pecan 's timer finally expires, it removes all routes through filbert from its routing table, including the route to subnet 3. It then receives an update from almond advertising that almond is 2 hops away from subnet 3. pecan installs this route and announces that it is 3 hops away from subnet 3. almond receives this update, installs the route, and announces that it is 4 hops away from subnet 3. Things continue on in this manner until the cost of the route to subnet 3 reaches 16 in both routing tables. If the update interval is 30 seconds, this could take a long time!
Split horizon and poison reverse are two features that attempt to avoid counting to infinity. Here's how:
Split horizon and poison reverse solve the problem described above. But what happens if almond crashes? Refer to Figure 7.2 With split horizon, salted and roasted do not advertise to almond the route to subnet 12 because they learned the route from almond . They do, however, advertise the route to subnet 12 to each other. When almond goes down, salted and roasted perform their own count to infinity before they remove the route to subnet 12. Triggered updates address this problem.
Triggered updates are a big help. Instead of waiting the normal 30-second update interval, a triggered update is sent immediately. Therefore, when an upstream router crashes or a local link goes down, immediately after the router updates its local routing table, it sends the changes to its neighbors. Without triggered updates, counting to infinity can take almost 8 minutes! With triggered updates, neighbors are informed in a few seconds. Triggered updates also use network bandwidth efficiently. They don't include the full routing table; they include only the routes that have changed.
Triggered updates take positive action to eliminate bad routes. Using triggered updates, a router advertises the routes deleted from its routing table with a infinite cost to force downstream routers to also remove them. Again, look at Figure 7.2 If almond crashes, roasted and salted wait 180 seconds and remove the routes to subnets 1, 3, and 12 from their routing tables. They then send each other triggered updates with a metric of 16 for subnets 1, 3, and 12. Thus they tell each other that they cannot reach these networks and no count to infinity occurs. Split horizon, poison reverse, and triggered updates go a long way to eliminating counting to infinity.
It is the final shortcoming - the fact that RIP is incompatible with CIDR supernets and variable-length subnets - that caused the RIP protocol to be moved to "historical" status in 1996. RIP is not compatible with current and future plans for the TCP/IP protocol stack. A new version of RIP had to be created to address this final problem.
RIP Version 2 (RIP-2), defined in RFC 1723, is a new version of RIP. It is not a completely new protocol. It simply defines extensions to the RIP packet format. RIP-2 adds a network mask and a next hop address to the destination address and metric found in the original RIP packet.
The network mask frees the RIP-2 router from the limitation of interpreting addresses based on strict address class rules. The mask is applied to the destination address to determine how the address should be interpreted. Using the mask, RIP-2 routers support variable-length subnets and CIDR supernets.
The next hop address is the IP address of the gateway that handles the route. If the address is 0.0.0.0, the source of the update packet is the gateway for the route. The next hop route permits a RIP-2 supplier to provide routing information about gateways that do not speak RIP-2. Its function is similar to an ICMP Redirect, pointing to the best gateway for a route and eliminating extra routing hops.
RIP-2 adds other new features to RIP. It transmits updates via the multicast address 22.214.171.124 to reduce the load on systems that are not capable of processing a RIP-2 packet. RIP-2 also introduces a packet authentication scheme to reduce the possibility of accepting erroneous updates from misconfigured systems.
Despite these changes, RIP-2 is compatible with RIP. The original RIP specification allowed for future versions of RIP. RIP has a version number in the packet header, and it had several empty fields for extending the packet. The new values used by RIP-2 did not require any changes to the structure of the packet. The new values are simply placed in the empty fields that the original protocol reserved for future use. Properly implemented RIP routers can receive RIP-2 packets and extract the data that they need from the packet without becoming confused by the new data.
Split horizon, poison reverse, triggered updates, and RIP-2 eliminate most of the problems with the original RIP protocol. But RIP-2 is still a distance vector protocol. There are other, newer routing technologies that are considered superior for large networks. In particular, link-state routing protocols are favored because they provide rapid routing convergence and reduce the possibility of routing loops.
Open Shortest Path First (OSPF), defined by RFC 2178, is a link-state protocol. As such, it is very different from RIP. A router running RIP shares information about the entire network with its neighbors. Conversely, a router running OSPF shares information about its neighbors with the entire network. The "entire network" means, at most, a single autonomous system. RIP doesn't try to learn about the entire Internet, and OSPF doesn't try to advertise to the entire Internet. That's not their job. These are interior routing protocols; and so their job is to construct the routing inside of an autonomous system. OSPF further refines this task by defining a hierarchy of routing areas within an autonomous system:
Only a large autonomous system needs to be subdivided into areas. The sample network shown in Figure 7.2 is small and would not need to be divided. We can, however, use it as an example to illustrate the different areas. We could divide this autonomous system into any areas we wish. Assume we divide it into three areas: area 1 contains subnet 3; area 2 contains subnet 1 and subnet 12; and area 3 contains subnet 25, subnet 36, and the PPP links. Furthermore, we could define area 1 as a stub area because filbert is that area's only area border router. We also could define area 2 as the backbone area because it interconnects the other two areas and all routing information between areas 1 and 3 must be distributed by area 2. Area 2 contains two area border routers, almond and filbert , and one interior router, pecan . Area 3 contains three routers: almond , roasted , and salted .
Clearly OSPF provides lots of flexibility for subdividing an autonomous system. But why is it necessary? One problem for a link-state protocol is the large quantity of data that can be collected in the link-state database and the amount of time it can take to calculate the routes from that data. A look at the protocol shows why this is true.
Every OSPF router builds a directed graph of the entire network using the Dijkstra Shortest Path First (SPF) algorithm. A directed graph is a map of the network from the perspective of the router, that is, the root of the graph is the router. The graph is built from the link-state database, which includes information about every router on the network and all the neighbors of every router. The link-state database for the autonomous system in Figure 7.2 contains 5 routers and 10 neighbors: filbert has 1 neighbor, pecan ; pecan has 2 neighbors, filbert and almond ; almond has 3 neighbors, pecan , salted , and roasted ; salted has 2 neighbors, almond and roasted ; and roasted has 2 neighbors, salted and almond . Figure 7.3 shows the graph of this autonomous system from the perspective of filbert . The Dijkstra algorithm builds the map in this manner:
The information in the link-state database is gathered and distributed in a simple and efficient manner. An OSPF router discovers its neighbors through the use of Hello packets.  It sends Hello packets and listens for Hello packets from adjacent routers. The Hello packet identifies the local router and lists the adjacent routers from which it has received packets. When a router receives a Hello packet that lists it as an adjacent router, it knows it has found a neighbor. It knows this because it can hear packets from that neighbor and, because the neighbor lists it as an adjacent router, the neighbor must be able to hear packets from it. The newly discovered neighbor is added to the local system's neighbor list.
The OSPF router then advertises all of its neighbors. It does this by flooding a Link-State Advertisement (LSA) to the entire network. The LSA contains the address of every neighbor and the cost of reaching that neighbor from the local system. Flooding means that the router sends the LSA out of every interface and that every router that receives the LSA sends it out of every interface except the one from which it was received. To avoid flooding duplicate LSAs, the routers store a copy of the LSAs they receive and discard duplicates.
Figure 7.2 provides an example. When OSPF starts on pecan it sends a Hello packet on subnet 1 and one on subnet 12. filbert and almond hear the Hello and respond with Hello packets that list pecan as an adjacent router. pecan hears their Hello packets and adds them to its neighbor list. pecan then creates an LSA that lists filbert and almond as neighbors with appropriate cost assigned to each. For instance, pecan might assign a cost of 5 to filbert and a cost of 10 to almond . pecan then floods the LSA on subnet 1 and subnet 12. filbert hears the LSA and floods it on subnet 3. almond receives the LSA and floods it on both of its PPP links. salted floods the LSA on the link toward roasted , and roasted floods it on the same link to salted . When salted and roasted received the second copy of the LSA, they discarded it, because it duplicated one that they have already received from almond . In this manner, every router in the entire network receives every other router's link-state advertisement.
OSPF routers track the state of their neighbors by listening for Hello packets. Hello packets are issued by all routers on a periodic basis. When a router stops issuing packets, it or the link it is attached to is assumed to be down. Its neighbors update their LSA and flood them through the network. The new LSAs are included into the link-state database on every router on the network and every router recalculates their network map based on this new information. Clearly, limiting the number of routers by limiting the size of the network reduces the burden of recalculating the map. For many networks the entire autonomous system is small enough. For others, dividing the autonomous system into areas improves efficiency.
Another feature of OSPF that improves efficiency is the designated router . The designated router is one router on the network that treats all other routers on the network as its neighbors, while all other routers treat only the designated router as their neighbor. This helps reduce the size of the link-state database and thus improves the speed of the shortest-path-first calculation. Assume a broadcast network with 5 routers. Five routers each with 4 neighbors produce a link-state database with 20 entries. But if one of those routers is the designated router, then that router has 4 neighbors and all other routers have only 1 neighbor, for a total of 10 link-state database entries. While there is no need for a designated router on such a small network, the larger the network, the more dramatic the gains. For example, a broadcast network with 25 routers has a link-state database of 50 entries when a designated router is used, versus a database of 600 entries without one.
OSPF provides the router with an end-to-end view of the route between two systems instead of the limited next-hop view provided by RIP. Flooding quickly disseminates routing information throughout the network. Limiting the size of the link-state database through areas and designated routers speeds the SPF calculation. Taken altogether, OSPF is an efficient link-state routing protocol.
OSPF also offers additional features. It provides password authentication to ensure that the update comes from a valid router. Currently OSPF uses an eight-character, clear-text password. Work is underway to add a Message Digest 5 (MD5) crypto-checksum for stronger authentication.
OSPF also supports equal-cost multi-path routing . This mouthful means that OSPF routers can maintain more than one path to a single destination. Given the proper conditions, this feature can be used for load balancing across multiple network links. However, most systems are not designed to take advantage of this feature. Refer to your router's documentation to see if it supports load balancing across equal-cost OSPF routes.