Wed Dec 13, 2017 5:25 pm
OSPF really is not a policy routing type of protocol.
It picks the link which represents the first hop in the shortest path to a given destination. The only "fancy" thing at its disposal is EQMP - equal cost multi-path, which means to load balance between X links if all of them share the same distance, and that being the best distance to the destination.
That being said, you can do a few things to fudge behavior that you want.
First of all, it sounds like your routers are set to redistribute static routes into OSPF, because other routers are picking up on your routing decisions. You can use route filters to prevent certain routes from being injected into OSPF, but once they're there, they're there - they can only be filtered out at area borders in certain broad ways. (i.e. not on a route-by-route basis ala BGP)
Another item to consider is the difference between external route types in OSPF: type1 and type2. (E1 & E2).
When an ASBR injects a route into OSPF as E2, it will set some metric, say cost=20. This value remains constant on E2 prefixes - so the cost of this link will be the same one hop away or 10 hops away. Routers will use the path cost to reach the ASBR as a tiebreaker when comparing two E2 routes to the same destination, having the same OSPF cost.
E1 routes are like E2, except that they also "accumulate" the internal path cost as well. Suppose the best path from some Router R1 to reach an ASBR is 315, and the ASBR injected some prefix with a cost of 50. R1 will show the cost to reach that destination as 365. Had the ASBR injected it as E2, the cost would just be 50.
One final note is that route types are more important to OSPF than the cost. So if you have a destination with several paths in OSPF:
Intra-Area cost = 10000
Inter-Area cost = 1000
E1 cost = 100
E2 cost = 10
OSPF will choose them in the order I listed, despite the fact that this is the reverse order of cost according to the metrics.
You can use these differences to influence behavior. Remember that default prefixes in OSPF are going to be external routes, but they can be injected as E1 or E2.
If you want to do some basic traffic engineering, you can use E1 default GW prefixes so that your network's internal topology will influence the choice made by each router. If you can tweak your interface costs such that a router will consider GW1 to be "closer" than GW2, while other routers will be closer to GW2 than GW1, this will basically give you the behavior that you want.
It does have limitations, though, because if your topology changes, then all bets are off - at least you need to consider what the network will do in various regimes of certain links being up/down, etc.