原理概述

原因

在OSPF的广播和NBMA类型网络中,如果有台路由器,若任意两台路由器之间都要建立邻接关系,则需要建立n*(n-1)/2个邻接关系,即当路由器很多时,则需要建立和维护的邻接关系就很多,两两之间需要发送的报文也就很多,这会造成内容重复的报文在网络中传递,浪费了设备的带宽资源。

定义:

DR(Designated Router,指定路由器),即所有其他路由器都只将各自的链路状态信息发送给DR,再由DR以组播方式发送至所有路由器。
BDR(Backup Designated Router)的概念,作为DR路由器的备份,当DR路由器失效时,BDR成为DR,并再选择新的BDR路由器。其他非DR/BDR路由器都称为DR Other 路由器。

选举DR/BDR的规则:

  • DR优先级,如果DR优先级为0,则不参与选举
  • Router-ID

需要注意的是,DR是在某个广播或者NBMA网段内进行选举的,是针对路由器的接口而言的。某个路由器在一个接口上可能是DR,在另一个接口上可能是BDR,或者是DR Other。

实验内容

网络设备管理与维护OSPF实验DR和BDR的选举 ospf协议dr和bdr的作用_网络

实验拓扑

网络设备管理与维护OSPF实验DR和BDR的选举 ospf协议dr和bdr的作用_OSPF_02


网络设备管理与维护OSPF实验DR和BDR的选举 ospf协议dr和bdr的作用_OSPF_03

实验步骤

1.配置路由器接口地址和环回接口地址
2.配置ospf网络

[R1]router id 1.1.1.1
[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]net  172.16.1.0   0.0.0.255


[R2]router id 2.2.2.2
[R2]ospf  1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]net 172.16.1.0   0.0.0.255

[R3]router id 3.3.3.3
[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]net 172.16.1.0   0.0.0.255

[R4]router id 4.4.4.4
[R4]ospf 1
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]net 172.16.1.0 0.0.0.255

配置完成后,同时重启4台路由器上的OSPF进程,或者直接同时重启路由器。

<R1>reset ospf process 
<R2>reset ospf process 
<R3>reset ospf process 
<R4>reset ospf process

使用display ospf peer brief查看OSPF邻居建立情况

[R1]dis ospf peer brief 

 OSPF Process 1 with Router ID 1.1.1.1
	  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/0             2.2.2.2          2-Way       
 0.0.0.0          GigabitEthernet0/0/0             3.3.3.3          Full        
 0.0.0.0          GigabitEthernet0/0/0             4.4.4.4          Full        
 ----------------------------------------------------------------------------
 
 可以观察到,R1已经和其他路由器成功建立起OSPF邻居关系。

查看DR/BDR状态

[R1]dis ospf peer 

 OSPF Process 1 with Router ID 1.1.1.1
	 Neighbors 

 Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 2.2.2.2          Address: 172.16.1.2      
   State: 2-Way  Mode:Nbr is  Master  Priority: 1
   DR: 172.16.1.4  BDR: 172.16.1.3  MTU: 0    
   Dead timer due in 31  sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:00:00     
   Authentication Sequence: [ 0 ] 

 Router ID: 3.3.3.3          Address: 172.16.1.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 172.16.1.4  BDR: 172.16.1.3  MTU: 0    
   Dead timer due in 35  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:05:13     
   Authentication Sequence: [ 0 ] 

 Router ID: 4.4.4.4          Address: 172.16.1.4      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 172.16.1.4  BDR: 172.16.1.3  MTU: 0    
   Dead timer due in 36  sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:05:13     
   Authentication Sequence: [ 0 ] 

可以观察到,R4为DR,R3为BDR。这是由于在默认情况下,每台路由器上的DR优先级都为1,此时是通过Router-ID的数值高低比较的。

3.验证网络类型点到多点的选举情况

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ospf network-type p2mp
	
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ospf network-type p2mp
	
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ospf network-type p2mp
	
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ospf network-type p2mp

在R1上再次观察此时OSPF的选举情况

[R1]dis ospf peer 

 OSPF Process 1 with Router ID 1.1.1.1
	 Neighbors 

 Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 2.2.2.2          Address: 172.16.1.2      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: None   BDR: None   MTU: 0    
   Dead timer due in 112 sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:01:50     
   Authentication Sequence: [ 0 ] 

 Router ID: 3.3.3.3          Address: 172.16.1.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: None   BDR: None   MTU: 0    
   Dead timer due in 101 sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:00:47     
   Authentication Sequence: [ 0 ] 

 Router ID: 4.4.4.4          Address: 172.16.1.4      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: None   BDR: None   MTU: 0    
   Dead timer due in 103 sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:00:47     
   Authentication Sequence: [ 0 ] 
   
可以观察到,DR/BDR都为None,验证了在点到多点的网络类型中不选举DR/BDR。在点到点的网络中也是。

4.根据网络需求影响DR/BDR选举
根据需求,需要使性能较好、处理能力较强的R1成为DR,性能次之的R2成为BDR,而性能最差的R4不能参加选举。

首先将OSPF网络类型还原为默认的广播网络类型

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ospf network-type  broadcast
	
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ospf network-type  broadcast
	
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ospf network-type  broadcast
	
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ospf network-type  broadcast

配置完成后,修改R1上的接口的DR优先级为100,R2为50,R4为0,R3保持默认不变

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ospf dr-priority 100

[R2]int g0/0/0	
[R2-GigabitEthernet0/0/0]ospf dr-priority 50

[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ospf dr-priority 0

配置完成后,查看路由器的DR/BDR选举情况

[R1]dis ospf peer 
 OSPF Process 1 with Router ID 1.1.1.1
	 Neighbors 
	 
 Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 2.2.2.2          Address: 172.16.1.2      
   State: Full  Mode:Nbr is  Master  Priority: 50
   DR: 172.16.1.3  BDR: 172.16.1.1  MTU: 0    
   Dead timer due in 34  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:01:08     
   Authentication Sequence: [ 0 ] 
 Router ID: 3.3.3.3          Address: 172.16.1.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 172.16.1.3  BDR: 172.16.1.1  MTU: 0    
   Dead timer due in 34  sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:03:11     
   Authentication Sequence: [ 0 ] 
 Router ID: 4.4.4.4          Address: 172.16.1.4      
   State: Full  Mode:Nbr is  Master  Priority: 0
   DR: 172.16.1.3  BDR: 172.16.1.1  MTU: 0    
   Dead timer due in 29  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:01:03     
   Authentication Sequence: [ 0 ] 

发现此时的DR与BDR都没有改变,即验证了OSPF的选举是非抢占性的。

同时重启4台路由器的OSPF进程,或者直接同时重启路由器。

[R1]dis ospf peer

 OSPF Process 1 with Router ID 1.1.1.1
	 Neighbors 
	 
 Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 2.2.2.2          Address: 172.16.1.2      
   State: Full  Mode:Nbr is  Master  Priority: 50
   DR: 172.16.1.1  BDR: 172.16.1.2  MTU: 0    
   Dead timer due in 31  sec 
   Retrans timer interval: 4 
   Neighbor is up for 00:00:23     
   Authentication Sequence: [ 0 ] 
 Router ID: 3.3.3.3          Address: 172.16.1.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 172.16.1.1  BDR: 172.16.1.2  MTU: 0    
   Dead timer due in 33  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:00:23     
   Authentication Sequence: [ 0 ] 
 Router ID: 4.4.4.4          Address: 172.16.1.4      
   State: Full  Mode:Nbr is  Master  Priority: 0
   DR: 172.16.1.1  BDR: 172.16.1.2  MTU: 0    
   Dead timer due in 33  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:00:13     
   Authentication Sequence: [ 0 ] 

此时在该广播网络中,R1为DR,R2为BDR。

实验目的

  • 理解OSPF在哪种网络类型中会选举DR/BDR
  • 掌握OSPF DR/BDR的选举规则
  • 掌握如何更改设备接口上的DR优先级
  • 理解OSPF DR/BDR选举的非抢占性特性