您好,登錄后才能下訂單哦!
OSPF(開放最短路徑優先)是一種內部網關協議。不同于IGRP,OSPF是一種無類鏈路狀態路由選擇協議,而不是一種分類距離矢量協議。OSPF被標準化,廣泛用于公共和私有網絡中。下面簡單介紹一下鏈路狀態路由協議工作過程,如下:
每臺路由器學習激活的直接相連的網絡。
每臺路由器和直接相連的路由器互交,發送Hello報文,建立鄰居關系。
每臺路由器構建包含直接相連的鏈路狀態的LSA(Link-State Advertisement,鏈路狀態通告)。鏈路狀態通告(LSA)中記錄了所有相關的路由器,包括鄰路由器的標識、鏈路類型、帶寬等。
每臺路由器泛洪鏈路狀態通告(LSA)給所有的鄰路由器,并且自己也在本地儲存鄰路由發過來的LSA,然后再將收到的LSA泛洪給自己的所有鄰居,直到在同一區域中的所有路由器收到了所有的LSA。每臺路由器在本地數據庫中保存所有收到的LSA副本,這個數據庫被稱作“鏈路狀態數據庫(LSDB,Link-State Database)”
每臺路由器基于本地的“鏈路狀態數據庫(LSDB)”然后執行“最短路徑優先(SPF)”算法,并以本路由器為根,生成一個SPF樹,基于這個SPF樹計算去往每個網絡的最短路徑,也就得到了最終的路由表。
簡單理解OSPF以下二個基礎知識點。
理解鄰居表、拓撲表以及路由表;
OSPF如何選舉RID?
OSPF度量值的計算方法;
說明:默認沒有R1到R3的快速以太網鏈路,此鏈路將在后面實驗OPSF度量值的計算方法上使用)
R2#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.2/32 [110/65] via 192.168.10.2, 00:04:11, Serial1/1
O 10.5.0.2/32 [110/65] via 192.168.20.2, 00:02:21, Serial1/0
C 10.6.0.0/16 is directly connected, Loopback0
O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:00:31, Serial1/3
O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:01:26, Serial1/2
192.168.10.0/30 is subnetted, 1 subnets
C 192.168.10.0 is directly connected, Serial1/1
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, Serial1/0
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/128] via 192.168.40.2, 00:00:31, Serial1/2
[110/128] via 192.168.50.2, 00:00:31, Serial1/3
192.168.40.0/30 is subnetted, 1 subnets
C 192.168.40.0 is directly connected, Serial1/2
192.168.50.0/30 is subnetted, 1 subnets
C 192.168.50.0 is directly connected, Serial1/3
如上面紅色部分,在OSPF中所有的回環接口都被自動宣告成32位的主機路由“/32”,如果想顯示回環接口的實際子網掩碼,可以在回環端口上使用下面的命令:
Ip ospf network point-to-point
我們來看看實際的結果,當在R1、R2上的loopback0端口輸入此命令后如下顯示:
R2#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0/16 [110/65] via 192.168.10.2, 00:00:11, Serial1/1
O 10.5.0.2/32 [110/65] via 192.168.20.2, 00:36:53, Serial1/0
C 10.6.0.0/16 is directly connected, Loopback0
O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:35:03, Serial1/3
O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:35:57, Serial1/2
------略-----
R1#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C 10.2.0.0/16 is directly connected, Loopback0
O 10.5.0.2/32 [110/129] via 192.168.10.1, 00:36:39, Serial0/0
O 10.6.0.0/16 [110/65] via 192.168.10.1, 00:00:38, Serial0/0
O 10.11.0.2/32 [110/129] via 192.168.10.1, 00:34:49, Serial0/0
O 10.12.0.2/32 [110/129] via 192.168.10.1, 00:35:48, Serial0/0
------略-----
R2#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
10.5.0.2 0 FULL/ - 00:00:34 192.168.20.2 Serial1/0
10.2.0.2 0 FULL/ - 00:00:31 192.168.10.2 Serial1/1
10.12.0.2 0 FULL/ - 00:00:34 192.168.40.2 Serial1/2
10.11.0.2 0 FULL/ - 00:00:33 192.168.50.2 Serial1/3
Neighbor ID:鄰居的RID,通過上面的輸出可以看到R3的RID是10.5.0.2,R1的RID是10.2.0.2,R5的RID是10.12.0.2和R4的RID是10.11.0.2,分別從不同的接口建立了鄰居關系。
Pir: OSPF鄰居接口的優先級,接口優先級用于DR和BDR的選舉,以太網接口的默認優先級是1,串行線路不需要選舉DR和BDR,所以串行線路的優先級是0,即0代表不參與選舉。
State:鄰居路由器的狀態,FULL代表已經建立鄰接關系,“/”后面是選舉的DR或BDR標識,因為串行線路不需要選舉,所以是“-”。
Dead time: 默認的死亡時間是hello時間的4倍,即40秒。死亡時間是一個倒計時,計時器為0時,該鄰居被刪除。
Address: 鄰居直連接口的IP地址。
Interface: 本路由的輸出接口。
R2#show ip ospf database
OSPF Router with ID (10.6.0.2) (Process ID 1)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
10.6.0.2 10.6.0.2 54 0x8000000c 0x00997e 9
10.5.0.2 10.5.0.2 393 0x80000005 0x00650d 3
10.12.0.2 10.12.0.2 299 0x80000007 0x0099d6 5
10.11.0.2 10.11.0.2 285 0x80000007 0x004419 5
10.2.0.2 10.2.0.2 19 0x80000006 0x00a5ea 3
Router ID簡稱RID,用來唯一標示OSPF網絡中的每一臺路由器。如果兩條OSPF路由器的RID一樣,彼此間無法建立鄰接關系。RID是以IP地址的形式出現的,那么RID的選舉順序是什么?我們先來看看R1的RID:
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 10.2.0.2
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.10.0 0.0.0.255 area 0
0.0.0.0 255.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
10.2.0.2 110 00:07:07
10.5.0.2 110 00:13:21
10.6.0.2 110 00:07:43
10.11.0.2 110 00:11:34
10.12.0.2 110 00:11:48
Distance: (default is 110)
下面我們來手工配置一下R1的Router ID:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#route ospf 1
A.B.C.D OSPF router-id in IP address format
R1(config-router)#route 20.20.20.20
R1(config-router)#Reload or use "clear ip ospf process" command, for this to take effect
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R1#
01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset
01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
01:24:05: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done
我們再來查看一下Route ID是什么情況:
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 20.20.20.20
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
-----略-----
從上面的例子中,我們看到RID可以是一個并不存在的IP地址,RID僅僅作為路由的標識,不會用于尋址。
另我們需要想一個問題,那就是如果取消R1的手動配置RID,并且關閉loopback0接口,這個時候最大的已激活回環接口IP應該是什么?同樣我們來看看實驗:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#route ospf 1
R1(config-router)#no route 20.20.20.20
R1(config-router)#int loopback0
R1(config-if)#shutdown
R1(config-if)#
%LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down
R1(config-if)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R1#
01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset
01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 192.168.10.2
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.10.0 0.0.0.255 area 0
0.0.0.0 255.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
Distance: (default is 110)
R1#
01:36:56: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done
如上實例說明一個問題,若沒有手動指定RID,路由器默認使用最大已激活的回環接口IP作為RID,但這里要注意的是最大并不是接口號最大,而是IP地址最大。還有一個問題就是如果路由器沒有激活的回環接口,路由器默認會選擇最大激活的物理接口的IP地址作為RID,如上則選擇的是物理接口192.168.10.2。
OSPF中使用的度量值是“花費(Cost)”,默認OSPF使用100Mb/s作為參考帶寬,使用100Mb/s除以實際鏈路帶寬,得出的值取整(對于小于0的結果,取1),就是花費。
比如串行線路的帶寬是1.544M,快速以太網的帶寬是100M,即如下:
串行線路的花費=100M/1.544≈64(取整,且不四舍五入)
快速以太網線路花費=100M/100M=1
繼續上面的實驗,同時我們在R1和R3中新增一條快速以太網鏈路,然后做相應的配置,再看看其R3的驗證:
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/2] via 172.16.50.1, 00:00:15, FastEthernet0/0
O 10.6.0.0 [110/65] via 192.168.20.1, 00:10:00, Serial0/3
O 10.11.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3
O 10.12.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/65] via 172.16.50.1, 00:00:15, FastEthernet0/0
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/192] via 192.168.20.1, 00:10:00, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3
我們可以看到[110/2],110是OSPF的默認管理距離,2是花費,去往10.2.0.0/16的花費是2,就是快速以太網的花費加上回環接口的花費,因為回環接口的帶寬非常高,用100M去除會小于0,所以取1。另外192.168.10.0 [110/65]的65是通過串行線路花費64,加上以太網花費1得到的。
現在我們關閉R3的快速以及網接口,再看看R3的路由表:
R3(config)#int fa0/0
R3(config-if)#shutdown
R3(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
00:17:25: %OSPF-5-ADJCHG: Process 1, Nbr 10.2.0.2 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
end
R3#
%SYS-5-CONFIG_I: Configured from console by console
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/129] via 192.168.20.1, 00:00:01, Serial0/3
O 10.6.0.0 [110/65] via 192.168.20.1, 00:17:06, Serial0/3
O 10.11.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3
O 10.12.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/128] via 192.168.20.1, 00:00:01, Serial0/3
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/192] via 192.168.20.1, 00:17:06, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3
此時會發現數據都要經過串行線路,并且花費變成了129。而192.168.10.0 [110/128]也變成了128。其實可以通過下面的方法修改計算花費的參考帶寬:
R3(config)#route ospf 1
R3(config-router)#auto-cost
R3(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
Please ensure reference bandwidth is consistent across all routers.
R3(config-router)#end
R3#
%SYS-5-CONFIG_I: Configured from console by console
當修改了所有路由器的參考帶寬后,再看看R3的路由表:
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 10.6.0.0 [110/6477] via 192.168.20.1, 00:02:42, Serial0/3
O 10.11.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 10.12.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 172.16.0.0 [110/13052] via 192.168.20.1, 00:00:28, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/19428] via 192.168.20.1, 00:00:18, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
同樣用去往10.2.0.0/16網絡的12953舉例計算花費如下:
R3和R2相連的串行鏈路花費=10000M/1.544M≈6476
R2和R1相連的串行鏈路花費=10000M/1.544M≈6476
R1上的loopback0接口的花費=10000M/8000M≈1
三條線路花費綜合即為12953,另其它端口花費同樣計算。
最后可以通過下面方法查看某接口的OSPF信息:
R3#show ip ospf int se0/3
Serial0/3 is up, line protocol is up
Internet address is 192.168.20.2/30, Area 0
Process ID 1, Router ID 10.5.0.2, Network Type POINT-TO-POINT, Cost: 6476
Transmit Delay is 1 sec, State POINT-TO-POINT, Priority 0
No designated router on this network
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:01
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 1 , Adjacent neighbor count is 1
Adjacent with neighbor 10.6.0.2
Suppress hello for 0 neighbor(s)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。