赞
踩
本章阐述了OSPF协议的特征、术语,OSPF的路由器类型、网络类型、区域类型、LSA类型,OSPF报文的具体内容及作用,描述了OSPF的邻居关系,通过实例让读者掌握OSPF在各种场景中的配置。
本章包含以下内容:
开放式最短路径优先(Open Shortest Path First,OSPF)是IETF(The Internet Engineering Task Force, 国际互联网工程任务组)开发的一个基于链路状态的内部网关协议(Interior Gateway Protocol)。目前,针对IPv4协议使用的是OSPF Version 2(RFC2328);针对IPv6协议使用的是OSPF Version 3(RFC2740)。如无特殊说明,本文中所指的OSPF均为OSPF Version 2。[2]
OSPF的路由器类型如图1-1所示。
图1-1路由器类型
OSPF的网络类型见表1-1
表1-1 OSPF的网络类型
网络类型 | 链路层协议 | 选择DR | Hello间隔/s | Dead间隔[10] /s | 邻居 |
P2P | PPP、HDLC | 否 | 10 | 40 | 自动发现 |
广播 | Ethernet | 是 | 10 | 40 | 自动发现 |
NBMA | 帧中继 | 是 | 30 | 120 | 管理员配置 |
P2MP | 管理员配置 | 否 | 30 | 120 | 自动发现 |
OSPF的区域类型包括普通区域、Stub区域、NSSA区域,见表2-1所示。
表1-2 OSPF的区域类型
区域类型 | 作用 |
骨干区域 | 骨干区域是连接所有其他OSPF区域的中央区域,通常用area 0表示 |
标准区域 | 标准区域是最通用的区域,它传输区域内、区域间路由和外部路由 |
STUB区域 | 拒绝4、5类LSA 自动下发一条3类的LSA的默认路由[11] |
Totally STUB区域 | 拒绝3、4、5类LSA 自动下发一条3类的LSA的默认路由 |
NSSA | 拒绝4、5类LSA,引入7类LSA 自动下发一条7类的LSA的默认路由 |
Totally NSSA | 拒绝3、4、5类LSA,引入7类LSA 自动下发一条3类和7类的LSA的默认路由 |
LSA是OSPF进行路由计算的关键依据,OSPF的LSU报文可以携带多种不同类型的LSA,各种类型的LSA拥有相同的报文头部。报文格式见表1-3。
表1-3 LSA的报文头部格式
LS Age | Options | LS type |
Link State ID | ||
Advertising Router | ||
LS sequence number[12] | ||
LS checksum[13] | length[14] |
以下是对报文头部的解释。
OSPF中对路由信息的描述都是封装在链路状态通告LSA(Link State Advertisement)中发布出去的,常用的LSA见表1-4。
表1-4 LSA的类型
LSA类型 | LSA作用 |
Router | 每个设备都会产生,描述了设备的链路状态和开销,在所属的区域内传播。 |
Network | 由DR产生,描述本网段的链路状态,在所属的区域内传播。 |
Network-summary | 由ABR产生,描述区域内某个网段的路由,并通告给其它区域 |
ASBR-summary | 由ABR产生,描述到ASBR的路由,通告给除ASBR所在区域的其他相关区域。 |
AS-external | 由ASBR产生,描述到AS外部的路由,通告到所有的区域 |
NSSA | 由ASBR产生,描述到AS外部的路由,仅在NSSA区域内传播。 |
OSPF用IP报文直接封装协议报文,协议号为89。OSPF分为5种报文:Hello报文、DD报文、LSR报文、LSU报文和LSAck报文,见表1-5。
表1-5 OSPF报文类型
报文类型 | 作用 |
Hello | 周期性发送,用来发现和维持OSPF邻居关系 |
DD | 描述本地LSDB(Link State Database)的摘要信息,用于两台设备进行数据库同步。 |
LSR | 用于向对方请求所需的LSA。 设备只有在OSPF邻居双方成功交换DD报文后才会向对方发出LSR报文。 |
LSU | 用于向对方发送其所需要的LSA。 |
LSA | 用来对收到的LSA进行确认。 |
AS区域内和区域间路由描述的是AS内部的网络结构,AS外部路由则描述了应该如何选择到AS以外目的地址的路由。OSPF将引入的AS外部路由分为Type1和Type2两类。见表1-6
表1-6 OSPF路由类型
路由类型 | 含义 |
Intra Area | 区域内路由。 |
Inter Area | 区域间路由。 |
Type1 |
|
Type2 |
|
1.实验目的
2.实验拓扑
单区域的OSPF实验拓扑如图1-2所示。
图1-2 配置单区域OSPF
3.实验步骤
R1的配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
[R1-GigabitEthernet0/0/0]quit
[R1]interface LoopBack 0
[R1-LoopBack0]ip address 1.1.1.1 24
[R1-LoopBack0]quit
R2的配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R2
[R2]interface g0/0/1
[R2-GigabitEthernet0/0/1]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/1]quit
[R2]interface g0/0/0
[R2-GigabitEthernet0/0/0]ip address 23.1.1.2 24
[R2-GigabitEthernet0/0/0]quit
[R2]interface LoopBack 0
[R2-LoopBack0]ip address 2.2.2.2 24
[R2-LoopBack0]quit
R3的配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R3
[R3]interface g0/0/1
[R3-GigabitEthernet0/0/1]ip address 23.1.1.3 24
[R3-GigabitEthernet0/0/1]quit
[R3]interface LoopBack 0
[R3-LoopBack0]ip address 3.3.3.3 32
[R3-LoopBack0]quit
R1的配置
[R1]ospf router-id 1.1.1.1 //启用OSPF,设置它的ROUTER-ID 1.1.1.1
[R1-ospf-1]area 0 //区域0
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255 //宣告网络12.1.1.0
[R1-ospf-1-area-0.0.0.0]network 1.1.1.0 0.0.0.255 //宣告网络1.1.1.0
[R1-ospf-1-area-0.0.0.0]quit
R2的配置
[R2]ospf router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 2.2.2.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]quit
R3的配置
[R3]ospf router-id 3.3.3.3
[R3-ospf-1]are
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]net
[R3-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]net
[R3-ospf-1-area-0.0.0.0]network 3.3.3.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]quit
【技术要点1】进程ID
OSPF的进程ID的编号范围为1-65535,只在本地有效,不同路由器的进程ID号可以不同
【技术要点2】Router ID
4.实验调试
<R1>display ospf interface all
OSPF Process 1 with Router ID 1.1.1.1 //OSPF的进程为1,router-id为1.1.1.1
Interfaces
Area: 0.0.0.0 (MPLS TE not enabled) //OSPF的区域为0
Interface: 12.1.1.1 (GigabitEthernet0/0/0)
Cost: 1 State: DR Type: Broadcast MTU: 1500
Priority: 1 //g0/0/0的开销为1,它是DR,网络类型为广播,MTU为1500,优选级为1
Designated Router: 12.1.1.1 //DR为12.1.1.1
Backup Designated Router: 12.1.1.2 //BDR为12.1.1.2
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
Interface: 1.1.1.1 (LoopBack0)
Cost: 0 State: P-2-P Type: P2P MTU: 1500
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
<R1>display ospf peer
OSPF Process 1 with Router ID 1.1.1.1
Neighbors
Area 0.0.0.0 interface 12.1.1.1(GigabitEthernet0/0/0)'s neighbors
Router ID: 2.2.2.2 Address: 12.1.1.2
State: Full Mode:Nbr is Master Priority: 1 //邻居状态为full,邻居为Master
DR: 12.1.1.1 BDR: 12.1.1.2 MTU: 0
Dead timer due in 34 sec
Retrans timer interval: 5
Neighbor is up for 00:29:56
Authentication Sequence: [ 0 ]
<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 109 60 8000000A 1
Router 1.1.1.1 1.1.1.1 169 48 80000007 1
Router 3.3.3.3 3.3.3.3 114 48 80000005 1
Network 23.1.1.2 2.2.2.2 109 32 80000003 0
Network 12.1.1.1 1.1.1.1 169 32 80000003 0
<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
1.1.1.1/32 0 Stub 1.1.1.1 1.1.1.1 0.0.0.0
12.1.1.0/24 1 Transit 12.1.1.1 1.1.1.1 0.0.0.0
2.2.2.2/32 1 Stub 12.1.1.2 2.2.2.2 0.0.0.0
3.3.3.3/32 2 Stub 12.1.1.2 3.3.3.3 0.0.0.0
23.1.1.0/24 2 Transit 12.1.1.2 2.2.2.2 0.0.0.0
Total Nets: 5
Intra Area: 5 Inter Area: 0 ASE: 0 NSSA: 0
<R1>terminal debugging //使能终端显示Debug信息功能
<R1>terminal monitor //使能终端显示信息中心发送信息的功能
<R1>debugging ospf event //用来查看OSPF协议工作过程中的所有事件
<R1>debugging ospf packet //用来查看OSPF协议工作过程中的所有的报文
<R1>system-view
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]shutdown
[R1-GigabitEthernet0/0/0]quit
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]undo shutdown
[R1-GigabitEthernet0/0/0]quit
[R1]info-center enable
Sep 2 2022 15:13:00-08:00 R1 %%01IFPDT/4/IF_STATE(l)[0]:Interface GigabitEthernet0/0/0 has turned into UP state.
[R1]
Sep 2 2022 15:13:00-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
[R1]
[R1]
Sep 2 2022 15:13:00.191.7-08:00 R1 RM/6/RMDEBUG:
FileID: 0xd017802c Line: 1295 Level: 0x20
OSPF 1: Intf 12.1.1.1 Rcv InterfaceUp State Down -> Waiting.
//接口UP后,OSPF状态从Down进入到Waiting状态。[23]
[R1]
Sep 2 2022 15:13:00.191.8-08:00 R1 RM/6/RMDEBUG:
FileID: 0xd0178025 Line: 559 Level: 0x20
OSPF 1: SEND Packet. Interface: GigabitEthernet0/0/0
[R1]
Sep 2 2022 15:13:00.191.9-08:00 R1 RM/6/RMDEBUG: Source Address: 12.1.1.1
[R1]
Sep 2 2022 15:13:00.191.10-08:00 R1 RM/6/RMDEBUG: Destination Address: 224.0.0.5
[R1]
[R1]
Sep 2 2022 15:13:00.191.11-08:00 R1 RM/6/RMDEBUG: Ver# 2, Type: 1 (Hello)
[R1]
Sep 2 2022 15:13:00.191.12-08:00 R1 RM/6/RMDEBUG: Length: 44, Router: 1.1.1.1
[R1]
Sep 2 2022 15:13:00.191.13-08:00 R1 RM/6/RMDEBUG: Area: 0.0.0.0, Chksum: fa9c
[R1]
Sep 2 2022 15:13:00.191.14-08:00 R1 RM/6/RMDEBUG: AuType: 00
[R1]
Sep 2 2022 15:13:00.191.15-08:00 R1 RM/6/RMDEBUG: Key(ascii): * * * * * * * *
[R1]
Sep 2 2022 15:13:00.191.16-08:00 R1 RM/6/RMDEBUG: Net Mask: 255.255.255.0
[R1]
Sep 2 2022 15:13:00.191.17-08:00 R1 RM/6/RMDEBUG: Hello Int: 10, Option: _E_
[R1]
Sep 2 2022 15:13:00.191.18-08:00 R1 RM/6/RMDEBUG: Rtr Priority: 1, Dead Int: 40
[R1]
Sep 2 2022 15:13:00.191.19-08:00 R1 RM/6/RMDEBUG: DR: 0.0.0.0
[R1]
Sep 2 2022 15:13:00.191.20-08:00 R1 RM/6/RMDEBUG: BDR: 0.0.0.0
[R1]
Sep 2 2022 15:13:00.191.21-08:00 R1 RM/6/RMDEBUG: # Attached Neighbors: 0
[R1]
Sep 2 2022 15:13:00.191.22-08:00 R1 RM/6/RMDEBUG:
[R1]
Sep 2 2022 15:13:00.191.23-08:00 R1 RM/6/RMDEBUG:
FileID: 0xd017802c Line: 1409 Level: 0x20
OSPF 1 Send Hello Interface Up on 12.1.1.1 //R1在接口上发送Hello包
[R1]
Sep 2 2022 15:13:00.641.1-08:00 R1 RM/6/RMDEBUG:
FileID: 0xd0178024 Line: 2236 Level: 0x20
OSPF 1: RECV Packet. Interface: GigabitEthernet0/0/0
[R1]
Sep 2 2022 15:13:00.641.2-08:00 R1 RM/6/RMDEBUG: Source Address: 12.1.1.2
[R1]
Sep 2 2022 15:13:00.641.3-08:00 R1 RM/6/RMDEBUG: Destination Address: 224.0.0.5
[R1]
Sep 2 2022 15:13:00-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[2]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=Init)
//从邻居收到Hello包,状态从Down进入到Init
[R1]
Sep 2 2022 15:13:00.641.5-08:00 R1 RM/6/RMDEBUG: Ver# 2, Type: 1 (Hello)
[R1]
Sep 2 2022 15:13:00.641.6-08:00 R1 RM/6/RMDEBUG: Length: 44, Router: 2.2.2.2
[R1]
Sep 2 2022 15:13:00.641.7-08:00 R1 RM/6/RMDEBUG: Area: 0.0.0.0, Chksum: f89a
[R1]
Sep 2 2022 15:13:00.641.8-08:00 R1 RM/6/RMDEBUG: AuType: 00
[R1]
Sep 2 2022 15:13:00.641.9-08:00 R1 RM/6/RMDEBUG: Key(ascii): * * * * * * * *
[R1]
Sep 2 2022 15:13:00.641.10-08:00 R1 RM/6/RMDEBUG: Net Mask: 255.255.255.0
[R1]
Sep 2 2022 15:13:00.641.11-08:00 R1 RM/6/RMDEBUG: Hello Int: 10, Option: _E_
[R1]
Sep 2 2022 15:13:00.641.12-08:00 R1 RM/6/RMDEBUG: Rtr Priority: 1, Dead Int: 40
[R1]
Sep 2 2022 15:13:00.641.13-08:00 R1 RM/6/RMDEBUG: DR: 0.0.0.0
[R1]
Sep 2 2022 15:13:00.641.14-08:00 R1 RM/6/RMDEBUG: BDR: 0.0.0.0
[R1]
Sep 2 2022 15:13:00.641.15-08:00 R1 RM/6/RMDEBUG: # Attached Neighbors: 0
[R1]
Sep 2 2022 15:13:00.641.16-08:00 R1 RM/6/RMDEBUG:
[R1]
Sep 2 2022 15:13:00.641.17-08:00 R1 RM/6/RMDEBUG:
FileID: 0xd017802d Line: 1136 Level: 0x20
OSPF 1: Nbr 12.1.1.2 Rcv HelloReceived State Down -> Init.
[R1]
Sep 2 2022 15:13:10-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[3]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=2Way)
//从邻居收到的Hello包,并在Hello包中看到了自己的ROUTER-ID[24] ,状态从Init进到2way
[R1]
Sep 2 2022 15:13:39-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=AdjOk?, NeighborPreviousState=2Way, NeighborCurrentState=ExStart)
//发送DD报文,进入到ExStart状态
[R1]
Sep 2 2022 15:13:44-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=NegotiationDone,NeighborPreviousState=ExStart,NeighborCurrentState=Exchange) //交互DD报文并发送LSR、LSU进入到Exchange
[R1]
Sep 2 2022 15:13:44-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[6]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=ExchangeDone,NeighborPreviousState=Exchange,NeighborCurrentState=Loading) //交互完毕进入到Loading状态
[R1]
Sep 2 2022 15:13:44-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[7]:Neighbor changes event: neighbor status changed. (ProcessId=256, NeighborAddress=2.1.1.12, NeighborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full
)
//LSA同步完成进入Full状态
本文出自作者的华为HCIA-DATACOM认证实验指南
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。