OSPF Redistribution Metrics
Unlike EIGRP, OSPF does not require that a metric be specified when redistribution from any route source into OSPF is performed. OSPF assigns a default route metric based on the route source. These default assignments are as follows:
- Redistributed routes from BGP are assigned a metric or cost of 1
- Redistributed routes from another OSPF process use the source routes cost
- All other redistributed routes are assigned a default metric of 20
As with EIGRP, there are several ways the OSPF metric can be configured during redistribution. The seed metric for all routes can be configured using the default-metric <value> router configuration command. The metric can also be configured directly during redistribution using the redistribute [protocol] metric <value> router configuration command. And finally, the OSPF metric can also be specified in a route map using the redistribute [protocol] route-map <name> router configuration command. The configuration of the OSPF metric using these three values is no different than was illustrated for EIGRP in the previous section, with the exception being that the metric will be the OSPF metric and not the EIGRP composite metric.
In addition to the metric, all OSPF external routes are designated as Type 2 external routes by default. However, this default behavior can be changed using the redistribute [protocol] metric-type <1 | 2> router configuration command or by setting the metric in a route map referenced during redistribution using the set metric-type [type-1 | type-2] route map configuration command. Before we delve into the specifics of external OSPF routes, it is important to have a solid understanding of the differences between Type 2 and Type 1 external OSPF routes. These are described in the following section.
Understanding and Calculating Type 2 External Routes
If no metric is assigned during redistribution, external routes are assigned a default metric of 20. Also, by default, OSPF external routes are Type 2 external routes. However, both the metric and metric type can be manually specified during redistribution into OSPF. Before we delve into the specifics of OSPF route redistribution, it is important to understand the difference between the Type 1 and Type 2 external routes.
The primary difference between Type 1 and Type 2 external routes is the way in which the cost or metric is calculated. In Cisco IOS software, external OSPF routes are designated as Type 2 routes. When routes are redistributed into OSPF as Type 2 then every router in the domain will see the same cost to reach the external networks. In other words, the cost in the External LSA (Type 5) LSA that is generated for the Type 2 external route will never change and the same value will be seen on all routers in the network, regardless of how far away they are from the ASBR that injected the external route into the OSPF domain.
Because the metric for Type 2 external routes remains consistent as the LSA is flooded through the OSPF domain, routers need to be able to have some kind of method to use as a tie-breaker when more than one ASBR injects the same external LSA into the routing domain or when there is more than one path to the ASBR. The tie-breaker is calculated in a different manner depending on whether the ASBR resides within the same area or in another area.
If the ASBR resides within the same area, routers look at the router ID listed in the advertising router field in the Type 5 LSA to determine the router ID of the ASBR. The routers then look at the intra-area Link State Advertisements to determine the best path to this router. The router then forwards traffic to the ASBR using the best intra-area route to the ASBR. To further clarify this point, consider the basic OSPF network topology that is illustrated in Figure 4-10 which shows fours routers in a single area:
Fig. 4-10. Understanding OSPF Type 2 External Routes
Referencing Figure 4-10, R1 is redistributing the 192.168.254.0/24 subnet into OSPF. The router generates a Type 5 LSA which is then flooded by R2 and R3 to R4. The cost of the respective links between R1 and R2 and between R2 and R3 is 1. However, the cost of the link between R2 and R4 is 97 and the cost of the link between R3 and R4 is 130.The Link State Database on R4 shows the following Type 5 LSA entries for this external route:
| R4#show ip ospf database external 192.168.254.0OSPF Router with ID (4.4.4.4) (Process ID 4)Type-5 AS External Link States
Routing Bit Set on this LSA |
Because R1 receives this LSA from both R2 and R3, the router looks at the intra-area LSAs for both routers to determine the next-hop router and interface it will use to forward traffic to the destination network. The intra-area LSA for R2 shows the following:
| R4#show ip ospf database router 2.2.2.2OSPF Router with ID (4.4.4.4) (Process ID 4)Router Link States (Area 0)
LS age: 886 Link connected to: another Router (point-to-point) Link connected to: a Stub Network Link connected to: another Router (point-to-point) Link connected to: a Stub Network |
Referencing the output above, the cost of the link between R4 and R2 is 97 while the cost of the link between R2 and R1 is 1. The total cost for this path is therefore 98. The router LSA for R3 shows reflects the following information:
| R4#show ip ospf database router 3.3.3.3OSPF Router with ID (4.4.4.4) (Process ID 4)Router Link States (Area 0)
LS age: 1035 Link connected to: another Router (point-to-point) Link connected to: a Stub Network Link connected to: another Router (point-to-point) Link connected to: a Stub Network |
Referencing the output above, the cost of the link between R4 and R3 is 130 while the cost of the link between R3 and R1 is 1. The total cost for this path is therefore 131. Given that the path via R2 is the best intra-area path to R1, R4 forwards traffic to the 192.168.254.0/24 subnet via Serial0/0 and shows 98 as the forward metric, i.e. the internal metric to get to the ASBR. However, the actual route metric for a Type 2 external route will never change and will always be set to 20. This is validated using the show ip route command on R4 as follows:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 20, type extern 2, forward metric 98 Last update from 10.0.2.2 on Serial0/0, 00:28:02 ago Routing Descriptor Blocks: * 10.0.2.2, from 1.1.1.1, 00:28:02 ago, via Serial0/0 Route metric is 20, traffic share count is 1 |
In the output above, because the route is a Type 2 external route, the actual route metric will always be consistent. However, the forward metric will vary depending on how far the router is from the ASBR. For example, if the link between R4 and R2 failed, R4 would use the path via router R3 to reach the ASBR. While the route would still show the default metric of 20, the forward metric would change to reflect the intra-area cost to reach the ASBR as is shown below:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 20, type extern 2, forward metric 131 Last update from 10.0.3.3 on Serial0/1, 00:00:00 ago Routing Descriptor Blocks: * 10.0.3.3, from 1.1.1.1, 00:00:00 ago, via Serial0/1 Route metric is 20, traffic share count is 1 |
For inter-area routes, the router calculates the forward metric to the ASBR (R1) by adding the cost to reach the ABR that flooded the Type 5 LSA into the area, to the cost of reaching the ASBR from the ABR. To further reinforce this point, consider the basic multi-area OSPF network topology illustrated in Figure 4-11. Referencing figure 4-13, R1, R2, and R3 are backbone routers. R4 resides in area 1. R1 (ASBR) is redistributing the 192.168.254.0/24 subnet into the OSPF domain. R2 and R3, flood the Type 5 LSA for this external entry into area 1 and it is received by router R4.
Fig. 4-11. Understanding OSPF Type 2 External Routes
Based on the topology illustrated in Figure 4-11, the LSDB on R4 shows the following entry:
| R4#show ip ospf database external 192.168.254.0OSPF Router with ID (4.4.4.4) (Process ID 4) Type-5 AS External Link States
Routing Bit Set on this LSA |
R4 calculates the cost of the metric of the external route by first looking at the cost to reach each individual ABR. This is performed by looking at the intra-area LSAs as was illustrated in the output of the show ip ospf database router command in the previous example. Because the values in Figure 4-10 are the same as those in Figure 4-11, there is no need to re-validate this step as we already know that the cost from R4 and R2 is 97, while the cost from R4 to R3 is 130.
As we learned in the previous chapter, a Type 4 LSA is created by each ABR for every ASBR that is reachable via an intra-area LSA. Although the Type 4 LSA is flooded by the ABR, it contains information on the ASBR, which includes the ABR metric to the ASBR. Based on this topology, the LSDB on R4 shows the two Type 4 LSAs received from ABRs R2 and R3:
| R4#show ip ospf database asbr-summary 1.1.1.1OSPF Router with ID (4.4.4.4) (Process ID 4)Summary ASB Link States (Area 1)
Routing Bit Set on this LSA LS age: 1150 |
Both of the Type 4 LSAs received by R4 from routers R2 and R3 show a metric of 1, which is the cost of each ABR to the ASBR. R4 calculates the forward metric to the external route by adding up the cost to the ABR and the cost from the ABR to the ASBR. The cost of the path through R2 would be 97 + 1 = 98, while the cost of the path through R3 would be 130 + 1 = 131. R4 prefers the path through R2 and uses this router as the next-hop device to the 192.168.254.0/24 subnet:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 20, type extern 2, forward metric 98 Last update from 10.0.2.2 on Serial0/0, 00:15:31 ago Routing Descriptor Blocks: * 10.0.2.2, from 1.1.1.1, 00:15:31 ago, via Serial0/0 Route metric is 20, traffic share count is 1 |
From a human perspective, you can use the show ip ospf border-routers command to list all know ABRs and ASBRs and determine the best path to the ASBR. The output of this command shows the following on R4:
| R4#show ip ospf border-routersOSPF Process 4 internal Routing TableCodes: i – Intra-area route, I – Inter-area route
I 1.1.1.1 [98] via 10.0.2.2, Serial0/0, ASBR, Area 1, SPF 3 |
From the output above, we can determine that from R4s perspective, the best path to the ASBR (R1) is via Serial0/0, which transits through R2 and have a total path cost of 98, which is the same value in the forward metric as seen in the output of the show ip route command. This command also includes the cost of reaching both ABRs from R4 itself. These cost values are the same as those shown in Figure 4-12 and Figure 4-13. Table 4-4 lists and describes the information included in the output of the show ip ospf border-routers command:
|
Field |
Description |
|---|---|
|
I or i |
The code may be one of two values which are used indicate whether the route is intra-area (i) or inter-area (I) |
|
1.1.1.1 |
This contains the router ID of the OSPF destination router |
|
[98] |
This indicates the cost of the path to destination router |
|
via 10.0.2.2 |
This indicates the next-hop address to the destination router |
|
Serial0/0 |
This indicates the outgoing interface to the destination router |
|
ASBR or ABR |
The router type may be one of two values which are used to indicate whether the router is an ASBR or an ABR |
|
Area 1 |
This indicates the area via which the route has been learned not the area in which the router resides |
|
SPF 3 |
This indicates the internal number of the SPF calculation that installs this route |
Tab. 4-4. The show ip ospf border-routers Command Fields
Understanding and Calculating Type 1 External Routes
Unlike for Type 2 external routes, the OSPF route metric for a Type 1 external route is calculated using the internal OSPF cost to the ASBR and the external redistribution cost. This means that unlike Type 2 external routes, if any routes are redistributed into OSPF as Type 1 external routes, the actual route metric will vary from router to router depending on how far downstream the router is from the ASBR and based on the cumulative cost of the links from the router to the ASBR. Going back to the topology illustrated in Figure 4-10 wherein routers R1, R2, R3 and R4 reside within the same area, R1 is configured to redistribute the 192.168.254.0/24 subnet as a Type 1 external route. The corresponding Type 5 LSA on R4 shows the following:
| R4#show ip ospf database external 192.168.254.0OSPF Router with ID (4.4.4.4) (Process ID 4)Type-5 AS External Link States
Routing Bit Set on this LSA |
In the output above, the Type 5 LSA shows the default metric that has been assigned during redistribution, which is 20. R4 calculates the route metric to the 192.168.254.0/24 subnet by adding this value to the cost of reaching the ASBR. The cumulative cost of reaching the ASBR can be determined by looking at the intra-area LSAs as illustrated below:
| R4#show ip ospf database router 2.2.2.2OSPF Router with ID (4.4.4.4) (Process ID 4)Router Link States (Area 0)
LS age: 476 Link connected to: another Router (point-to-point) Link connected to: a Stub Network Link connected to: another Router (point-to-point) Link connected to: a Stub Network |
In the output above, the cost of the link between R2 and R1 is 1, while the cost of the link between R2 and R4 is 97. The total path cost to the ASBR through R2 is 98. The same command will also provide the same information for the path cost through R3, as follows:
| R4#show ip ospf database router 3.3.3.3OSPF Router with ID (4.4.4.4) (Process ID 4)Router Link States (Area 0)
LS age: 653 Link connected to: another Router (point-to-point) Link connected to: a Stub Network Link connected to: another Router (point-to-point) Link connected to: a Stub Network |
In this case, the path cost between R4 and R3 is 130, while the cost of the link between R3 and R1 is 1. The total path cost through R3 would be 131. After having derived this information, R4 calculates the route metric for the 192.168.254.0/24 subnet as follows:
- Total Cost to ASBR via R2 (98) + Redistribution Metric (20) = Route Metric of 118
- Total Cost to ASBR via R3 (131) + Redistribution Metric (20) = Route Metric of 151
The metric for the path via R2 is better. This route is placed into the RIB as follows:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 118, type extern 1 Last update from 10.0.2.2 on Serial0/0, 00:12:00 ago Routing Descriptor Blocks: * 10.0.2.2, from 1.1.1.1, 00:12:00 ago, via Serial0/0 Route metric is 118, traffic share count is 1 |
If the link between R2 and R4 failed, the path via R3 would be used. This would have a route metric of 151 as illustrated in the following output:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 151, type extern 1 Last update from 10.0.3.3 on Serial0/1, 00:00:04 ago Routing Descriptor Blocks: * 10.0.3.3, from 1.1.1.1, 00:00:04 ago, via Serial0/1 Route metric is 151, traffic share count is 1 |
For inter-area Type 1 external routes, the router uses the total cost from itself to the ABR, which would included in intra-area LSAs, the cost of the ABR to the ASBR, which is included in the Type 4 LSAs, and the external metric assigned during redistribution. The cost from the local router itself to the ABR and from the ABR to the ASBR represents the internal OSPF cost. Referencing the multi-area OSPF topology shown in Figure 4-12, R4 would calculate the best path to 192.168.254.0/24 by as follows:
- Path via R2 = R4 cost to R2 (97) + R2 cost to R1 (1) + redistribution metric (20) = 118
- Path via R3 = R4 cost to R3 (130) + R3 cost to R1 (1) + redistribution metric (20) = 151
The route metric for the best path (via R2) is shown in the following output:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 118, type extern 1 Last update from 10.0.2.2 on Serial0/0, 00:07:31 ago Routing Descriptor Blocks: * 10.0.2.2, from 1.1.1.1, 00:07:31 ago, via Serial0/0 Route metric is 118, traffic share count is 1 |
A simpler way to calculate the metric manually would be to add the metric included to the ASBR shown in the output of the show ip ospf border-routers command to the redistribution metric as illustrated below:
| R4#show ip ospf border-routersOSPF Process 4 internal Routing TableCodes: i – Intra-area route, I – Inter-area route
I 1.1.1.1 [98] via 10.0.2.2, Serial0/0, ASBR, Area 1, SPF 8 |
The route metric for the path via R3, which would only be used when the path via R2 was not available, is shown in the following output:
| R4#show ip route 192.168.254.0 255.255.255.0 Routing entry for 192.168.254.0/24 Known via “ospf 4”, distance 110, metric 151, type extern 1 Last update from 10.0.3.3 on Serial0/1, 00:00:00 ago Routing Descriptor Blocks: * 10.0.3.3, from 1.1.1.1, 00:00:00 ago, via Serial0/1 Route metric is 151, traffic share count is 1 |
Again, this can be calculated by simply adding the metric in the output of the show ip ospf border-routerscommand to the redistribution metric:
| R4#show ip ospf border-routersOSPF Process 4 internal Routing TableCodes: i – Intra-area route, I – Inter-area route
I 1.1.1.1 [131] via 10.0.3.3, Serial0/1, ASBR, Area 1, SPF 9 |
In summation, it is important to remember that the metric of a Type 2 route is always the metric assigned during redistribution, i.e. the external cost. Routers will forward traffic to external subnets to the ASBR that advertises the lowest metric to the destination network, irrespective of the interior cost to reach that route. However, if the external route metrics are the same for, internal costs will be used to break the tie.
The Type 1 metric is derived from the external cost and the internal cost used to reach that route. By default, OSPF will always prefer a Type 1 route over a Type 2 route for the same destination network(s). This happens regardless of the internal cost. These concepts are described in further detail in the route redistribution configuration examples that follow.

