簡介
OSPF協定的全稱是Open Shortest Path First,即開放式最短路徑優先,它是一個內部網關協定,用於在單一自治系統內決策路由。區別於距離矢量協定(RIP),OSPF具有支持大型網路、路由收斂快、占用網路資源少等優點,在目前套用的路由協定中占有相當重要的地位。根據路由器所連線的物理網路不同,OSPF將網路劃分為四種類型:廣播多路訪問型(Broadcast Multi Access)、非廣播多路訪問型(None Broadcast Multi Access,NBMA)、點到點型(Point-to-Point)、點到多點型(Point-to-MultiPoint) 。
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