OSPF cost calculation
-
Okay, dumb question.. Does OSPF cost evaluate both the egress and ingress interface costs? Or is it egress only?
For example in the following diagram, if router A was calculating OSPF cost to reach Network 1, would the cost be 30, adding up the cost of every interface? Or would Router B Gi0/1 be excluded from the calculation?
-
This is one that you could easily test by running a basic lab setup. I setup a 3 ( R1-----R2----R3) router lab to show. Now I'm using Gig interfaces and loopbacks so the costs are different.
is the result from my R1 (=Router A)
R1(config-router)#do show ip route ospf Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/2] via 192.168.16.2, 00:05:48, GigabitEthernet0/1 3.0.0.0/32 is subnetted, 1 subnets O 3.3.3.3 [110/3] via 192.168.16.2, 00:04:15, GigabitEthernet0/1 172.31.0.0/24 is subnetted, 1 subnets O 172.31.16.0 [110/2] via 192.168.16.2, 00:05:22, GigabitEthernet0/1
Here is from my R3:
R3(config-router)#do show ip route ospf Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/2] via 172.31.16.2, 00:05:28, GigabitEthernet0/0 O 192.168.16.0/24 [110/2] via 172.31.16.2, 00:05:28, GigabitEthernet0/0
I forgot to post the result:
As you can see from R1 to 172.31.16.0...is only two a metric cost of 2...though there is an exiting interface, incoming interface and exiting interface in between. So in a practical sense only count the exiting interface. This seems to have been true also with the virtual loopback int as well (this I didn't remember).
-
This is one that you could easily test by running a basic lab setup. I setup a 3 ( R1-----R2----R3) router lab to show. Now I'm using Gig interfaces and loopbacks so the costs are different.
is the result from my R1 (=Router A)
R1(config-router)#do show ip route ospf Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/2] via 192.168.16.2, 00:05:48, GigabitEthernet0/1 3.0.0.0/32 is subnetted, 1 subnets O 3.3.3.3 [110/3] via 192.168.16.2, 00:04:15, GigabitEthernet0/1 172.31.0.0/24 is subnetted, 1 subnets O 172.31.16.0 [110/2] via 192.168.16.2, 00:05:22, GigabitEthernet0/1
Here is from my R3:
R3(config-router)#do show ip route ospf Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/2] via 172.31.16.2, 00:05:28, GigabitEthernet0/0 O 192.168.16.0/24 [110/2] via 172.31.16.2, 00:05:28, GigabitEthernet0/0
I forgot to post the result:
As you can see from R1 to 172.31.16.0...is only two a metric cost of 2...though there is an exiting interface, incoming interface and exiting interface in between. So in a practical sense only count the exiting interface. This seems to have been true also with the virtual loopback int as well (this I didn't remember).
-
Thanks Ronnie. I was pretty confident that was the case, but I appreciate you confirming.
So in our particular use case this gets a little tricky. Say you have two sites with a single router each, but two connections between them. Router “A” has two internet connections. Site “B” has a single internet connection. There is no traditional leased line between each router, instead there are two “tunnel” interfaces on each router with GRE+encrytion.
Where it gets tricky with cost, let’s say circuit 1 on router A is a 200Mbps circuit and Circuit 2 in site A is a backup 20Mbps circuit. Without getting in the details of reference bandwidth and the actual cost, it is pretty straight forward to say that circuit 1 will be the preferred path. However, in site “B” there is only a single internet connection for both tunnel interfaces. If the cost is the same for both tunnel interfaces going to circuit 1/2 in site A, there is a chance that the site B will use the tunnel interface which terminates to the slower link in site A. The only way around this I can think of is to manually adjust the cost of the second tunnel in site B so that it is intentionally higher than the preferred path.
Would that cause other issues though? Something you’ve run into before?
Regards,
Adam Tyler -
Since you call "Circuit 2" a backup link...why not just make it a floating static route instead with an AD that is just slightly higher than 110 (for example 111). Then that second link will only appear in the table, if the Circuit 1 goes down?
-
@Ronnie-Wong said in OSPF cost calculation:
Since you call "Circuit 2" a backup link...why not just make it a floating static route instead with an AD that is just slightly higher than 110 (for example 111). Then that second link will only appear in the table, if the Circuit 1 goes down?
Thanks Ronnie, interesting suggestion. I guess the reason I wouldn’t do a floating static route is because I’d still need the router to “learn” of remote routes dynamically even in the event of a failover condition. So the “backup” circuit would still need to have an OSPF adjacency and pick right up if the primary tunnel interface fails.
Regards,
Adam Tyler -
@Adam-Tyler,
So just leave as is.
You won't have to worry if your links are different (20mbps and 200mbps). OSPF will only see the 200mbps and put that into the routing table anyways. OSPF cannot do unequal cost load balancing, so that 20mbps route would only appear if the 200mbps route disappears. Look at my ospf route to 1.1.1.1R2(config-router)#do show ip route ospf 1 Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override Gateway of last resort is not set 1.0.0.0/32 is subnetted, 1 subnets O 1.1.1.1 [110/2] via 10.0.0.1, 00:00:11, GigabitEthernet0/0 R2(config-router)#int g0/0 R2(config-if)#shutdown R2(config-if)#do show i *Dec 17 10:14:12.967: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on GigabitEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached R2(config-if)#do show ip ro *Dec 17 10:14:14.947: %LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to administratively down *Dec 17 10:14:15.947: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to downu R2(config-if)#do show ip route ospf Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override Gateway of last resort is not set 1.0.0.0/32 is subnetted, 1 subnets O 1.1.1.1 [110/65] via 10.0.100.1, 00:00:00, Serial1/0 10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks O 10.0.0.0/24 [110/65] via 10.0.100.1, 00:00:00, Serial1/0 R2(config-if)#