生成树协议(STP)原理
在许多交换机或交换机设备组成的网络环境中,通常都使用一些备份连接,以提高网络的健全性、稳定性。备份连接也叫备份链路、冗余链路等。
备份链路使网络存在环路,环路问题是备份链路所面临的最为严重的问题,环路问题将会导致:
广播风暴
多帧复制
MAC地址表的不稳定
在局域网通信中,为了能确保网络连接可靠性和稳定性,常常需要网络提供冗余链路。当一条通信信道遇到堵塞或者不畅通时,就启用备份链路。
为了解决冗余链路引起的问题,IEEE通过了IEEE 802.1d协议,即生成树协议
生成树协议的发展过程划分成三代。
第一代生成树协议:STP/RSTP
第二代生成树协议:PVST/PVST+
第三代生成树协议:MISTP/MSTP
一、STP工作原理
术语:
Bridge ID:每个交换机唯一的桥ID,由桥优先级和Mac地址组合而成(优先级+MAC地址);Root path cost:交换机到根交换机的路径花费,以下简称根路径花费;
Port ID:每个端口ID,由端口优先级和端口号组合而成;
BPDU:交换机之间通过交换BPDU(Bridge Protocol Data Units,交换机协议数据单元)帧来获得建立最佳树形拓扑结构所需要的信息。
STP将一个环形网络生成无环拓朴的步骤:
选择根网桥(Root Bridge)
选择根端口(Root Ports)
选择指定端口(Designated Ports)
1、选择根网桥
网桥ID是唯一的,交换机之间选择BID值最小的交换机作为网络中的根网桥
选择根网桥的目的是为了给将生成的树形结构确定一个树根
2、选择根端口
在非根网桥上选择一个到根网桥最近的端口作为根端口
选择根端口的依据是:
根路径成本最低(是网桥到根网桥的路径上所有链路的成本之和);
直连的网桥ID最小;
端口ID最小;
路径成本根据链路带宽的高低规定:
链路带宽(Mb/s)路径成本
10 100
16 62
45 39
100 19
155 14
622 6
1000 4
10000 2
3、选择指定端口
在每个网段上,选择1个指定端口
首先,根桥上的端口全是指定端口。
非根桥上的指定端口的判断依据如下:
根路径成本最低
端口所在的网桥的ID值较小
端口ID值较小
举例:
查看生成树状态和端口状态:
SW_A#sh spanning-tree
VLAN1 is executing the ieee compatible Spanning Tree protocol Bridge Identifier has priority 32768, address cc00.0128.0000 Configured hello time 2, max age 20, forward delay 15
We are the root of the spanning tree
Topology change flag not set, detected flag not set
Number of topology changes 1 last change occurred 00:03:26 ago
from FastEthernet0/2
Times: hold 1, topology change 35, notification 2
hello 2, max age 20, forward delay 15
Timers: hello 0, topology change 0, notification 0, aging 300
Port 1 (FastEthernet0/0) of VLAN1 is forwarding
Port path cost 19, Port priority 128, Port Identifier 128.1.
Designated root has priority 32768, address cc00.0128.0000
Designated bridge has priority 32768, address cc00.0128.0000
Designated port id is 128.1, designated path cost 0
Timers: message age 0, forward delay 0, hold 0
Number of transitions to forwarding state: 1
BPDU: sent 106, received 9
Port 2 (FastEthernet0/1) of VLAN1 is forwarding
Port path cost 19, Port priority 128, Port Identifier 128.2.
Designated root has priority 32768, address cc00.0128.0000
Designated bridge has priority 32768, address cc00.0128.0000
Designated port id is 128.2, designated path cost 0
Timers: message age 0, forward delay 0, hold 0
Number of transitions to forwarding state: 1
BPDU: sent 106, received 10
Port 3 (FastEthernet0/2) of VLAN1 is forwarding
Port path cost 19, Port priority 128, Port Identifier 128.3.
Designated root has priority 32768, address cc00.0128.0000
Designated bridge has priority 32768, address cc00.0128.0000
Designated port id is 128.3, designated path cost 0
Timers: message age 0, forward delay 0, hold 0
Number of transitions to forwarding state: 1
BPDU: sent 106, received 10
SW_A#sh spanning-tree bri
VLAN1
Spanning tree enabled protocol ieee
Root ID Priority 32768
Address cc00.0128.0000
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32768