STP生成树协议:
STP选举过程:
1 | 选举根桥(Root Bridge) |
---|---|
2 | 在每个非根桥上选举一个根端口(Root Port) |
3 | 选举指定端口(Designated Port) |
4 | 阻塞剩余端口(Non-Designated Port) |
STP选举依据:
Bridge ID:
2字节(16bit) | 6字节(48bi’t) | |
---|---|---|
Bridge ID | 端口优先级(Priority)默认值为32768(16bit的中间十进制数值),步长为4096(16bit最高4bit),后12为vlan id | 交换机mac地址 |
路径开销(通过链路速度决定):
COST表:
Bandwidth(Mbps) | 4 | 10 | 16 | 45 | 100 | 155 | 1000 | 10000 |
---|---|---|---|---|---|---|---|---|
cost值 | 250 | 100 | 62 | 39 | 19 | 14 | 4 | 2 |
Port ID:
端口优先级 | 端口编号 | |
---|---|---|
Port ID | 8bit(默认值128 | 8bit(不可更改) |
1.选举根桥(Root Bridge):
比较交换机的Bridge ID,先比较优先级,数值小的胜出,如相同则比较MAC地址,数值小的胜出,作为根桥
2.指定非根网桥上的根端口(Root Port):
比较去往根桥路径开销,数值越小越好,如相同,则比较发送方的Bridge ID,数值小的胜出,如相同则比较Port ID 小的胜出
3.选举指定端口(Designated Port):
比较去往根桥路径开销,数值越小越好,如相同,则比较发送方(发送BPDU的一方,既链路的另一方)的Bridge ID,数值小的胜出,如相同则比较Port ID 小的胜出
4.阻塞剩余端口:
如果既不是Root Port,也不是Designated Port,那么就会被阻塞,不同的stp协议名称不同,PVST(Alternate Port),STP(Blocking Port)
选举原则:
- 比较Bridge ID,数值小的胜出(只用在选举Root Bridge时使用)
- 比较根路径开销,数值小的胜出
- 比较发送方的Bridge ID,数值小的胜出
- 比较Port ID,数值小的胜出
选举总结:
- 根桥上的端口都是指定端口
- 根端口的对端一定是指定端口
- 每个非根交换机上只有一个根端口
- 每条链路上必有一个指定端口
STP生成树版本:
STP实验:
SW0:
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769 #优先级32768 + 1(vlan1)
Address 0010.11A5.D287 #MAC地址
Cost 19 #根桥cost百兆线
Port 1(FastEthernet0/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0090.0C46.AD25
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Root FWD 19 128.1 P2p #f0/1 root port
Fa0/2 Altn BLK 19 128.2 P2p #f0/2 ALternate port
SW1:
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0010.11A5.D287
This bridge is the root #switch1 为根桥
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0010.11A5.D287
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- ------------------spanning-tree vlan 1 root primary--------------
Fa0/2 Desg FWD 19 128.2 P2p #f0/2为指定端口
Fa0/1 Desg FWD 19 128.1 P2p #f0/1为指定端口
改变SW0的优先级,这样SW1就可以作为根桥了,交换机的不同端口的角色也就随之改变:
SW0:
Switch(config)#spanning-tree vlan 1 priority ?
<0-61440> bridge priority in increments of 4096 #设置优先级为4096的倍数
Switch(config)#spanning-tree vlan 1 priority 4096 #设置SW0的优先级为4096比SW1小,这样SW1就作为根桥了
也可以把直接把SW0设置为根桥:
SW0:
Switch(config)#spanning-tree vlan 1 root primary #设置这个交换机为这个生成树的根桥这个命令
可以将当前交换机的的默认优先级减去8192 32769 - 8192 = 24577
Switch(config)#spanning-tree vlan 1 root primary
Switch(config)#do show span
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 24577 #32769 - 8192 = 24577
Address 0090.0C46.AD25
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 24577 (priority 24576 sys-id-ext 1)
Address 0090.0C46.AD25
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Desg FWD