配置好地址等基本信息,动态路由协议信息,测试互连可达性。
按拓扑规定,配置相应接口的OSPF的链路开销值(cost):
R1(config)#int lo0
R1(config-if)#ip ospf cost 1-------->单向影响,只影响外出路由的度量计算。
R1(config-if)#int s0/0 即影响R1至R2的度量,不影响R2至R1的度量。
R1(config-if)#ip ospf cost 10
R1(config-if)#int s0/1
R1(config-if)#ip ospf cost 2
R1(config-if)#exit
R2(config)#int s0/0
R2(config-if)#ip ospf cost 10
R2(config-if)#int s0/1
R2(config-if)#ip ospf cost 2
R2(config-if)#int s0/2
R2(config-if)#ip ospf cost 2
R2(config-if)#exit
R3(config)#int s0/0
R3(config-if)#ip ospf cost 2
R3(config-if)#int s0/1
R3(config-if)#ip ospf cost 5
R3(config-if)#exit
R4(config)#int s0/0
R4(config-if)#ip ospf cost 2
R4(config-if)#int s0/1
R4(config-if)#ip ospf cost 2
R4(config-if)#int s0/2
R4(config-if)#ip ospf cost 5
R4(config-if)#exit
分析R3到192.168.1.1的路径:
OSPF使用cost值来计算到达目标网络度量,当出现多条冗余路径时,会使用SPF算法进行最佳路由计算与选择最佳路径。
R3到达192.168.1.0/24网络的路径共有如下四条:
编号 路径 cost值
1# R3----->R2----->R1----->目标 13
2# R3----->R2----->R4----->R1----->目标 7
3# R3----->R4----->R1----->目标 8
4# R3----->R4----->R2----->R1----->目标 18
按上述条目看,R3应该会首先选择2#路径,因为2#路径的cost值最小,为验证,查看R3路由表:
R3#show ip route
Gateway of last resort is not set
172.16.0.0/30 is subnetted, 5 subnets
O IA 172.16.255.0 [110/12] via 172.16.255.5, 00:18:16, Serial0/0
C 172.16.255.4 is directly connected, Serial0/0
C 172.16.255.8 is directly connected, Serial0/1
O IA 172.16.255.12 [110/6] via 172.16.255.5, 00:18:16, Serial0/0
O 172.16.255.16 [110/4] via 172.16.255.5, 00:18:16, Serial0/0
192.168.1.0/32 is subnetted, 1 subnets
O IA 192.168.1.1 [110/7] via 172.16.255.5, 00:18:16, Serial0/0
确实如此。
测试有效性:
R3#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/53/88 ms
为确认确实使用2#路径,跟踪查看:
R3#tracer 192.168.1.1
Type escape sequence to abort.
Tracing the route to 192.168.1.1
1 172.16.255.5 32 msec 60 msec 84 msec
2 172.16.255.1 52 msec * 104 msec-------->用的是1#路径
产生这个问题的主要原因是:
当R3 路由器在选择到达R1 的192.168.1.0/24 网络的路由时,使用的确实是SPF 的算法。计算最短最佳路由。因此R3 在比较几条路由器时,会选择从R2,R4,R1 这样的路由,因为其cost 值是7。
当R3 向数据包转发给R2 的时候,R2 发现此数据包是要到达其它网络。因此R2 不会将数据包再转发给其相同区域的其它路由器。因为R2 自己是ABR,他认为到达其它区域的数据包,需要直接转发给骨干区域。而自己也恰巧与骨干区域相连。因此R2 直接将数据包转发给骨干区域的R1 路由器。
总结:
OSPF 区域间的路由,并不是完全根据cost 值计算的最短路径优先算法。而是有点类似于距离矢量的算法。