BGP Route Optimization: Advanced Techniques for Traffic Engineering

Border Gateway Protocol (BGP) route optimization is critical for service providers and large enterprises seeking to control traffic flows, improve performance, and reduce costs. This guide explores advanced BGP techniques for route manipulation, traffic engineering, and path selection optimization.

Understanding BGP Path Selection

BGP uses a complex 13-step decision process to select the best path. Understanding this algorithm is fundamental to effective route optimization:

  1. Highest Weight (Cisco-proprietary, local to router)
  2. Highest Local Preference (AS-wide, outbound traffic)
  3. Locally Originated Routes (network, aggregate, redistribute)
  4. Shortest AS Path
  5. Lowest Origin Type (IGP < EGP < Incomplete)
  6. Lowest MED (Multi-Exit Discriminator, inbound from neighbor AS)
  7. eBGP over iBGP
  8. Lowest IGP Metric to Next Hop
  9. Oldest eBGP Route
  10. Lowest Router ID
  11. Minimum Cluster List Length
  12. Lowest Neighbor Address

Local Preference for Outbound Traffic Control

Local Preference (LP) influences outbound traffic by making certain exit points preferred across the entire AS.

Practical Implementation

Configuring Local Preference

! Prefer ISP1 for all traffic
router bgp 65001
 neighbor 203.0.113.1 remote-as 65000
 !
 address-family ipv4
  neighbor 203.0.113.1 route-map SET_LP_HIGH in
 exit-address-family
!
route-map SET_LP_HIGH permit 10
 set local-preference 200
!
! ISP2 gets default LP of 100
router bgp 65001
 neighbor 198.51.100.1 remote-as 65002
 address-family ipv4
  neighbor 198.51.100.1 activate
 exit-address-family

All routers in AS 65001 will now prefer ISP1 (LP 200) over ISP2 (LP 100) for identical prefixes.

Selective LP Based on Prefix

Optimize paths based on destination networks:

! Route critical applications via low-latency ISP
ip prefix-list CRITICAL_APPS seq 10 permit 192.0.2.0/24
ip prefix-list CRITICAL_APPS seq 20 permit 198.18.0.0/15
!
route-map OPTIMIZE_OUTBOUND permit 10
 match ip address prefix-list CRITICAL_APPS
 set local-preference 250
!
route-map OPTIMIZE_OUTBOUND permit 20
 set local-preference 100
!
router bgp 65001
 address-family ipv4
  neighbor 203.0.113.1 route-map OPTIMIZE_OUTBOUND in
 exit-address-family

AS Path Prepending for Inbound Traffic

Manipulate AS path length to make certain links less attractive to remote autonomous systems.

! Make ISP2 link backup by prepending ASN 3 times
ip prefix-list OUR_PREFIXES seq 10 permit 203.0.113.0/24
!
route-map PREPEND_BACKUP permit 10
 match ip address prefix-list OUR_PREFIXES
 set as-path prepend 65001 65001 65001
!
router bgp 65001
 neighbor 198.51.100.1 remote-as 65002
 address-family ipv4
  neighbor 198.51.100.1 route-map PREPEND_BACKUP out
 exit-address-family

Remote ASes will see path length: AS 65002 65001 65001 65001 65001 (length 5 vs. 2 via ISP1), making ISP1 preferred.

Selective Prepending

Prepend only for non-critical prefixes, keeping critical services on primary path:

ip prefix-list CRITICAL seq 10 permit 203.0.113.0/25
ip prefix-list NON_CRITICAL seq 10 permit 203.0.113.128/25
!
route-map SELECTIVE_PREPEND permit 10
 match ip address prefix-list CRITICAL
!
route-map SELECTIVE_PREPEND permit 20
 match ip address prefix-list NON_CRITICAL
 set as-path prepend 65001 65001 65001
!
router bgp 65001
 neighbor 198.51.100.1 route-map SELECTIVE_PREPEND out

MED (Multi-Exit Discriminator) for Provider Influencing

MED suggests to a neighboring AS which entry point to prefer when multiple links exist.

Practical Implementation

Setting MED Values

! Prefer NYC border router over LAX for inbound traffic
router bgp 65001
 ! NYC Router
 neighbor 203.0.113.1 remote-as 65000
 address-family ipv4
  neighbor 203.0.113.1 route-map SET_MED_LOW out
 exit-address-family
!
route-map SET_MED_LOW permit 10
 set metric 50
!
! LAX Router  
router bgp 65001
 neighbor 203.0.113.2 remote-as 65000
 address-family ipv4
  neighbor 203.0.113.2 route-map SET_MED_HIGH out
 exit-address-family
!
route-map SET_MED_HIGH permit 10
 set metric 100

Note: Lower MED is preferred. AS 65000 will choose NYC (MED 50) over LAX (MED 100).

MED Always-Compare

By default, MED is compared only between paths from the same neighboring AS. Enable comparison across all paths:

router bgp 65001
 bgp always-compare-med

Community-Based Traffic Engineering

BGP communities enable scalable policy implementation through tagging routes with 32-bit values.

Standard Communities

! Tag routes by geographic region
ip community-list standard AMERICAS permit 65001:1000
ip community-list standard EMEA permit 65001:2000
ip community-list standard APAC permit 65001:3000
!
route-map TAG_REGION permit 10
 match ip address prefix-list AMERICAS_PREFIXES
 set community 65001:1000
!
router bgp 65001
 neighbor 203.0.113.1 send-community
 address-family ipv4
  neighbor 203.0.113.1 route-map TAG_REGION out
 exit-address-family

Well-Known Communities

  • NO_EXPORT (0xFFFFFF01): Do not advertise to eBGP peers
  • NO_ADVERTISE (0xFFFFFF02): Do not advertise to any peer
  • LOCAL_AS (0xFFFFFF03): Do not advertise outside confederation sub-AS
! Prevent route advertisement beyond directly connected AS
route-map NO_TRANSIT permit 10
 set community no-export

Laboratory Exercise

Large Communities for Scale

RFC 8092 Large Communities use Global:Local1:Local2 format (each 32-bit):

! More granular tagging
route-map TAG_LARGE_COMM permit 10
 set large-community 65001:100:1 65001:100:2
!
! Match specific large community
ip large-community-list standard MATCH_LC permit 65001:100:1
!
route-map FILTER_LC permit 10
 match large-community MATCH_LC
 set local-preference 150

Large communities avoid exhaustion issues with standard 32-bit communities in massive deployments.

BGP Best Path Selection Optimization

BGP Best Path Multipath

Enable ECMP load balancing across multiple equal-cost BGP paths:

router bgp 65001
 maximum-paths 4
 maximum-paths ibgp 4

This allows load balancing across up to 4 parallel paths with identical attributes through step 7 of the selection algorithm.

BGP Add-Path

Advertise multiple paths for the same prefix, enabling diverse path calculation:

router bgp 65001
 address-family ipv4
  neighbor 192.168.1.2 activate
  neighbor 192.168.1.2 advertise diverse-path backup
 exit-address-family

Route Reflector Optimization

Hierarchical Route Reflectors

Reduce full-mesh iBGP requirements with two-tier RR architecture:

! Tier 1 RR (reflects to Tier 2 RRs)
router bgp 65001
 neighbor 192.168.1.10 route-reflector-client
 neighbor 192.168.1.11 route-reflector-client
!
! Tier 2 RR (reflects to edge routers)
router bgp 65001
 neighbor 192.168.2.1 route-reflector-client
 neighbor 192.168.2.2 route-reflector-client

Optimal Route Reflection (ORR)

Use dedicated RR with full topology view for best path calculation:

router bgp 65001
 bgp optimal-route-reflection ORR_GROUP
!
rib-update-locator ORR_GROUP
 rib-update-source Loopback100

Traffic Load Balancing Techniques

Unequal Cost Load Balancing with DMZ Link Bandwidth

router bgp 65001
 bgp dmzlink-bw
 maximum-paths ibgp 4
!
interface GigabitEthernet0/0/0
 bandwidth 1000000
!
interface GigabitEthernet0/0/1
 bandwidth 500000

Traffic will be distributed 2:1 ratio across the links based on configured bandwidth.

Troubleshooting BGP Path Selection

# Show BGP decision process for specific prefix
show bgp ipv4 unicast 203.0.113.0/24

# Display all paths (not just best)
show bgp ipv4 unicast 203.0.113.0/24 bestpath-compare

# Show why specific path was chosen
show bgp ipv4 unicast 203.0.113.0/24 | include best

# Examine route-map application
show route-map OPTIMIZE_OUTBOUND

# Verify community tags
show bgp ipv4 unicast community 65001:1000

Best Practices Summary

Goal Primary Tool Scope
Control outbound traffic Local Preference AS-wide
Influence inbound traffic AS Path Prepending Internet-wide
Suggest entry point MED Neighboring AS
Scalable policy Communities AS-wide or beyond
Load balancing Multipath + Add-Path Local router

Conclusion

BGP route optimization requires deep understanding of the path selection algorithm and skillful application of policy tools. By combining Local Preference, AS path manipulation, MED, communities, and advanced features like Add-Path, network engineers can achieve precise traffic engineering while maintaining stability and scalability.

Effective optimization balances business objectives (cost reduction, performance improvement) with technical constraints (routing stability, convergence time), requiring continuous monitoring and iterative refinement as traffic patterns evolve.

Parveen Jindgar

Parveen Jindgar

Engineering Leader

I am an engineering leader with over 20 years of experience working on large-scale packet networks in Service Provider and latency-sensitive environments. My work has centered on end-to-end architectural ownership of backbone and edge infrastructures — spanning platform and vendor selection, routing and control-plane design, and the evolution of networks under real operational and economic constraints. PacketBytes is a personal space where I document the engineering thinking behind these systems — examining architectures, control planes, and design trade-offs as they behave under real traffic, real failures, and real operational pressure, beyond configuration and into intent.

Leave a Reply

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