Saturday, January 27, 2024

Adjusting OSPF path selection

 

If you want to adjust the the path of an ospf router, beyond the route type (which is it's first and foremost criteria), there are a couple ways you can do it.

Link Cost:

Fist way is adjusting the cost of the link from the perspective of the ospf router. Lower cost is preferred, and if there are a couple links with equal cost, then they will be load balanced automatically.

First thing you may want to do is set your reference bandwidth across all ospf routers. A setting of 10,000 (expressed in Mbps - 10,000 Mbps is 10 Gbps) will be equivalent to 10 Gig, so  a 10 Gig interface will have a cost of 1, a 1 Gig interface a cost of 10, 100Mbps a cost of 100, and so on.

router ospf 1
auto-cost reference-bandwidth 10000


Consider the topology below...currently the route from R7 to the 4.4.4.4 network has the option of 2 paths -  both of equal cost - so they will be load balanced by ospf.


But if we want to only use say the link between R7 and and R1, we can do that by changing the link cost.

Current cost is 10 - and the route table for R7 is shown below- 2 equal cost routes to 4.4.4.4. Note that the loopback interface has a cost of 1, as it's a connected interface.....hence the 3 x 10 links + 1 gives you the 31.



Using the ip ospf cost # command under the respective interface will will change it the cost

R7(config)#interface gigabitEthernet 0/0
R7(config-if)#ip ospf cost 9

Now, we get this - a cost of 9


with a single "better" route (cost of 30 vs 31) to 4.4.4.4


This works fine...BUT...it will effect ALL routes advertised, and destined, across that link. May not be what we need. 

Administrative Distance (AD):

You can use the distance command to change the Administrative Distance of a specific route (AD)

First define the route you want to change the AD for in an access-list... in this case, it's 4.4.4.4/32 

R7(config)#access-list 1 permit host 4.4.4.4

Next determine the advertising router - the router that the route is learned from, in this case it's R3 - we need to use the routers ospf router id - which is 3.3.3.3 as shown below


Apply the distance command

distance <AD value> <advertising router id\wild card mask> <route defined in access list>

R7(config)#router ospf 1
R7(config-router)#distance 99 3.3.3.3 0.0.0.0 1 

This works, BUT, it does nothing to favor one link over another - you still have equal cost over the 2 links to the route


Due to OSPF's link-state nature, it's more preferable to use policy based routing (PBR), and direct the traffic type you want over a certain link.

PBR:

In the topology below, we will set the next hop to for ICMP traffic originating at R8, to use the link between the R1 and R7.


We will first create an access list to identify the route (destination in this case)

ip access-list extended ICMP
 permit icmp any host 4.4.4.4

Next we create a route-map to match the traffic type (icmp) and set the next hop

route-map PBR-ICMP permit 5
 match ip address ICMP
 set ip next-hop 10.1.17.1

Now tie it in and activate the PBR on the incoming incoming interface on R7 from R8

interface GigabitEthernet0/2
 ip policy route-map PBR-ICMP

Execute a ping on R8 to 4.4.4.4

You can observe the route-map matches incrementing here



Also, if you enable some debugging on R7 - then execute a ping on R8, you can validate the PBR is taking action on the traffic destine for 4.4.4.4

R7#debug ip policy


Hope this has been a useful reference on influencing OSPF routes

Here's a quick table of the OSPF route and LSA types:

Intra-Area (O)
Inter-Area (O IA)
External Type 1 (E1)
NSSA Type 1 (N1)
External Type 2 (E2)
NSSA Type 2 (N2)

LSA Type 1:            Router LSA
LSA Type 2:            Network LSA
LSA Type 3:            Summary LSA
LSA Type 4:            Summary ASBR LSA
LSA Type 5:            Autonomous system external LSA
LSA Type 6:            Multicast OSPF LSA
LSA Type 7:            Not-so-stubby area LSA
LSA Type 8:            External attribute LSA for BGP


 





No comments:

Post a Comment