Home » BGP » BGP Decision Process

BGP Decision Process

When running BGP, the routes are exchanged between BGP peers using the UPDATE messages. UPDATE messages can send new routes or modified routes to a destination  and also withdrawn routes for a destination. These routes received in the update messages are kept separate from the IP routing table initially, and only the best route selected is placed in the IP routing table. The final decision to route a packet to its destination is always made from the IP routing table. A BGP speaker might receive multiple routes to the same destination from multiple BGP peers. BGP does not flood all its peers with all the routes received in the UPDATE messages, instead it picks the best route to a destination and sends only this best route to its BGP peers. This means only the best routes learnt from the BGP peers and locally originated routes are installed in the IP routing table. The router running BGP will have to go through a decision process before installing the best routes in the IP routing table.

All BGP routes received in the UPDATE messages are stored in Routing Information Base (RIBs). The information is stored in these following three RIBs: (RIB = Routing Information Base)

1. Adj-RIBs-In : All routes received from other BGP speakers are stored in this RIB.
2. Adj-RIBs-Out: All routes that will be advertised to other BGP speakers will be stores in this RIB.
3. LOC-RIB: All routes used locally by the BGP speaker and the next-hop for each of these routes must be present in the forwarding information base. These are the routes which have been selected by the BGP speaker by applying its local routing policies.

When routes are received from BGP peers, if the Next hop address specified in the UPDATE message is not reachable then that route is not selected to be put in the LOC-RIB. BGP decision process selects best routes by applying the locally defined routing policies to the routes which it has stored in the Adj-RIBs-In, it stores these best routes in the LOC-RIB and places them in Adj-RIBs-Out for advertisement to other BGP peers.

When the routes are receives from BGP speakers they are stored in Adj-RIB-In, the input policy handles the route filtering based on parameters such as AS_Path, and other BGP attributes. Once the input policy is applied, and based on the BGP decision process the best routes are placed in the Local-RIB. These routes now also become the candidates to be advertised to other BGP peers and also placed in the IP routing table. Routes originated locally by the router are also placed in the IP routing table after going through the impute policy checks and these routes are also now the candidate routes to be advertised to BGP peers. Then the output policy applies filters and might change some BGP attributes such as AS_Path and send these routes in updates to other BGP peers. All routes that are advertised to BGP peers internal or external pass through the defined output policy. Note that if a route for some reason is not placed in the IP routing table then that route cannot be advertised to any BGP peer.

When multiple routes exist for the same destination remember the most specific route is always selected but if multiple equally specific routes for the same destination exist then the following decision process kicks in to select the best route  which can be placed in the IP routing table.

BGP Route Selection Process:

Below Steps show the sequence on how BGP chooses the best route:

1. Any route whose Next HOP  is not reachable is always  ignored. Therefore it is important for to have the Next HOP route in the IGP.
2. Prefer the route with the highest administrative weight (Cisco specific parameter, which is local to the router)
3. If the weights are equal, then prefer the route with highest LOCAL_PREF.
4. If the LOCAL_PREF is same and there are no locally originated routes then prefer the path with the shortest AS_PATH.
5. If the AS_PATH is the same length, then prefer the route with lowest origin type. (Origin type IGP is the lowest and is preferred over Origin type EGP, the last in the  preference is origin type INCOMPLETE)
6. If the ORIGIN TYPE is same then Prefer the routes with lowest MED value on the route only if the routes are received from the same Autonomous System. If the routes are not received from the same AS, and if the command “bgp-always-comapre-med” is enabled then MED is compared between routes received from multiple Autonomous Systems when these routes point to the same destination. If this commandis configured then it needs to be configured on every BGP router in the AS.
7. If the MEDs are equals then prefer EGP path to IGP path.
8. If all are equal at this point, then prefer the route that can be reached via the closest IGP neighbor, that is the shortest internal path inside an AS.
9. If the path is same, then select the oldest route, that is route with higher age or the route that was learnt first.
10. If the path is same, then the last resort is to check the BGP Router ID, the lowest value is selected, which means select the route from BGP router with the lowest Router-ID.  Router can be manually configured or if not manually configured then in Cisco its the highest IP address on loopback interface and if no loopback interface configured then the highest IP address on any physical interface. Router ID is vendor specific.
11. If the router-id is same then select the route on the lowest interface ip address.

In Summary the order of preference is:

1. Select only the routes whose next hop is reachable.
2. Select route with highest WEIGHT  [ Cisco Specific and Local on the router]
3. Select route with highest LOCAL PREFERENCE  [Local within an AS, default is 100]
4. Select Locally originated Routes (Self sourced routes into BGP are preferred)
5. Select Shortest AS Path
6. Select Lowest Origin Code:  IGP > EGP > Incomplete( Route with a ?)
7. Select Lowest MED (shown as metric in ‘sh ip bgp’ command)
8. Select EBGP learnt routes over IBGP learnt routes
9. Select Smallest IGP metric to  next-hop.
10. Select Oldest Route (Age)
11. Select neighbor with Lowest Router ID
12. Select Lowest Interface IP address if the router-id is the same.

* And Most Importantly when this process is complete the route does not go into routing table automatically: After this process is complete in BGP, the route  will  make it to the Routing table only  if there is no other route with longer prefix and no other route with better Admin-Distance for the destination in question.

Python Tutorial: Python Network Programming – Build 7 Apps


Incoming search terms for the article:

One thought on “BGP Decision Process

Leave a Reply