What Is OSPF And How Is It Configured

A router requires a router ID if it is to run OSPF. A router ID is a 32-bit unsigned integer, uniquely identifying a router in an AS.

A router ID can be manually configured or automatically selected by a router:

* It is recommended that you manually configure a router ID to ensure OSPF stability.
* If no router ID is manually configured for a router, the router selects an interface IP address as its router ID. A router selects its router ID based on the following rules: 1. The router preferentially selects the largest IP address among loopback interface addresses as its router ID.
2. If no loopback interface is configured, the router selects the largest IP address among other interface addresses as its router ID.

After the router has been running OSPF and selected its router ID, it still uses this router ID if the interface whose IP address is used as the router ID is Down or disappears (for example, the undo interface loopback loopback-number command is run) or a larger interface IP address exists. The router can obtain a new router ID only after a router ID is reconfigured for the router or an OSPF router ID is reconfigured and the OSPF process restarts.

link State
OSPF is a link-state protocol. A link can be considered as a router interface. The link state is a description of that interface and of the relationship with its neighboring routers. For example, a description of the interface includes the IP address and mask of the interface, the type of the connected network, and the connected neighbors. The collection of all these link states forms a link-state database (LSDB).

COST
* OSPF uses the cost as the route metric.
* Each OSPF-enabled interface has a cost value. The formula used to calculate the cost is: Cost = 100M/Interface bandwidth. 100 Mbit/s is the OSPF reference bandwidth.
* The cost of an OSPF route is the sum of the cost values of all incoming interfaces from the source router to the destination router. The default reference bandwidth is 100 Mbit/s. If the transmission medium has a bandwidth higher than 100 Mbit/s, a cost of less than 1 is calculated, which is not allowed in OSPF and will be rounded off to 1. Currently, many network devices use interfaces with more than 100 Mbit/s bandwidth. In this case, route cost calculation is inaccurate. To address this problem, run the bandwidth-reference command to change the reference bandwidth. If you need to configure this command, you are advised to configure it on all OSPF routers on the entire network.

* OSPF uses the cost as the route metric.
* Each OSPF-enabled interface has a cost value. The formula used to calculate the cost is: Cost = 100M/Interface bandwidth. 100 Mbit/s is the OSPF reference bandwidth.
* The cost of an OSPF route is the sum of the cost values of all incoming interfaces from the source router to the destination router. The default reference bandwidth is 100 Mbit/s. If the transmission medium has a bandwidth higher than 100 Mbit/s, a cost of less than 1 is calculated, which is not allowed in OSPF and will be rounded off to 1. Currently, many network devices use interfaces with more than 100 Mbit/s bandwidth. In this case, route cost calculation is inaccurate. To address this problem, run the bandwidth-reference command to change the reference bandwidth. If you need to configure this command, you are advised to configure it on all OSPF routers on the entire network.

Packet Types
Table 1-1 Packet typesPacket Type

Function

Hello packet

Sent periodically to discover and maintain OSPF neighbor relationships.

Database Description (DD) packet

Contains brief information about the local link-state database (LSDB) and synchronizes the LSDBs on two devices.

Link State Request (LSR) packet

Requests the required LSAs from neighbors.

LSR packets are sent only after DD packets are exchanged successfully.

Link State Update (LSU) packet

Sends the required LSAs to neighbors.

Link State Acknowledgement (LSAck) packet

Acknowledges the receipt of an LSA.

LSA Types
Table 1-2 LSA typesLSA Type

Function

Router-LSA (Type 1)

Describes the link status and link cost of a router. It is generated by every router and advertised in the area to which the router belongs.

Network-LSA (Type 2)

Describes the link status of all routers on the local network segment. Network-LSAs are generated by a designated router (DR) and advertised in the area to which the DR belongs.

Network-summary-LSA (Type 3)

Describes routes to a specific network segment in an area. Network-summary-LSAs are generated by an Area Border Router (ABR) and advertised in all areas except totally stub areas and Not-So-Stubby Areas (NSSAs). For example, an ABR belongs to both area 0 and area 1. Area 0 has a network segment 10.1.1.0, and area 1 has a network segment 11.1.1.0. The Type 3 LSA of the network segment 11.1.1.0 generated by the ABR for area 0 and the Type 3 LSA of the network segment 10.1.1.0 generated by the ABR for area 1 are advertised within the non-totally stub area or NSSA.

ASBR-summary-LSA (Type 4)

Describes routes to an Autonomous System Boundary Router (ASBR). ASBR-summary-LSAs are generated by an ABR and advertised to all related areas except the area to which the ASBR belongs.

AS-external-LSA (Type 5)

Describes routes to a destination outside the AS. AS-external-LSAs are generated by an ASBR and advertised to all areas except stub areas and NSSAs.

NSSA-LSA (Type 7)

Describes routes to a destination outside the AS. Generated by an ASBR and advertised in NSSAs only.

Opaque-LSA (Type 9/Type 10/Type 11)

Provides a universal mechanism for OSPF extension.

* Type 9 LSAs are advertised only on the network segment where the interface originating Type 9 LSAs resides. Grace LSAs used to support GR are a type of Type 9 LSAs.
* Type 10 LSAs are advertised inside an OSPF area. LSAs used to support TE are a type of Type 10 LSAs.
* Type 11 LSAs are advertised within an AS. At present, there are no applications of Type 11 LSAs.

Support status of LSAs in different types of areas
Table 1-3 Support status of LSAs in different types of areasArea Type

Router-LSA (Type 1)

Network-LSA (Type 2)

Network-summary-LSA (Type 3)

ASBR-summary-LSA (Type 4)

AS-external-LSA (Type 5)

NSSA-LSA (Type 7)

Common area (including standard and backbone areas)

Supported

Supported

Supported

Supported

Supported

Not supported

Stub area

Supported

Supported

Supported

Not supported

Not supported

Not supported

Totally stub area

Supported

Supported

Not supported

Not supported

Not supported

Not supported

NSSA

Supported

Supported

Supported

Not supported

Not supported

Supported

Totally NSSA

Supported

Supported

Not supported

Not supported

Not supported

Supported

Router Types
Figure 1-1 lists common Router types used in OSPF.

Figure 1-1 Router typesTable 1-4 Router typesRouter Type

Description

Internal router

All interfaces on an internal router belong to the same OSPF area.

Area Border Router (ABR)

An ABR belongs to two or more than two areas, one of which must be the backbone area.

An ABR is used to connect the backbone area and non-backbone areas. It can be physically or logically connected to the backbone area.

Backbone router

At least one interface on a backbone router belongs to the backbone area.

Internal routers in Area 0 and all ABRs are backbone routers.

AS Boundary Router (ASBR)

An ASBR exchanges routing information with another ASs.

An ASBR does not necessarily reside on the border of an AS. It can be an internal router or an ABR. An OSPF device that has imported external routing information will become an ASBR.

Route Types
Inter-area and intra-area routes in an AS describe the AS’s network structure. AS external routes describe the routes to destinations outside an AS. OSPF classifies the imported AS external routes into Type 1 and Type 2 external routes.

Table 1-5 lists route types in descending priority order.

Table 1-5 Route typesRoute Type Description Intra-area route Indicates routes within an area. Inter-area route Indicates routes between areas. Type 1 external route Type 1 external routes have high reliability. Cost of a Type 1 external route = Cost of the route from a local router to an ASBR + Cost of the route from the ASBR to the destination of the Type 1 external route Type 2 external route Type 2 external routes have low reliability, and therefore OSPF considers that the cost of the route from an ASBR to the destination of a Type 2 external route is much greater than the cost of any internal route to the ASBR. Cost of a Type 2 external route = Cost of the route from the ASBR to the destination of the Type 2 external routeArea Types
Table 1-6 Area typesArea Type

Function

Common area

OSPF areas are common areas by default. Common areas include standard areas and backbone areas.

* A standard area is the most common area and transmits intra-area routes, inter-area routes, and external routes.
* A backbone area connects all the other OSPF areas. It is usually named Area 0.

Stub area

A stub area does not advertise AS external routes, but only intra-area and inter-area routes.

Compared with a non-stub area, the Router in a stub area maintains fewer routing entries and transmits less routing information.

To ensure the reachability of AS external routes, the ABR in a stub area advertises Type 3 default routes to the entire stub area. All AS external routes must be advertised by the ABR.

Totally stub area

A totally stub area does not advertise AS external routes or inter-area routes, but only intra-area routes.

Compared with a non-stub area, the Router in a totally stub area maintains fewer routing entries and transmits less routing information.

To ensure the reachability of AS external and inter-area routes, the ABR in a totally stub area advertises Type 3 default routes to the entire totally stub area. All AS external and inter-area routes must be advertised by the ABR.

NSSA

An NSSA can import AS external routes. An ASBR uses Type 7 LSAs to advertise the imported AS external routes to the entire NSSA. These Type 7 LSAs are translated into Type 5 LSAs on an ABR, and are then flooded in the entire OSPF AS.

An NSSA has the characteristics of the stub areas in an AS.

An ABR in an NSSA advertises Type 7 default routes to the entire NSSA. All inter-area routes must be advertised by the ABR.

Totally NSSA

A totally NSSA can import AS external routes. An ASBR uses Type 7 LSAs to advertise the imported AS external routes to the entire NSSA. These Type 7 LSAs are translated into Type 5 LSAs on an ABR, and are then flooded in the entire OSPF AS.

A totally NSSA has the characteristics of the totally stub areas in an AS.

An ABR in a totally NSSA advertises Type 3 and Type 7 default routes to the entire totally NSSA. All inter-area routes must be advertised by the ABR.

OSPF Network Types
Table 1-7 lists four OSPF network types that are classified based on link layer protocols.

Table 1-7 OSPF network typesNetwork Type Description Broadcast A network with the link layer protocol of Ethernet or Fiber Distributed Data Interface (FDDI) is a broadcast network by default. On a broadcast network: * Hello packets, LSU packets, and LSAck packets are usually transmitted in multicast mode. 224.0.0.5 is an IP multicast address reserved for an OSPF device. 224.0.0.6 is an IP multicast address reserved for an OSPF DR or backup designated router (BDR). * DD and LSR packets are transmitted in unicast mode. Non-Broadcast Multi-Access (NBMA) A network with the link layer protocol of frame relay (FR), X.25 is an NBMA network by default. On an NBMA network, protocol packets such as Hello packets, DD packets, LSR packets, LSU packets, and LSAck packets are sent in unicast mode. Point-to-Multipoint (P2MP) No network is a P2MP network by default, no matter what type of link layer protocol is used on the network. A network can be changed to a P2MP network. The common practice is to change a non-fully meshed NBMA network to a P2MP network. On a P2MP network: * Hello packets are transmitted in multicast mode using the multicast address 224.0.0.5. * Other types of protocol packets, such as DD packets, LSR packets, LSU packets, and LSAck packets are sent in unicast mode. Point-to-point (P2P) By default, a network where the link layer protocol is PPP, HDLC, or LAPB is a P2P network. On a P2P network, protocol packets such as Hello packets, DD packets, LSR packets, LSU packets, and LSAck packets are sent in multicast mode using the multicast address 224.0.0.5.DR and BDR
On broadcast or NBMA networks, any two routers need to exchange routing information. As shown in Figure 1-2, n routers are deployed on the network. n x (n – 1)/2 adjacencies must be established. Any route change on a router is transmitted to other routers, which wastes bandwidth resources. OSPF resolves this problem by defining a DR and a backup designated router (BDR). After a DR is elected, all routers send routing information only to the DR. Then the DR broadcasts LSAs. Routers other than the DR and BDR are called DR others. The DR others establish only adjacencies with the DR and BDR and not with each other. This process reduces the number of adjacencies established between routers on broadcast or NBMA networks.

Figure 1-2 Network topologies before and after a DR electionIf the original DR fails, routers must reelect a DR and the routers except the new DR must synchronize routing information to the new DR. This process is lengthy, which may cause incorrect route calculations. A BDR is used to shorten the process. The BDR is a backup for a DR. A BDR is elected together with a DR. The BDR establishes adjacencies with all routers on the network segment and exchanges routing information with them. When the DR fails, the BDR immediately becomes a new DR. The routers need to reelect a new BDR, but this process does not affect route calculations.

The DR priority of a router interface determines its qualification for DR and BDR elections. The router interfaces with their DR priorities greater than 0 are eligible. Each router adds the elected DR to a Hello packet and sends it to other routers on the network segment. When both router interfaces on the same network segment declare that they are DRs, the router interface with a higher DR priority is elected as a DR. If the two router interfaces have the same DR priority, the router interface with a larger router ID is elected as a DR.

Stub Area
Stub areas are specific areas where ABRs do not flood the received AS external routes. In stub areas, Routers maintain fewer routing entries and less routing information.

Configuring a stub area is optional. Not every area can be configured as a stub area. A stub area is usually a non-backbone area with only one ABR and is located at the AS border.

To ensure the reachability of the routes to destinations outside an AS, the ABR in the stub area generates a default route and advertises the route to the non-ABRs in the same stub area.

Note the following points when configuring a stub area:

* The backbone area cannot be configured as a stub area.
* Before configuring an area as a stub area, you must configure stub area attributes on all Routers in the area.
* There should be no ASBR in a stub area, meaning that AS external routes cannot be transmitted in the stub area.
* Virtual connections cannot cross a stub area.

NSSA
NSSAs are a special type of OSPF areas. There are many similarities between an NSSA and a stub area. Both of them do not advertise the external routes received from the other OSPF areas. The difference is that a stub area cannot import AS external routes, whereas an NSSA can import AS external routes and advertise the imported routes to the entire AS.

After an area is configured as an NSSA, an ABR in the NSSA generates a default route and advertises the route to the other Routers in the NSSA. This is to ensure the reachability of the routes to the destinations outside an AS.

Note the following points when configuring an NSSA:

* The backbone area cannot be configured as an NSSA.
* Before configuring an area as an NSSA, you must configure NSSA attributes on all Routers in the area.
* Virtual connections cannot cross an NSSA.

Neighbor State Machine
To exchange routing information on an OSPF network, neighbor routers must establish adjacencies. The differences between neighbor relationships and adjacencies are described as follows:

* Neighbor relationship: After the local router starts, it uses an OSPF interface to send a Hello packet to the remote router. After the remote router receives the packet, it checks whether the parameters carried in the packet are consistent with its own parameters. If the parameters carried in the packet are consistent with its own parameters, the local and remote routers establish a neighbor relationship.
* Adjacency: After the local and remote routers establish a neighbor relationship, they exchange DD packets and LSAs to establish an adjacency.

OSPF has eight state machines: Down, Attempt, Init, 2-way, Exstart, Exchange, Loading, and Full.

* Down: It is in the initial stage of setting up sessions between neighbors. The state machine is Down when a router fails to receive Hello packets from its neighbor before the dead interval expires.
* Attempt: It occurs only on an NBMA network. The state machine is Attempt when a neighbor does not reply with Hello packets before the dead interval has expired. The local router, however, keeps sending Hello packets to the neighbor at every poll interval.
* Init: The state machine is Init after a router receives Hello packets.
* 2-way: The state machine is 2-way when the Hello packets received by a router contain its own router ID. The state machine will remain in the 2-way state if no neighbor relationship is established, and will become Exstart if a neighbor relationship is established.
* Exstart: The state machine is Exstart when the two neighbors start to negotiate the master/slave status and determine the sequence numbers of DD packets.
* Exchange: The state machine is Exchange when a router starts to exchange DD packets with its neighbor after the master/slave status negotiation is completed.
* Loading: The state machine is Loading after a router has finished exchanging DD packets with its neighbor.
* Full: The state machine is Full when the LSA retransmission list is empty.

OSPF Packet Authentication
OSPF supports packet authentication. Only the OSPF packets that have been authenticated can be received. If OSPF packets are not authenticated, a neighbor relationship cannot be established.

The Router supports two authentication methods:

* Area-based authentication
* Interface-based authentication

When both area-based and interface-based authentication methods are configured, interface-based authentication takes effect.

OSPF Route Summarization
Route summarization means that an ABR in an area summarizes the routes with the same prefix into one route and advertises the summarized route to the other areas.

Route summarization between areas reduces the amount of routing information to be transmitted, reducing the size of routing tables and improving device performance.

Route summarization can be carried out by an ABR or an ASBR:

* Route summarization on an ABR:When an ABR in an area advertises routing information to other areas, it generates Type 3 LSAs by network segment. If this area contains consecutive network segments, you can run a command to summarize these network segments into one network segment. The ABR only needs to send one summarized LSA, and will not send the LSAs that belong to the summarized network segment specified in the command.

* Route summarization on an ASBR:If the local device is an ASBR and route summarization is configured, the ASBR will summarize the imported Type 5 LSAs within the aggregated address range. After an NSSA is configured, the ASBR needs to summarize the imported Type 7 LSAs within the aggregated address range. If the local device is an ASBR and ABR, the device will summarize the Type 5 LSAs that are translated from Type 7 LSAs.

OSPF Default Route
A default route is a route of which the destination address and mask are all 0s. If a router cannot find a route in its routing table for forwarding packets, it can forward packets using a default route. Due to hierarchical management of OSPF routes, the priority of default Type 3 routes is higher than the priority of default Type 5 or Type 7 routes.

OSPF default routes are usually used in the following cases:

* An ABR advertises default Type 3 Summary LSAs to instruct routers within an area to forward packets between areas.
* An ASBR advertises default Type 5 ASE LSAs or default Type 7 NSSA LSAs to instruct routers in an AS to forward packets to other ASs.

Principles for advertising OSPF default routes are described below:

* An OSPF router advertises an LSA that describes a default route only when an interface on the OSPF router is connected to a network outside an area.
* If an OSPF router has advertised an LSA carrying information about a type of default route, the OSPF router does not learn this type of default routes advertised by other routers. This means that the OSPF router no longer calculates routes based on the LSAs carrying information about the same type of the default routes advertised by other routers, but stores these LSAs in its LSDB.
* The route on which default external route advertisement depends cannot be a route in the local OSPF AS. This means that the route cannot be the one learned by the local OSPF process. This is because default external routes are used to guide packet forwarding outside an AS, whereas the routes within an AS have the next hop pointing to the devices within the AS.

Table 1-8 lists principles for advertising default routes in different areas.

Table 1-8 Principles for advertising OSPF default routesArea Type Function Common area By default, devices in a common OSPF area do not automatically generate default routes, even if the common OSPF area has default routes. When a default route on the network is generated by another routing process (not OSPF process), the device that generates the default route must advertise the default route in the entire OSPF AS. (Run a command on an ASBR to configure the ASBR to generate a default route. After the configuration, the ASBR generates a default Type 5 ASE LSA and advertises the LSA to the entire OSPF AS.) Stub area A stub area does not allow AS external routes (Type 5 LSAs) to be transmitted within the area. All routers within the stub area must learn AS external routes from the ABR. The ABR automatically generates a default Summary LSA (Type 3 LSA) and advertises it to the entire stub area. Then all routes to destinations outside an AS can be learned from the ABR. Totally stub area A totally stub area does not allow AS external routes (Type 5 LSAs) or inter-area routes (Type 3 LSAs) to be transmitted within the area. All routers within the totally stub area must learn AS external routes and other areas’ routes from the ABR. The ABR automatically generates a default Summary LSA (Type 3 LSA) and advertises it to the entire totally stub area. Then, all routes to destinations outside an AS and to destinations in other areas can be learned from the ABR. NSSA An NSSA allows its ASBRs to import a small number of AS external routes, but does not advertise ASE LSAs (Type 5 LSAs) received from other areas within the NSSA. This means that AS external routes can be learned only from ASBRs in the NSSA. Devices in an NSSA do not automatically generate default routes. Use either of the following methods as required: * To advertise some external routes using the ASBR in the NSSA and advertise other external routes through other areas, configure a default Type 7 LSA on the ABR and advertise this LSA in the entire NSSA. * To advertise all the external routes using the ASBR in the NSSA, configure a default Type 7 LSA on the ASBR and advertise this LSA in the entire NSSA. The difference between these two configurations is described below: * An ABR will generate a default Type 7 LSA regardless of whether the routing table contains the default route 0.0.0.0. * An ASBR will generate a default Type 7 LSA only when the routing table contains the default route 0.0.0.0. A default route is flooded only in the local NSSA and is not flooded in the entire OSPF AS. If Routers in the local NSSA cannot find routes to the outside of the AS, the Routers can forward packets to the outside of the AS through an ASBR. Packets of other OSPF areas, however, cannot be sent to the outside of the AS through this ASBR. Default Type 7 LSAs will not be translated into default Type 5 LSAs and flooded in the entire OSPF AS. Totally NSSA A totally NSSA does not allow AS external routes (Type 5 LSAs) or inter-area routes (Type 3 LSAs) to be transmitted within the area. All Routers within the totally NSSA must learn AS external routes from the ABR. The ABR automatically generates a default Summary LSA and advertises it to the entire totally NSSA. Then all external routes received from other areas and inter-area routes can be advertised within the totally NSSA.OSPF Route Filtering
OSPF supports route filtering using routing policies. By default, OSPF does not filter routes.

Routing policies used by OSPF include the route-policy, access-list, and prefix-list.

OSPF route filtering can be used for:

* Importing routesOSPF can import routes learned by other routing protocols. You can configure routing policies to filter the imported routes to allow OSPF to import only the routes that match specific conditions.

* Advertising imported routesOSPF advertises the imported routes to its neighbors. You can configure filtering rules to filter the routes to be advertised. The filtering rules can be configured only on ASBRs.

* Learning routesFiltering rules can be configured to allow OSPF to filter the received intra-area, inter-area, and AS external routes. After receiving routes, an OSPF device adds only the routes that match the filtering rules to the local routing table, but can still advertise all routes from the OSPF routing table.

* Learning inter-area LSAsYou can run a command to configure an ABR to filter the incoming Summary LSAs. This configuration takes effect only on ABRs because only ABRs can advertise Summary LSAs.

Table 1-9 Differences between inter-area LSA learning and route learningInter-area LSA Learning

Route Learning

Directly filters the incoming LSAs.

Filters the routes that are calculated based on LSAs, but does not filter LSAs. This means that all incoming LSAs are learned.

* Advertising inter-area LSAsYou can run a command to configure an ABR to filter the outgoing Summary LSAs. This configuration takes effect only on ABRs.

OSPF Multi-Process
OSPF supports multi-process. Multiple OSPF processes can run on the same Router, and they are independent of each other. Route exchanges between different OSPF processes are similar to route exchanges between different routing protocols.

Each interface on the Router belongs to only one OSPF process.

A typical application of OSPF multi-process is that OSPF runs between PEs and CEs in a VPN, whereas OSPF is used as an IGP on the backbone of the VPN. Two OSPF processes on the same PE are independent of each other.

OSPF RFC 1583 Compatibility
RFC 1583 is an earlier version of OSPFv2.

When OSPF calculates external routes, routing loops may occur because RFC 2328 and RFC 1583 define different route selection rules. To prevent routing loops, both communication ends must use the same route selection rules.

* After RFC 1583 compatibility is enabled, OSPF uses the route selection rules defined in RFC 1583.
* When RFC 1583 compatibility is disabled, OSPF uses the route selection rules defined in RFC 2328.

OSPF calculates external routes based on Type 5 LSAs. If the router enabled with RFC 1583 compatibility receives a Type 5 LSA:

* The Router selects a route to the ASBR that originates the LSA, or to the forwarding address (FA) described in the LSA.
* The Router selects external routes to the same destination.

By default, OSPF uses the route selection rules defined in RFC 1583.