OSPF 是一种使用多播的链路状态协议。它发送泛洪的链路状态广告 (LSA)。
每个路由器通过运行 SPF 来构建一棵树,其中路由器本身是树的根。在 OSPF 中,我们有传输网络和末节网络。传输网络是用于传输到达网络的网络,而存根网络是您描述的端点或叶子。
如果我们在同一区域,则检查路由器 LSA(类型 1)以找到目的地。这是到达 R1 网络的路由器 LSA,其 RID 为 1.1.1.1。
R2#sh ip ospf data router 1.1.1.1
OSPF Router with ID (2.2.2.2) (Process ID 1)
Router Link States (Area 0)
LS age: 256
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 1.1.1.1
Advertising Router: 1.1.1.1
LS Seq Number: 80000005
Checksum: 0x4B09
Length: 60
Number of Links: 3
Link connected to: a Stub Network
(Link ID) Network/subnet number: 1.1.1.1
(Link Data) Network Mask: 255.255.255.255
Number of TOS metrics: 0
TOS 0 Metrics: 1
Link connected to: a Transit Network
(Link ID) Designated Router address: 13.13.13.1
(Link Data) Router Interface address: 13.13.13.1
Number of TOS metrics: 0
TOS 0 Metrics: 10
Link connected to: a Transit Network
(Link ID) Designated Router address: 12.12.12.2
(Link Data) Router Interface address: 12.12.12.1
Number of TOS metrics: 0
TOS 0 Metrics: 10
R1 对该存根网络的成本为 1。R2 可以通过 12.12.12.0/24 中转网络到达该网络。因此,我们需要添加 10 的成本,从而使总指标达到 11。
R2#sh ip route 1.1.1.1
Routing entry for 1.1.1.1/32
Known via "ospf 1", distance 110, metric 11, type intra area
Last update from 12.12.12.1 on FastEthernet0/0, 00:06:49 ago
Routing Descriptor Blocks:
* 12.12.12.1, from 1.1.1.1, 00:06:49 ago, via FastEthernet0/0
Route metric is 11, traffic share count is 1
这是区域内路线。对于区域间路由,OSPF 实际上就像一个距离矢量协议,因为流量是通过 ABR 发送的。我们如何识别 ABR?
R4#sh ip ospf data router 2.2.2.2
OSPF Router with ID (4.4.4.4) (Process ID 1)
Router Link States (Area 1)
Routing Bit Set on this LSA
LS age: 573
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 2.2.2.2
Advertising Router: 2.2.2.2
LS Seq Number: 80000002
Checksum: 0xCCB6
Length: 36
**Area Border Router**
Number of Links: 1
Link connected to: a Transit Network
(Link ID) Designated Router address: 24.24.24.2
(Link Data) Router Interface address: 24.24.24.2
Number of TOS metrics: 0
TOS 0 Metrics: 10
B 位在 OSPF 报头中设置,使路由器成为 ABR。
这可以在数据包捕获中看到。
要查找区域间路由的度量,需要添加到目的地的 ABR 度量 + 到 ABR 的本地路由的度量。
R4#sh ip ospf border-routers
OSPF Process 1 internal Routing Table
Codes: i - Intra-area route, I - Inter-area route
i 2.2.2.2 [10] via 24.24.24.2, FastEthernet0/0, ABR, Area 1, SPF 4
i 3.3.3.3 [10] via 34.34.34.3, FastEthernet0/1, ABR, Area 1, SPF 4
R4#
这里到达两个 ABR 的成本是 10。因为从 ABR 到目的地的成本是 11,这意味着 R4 的度量是 21。
R4#sh ip route 1.1.1.1
Routing entry for 1.1.1.1/32
Known via "ospf 1", distance 110, metric 21, type inter area
Last update from 24.24.24.2 on FastEthernet0/0, 00:09:37 ago
Routing Descriptor Blocks:
* 34.34.34.3, from 3.3.3.3, 00:09:37 ago, via FastEthernet0/1
Route metric is 21, traffic share count is 1
24.24.24.2, from 2.2.2.2, 00:09:37 ago, via FastEthernet0/0
Route metric is 21, traffic share count is 1
它是哪个。因为这里有两个具有相同成本的 ABR,所以两条路由都安装到 RIB/FIB 中。如果我们将成本增加到一个 ABR,那么只会安装一个条目。
R4#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R4(config)#int f0/0
R4(config-if)#ip ospf cost 11
R4(config-if)#^Z
R4#sh ip route 1.1.1.1
Routing entry for 1.1.1.1/32
Known via "ospf 1", distance 110, metric 21, type inter area
Last update from 34.34.34.3 on FastEthernet0/1, 00:10:58 ago
Routing Descriptor Blocks:
* 34.34.34.3, from 3.3.3.3, 00:10:58 ago, via FastEthernet0/1
Route metric is 21, traffic share count is 1
在 OSPF 中确实没有 AS 的概念,但您可以创建默认路由,然后最佳指标将获胜。如果您想进一步了解 OSPF,我建议您通读RFC 2328和OSPF:互联网路由协议剖析。