# Optimizing the Cost to Reach a Range of OSPF Routers Within an Area

OSPF automatically calculates a cost for an area based on the individual costs from an area border router to each OSPF router within that area. The highest individual cost is advertised by the area border router as the aggregate cost for routers in an adjacent area to reach any router within the first area. Consider the topology shown in Figure 17.

Figure 17: Optimizing OSPF Area Aggregate Costs

In this example, the router IDs of the OSPF routers in area 1 are announced by OSPF into area 0. ABR 1 and ABR 2 aggregates the 10.1.1.x networks in area 1 at the border. Each individual OSPF link has a cost of 1.

ABR 1 calculates the following costs:

- A cost of 5 to reach Router 6:
  ABR 1-->Router 4-->Router 5--> ABR 2-->Router 6
- A cost of 3 to reach Router 5:
  ABR 1-->Router 4-->Router 5
- A cost of 2 to reach Router 4:
  ABR 1->Router 4

The highest individual cost is 5. ABR 1 subsequently advertises a cost of 5 for the aggregate 10.1.1.0 to be announced into area 0.

ABR 2 calculates the following costs:

- A cost of 2 to reach Router 6:
  ABR 2-->Router 6
- A cost of 2 to reach Router 5:
  ABR 2-->Router 5
- A cost of 3 to reach Router 4:
  ABR 2-->Router 5-->Router 4

The highest individual cost is 3. ABR 2 subsequently calculates a cost of 3 for the aggregate 10.1.1.0 to be announced into area 0.

When Router 3 sends traffic to Router 4, it routes the traffic via ABR 2 because ABR 2 advertises a lower cost than does ABR 1. However, this path is not optimal, because the traffic must traverse Router 3-->Router 7-->ABR 2--> Router 5-->Router 4. The path through ABR 1, Router 3-->ABR 1-->Router 4 is a better path, even though ABR 1 advertised a higher aggregate cost.

You can avoid this kind of suboptimal routing by manually configuring a cost for the aggregate. The summary LSA then announces the configured cost instead of the automatically calculated cost. Use the cost keyword with the area range command to specify a cost for a range of OSPF networks aggregated at an area boundary.