1.状态切换

序号

状态切换

切换原因

to Disabled

管理员shutdown端口或端口失效

to Blocking

当前端口放弃Root PortDesignated  Port角色,且经过选举后被阻塞

Disabled to Listening

管理员激活端口或端口由失效恢复,此时端口为Designated  Port,开始发送BPDU

Blocking to Listening

Blocking State,通过BPDU信息,当前端口决定成为Root PortDesignated 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是为了更加形象,易于描述

2Best BPDU参数

RID

是当前Spanning Tree拓扑中,根桥的BID

Root Path Cost

是当前交换机(Root Port)到根桥的开销

BID

每个SegmentDesignated BridgeBID(每个端口有所不同)

PID

每个SegmentDesignated BridgePID(每个端口有所不同)

3作用

用于维护Spanning Tree信息

2.2 维护机制

交换机端口收到BPDU时,便将其与该端口对应的Best BPDU相比较

1参数一致

刷新保持计时器

2收到的BPDU参数更优

端口角色、状态将会发生改变

3本地Best BPDU更优

Designated Port

发送BPDU,使远端与本地保持一致

Root PortBlocking 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的端口状态判断机制

1Root Port丢失到根桥连接

MaxAgeTimeexpire

ifno BPDU rcv || haven't rcv BestBPDUon RootPort

PortRoleRootPort to DesignatedPort

PortStatestay Forwarding

else ifport change state to down

PortStateForwardingto Disabled

注意:

特殊情况下,当前交换机如果由于根端口丢失到根桥连接,进而导致交换机所有端口无法了解到根桥信息时,当前交换机将认为自己是根桥

2其它端口发现到根桥的更优路径

BPDUBPDU rcv onother ports

ifa new root port is on one of other ports

PortRolegive up RootPort

PortStateRootPortto Blocking       //这是通常情况

注意:

之所以说通常进入Blocking State是因为原拓扑中,Root Port链路对端是Designated Port,距离根桥的距离更近

如果Spanning Tree拓扑发生较大变化,当前端口不排除成为Designated Port的可能,此时则依然维持Forwarding State

3出现新根桥,且当前端口未能选举成Root Port

BPDUa BPDU rcv onother ports

ifthis other port elected to be the new RootPort

PortRolegive up RootPort

PortStateForwarding

BPDUa BPDU rcv on old RootPort

ifold RootPort is failed in the election

PortStateForwardingto Blocking

else

PortRoleto be DesignatedPort

PortStatestay Forwarding


4.端口放弃Designated Port角色

4.1  放弃Designated Port可能导致的状态切换

Forwarding to Forwarding

Forwarding to Blocking

Forwarding to Disabled

4.2 何时放弃Designated Port

1出现到根桥的新路径

BPDUa better BPDUrcv on DesignatedPort

ifa new DesignatedBridgeis elected in the segment

PortRolegive up DesignatedPort

PortStateForwardingto Blocking

else ifthe DesignatedPort iselected to be the new RootPort on the bridge

PortStatestay Forwarding

2出现新根桥,且当前端口未能选举为Designated Port

BPDUa new BPDU rcvon DesignatedPort

Bridgea new RootBridge found

supersede the old RootBridge

ifDesignatedPort is elected to be the new RootPort

PortStatestay Forwarding

else ifDesignatedPort is failed in the election

PortRolegive up DesignatedPort

PortStateForwardingto Blocking

3Designated Port被失效或被手动关闭

放弃Designated Port角色,进入Disabled状态


5.端口决定成为Root Port

5.1 可能导致的状态切换

Blocking to Listening

Forwarding to Forwarding

Listeing to Listening

5.2 何时决定成为Root Port

1Blocking端口发现去往根桥捷径

BPDUa better BPDUrcv on BlockingPort

ifPortState==Blocking &&Port is elected to be RootPort

PortStateBlockingto Listening

2Blocking端口发现新根桥

a new RootBridge discovered

ifPortState==Blocking &&Port is elected to be RootPort

PortStateBlockingto Listening

3Designated Port放弃当前角色

PortRoleDesignatedPort

BPDUa better BPDUrcv on DesignatedPort

ifDesignatedPort change to RootPort

PortStatestay Forwarding

4端口激活或恢复后,选举为Root Port

ifPortState change state to Up                 //端口激活或恢复

PortStateDisabledto Listening

PortRoleDesignatedPort

ForwardDelayTimeron

BPDUa BPDU rcv onListeningPort

ifPort is elected to be RootPort

PortStatego on with Listening

ForwardDelayTimergoon

ForwardDelayTimerexpire

PortStateListening to Learning

ForwardDelayTimerexpire

PortStateLearning to Forwarding


6.端口决定成为Designated Port

6.1 可能导致的状态切换

Blocking to Listening

Forwarding to Forwarding

Listening to Listening

6.2 何时决定成为Designated Port

Bridgealready has a RootPort

ifPortState == Blocking

MaxAgeTimeexpire

ifno BPDU rcv || haven't rcv BestBPDUon DesignatedPort

PortRoledecide to be DesignatedPort

PortStateBlocking to Listening


else ifPortState ==Forwarding      //端口处于转发状态且不是指定端口,稳定拓扑中,则为根端口

PortRoleRootPort

BPDUa BPDU rcv onthis port

ifthis port give up the RootPort role && BPDU isnot better than BestBPDU

PortRoleDesignatedPort

PortStatestay Forwarding


else ifport was down && comes Up

PortStateDisabled to Listening

PortRoleDesignatedPort

BPDUa BPDU rcv onthis port

ifthis BPDU is not better thanBestBPDU

PortStatego on with Listening

ForwardDelayTimergoon

ForwardDelayTimerexpire

PortStateListening to Learning

ForwardDelayTimerexpire

PortStateLearning to Forwarding

6.3 成为Designated Port以后

BPDUa BPDU rcv onDesignatedPort

ifthis BPDU is not better thanBestBPDU

BPDUsend BPDU on DesignatedPort

注意:

Root Portnon-Designated Port选择忽略不同,指定端口由于具备BPDU发送能力,此时会主动同步下游设备