1.状态切换
序号 |
状态切换 |
切换原因 |
① |
to Disabled |
管理员shutdown端口或端口失效 |
② |
to Blocking |
当前端口放弃Root Port或Designated Port角色,且经过选举后被阻塞 |
③ |
Disabled to Listening |
管理员激活端口或端口由失效恢复,此时端口为Designated Port,开始发送BPDU |
④ |
Blocking to Listening |
在Blocking State,通过BPDU信息,当前端口决定成为Root Port或Designated Port |
⑤ |
Listening to Learning & Learning to Forwarding |
Forward Delay计时器超时 |
⑥ |
Blocking to Forwarding |
配置了STP增强特性 |
注意:
当端口由Disabled to Listening时,能够转发BPDU,可以认为是DesignatedPort
该端口此后如果能够收到BPDU,则将根据BPDU决定成为RootPort,或将端口状态转为Blocking,或继续维持DesignatedPort角色
2.状态维护机制
2.1 Best BPDU
(1)何为Best BPDU
Spanning Tree拓扑稳定时,交换机所了解到的最优BPDU参数
注意:
实际上交换机收到BPDU时,与本地STP数据库中信息进行比较,这里称为BestBPDU是为了更加形象,易于描述
(2)Best BPDU参数
①RID
是当前Spanning Tree拓扑中,根桥的BID
②Root Path Cost
是当前交换机(Root Port)到根桥的开销
③BID
每个Segment内Designated Bridge的BID(每个端口有所不同)
④PID
每个Segment内Designated Bridge的PID(每个端口有所不同)
(3)作用
用于维护Spanning Tree信息
2.2 维护机制
交换机端口收到BPDU时,便将其与该端口对应的Best BPDU相比较
(1)参数一致
刷新保持计时器
(2)收到的BPDU参数更优
端口角色、状态将会发生改变
(3)本地Best BPDU更优
①Designated Port
发送BPDU,使远端与本地保持一致
②Root Port或Blocking Port
由于这两种端口都没有发送BPDU的能力,因此简单忽略该BPDU
2.3 Inferior BPDU
是指不如本地Best BPDU的消息
2.4 Better(Superior) BPDU
是指比本地保存的Best BPDU更优的消息
3.端口放弃Root Port角色
3.1 放弃Root Port可能导致的状态切换
①Forwarding to Forwarding
②Forwarding to Blocking
③Forwarding to Disabled
3.2 何时放弃Root Port
为了方便各种不同情况的判断,下文均以伪代码的形式表示STP的端口状态判断机制
(1)Root Port丢失到根桥连接
MaxAgeTime:expire
if(no BPDU rcv || haven't rcv BestBPDUon RootPort)
PortRole:RootPort to DesignatedPort
PortState:stay Forwarding
else if(port change state to down)
PortState:Forwardingto Disabled
注意:
特殊情况下,当前交换机如果由于根端口丢失到根桥连接,进而导致交换机所有端口无法了解到根桥信息时,当前交换机将认为自己是根桥
(2)其它端口发现到根桥的更优路径
BPDU:BPDU rcv onother ports
if(a new root port is on one of other ports)
PortRole:give up RootPort
PortState:RootPortto Blocking //这是通常情况
注意:
之所以说通常进入Blocking State是因为原拓扑中,Root Port链路对端是Designated Port,距离根桥的距离更近
如果Spanning Tree拓扑发生较大变化,当前端口不排除成为Designated Port的可能,此时则依然维持Forwarding State
(3)出现新根桥,且当前端口未能选举成Root Port
BPDU:a BPDU rcv onother ports
if(this other port elected to be the new RootPort)
PortRole:give up RootPort
PortState:Forwarding
BPDU:a BPDU rcv on old RootPort
if(old RootPort is failed in the election)
PortState:Forwardingto Blocking
else
PortRole:to be DesignatedPort
PortState:stay Forwarding
4.端口放弃Designated Port角色
4.1 放弃Designated Port可能导致的状态切换
①Forwarding to Forwarding
②Forwarding to Blocking
③Forwarding to Disabled
4.2 何时放弃Designated Port
(1)出现到根桥的新路径
BPDU:a better BPDUrcv on DesignatedPort
if(a new DesignatedBridgeis elected in the segment)
PortRole:give up DesignatedPort
PortState:Forwardingto Blocking
else if(the DesignatedPort iselected to be the new RootPort on the bridge)
PortState:stay Forwarding
(2)出现新根桥,且当前端口未能选举为Designated Port
BPDU:a new BPDU rcvon DesignatedPort
Bridge:a new RootBridge found
supersede the old RootBridge
if(DesignatedPort is elected to be the new RootPort)
PortState:stay Forwarding
else if(DesignatedPort is failed in the election)
PortRole:give up DesignatedPort
PortState:Forwardingto Blocking
(3)Designated Port被失效或被手动关闭
放弃Designated Port角色,进入Disabled状态
5.端口决定成为Root Port
5.1 可能导致的状态切换
①Blocking to Listening
②Forwarding to Forwarding
③Listeing to Listening
5.2 何时决定成为Root Port
(1)Blocking端口发现去往根桥捷径
BPDU:a better BPDUrcv on BlockingPort
if(PortState==Blocking &&Port is elected to be RootPort)
PortState:Blockingto Listening
(2)Blocking端口发现新根桥
a new RootBridge discovered
if(PortState==Blocking &&Port is elected to be RootPort)
PortState:Blockingto Listening
(3)Designated Port放弃当前角色
PortRole:DesignatedPort
BPDU:a better BPDUrcv on DesignatedPort
if(DesignatedPort change to RootPort)
PortState:stay Forwarding
(4)端口激活或恢复后,选举为Root Port
if(PortState change state to Up) //端口激活或恢复
PortState:Disabledto Listening
PortRole:DesignatedPort
ForwardDelayTimer:on
BPDU:a BPDU rcv onListeningPort
if(Port is elected to be RootPort)
PortState:go on with Listening
ForwardDelayTimer:goon
ForwardDelayTimer:expire
PortState:Listening to Learning
ForwardDelayTimer:expire
PortState:Learning to Forwarding
6.端口决定成为Designated Port
6.1 可能导致的状态切换
①Blocking to Listening
②Forwarding to Forwarding
③Listening to Listening
6.2 何时决定成为Designated Port
Bridge:already has a RootPort
if(PortState == Blocking)
MaxAgeTime:expire
if(no BPDU rcv || haven't rcv BestBPDUon DesignatedPort)
PortRole:decide to be DesignatedPort
PortState:Blocking to Listening
else if(PortState ==Forwarding) //端口处于转发状态且不是指定端口,稳定拓扑中,则为根端口
PortRole:RootPort
BPDU:a BPDU rcv onthis port
if(this port give up the RootPort role && BPDU isnot better than BestBPDU)
PortRole:DesignatedPort
PortState:stay Forwarding
else if(port was down && comes Up)
PortState:Disabled to Listening
PortRole:DesignatedPort
BPDU:a BPDU rcv onthis port
if(this BPDU is not better thanBestBPDU)
PortState:go on with Listening
ForwardDelayTimer:goon
ForwardDelayTimer:expire
PortState:Listening to Learning
ForwardDelayTimer:expire
PortState:Learning to Forwarding
6.3 成为Designated Port以后
BPDU:a BPDU rcv onDesignatedPort
if(this BPDU is not better thanBestBPDU)
BPDU:send BPDU on DesignatedPort
注意:
与Root Port及non-Designated Port选择忽略不同,指定端口由于具备BPDU发送能力,此时会主动同步下游设备