This document provides a structured overview of route redistribution between OSPF and BGP, focusing on potential routing loops and mitigation strategies using route tags. It is designed for IT professionals, network engineers, and those preparing for certifications such as CCNA or CCNP. The content includes configuration examples, verification steps, and best practices to ensure reliable implementation in production environments.
1. Overview of Route Redistribution
Route redistribution enables the exchange of routing information between different protocols, allowing a cohesive view of the network topology. In environments combining OSPF (an interior gateway protocol, IGP) for internal routing and BGP (an exterior gateway protocol, EGP) for external connectivity, redistribution is essential for hybrid topologies, such as those in MPLS VPNs or enterprise edge deployments.
- OSPF: A link-state IGP optimized for intra-domain routing, utilizing areas and link-state advertisements (LSAs).
- BGP: A path-vector EGP designed for inter-domain routing, supporting autonomous system (AS) boundaries and policy-based controls.
Redistribution must be managed carefully to avoid suboptimal paths or loops, particularly in mutual redistribution scenarios.
Route Preference Table
Administrative distance (AD) determines route selection across protocols, while OSPF employs an internal hierarchy for routes with equal AD. The following table outlines key attributes and preferences in a mixed OSPF/BGP environment.
| Protocol | Admin Distance (AD) | Default Seed Metric | Route Types | Overall Preference in Mixed OSPF/BGP Setup |
|---|---|---|---|---|
| BGP (eBGP) | 20 | N/A (uses MED/weight) | i (internal), e (external) | Highest: Lowest AD ensures BGP routes are preferred over all OSPF routes for the same prefix. Implement filters and tags to mitigate loop risks. |
| OSPF Internal | 110 | N/A | O (intra-area), O IA (inter-area) | High (within OSPF): Preferred over OSPF external routes; subordinate to BGP. |
| OSPF External Type 1 (E1) | 110 | 20 | Cumulative cost (internal + external) | Medium (within OSPF): Preferred over E2 due to inclusion of full path costs; subordinate to BGP and internal OSPF. |
| OSPF External Type 2 (E2) | 110 | 20 | External metric only (default for redistribution) | Lowest (within OSPF): Relies solely on external metric; tiebreaker uses external metric value, then ASBR path cost. Subordinate to BGP. |
Note: BGP’s low AD (20) often drives routing loops during mutual redistribution, as it overrides OSPF routes (AD 110), prompting re-redistribution.
OSPF Internal Route Preference Hierarchy
For OSPF routes with equal AD (110), selection follows this order:
| Preference Order | Route Type | Description | Rationale for Preference |
|---|---|---|---|
| 1 | O (Intra-area) | Routes within the same OSPF area | Derived directly from the link-state database (LSDB); highest fidelity. |
| 2 | O IA (Inter-area) | Routes across OSPF areas via area border routers (ABRs) | Efficient summarization at ABRs; next-highest trust level. |
| 3 | E1 (External Type 1) | External routes with cumulative metric | Incorporates total path cost for accurate load balancing. |
| 4 | E2 (External Type 2) | External routes with external metric only | Simplifies external path evaluation; default for redistributed routes (e.g., from BGP or static). Tiebreaker: lowest external metric, then lowest ASBR cost. |
To configure E1 instead of the default E2: redistribute bgp 65000 subnets metric-type 1.
2. Lab Topology and Initial Configuration
Consider a basic three-router topology for illustration:
- CE1 (AS 65001, OSPF Area 0): Loopback 10.1.1.1/32; connected to PE via 192.168.1.0/24.
- PE (BGP AS 65000): Redistribution point; connected to CE1 (192.168.1.0/24) and CE2 (192.168.2.0/24).
- CE2 (AS 65002, OSPF Area 0): Loopback 10.2.2.2/32; connected to PE via 192.168.2.0/24.
Objective: Enable CE1 to reach CE2’s loopback via OSPF (sourced from BGP) without loops.
Initial Cisco IOS configuration (pre-redistribution):
! CE1
router ospf 1
network 10.1.1.1 0.0.0.0 area 0
network 192.168.1.0 0.0.0.255 area 0
! PE
router bgp 65000
neighbor 192.168.1.1 remote-as 65001
neighbor 192.168.2.2 remote-as 65002
!
router ospf 1
network 192.168.1.0 0.0.0.255 area 0
network 192.168.2.0 0.0.0.255 area 0
! CE2 (mirrors CE1)
Without redistribution, inter-CE reachability is unavailable.
3. Implementing Mutual Redistribution
Basic redistribution commands on PE:
! OSPF into BGP
router bgp 65000
redistribute ospf 1
! BGP into OSPF (defaults to E2)
router ospf 1
redistribute bgp 65000 subnets
This installs OSPF E2 routes (AD 110) on remote routers, enabling basic connectivity.
Routing Loop Risks
Mutual redistribution can induce loops due to AD discrepancies and lack of origin tracking:
- CE2 advertises 10.2.2.2/32 into OSPF; PE installs as internal OSPF route (AD 110).
- PE redistributes to BGP; route becomes BGP (AD 20).
- PE advertises to CE1; CE1 prefers BGP route (AD 20).
- If CE1 redistributes BGP to OSPF, the route floods back to PE.
- PE prefers its BGP route but forwards traffic via the looped OSPF path, causing blackholing.
In multi-homed designs (e.g., multiple PEs), this escalates to network-wide instability, including high CPU utilization and packet loss.
4. Mitigating Loops with Route Tags
Route tags provide origin identification, allowing selective filtering during redistribution. Tags are applied via route-maps and propagated in OSPF LSAs and BGP attributes.
Mechanism
- Outbound Tagging: Assign a unique tag (e.g., 100 for BGP → OSPF) during redistribution.
- Inbound Filtering: Deny routes matching the tag to prevent re-redistribution.
Configuration Example
On PE, using tags 100 (BGP → OSPF) and 200 (OSPF → BGP):
! Route-Maps
route-map BGP-TO-OSPF permit 10
set tag 100
!
route-map OSPF-TO-BGP deny 10
match tag 100
!
route-map OSPF-TO-BGP permit 20
set tag 200
! Redistribution
router ospf 1
redistribute bgp 65000 subnets route-map BGP-TO-OSPF
!
router bgp 65000
redistribute ospf 1 match internal external 1 external 2 route-map OSPF-TO-BGP
For multi-ASBR environments, tag with AS number (e.g., set tag 65000) and filter accordingly on peers.
Verification
show ip route tag: Displays tagged routes in the RIB.show ip ospf database external: Inspects LSA tags.- Connectivity:
ping 10.2.2.2 source 10.1.1.1from CE1 (should succeed via direct path). - Debugging:
debug ip routingfor real-time route changes.
Alternative: BGP Communities
In BGP-dominant topologies, use communities for tagging:
route-map OSPF-TO-BGP permit 20
set community 65000:666
!
ip community-list standard LOOP-BLOCK permit 65000:666
route-map BGP-TO-OSPF deny 10
match community LOOP-BLOCK
5. Best Practices
- Minimize Redistribution: Use BGP
networkcommands instead of full OSPF → BGP redistribution where feasible. - Metric Tuning: Assign high seed metrics (e.g., OSPF E2 metric 1000) to deprioritize externals.
- Access Controls: Apply ACLs or prefix-lists for granular filtering prior to tags.
- External Type Selection: Employ E1 for paths requiring cumulative cost awareness; E2 for external-metric-dominant scenarios.
- Testing: Validate in a lab with traffic generators and traceroute to simulate failures.
- Scalability: Leverage VRFs and per-site tags in VPN deployments.
- Documentation: Maintain topology diagrams and tag assignments for auditability.
6. Review Questions
- What is the default OSPF external type for redistributed BGP routes? (Answer: E2)
- How does BGP’s AD contribute to loops in mutual redistribution? (Answer: It overrides OSPF routes, enabling re-redistribution.)
- Given a route-map with
set tag 100for BGP → OSPF, what command blocks it on re-entry? (Answer:match tag 100under deny sequence.) - In an OSPF tie between E1 and E2 routes, which is selected? (Answer: E1, per internal hierarchy.)
- Implement the topology, omit tags to induce a loop, then apply tags. Document
show ip routeoutputs before and after.