How a Router Selects the Best Route

A router’s main responsibility is to receive packets and forward them to the right destination. But how does a router think and what is the process of deciding the best route to forward a packet to? This post describes this decision process and preference order based on examples.

1. Longest prefix length – When multiple routes with different prefix length 

A destination IP address can belong to various subnets that exist in the routing table. When there are multiple routes with different prefix lengths to a destination, then the longest match is always preferred regardless of the routing protocol used. For example, if the routing table contains the prefixes:

10.1.1.0/20
10.1.1.0/24
10.1.1.0/27

then a packet with destination IP address 10.1.1.1 belongs to all of those subnets. In this case, the longest prefix match is preferred. That means that the router will choose the subnet that is matching most of its bits to the destination IP address, let’s see how:

The network address has the following binary representation:

10.1.1.0 → 00001010.00000001.00000001.00000000

The different subnet mask lengths are:

/20 → 00001010.00000001.0000|0001.00000000
/24 → 00001010.00000001.00000001|.00000000
/27  00001010.00000001.00000001.000|00000

The destination IP address in binary form is:

10.1.1.1  00001010.00000001.00000001.00000001

As you can see, subnet 10.1.1.0/27 is the longest prefix match of the address 10.1.1.1, so this route is going to be selected by the router in order to forward the packet.

2. Administrative distance – When multiple routes with same prefix length 

A particular destination can be advertised to the router by various routing protocols, for example static route, BGP, OSPF, etc. In this case, the selection of the best route is based on the “administrative distance” where the lowest value is preferred. Administrative distance is a value which measures how “trustworthy” a routing protocol is and there are specific values for it (it can be adjusted though manually). The table below describes the administrative distance of some protocols in a Cisco router:

Protocol Administrative Distance
Connected 0
Static 1
eBGP 20
EIGRP internal 90
IGRP 100
OSPF 110
IS-IS 115
RIP 120
EIGRP external 170
iBGP 200

For instance, if the following routes are advertised in the routing table:

10.1.1.0/27 BGP
10.1.1.0/27 OSPF
10.1.1.0/27 Static

the router will select the static route in order to forward the packet, since static has the lowest administrative distance.

3. Metrics – When multiple routes with same prefix length and protocol

A routing protocol can learn multiple paths for the same destination. In this case, each routing protocol uses their own internal metrics (for example based on distance, speed, hops, etc.) to calculate which of those paths is the best one.

Related articles

Advertisements

About TelcoNotes

IP & VoIP networking

Posted on September 9, 2013, in IP Routing and tagged , , , . Bookmark the permalink. 2 Comments.

  1. Can I simply say what a relief to uncover someone that actually knows what they’re
    talking about online. You certainly understand how to bring a problem to light and make it important.
    More people should look at this and understand this side
    of your story. I can’t believe you are not more popular because you definitely possess the gift.

  2. koh sze jie.

    Agreed. Nice article.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: