In this second part of my blog series about the BGP Path Selection Algorithm, I will discuss the following attributes:
- Origin Type
- Lowest MED
- eBGP over iBGP
- Lower RID
The first attribute in the list is the Origin Type or Origin Code, which is a well-known mandatory BGP attribute. There are three possible values for this attribute:
- IGP (i)
- EGP (e)
- Incomplete (?)
When a network is advertised into BGP using a network statement, the origin IGP (i) is used by default. EGP (e) refers to the old Exterior Gateway Protocol (EGP) that was used before BGP and it is not used anymore. Therefore, the e origin code will rarely appear in the BGP table nowadays. Finally, networks that are advertised into BGP using the redistribute command are set with the Incomplete (?) origin code. IGP (i) is preferred over Incomplete (?).
Let’s use the following topology to see this attribute in action:
R2 and R3 are both connected to the LAN segment (192.168.1.0/24 network). An eBGP session is configured between R1 and R2 and between R1 and R3. R2 uses a network statement to advertise the 192.168.1.0/24 network to R1, while R3 uses the redistribute connected command instead.
Here is the BGP configuration on every router:
If we examine the BGP table on R1, we can see that R1 has learned two routes to the 192.168.1.0/24 network:
The preferred path to reach the 192.168.1.0/24 network is through R2, which has the i origin code. The route through R3 has the ? origin since the 192.168.1.0/24 network was advertised into BGP in R3 using redistribution.
The next attribute in the list is the Multi-Exit Discriminator (MED). The MED attribute, also called as metric, is a non-transitive BGP attribute whose purpose is to influence the inbound traffic coming from another AS. When you advertise a network into BGP, by default, the MED is set to the IGP path to reach the network being advertised. Since the MED is a metric, a lower MED is preferred over a higher MED.
Let’s use the following topology to explain the MED attribute:
Above we have two Autonomous Systems (AS): AS100 (R1 and R2) and AS300 (R3). R1 and R2 both advertise the 192.168.1.0/24 network into BGP. Therefore, R3 has two possible paths to reach the 192.168.1.0/24 network.
Let’s begin using the following initial configuration:
If we examine R3 BGP table, we can see that the BGP path selection algorithm has chosen the path through R1:
Notice from the previous output that both routes learned by R3 have a metric of 0. Now let’s set the MED in R1 to 500 by using a route-map:
If we examine R3 BGP table again, we can see that the BGP path selection algorithm has now chosen the path through R2 because it is the path with lower MED:
Let’s discuss the next decision factor used in BGP: eBGP over iBGP. The BGP Path Selection Algorithm always prefers eBGP routes over iBGP routes. Let’s change the previous topology to see this decision step in action:
R1 and R2 are now using an iBGP session between them to share the routes learned from R3. Here is the new BGP configuration on every router:
If we examine the BGP table on R1, we can see that R1 has learned two routes to reach the 192.168.1.0/24 network: one route through R3 (eBGP) and one route through R2 (iBGP). The preferred route is the eBGP route through R3:
If we examen the BGP table on R2, we can see that R2 has also chosen the eBGP route through R3:
If none of the previous attributes can be used as a decision factor to select the best BGP path, the BGP Selection Algorithm will choose the path learned from the peer with the lower RID. This is the last attribute in the list shown at the begining of the post.
Let’s go back to the topology used to describe the MED attribute:
Before configuring the MED in R1, why did R3 choose the route through R1 to reach the 192.168.1.0/24 network? Let’s examine R3 BGP table again:
If we examine the attributes discussed in Part I of this blog series about BGP Path Selection (weight, local preference, local originate, shortest AS path), we can verify that none of the attributes can be used as a decision factor to select the best path. Both routes have a weight of 0, we have not configured local preference values to favor any one route over the other, none of the routes are locally originated and both routes have the same AS path length.
Now, let’s examine the new attributes discussed in this post. The origin type is the same for the two routes (i), since both R1 and R2 are advertising the 192.168.1.0/24 network using a network statement. Both routes have a MED of 0, since both R1 and R2 are advertising a directly connected network. Finally, both routes are eBGP routes, since R3 has learned both routes from a peer that belong to a different AS. As a result, BGP has chosen the route advertised by the peer with the lowest RID, which is R1 (184.108.40.206).