一.STP协议
为了提高网络可靠性,交换网络中通常会使用冗余(备份)链路。然而冗余链路会给网络带来环路风险,并导致网络风暴以及MAC地址表不稳定等问题,进而会影响到用户的通信质量。生成树协议STP协议可以在提高可靠性的同时又能避免环路带来的各种问题。生成树协议STP(Spanning Tree Portocol)用来防止交换环路。
二层交换机通过多条链路互联时,虽然能够提升网络可靠性,但同时会带来环路影响,如广播风暴、主机会收到重复数据帧、MAC地址表震荡。STP通过阻塞端口来消除环路,并能够实现链路备份的目的。
网桥协议数据单元BPDU(Bridge Protocol Data Unit)携带优先级和MAC地址,包含桥ID、路径开销、端口ID、计时器等参数,每隔2秒自动发送报文
二.思想及原理
STP协议思想:
自然界中生长的树不会出现环路,如果网络也能够像─棵树一样生长就不会出现环路了。
STP协议实现原理:
通过有选择性地阻塞网络冗余链路达到消除网络二层环路的目的,同时具备链路的
三.实验
第一步开启stp服务
lsw1
system-view
[Huawei]sysname lsw1
[lsw1]stp enable
[lsw1]stp mode stp //stp协议的类型为传统stp
[lsw1]stp priority 4096 //修改优先级为4096
lsw2
system-view
[Huawei]sysname lsw2
[lsw2]stp enable
[lsw2]stp mode stp
[lsw2]stp priority 8192
lsw3
system-view
[Huawei]sysname lsw3
[lsw3]stp enable
[lsw3]stp mode stp
lsw4
system-view
[Huawei]sysname lsw4
[lsw4]stp enable
[lsw4]stp mode stp
第二步查看stp状态
lsw1
[lsw1]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :4096 .4c1f-cc78-78b6
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc78-78b6 / 0
CIST RegRoot/IRPC :4096 .4c1f-cc78-78b6 / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :11
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:3m:36s
Number of TC :14
Last TC occurred :Ethernet0/0/3
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Protocol :Enabled
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc78-78b6 / 128.1
Port Edged :Config=default / Active=disabled
Point-to-point :Config=auto / Active=true
Transit Limit :147 packets/hello-time
Protection Type :None
lsw2
[lsw2]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :8192 .4c1f-cc87-29f3
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc78-78b6 / 200000
CIST RegRoot/IRPC :8192 .4c1f-cc87-29f3 / 0
CIST RootPortId :128.1
BPDU-Protection :Disabled
TC or TCN received :64
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:4m:30s
Number of TC :13
Last TC occurred :Ethernet0/0/1
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Protocol :Enabled
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc78-78b6 / 128.1
Port Edged :Config=default / Active=disabled
Point-to-point :Config=auto / Active=true
Transit Limit :147 packets/hello-time
Protection Type :None
lsw3
[lsw3]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-ccc8-110d
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc78-78b6 / 200000
CIST RegRoot/IRPC :32768.4c1f-ccc8-110d / 0
CIST RootPortId :128.1
BPDU-Protection :Disabled
TC or TCN received :102
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:5m:6s
Number of TC :10
Last TC occurred :Ethernet0/0/1
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Protocol :Enabled
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc78-78b6 / 128.2
Port Edged :Config=default / Active=disabled
Point-to-point :Config=auto / Active=true
Transit Limit :147 packets/hello-time
Protection Type :None
lsw4
[lsw3]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-ccc8-110d
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc78-78b6 / 200000
CIST RegRoot/IRPC :32768.4c1f-ccc8-110d / 0
CIST RootPortId :128.1
BPDU-Protection :Disabled
TC or TCN received :102
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:5m:6s
Number of TC :10
Last TC occurred :Ethernet0/0/1
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Protocol :Enabled
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc78-78b6 / 128.2
Port Edged :Config=default / Active=disabled
Point-to-point :Config=auto / Active=true
Transit Limit :147 packets/hello-time
Protection Type :None
第三步查看STP端口角色
使用命令display stp brief查看一下几台交换机上的STP端口角色,在lsw1上,我们可以看到三个端口都是指定端口(DESI),状态都是转发(FORWARDING)。在lsw2上,我们则可以看到Ethernet0/0/1是lsw2的根端口(ROOT),状态也是转发(FORWARDING);Ethernet0/0/2 和Ethernet0/0/3 是指定端口,状态都是转发(FROWARDING)。在lsw3和lsw4上,我们可以看到连接lsw1的端口为根端口(ROOT),状态是转发(FORWARDING);而与lsw2相连的端口是预备端口(ALTE),状态是阻塞(DISCARDING)。
lsw1
[lsw1]dis stp brief
MSTID Port Role STP State Protection
0 Ethernet0/0/1 DESI FORWARDING NONE
0 Ethernet0/0/2 DESI FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
lsw2
[lsw2]dis stp brief
MSTID Port Role STP State Protection
0 Ethernet0/0/1 ROOT FORWARDING NONE
0 Ethernet0/0/2 DESI FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
lsw3
[lsw3]dis stp b
MSTID Port Role STP State Protection
0 Ethernet0/0/1 ROOT FORWARDING NONE
0 Ethernet0/0/2 ALTE DISCARDING NONE
lsw4
[lsw4]dis s b
MSTID Port Role STP State Protection
0 Ethernet0/0/1 ROOT FORWARDING NONE
0 Ethernet0/0/2 ALTE DISCARDING NONE
效果达成
总结:我们平时做实验,只需要指定一个主根桥,一个优先级比较大的副根桥就行(优先级越小越好),其他的只是检查工作.