Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

OSPF wins over BGP

I have a remote site with 2 wan connection back to head office.

1. MPLS using BGP (Serial 1)

2. GRE tunnel over internet using OSPF (Serial 2)

For some reason where both protocols are advertising the same route ospf wins

even though ospf has a cost and distance of 110/67 and the bgp route has 20/0, the router chooses ospf.

If I filter ospf for a specific route, the router then uses bgp (20/0).

What am I missing? Surely bgp should over write ospf.

Config...

router ospf 3

log-adjacency-changes

redistribute static

network 10.4.2.0 0.0.0.255 area 0

network 10.3.2.0 0.0.0.255 area 0

network 10.1.0.0 0.0.255.255 area 0

network 10.2.0.0 0.0.255.255 area 0

default-information originate

distribute-list ospf-ny in

!

router bgp 3

no synchronization

bgp log-neighbor-changes

network 10.1.0.0 mask 255.255.0.0

network 10.2.0.0 mask 255.255.0.0

redistribute ospf 3 metric 790 match internal external 1 external 2

neighbor xxx.xxx.xxx.xxx remote-as 5000

no auto-summary

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: OSPF wins over BGP

Hello,

first the announcement of a network will for sure be faster through OSPF than through BGP. Once you have the OSPF route in the routing table you redistribute it into BGP. Now BGP learns the network through AS 5000.

At this point BGP path selection determines which of the two is the better path. And the winner is: locally redistributed route! (Do a show ip bgp to check this!). With this one BGP does NOT win against OSPF - actually where it comes from.

Administrative distance does not play a role in BGP path selection.

So you would need a route-map with the redistribution in case you would like to change this.

router bgp 3

redistribute ospf 3 metric 790 match internal external 1 external 2 route-map OSPF2BGP

route-map OSPF2BGP permit 10

match ip addess 100

set weight 0

set local preference 50

access-list 100 permit ...networks...

This will do the trick. But be extremely careful this way you might generate a routing loop easily (OSPF->BGP->MPLS->BGP->OSPF and round and round it goes ;-). So you need to include some sort of filter to prevent this.

Did this help? Please rate all posts.

Martin

Purple

Re: OSPF wins over BGP

Hi,

Just to expand on Martin's post....

When BGP injects a local route into the BGP table, it gives it a weight of 32768, by default. In your case, it is the OSPF-learned route that is getting injected into BGP with a weight of 32768. The same route is also being learned via EBGP. EBGP routes, by default, will be given a weight of 0 and a local preference of 100. Now, the BGP table will have two routes for the same prefix - which you will see if you enter in 'sh ip bgp '. Since weight is the highest ranked parameter in the BGP best path selection process, the locally-injected route will take preference and will be selected as the best route. Therefore, as far as the routing table is concerned, the best BGP path for that prefix is the locally-injected route (which was learned via OSPF). That is why you see that the installed route is an OSPF route.

The AD does not come into the picture as far as BGP path selection goes (although a distrinction between EBGP and IBGP learned routes is made further down the BGP best path selection process).

However, if you had had a situation where you were not redistributing the OSPF route into BGP, the BGP table would only have a single path for this prefix, the one learned via EBGP. This would then be compared against the OSPF route and since EBGP has an AD of 20, the EBGP route would have been installed.

The alternative, as per Martin's post, is to redistribute the OSPF route into BGP, but to make it less attractive to the BGP best path selection process by making its weight the same as the EBGP route but give it a local preference that is lower than the EBGP route.

Hope that helps,

Paresh.

4 REPLIES

Re: OSPF wins over BGP

Hello,

first the announcement of a network will for sure be faster through OSPF than through BGP. Once you have the OSPF route in the routing table you redistribute it into BGP. Now BGP learns the network through AS 5000.

At this point BGP path selection determines which of the two is the better path. And the winner is: locally redistributed route! (Do a show ip bgp to check this!). With this one BGP does NOT win against OSPF - actually where it comes from.

Administrative distance does not play a role in BGP path selection.

So you would need a route-map with the redistribution in case you would like to change this.

router bgp 3

redistribute ospf 3 metric 790 match internal external 1 external 2 route-map OSPF2BGP

route-map OSPF2BGP permit 10

match ip addess 100

set weight 0

set local preference 50

access-list 100 permit ...networks...

This will do the trick. But be extremely careful this way you might generate a routing loop easily (OSPF->BGP->MPLS->BGP->OSPF and round and round it goes ;-). So you need to include some sort of filter to prevent this.

Did this help? Please rate all posts.

Martin

Purple

Re: OSPF wins over BGP

Hi,

Just to expand on Martin's post....

When BGP injects a local route into the BGP table, it gives it a weight of 32768, by default. In your case, it is the OSPF-learned route that is getting injected into BGP with a weight of 32768. The same route is also being learned via EBGP. EBGP routes, by default, will be given a weight of 0 and a local preference of 100. Now, the BGP table will have two routes for the same prefix - which you will see if you enter in 'sh ip bgp '. Since weight is the highest ranked parameter in the BGP best path selection process, the locally-injected route will take preference and will be selected as the best route. Therefore, as far as the routing table is concerned, the best BGP path for that prefix is the locally-injected route (which was learned via OSPF). That is why you see that the installed route is an OSPF route.

The AD does not come into the picture as far as BGP path selection goes (although a distrinction between EBGP and IBGP learned routes is made further down the BGP best path selection process).

However, if you had had a situation where you were not redistributing the OSPF route into BGP, the BGP table would only have a single path for this prefix, the one learned via EBGP. This would then be compared against the OSPF route and since EBGP has an AD of 20, the EBGP route would have been installed.

The alternative, as per Martin's post, is to redistribute the OSPF route into BGP, but to make it less attractive to the BGP best path selection process by making its weight the same as the EBGP route but give it a local preference that is lower than the EBGP route.

Hope that helps,

Paresh.

New Member

Re: OSPF wins over BGP

Hi

Many thanks to both of you, the solution worked perfectly.

Rich

New Member

Re: OSPF wins over BGP

Not always IGP wins over EGP, even when there is distribution.

If the route or prefix for any reason disappears from the IGP, the EGP route will be immediately injected in the routing table with an AD of 20 if it is eBGP.

Then when the IGP recovers, since the eBGP route is already established in the routing table, IGP will not participate in the EGP path selection. Therefore it will not be selected.

The only way to make it work is 'clear ip bgp *', which basically resets BGP and clears the routing table from all BGP entries. This is a manual process and I would not recommend it.

Does anybody know a trick to overcome this limitation or 'feature'?

441
Views
0
Helpful
4
Replies
CreatePlease login to create content