03 OSPF Basics
03 OSPF Basics
Page 1 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Foreword
• Routers forward data packets based on routing tables. Routing entries can be manually configured or generated using
dynamic routing protocols.
• Compared with dynamic routes, static routes use less bandwidth and do not utilize CPU resources for route
calculation and update analysis. Static routes alone can implement interworking for simple networks. If a network
fault occurs or the topology changes, static routes cannot be automatically updated and must be manually
reconfigured to adapt to the network change.
• Compared with static routes, dynamic routing protocols have higher scalability and better adaptability.
• The Open Shortest Path First (OSPF), as an Interior Gateway Protocol (IGP), is widely used because it features high
scalability and fast convergence.
• This course describes basic OSPF concepts, OSPF adjacency establishment, and basic OSPF configurations.
Page 2 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Objectives
• On completion of this course, you will be able to:
▫ Describe the overall process of OSPF route calculation.
Page 3 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
4. Basic OSPF Configurations
Page 4 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Classification of Dynamic Routing Protocols
By ASs
Page 5 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Distance-Vector Routing Protocol
• A router running a distance-vector routing protocol periodically floods its routing table. Through route exchange,
each router learns routes from neighboring routers, loads the routes to its routing table, and then advertises the routes
to other neighboring routers.
• All routers on a network do not know the network topology. They only know the direction to a destination network
segment and the cost.
10.0.3.3
R1 R2 R3
To reach the device at 10.0.3.3,
pass through R2.
Page 6 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Link State Routing Protocol: LSA Flooding
• A link-state routing protocol advertises the link state but not routing information.
• Routers running link-state routing protocols establish neighbor relationships and then exchange Link State
Advertisements (LSAs).
R1 1 00 M R3
M 0
100
LSA LSA
R4
OSPF
Page 7 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Link State Routing Protocol: LSDB Maintenance
Each router generates LSAs and adds the received LSAs to its own link state database (LSDB). Routers parse the LSAs
stored in their LSDBs to obtain the network topology.
LSDB
• Routers use LSDBs to store LSAs.
• An LSDB usually stores various types of
LSA LSA LSAs, and each type of LSA describes
LSD R2 1.54 LSD different information.
4M
B 1 00M B
R1 1 00 M R3
M 0
100
LSDB
LSA LSA
R4
OSPF
Page 8 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Link State Routing Protocol: SPF Calculation
Each router uses the Shortest Path First (SPF) algorithm to calculate routes based on the LSDB. Each router calculates a
loop-free tree with itself as the root and the shortest path. With the tree, the router knows the optimal paths to all network
segments.
LSDB
Each router calculates a loop-free tree with itself
as the root and the shortest path.
LSD R2 1.54 LSD
4M
B 1 00M B
2
R1 1 00 M R3
M 0
100
LSDB
3 1
R4 4
OSPF
Page 9 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Link State Routing Protocol: Routing Table
Generation
A router installs the calculated optimal path to its routing table.
R1 1 00 M R3
M 0
100
R4
Routing
LSDB table OSPF
Page 10 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Summary of Link State Routing Protocols
Establish a neighbor LSDB Exchange link state LSDB
relationship information
R1 R2 R1 R2
e
Ex
n t
Es
io ta
r
at k s
ta c
p o
h
hi hb
bl
i n an g
rm i n
ish
ns i g
fo e l
re fo e l
tio ne
la
i n an g
tio a ne rm i n
la a
at k s
ch
re l i s h
ns ig io ta
Ex
hi hb
b
p or n te
ta
Es
R3 R3
1 2 LSDB
1 2
Page 11 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
4. Basic OSPF Configurations
Page 12 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Overview of OSPF
• OSPF, defined by the Internet Engineering Task Force (IETF), is an IGP based on the link state. OSPF
version 2 (OSPFv2), defined in RFC 2328, is intended for IPv4, and OSPF version 3 (OSPFv3)), defined
in RFC 2740, is intended for IPv6.
Page 13 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Application Scenarios
Core layer
buildings.
Area 0
▫ The core and aggregation layers are deployed in the
OSPF backbone area.
Aggregation layer
▫ The access and aggregation layers are deployed in
Access layer …
Page 14 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Router ID Area Metric
▫ If the router ID is not manually configured, a router uses the largest IP address of a loopback interface as the router ID.
▫ If no loopback interface is configured, the router uses the largest IP address of a physical interface as the router ID.
R1 Area 0 R2
I'm 10.0.1.1
Router ID 10.0.3.3 R3
Page 15 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Router ID Area Metric
• An OSPF area ID is a 32-bit non-negative integer in dotted decimal notation (the format is the same as that of an IPv4
address), for example, area 0.0.0.1. For simplicity, an OSPF area ID is also expressed in decimal notation.
R1 Area 0 R2
R3
Page 16 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Router ID Area Metric
• OSPF uses the accumulated cost, that is, the total cost of the outbound interfaces of all routers that the traffic passes
from the source network to the destination network.
Cost of the OSPF Interface Accumulated Cost of the OSPF Path
FE interface GE interface
Default cost = 1 Default cost = 1 Cost = 1 Cost = 64
R1 R2 R3
Different OSPF interfaces have different costs because of their In the routing table of R3, the cost of the OSPF route to network segment
different bandwidths. 10.0.1.1/32 is 1 plus 64, that is, 65.
Page 17 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Router ID Area Metric
Default cost of GE 0/0/1 Default cost of GE 0/0/1 GE 0/0/1 Cost 10 GE 0/0/1 Cost 10
Area 1 Area 1
By default, there are two paths from R4 to network segment 10.0.1.1/32, In the figure, the cost of the device interface is changed to ensure that traffic
and the data forwarding path is uncontrollable. does not need to pass through R2 when the access router accesses R1.
Page 18 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Neighbor Table LSDB OSPF Routing Table
▫ The OSPF neighbor table displays the status of the neighbor relationship between OSPF routers. You can run the display ospf
peer command to view the status.
<R1> display ospf peer
OSPF Process 1 with Router ID 10.0.1.1
[R1]display ospf peer Neighbors
Area 0.0.0.0 interface 10.0.12.1(GigabitEthernet1/0/0)'s neighbors
Router ID: 10.0.2.2 Address: 10.0.12.2 GR State: Normal
Router ID:10.0.1.1 Router ID:10.0.2.2 State: Full Mode:Nbr is Master Priority: 1
DR: 10.0.12.1 BDR: 10.0.12.2 MTU: 0
GE1/0/0 GE1/0/0 Dead timer due in 35 sec
R1 10.0.12.1/30 10.0.12.2/30 R2 Retrans timer interval: 5
Neighbor is up for 00:00:05
Authentication Sequence: [ 0 ]
Page 19 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Neighbor Table LSDB OSPF Routing Table
▫ Type indicates the LSA type, and AdvRouter indicates the router that sends the LSA.
▫ You can run the display ospf lsdb command to check the LSDB.
Page 20 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Neighbor Table LSDB OSPF Routing Table
▫ An OSPF routing table contains information that guides packet forwarding, for example, destination, cost, and next hop.
▫ You can run the display ip routing-table command to check the OSPF routing table.
Total Nets: 3
Intra Area: 3 Inter Area: 0 ASE: 0 NSSA: 0
Page 21 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Packet Format and Type
• OSPF defines five types of packets. Different types of OSPF packets have the same header format.
• OSPF packets are encapsulated in IP packets. The protocol number in the IP header of OSPF packets is 89.
Protocol number
89
Page 22 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
▪ Neighbor Relationship Establishment
▫ Adjacency Establishment
Page 23 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Summary of OSPF Working Mechanism
R1 R2
• On an Ethernet link, by default, OSPF sends Hello packets in multicast mode (destination address: 224.0.0.5).
• An OSPF Hello packet contains information such as the router ID and neighbor list of a router.
R2 R1
10.0.2.2 10.0.1.1
Neighbor status
of R1 Down: Initial state of a neighbor, which indicates that no
Hello (Router ID: 10.0.1.1 neighbor: null) packets are received from the neighbor.
1 Down
Init: The router has received a Hello packet from its
Hello (Router ID: 10.0.2.2 neighbor: null)
1 Init neighbor, but its router ID is not in the neighbor list of the
received Hello packet.
Hello (Router ID: 10.0.2.2 neighbor: 10.0.1.1)
2 2-way 2-way: The router finds that its router ID exists in the
neighbor list of the received Hello packet.
Page 25 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Hello Packet
• Hello packets are used in the following scenarios: • Key fields
▫ Network Mask: indicates the network mask of the interface that sends Hello packets.
▫ Neighbor discovery: Hello packets are used to automatically
▫ HelloInterval: indicates the interval at which Hello packets are sent. The value is 10s
discover neighboring routers. typically.
▫ Neighbor relationship establishment: The two ends negotiate ▫ RouterDeadInterval: indicates the expiration time of a neighbor relationship. If a device
does not receive any Hello packets from its neighbors within a specified Dead interval, the
parameters in Hello packets and establish a neighbor relationship.
neighbors are considered to be Down. The value is 40s typically.
▫ Neighbor relationship holding: A router periodically sends and ▫ Neighbor: indicates the router ID of a neighbor.
receives Hello packets to detect the operating status of neighbors. • Description of other fields
▫ Options:
▪ E: indicates whether external routes are supported.
Network Mask ▪ MC: indicates whether to support forwarding of multicast data packets.
Hello Interval Options Router Priority ▪ N/P: indicates whether the area is an NSSA.
RouterDeadInterval ▫ Router Priority: indicates the DR priority. The default value is 1. If it is set to 0, the
Designated Router router cannot participate in DR or BDR election.
Backup Designated Router ▫ Designated Router: indicates the interface address of a DR.
Page 26 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
▫ Neighbor Relationship Establishment
▪ Adjacency Establishment
▫ Functions of the DR and BDR
Page 27 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Adjacency Establishment (1)
R2 R1
10.0.2.2 10.0.1.1Neighbor status Fields in DD packets
of R1 ▫ I: If the DD packet is the first among multiple consecutive
DD packets sent by a device, this field is set to 1.
2-way Otherwise, this field is set to 0.
ExStart: The router starts to send DD ▫ M (More): If the DD packet is the last among multiple
DD(Seq=X, I=1, M=1, MS=1) packets to its neighbor. The DD
consecutive DD packets sent by a device, this field is set to
ExStart packets sent in this state do not
0. Otherwise, this field is set to 1.
contain the link state description.
▫ MS (Master/Slave): When two OSPF routers exchange
DD(Seq=Y, I=1, M=1, MS=1)
DD packets, they need to determine the master/slave
relationship. The router with a larger router ID becomes
DD (Seq=Y, LSDB summary) the master router. The value 1 indicates that the sender is
Exchange: A router and its neighbor
Exchange the master.
exchange DD packets that contain
DD (Seq = Y + 1, LSDB summary, MS link state summaries. ▫ DD sequence number: indicates the sequence number of
= 1) a DD packet. The master and slave devices use sequence
numbers to ensure the reliability and integrity of DD
Loading: A router and its neighbor packet transmission.
DD(Seq=Y+1)
Loading send LSR packets, LSU packets, and
LSAck packets to each other.
Page 28 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
DD Packet
A DD packet contains the LSA header information, including the LS type, LS ID, Advertising Router, LS Sequence
Number, and LS Checksum.
Page 29 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Adjacency Establishment (2)
R2 R1
• R1 starts to send LSR packets to R2 to request the link state
Neighbor status
information that is discovered through DD packets in Exchange state
of R1
LSR and does not exist in the local LSDB.
Loading • R2 sends an LSU packet to R1. The LSU packet contains detailed
information about the requested link state. After R1 receives the LSU
LSU
Full packet and does not have other LSAs to be requested, R1 changes the
neighbor status from Loading to Full.
LSAck
• R1 sends an LSAck packet to R2 to acknowledge the LSU packet.
Full: The router has synchronized
the LSDB with the neighbor.
Question: If multiple routers are located on the same broadcast network, what are the problems in establishing adjacencies using the
preceding method?
Page 30 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
▫ Neighbor Relationship Establishment
▫ Adjacency Establishment
Page 31 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Functions of the DR and BDR
Problems on the MA Network DR election on an MA network:
• A DR establishes and maintains adjacencies on an MA network and synchronizes
▫ n x (n-1)/2 adjacencies complicate management.
LSAs.
▫ Repeated LSA flooding wastes resources. Solution
• The DR establishes adjacencies with all other routers and exchanges link state
information with them. Other routers do not directly exchange link state information.
• To prevent single points of failures (SPOFs), a BDR is elected to quickly take over
services of the DR when the DR fails.
R1 R2 R1 R2
DR BDR DR BDR
Adjacency
R3 R4 R5 R3 R4 R5
Page 32 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
DR and BDR Election Rules
• DR or BDR election is in non-preemption mode.
R1 (DR) R2 (DRother)
• DR or BDR election is based on interfaces. 10.0.1.1 10.0.2.2
• Question:
▫ If the priorities of the four routers in the preceding figure are all set to 0, can OSPF work normally?
▫ Which types of links form an MA network by default?
Page 33 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
DR and BDR Election on Different Types of
Networks
OSPF Network Common Data Link Whether to Elect Whether to Establish an
Type Layer Protocol a DR Adjacency with the Neighbor
Point-to-point PPP and HDLC No Yes
Page 34 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Adjusting the OSPF Network Type of Device
Interfaces as Needed
• The OSPF network type is automatically set based on the data link
layer encapsulation of the interface.
In the interface view, run the ospf network { p2p | p2mp | broadcast | nbma } command to change the network type of
the interface.
Page 35 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Introduction to Dynamic Routing Protocols
2. Overview of OSPF
3. OSPF Working Mechanism
4. Basic OSPF Configurations
Page 36 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Configuration Commands (1)
1. Create an OSPF process and enter the OSPF view.
The router supports OSPF multi-process, and the process ID is configured locally. Two devices that use different OSPF process IDs can also establish an adjacency.
Run the following command to configure the network segment included in the area. The mask length of the interface IP address is larger than or equal to the mask length
specified by the network command, and the primary IP address of the interface must be on the network segment specified by the network command. In this case, OSPF
The ospf enable command takes precedence over the network command.
Page 37 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Configuration Commands (2)
5. Set a priority for an interface that participates in the DR election in the interface view.
By default, for a P2P or broadcast interface, the interval for sending Hello packets is 10 seconds; the dead interval after which an interface considers its OSPF neighbor
By default, the network type of an interface is determined by the physical interface. The network type of an Ethernet interface is broadcast, and the network type of a serial
Page 38 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Examples
• Basic information: The router ID of each device is 10.0.x.x, where x is
R1 R2 the router number. For example, the router ID of R5 is 10.0.5.5. The IP
GE0/0/0 GE0/0/0
address for interconnection between devices is 10.0.xyz.x(y)/24, where
xyz indicate the router numbers. The router numbers are in ascending
Se
/1
Se1/0/0
1/ 0
0/
GE
order. For example, the IP address of GE0/0/1 on R2 is 10.0.235.2/24.
/1
/1
Se
0
0/
1/ 0
• Topology: Five routers work in area 0.
GE
/1
SW1 R4
/2
GE
/1
0
1/ 0
0/
Se
/3
0 /
/0
1/0
Se
0
GE
/0
/0
[R2-ospf-1]area 0.0.0.0
[R2-ospf-1-area-0.0.0.0] network 10.0.12.0 0.0.0.255
R3 R5 [R2-ospf-1-area-0.0.0.0] network 10.0.24.2 0.0.0.0
Ethernet link [R2-ospf-1-area-0.0.0.0] network 10.0.235.2 0.0.0.0
Serial link
Page 39 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Verification (1)
Run the display ospf interface all command to check information about all OSPF
interfaces on the device.
R1 R2
GE0/0/0 • Time parameters, such as the interval for sending Hello packets and dead interval
• Interface IP address of the DR and the priority of the DR for an Ethernet link
/1
Se
0
0/
1/ 0
GE
[R2]display ospf interface all
/1
OSPF Process 1 with Router ID 10.0.2.2
Area: 0.0.0.0
Interface: 10.0.12.2 (GigabitEthernet0/0/0)
SW1 Cost: 1 State: DR Type: Broadcast MTU: 1500 Priority: 1
R4 Designated Router: 10.0.12.2
Backup Designated Router: 10.0.12.1
Timers: HELLO 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
Page 40 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Verification (2)
Run the display ospf peer command to check the neighbor status of the device.
• Router ID of the neighboring router
R1 R2
• Neighbor status, such as FULL, TWO-WAY, and DOWN
Page 41 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Verification (3)
On a P2P network, DR or BDR election is not required. Therefore, when checking
the OSPF neighbor table of R2, you can find that the DR/BDR field of Serial1/0/1
R1 R2
in the command output is None.
Page 42 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Verification (4)
Run the display ospf lsdb command to check the LSDB of the device.
• An LSDB consists of multiple types of LSAs. All LSAs have the same packet header format,
R1 R2
in which key fields such as Type, LinkState ID, and AdvRouter are included. The next course
will focus on LSA details.
Area: 0.0.0.0
SW1
R4 Type LinkState ID AdvRouter Age Len Sequence Metric
Router 10.0.4.4 10.0.4.4 662 72 80000006 48
Router 10.0.2.2 10.0.2.2 625 72 8000000C 1
Router 10.0.1.1 10.0.1.1 638 60 80000007 1
Router 10.0.5.5 10.0.5.5 634 60 8000000B 1
Router 10.0.3.3 10.0.3.3 639 60 80000009 1
R3 R5 Network 10.0.235.5 10.0.5.5 634 36 80000005 0
Network 10.0.12.2 10.0.2.2 629 32 80000003 0
Page 43 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
OSPF Configuration Verification (5)
Run the display ospf routing command to check the OSPF routing table of the
device.
R1 R2
• The OSPF routing table of R2 shows that R2 has learned the routes to the entire network
through OSPF.
Page 44 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Quiz
1. (Single) Which of the following packets is used by OSPF to maintain neighbor relationships? ( )
A. Hello
B. Database Description
C. LSR
D. LSU
B. P2MP network
C. Broadcast network
D. NBMA network
Page 45 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
Summary
• This course describes basic OSPF concepts, including the router ID, area, and cost. Routers
running OSPF send link state information to each other to calculate the topology and routes.
• This course describes the process of establishing OSPF neighbor relationships and adjacencies.
On an MA network, the DR and BDR need to be elected. There are five types of OSPF packets.
All packets have the same packet header format. An OSPF router periodically sends Hello
packets to discover and maintain neighbor relationships, and uses DD, LSR, LSU, and LSAck
packets to synchronize LSDBs. Finally, this course introduces the simple configuration of a
single OSPF area.
Page 46 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.
谢谢
Thank You
www.huawei.com
Page 47 Copyright © 2020 Huawei Technologies Co., Ltd. All rights reserved.