Page 1 of 1

[OSPF][iBGP] route filtering syntax help

Posted: Wed Jan 22, 2025 2:05 pm
by Byron
Hi all,

ROS 7.17

refer to the beautiful paint drawing that I have attached.

Green - gateways
Black - backbone links
Red - backup backbone links
Blue - WAN Provider links
Yellow - Internet (Cloud)

How do I add cost to the backup backbone (Red) link so that when adjacency is formed, they will not be advertised? If I set the backup link into an ospf area, the routes from either side do not redistribute into one another. So basically I want the backup links to only advertise when it is active and the main links to their respective WANs drop.

For example, if a black link dies on either side, it must failover via the red link out to the opposite WAN/ Provider.

If I set it as a backbone area in OSPF this works but then all traffic uses a single provider (WAN) instead of their respective provider split as per the red link.

Help? my brain is tired.

Re: [OSPF] adding cost on backbone neighbor

Posted: Wed Jan 22, 2025 2:16 pm
by Byron
As in attached on this post.

When red link is not setup in OSPF the traffic flows correctly as seen by the purple arrows.

When red link is setup in OSPF the traffic flows incorrectly as seen by the purple arrows.

Routes are then learned on the routing concentrator via one WAN link and has backups via the OTHER WAN link. I want it to show on the concentrator that routes are learned via the correct WAN and the respective backup link/ routes are learned via their respective WAN link.

If this makes sense. (left = correct but its not setup for failover via red link)

Re: [OSPF] adding cost on backbone neighbor

Posted: Wed Jan 22, 2025 5:14 pm
by tdw
How do I add cost to the backup backbone (Red) link so that when adjacency is formed, they will not be advertised? If I set the backup link into an ospf area, the routes from either side do not redistribute into one another. So basically I want the backup links to only advertise when it is active and the main links to their respective WANs drop.
OSPF does not work like that. Links are always advertised, the OSPF algorithm then determines the shortest path from all of the advertised links within an instance.

If the gateways with the external connections (those with blue links in your diagram) are set to redistribute default route if installed then the path cost from each of the other gateways is the sum of the intervening path costs, with the default cost of 10 the break would be as drawn.

If your concentrator is also part of the OSPF instance presumably you have virtual links across both of the Internet connections to wherever your concentrator is.

Re: [OSPF] adding cost on backbone neighbor

Posted: Thu Jan 23, 2025 8:49 am
by Byron
How do I add cost to the backup backbone (Red) link so that when adjacency is formed, they will not be advertised? If I set the backup link into an ospf area, the routes from either side do not redistribute into one another. So basically I want the backup links to only advertise when it is active and the main links to their respective WANs drop.
OSPF does not work like that. Links are always advertised, the OSPF algorithm then determines the shortest path from all of the advertised links within an instance.

If the gateways with the external connections (those with blue links in your diagram) are set to redistribute default route if installed then the path cost from each of the other gateways is the sum of the intervening path costs, with the default cost of 10 the break would be as drawn.

If your concentrator is also part of the OSPF instance presumably you have virtual links across both of the Internet connections to wherever your concentrator is.

Should I then be playing with the cost on the black links instead of the red link?

I know that the routes will be advertised at the WAN points no matter what. But I'm running iBGP to the concentrators and that's where my problem is with the routes being advertised into the concentrator table with the one WAN point for all and the second WAN point as a backup.

Re: [OSPF] adding cost on backbone neighbor

Posted: Thu Jan 23, 2025 3:06 pm
by tdw
Having only used OSPF and dynamic static routes (i.e. static routes attached to PPP secrets) I don't know how the metrics between routing protocols are handled in the Mikrotik BGP implementation.

The topic title doesn't really reflect the problem at hand, you may wish to edit it so others may see it be able to help. They will almost certainly want more information than just a network sketch.

Re: [OSPF] adding cost on backbone neighbor

Posted: Thu Jan 23, 2025 6:52 pm
by Larsa
@Byron – I might have missed or misunderstood something, so this is just a guess:

I presume you’re advertising default gateways for both "network stacks" through the red (backup) link. To start troubleshooting, try checking one of the nodes and looking at the distance in the routing tables for the OSPF-generated default routes. Also, check for any static routes that might interfere, cause conflicts, or mess with redistribution.

Adjust the OSPF costs for each link of the stack and the backup link if necessary. Make sure the OSPF costs for the red (backup) link are high enough so it's only used when the black (primary) links fail. Also, double-check that the red backup link is in the right OSPF area for redistribution.

Toggle the backup link and monitor the distance for the OSPF-generated default routes on the node you’re troubleshooting. If you're using BFD, you should notice a change within a second. Otherwise, it will take the standard 10 seconds for ethernet and 30 seconds for non-broadcast links. If everything looks good, you can start toggling the "black" links and monitor the default routes.

Re: [OSPF] adding cost on backbone neighbor

Posted: Fri Jan 24, 2025 8:31 am
by Byron
Maybe I am thinking about this the wrong way. My OSPF within each stack is correct and to think about it advertising correctly.

The issue starts when each WAN point learns the OSPF routes via iBGP, My concentrator then sees the routes coming from both WAN points, picks 1 to get to all said routes, and uses the other as a backup to get to all routes.

the only logical thing I can think of is to add filters to add a weigh metric to the iBGP points for the needed network ranges.... I'm wonder if there is a "better" way of doing this.

Re: [OSPF] adding cost on backbone neighbor

Posted: Fri Jan 24, 2025 8:35 am
by Byron
@Byron – I might have missed or misunderstood something, so this is just a guess:

I presume you’re advertising default gateways for both "network stacks" through the red (backup) link. To start troubleshooting, try checking one of the nodes and looking at the distance in the routing tables for the OSPF-generated default routes. Also, check for any static routes that might interfere, cause conflicts, or mess with redistribution.

Adjust the OSPF costs for each link of the stack and the backup link if necessary. Make sure the OSPF costs for the red (backup) link are high enough so it's only used when the black (primary) links fail. Also, double-check that the red backup link is in the right OSPF area for redistribution.

Toggle the backup link and monitor the distance for the OSPF-generated default routes on the node you’re troubleshooting. If you're using BFD, you should notice a change within a second. Otherwise, it will take the standard 10 seconds for ethernet and 30 seconds for non-broadcast links. If everything looks good, you can start toggling the "black" links and monitor the default routes.
meant to quote you for the above reply.

Re: [OSPF][iBGP] adding cost on backbone neighbor

Posted: Fri Jan 24, 2025 9:45 am
by BartoszP
I think that the problem could be that you broadcast OSPF with iBGP and when the route cost changes during DR, BDR election or/and some links go down then default gateways change. My config for OSPF anounces only OSPF links and lo interfaces to let them see each other and then only lo interfaces are used for BGP.

Re: [OSPF][iBGP] adding cost on backbone neighbor

Posted: Fri Jan 24, 2025 10:54 am
by jprietove
I think you have to use external type 1 for the default route, so the cost will be the sum of external cost plus interface costs.

You can use filter like this:
if ( dst == 0.0.0.0/0 ) { set ospf-ext-type type1; accept }

Re: [OSPF] adding cost on backbone neighbor

Posted: Fri Jan 24, 2025 2:06 pm
by Larsa
The issue starts when each WAN point learns the OSPF routes via iBGP, My concentrator then sees the routes coming from both WAN points, picks 1 to get to all said routes, and uses the other as a backup to get to all routes. the only logical thing I can think of is to add filters to add a weigh metric to the iBGP points for the needed network ranges.... I'm wonder if there is a "better" way of doing this.

I’m not entirely sure how OSPF interacts with iBGP on the yellow gateway nodes in this case. I assume you’re not running iBGP in parallel with OSPF on both "stacks", like in the drawing. Btw, what do you mean by the yellow nodes being connected to a single "concentrator" ("My concentrator," as you called it)?

Anyway, if OSPF is learning both default routes from iBGP and advertising them as a pair in the wrong order on both sides, it should be easily spotted in the routing tables on any of the black nodes. To fix it, you could, for example, set up and advertise static default routes from the yellow node to each black node, or try using filters to adjust route preferences.

In my world, the "better" way is the one that's easiest, takes the least effort, and causes the least interference with other stuff! ;)

Re: [OSPF][iBGP] adding cost on backbone neighbor

Posted: Wed Jan 29, 2025 11:22 am
by Byron
ok now I want to create a iBGP filter rule to execute this:

If ospf-type = external then set bgp-med +1 (As an example)

But I'm trying to figure out the syntax but I cant seem to get it right.

Thanks in advanced.

Re: [OSPF][iBGP] route filtering syntax help

Posted: Tue Feb 04, 2025 1:12 pm
by Byron
bump

Re: [OSPF][iBGP] adding cost on backbone neighbor

Posted: Tue Feb 04, 2025 3:35 pm
by Larsa
ok now I want to create a iBGP filter rule to execute this...

I thought you were having trouble with OSPF. What are you trying to solve with BGP? Some more background would help.

Re: [OSPF][iBGP] route filtering syntax help

Posted: Wed Feb 05, 2025 11:31 am
by Byron
ok now I want to create a iBGP filter rule to execute this...

I thought you were having trouble with OSPF. What are you trying to solve with BGP? Some more background would help.
I have iBGP between my concentrator and the two WAN points. and I redistribute OSPF routes into my iBGP links.

If I can tell iBGP to add med/cost to the links I will be able to do it, I think. I just need some syntax help and then I have a plan.

Re: [OSPF][iBGP] route filtering syntax help

Posted: Wed Feb 05, 2025 2:45 pm
by Larsa
I’m not sure what you mean by “concentrator” in this case so you'll need to be more specific than that. Btw, did you manage to spot the root cause by checking how OSPF adds default routes to the routing table in one of the black nodes?

That said, MED is primarily designed to influence inbound traffic from external ASes (eBGP peers), so bgp-local-pref might be a better fit here. But have you considered using OSPF inbound filtering instead?