cost在路由协议中其实是一个由管理员指定数值的度量。cost在ospf中是唯一的度量值,对于cisco路由器cost的值如果不是管理员手工指定则为100000000/bandwidth.如果接口带宽为100m,则cost=1,也可以手工调整100000000这个参数。如果你愿意也可以用 ip ospf cost xx 命令来手工指定cost的大小。另外,二楼说的少了一个值的应该是MTU,但是二楼说的那么多值一般用于igrp/eigrp路由协议,而且和cost一样都是度量值的一种。而ospf和isis协议度量值一般只有一个就是cost。 |
拓扑为工大瑞普ccnp实验lab17,描述如下:
R1(S1/1)--R2(S1/0),cost=10;R1(S1/2)-framerelay-R4(S1/2),cost=2
R2(S1/1)--R3(S1/0),cost=2,R2(F0/0)--R4(F0/0),cost=2
R3(S1/1)--R4(S1/0),cost=5
R1的F0/0口连接网络192.168.1.0/24,cost=1
R1#show run
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
!
interface Serial1/1
description DCE,OSPF area 0,connected to R2's S1/0,ip 172.16.255.2/30
ip address 172.16.255.1 255.255.255.252
ip ospf cost 10
clock rate 9600
!
interface Serial1/2
description FrameRelay,OSPF area 0,connected to R4's S1/2,ip 172.16.255.14/30
ip address 172.16.255.13 255.255.255.252
encapsulation frame-relay
ip ospf network broadcast
ip ospf cost 2
!
router ospf 100
router-id 1.1.1.1
network 172.16.255.0 0.0.0.3 area 0
network 172.16.255.12 0.0.0.3 area 0
network 192.168.1.0 0.0.0.255 area 2
!
////////////////////
R2#show run
interface FastEthernet0/0
description OSPF area 1,connected to Network 172.16.255.16/30
ip address 172.16.255.17 255.255.255.252
ip ospf cost 2
!
interface Serial1/0
description DTE,OSPF area 0,connected to R1's S1/1,ip 172.16.255.1/30
ip address 172.16.255.2 255.255.255.252
ip ospf cost 10
!
interface Serial1/1
description DCE,OSPF area 1,connected to R3's S1/0,ip 172.16.255.6/30
ip address 172.16.255.5 255.255.255.252
ip ospf cost 2
clock rate 9600
!
router ospf 100
router-id 2.2.2.2
network 172.16.255.0 0.0.0.3 area 0
network 172.16.255.4 0.0.0.3 area 1
network 172.16.255.16 0.0.0.3 area 1
!
////////////////////
R3#show run
interface Serial1/0
description DTE,OSPF area 1,connected to R2's S1/1,ip 172.16.255.5/30
ip address 172.16.255.6 255.255.255.252
ip ospf cost 2
!
interface Serial1/1
description DCE,OSPF area 1,connected to R4's S1/0,ip 172.16.255.10/30
ip address 172.16.255.9 255.255.255.252
ip ospf cost 5
clock rate 9600
!
router ospf 100
router-id 3.3.3.3
network 172.16.255.4 0.0.0.3 area 1
network 172.16.255.8 0.0.0.3 area 1
!
////////////////////
R4#show run
interface FastEthernet0/0
description OSPF area 1,connected to Network 172.16.255.16/30
ip address 172.16.255.18 255.255.255.252
ip ospf cost 2
!
interface Serial1/0
description DTE,OSPF area 1,connected to R3's S1/1,ip 172.16.255.9/30
ip address 172.16.255.10 255.255.255.252
ip ospf cost 5
!
interface Serial1/2
description FrameRelay,OSPF area 0,connected to R1's S1/2,ip 172.16.255.13/30
ip address 172.16.255.14 255.255.255.252
encapsulation frame-relay
ip ospf network broadcast
ip ospf cost 2
!
router ospf 100
router-id 4.4.4.4
network 172.16.255.8 0.0.0.3 area 1
network 172.16.255.12 0.0.0.3 area 0
network 172.16.255.16 0.0.0.3 area 1
!
R3#traceroute 192.168.1.1
1 172.16.255.5 24 msec 68 msec 12 msec
2 172.16.255.1 20 msec * 20 msec
R3#show ip route
172.16.0.0/30 is subnetted, 5 subnets
O IA 172.16.255.0 [110/12] via 172.16.255.5, 00:00:07, Serial1/0
C 172.16.255.4 is directly connected, Serial1/0
C 172.16.255.8 is directly connected, Serial1/1
O IA 172.16.255.12 [110/6] via 172.16.255.5, 00:00:07, Serial1/0
O 172.16.255.16 [110/4] via 172.16.255.5, 00:00:07, Serial1/0
O IA 192.168.1.0/24 [110/7] via 172.16.255.5, 00:00:07, Serial1/0
从R3到达192.168.1.0/24,最少的cost为R3-R2-R4-R1=7,可实际路由为R3-R2-R1=13。为何出现这样的情况?
首先查看R3的ospf database:
R3#show ip ospf data
Router Link States (Area 1)
Link ID ADV Router Age Seq# Checksum Link count
2.2.2.2 2.2.2.2 673 0x80000005 0x003C97 3
3.3.3.3 3.3.3.3 615 0x80000003 0x005569 4
4.4.4.4 4.4.4.4 628 0x80000005 0x00951E 3
Net Link States (Area 1)
Link ID ADV Router Age Seq# Checksum
172.16.255.17 2.2.2.2 673 0x80000002 0x002C22
Summary Net Link States (Area 1)
Link ID ADV Router Age Seq# Checksum
172.16.255.0 2.2.2.2 673 0x80000002 0x001858
172.16.255.0 4.4.4.4 628 0x80000002 0x00EF76
172.16.255.12 2.2.2.2 673 0x80000004 0x00AFB0
172.16.255.12 4.4.4.4 628 0x80000004 0x000F53
192.168.1.0 2.2.2.2 673 0x80000002 0x00FCC1
192.168.1.0 4.4.4.4 628 0x80000002 0x00704E
可以肯定,R4和R2同时向R3通告了192.168.1.0/24的路由
R3#show ip ospf database summary
Routing Bit Set on this LSA
LS age: 886
Options: (No TOS-capability, DC, Upward)
LS Type: Summary Links(Network)
Link State ID: 192.168.1.0 (summary Network Number)
Advertising Router: 2.2.2.2
LS Seq Number: 80000002
Checksum: 0xFCC1
Length: 28
Network Mask: /24
TOS: 0 Metric: 11
Routing Bit Set on this LSA
LS age: 843
Options: (No TOS-capability, DC, Upward)
LS Type: Summary Links(Network)
Link State ID: 192.168.1.0 (summary Network Number)
Advertising Router: 4.4.4.4
LS Seq Number: 80000002
Checksum: 0x704E
Length: 28
Network Mask: /24
TOS: 0 Metric: 3
这里已经出现了两个问题。1、以该通告的cost来计算,R3通过R2(2.2.2.2)到达192.168.1.0/24的总cost为13,通过R4(4.4.4.4)的cost为8,而R3却没有选择R4作为首选ABR;2、R2通告的192.168.1.0/24的cost为11,而不是我们所预计的5。
R3肯定是了解整个拓扑的情况,因为从它的路由表中可以看出,到达192.168.1.0/24的最少cost与理论值一直,为7。因此R3的路由选择并没有错,关键是R2。
R2#show ip route
O IA 192.168.1.0/24 [110/11] via 172.16.255.1, 00:07:39, Serial1/0
无论从这里还是刚才R3接收到的LSA看,R2自身认定192.168.1.0/24的cost为11,并且把该值通知给了R3。但是R3并没有采取该metric,而是通过自身计算,“得出”了“R2应该从R4转发到192.168.1.0/24的数据包”这个结论。关键问题是,R2并没有采纳该结论。
个人感觉实在不应该出现这种问题。可能有人觉得R2的选路出了问题,但我觉得造成次优路由选择错误的不是R2,而是R3。首先,OSPF是一个可划分区域的路由协议。从大局上看,最优路由因该有两个条件。一是区域间最优,即转发数据包从ABR到达另一个ABR,其中骨干内的cost最少;二是区域内最优,即源到ABR,以及ABR到目的地的cost最少。区域与区域间的路由选择是各自独立的,包括骨干区域。现在的情况是,R3干预了区域间及ABR到目的地的区域内两者的选路。因此它得出了R2会通过R4转发数据包这种错误的结论。另外,R2已经通告了它到达192.168.1.0/24的cost为11,R4也通告了cost为3,但R3仍旧选择了R2。当然这是LS routing相对于DV routing的一个进步,即路由器能够了解整个网络拓扑的结构而做出更加正确的决策,只是这里的决策已经越俎代庖了。从实验本身来看,个人觉得最为合理的路由应该是R3-R4-R1,即R3不再了解整网的拓扑,而只是了解本区域的拓扑及各ABR通告的cost,根据这些得出的结论,虽然并非最优的结论,但是会更加合理。
ps:
有朋友要求贴上R2、R4的路由表,若是能够帮助表达我的意思,也就是举手之劳而已。下面是完整的路由表
R4#show ip route
172.16.0.0/30 is subnetted, 5 subnets
O 172.16.255.0 [110/12] via 172.16.255.13, 00:00:04, Serial1/2
O 172.16.255.4 [110/4] via 172.16.255.17, 00:00:54, FastEthernet0/0
C 172.16.255.8 is directly connected, Serial1/0
C 172.16.255.12 is directly connected, Serial1/2
C 172.16.255.16 is directly connected, FastEthernet0/0
O IA 192.168.1.0/24 [110/3] via 172.16.255.13, 00:00:04, Serial1/2
R2#show ip route
172.16.0.0/30 is subnetted, 5 subnets
C 172.16.255.0 is directly connected, Serial1/0
C 172.16.255.4 is directly connected, Serial1/1
O 172.16.255.8 [110/7] via 172.16.255.6, 00:07:09, Serial1/1
[110/7] via 172.16.255.18, 00:07:09, FastEthernet0/0
O 172.16.255.12 [110/12] via 172.16.255.1, 00:06:19, Serial1/0
C 172.16.255.16 is directly connected, FastEthernet0/0
O IA 192.168.1.0/24 [110/11] via 172.16.255.1, 00:06:19, Serial1/0