频道栏目
首页 > 资讯 > 网络协议 > 正文

OSPF协议中cost值的计算

11-12-15        来源:[db:作者]  
收藏   我要投稿

 

在ospf协议中每个接口根据其速率不同,都有一个默认的公式计算的cost值,ospf协议采用cost值来决定到达目的地的最佳路径,如果存在多条到达目的地的路径,优先选用cost值最低的路径。Cost值的计算是沿目的地途中所有转发数据的接口的cost值的总和,下面通过实验来验证一下。

如下拓扑图:

 

 

在RT11上的路由表如下:

rt11#sh 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

 

     172.19.0.0/24 is subnetted, 1 subnets

O       172.19.10.0 [110/3] via 10.1.1.6, 00:00:12, FastEthernet2/0

     10.0.0.0/30 is subnetted, 2 subnets

O       10.3.3.4 [110/2] via 10.1.1.6, 00:00:12, FastEthernet2/0

C       10.1.1.4 is directly connected, FastEthernet2/0

C    192.168.1.0/24 is directly connected, FastEthernet0/0

C    192.168.2.0/24 is directly connected, FastEthernet0/1

在这台路由器上到达172.19.10.0的度量值为3,计算方式为:

RT11的数据转发接口f2/0的cost值“1”+RT12的数据转发接口f2/0的cost值“1”+sw2的目标接口vlan1的cost值“1”=3。

为了证明,将RT12的数据流入接口f0/0的cost值改为50,数据转发接口f2/0的cost值改为60,sw2的vlan1的cost改为70,再来看看路由表:

rt11#sh 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

 

     172.19.0.0/24 is subnetted, 1 subnets

O       172.19.10.0 [110/131] via 10.1.1.6, 00:00:00, FastEthernet2/0

     10.0.0.0/30 is subnetted, 2 subnets

O       10.3.3.4 [110/61] via 10.1.1.6, 00:00:00, FastEthernet2/0

C       10.1.1.4 is directly connected, FastEthernet2/0

C    192.168.1.0/24 is directly connected, FastEthernet0/0

C    192.168.2.0/24 is directly connected, FastEthernet0/1

这时到达172.19.10.0的度量值为131了,由1+60+70计算得来,RT12上的数据流入接口f0/0的cost值没有参与计算。

那么再看从SW1上的路由表:

sw2#sh 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

 

     172.19.0.0/24 is subnetted, 1 subnets

C       172.19.10.0 is directly connected, Vlan1

     10.0.0.0/30 is subnetted, 2 subnets

C       10.3.3.4 is directly connected, Vlan2

O       10.1.1.4 [110/51] via 10.3.3.5, 00:00:00, Vlan2

O    192.168.1.0/24 [110/52] via 10.3.3.5, 00:00:00, Vlan2

O    192.168.2.0/24 [110/52] via 10.3.3.5, 00:00:00, Vlan2

从这个路由表上就更加验证了ospf协议中度量值的计算,从sw1到192.168.1.0的度量值计算为:

Sw1的数据转发接口vlan2的cost值“1”+RT12的数据转发接口f0/0的cost值“50”+RT11的目的接口的cost值“1”=52

那么针对重发布的路由的度量值又是如何计算的呢,在RT11上将两个直连网络192.168.1.0和192.168.2.0改为重发布:

配置命令:

access-list 10 permit 192.168.1.0

access-list 20 permit 192.168.2.0

!

route-map setmetric permit 10

 match ip address 10

 set metric 5

!

route-map setmetric permit 20

 match ip address 20

 set metric 20

 

router ospf 100

 log-adjacency-changes

 redistribute connected subnets route-map setmetric

这样就将192.168.1.0的度量值改为了5,192.168.2.0的度量值改为了20,在rt12和SW1上查看路由表:

rt12#sh 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

 

     172.19.0.0/24 is subnetted, 1 subnets

O       172.19.10.0 [110/130] via 10.3.3.6, 00:04:08, FastEthernet2/0

     10.0.0.0/30 is subnetted, 2 subnets

C       10.3.3.4 is directly connected, FastEthernet2/0

C       10.1.1.4 is directly connected, FastEthernet0/0

O E2 192.168.1.0/24 [110/5] via 10.1.1.5, 00:04:08, FastEthernet0/0

O E2 192.168.2.0/24 [110/20] via 10.1.1.5, 00:04:08, FastEthernet0/0

 

sw2#sh 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

 

     172.19.0.0/24 is subnetted, 1 subnets

C       172.19.10.0 is directly connected, Vlan1

     10.0.0.0/30 is subnetted, 2 subnets

C       10.3.3.4 is directly connected, Vlan2

O       10.1.1.4 [110/51] via 10.3.3.5, 00:04:32, Vlan2

O E2 192.168.1.0/24 [110/5] via 10.3.3.5, 00:04:32, Vlan2

O E2 192.168.2.0/24 [110/20] via 10.3.3.5, 00:04:32, Vlan2

RT12和SW1的路由表中,到达192.168.1.0和192.168.2.0的度量值和重发布时指定的度量值是一致的,那么就说明重发布时的度量值与接口的cost值是无关的。

了解了cost值的计算,可以在具有冗余的路径的环境下合理的修改cost值,来控制数据的转发路径。

本文出自 “活着” 博客

相关TAG标签
上一篇:ARP报文归属问题
下一篇:相同VLAN跨交换机通信
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站