简介
OSPF协议的全称是Open Shortest Path First,即开放式最短路径优先,它是一个内部网关协议,用于在单一自治系统内决策路由。区别于距离矢量协议(RIP),OSPF具有支持大型网络、路由收敛快、占用网络资源少等优点,在目前应用的路由协议中占有相当重要的地位。根据路由器所连接的物理网络不同,OSPF将网络划分为四种类型:广播多路访问型(Broadcast Multi Access)、非广播多路访问型(None Broadcast Multi Access,NBMA)、点到点型(Point-to-Point)、点到多点型(Point-to-MultiPoint)1。
NBMA网络模型为了更详细地对NBMA网络中出现的问题进行分析,我们首先建立一个简单的NBMA网络模型(Fram Relay为例),作为研究DR选举的网络环境。如图所示,该网络模型为一个帧中继类型的网络,R0、R1、R2为网络主干,利用R01、R12、R22模拟业务子网,该网络拓扑中各设备的接口地址按照表1~表2所示进行配置。以上网络模型通过帧中继互联完成后,R0、R1、R2三台路由器均可相互通信,由于没有配置静态路由或相关路由协议,R01、R12、R22暂无法相互通信。
例子本次实验是NBMA网络上,广播模式下的OSPF,网络拓扑是全互联的,接下来还有部分互联的
R1配置:
interface Loopback1
ip address 1.1.1.1 255.255.255.0
ip ospf network point-to-point //OSPF将通告环回接口的实际子网掩码如不配这句将通告成/32
!
interface Serial1/2
ip address 10.0.1.1 255.255.255.0
encapsulation frame-relay //封装成帧中继
ip ospf network broadcast //设置成广播模式,广播模式下自动建立邻居关系
serial restart-delay 0
!
router ospf 1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 10.0.1.0 0.0.0.255 area 0
!
R2配置:
interface Loopback1
ip address 2.2.2.2 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/2
ip address 10.0.1.2 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
serial restart-delay 0
!
router ospf 1
log-adjacency-changes
network 2.2.2.0 0.0.0.255 area 0
network 10.0.1.0 0.0.0.255 area 0
!
R3配置:
interface Loopback1
ip address 3.3.3.3 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/2
ip address 10.0.1.3 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
serial restart-delay 0
!
router ospf 1
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 10.0.1.0 0.0.0.255 area 0
!
各个路由器路由表:
R1(config-router)#do show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback1
2.0.0.0/24 is subnetted, 1 subnets
O 2.2.2.0 [110/65] via 10.0.1.2, 00:14:05, Serial1/2
3.0.0.0/24 is subnetted, 1 subnets
O 3.3.3.0 [110/65] via 10.0.1.3, 00:14:05, Serial1/2
10.0.0.0/24 is subnetted, 1 subnets
C 10.0.1.0 is directly connected, Serial1/2
Router(config-if)#do show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
O 1.1.1.0 [110/65] via 10.0.1.1, 00:31:00, Serial1/2
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback1
3.0.0.0/24 is subnetted, 1 subnets
O 3.3.3.0 [110/65] via 10.0.1.3, 00:31:00, Serial1/2
10.0.0.0/24 is subnetted, 1 subnets
C 10.0.1.0 is directly connected, Serial1/2
R3(config-if)#do show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
O 1.1.1.0 [110/65] via 10.0.1.1, 00:15:40, Serial1/2
2.0.0.0/24 is subnetted, 1 subnets
O 2.2.2.0 [110/65] via 10.0.1.2, 00:15:40, Serial1/2
3.0.0.0/24 is subnetted, 1 subnets
C 3.3.3.0 is directly connected, Loopback1
10.0.0.0/24 is subnetted, 1 subnets
C 10.0.1.0 is directly connected, Serial1/2
各个路由器邻居关系:
R1(config-router)#do show ip ospf ne
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DROTHER 00:00:35 10.0.1.2 Serial1/2
3.3.3.3 1 FULL/DR 00:00:37 10.0.1.3 Serial1/2
R2(config-if)#do show ip ospf ne
Neighbor ID Pri State Dead Time Address Interface
1.1.1.1 1 FULL/BDR 00:00:38 10.0.1.1 Serial1/2
3.3.3.3 1 FULL/DR 00:00:39 10.0.1.3 Serial1/2
R3(config-if)#do show ip ospf ne
Neighbor ID Pri State Dead Time Address Interface
1.1.1.1 1 FULL/BDR 00:00:35 10.0.1.1 Serial1/2
2.2.2.2 1 FULL/DROTHER 00:00:35 10.0.1.2 Serial1/2
R3是DR,R1是BDR,R2是DROTHER