Static routing cannot make automatic adjustment as the network changes. Meanwhile, in large-scale networks, manually managing routing tables of routers is a daunting task prone to mistakes. Therefore, dynamic routing was created.

In dynamic routing, administrators no longer need to manually maintain the routing tables of routers, but simply run a dynamic routing protocol on each router. Dynamic routing protocols generate and maintain routing tables through the exchange of routing information. When the network topology changes, dynamic routing protocols can automatically update the routing table and determine the optimal path for data transmission.

There are numerous dynamic routing protocols, such as Routing Information Protocol (RIP), Open Shortest Path First (OSPF), Intermediate System to OSPF (Open Shortest Path First), IS-IS (Intermediate System to Intermediate System) and BGP (Border Gateway Protocol). Among them, OSPF has a wide range of application scenarios and is based on link state algorithm.

In this chapter, we first introduce the shortest path first algorithm, then explain the features of OSPF protocol, its working process, message types, related terms, network types supported, designated router (DR), backup designated router (BDR), three tables of OSPF and OSPF area, and finally illustrate the single-area configuration and multi-area configuration of OSPF protocol.

6.1 Classification of Dynamic Routing Protocols

Dynamic routing protocols are capable of building routing tables, maintaining routing information, and selecting the optimal path. They can automatically adapt to changes in network state and maintain routing information without the involvement of network administrators. Due to the need to exchange routing information, dynamic routing protocols consume network bandwidth and system resources, so they are less secure than static routing. Dynamic routing protocols are suitable for complex network environments with redundant connections. In dynamic routing protocols, whether the destination network is reachable depends on the network state.

  1. 1.

    Classification by working mechanism and algorithm

    Dynamic routing protocols can be classified into distance vector routing protocols and link state routing protocols according to their working mechanisms and algorithms.

    1. (a)

      Distance vector routing protocols.

      Distance vector routing protocols use distance vector (DV) algorithm. Each router using distance vector algorithm periodically exchanges the entire routing table with its directly connected neighbors. After the network topology is changed, routers exchange update packets at regular intervals to obtain information about the changes in the network and thus update the routing table.

      The metric of the distance vector routing protocol has low confidence. Distance vector routing protocols use only the number of hops as the basis for selecting the best path, without taking into consideration factors such as the bandwidth and latency of the links between routers. This results in packets being delivered on a link that seems to have a few hop counts but is actually subject to a narrow bandwidth and long latency. The information exchange is achieved by periodically broadcasting the entire routing table. In slightly larger networks, the routing table exchanged between routers can be massive, which generates a lot of traffic, resulting in slow convergence.

      Distance vector routing protocols include RIP, BGP, etc.

    2. (b)

      Link state routing protocols.

      Link state routing protocols use link state (LS) algorithm. Instead of simply learning routes from neighboring routers, routers performing this algorithm divide routers into areas, collect link state information from all routers in the area, and generate network topology based on the link state information, after which each router calculates routes to each network based on the topology.

      Link-state routing protocols include OSPF, IS-IS, etc.

  2. 2.

    Classification by working area

    By working area, dynamic routing protocols can be classified into interior gateway protocols and exterior gateway protocols.

    Large ISP networks may have thousands of routers in their networks, while smaller ones usually have only a dozen routers. Each ISP manages its own intranet, which is called an autonomous system (AS). An AS is a group of networks that exchange routing information with each other through a unified routing protocol. Its connections to other ISPs are called interior connection. Therefore, the Internet can also be seen as an interconnection of domains. The domain mentioned here is an autonomous system.

    1. (a)

      Interior gateway protocols.

      Interior Gateway Protocol (IGP) is a routing protocol responsible for routing within an autonomous system. It is responsible for ensuring that each router in a domain follows the same way of representing routing information and the same rules for publishing and processing information. It is mainly used for discovering and calculating routes.

      Interior gateway protocols include RIP, OSPF, IS-IS, etc.

    2. (b)

      Exterior gateway protocols

      Exterior Gateway Protocol (EGP) is responsible for the interaction of routing information and reachable information between autonomous systems or between domains. It is mainly used for delivering routes.

      Exterior gateway protocols include EGP and BGP. EGP protocol is an early exterior gateway protocol (here EGP is a kind of exterior gateway protocol), which is only used as a standard exterior gateway protocol and is not widely used because it is inefficient. BGP protocol, especially BGP-4, provides a new set of mechanisms to support classless inter-domain routing. BGP-4 also introduces mechanisms to support route aggregation, including aggregation of AS paths, and these changes provide support for supernet solutions.

6.2 Overview of OSPF Protocol

OSPF protocol uses the shortest path first algorithm to calculate the shortest path to each network segment via the link state database. This section will explain the shortest path first algorithm with the help of practical examples, and introduce the advantages of OSPF protocol, its working process, message types, related terms, network types supported, roles of DR and BDR, three tables and OSPF areas.

6.2.1 Introduction to OSPF Protocol

OSPF protocol is a typical link state routing protocol. Routers running OSPF protocol (OSPF routers) interact with each other with link state information instead of directly interacting routes. OSPF routers collect the link state information in the network and store it in the Link State DataBase (LSDB). Routers in the network have the same link state database, that is, the same network topology. Each OSPF router uses the short path first (SPF) algorithm to calculate the shortest path to each network segment and loads the routes formed by these shortest paths into the routing table.

The main advantages of OSPF protocol are as follows.

  1. 1.

    OSPF supports variable length subnet masks (VLSM) and manual route summarization.

  2. 2.

    OSPF protocol can prevent routing loops. Each router uses the shortest path first algorithm through the link state database so that no loops will be generated.

  3. 3.

    OSPF converges quickly and can pass the routing changes throughout the autonomous system in the shortest possible time.

  4. 4.

    OSPF is suitable for large scale networks. The OSPF protocol has no limit on the number of hop counts of the route. Its concept of area division and multi-area design allows OSPF to support large scale networks.

  5. 5.

    Cost is used as the metric. When the OSPF protocol is designed, the impact of link bandwidth on the routing metric is taken into consideration. OSPF protocol uses the cost as a criterion, and the link cost is inversely associated with link bandwidth, that is, the higher the bandwidth, the lower the cost, so that OSPF routing is mainly based on bandwidth.

6.2.2 Routing Tables Generated from the Shortest Path

Routers running OSPF protocol can generate a complete network topology based on the link state database, and all routers have the same network topology. In Fig. 6.1, the network segments connected by the routers and the cost calculated from the bandwidth on each link are marked. To facilitate our calculations, the costs marked are relatively small. To simply the illustration, network segments occupied by the connections between routers are not drawn here and are not involved in the following discussion.

Fig. 6.1
figure 1

Network topology generated from the link state database

Each router uses the shortest path first algorithm to compute a loop-free tree of shortest path with itself as a root. The process of the shortest path first algorithm is not elaborated here, and only the results are shown. Fig. 6.2 displays the shortest path tree of Router RA, i.e., the loop-free path with the lowest cumulative cost to other network segments.

Fig. 6.2
figure 2

Shortest path tree of Router RA

The minimum cumulative cost from Router RA to other network segments is easily known from Fig. 6.2, as follows.

To network segment B: RA→RB, with a cumulative cost of 2.

To network segment C: RA→RB → RC, with a cumulative cost of 7.

To network segment D: RA→RH → RE → RD, with a cumulative cost of 7.

To network segment E: RA→RH → RE, with a cumulative cost of 5.

To network segment F: RA→RB → RG → RF, with a cumulative cost of 6.

To network segment G: RA→RB → RG, with a cumulative cost of 4.

To network segment H: RA→RH, with a cumulative cost of 4.

Figure 6.3 shows the shortest path tree of Router RH, i.e., the loop-free path with the lowest cumulative cost to other network segments.

Fig. 6.3
figure 3

Shortest path tree of Router RH

In order to quickly select a forwarding path for packets, each router also generates routes to each network segment based on the calculated shortest path tree. Figure 6.4 shows the routing table generated by Router RA based on the shortest path tree.

Fig. 6.4
figure 4

Generate a routing table

6.2.3 Related Terms of OSPF Protocol

  1. 1.

    Router-ID.

    Routers running the OSPF protocol in the network are required to have a unique identifier, which is the Router-ID. The Router-ID cannot be duplicated in the network, otherwise the link state received by the router cannot determine the identity of the sender. The link states sent by OSPF routers all carry their own Router-ID. The Router-ID is represented in the form of an IP address. There are three methods to determine the Router-ID.

    • Manually specify the Router-ID.

    • The IP address of the largest active loopback interface of the router, that is, the IP address with the largest number, for example, a Class C address takes precedence over a Class B address. The IP address of an inactive interface cannot be used as the Router-ID.

    • If there is no active loopback interface, the largest IP address of the active physical interface is selected.

      In practical projects, Router-ID is usually assigned to the device by manual configuration. It is commonly done by configuring the Router-ID to match the IP address of an interface (usually the loopback interface) of the device.

  2. 2.

    Metric.

    OSPF uses cost as a metric for routing. Each OSPF-activated interface maintains an interface cost. The default interface cost value= \( \frac{100\ \mathrm{Mbit}/\mathrm{s}}{\mathrm{Interface}\ \mathrm{bandwith}} \), where, 100 Mbit/s is the default reference value specified by OSPF, which is adjustable.

    As can be seen from the formula, OSPF protocol selects the optimal path based on bandwidth, that is, the higher the bandwidth, the lower the calculated cost. The optimal path is the one with the lowest cumulative cost of the links reaching the destination network.

    For example, for an interface with a bandwidth of 10 Mbit/s, to calculate the cost, 10 Mbit is converted to 10000000 bit, and then 100000000 is divided by that bandwidth. The result is 100000000/10000000 = 10, so for a 10 Mbit/s interface, OSPF considers the interface to have a metric of 10. It should be noted that in the calculation, the unit of bandwidth is bit/s instead of kbit/s. For example, for an interface with a bandwidth of 100 Mbit/s, the cost is 100000000/100000000 = 1. The cost must be an integer, so even for an interface with a bandwidth of 1000 Mbit/s (1 Gbit/s), its cost is the same as that of the 100 Mbit/s interface, that is 1. If the router has to go through two interfaces to reach the destination network, then obviously, the costs of the two interfaces have to be accumulated to be the metric for reaching the destination network. Therefore, when the OSPF router calculates the metric for reaching the destination network, it must add up the costs of all the interfaces along the way, and in this process, only the outgoing interfaces are calculated and not the ingoing interfaces. Figure 6.5 illustrates the interface costs and cumulative costs.

    OSPF automatically calculates the cost of the interface, however, it is also possible to manually specify the cost for the interface, and the manually specified one takes precedence over the automatically calculated one.

  3. 3.

    Link.

    A link is an interface of a router, which refers to the interface running under the OSPF process in this case.

  4. 4.

    Link state.

    The link state is the descriptive information of the OSPF interface, such as the interface’s IP address, subnet mask, network type, cost, etc. What is exchanged between OSPF routers is not the routing table, but the link state.

  5. 5.

    Neighbor.

    Routers on the same network segment can become neighbors. Routers discover neighbors through the Hello messages, which are sent at regular intervals by each interface using IP multicast. Once a router finds itself in the Hello message of its neighboring routers, they become neighbors, and such relationship requires the confirmation from both sides of the communication.

  6. 6.

    Neighbor state.

    After the neighboring routers exchange database description, link state request, link state update, and link state acknowledgement messages, the link state databases of the devices at both ends are identical and enter the neighbor state.

Fig. 6.5
figure 5

Interface cost and cumulative cost

6.2.4 OSPF Working Process

A router running the OSPF protocol has three tables, namely, neighbor table, link state table (link state database) and routing table. The following elaborates the working process of OSPF protocol by introducing the process of generating these three tables and analyzing what changes occur in the router during the process.

  1. 1.

    Establish a neighbor table.

    A router in an OSPF area first establishes a neighbor relationship with its neighboring routers. When a router starts working, it sends a Hello packet every 10 s, by which it learns which neighboring routers are working and the “cost” of sending data to them, thus generating a “neighbor table”.

    If a router does not receive a Hello packet from a neighboring router for 40 s, it assumes that the neighboring router is unreachable and the router immediately modifies the link state database and recalculates the routing table.

    Figure 6.6 illustrates the process of routers R1 and R2 establishing a neighbor table by Hello packets. At first, the OSPF state of router R1 interface is “down state”, and after router R1 sends a Hello packet, the state changes to “init state”. When it receives a Hello packet from router R2 and sees its own Router-ID in the neighbor table responded by other routers, a neighbor relationship is established and the state is changed to “two-way state”.

  2. 2.

    Establish a link state table.

    As shown in Fig. 6.6, after establishing the neighbor table, neighboring routers have to exchange link states to establish a link state table. In establishing the link state table, routers have to go through exchange state, loading state, and full state.

    Exchange state: OSPF lets each router exchange the link state summary (description) information already in the database with neighboring routers using the database description packets. The summary information sent contains all the routers (Router-IDs) in its own link state table.

    Loading state: after exchanging database description packets with neighboring routers, the router then uses link-state request packets to request the other side for the detailed information about the link state of certain routers that it lacks. Through this series of packet exchanges, a network-wide synchronized LSDB is established.

    Full state: the synchronization of link state database among neighbors is completed, so that all routers in the network have the same link state database and master the full network topology.

  3. 3.

    Generate a routing table.

    Based on the link state database, each router uses the shortest path first (SPF) algorithm to calculate a loop-free “tree” of shortest path with itself as a root, thus generating route entries to reach the destination network.

Fig. 6.6
figure 6

Working process of OSPF protocol

6.2.5 OSPF Message Types

There are five OSPF message types in total, and Fig. 6.6 identifies the message types used in each phase of the OSPF operation.

Type 1: Hello packets, which are used to discover and maintain neighbors.

Type 2: Database Description (DD) packets, which are used to send summary information to neighbors about all link state entries in their own link state database. The summary information is about all routers (Router-IDs) in the link state table.

Type 3: Link State Request (LSR) packets, which are used to request detailed information from the other party about the missing link state information of a router.

Type 4: Link State Update (LSU) packets, which are used to send detailed link state information. Routers use such packets to inform neighboring routers of their link state. In OSPF, only LSU needs to display an acknowledgement.

Type 5: Link State Acknowledgement (LSAck) packets, which are used to acknowledge the LSU.

6.2.6 Network Types Defined by OSPF

Before explaining the designated router (DR) and backup designated router (BDR), it is necessary to understand the OSPF network types.

The OSPF network type is an imperative interface variable that affects the operation of OSPF on the interface, for example, what method is used to send OSPF protocol messages, and whether the designated router and backup designated router need to be elected. The default OSPF network type for an interface depends on the data link layer encapsulation used by the interface.

OSPF defines four network types, namely, point to point (P2P) network, broadcast multi-access (BMA) network, non-broadcast multiple access (NBMA) network, and point to multiple point (P2MP) network.

In general, the network type of the OSPF interfaces at both ends of the link must be the same, otherwise the neighbor relationship cannot be established between the two. The OSPF network type can be manually modified on the interface via commands to suit different network scenarios. For example, a BMA network can be modified to a P2P network.

[R1-GigabitEthernet0/0/0]ospf network-type ? broadcast Specify OSPF broadcast network nbma Specify OSPF NBMA network p2mp Specify OSPF point-to-multipoint network p2p Specify OSPF point-to-point network

P2P refers to an environment where only two network devices can be connected to a link, as shown in Fig. 6.7a. A typical example is a PPP link. When an interface is encapsulated using PPP, the default network type used by OSPF on that interface is P2P.

Fig. 6.7
figure 7

P2P and broadcast networks

BMA, also known as Broadcast, refers to a broadcast-enabled environment that allows multiple devices to access, as shown in Fig. 6.7b. A typical example is Ethernet. When an interface is encapsulated using Ethernet, the default network type used by OSPF on that interface is BMA.

NBMA refers to a broadcast-disabled environment that allows multiple network devices to access, as shown in Fig. 6.8a. A typical example is frame relay (FR) networks.

Fig. 6.8
figure 8

NBMA and P2MP

P2MP is equivalent to a network obtained by bundling one end of multiple P2P links, as shown in Fig. 6.8b. By default, no link layer protocol is considered a P2MP network. This network type must be configured by changing the other network types into it. It is commonly done by changing a non-fully connected NBMA to a point-to-multipoint network.

6.2.7 DR and BDR

There are two types of multi-access (MA) networks: broadcast multi-access (BMA) and non-broadcast multi-access (NBMA). Ethernet is a typical type of broadcast multi-access network.

In an MA network, if each OSPF router establishes OSPF neighbor relationship with all other routers, there will be too many OSPF neighbor relationships in the network, as shown in Fig. 6.9, which will increase the burden on the devices and the number of OSPF messages flooded in the network. When the topology changes, the LSA flooding in the network may cause waste of bandwidth and loss of equipment resources.

Fig. 6.9
figure 9

Multi-access network neighbor relationship

To optimize the OSPF neighbor relationship in MA networks, OSPF specifies three OSPF router identities: designated router (DR), backup designated router (BDR), and DRother router. The OSPF protocol allows only DR and BDR to establish neighbor relationship with DRother, and no neighbor relationship is established between DRother routers, so both parties are stalled in the “two-way” state.

The BDR will monitor the state of DR and take over the role of the current DR in case of its failure.

DR and BDR election rules: DR and BDR are elected by all routers in the same network segment according to the router preference and Router-ID through Hello messages. Only routers with preference greater than 0 are eligible for the election. To conduct DR/BDR election, each router writes the DR it elects in the Hello message and sends it to the router running OSPF protocol on the network segment. When two routers in the same network segment declare themselves as the DR at the same time, the router with higher preference wins. If the preferences are equal, the one with larger Router-ID wins. If a router has a preference of 0, it will not be elected as DR or BDR.

It should be noted that the DR is elected only on broadcast or NBMA interfaces, not on point to point or point to multipoint interfaces. DR is a concept in a particular network segment and is specific to a router’s interface. A router may be a DR on one interface and a BDR or a DRother on another interface. The preference of a router can affect an election process, but when a DR/BDR has been elected, even if a router with a higher preference becomes active, it will not replace the DR/BDR already elected in that network segment as the new DR/BDR. A DR is not necessarily the router interface with the highest router preference; and similarly, the BDR is not necessarily the router interface with the next highest router preference.

This design means to make the DR or BDR the center of information exchange, as shown in Fig. 6.10, instead of enabling every router to exchange updated information with other routers on that network segment in pairs. Routers first exchange update information with the DR and BDR, and then the DR forwards these updates to the other routers on that network segment.

Fig. 6.10
figure 10

Neighbor relationship

From Fig. 6.10, we can see that neighbors do not necessarily share a neighbor relationship. R3 has four neighbors, but only forms neighbor relationships with R1 and R2. Routers in point to point networks always form neighbor relationships with their neighbors, as shown in Fig. 6.11. If two routers are directly connected via Ethernet interfaces, you can manually designate the Ethernet interfaces of these two routers as P2P interfaces so that there will be no DR and BDR election.

Fig. 6.11
figure 11

P2P Neighbor relationship

6.2.8 Three Tables of OSPF

OSPF has three important tables: the OSPF neighbor table, LSDB table, and OSPF routing table.

OSPF requires neighbor relationships to be established before link state information can be passed. The neighbor relationship is established by exchanging Hello messages. OSPF neighbor table shows the neighbor states between OSPF routers, and the neighbor table can be viewed by the display ospf peer command.

Routers running the link state routing protocol flood the network with link state information. In OSPF, this information is called LSA, and the LSDB stores the LSA information it generated by itself and received from its neighbors, so the LSDB can be seen as the router’s complete understanding of the network. The command to view the LSDB of a device on a Huawei device is display ospf lsdb.

Based on the data in the LSDB, OSPF runs the SPF algorithm and obtains a loop-free tree of shortest path with itself as a root. Based on this tree, OSPF is able to discover the optimal path to each segment in the network to get routing information and load it into the OSPF routing table. Of course, whether these routes in the OSPF routing table will eventually be loaded to the global routing table is subject to further processes such as comparing route preferences. The command to view the OSPF routing table of the device on a Huawei device is display ospf routing.

6.2.9 OSPF Areas

To enable OSPF to be used in very large-scale networks, OSPF subdivides an autonomous system into a number of smaller ones called areas. The advantage of areas is that the scope of the flooding method for exchanging link state information can be controlled within an area instead of the entire autonomous system, which reduces the amount of traffic throughout the network, decreases the size of the LSDB, improves the scalability of the network, and enables fast convergence. Routers within an area only need to know the complete network topology of this area and not the network topology of other areas. To enable an area to communicate with other areas, OSPF uses a hierarchical division of areas.

When a network contains multiple areas, the OSPF protocol has a special rule that one of the areas must be Area 0, which is commonly called a backbone area. A desirable way to design an OSPF network is to start with the backbone area and then expand to other areas. The backbone area is at the center of all other areas, i.e., all areas must be physically or logically connected to the backbone area. The reason for this design is because the OSPF protocol has to bring routing information from all areas into the backbone area, and then distribute such information from the backbone area to non-backbone areas.

Figure 6.12 illustrates an autonomous system with three areas. Each area has a 32-bit area identifier (expressed in dotted decimal). The size of an area should not be too large, and it is suggested to keep the number of routers in the area under 200.

Fig. 6.12
figure 12

Autonomous system and OSPF areas

As shown in Fig. 6.12, multi-area division is used in combination with IP address planning to ensure a contiguous address space of an area so that the network in the area can be summarized into a single route on the area boundary router and advertised to other areas.

As shown in Fig. 6.12, the upper layer area is called the backbone area, whose identifier is specified as 0.0.0.0. The role of the backbone area is to connect other lower layer areas. The information sent from other areas will go through route summarization by area border routers (ABRs). Router R4 and R5 are both area border routers. Obviously, each area should have at least one area border router. A router within the backbone area is called a backbone router, such as R1, R2, R3, R4, and R5. Backbone routers can also be area border routers, such as R4 and R5. There is also a router within the backbone area (R3 in Fig. 6.12) that is dedicated to exchanging routing information with other autonomous systems. Such a router is called an autonomous system boundary router (ASBR).

It should be noted that ABR is connected to the backbone area and non-backbone area, and ASBR is connected other ASs.

6.3 Configuration of OSPF Protocol

Small and medium enterprise have small networks and a limited number of routing devices, so they can consider putting all devices in the same OSPF area. Large enterprises have large-scale networks, with a lot of router devices and a distinct network hierarchy, so it is recommended to use OSPF multi-area method.

6.3.1 Single-Area Configuration of OSPF Protocol

When referring to Fig. 6.13 to set up the network environment, routers and computers in the network are connected and configured with interface IP addresses according to the topology in the figure. The following operation configures these routers to run the OSPF protocol, and configures them to be in a single area. Although there is only one area, that area can only be the backbone area, with the area number of 0.0.0.0, which can also be written as 0.

Fig. 6.13
figure 13

Configure network topology for OSPF protocol

After entering the OSPF view, you need to specify the interfaces running OSPF protocol and the areas where these interfaces are located according to the network planning. First, you need to execute the area area-id command in the OSPF view. The command is used to create an area and enter the area view. Then, in the area view, execute the network address wildcard-mask command, which is used to specify the area interfaces running the OSPF.

The configuration on router R1 is as follows.

[R1]display router id                         --Display current router ID RouterID:172.16.1.1         [R1]ospf 1 router-id 1.1.1.1                  --Enable ospf 1 process and specify Router-ID used [R1-ospf-1]area 0.0.0.0                       --Enter area 0.0.0.0 [R1-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255   --Specify the interface working in Area 0 [R1-ospf-1-area-0.0.0.0]quit

Relevant explanations are as follows.

  1. 1.

    The [R1]ospf 1 router-id 1.1.1.1 command enables the OSPF process on the router. The number “1” after “ospf” is the number assigned to the process. The range of the number is between 1 to 65,535.

  2. 2.

    If Router-ID is not specified when OSPF protocol is enabled, the Router-ID specified by the router-id command is used. The following command is used to specify the Router-ID.

[R1]router-id 1.1.1.1

  1. 3.

    [R1-ospf-1]area 0.0.0.0: this is a field used to indicate the area in the OSPF protocol packet, accounting for four bytes, which is exactly the space occupied by an IPv4 address. Therefore, when configuring it, you can directly write the number, or you can use dotted decimal to indicate the area of the specified ospf 1 process. Area 0 can be written as 0.0.0.0, and Area 1 can be written as 0.0.0.1.

  2. 4.

    The command to declare the network segment of OSPF is network + IP + wildcard-mask, which filters a set of IP addresses by IP and wildcard-mask so as to locate the range of interfaces that need to be enabled with OSPF (interfaces with IP addresses in this range will be enabled with OSPF).

Wildcard masks are used to limit the number of host bits, i.e., the number of host bits is represented by a consecutive “1” from right to left, which cannot be interrupted by 0.

If you enter “[R1-ospf-1-area-0.0.0.0] network 172.16.0.0 0.0.255.255” when configuring OSPF, it means that the IP address set contains 172.16.0.0 to 172.16.255.255. This address set contains all interfaces of router R1.

If you want to write the wildcard mask after “network” for the network segment where each interface is located, you have to write three entries, which makes the address set identified more accurate. If different interfaces are in different areas, each of them should be specifically configured. In this example, three entries should be written for router R1 if “network” is written for the network segment where each interface is located, as shown below.

[R1-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.255 [R1-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.0.3 [R1-ospf-1-area-0.0.0.0]network 172.16.0.16 0.0.0.3

The configuration on router R2 is as follows.

[R2]ospf 1 router-id 2.2.2.2 [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255 --Specify the interface working in Area 0 [R2-ospf-1-area-0.0.0.0]quit                                              

The configuration on router R3 is as follows.

[R3]ospf 1 router-id 3.3.3.3 [R3-ospf-1]area 0 [R3-ospf-1-area-0.0.0.0]network 172.16.0.6 0.0.0.0   --Followed by the interface address, and the wildcard mask is 0.0.0.0 [R3-ospf-1-area-0.0.0.0]network 172.16.0.9 0.0.0.0   [R3-ospf-1-area-0.0.0.0]network 172.16.2.1 0.0.0.0  

You can also write the address of the interface after “network”, and the wildcard mask should be written as 0.0.0.0. In this way, once the IP address of the interface is changed, you have to reconfigure the interface covered by OSPF.

The configuration on router R4 is as follows.

[R4]ospf 1 router-id 4.4.4.4 [R4-ospf-1]area 0 [R4-ospf-1-area-0.0.0.0]network 172.16.0.16 0.0.0.3       [R4-ospf-1-area-0.0.0.0]network 172.16.0.12 0.0.0.3         [R4-ospf-1-area-0.0.0.0]quit

The configuration on router R5 is as follows.

[R5-ospf-1]area 0 [R5-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255 --This writing covers all addresses

Display the interfaces running the OSPF protocol on R1.

[R1]display ospf interface OSPF Process 1 with Router ID 1.1.1.1 Interfaces Area: 0.0.0.0 (MPLS TE not enabled) IP Address Type State Cost Pri DR BDR 172.16.1.1 Broadcast Waiting 1 1 0.0.0.0 0.0.0.0 172.16.0.1 P2P P-2-P 48 1 0.0.0.0 0.0.0.0 172.16.0.17 P2P P-2-P 48 1 0.0.0.0 0.0.0.0

Routers running OSPF are divided into roles such as autonomous system boundary router, and area border router. Routers of different roles generate different types of LSAs. There are five types of LSAs.

Type 1 LSAs is called router-LSA and is generated by all routers. A router within an area generates one LSA1 for that area. In other words, if a device is connected to multiple areas, it generates one LSA for each area. Type 1 LSAs are sent as floods, and the boundary of the flood is the ABR.

Type 2 LSA is called network-LSA and is generated by the DR in the area. In each MA network the DR generates a LSA2 for that network, and no Type 2 LSAs are generated in P2P networks.

Type 3 LSA is called network-summary-LSA and is generated by ABR only. Since ABR is connected to multiple areas, it will receive LSA1 and LSA2 from different regions at the same time, and ABR converts these LSAs into LSA3 for delivery in areas after calculation.

Type 4 LSA is called autonomous system boundary summary LSA (ASBR-Summary-LSA), and it will not be introduced in detail here.

Type 5 LSA is called AS-External-LSA, and it is not explained here.

By entering “display ospf lsdb router x.x.x.x”, you can view the Type 1 LSAs generated by routers with Router-ID “x.x.x.x”. Type 1 LSAs “introduce themselves” in the areas they are connected to: which of my links are OSPF enabled; with whom I have established OSPF neighbor relationship; how I am connected to my neighbors; and what the network segment is between me and my neighbors.

[R1]display ospf lsdb router 1.1.1.1 OSPF Process 1 with Router ID 1.1.1.1 Area: 0.0.0.0 Link State Database Type : Router --The type is router Ls id : 1.1.1.1 Adv rtr : 1.1.1.1 Ls age : 72 Len : 84 Options : E seq# : 80000004 chksum : 0x83e1 Link count: 5 * Link ID: 172.16.1.0 --Connect network segment 172.16.1.0/24, and the cost is 1 Data : 255.255.255.0 Link Type: StubNet Metric : 1 Priority : Low * Link ID: 2.2.2.2 --Point-to-point connection with router whose router-id is 2.2.2.2, and the cost is 48 Data : 172.16.0.1 Link Type: P-2-P Metric : 48 * Link ID: 172.16.0.0 -- Connect network segment 172.16.1.0/24, and the cost is 48 Data : 255.255.255.252 Link Type: StubNet Metric : 48 Priority : Low * Link ID: 4.4.4.4 -- Point to point connection with router whose router-id is 4.4.4.4, and the cost is 48 Data : 172.16.0.17 Link Type: P-2-P Metric : 48 * Link ID: 172.16.0.16 -- Connect network segment 172.16.0.16/30, and the cost is 48 Data : 255.255.255.252 Link Type: StubNet Metric : 48 Priority : Low

6.3.2 Multi-area Configuration of OSPF Protocol

Referring to Fig. 6.14 to build the network environment, the routers in the network are connected according to the topology in the figure, and the interface IP addresses are configured according to the planned network segment. The routers in the network are divided into three areas, as the network in Area 0 is assigned the address block 40.0.0.0/16, the network in Area 1 40.1.0.0/16, and the network in Area 2 40.2.0.0/16. The routers in these three areas are configured to run the OSPF protocol to build routing tables and perform route summarization at the area border routers.

Fig. 6.14
figure 14

Multi-area OSPF network topology

As you can see in Fig. 6.14, OSPF areas and IP address planning are related, and it is best to have consecutive addresses in an area, which makes it convenient for route summarization at the area borders.

The following is the configuration on router R1, the backbone area router.

<R1>system [R1]ospf 1 router-id 1.1.1.1                   --Enable ospf 1 process and specify the router-ID used [R1-ospf-1]area 0.0.0.0                        --Create area and enter area 0. 0. 0. 0 [R1-ospf-1-area-0.0.0.0]network 40.0.0.0 0.0.255.255 --Specify the address range working in Area 0 [R1-ospf-1-area-0.0.0.0]quit

The following is the configuration on router R2, an area border router, to specify the interfaces working in Area 0 and Area 1.

[R2]ospf 1 router-id 2.2.2.2 [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]network 40.0.0.0 0.0.255.255 -- Specify the interface working in Area 0 [R2-ospf-1-area-0.0.0.0]quit     [R2-ospf-1]area 0.0.0.1 [R2-ospf-1-area-0.0.0.1]network 40.1.0.0 0.0.255.255 -- Specify the interface working in Area 1 [R2-ospf-1-area-0.0.0.1]quit [R2-ospf-1]display this --Follow OSPF 1 configuration [V200R003C00] # ospf 1 router-id 2.2.2.2 area 0.0.0.0 network 40.0.0.0 0.0.255.255 area 0.0.0.1 network 40.1.0.0 0.0.255.255 # return                                          

The following is the configuration on router R3.

[R3]ospf 1 router-id 3.3.3.3 [R3-ospf-1]area 0.0.0.0 [R3-ospf-1-area-0.0.0.0]network 40.0.0.0 0.0.255.255 [R3-ospf-1-area-0.0.0.0]quit [R3-ospf-1]area 0.0.0.2 [R3-ospf-1-area-0.0.0.2]network 40.2.0.1 0.0.0.0 --Write the interface address,and the wildcard-mask is 0. 0. 0. 0 [R3-ospf-1-area-0.0.0.2]network 40.2.1.1 0.0.0.0 --Write the interface address,and the wildcard-mask is 0. 0. 0. 0 [R3-ospf-1-area-0.0.0.2]quit

The following is the configuration on router R4.

[R4]ospf 1 router-id 4.4.4.4 [R4-ospf-1]area 1 [R4-ospf-1-area-0.0.0.1]net [R4-ospf-1-area-0.0.0.1]network 40.1.0.0 0.0.255.255 [R4-ospf-1-area-0.0.0.1]quit

The following is the configuration on router R5.

[R5]ospf 1 router-id 5.5.5.5 [R5-ospf-1]area 1 [R5-ospf-1-area-0.0.0.1]network 40.1.0.0 0.0.255.255 [R5-ospf-1-area-0.0.0.1]quit

The following is the configuration on router R6.

[R6]ospf 1 router-id 6.6.6.6 [R6-ospf-1]area 2 [R6-ospf-1-area-0.0.0.2]network 40.2.0.0 0.0.255.255 [R6-ospf-1-area-0.0.0.2]quit

The following is the configuration on router R7.

[R7]ospf 1 router-id 7.7.7.7 [R7-ospf-1]area 2 [R7-ospf-1-area-0.0.0.2]network 40.2.0.0 0.0.255.255 [R7-ospf-1-area-0.0.0.2]quit

6.3.3 View the Three Tables of the OSPF Protocol

A router running the OSPF protocol has three tables: the neighbor table, link state table, and routing table. These three tables are displayed below.

  1. 1.

    Check the neighbor table of router R1. By entering “display ospf peer” in system view, you can view the information of neighboring routers, and by entering “display ospf peer brief”, the brief of neighboring routers is displayed.

    <R1>display ospf peer brief         --Display the brief of neighboring router OSPF Process 1 with Router ID 1.1.1.1 Peer Statistic Information ---------------------------------------------------------------------------- Area Id Interface Neighbor id State 0.0.0.0 Serial2/0/0 2.2.2.2 Full 0.0.0.0 Serial2/0/1 3.3.3.3 Full ---------------------------------------------------------------------------- <R1>display ospf peer                --Display detailed information of neighboring routers

    When the router and its neighbors are in the full state, the link state databases of all routers are synchronized.

  2. 2.

    Display the link state table. The display ospf lsdb command is used to display how many routers in the link state table have advertised their link state. The router that has advertised the link state is AdvRouter.

    <R1>display ospf lsdb OSPF Process 1 with Router ID 1.1.1.1 Link State Database Area: 0.0.0.0 Type LinkState ID AdvRouter Age Len Sequence Metric Router 2.2.2.2 2.2.2.2 1260 48 80000011 48 Router 1.1.1.1 1.1.1.1 1218 84 80000013 1 Router 3.3.3.3 3.3.3.3 1253 48 80000010 48 Sum-Net 40.1.3.0 2.2.2.2 301 28 80000001 49 Sum-Net 40.1.2.0 2.2.2.2 221 28 80000001 49 Sum-Net 40.1.1.0 2.2.2.2 932 28 80000001 48 Sum-Net 40.1.0.255 2.2.2.2 932 28 80000001 48 Sum-Net 40.2.3.0 3.3.3.3 856 28 80000001 49 Sum-Net 40.2.2.0 3.3.3.3 856 28 80000001 49 Sum-Net 40.2.1.0 3.3.3.3 856 28 80000001 48 Sum-Net 40.2.0.255 3.3.3.3 856 28 80000001 48

    From the above output, we can see that subnet information for Area 1 and Area 2 appears in the link state database of the backbone area router R1. This subnet information is advertised to the backbone area by the area border router. If route summarization is configured on the area border router, Area 1 and Area 2 are summarized into one link state.

    OSPF calculates the shortest path based on the link state database. The link state database records which routers are running OSPF, how many subnets each router is connected to, which neighbors each router has, and over what link (point to point link or Ethernet link) they are connected.

  3. 3.

    Enter “display ip routing-table” to view the routing table. Proto is the route learned through the OSPF protocol, and its OSPF protocol preference (i.e., Pre) is 10, and the cost is the cumulative cost to reach the destination network segment calculated using bandwidth.

    <R1>display ip routing-table protocol ospf --View OSPF route Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 8 Routes : 8 OSPF routing table status : <Active> Destinations : 8 Routes : 8 Destination/Mask Proto Pre Cost Flags NextHop Interface 40.1.0.0/24 OSPF 10 96 D 40.0.1.2 Serial2/0/0 40.1.1.0/24 OSPF 10 96 D 40.0.1.2 Serial2/0/0 40.1.2.0/24 OSPF 10 97 D 40.0.1.2 Serial2/0/0 40.1.3.0/24 OSPF 10 97 D 40.0.1.2 Serial2/0/0 40.2.0.0/24 OSPF 10 96 D 40.0.2.2 Serial2/0/1 40.2.1.0/24 OSPF 10 96 D 40.0.2.2 Serial2/0/1 40.2.2.0/24 OSPF 10 97 D 40.0.2.2 Serial2/0/1 40.2.3.0/24 OSPF 10 97 D 40.0.2.2 Serial2/0/1 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0

    When entering “display ospf routing”, only the routes generated by the OSPF protocol are displayed, and you can see the ID of the advertiser, that is AdvRouter. As you can see from the output below, the default cost is 1 for directly connected Ethernet interfaces and 48 for directly connected serial interfaces.

<R1>display ospf routing OSPF Process 1 with Router ID 1.1.1.1 Routing Tables Routing for Network Destination Cost Type NextHop AdvRouter Area 40.0.0.0/24 1 Stub 40.0.0.1 1.1.1.1 0.0.0.0 --Default cost of the directly connected Ethernet interface 40.0.1.0/24 48 Stub 40.0.1.1 1.1.1.1 0.0.0.0 --Default cost of the directly connected serial interface 40.0.2.0/24 48 Stub 40.0.2.1 1.1.1.1 0.0.0.0 40.1.0.0/24 96 Inter-area 40.0.1.2 2.2.2.2 0.0.0.0 40.1.1.0/24 96 Inter-area 40.0.1.2 2.2.2.2 0.0.0.0 40.1.2.0/24 97 Inter-area 40.0.1.2 2.2.2.2 0.0.0.0 40.1.3.0/24 97 Inter-area 40.0.1.2 2.2.2.2 0.0.0.0 40.2.0.0/24 96 Inter-area 40.0.2.2 3.3.3.3 0.0.0.0 40.2.1.0/24 96 Inter-area 40.0.2.2 3.3.3.3 0.0.0.0 40.2.2.0/24 97 Inter-area 40.0.2.2 3.3.3.3 0.0.0.0 40.2.3.0/24 97 Inter-area 40.0.2.2 3.3.3.3 0.0.0.0 Total Nets: 11 Intra Area: 3 Inter Area: 8 ASE: 0 NSSA: 0

6.3.4 Route Summarization on the Area Border Router

  1. 1.

    Perform summarization on the area border router R2. Summarize Area 1 as “40.1.0.0 255.255.0.0” and specify the cost as 10; summarize Area 0 as “40.0.0.0 255.255.0.0” and specify the cost as 10.

[R2]ospf 1 [R2-ospf-1]area 1 [R2-ospf-1-area-0.0.0.1]abr-summary 40.1.0.0 255.255.0.0 cost 10 [R2-ospf-1-area-0.0.0.1]quit [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]abr-summary 40.0.0.0 255.255.0.0 cost 10 [R2-ospf-1-area-0.0.0.0]quit

  1. 2.

    Perform summarization on the area border router R3. Summarize Area 2 as “40.2.0.0 255.255.0.0” and specify the cost as 20; summarize Area 0 as “40.0.0.0 255.255.0.0” and specify the cost as 10.

[R3]ospf 1 [R3-ospf-1]area 0 [R3-ospf-1-area-0.0.0.0]abr-summary 40.0.0.0 255.255.0.0 cost 10 [R3-ospf-1-area-0.0.0.0]quit [R3-ospf-1]area 2 [R3-ospf-1-area-0.0.0.2]abr-summary 40.2.0.0 255.255.0.0 cost 20 [R3-ospf-1-area-0.0.0.2]quit [R3-ospf-1]quit

  1. 3.

    After configuring summarization on the area border router, by checking the OSPF link state on R1, you can see that there is only one record about Area 1 and Area 2 in R1’s link state database.

<R1>display ospf lsdb OSPF Process 1 with Router ID 1.1.1.1 Link State Database Area: 0.0.0.0 Type LinkState ID AdvRouter Age Len Sequence Metric Router 2.2.2.2 2.2.2.2 1732 48 80000011 48 Router 1.1.1.1 1.1.1.1 1690 84 80000013 1 Router 3.3.3.3 3.3.3.3 1725 48 80000010 48 Sum-Net 40.1.0.0 2.2.2.2 99 28 80000001 10 Sum-Net 40.2.0.0 3.3.3.3 26 28 80000001 20

  1. 4.

    Display the routes generated by the OSPF protocol on R1. You can see that Area 1 and Area 2 are summarized into one route with a cost of 58 and 68 respectively, which is related to the cost specified during summarization.

<R1>display ospf routing OSPF Process 1 with Router ID 1.1.1.1 Routing Tables Routing for Network Destination Cost Type NextHop AdvRouter Area 40.0.0.0/24 1 Stub 40.0.0.1 1.1.1.1 0.0.0.0 40.0.1.0/24 48 Stub 40.0.1.1 1.1.1.1 0.0.0.0 40.0.2.0/24 48 Stub 40.0.2.1 1.1.1.1 0.0.0.0 40.1.0.0/16 58 Inter-area 40.0.1.2 2.2.2.2 0.0.0.0 40.2.0.0/16 68 Inter-area 40.0.2.2 3.3.3.3 0.0.0.0 Total Nets: 5 Intra Area: 3 Inter Area: 2 ASE: 0 NSSA: 0

6.4 Exercises

  1. 1.

    Which of the following descriptions of the OSPF protocol is the most accurate one ( )?

    1. A.

      OSPF protocol calculates the optimal route based on the link state method

    2. B.

      OSPF protocol is an exterior gateway protocol used between autonomous systems

    3. C.

      OSPF protocol cannot dynamically change the route according to the network communication

    4. D.

      OSPF protocol is only suitable for small networks

  2. 2.

    Which of the following descriptions of the OSPF protocol is incorrect ( )?

    1. A.

      OSPF is a link-state protocol

    2. B.

      OSPF uses link-state advertisements to spread routing information

    3. C.

      In a OSPF network, Area 1 is used to represent the backbone network segment

    4. D.

      Multiple routing processes can be configured in OSPF routers

  3. 3.

    OSPF supports multiple processes, if you don’t specify the process number, the default process number used is ( ).

    1. A.

      0

    2. B.

      1

    3. C.

      10

    4. D.

      100

  4. 4.

    Router AR2200 learns the route entries to the same network via OSPF and RIPv2 at the same time; the cost value of the route learned through OSPF is 4882, and the hop count of the route learned through RIPv2 is 4, then the router will have ( ) in its routing table.

    1. A.

      RIPv2 route

    2. B.

      OSPF and RIPv2 routes

    3. C.

      OSPF route

    4. D.

      Neither of them

  5. 5.

    As shown in Fig. 6.15, OSPF protocol is configured for the routers in the network, and the following configurations are performed on routers A and B.

    [A]ospf 1 router-id 1.1.1.1 [A-ospf-1]area 0.0.0.0 [A-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255 [A-ospf-1-area-0.0.0.0]network 192.168.0.0 0.0.0.255 [B]ospf 1 router-id 1.1.1.2 [B-ospf-1]area 0.0.0.0 [B-ospf-1-area-0.0.0.0]network 192.168.0.0 0.0.255.255

    Which of the following statements is incorrect? ( )

    1. A.

      Router B can learn the route to network segment 172.16.0.0/24 through the OSPF protocol

    2. B.

      Router B can learn the route to network segment 192.168.1.0/24 through the OSPF protocol

    3. C.

      Router A can learn the route to network segment 192.168.2.0/24 through the OSPF protocol

    4. D.

      Router A can learn the route to network segment 192.168.3.0/24 through the OSPF protocol

  6. 6.

    (Multi-selection) To configure OSPF on a router, the configurations must be done manually are ( ).

    1. A.

      Configure Router-ID

    2. B.

      Open OSPF process

    3. C.

      Create OSPF areas

    4. D.

      Specify the network segments contained in each area

  7. 7.

    On the VRP platform, the default protocol preferences of direct routes, static routes, RIP, and OSPF, in descending order, are ( ).

    1. A.

      Direct routes, static routes, RIP, OSPF

    2. B.

      Direct routes, OSPF, static routes, RIP

    3. C.

      Direct routes, OSPF, RIP, static routes

    4. D.

      Direct routes, RIP, static routes, OSPF

  8. 8.

    The administrator configures OSPF on a router, but no loopback interface is configured on that router. Which of the following descriptions of Router-ID is correct ( )?

    1. A.

      The minimum IP address of the physical interface of the router will become the Router-ID

    2. B.

      The maximum IP address of the physical interface of the router will become the Router-ID

    3. C.

      The IP address of the router’s management interface will become the Router-ID

    4. D.

      The preference of the router will become the Router-ID

  9. 9.

    Which of the following descriptions of Router-ID in OSPF is correct ( )?

    1. A.

      Router-ID must be the same in the same area, while that in different areas can be different

    2. B.

      Router-ID must be the IP address of a router interface

    3. C.

      Router-ID must be specified by manual configuration

    4. D.

      The prerequisite for the OSPF protocol to work properly is that the router has a Router-ID

  10. 10.

    A router learns a route to the same destination address through RIP, OSPF, and static routing. By default, the VRP will eventually select the route learned through which protocol? ( )

    1. A.

      RIP

    2. B.

      OSPF

    3. C.

      RIP

    4. D.

      Static routing

  11. 11.

    (Multi-selection) Assume the configuration is like below.

    [R1]ospf [R1-ospf-1]area 1 [R1-ospf-1-area-0.0.0.1]network 10.0.12.0 0.0.0.255

    The administrator has configured OSPF on router R1, but R1 cannot learn routes from other routers, so the possible reasons are ( ).

    1. A.

      The area ID configured on this router is different from the area ID of its neighboring router

    2. B.

      This router is not configured for authentication, but the neighboring routers are configured for authentication

    3. C.

      This router is not configured with OSPF process number when it is configured

    4. D.

      This router is configured with OSPF without advertising the neighbor’s network

Fig. 6.15
figure 15

Network topology