STP/RSTP/MSTP协议简介


STP

一、STP协议

STP 协议:生成树协议。

二、为什么要有STP协议?

因为当有环路存在时,广播的发送回引起全网的广播风暴,因此需要打破生成的条件,而STP协议就是解决二层广播风暴的重要手段,另外我们会阻塞一些端口,打破环路生成条件,当链路出现问题时,这些阻塞的端口可以过渡到转发状态,实现链路的备份左右。

BPDU

一、什么是BPDU?

BPDU:网桥协议数据单元。
STP的各种选举是通过交换BPDU报文来实现的,BPDU是直接封装在以太帧中的。
对于参与STP的所有SW,它们都是通过数据的交换来获取网络中其它的SW的信息,这种消息就被称为BPDU。
BPDU是直接封装在二层的协议。

二、BPDU的功能

功能:

  • 选举根桥
  • 确定冗余路径的位置
  • 通过阻塞特定的端口来避免环路
  • 通告网络的拓扑变更
  • 监控生成树的状态

三、BPDU的类型

BPDU分两种类型:

  • 配置BPDU:
    通常由根桥以周期性间隔发出,包括了STP参数,用于各种选举。
  • TCN(拓扑变更通告)BPDU:
    这种BPDU事当交换机检测到拓扑发生变更时所产生,可由非根网桥发出。

端口

一、端口角色

  1. RP:根端口。每个非根网桥上有且只有一个,选举到达根网桥上路径开销最小的成为根端口。
  2. DP:指定端口。根网桥上每个端口都是指定端口,非根网桥上需要转发数据的端口也是指定端口。
  3. AP:预备端口。该接口状态为blocking状态,只收BPDU,不发BPDU。

二、端口状态描述

  1. Disabled(禁用状态):不转发数据帧,不学习MAC地址表,不参与生成树的计算。
  2. Blocking(阻塞状态):不转发数据帧,不学习MAC地址表,接收并处理BPDU,不发送BPDU。
  3. Listening(侦听状态):不转发数据帧,不学习MAC地址表,参与生成数计算,接收并发送BPDU。
  4. Learing(学习状态):不转发数据帧,学习MAC地址表,参与生成树计算,接收并发送BPDU。
  5. Forwarding(转发状态):转发数据帧,学习MAC地址表,参与生成树计算,接收并发送BPDU。

三、端口过渡

端口由Blocking过渡到Forwarding有50S延时,Blocking到Listening有20S的老化时间,Listening到Learing有15S过渡时间,Learing到Forwarding有15S过渡时间。

四、角色选举

  1. 选举根交换机的规则:
    Lowest BID=网桥优先级+MAC地址(越小越优)

  2. 选举根端口、指定端口的规则:

  • lowest path cost to root bridge(到达根最小路径开销)
  • Lowest sender BID(最小的发送方BID)
  • Lowest sender port ID(最小的发送方PID)端口优先级(默认128)+发送方端口号

五、选举的一些影响因素

1、路径开销:

BW COST
10M 100
100M 19
1G 4
10G 2

2、修改网桥接口(端口)优先级命令:
例:[SW1-Ethernet0/0/1]stp port priority 0(数值为16的倍数)

六、根网桥

设置成根网桥的两种方法:
1、修改网桥优先级命令:
例:[SW1]stp priority 0(数值需设定为4096的倍数)
2、设置此网桥为根桥
例:[SW1]stp root primary(优先级将变为0)

RSTP

  • RSTP:快速生成树协议。
    作用:缩短生成树端口由阻塞到转发状态的过度时间。
  • 开启快速生成树的方法
    [ ]stp enable
    [ ]stp mode rstp

MSTP

一、 MSTP

MSTP:多实例生成树协议。

二、MSTP的作用

作用:让指定的一个vlan或者多个vlan生成一棵树,实现链路的负载均衡。

例:

[LSW1]stp mode mstp	        #stp模式设置为mstp
[LSW1]stp region-configuration     #进入mstp设置模式
[LSW1-mst-region]region-name huawei	     #区域名为huawei 
[LSW1-mst-region]revision-level 1	    #版本级别为1
[LSW1-mst-region]instance 1 vlan 10	    #定义实例1为vlan10
[LSW1-mst-region]instance 2 vlan 20	    #定义实例2为vlan20
[LSW1-mst-region]active region-configuration     #对mstp配置保存
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW1-mst-region]q
[LSW1]stp instance 1 root primary      #定义本交换机为实例1的根
[LSW1]stp instance 2 root secondary    #定义本交换机为实例2的备选根

三、MSTP实例:

在这里插入图片描述
LSW1:

<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname LSW1
[LSW1]vlan bat 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW1]int e0/0/1	
[LSW1-Ethernet0/0/1]port hybrid pvid vlan 10	
[LSW1-Ethernet0/0/1]port hybrid untagged vlan 10 20
[LSW1-Ethernet0/0/1]int g0/0/1
[LSW1-GigabitEthernet0/0/1]port hybrid pvid vlan 10
[LSW1-GigabitEthernet0/0/1]port hybrid untagged vlan 10 20
[LSW1-GigabitEthernet0/0/1]int e0/0/2	
[LSW1-Ethernet0/0/2]port link-type trunk	
[LSW1-Ethernet0/0/2]port trunk allow-pass vlan 10 20
[LSW1-Ethernet0/0/2]q
[LSW1]stp mode mstp	
[LSW1]stp region-configuration 
[LSW1-mst-region]region-name huawei	
[LSW1-mst-region]revision-level 1	
[LSW1-mst-region]instance 1 vlan 10	
[LSW1-mst-region]instance 2 vlan 20	
[LSW1-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW1-mst-region]q
[LSW1]stp instance 1 root primary 
[LSW1]stp instance 2 root secondary 

LSW2

<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname LSW2
[LSW2]vlan bat 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW2]int e0/0/1	
[LSW2-Ethernet0/0/1]port hybrid pvid vlan 20	
[LSW2-Ethernet0/0/1]port hybrid untagged vlan 10 20
[LSW2-Ethernet0/0/1]int g0/0/1
[LSW2-GigabitEthernet0/0/1]port hybrid pvid vlan 20
[LSW2-GigabitEthernet0/0/1]port hybrid untagged vlan 10 20
[LSW2-GigabitEthernet0/0/1]int e0/0/2	
[LSW2-Ethernet0/0/2]port link-type trunk	
[LSW2-Ethernet0/0/2]port trunk allow-pass vlan 10 20
[LSW2-Ethernet0/0/2]q
[LSW2]stp mode mstp	
[LSW2]stp region-configuration 
[LSW2-mst-region]region-name huawei	
[LSW2-mst-region]revision-level 1	
[LSW2-mst-region]instance 2 vlan 20	
[LSW2-mst-region]instance 1 vlan 10	
[LSW2-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW2-mst-region]q		
[LSW2]stp instance 1 root secondary 	
[LSW2]stp instance 2 root primary 

LSW3

<Huawei>
<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname LSW3
[LSW1]vlan bat 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW3]int e0/0/1	
[LSW3-Ethernet0/0/1]port hybrid pvid vlan 10	
[LSW3-Ethernet0/0/1]port hybrid untagged vlan 10 20
[LSW3-Ethernet0/0/1]int e0/0/2
[LSW3-Ethernet0/0/2]port hybrid pvid vlan 20
[LSW3-Ethernet0/0/2]port hybrid untagged vlan 10 20
[LSW3-Ethernet0/0/2]int e0/0/3
[LSW3-Ethernet0/0/3]port hybrid pvid vlan 10
[LSW3-Ethernet0/0/3]port hybrid untagged vlan 10 20
[LSW3-Ethernet0/0/3]int e0/0/4
[LSW3-Ethernet0/0/4]port hybrid pvid vlan 20
[LSW3-Ethernet0/0/4]port hybrid untagged vlan 10 20
[LSW3-Ethernet0/0/4]q
[LSW3]stp mode mstp
[LSW3]stp region-configuration 
[LSW3-mst-region]region-name huawei	
[LSW3-mst-region]revision-level 1	
[LSW3-mst-region]instance 1 vlan 10	
[LSW3-mst-region]instance 2 vlan 20	
[LSW3-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.

R1

<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]ip address 192.168.10.254 24
[R1-GigabitEthernet0/0/0]interface g0/0/1
[R1-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R1-GigabitEthernet0/0/1]ip address 192.168.20.254 24
[R1-GigabitEthernet0/0/1]q
[R1]interface loop	
[R1]interface LoopBack 0
[R1-LoopBack0]ip add 1.1.1.1 24

通讯结果:

PC>ping 192.168.20.10    #PC1通讯PC2:

Ping 192.168.20.10: 32 data bytes, Press Ctrl_C to break
From 192.168.20.10: bytes=32 seq=1 ttl=127 time=109 ms
From 192.168.20.10: bytes=32 seq=2 ttl=127 time=156 ms
From 192.168.20.10: bytes=32 seq=3 ttl=127 time=110 ms
From 192.168.20.10: bytes=32 seq=4 ttl=127 time=140 ms
From 192.168.20.10: bytes=32 seq=5 ttl=127 time=141 ms

--- 192.168.20.10 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 109/131/156 ms
PC>ping 192.168.10.10     #PC2通讯PC1:

Ping 192.168.10.10: 32 data bytes, Press Ctrl_C to break
From 192.168.10.10: bytes=32 seq=1 ttl=127 time=141 ms
From 192.168.10.10: bytes=32 seq=2 ttl=127 time=140 ms
From 192.168.10.10: bytes=32 seq=3 ttl=127 time=125 ms
From 192.168.10.10: bytes=32 seq=4 ttl=127 time=125 ms
From 192.168.10.10: bytes=32 seq=5 ttl=127 time=156 ms

--- 192.168.10.10 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 125/137/156 ms

总结

在一个复杂的网络环境中,难免会出现环路。由于冗余备份的需要,网络设计者都倾向于在设备之间部署多条物理链路,其中一条作主用链路,其他链路作备份,这样都有可能会导致环路产生。
环路会产生广播风暴,最终导致整个网络资源被耗尽,网络瘫痪不可用。环路还会引起MAC地址表震荡导致MAC地址表项被破坏。
为了破除环路,可以采用数据链路层协议STP,运行该协议的设备通过彼此交互信息发现网络中的环路,并有选择的对某个端口进行阻塞,最终将环形网络结构修剪成无环路的树形网络结构,从而防止报文在环形网络中不断循环,避免设备由于重复接收相同的报文造成处理能力下降。

猜你喜欢

转载自blog.csdn.net/Lucien010230/article/details/111597379