STP(生成树)实验
实验拓扑
注:如无特别说明,描述中的R1或SW1对应拓扑中设备名称末尾数字为1的设备,R2或SW2对应拓扑中设备名称末尾数字为2的设备,以此类推
实验需求
- 开启所有设备,等待STP收敛后观察STP状态
- 使SW4成为根网桥
- 使闭塞端口出现在SW2上
- 把SW1上连接的PC的端口配置为边缘端口
实验步骤
一、确认初始根网桥以及闭塞端口
1、设备开机运行、STP收敛后,由于华三模拟器的设备创建规则使得:SW1的Mac地址应该是最小的,会成为根网桥,在SW1上查看STP运行状态,确认SW1为根网桥
。
[SW1]dis stp
-------[CIST Global Info][Mode MSTP]-------
Bridge ID : 32768.12f7-1308-0100
Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20
Root ID/ERPC : 32768.12f7-1308-0100, 0 #根桥ID
RegRoot ID/IRPC : 32768.12f7-1308-0100, 0
RootPort ID : 0.0
BPDU-Protection : Disabled
Bridge Config-
Digest-Snooping : Disabled
TC or TCN received : 7
Time since last TC : 0 days 0h:5m:1s
2、根据STP计算机制,所有链路开销一致,闭塞端口应该会出现在SW4上。在SW4上查看端口状态,确认SW4的g1/0/2为闭塞端口
[SW4]dis stp brief
MST ID Port Role STP State Protection
0 GigabitEthernet1/0/1 ROOT FORWARDING NONE
0 GigabitEthernet1/0/2 ALTE DISCARDING NONE
二、设置新的根网桥(SW4)
1、希望SW4成为根网桥,最好的办法是让SW4的优先级成为全网最小
。默认优先级都为32768,所以只需要把SW4的优先级改成比32768小即可。
[SW4]stp priority ? #确定可设置参数范围
INTEGER<0-61440> Bridge priority, in steps of 4096
[SW4]stp priority 8192 #将优先级设置为8192
[SW4]%Nov 3 09:21:53:754 2023 SW4 STP/6/STP_DETECTED_TC: Instance 0's port GigabitEthernet1/0/2 detected a topology change.
#检验SW4是否成为新的根网桥
[SW4]dis stp
-------[CIST Global Info][Mode MSTP]-------
Bridge ID : 8192.12f7-2a42-0400
Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20
Root ID/ERPC : 8192.12f7-2a42-0400, 0
RegRoot ID/IRPC : 8192.12f7-2a42-0400, 0
RootPort ID : 0.0
BPDU-Protection : Disabled
Bridge Config-
Digest-Snooping : Disabled
TC or TCN received : 6
Time since last TC : 0 days 0h:2m:44s
三、自定义新的闭塞端口(SW2)
1、由于SW4成为了根网桥,按照STP计算机制,此时闭塞端口应该在SW1上。若要使闭塞端口到SW2上,就需要让SW2到SW1的cost比SW4到SW1更大。H3C交换机千兆口的cost默认是20
,所以可以把SW2的g1/0/2接口的cost改为300
# SW4成为新的根网桥后,SW1的g1/0/2口变为新的闭塞端口
<SW1>dis stp brief
MST ID Port Role STP State Protection
0 GigabitEthernet1/0/1 ROOT FORWARDING NONE
0 GigabitEthernet1/0/2 ALTE DISCARDING NONE
# 调整SW2的g1/0/2口的cost值大于20,使之成为新的闭塞端口
<SW2>sy
System View: return to User View with Ctrl+Z.
[SW2]int g1/0/2
[SW2-GigabitEthernet1/0/2]stp cost ?
INTEGER<1-200000> Port path cost
[SW2-GigabitEthernet1/0/2]stp cost 300
[SW2-GigabitEthernet1/0/2]%Nov 3 09:31:30:022 2023 SW2 STP/6/STP_NOTIFIED_TC: Instance 0's port GigabitEthernet1/0/1 was notified a topology change.
# 查看SW2的g1/0/2口是否为闭塞端口
[SW2-GigabitEthernet1/0/2]qu
[SW2]dis stp brief
MST ID Port Role STP State Protection
0 GigabitEthernet1/0/1 ROOT FORWARDING NONE
0 GigabitEthernet1/0/2 ALTE DISCARDING NONE
三、配置边缘接口(SW1)
# 将g1/0/3和g1/0/4口配置为边缘接口
[SW1]int g1/0/3
[SW1-GigabitEthernet1/0/3]stp edged-port
Edge port should only be connected to terminal. It will cause temporary loops if port GigabitEthernet1/0/3 is connected to bridges. Please use it carefully.
[SW1-GigabitEthernet1/0/3]int g1/0/4
[SW1-GigabitEthernet1/0/4]stp edged-port
Edge port should only be connected to terminal. It will cause temporary loops if port GigabitEthernet1/0/4 is connected to bridges. Please use it carefully.