STP学习笔记
网桥=交换机
热备份
冷备份
交换网络中存在环路时容易造成
1、  广播风暴
2、  多帧复制
3、  MAC地址表不稳定
802.1D STP――阻止环路
工作原理:
BPDU
根桥:统领整个2层网络
端口ID不等于端口号
s h   int   |  include bia(查看所有的MAC地址)
show spanning-tree
spanning-tree vlan 1 root primary
spanning-tree vlan 1 priority ?
只有根桥会产生配置BPDU
端口优先级默认会128IOS32cataos
根桥是可以抢占的
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

spanning-tree cost
spanning-tree vlan 1 cost
spanning-tree vlan 1 ,3,5,7,9-15port-priority
bandwidth
端口状态
block(20 sec)
listening(没有MAC地址表,侦听BPDU)
learning(mac地址学习)
forwarding
TCN BPDU 只能从root port发送,一直发送直到收到TCA
PORTFAST
PVST+
RSTP
MSTP(多个VLAN共用一个生成树)802.1s
STP增强-PortFast-UplinkFast-BackboneFast
uplinkfast―――接入层(上行链路发生变化时加速收敛)
backbone---非直连检测(用在所有交换机)
spanning-tree uplinkfast
spanning-tree backbonefast
BPDU保护(spanning-tree bpdugruard enable接口下)
所有接口都启用
spanning-tree portfast bpduguard default
Port Fast特性指连接端工作站或服务器的端口无需经过监听和学习状态,直接从堵塞状态进入转发状态.因为这些端工作站或服务器无需接收BPDU.这样减少了STP的收敛时间,节约了30(转发延迟)的时间.但是在启用该特性前要确保网络无环路 .
启用快速端口特性的步骤如下 :
进入连接端工作站或服务器的端口 :
Aiko(config)#interface {interface}
启用快速端口特性,默认该特性只是启用在层2接入端口上的 ;
也可以指定在中继端口启用该特性 : Aiko(config-if)#spanning-tree portfast [trunk]
全局启用快速端口特性.该特性只会在层2接入端口上启用.可选 :
Aiko(config)#spanning-tree portfast default

Port Fast
对防环路的两个补偿机制 :
BPDU Guard
BPDU过滤

uplinkfast
是用在access layer中的交换机上的而且用在有阻断端口的交换机上,当RP完蛋了,马上启动阻断端口保持通信。这样收敛时间很快,不用从新进行STP运算,直接从blocking跳到fowarding

backbonefast
用在distribution layer中的交换机上。而且要求所有交换机都得启动backbonefast。当一台交换机的 RP坏掉的时候,失去了和RB的连接,它向他的其他端口,包括阻塞端口(如果有的话)发送下级BPDU。收到下级BPDU的交换机有3种情况:1,如果收到下级BPDU的端口是阻塞端口,那么阻塞端口和根端口都作为候选端口(用来到达根桥用的);2,如果收到下级BPDU的端口是根端口,那么阻塞端口被作为候选端口,因为只能通过它到达根桥了;3,如果收到下级BPDU的端口是根端口,并且这个交换机上没有阻塞端口,那么证明这台交换机失去了到根桥的连接,需要从新进行STP运算。

交换机中只要有一台处于第三种状态,就要从新进行STP运算。除此之外,只需花去max age delay的时间(就是最初的20s)就可以收敛完毕。
 
.     缺省情况下,假定交换机的所有端口都将与交换机或者网桥连接,所以所有端口都运行STP算法,即如果网络发生了变化,在端口发送数据之前要等待50s
.     而事实上许多端口会直接连接工作站或者服务器。所以我们采用PortFast可以让这些端口节省ListeningLearning状态的时间,立即进入Forwarding状态。
.     需要注意的是:PortFast仅仅让端口在网络环境变化的情况下直接进入Forwarding状态。而端口仍然运行STP协议,所以如果检测到环路,端口仍将由Forwarding状态变成Blocking状态。

在基于SET的交换机上启用: Set spantree portfast mod_num/ports_num
在基于IOS的交换机上启用: Spantree start-forwarding/no spantree start-forwarding
The portfast feature is a Cisco proprietary change in the STP implementation. The command is applied to specific ports and has two effects:
Ports coming up are put directly in the forwarding STP mode, instead of going through the learning and listening process.
       The switch never generates a TCN when a port configured for portfast is going up or down.

UplinkFast
(上行速)
.     背景资料:STP确保了在拓*变化的情况下没有环路产生,但收敛速度慢。一些实时以及对带宽敏感的网络应用是不能接受的

.     STP收敛速度慢的原因是收敛算法需要化时间确定一条可替代的链路,缺省时间是50s,即20sBlockingListening)+15sListeningLearning)+15sLearningForwarding)。

.     解决的方法是一旦发现了线路down,马上把Blockingport切换到Forwarding,不要经过ListeningLearning阶段。这就是UplinkFast,切换时间可以在2s4s

UplinkFast
被设计应用在接入层交换机。一般应用两条上行链路连接到分布层,一条是冗余链路。
.     UplinkFast激活一个快速重新配置的条件:
在交换机上必须启动了UplinkFast功能;至少有一个处于Blocking的端口(即有冗余链路);链路失效必须发生在Root Port上。

.     交换机启动了UplinkFast后,由于提高了交换机上所有端口的路径开销,所以不适合作为根桥。
he spanning tree port cost and port-VLAN cost of all ports on the switch is increased by 3000.

The spanning tree bridge priority for all VLANs is set to 49152. This makes it unlikely that the switch will become the root switch.
具体来说,一个上行链路组由根端口和除自环端口之外的一组阻断端口组成,上行速链路使交换机上的一个阻断端口几乎立刻进行转发。
很重要的一点就是:上行链路只能配置在接入层交换机上,因为从根端口到其非指定备份端口的快速转发只能在生成树拓*结构的根端口上被确定性的完成。
配置如下:
set spantree uplinkfast enable (
基于 SET)
switch(config)uplink-fasts%b,}"D(]e+FP
但是用set spantree uplinkfast enable 将会影响到VLAN,并且提高了交换机所有端口的端口开销,使它不容易成为一台根网桥。
BackboneFast
Cisco
专有。用在核心层和主干网络中。设置命令没有基于IOS的,只有基于Set命令的。
Inferior BPDU
(下级BPDU)(全部交换机都要启用) You must enable BackboneFast on all switches in the network.
当指定网桥失去了与根桥的连接时,会就发出Inferior BPDU,表明自己是新的根桥。这样对方的交换机就会在自己的Root Port和原本处于Blocking状态的端口都收到BPDU了。
配置: switch>(enable) set spantree backbonefast

 

 


BackboneFast is a Catalyst feature that is initiated when a <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />RootPort or blocked port on a switch receives inferior BPDUs from its DesignatedBridge. An inferior BPDU identifies one switch as both the RootBridge and the DesignatedBridge. When a switch receives an inferior BPDU, it means that a link to which the switch is not directly connected (an indirect link) has failed. That is, the DesignatedBridge has lost its connection to the RootBridge. Under STP rules, the switch ignores inferior BPDUs for the configured Max Age (the default is 20 seconds).
The role of BackboneFast is essentially to cheat this 20-second delay. When the switch receives the inferior BPDU, the switch tries to determine if it has an alternative path to the RootBridge.
backbonefast
catalyst交换机端口或阻塞端口在接收到一个有问题的BPDU的时候才启动的一个特性,之所以说他这个BPDU有问题,是因为在上次STP计算过程中它已经是指定网桥了,现在它竟然还告诉我说他是根桥,这明显有问题,20秒都还没有过呢?当我是傻的呀!!既然我不傻,那就说明它出问题了,问题原因可能是它的根路径发生中断了,因为没有跟我直连接,所以我不知道。跟据STP规则,就算它丢了根路径,我也没办法去救它,因为我必须等到我这个接口上保存的最佳BPDU老化了才行,这个时间是20秒。但是我是谁?我是cisco公司生出来的儿子,熟话说,虎父无犬子,更何况,它是我的兄弟,所以我必需要想办法来规避这个20秒的等待时间。这就是我所具有的backbonefast特性,跟据这个特性,我将找出一条到达根桥的备选路径出来,只要我能找到这条到达根的备选路径,那就不用管什么20秒的等待,我可以真接老化,一秒都不用等。

There are two cases to consider:
重新找一条到根的路径,这不难。最大的问题在于,我自己必须要有去往根的备选路径才行。那么什么情况,我有备选路径呢?其实主要有两情况,如下:
*First, if the inferior BPDU arrives on a blocked port, the RootPort and other blocked ports on the switch become alternative paths to the RootBridge.
第一,如果这个有问题的BPDU到达了我的阻塞端口,那么我的根端口和其他的阻塞端口将变成到达根的备选路径。
**Second, if the inferior BPDU arrives on the RootPort, all blocked ports become potential alternative paths to the RootBridge.
第二,如果这个有问题的BPDU到达了我的根端口,那么我的所有阻塞端口都将变成潜在的到达根的备选路径。
If the inferior BPDU arrives on the Root Port and there are no blocked ports the switch assumes that it has lost connectivity to the Root Bridge causing the Max Age on the root to expire, and becomes the Root Bridge according to normal STP rules. If the switch has alternative paths to the RootBridge it uses these alternative paths to transmit a new kind of Protocol Data Unit (PDU) called the Root Link Query PDU. The switch sends the Root Link Query PDU on all potential alternative paths to the Root Bridge.
如果这个有问题的BPDU到达我的根端口,并且我这没任何阻塞端口,那么根据上面讲的第二种情况,就是说我根本就没有了到达根的备选路径,这说明我到根也丢了,那这下好了,还帮什么帮,再跟据STP规则重新计算STP拓朴得了。再假如我有备选路径,无论是第一种情况,还是第二种情况,只要我有,那么我就会在这些备选路径上发送一种新的协议数据报文(PDU)叫做根连路查寻PDU,就是说我会把这个报文从所有的潜在备选路径上发到根桥去。

If the switch determines that it still has an alternative path to the root, it causes the Max Age on the ports on which it received the inferior BPDU to expire. The switch then makes all ports on which it received an inferior BPDU its Designated Ports and moves them out of the Blocking state (if they were in the Blocking state), through the Listening and Learning states, and into the Forwarding state. On the other hand, if the switch learns via the Root Link Query process that all the alternative paths to the Root Bridge have lost connectivity to the root, the switch causes the Max Age on the ports on which it received inferior BPDUs to expire, and a new STP topology is calculated.

假如我确认了还有可以到达根的备选路径径,那么我就真接把接到问题BPDU的端口老化掉,让我所有接到这个问题BPDU的端口全部进入指定端口角色,同时改变阻塞状态(如果原来是阻塞的话),时入侦听和学习状态,并最终进入转发状态。另一种情况是,通过RLQPDU了解到所有备选中径都丢失了到达根的连接,那么我也会把接到问题BPDU的端口老化,并重新计算STP拓朴。
本文出自 51CTO.COM技术博客