Border Gateway Protocol (BGP) Basics, Attributes and Best Path Selection Process

Border Gateway Protocol or BGP is the protocol of the internet. BGP forms the backbone of the internet in the form of thousands of neighbour adjacencies where global routes from different Autonomous Systems (AS) are shared in between to provide the underlying fabric of communication over the internet.

Although referred to as a routing protocol, BGP is an application that runs over tcp port 179. This enables BGP to run and form neighbour relationships across multiple hops an element missing from other routing protocols. BGP works in the same way as any application would whereby it forms a session over tcp, builds neighbour relationship and then shares routes with attributes. Overall this is the general function BGP performs.

Since Interior Gateway Protocols (IGP) run within an Autonomous System (AS), BGP’s main goal is to send summarised routing prefixes over to another Autonomous System (AS) via an External BGP (ebgp) relationship. This means internal routing within an AS is dealt with using any routing protocol and external communication is taken care of by eBGP.

However, BGP has another variant called Internal BGP (iBGP) that specifically deals with BGP’s implementation within an AS.

In a large network, infrastructure is usually made reachable using IGP whereas iBGP is then configured across the network to form a full mesh between all the participating routers. The full mesh is virtual in nature with the IGP making sure all iBGP neighbours can reach each other. This then enables iBGP neighbours to share routes with each other. As all iBGP neighbours learn routes from other iBGP neighbours, the iBGP neighbours that have external BGP (eBGP) neighbour relations with routers belonging to other Autonomous systems share the routes from within the Autonomous System to other Autonomous systems directly connected via eBGP.

This is BGP at work in a nutshell. However, since BGP works like an application it allows multiple bundling of Autonomous Systems to form a traffic path for a specific route. For example, route 8.8.8.0/24 could be advertised from AS15109 to AS44332 to AS21134. Since the eBGP relationship between AS15109 shared the route to AS44332 which saw the route pass through its iBGP network to advertise the route via an eBGP relationship to AS21134. Therefore, the router in AS21134 would see that it needs to pass through AS44332 to reach AS15109 where 8.8.8.0/24 network resides. This is what formulates the internet routing table which currently consists of more than 600,000 destinations all learned via BGP. All destinations list an AS Path that the traffic would traverse through if selected as the best path.

BGP Attributes:

BGP has certain attributes that affect the best path selection process. These attributes are:

  • Origin
  • Weight
  • AS-Path
  • Next Hop
  • Local Preference
  • Community
  • Multiple Exit Discriminator (MED)
  • Weight – Higher the better
  • Local Preference – Higher the better
  • Self-originated – Prefer paths that have been locally originated
  • AS Path – Least number of Autonomous Systems in the path the better
  • Origin – Prefer IGP over EGP and EGP over unknown
  • MED – Lower the better
  • External – Prefer eBGP learnt route over iBGP
  • IGP cost – lower the better – BGP will consider the IGP metric
  • eBgp peering – Older the better – prefer stable routes over unstable ones
  • Router ID – Lower the better – final tie breaker

Origin:

This attributes defines if the route was originated via IGP, EGP or unknown. EGP was the protocol in use before BGP became common so you shouldn’t see this next to the origin attribute with any received route.

Weight:

This is a cisco proprietary attribute that can be configured on cisco routers only. If a higher weight is given to a specific route that it would implicate that the route would be preferred over other routes received by other neighbours. However, this attribute is local and is not shared across the AS.

AS-Path:

This attribute defines the list of Autonomous Systems the route has traversed before reaching the router.

Next Hop:

This is usually the address of the neighbour that advertised the route. This value is usually modified before re-advertising the route as BGP checks if it can reach the next hop value associated with a route and if the next hop value is unreachable, it renders a route unusable. Therefore, if the route is received from a eBGP neighbour, the next hop value is modified by the router to a self value by associating its own IP address with it before re-advertising the route to its iBGP peers. The iBGP peers happily install the route in their routing table as they can reach the next hop value associated with the route because it now points to the border router in their own AS rather than the router’s IP in another AS they don’t know about.

Local Preference:

This value works in the same way as weight with the only difference being that once configured, this attribute is advertised throughout the AS.

Community:

This attribute essentially behaves as a route tag and the result is that all routes received with a certain tag can then be treated in a certain way. For example, all routes that are tagged with a community if 200 can then be assigned local preference of 3000 etc.

Multiple Exit Discriminator (MED):

Multiple Exit Discriminator (MED) is a metric that is the only attribute that can be shared to a neighbour in another Autonomous System. This attribute allows some control over return traffic but the catch is the presence of redundant links to the neighbouring AS as MED value is discarded when the route is further advertised to another AS by the neighbouring AS. Therefore, in the presence of two links to an AS, MED can be increased on one link which would result in all traffic to return using the other link as MED is lower the better. This action would work in the absence of other configuration by the neighbouring AS defining path preference using local preference which are preferred by BGP when selecting the best path over MED.

BGP path selection process:

BGP uses all received attributes along with a route in a specific order to select the best path in case multiple routes to the same destination have been received by more than one BGP neighbour.

The best path process is as follows:

  • Weight – Higher the better
  • Local Preference – Higher the better
  • Self-originated – Prefer paths that have been locally originated
  • AS Path – Least number of Autonomous Systems in the path the better
  • Origin – Prefer IGP over EGP and EGP over unknown
  • MED – Lower the better
  • External – Prefer eBGP learnt route over iBGP
  • IGP cost – lower the better – BGP will consider the IGP metric
  • eBgp peering – Older the better – prefer stable routes over unstable ones
  • Router ID – Lower the better – final tie breaker

Got questions? Leave a comment! Let’s chat.

Rafay Rasool is a Network Specialist with over 8 years of experience designing, configuring and implementing core network solutions based predominantly but not limited to Juniper Routers, Switches and Firewalls along with other vendors such as Cisco, Huawei, Siemens, Aerohive, Ringmaster, Pulse etc for Internet Service Provider and Enterprise Networks.

Rafay is an avid supporter of network automation and likes to code and automate networking solutions.