Enterprise Networking / BGP
BGP Traffic Engineering: Controlling Inbound and Outbound Traffic
Understanding BGP path selection, AS-path prepending, Local Preference, MED, communities, and routing policy in enterprise networks.
Border Gateway Protocol (BGP) is the routing protocol that connects autonomous systems across the Internet and within many enterprise WAN and cloud architectures.
Unlike traditional interior gateway protocols, such as OSPF or IS-IS, BGP does not simply calculate the shortest path to a destination. Instead, it selects routes based on attributes and routing policies that allow network operators to influence traffic flow.
One of the most important concepts in BGP traffic engineering is understanding the difference between controlling outbound traffic and influencing inbound traffic.
These are two different problems, and BGP provides different mechanisms for addressing each.
1. Understanding Inbound vs. Outbound Traffic
The direction of traffic is always described from the perspective of your autonomous system (AS).
| Direction | Description | Routing Control |
|---|---|---|
| Outbound | Traffic leaving your AS | Primarily your AS |
| Inbound | Traffic entering your AS | Primarily external ASes |
Consider an enterprise connected to two Internet service providers:
- Enterprise: AS 65001
- ISP A: AS 65002
- ISP B: AS 65003
Your enterprise advertises its public IP prefixes to both ISPs and receives routes toward external destinations from both providers.
When traffic leaves your enterprise, your BGP policies determine which provider is preferred.
When traffic originates somewhere on the Internet and travels toward your enterprise, the originating network and intermediate autonomous systems make their own routing decisions.
Understanding this distinction is essential when designing redundant Internet connectivity, multi-region cloud environments, and enterprise WAN architectures.
2. Outbound Traffic Engineering
Outbound traffic engineering determines which connection your network uses to reach external destinations.
For example, an enterprise might want Chicago to be the preferred Internet exit while New York remains available as a backup.
Because the enterprise controls its own BGP routing policy, outbound traffic engineering is generally more predictable than inbound traffic engineering.
Local Preference (LOCAL_PREF)
Local Preference is one of the most useful BGP attributes for controlling outbound traffic across an autonomous system.
It determines which exit path routers within your AS should prefer when multiple routes exist to the same destination.
Higher Local Preference wins.
The default Cisco Local Preference is 100 unless otherwise configured.
| Connection | Local Preference | Behavior |
|---|---|---|
| Chicago ISP | 200 | Preferred outbound path |
| New York ISP | 100 | Secondary outbound path |
Assuming both paths are valid and earlier attributes such as Weight do not override the comparison, Chicago becomes the preferred outbound path.
Local Preference is propagated through iBGP so other routers within the autonomous system can apply the same routing preference.
However, Local Preference is not advertised to ordinary eBGP neighbors.
Weight
Weight is a Cisco-specific path-selection parameter used to influence routing decisions on an individual router.
Higher Weight wins.
Weight is evaluated before Local Preference in the standard Cisco BGP best-path selection process.
Unlike Local Preference, Weight is not propagated to other BGP routers.
For example, setting Weight 500 for routes learned from ISP A and Weight 100 for routes learned from ISP B makes ISP A preferable on that individual router, assuming both paths are valid.
Weight can be useful for router-specific policy, but Local Preference is generally more appropriate for consistent outbound traffic engineering across multiple enterprise routers.
Inbound Route Filtering
Despite its name, inbound route filtering can influence outbound traffic engineering.
An inbound BGP route-map or prefix-list controls which routes your router accepts from its peers.
For example, you might accept a default route from one provider but reject selected routes from another.
Because rejected routes cannot participate in normal BGP path selection, filtering changes which outbound paths remain available.
However, filtering is a relatively coarse mechanism. When the objective is simply to prefer one valid path over another, Local Preference is generally the better tool.
IGP Metric to the BGP Next Hop
When earlier BGP attributes are equal, routers may use the interior gateway protocol metric to determine the preferred path to the BGP next hop.
This can produce hot-potato routing, where traffic exits the autonomous system through the closest suitable external connection.
For example, routers in Chicago may exit through Chicago while routers in New York exit through New York.
This can reduce unnecessary backhaul traffic across an enterprise WAN.
However, IGP distance is evaluated relatively late in the Cisco best-path selection process. Earlier attributes, such as Local Preference, may override geographic proximity.
3. Inbound Traffic Engineering
Inbound traffic engineering is more challenging because your enterprise does not control the routing policies of other autonomous systems.
You advertise routes to your providers, but those providers and other networks determine which paths they prefer.
AS-Path Prepending
AS-path prepending is one of the most commonly used techniques for influencing inbound traffic.
Every BGP route contains an AS_PATH attribute identifying the autonomous systems traversed by the route advertisement.
BGP generally prefers a shorter AS path when earlier best-path criteria are equal.
AS-path prepending intentionally adds additional occurrences of your ASN to a route advertisement, making that path appear longer.
Assume your enterprise originates prefix 203.0.113.0/24.
| Connection | AS_PATH |
|---|---|
| Chicago ISP | 65002 65001 |
| New York ISP | 65003 65001 65001 65001 65001 |
In this example, New York advertises the enterprise prefix with three additional prepends.
If a remote AS learns both paths and earlier routing policies do not override AS_PATH comparison, Chicago becomes the more attractive route.
AS-path prepending is a traffic-engineering signal, not an instruction that external autonomous systems must obey.
Multi-Exit Discriminator (MED)
MED is another BGP attribute used to influence inbound traffic routing.
MED is particularly useful when two autonomous systems are interconnected at multiple locations.
For example, your enterprise might connect to the same provider in Chicago and New York.
| Connection | MED |
|---|---|
| Chicago | 50 |
| New York | 100 |
Lower MED wins.
Assuming earlier attributes are equal and the provider honors MED, Chicago becomes the preferred entry point into your network.
However, MED has an important limitation.
By default, Cisco BGP generally compares MED only between paths learned from the same neighboring autonomous system.
Configuration options such as bgp always-compare-med can change this behavior.
MED is also not normally propagated from one external neighboring AS to another.
Therefore, MED should not be considered a reliable mechanism for influencing path selection across unrelated Internet providers.
More-Specific Route Advertisements
Another powerful inbound traffic-engineering technique involves advertising more-specific routes through selected providers.
IP forwarding uses longest-prefix matching.
| Provider | Advertised Prefix |
|---|---|
| ISP A | 203.0.112.0/22 |
| ISP B | 203.0.113.0/24 |
Traffic destined for 203.0.113.10 normally follows the /24 through ISP B, provided the route is installed and usable.
This happens because the /24 is more specific than the /22.
The forwarding decision between those prefixes does not depend on which route has the shorter AS_PATH.
Longest-prefix matching determines which destination prefix is used before the path attributes for that prefix become relevant.
However, more-specific advertisements have limitations.
Internet providers frequently apply prefix-length filtering. IPv4 routes longer than /24 are commonly filtered from the global Internet routing table.
Route deaggregation also increases routing-table size and operational complexity.
More-specific route advertisement should therefore be used selectively and coordinated with upstream providers.
Outbound Advertisement Filtering
Outbound BGP filtering controls which prefixes your router advertises to its neighbors.
Although the filtering policy is applied in the outbound direction, it can influence inbound traffic because external networks can only select paths they learn.
For example, you could advertise a prefix through Chicago while suppressing it through New York.
However, doing so also removes New York as an advertised backup path for that prefix unless another route provides reachability.
For redundant enterprise designs, maintaining advertisements through both providers and influencing their relative preference is often preferable.
4. BGP Communities: Routing Policy at Scale
BGP communities provide a scalable mechanism for classifying routes and associating them with routing policies.
A community is a value attached to a BGP route.
The community itself does not automatically change the best-path decision.
Instead, a router or routing policy must recognize the community and perform an associated action.
Internal Communities
Within an enterprise network, communities are useful for distributing routing-policy information.
For example, a WAN edge router might tag routes based on the location where they were learned.
| Community | Classification |
|---|---|
65001:100 |
Chicago routes |
65001:200 |
New York routes |
65001:300 |
Cloud connectivity routes |
These values are illustrative and represent a locally defined community scheme.
Downstream routers can match these communities and apply routing policies through route-maps.
This avoids maintaining separate prefix-lists for every route learned from each location.
Communities become particularly useful as enterprise networks expand across additional data centers, cloud regions, and interconnection facilities.
Provider-Defined Communities
Communities are also widely used between enterprises and service providers.
Many providers publish community values that customers can attach to route advertisements.
Depending on the provider, these communities may request actions such as:
- Changing Local Preference within the provider’s AS
- Applying AS-path prepending toward selected upstream peers
- Suppressing advertisements to selected peers or geographic regions
- Triggering remotely triggered blackholing or traffic-diversion policies
For example, an ISP might publish a community that requests three AS-path prepends toward one of its upstream networks.
Your enterprise attaches the community, and the provider applies the documented policy.
Community formats include standard, extended, and large communities. Each has different use cases and encoding characteristics.
The propagation and interpretation of communities must be verified for every BGP peering relationship.
5. Cisco BGP Best-Path Selection
Understanding Cisco’s best-path selection process is essential for troubleshooting unexpected routing decisions.
BGP does not evaluate all attributes and calculate a combined score.
Instead, it evaluates eligible paths using a defined sequence of criteria.
The first applicable criterion that differentiates two paths generally determines the preferred route.
Before best-path comparison, BGP must also determine whether the path is valid and its next hop is reachable.
Standard Cisco Best-Path Selection Order
| Order | Attribute | Preference |
|---|---|---|
| 1 | Weight | Highest |
| 2 | Local Preference | Highest |
| 3 | Locally Originated | Prefer local |
| 4 | AS_PATH | Shortest |
| 5 | Origin Type | IGP, EGP, Incomplete |
| 6 | MED | Lowest, when comparable |
| 7 | eBGP vs. iBGP | eBGP |
| 8 | IGP Metric to Next Hop | Lowest |
| 9 | External Path Age | Oldest, when applicable |
| 10 | BGP Router ID | Lowest |
| 11 | Cluster-List Length | Shortest |
| 12 | Neighbor IP Address | Lowest |
Important Best-Path Considerations
Weight and Local Preference are evaluated before AS_PATH.
A route with Local Preference 200 can be preferred over a route with Local Preference 100 even when the higher-preference route has a longer AS_PATH, assuming Weight does not decide the comparison.
MED is evaluated after AS_PATH.
A shorter AS_PATH can win before MED is considered.
eBGP is not automatically preferred over every iBGP route.
Earlier BGP attributes may select an iBGP-learned path before the eBGP versus iBGP comparison occurs.
The best-path algorithm can vary by platform and configuration.
Cisco IOS, IOS XE, IOS XR, and other implementations can include additional criteria or configurable behavior.
Features such as AIGP, BGP cost communities, modified MED comparison, and BGP multipath can affect route selection or forwarding behavior.
Always verify the actual behavior of the platform and software version being deployed.
6. Practical Example: Dual-Provider Enterprise Internet Edge
Consider an enterprise with Internet connectivity through Chicago and New York.
The architecture requires:
- Chicago preferred for outbound Internet traffic
- Chicago preferred for inbound traffic where possible
- New York available as a backup
Outbound Design
The enterprise receives routes through both providers.
| Connection | Local Preference |
|---|---|
| Chicago | 200 |
| New York | 100 |
Internal routers prefer Chicago for matching destinations when both routes are otherwise eligible.
If the Chicago route is withdrawn, New York can become the preferred path.
The actual failover time depends on failure detection, route propagation, next-hop reachability, and convergence.
Inbound Design
The enterprise advertises its public prefixes through both providers.
Chicago advertises the prefixes without additional AS-path prepending.
New York advertises the same prefixes with three additional prepends.
External networks that learn both routes may prefer Chicago because of its shorter AS_PATH.
If Chicago becomes unavailable and its advertisements are withdrawn, New York remains available as an alternate path.
However, inbound path selection is never guaranteed because remote networks maintain independent routing policies.
7. Why BGP Does Not Guarantee Symmetric Routing
A common misconception is that traffic entering an enterprise through one provider must return through the same provider.
This is not how BGP works.
Consider a client accessing an enterprise application.
Inbound traffic:
Client → ISP A → Enterprise
Outbound response:
Enterprise → ISP B → Client
The client may enter through ISP A because of the routing policies of external autonomous systems.
Your enterprise may send the response through ISP B because its Local Preference favors that connection.
This creates asymmetric routing.
Asymmetric routing is valid from an IP routing perspective. The Internet does not require traffic in both directions to follow the same path.
However, asymmetric routing can introduce complications for stateful firewalls, NAT, traffic inspection, and other systems that depend on observing both directions of a session.
For example, a stateful firewall that sees only one direction of a connection may not have the necessary session state to permit return traffic.
8. BGP Route Filtering: A Non-Negotiable Requirement
One of the most important operational practices in BGP is explicitly controlling the routes your network accepts and advertises.
Always implement and validate inbound and outbound routing policies.
Never assume the neighboring AS will perform the necessary filtering for you.
Inbound Filtering
Inbound filtering protects your routing domain from unexpected or unauthorized advertisements.
Depending on the connection, appropriate policies may include:
- Accepting only expected customer, partner, or cloud prefixes
- Rejecting unauthorized or malformed advertisements
- Rejecting inappropriate or unexpected default routes
- Implementing maximum-prefix limits
- Applying AS-path policies and route-origin validation where appropriate
For Internet transit, the filtering policy depends on whether the connection receives a default route, partial routes, or the full Internet routing table.
A default-only connection should not use the same route-acceptance policy as a full-table transit connection.
Outbound Filtering
Outbound filtering controls which prefixes your router advertises to external peers.
Your network should advertise only prefixes that the neighboring AS is authorized and intended to receive.
Incorrect outbound policies can cause route leaks involving internal networks, customer prefixes, cloud routes, or routes learned from another provider.
For enterprise Internet connectivity, outbound routing policies should generally permit explicitly approved public prefixes and deny everything else.
Private cloud and partner connections may have different requirements, but the same principle applies.
9. Troubleshooting BGP Traffic Engineering
When a route does not follow its intended path, start by examining the actual BGP attributes and routing policies.
Useful Cisco IOS/IOS XE commands include:
show ip bgp summary
show ip bgp
show ip bgp <prefix>
show ip bgp neighbors <peer-ip> routes
show ip bgp neighbors <peer-ip> advertised-routes
show ip route <prefix>
show ip cef <destination> detail
Equivalent address-family-specific commands may be required depending on the platform and configuration.
Focus on the following questions:
- Is the expected route actually being received?
- Is the route valid, and is its next hop reachable?
- What Weight and Local Preference values are assigned?
- What is the AS_PATH length?
- Is MED being compared between the available paths?
- Are route-maps modifying the attributes?
- Is the selected BGP route installed in the routing table?
- What next hop does the forwarding table actually use?
Control Plane vs. Forwarding Plane
An important troubleshooting distinction is the difference between the BGP control plane and the actual forwarding plane.
A route appearing in the BGP table does not necessarily mean that route is being used to forward packets.
Administrative distance, recursive next-hop resolution, policy-based routing, and other forwarding behavior may affect the installed or selected path.
Always verify the routing information base (RIB) and forwarding information base (FIB) when troubleshooting traffic flow.
Do Not Rely Exclusively on Ping and Traceroute
ICMP and traceroute are useful diagnostic tools, but they do not always reveal the complete forwarding path or accurately identify packet loss.
Internet routers may implement:
- ICMP rate limiting
- Control-plane policing
- Traceroute filtering or suppression
- Different handling of transit traffic and control-plane traffic
Asymmetric routing can further complicate diagnostic results.
Packet loss reported at an intermediate traceroute hop does not necessarily mean transit traffic is being dropped at that router.
Where possible, corroborate findings using BGP tables, interface counters, flow telemetry, provider route views, and end-to-end application testing.
10. BGP Traffic Engineering Best Practices
Prefer Predictable Routing Policies
Use Local Preference for consistent outbound policy across an autonomous system. Avoid unnecessary combinations of Weight, Local Preference, and route filtering when a simpler design will achieve the objective.
Understand Attribute Scope
Weight is local to one Cisco router. Local Preference operates within an AS. AS_PATH is carried between autonomous systems. MED is generally intended to influence the directly neighboring AS.
Use Communities Deliberately
Document community values and verify which policies act on each community. Do not assume different providers interpret communities identically.
Preserve Redundancy
Avoid removing backup route advertisements simply to force traffic over a preferred connection unless doing so is an explicit architectural requirement.
Validate Failover Behavior
An established backup BGP session does not prove application recovery will meet the required convergence target. Test route withdrawal, path convergence, forwarding behavior, and application availability.
Evaluate Complete Traffic Flows
Understand both inbound and outbound paths, particularly where stateful firewalls, cloud connectivity, and geographically distributed applications are involved.
Document Routing Policies
Record intended primary and secondary paths, prefix advertisements, Local Preference values, prepend counts, communities, and expected failover behavior.
Filter External Peerings
Apply appropriate inbound and outbound routing controls and verify the resulting advertisements before placing a BGP peering relationship into production.
Final Thoughts
BGP traffic engineering is ultimately about influencing routing decisions through well-defined policies.
For outbound traffic, your enterprise generally has direct control over which paths it prefers.
For inbound traffic, you advertise routes and attributes that can influence decisions made by external autonomous systems.
Understanding this separation is critical.
Local Preference, Weight, AS-path prepending, MED, communities, and route filtering are all useful tools, but each operates within a specific scope and has limitations.
A good BGP design does not rely on one attribute to solve every problem. It combines routing policy, redundancy, filtering, operational visibility, and failure testing to produce predictable behavior.
Final Recommendation
Never establish an external BGP peering relationship without explicitly defining and validating what routes you will accept and what routes you will advertise.
Keep the architecture simple, make routing decisions intentional, and verify how the network behaves during both normal operation and failure conditions.
Technical References
- Cisco — Select BGP Best-path Algorithm
- RFC 4271 — A Border Gateway Protocol 4 (BGP-4)
- RFC 7454 — BGP Operations and Security
- RFC 1997 — BGP Communities Attribute
- RFC 8092 — BGP Large Communities Attribute
Note: IP addresses and AS numbers used in the examples are illustrative. The public prefixes shown are documentation ranges and are not intended for production Internet advertisement.