Technology

What are the Best Path Selection Criteria in BGP?

Border Gateway Protocol (BGP) is an exterior gateway protocol designed to exchange routing and reachability information among autonomous systems (AS) on the internet.

Among multiple autonomous systems, BGP is used for choosing the best route for a packet from source to destination.

In an earlier blog, we have discussed what is BGP and why we produce BGP, and the type of messages used in it.

In this blog, we will discuss the path attributes. BGP is the path-vector routing protocol, with the help of path-attributes we can manipulate prefixes paths.

The best path selection criteria of BGP are-

  • Next hope
  • Weight
  • Local preference
  • Self-advertise
  • AS path
  • Origin code
  • MED
  • External> Internal
  • IGP (Interior Gateway Protocol) cost to reach next hop
  • Oldest path (for EBGP neighbor only)
  • Router-ID of neighbor
  • Lower neighbor address
  • Next-hop: – Next hop reachability is compulsory for BGP prefixes to reach from source to destination, if next-hop is not reachable then it will not compare another path attribute.
  • Weight: –
  • It is a Cisco proprietary, and it has local significance.
    • Weight information is not carried along with BGP update.
    •  For self-advertised prefixes it is by default 32768 and for all received prefixes by default it is 0, higher weight will always be preferred.
  • Local Preference: –
  • BGP will always include the local preference attribute in its outgoing BGP update but only for the IBGP neighbor.
    • For IBGP, 100 is the default value of the local preference.
    • Higher will always prefer.
    • If any router receives prefixes from EBGP neighbor (0) and from IBGP neighbor (100) in that case local preference will never compare.
  • Self-Advertised: – Prefer the path that the local router originated. In the BGP table, you will see the next hop (0.0.0.0). A BGP router will prefer the same prefix that is directly connected to BGP itself over the me prefix t that getting from another router installed in BGP.
  • AS Path: – It is used to prevent routing loops in BGP. The router will define that path as best which is providing a destination network after crossing the minimum number of AS.
  • Origin Code: –
    • i= Route advertises by BGP network command.
    • E= If any route is advertised in EGP (Exterior Gateway Protocol).
    • ? = If we redistributed anything in BGP by default origin code will be “?”.

i>E>?

  • MED (Metric):
  • By default, MED is 0, lower will always be preferred.
    • If we redistribute any routing protocol into BGP, their metric will go along with BGP update in the form of MED.
    • Sometimes metrics will be 0, sometimes null.
  • External>Internal: –
  • If any prefix comes from two different neighbors, one is EBGP and one is IBGP then it will prefer external first.
  • IGP cost to reach next-hop:
  • If IGP (OSPF (Open Shortest Path First), EIGRP) configures the background of BGP then BGP can use IGP cost to reach the next-hop address.
    • Lower costs will be preferred.
  • Oldest Path (for EBGP neighbor only): –
  • If the router receives the same prefix coming from two different EBGP neighbors, then the oldest path is always preferred.
  • Router-ID of Neighbor: –
  • Lower will always be preferred.
    • If the router receives the same prefix coming from two different IBGP neighbors, then the lower router-id of the neighbor will always be preferred.
  • Lower Neighbor Address: –
    • If the router receives the same prefix coming from two neighbors with the same router-id, then a lower IP address will be preferred.

Let us take an example…

Here we have built a network in which site A is in BGP AS 65530. IBGP indirect neighborship is performed in between R1 and R4 with loopback and OSPF is the IGP routing protocol that makes reachability in between R1, R2, R3, and R4. R2 and R3 are BGP-free routers and traffic will forward base on MPLS (Multiprotocol Label Switching) labels on these routers. By default, the prefix of site B is not allowed on site A and vice versa, because of loop avoidance in the same AS. To achieve this, we run the allow-as command in the same AS in BGP.

BGP commands on routers are-

Site A

SiteA#show run | sec bgp

router bgp 65530

 bgp log-neighbor-changes

 network 30.1.1.0 mask 255.255.255.0

 neighbor 15.1.1.1 remote-as 100

 neighbor 15.1.1.1 allowas-in

R1

router bgp 100

 bgp log-neighbor-changes

 neighbor 4.4.4.4 remote-as 100

 neighbor 4.4.4.4 update-source Loopback1

 neighbor 4.4.4.4 next-hop-self

 neighbor 15.1.1.2 remote-as 65530

R4

router bgp 100

 bgp log-neighbor-changes

 neighbor 1.1.1.1 remote-as 100

 neighbor 1.1.1.1 update-source Loopback1

 neighbor 1.1.1.1 next-hop-self

 neighbor 46.1.1.2 remote-as 65530

Site B

router bgp 65530

 bgp log-neighbor-changes

 network 20.1.1.0 mask 255.255.255.0

 redistribute connected route-map ICMP (redistribute connected route into BGP with the help of route-map named ICMP)

 neighbor 46.1.1.4 remote-as 100

 neighbor 46.1.1.4 allowas-in

Note: – OSPF is running as IGP protocol at the backend on R1, R2, R3, and R4, and their loopback relates to OSPF with each other.

 Please check mention Below BGP summary –

Command on site A – show ip bgp summary

Site A router has an EBGP neighborship with an R1 router on directly connected interfaces and receiving 2 prefixes from R1. Here it shows the neighbor IP, Version, AS of neighbor, Msg sent/Received and other fields.

 BGP update message carries prefixes and path-attributes. To check we will use “show ip bgp” command.

The above BGP routing table shows path attributes and prefixes received from the BGP neighbor, and self-generated prefixes are received with the weight of 32768. The prefixes are added to the routing table to see if it is best and valid in the BGP route. Prefixes 20.1.1.0/24 and 50.50.50.0/24 are received from site B over transit network BGP 100. In the background, OSPF is running as IGP protocol to make the reachability between IBGP routers. IBGP indirect neighborship is established in between provider edge routers with the help of loopback.

Ping to check the connectivity of site B from site A.

Router R1 # show ip bgp

On the R1 route table, to reach prefix 20.1.1.1 next hop is 4.4.4.4 in the routing table, which is R4 loopback. R1, R2, R3, and R4 traffic is forwarding based on MPLS labels.

Router R3: –

Traffic is forwarded based on the label.

Router R4

On R4 router label is removed from the router and further traffic is forwarding based on routing table.

Site B # show ip bgp – to see the prefixes and path attributes

In this blog we have discussed the best path selection criteria in BGP, hope this blog will help you to understand the path selection in BGP. In the next blog, we will explain how we can path manipulate the prefixes by using the path attributes.

Zindagi Technologies is an IT consulting company having engineers with decades of experience in planning, designing, and implementing Datacentres services along with Managed IT Services, cybersecurity, cloud solutions. With our help, you can take your business ahead. Let us get to know more about you and your business. Visit us at Zindagi or call us on +91-9773973971.

Author
Prakash Raghav
Senior Consultant Enterprise Networking

Author

Team ZT

Leave a comment

Your email address will not be published. Required fields are marked *