STP is defined as Spanning Tree Protocol, used in switches to prevent looping problem when multiple switches are connection with each other. As we need to maintain redundancy , we also need to prevent any looping events.
By default STP Basic Mode is ON in switches. But this can be further modified using certain commands.
STP Convergence comes in three steps:-
Step 1: Election of Root Bridge: Considering Bridge ID(Bridge Priority+MAC), a bridge is selected as root bridge.
Step2: Root Port Selection: Port through which other switches are connected with the root bridge.
Step3: Designated/Non-Designated Ports: After all switches having their root port selected, other ports can be either designated or non designated depending on costing. The port through which cost is lower to connect with root bridge is defined as designated port. The other ports are defined as Non-Designated Port.
A port of a bridge can be in different modes. Modes are Blocking, Listening, Learning, Forwarding & Disabled.
Root Bridge Election can be influenced in two different methods.
Method 1:
By default priority is set to 32768 in VLAN 1.. To define the Bridge Priority followig commands can be used:-
Config# spanning-tree vlan <vlan id> primary
#spanning-tree vlan <vlan ID> secondary
Range for primary-> 24576 or 4096 incremental but below the lowest detected
secondary 28672 (predefined)
Method 2:
This commands should in interface mode.
spanning-tree vlan vlan<vlan id> priority 24576
range of priority (0 – 65536)
Defining switch priority:
In some cases, it might happen that multiple ports get the same cost for reaching root bridge. In this case, switch port priority can be modified. By default switch port priority is 128. For fa0/1 it is 128.1, for fa0/2 it is 128.2.
Configuring port priority:
(config-if)# spanning-tree port priority <value> value range (0 – 240), Incremental of 16
To prevent broadcasting bpdu packet to access mode ports (through which pcs are connected):
(config-if)# spanning-tree port-fast
There is also another command bpdu guard to shutdown the certain port if any switch is connected instead of a pc through that port.