STP复习:

1、根桥的选举

  根据BID来选举,BID由桥优先级(2字节)+vlan MAC(6字节),最小的当选

wKiom1L1aP3h2JIeAACDoxn8h3g187.jpg

sw1:show spanning-tree vlan 1

Sw1#show spanning-tree vlan 1

VLAN0001

 Spanning tree enabled protocol ieee

 Root ID    Priority    32769

            Address     0001.636E.5B05

            This bridge is the root

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec


 Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)

            Address     0001.636E.5B05

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

            Aging Time  20


Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Desg FWD 4         128.25   P2p

Gi1/2            Desg FWD 4         128.26   P2p

sw1的BID=32769+0001.636E.5B05

sw2:show spanning-tree vlan 1

Sw2#show spanning-tree vlan 1

VLAN0001

 Spanning tree enabled protocol ieee

 Root ID    Priority    32769

            Address     0001.636E.5B05

            Cost        4

            Port        26(GigabitEthernet1/2)

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec


 Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)

            Address     00D0.BA51.8A2D

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

            Aging Time  20


Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Desg FWD 4         128.25   P2p

Gi1/2            Root FWD 4         128.26   P2p

sw2的BID=32769+00D0.BA51.8A2D

sw3:show spanning-tree vlan 1

Sw3#show spanning-tree vlan 1

VLAN0001

 Spanning tree enabled protocol ieee

 Root ID    Priority    32769

            Address     0001.636E.5B05

            Cost        4

            Port        26(GigabitEthernet1/2)

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec


 Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)

            Address     00E0.B0A8.79C6

            Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

            Aging Time  20


Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Altn BLK 4         128.25   P2p

Gi1/2            Root FWD 4         128.26   P2p

sw3的BID=32769+00E0.B0A8.79C6

sw1的BID=32769+0001.636E.5B05

sw2的BID=32769+00D0.BA51.8A2D

对比下,因为桥优先级(默认值)都一样,所以比较VLAN的MAC地址

可以看出,sw1的MAC最小,其次是sw2,最后是sw3

2、根端口RP的选举

  *看入口COST,谁小

  *看sender BID,谁小

  *看PID,谁小

  因为根桥上面的端口全是指定端口DP,所以根端口在非根桥上选举

  sw2:show spanning-tree vlan 1

Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Desg FWD 4         128.25   P2p

Gi1/2            Root FWD 4         128.26   P2p

我们看到入站COST值一样,接着比sender BID,呵呵,那肯定是连接根桥的sender BID最小

也就是G1/2

sw3:show spanning-tree vlan 1

Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Altn BLK 4         128.25   P2p

Gi1/2            Root FWD 4         128.26   P2p

入站COST值一样,比sender BID ,还是连接根桥的BID最小,也就是端口G1/2

根端口是在一个设备上唯一的选举一个,并且RP必定和一个DP成对存在

入站的COST值可以改变吗?


3、指定端口的选举

  *出站COST,谁小

  *sender BID,谁小

  *PID,谁小

  sw2:show spanning-tree vlan 1

Interface        Role Sts Cost      Prio.Nbr Type

---------------- ---- --- --------- -------- --------------------------------

Gi1/1            Altn BLK 4         128.25   P2p

Gi1/2            Root FWD 4         128.26   P2p

出站COST一样,比sender BID,因为sw3的BID大,所以G1/1就是指定端口DP

sw3:

不用选举了啦,必须在环路中,阻塞一个端口,这里告诉我们了一个问题

DP是在一段网段中选举的,而且DP的对端不一定是RP哦,有可能是个阻塞端口


portfast:

在接入层的接入端口上做

PC接入交换机需要多久才能forwarding呢?30秒

*Mar  1 00:05:34.751: STP: VLAN1 Fa0/15 -> listening

             15s  这边直接从blocking到了listening了,那个20s的老化时间呢?

它是这样一个机制:交换机如果每隔2秒就能接收到一个BPDU,blocking直接到listening就不需要

20秒的老化时间,如果2秒没有接收到,开始20秒的老化计时器时间,这个时候如果检测到forwarding

端口直连检测down掉后,从blocking到listening状态,20秒的老化时间不可避免了。

*Mar  1 00:05:49.775: STP: VLAN1 Fa0/15 -> learning

             15s

*Mar  1 00:06:04.787: STP: VLAN1 Fa0/15 -> forwarding

当做了portfast以后,直接从blocking到forwarding ,节省了30s

配置命令行:

interface f0/6

spanning-tree portfast

这个端口就变成了边缘端口

全局命令:spanning-tree portfast default

例外接口:interface f0/15

         spanning-tree portfast disable


UplinkFast:

上行链路有两个,当其中一个down掉后,另一个链路从blocking到forwarding需要多久?

wKioL1L1eQXAr8rEAACRBtoOZ8I560.jpg

也就是swo到root的链路down掉后,swo->sw1的链路从blocking到forwarding的时间

答案是30s,因为sw0的直连检测,感知到swo->root的链路断掉了

直接将另一个端口从blocking状态切换到listening

而这个端口一直从backup root那接收到BPDU,20s的老化时间没有被启用,所以省略了20s


它是一个全局命令spanning-tree uplinkfast,应用在接入层交换机,节约30s

cost值会变大,桥优先级也变大,就是为了让它不能成为根桥

show spanning-tree uplinkfast


BackboneFast:

wKiom1L1gceTHvl1AACdBn-GBSk067.jpg

结合上图,sw1和sw2之间的链路就是主干链路,如果它down掉的话

sw3上f0/15需要经过多久时间可以进入forwarding状态?

sw3的f0/15端口在主干链路没有down,每2秒接收到的是带sw1的BID

而down掉之后,sw2没有去往root的链路,将自己作为root,发送BPDU

这个时候,sw3会接收到两种BPDU,而来自SW2的BPDU就是次级BPDU

f0/15接收不到原来带SW1 BID的BPDU,开始老化计时20s,才能到达listening状态

所以需要50秒后,才可以进入forwarding状态


backbonefast 应用于所有交换机,节省了20秒,全局启用:spanning-tree backbonefast

启用backbonefast的流程

wKiom1L1hN7RQ34gAADQuF18oUI540.jpg

当主干链路down掉后,sw2会发送一个次级BPDU

而sw3接收到次级BPDU后,会向root发送一个RLQ根桥链路查询报文

查询root是否正常,如果正常,root会回复一个reply

sw3接收到该reply,将f0/15从blocking直接变到listening

*Mar  1 00:39:16.071: STP: VLAN1 Fa0/15 -> listening

*Mar  1 00:39:17.003: STP: VLAN1 heard root 16384-c204.1408.0000 on Fa0/15

*Mar  1 00:39:17.003: current Root has  8192-c203.1408.0000

*Mar  1 00:39:17.043: STP: VLAN1 Topology Change rcvd on Fa0/15

*Mar  1 00:39:17.043: STP: VLAN1 sent Topology Change Notice on Fa0/14

Sw3#show spanning-tree brie

*Mar  1 00:39:31.071: STP: VLAN1 Fa0/15 -> learning

Sw3#show spanning-tree brie

*Mar  1 00:39:46.071: STP: VLAN1 sent Topology Change Notice on Fa0/14

*Mar  1 00:39:46.071: STP: VLAN1 Fa0/15 -> forwarding

show spanning-tree backbonefast


RSTP(802.1w):

端口状态:

1、discarding  相当于STP中的blocking和listening,不能学习MAC地址,只能监听

2、learning    可以学习mac地址

3、forwarding


端口角色:

RP DP

替代端口:

两个设备中间的链路的一段时替代端口

备份端口:

一个设备中有个端口是备份端口

wKioL1L1jdnjB05UAAGdtwDDHUw804.jpg

RSTP是分段收敛的

root发送proposal,非根桥进行同步

同步后,回复一个agreement,同步就是保证没有环路


不是所有的链路都可以执行快速收敛的,只有P2p类型的链路才可以

共享的不可以的

链路类型根据双工模式来选择,全双工是P2p,半双工share

interface f0/0

spanning-tree link-type point-to-point

强制修改链路类型


思科交换机默认工作在pvst



MSTP:多生成树协议 802.1s

spanning-tree mode mst默认所有VLAN一个组

show spanning-tree mst 查看组里的VLAN

spanning-tree mst configuration

instance 1 vlan 1-5

instance 2 vlan 6-10


怎样将交换机作为instance 1的根桥


spanning-tree mst 1 priority 修改作为instance 1的根桥

show spanning-tree mst configuration


EhterChannel:

interface rang f0/1 - 3

channel-group 1 mode on

支持EhterChannel的条件:

1、接口要支持etherchannel

2、一样的speed和双工模式

3、不能作为SPAN的目标端口

4、地址必须配置到port-channel逻辑接口上

5、接口必须属于同一个vlan


port-channel负载分担

1、src-mac,基于源MAC负载负担

  意思就是同一个源MAC走相同的路径

2、dst-mac,基于目的MAC负载分担


STP的安全:

BPDU Guard 接入层交换上应用

    当接口启用BPDU Guard接收到BPDU的时候,置端口状态为err-disable

    恢复有两种方法:

    1、接口shutdown ,no shutdown

    2、全局模式下,errdisable recovery cause bpduguard 12s 默认300s自动恢复

接口模式下:spanning-tree bpduguard enable

全局模式下:spanning-tree portfast bpduguard default

           interface f0/15

           spanning-tree bpduguard disable

BPDU Filter:接收到后,drop BPDU,接口还是可以用的,它的优先级比BPDUGuard高

全局模式下,spanning-tree portfast bpdufilter default

接口模式下,spanning-tree bpdufilter enable


ROOT Guard:在接入低BID的话,会改变原先的STP拓扑

收到优质BPDU就将端口置为inconsistent,端口状态就为broken

接口下,spanning-tree guard root,只能在接口下配

show spanning-tree interface f0/15 detail

show spanning-tree inconsistentports


防环机制:

单向链路造成的环路

udld主要用于光纤的单向链路检测

show udld interface f0/1

udld enable 全局启用

udld port   接口模式下启用

解决物理链路的环路,基于端口


loop guard:基于VLAN,建议配在根端口和替代端口上,解决软问题(比如CPU很忙,没来得及发BPDU)

接口下,spanning-tree guard loop