OSPF实验2DR/BDR的选取(转载)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

实验级别: Professional

 

 

情况一:

 

   我们都知道 OSPF 选取 DR 的过程是首先比较优先级,在优先级相同的情况下选择 RID 较高的为 DR ,但是我多次实验后发现在很多时候 DR 并非 RID 最高的路由器,这是什么原因呢?

    在翻阅了卷一有关 OSPF DR 选取的介绍时,发现了这么一句话: 在一个多址网络上,最先初始化启动的两台具有 DR 选取资格的路由器将成为 DR BDR 路由器。 这是我总结了非最高 RID 而成为 DR 的实验,发现这些路由器都是我在进行 OSPF 配置的时候首先启动 ospf 的路由器,那会不会是因为这些路由器首先启动了 OSPF ,然后把自己设置为 DR 导致其他路由器启动 OSPF 后就不再进行 DR 的选取了呢?于是我做了下面的这个实验。

 

    实验的 topo 很简单,我就不画了,就是两台路由器通过 fa0/0 口相连接。
R1:
conf t
ho R1
int lo0
ip add <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1.1.1.1 255.255.255.0
int fa0/0
ip add 172.1.1.1 255.255.255.0
no sh
router ospf 10
net 172.1.1.1 0.0.0.0 a 0

R2:
conf t
ho R2
int lo0
ip add 2.2.2.2 255.255.255.0
int fa0/0
ip add 172.1.1.2 255.255.255.0
no sh

R1 启动 ospf 进程后,我们在 R2 上暂时先不开启 ospf ,在 R1 上发现了以下信息:

 

R1#sho ip ospf int
FastEthernet0/0 is up, line protocol is up
  Internet Address 172.1.1.1/24, Area 0
  Process ID 10, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec,
State DR , Priority 1
  Designated Router (ID) 1.1.1.1, Interface address 172.1.1.1
  No backup designated router on this network
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:01
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 0, maximum is 0
  Last flood scan time is 0 msec, maximum is 0 msec
  Neighbor Count is 0, Adjacent neighbor count is 0
  Suppress hello for 0 neighbor(s)

 

    我们看到 R1 已经把自己设定为 DR 了,按照 OSPF 的规则,新加入的路由器即使 RID DR 高,也不会替换 DR 。这就说明了为什么在有些时候 DR 并非 RID 最高的路由器。

 

    当然这个实验也顺便验证了 ospf DR 选取结束后,除非 DR 路由器出现故障,否则就是有更高优先级或者 RID 的路由器进入 OSPF 进程,也是无法改变 DR 的。既 DR 是不可以抢夺的! <?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />

 

情况二(本实验参照了 ITAA 实验室 Netfish 的实验):

    ospf 中有一个 Wait Timer 计时器,在这个计时器所限定的时间内起来的 OSPF 可以视为同时起机。

  

  TCP/IP 1 292 页对于这个时间间隔是这样定义的:

    Wait Timer: 在开始选举 DR BDR 之间,路由器等待邻居路由器的 Hello 数据包通告 DR BDR 的时长。长度就是 RouterDeadInterval 的时间。

 

    本实验拓扑与情况一相同,不同的地方在于当我们在 R1 上启动 OSPF 后, 迅速 (一定要迅速,非常迅速! 40s 之内)在 R2 上也启动 ospf ,通过 debug 信息可以看到以下情况:

R1#debug ip ospf adj
OSPF adjacency events debugging is on
R1#debug ip ospf ev
OSPF events debugging is on

*Aug 14 00:56:19.047: OSPF: Interface FastEthernet0/0 going Up
*Aug 14 00:56:19.051: OSPF: Send hello to 224.0.0.5 area 0 on FastEthernet0/0 from 172.1.1.1
*Aug 14 00:56:19.551: OSPF: Build router LSA for area 0, router ID 1.1.1.1, seq 0x80000001
*Aug 14 00:56:19.555: OSPF: Rcv hello from 2.2.2.2 area 0 from FastEthernet0/0 172.1.1.2
*Aug 14 00:56:19.555: OSPF: End of hello processing
R1(config-router)#
*Aug 14 00:56:29.051: OSPF: Send hello to 224.0.0.5 area 0 on FastEthernet0/0 from 172.1.1.1
*Aug 14 00:56:29.451: OSPF: Rcv hello from 2.2.2.2 area 0 from FastEthernet0/0 172.1.1.2
*Aug 14 00:56:29.455: OSPF: 2 Way Communication to 2.2.2.2 on FastEthernet0/0, state 2WAY
*Aug 14 00:56:29.455: OSPF: End of hello processing
R1(config-router)#
*Aug 14 00:56:39.051: OSPF: Send hello to 224.0.0.5 area 0 on FastEthernet0/0 from 172.1.1.1
*Aug 14 00:56:39.427: OSPF: Rcv hello from 2.2.2.2 area 0 from FastEthernet0/0 172.1.1.2
*Aug 14 00:56:39.427: OSPF: End of hello processing
R1(config-router)#
*Aug 14 00:56:49.051: OSPF: Send hello to 224.0.0.5 area 0 on FastEthernet0/0 from 172.1.1.1
*Aug 14 00:56:49.447: OSPF: Rcv hello from 2.2.2.2 area 0 from FastEthernet0/0 172.1.1.2
*Aug 14 00:56:49.447: OSPF: End of hello processing
R1(config-router)#
*
Aug 14 00:56:59.051: OSPF: end of Wait on interface FastEthernet0/0
*Aug 14 00:56:59.051: OSPF: DR/BDR election on FastEthernet0/0
*Aug 14 00:56:59.051: OSPF: Elect BDR 2.2.2.2
*Aug 14 00:56:59.055: OSPF: Elect DR 2.2.2.2
*Aug 14 00:56:59.055:        DR: 2.2.2.2 (Id)   BDR: 2.2.2.2 (Id)

*Aug 14 00:56:59.055: OSPF: Send DBD to 2.2.2.2 on FastEthernet0/0 seq 0x826 opt 0x52 flag 0x7 len 32
*Aug 14 00:56:59.059: OSPF: Send hello to 224.0.0.5 area 0 on FastEthernet0/0 from 172.1.1.1
*Aug 14 00:56:59.459: OSPF: Rcv hello from 2.2.2.2 area 0 from FastEthernet0/0 172.1.1.2
*Aug 14 00:56:59.463: OSPF: Neighbor change Event on interface FastEthernet0/0
*Aug 14 00:56:59.463: OSPF: DR/BDR election on FastEthernet0/0
*Aug 14 00:56:59.463: OSPF: Elect BDR 1.1.1.1
*Aug 14 00:56:59.467: OSPF: Elect DR 2.2.2.2
*Aug 14 00:56:59.467: OSPF: Elect BDR 1.1.1.1
*Aug 14 00:56:59.467: OSPF: Elect DR 2.2.2.2
*Aug 14 00:56:59.471:        DR: 2.2.2.2 (Id)   BDR: 1.1.1.1 (Id)

 

这个时候我们发现两个路由器进行了 DR/BDR 的选取,并且结论和书上介绍的完全一致。

 

Debug 信息的时间上来看,从启动 OSPF 进程到开始选举 DR DBR 的时间间隔是 40 ,在这个时间段内,无论 R1 还是 R2 并没有选举 DR DBR

 

RFC2328 中对这个时间间隔的定义如下:
Wait Timer
        A single shot timer that causes the interface to exit the
        Waiting state, and as a consequence select a Designated Router
        on the network.  The length of the timer is RouterDeadInterval
        seconds.

 

因为在广播链路中的 RouterDeadInterval 40 秒,所以我们看到的这个时间间隔为 40 秒。

 

结论:

      并不是先启动 OSPF 进程的路由器就是 DR ,而是有一个时间间隔让路由器来等待其他路由器,在这个时间间隔内,路由器相互监听 Hello 包中的 DR DBR 字段中的信息,并且服从优先级原则,可以这样认为 —— 选举是公平的。

 

 

实际情况:

      在实际的网络中,即使是 40 秒内同时起进程的情况也少见;实际情况下是率先启用 ospf 进程的路由器就很有可能成为 DR ,第二个启动的就很有可能成为 BDR ,考虑到路由器故障或者重启等情况,实际的运行效果是: 得最久的路由器成为 DR (比多长时间不重起) .