9.6 OSPF的DR与BDR
9.6.1 原理概述
在OSPF的广播类型网络和NBMA类型网络中,如果网络中有n台路由器,若任意两台路由器之间都要建立邻接关系,则需要建立n×(n-1)/2个邻接关系,即当路由器很多时,则需要建立和维护的邻接关系就很多,两两之间需要发送的报文也就很多,这会造成很多内容重复的报文在网络中传递,浪费了设备的带宽资源。因此在广播和NBMA类型网络中,OSPF协议定义了指定路由器DR(Designated Router),即所有其他路由器都只将各自的链路状态信息发送给DR,再由DR以组播方式发送至所有路由器,大大减少了OSPF数据包的发送。
但是如果DR由于某种故障而失效,此时网络中必须重新选举DR,并同步链路状态信息,这需要较长的时间。为了能够缩短这个过程,OSPF协议又定义了BDR(BackupDesignated Router)的概念,作为DR路由器的备份,当DR路由器失效时,BDR成为DR,并再选择新的BDR路由器。其他非DR/BDR路由器都称为DR Other路由器。
每一个含有至少两个路由器的广播类型网络或NBMA类型网络都会选举一个DR和BDR。选举规则是首先比较DR优先级,优先级高者成为DR,次高的成为BDR。如果优先级相等,则Router-ID数值高的成为DR,次高的成为BDR。如果一台路由器的DR优先级为0,则不参与选举。需要注意的是,DR是在某个广播或者NBMA网段内进行选举的,是针对路由器的接口而言的。某台路由器在一个接口上可能是DR,在另一个接口上有可能是BDR,或者是DR Other。
若DR、BDR已经选举完毕,人为修改任何一台路由器的DR优先级值为最大,也不会抢占成为新的DR或BDR,即OSPF的DR/BDR选举是非抢占的。
9.6.2 实验内容
某公司有4个部门,路由器R1连接到总经理办公室,路由器R2连接到人事部,R3连接到开发部,R4连接到市场部。4台路由器通过交换机S1互联,每台路由器都运行了OSPF路由协议,都运行在区域0内,使得公司内部各部门网络能够互相通信。由于路由器通过广播网络互连,OSPF会选举DR和BDR,现网络管理员要配置使得性能较好的R1成为DR,性能次之的R2成为BDR,而性能最差的R4不能参加DR和BDR的选举,由此来完成网络的优化。
9.6.3 实验拓扑
9.6.4 实验编址
设备 | 接口 | IP地址 | 子网掩码 | 默认网关 |
---|---|---|---|---|
AR1(AR2220) | GE 0/0/0 | 172.16.1.1 | 255.255.255.248 | N/A |
AR1(AR2220) | GE 0/0/1 | 192.168.10.254 | 255.255.255.0 | N/A |
AR1(AR2220) | Loopback 0 | 1.1.1.1 | 255.255.255.255 | N/A |
AR2(AR2220) | GE 0/0/0 | 172.16.1.2 | 255.255.255.248 | N/A |
AR2(AR2220) | GE 0/0/1 | 192.168.20.254 | 255.255.255.0 | N/A |
AR2(AR2220) | Loopback 0 | 2.2.2.2 | 255.255.255.255 | N/A |
AR3(AR2220) | GE 0/0/0 | 172.16.1.3 | 255.255.255.248 | N/A |
AR3(AR2220) | GE 0/0/1 | 192.168.30.254 | 255.255.255.0 | N/A |
AR3(AR2220) | Loopback 0 | 3.3.3.3 | 255.255.255.255 | N/A |
AR4(AR2220) | GE 0/0/0 | 172.16.1.4 | 255.255.255.248 | N/A |
AR4(AR2220) | GE 0/0/1 | 192.168.40.254 | 255.255.255.0 | N/A |
AR4(AR2220) | Loopback 0 | 4.4.4.4 | 255.255.255.255 | N/A |
PC1 | Ethernet 0/0/1 | 192.168.10.1 | 255.255.255.0 | 192.168.10.254 |
PC2 | Ethernet 0/0/1 | 192.168.20.1 | 255.255.255.0 | 192.168.20.254 |
PC3 | Ethernet 0/0/1 | 192.168.30.1 | 255.255.255.0 | 192.168.30.254 |
PC4 | Ethernet 0/0/1 | 192.168.40.1 | 255.255.255.0 | 192.168.40.254 |
9.6.5 实验步骤
1、基本配置
根据实验编址表进行相应的基本IP地址配置和OSPF配置,并重启OSPF进程。
[AR1]interface GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ip address 172.16.1.1 29
[AR1-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR1-GigabitEthernet0/0/1]ip address 192.168.10.254 24
[AR1-GigabitEthernet0/0/1]interface loopback 0
[AR1-LoopBack0]ip address 1.1.1.1 32
[AR1-LoopBack0]router id 1.1.1.1 # 设置环回地址作为Router-ID
Info: Router ID has been modified, please reset the relative protocols manually to update the Router ID.
[AR1]ospf 1
[AR1-ospf-1]area 0
[AR1-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.7
[AR1-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[AR1-ospf-1-area-0.0.0.0]return
<AR1>reset ospf process # 重启OSPF进程
Warning: The OSPF process will be reset. Continue? [Y/N]:y[AR2]interface GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip address 172.16.1.2 29
[AR2-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip address 192.168.20.254 24
[AR2-GigabitEthernet0/0/1]interface loopback 0
[AR2-LoopBack0]ip address 2.2.2.2 32
[AR2-LoopBack0]router id 2.2.2.2
Info: Router ID has been modified, please reset the relative protocols manually to update the Router ID.
[AR2]ospf 1
[AR2-ospf-1]area 0
[AR2-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.7
[AR2-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[AR2-ospf-1-area-0.0.0.0]return
<AR2>reset ospf process
Warning: The OSPF process will be reset. Continue? [Y/N]:y[AR3]interface GigabitEthernet 0/0/0
[AR3-GigabitEthernet0/0/0]ip address 172.16.1.3 29
[AR3-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR3-GigabitEthernet0/0/1]ip address 192.168.30.254 24
[AR3-GigabitEthernet0/0/1]interface loopback 0
[AR3-LoopBack0]ip address 3.3.3.3 32
[AR3-LoopBack0]router id 3.3.3.3
Info: Router ID has been modified, please reset the relative protocols manually to update the Router ID.
[AR3]ospf 1
[AR3-ospf-1]area 0
[AR3-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.7
[AR3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[AR3-ospf-1-area-0.0.0.0]return
<AR3>reset ospf process
Warning: The OSPF process will be reset. Continue? [Y/N]:y[AR4]interface GigabitEthernet 0/0/0
[AR4-GigabitEthernet0/0/0]ip address 172.16.1.4 29
[AR4-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR4-GigabitEthernet0/0/1]ip address 192.168.40.254 24
[AR4-GigabitEthernet0/0/1]interface loopback 0
[AR4-LoopBack0]ip address 4.4.4.4 32
[AR4-LoopBack0]router id 4.4.4.4
Info: Router ID has been modified, please reset the relative protocols manually to update the Router ID.
[AR4]ospf 1
[AR4-ospf-1]area 0
[AR4-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.7
[AR4-ospf-1-area-0.0.0.0]network 192.168.40.0 0.0.0.255
[AR4-ospf-1-area-0.0.0.0]return
<AR4>reset ospf process
Warning: The OSPF process will be reset. Continue? [Y/N]:y
配置完成后检查OSPF的邻居建立转态,使用display ospf peer brief
命令进行查看 。其他设备省略。
[AR1]display ospf peer briefOSPF Process 1 with Router ID 1.1.1.1Peer Statistic Information----------------------------------------------------------------------------Area Id Interface Neighbor id State 0.0.0.0 GigabitEthernet0/0/0 2.2.2.2 Full 0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full 0.0.0.0 GigabitEthernet0/0/0 4.4.4.4 Full ----------------------------------------------------------------------------
2、查看默认情况下的DR/BDR状态
使用display ospf peer
命令查看此时默认情况下ospf网络中的DR/BDR选举情况。
[AR1]display ospf peerOSPF Process 1 with Router ID 1.1.1.1Neighbors Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighborsRouter ID: 2.2.2.2 Address: 172.16.1.2 State: Full Mode:Nbr is Master Priority: 1DR: 172.16.1.1 BDR: 172.16.1.2 MTU: 0 Dead timer due in 34 sec Retrans timer interval: 5 Neighbor is up for 00:34:29 Authentication Sequence: [ 0 ] Router ID: 3.3.3.3 Address: 172.16.1.3 State: Full Mode:Nbr is Master Priority: 1DR: 172.16.1.1 BDR: 172.16.1.2 MTU: 0 Dead timer due in 34 sec Retrans timer interval: 5 Neighbor is up for 00:26:06 Authentication Sequence: [ 0 ] Router ID: 4.4.4.4 Address: 172.16.1.4 State: Full Mode:Nbr is Master Priority: 1DR: 172.16.1.1 BDR: 172.16.1.2 MTU: 0 Dead timer due in 32 sec Retrans timer interval: 5 Neighbor is up for 00:15:30 Authentication Sequence: [ 0 ]
可以观察到此时的网络中,R1是DR,R2是BDR。
接下来在每台设备上的相关接口下使用ospf ntwork-type p2mp命令修改OSPF的网络类型为点对多点。
[AR1]interface GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ospf network-type p2mp[AR2]interface GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ospf network-type p2mp[AR3]interface GigabitEthernet 0/0/0
[AR3-GigabitEthernet0/0/0]ospf network-type p2mp[AR4]interface GigabitEthernet 0/0/0
[AR4-GigabitEthernet0/0/0]ospf network-type p2mp
再次查看R1上面的OSPF的DR/BDR选举情况。
[AR1]display ospf peerOSPF Process 1 with Router ID 1.1.1.1Neighbors Area 0.0.0.0 interface 172.16.1.1(GigabitEthernet0/0/0)'s neighborsRouter ID: 2.2.2.2 Address: 172.16.1.2 State: Full Mode:Nbr is Master Priority: 1DR: None BDR: None MTU: 0 Dead timer due in 109 sec Retrans timer interval: 0 Neighbor is up for 00:02:01 Authentication Sequence: [ 0 ] Router ID: 3.3.3.3 Address: 172.16.1.3 State: Full Mode:Nbr is Master Priority: 1DR: None BDR: None MTU: 0 Dead timer due in 94 sec Retrans timer interval: 0 Neighbor is up for 00:02:01 Authentication Sequence: [ 0 ] Router ID: 4.4.4.4 Address: 172.16.1.4 State: Full Mode:Nbr is Master Priority: 1DR: None BDR: None MTU: 0 Dead timer due in 117 sec Retrans timer interval: 0 Neighbor is up for 00:01:31 Authentication Sequence: [ 0 ]
可以看到DR/BDR都为none,验证了在点对多点的网络类型中不选举DR/BDR。
3、根据现在网络需求影响DR/BDR选举
R1为DR,R2为BDR,R4不参与选举。先恢复为默认的广播网络类型。然后修改R1上GE 0/0/0接口的DR优先级为100,R2为50,R3保持不变,R4为0.配置好要记得重启OSPF进程。
[AR1]interface GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ospf network-type broadcast
[AR2]interface GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ospf network-type broadcast
[AR3]interface GigabitEthernet 0/0/0
[AR3-GigabitEthernet0/0/0]ospf network-type broadcast
[AR4]interface GigabitEthernet 0/0/0
[AR4-GigabitEthernet0/0/0]ospf network-type broadcast
# 修改路由器上GE 0/0/0接口的DR优先级,R1为100,R2为50,R3保持不变,R4为0
[AR1-GigabitEthernet0/0/0]ospf dr-priority 100
[AR2-GigabitEthernet0/0/0]ospf dr-priority 50
[AR4-GigabitEthernet0/0/0]ospf dr-priority 0