由ITAA reeper作
关于OSPFCOST 扩展研究(参考实验手册3.4):<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><?XML:NAMESPACE PREFIX = O />

本实验拓扑图如下:

<?:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><?XML:NAMESPACE PREFIX = V /> 

2006-10-31_113646_ospf.jpg

实验目的:

<1> 正确配置,完成OSPF基本选路:

R3到达<?:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><?XML:NAMESPACE PREFIX = ST1 />12.1.1.0/24 这一网络 ,S1/0S2/0实现负载均衡
 

<2> 更改R2S2/0 端口的COST:110;

         R1S1/0端口的COST:100;

影响R3到达12.1.1.0/24 的选路,说明OSPF更改COST可以影响到别人
 

<3> R1S2/0端口DOWN,R3自动切换到R2到达12.1.1.0/24,查看OSPF数据库,

      R2R3LSA-1,包含了R2的各端口的 地址/对端接口/地址/链路开销……
 

<4> 扩展: R1上加一台路由器R4, R3到达4.4.4.0/24网络必须经过R2,R1,R4.

那这里R3要到达4.4.4.0/24的网络,是用R2S2/0端口开销记算呢? 还是R1S1/0 ?

反之,R4要到3.3.3.0/24 网络,又用哪个COST计算的呢?
 

<5> 总结OSPF 计算COST的值的步骤, 理解OSPF选路
 

目的一, R3实现负载均衡:

Gateway of last resort is not set

         1.0.0.0/32 is subnetted, 1 subnets

O       1.1.1.1 [110/65] via 13.1.1.1, 00:00:36, Serial1/0

         2.0.0.0/32 is subnetted, 1 subnets

O       2.2.2.2 [110/65] via 23.1.1.2, 00:00:36, Serial2/0

         3.0.0.0/24 is subnetted, 1 subnets

C       3.3.3.0 is directly connected, Loopback0

         23.0.0.0/24 is subnetted, 1 subnets

C       23.1.1.0 is directly connected, Serial2/0

          12.0.0.0/24 is subnetted, 1 subnets

O        12.1.1.0 [110/128] via 23.1.1.2, 00:00:36, Serial2/0

                      [110/128] via 13.1.1.1, 00:00:36, Serial1/0

          13.0.0.0/24 is subnetted, 1 subnets

C       13.1.1.0 is directly connected, Serial1/0

 配置完成,正确选路.开销为64+64=128
 
目的二, 分别更改R1R2 12.1.1.0/24 网络的COST, 影响R3选路:

R2(config)#int s2/0

R2(config-if)#ip ospf cost 110

R1(config)#int s1/0

R1(config-if)#ip ospf cost 100

毫无疑问,这里R3到达12.1.1.0/24 网络要通过COST小的,也就是R1.

       R3#     12.0.0.0/24 is subnetted, 1 subnets

O       12.1.1.0 [110/164] via 13.1.1.1, 00:24:14, Serial1/0

    这证明:

OSPP里所有路由器的动作,是计算自己所有OSPF接口/链路的COST,并通过

LSA-1通告出去! 同时把受到的到达各个网络的COST (包括自己链路) 相加,

选择最优的装进路由表.
 

     

 
目的三, 我们先来看一下OSPF的数据库, 了解LSA-1里面的一些内容:

     R3#show ip ospf database router

                OSPF Router with ID (3.3.3.3) (Process ID 10)

                     Router Link States (Area 0)

        LS age: 556

        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: 80000007

        Checksum: 0x5BEE

        Length: 84

        Number of Links: 5

     

        Link connected to: a Stub Network

         (Link ID) Network/subnet number: 12.1.1.0

         (Link Data) Network Mask: 255.255.255.0

         Number of TOS metrics: 0

            TOS 0 Metrics: 100

     

   LS age: 1168

        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: 80000005

        Checksum: 0xCB4E

        Length: 84

        Number of Links: 5

       Link connected to: a Stub Network

        (Link ID) Network/subnet number: 12.1.1.0

        (Link Data) Network Mask: 255.255.255.0

        Number of TOS metrics: 0

          TOS 0 Metrics: 110

R3 只是提取到同一网络最小 Metrics,再和自己计算的链路COST, 做累加

100+64=164,装进路由表!
 

目的四, R1上加一台路由R4, 相当于:R4=>R1=>R2=>R3 串连, 拓扑如下:
2006-10-31_115038_ospf2.jpg

R4正确配置, DOWNR1S2/0端口,现在我们来看一下, R4到达3.3.3.0/24网络,
采用的是R1100? 还是R2110 ? 反之, R34.4.4.0/24 ?

R4通过E0/0 连接R1, 并宣告进OSPF区域0:

R4#

router ospf 10

      router-id 4.4.4.4

network 4.4.4.0 0.0.0.255 area 0

      network 14.1.1.0 0.0.0.255 area 0

  

R4#show ip route
 Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets

O       1.1.1.1 [110/11] via 14.1.1.1, 00:05:49, Ethernet0/0

     2.0.0.0/32 is subnetted, 1 subnets

O       2.2.2.2 [110/111] via 14.1.1.1, 00:05:49, Ethernet0/0

     3.0.0.0/32 is subnetted, 1 subnets

O       3.3.3.3 [110/175] via 14.1.1.1, 00:05:49, Ethernet0/0

     4.0.0.0/24 is subnetted, 1 subnets

C       4.4.4.0 is directly connected, Loopback0

     23.0.0.0/24 is subnetted, 1 subnets

O       23.1.1.0 [110/174] via 14.1.1.1, 00:05:49, Ethernet0/0

     12.0.0.0/24 is subnetted, 1 subnets

O       12.1.1.0 [110/110] via 14.1.1.1, 00:05:49, Ethernet0/0

     14.0.0.0/24 is subnetted, 1 subnets

C       14.1.1.0 is directly connected, Ethernet0/0

R3#show ip route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets

O       1.1.1.1 [110/175] via 23.1.1.2, 00:07:02, Serial2/0

     2.0.0.0/32 is subnetted, 1 subnets

O       2.2.2.2 [110/65] via 23.1.1.2, 00:07:02, Serial2/0

     3.0.0.0/24 is subnetted, 1 subnets

C       3.3.3.0 is directly connected, Loopback0

     4.0.0.0/32 is subnetted, 1 subnets

O       4.4.4.4 [110/185] via 23.1.1.2, 00:07:02, Serial2/0

     23.0.0.0/24 is subnetted, 1 subnets

C       23.1.1.0 is directly connected, Serial2/0

     12.0.0.0/24 is subnetted, 1 subnets

O       12.1.1.0 [110/174] via 23.1.1.2, 00:07:02, Serial2/0

     14.0.0.0/24 is subnetted, 1 subnets

O       14.1.1.0 [110/184] via 23.1.1.2, 00:07:03, Serial2/0

结论:

R4=>R1=>R2=>R3

COST=10+100+64+1

R3=>R2=>R1=>R4

COST=64+110+10+1
 
 

,实验总结:

任何OSPF路由器,都是以自己为根, 通过链路状态, 计算出一棵树!

实验证明了COST值的累加,这里又有点距离矢量加跳数的意思. 错!

这个累加和(175)只是R4自己的动作! 所累加的每个COST值是每台路由器通告的最原始的!

对于R4而言, 自己为根, 最近的枝就是R1,通过R1S1/0端口到达12.1.1.0/24,

以及后面的网络, 就算R2LSA里的Metrics再小也不会采用!

R3则相反,反之亦然!

总结一句, 更改COST值时, 以目的网络为参考点, 所做的COST/参数改动,只对

其上游路由器 (包括本路由) 选路起作用!!!