Spanning Tree Protocol isn't a topic that you can learn by simply asking questions and getting answers. You really need to study it. Cisco has a ton of great resources on it. Wikipedia is pretty good too. Here are a couple of hints.
In a complex mesh topology of interconnected switches, Spanning Tree Protocol creates a tree topology that spans the network of interconnected switches. The protocol elects a root bridge for the tree topology. The root is the bridge with the lowest Bridge
ID. Each other bridge then calculates the cost from each of its ports to reach the root bridge. The root port is the port that that has the least-cost path to the root bridge.
When running STP, a switch port has five possible states:
- Blocking: Blocks traffic, but may transition to another state.
- Listening: Processes Bridge Protocol Data Units (BPDUs) and awaits information that would cause the port to return to the blocking state; does not populate the MAC address table and does not forward traffic.
- Learning: Learns source addresses from frames received and populates the MAC address table, but does not forward frames.
- Forwarding: Normal operation; sends and receives frames; monitors incoming BPDUs that would indicate the port should return to the blocking state to prevent a loop.
- Disabled: Not strictly part of STP; a network administrator can manually disable a port
The time spent in the Listening and Learning states is determined by a value known as the Forward Delay (default 15 seconds and set by the root bridge). To bypass the Forward Delay and immediately transition into the Forwarding state, on a Cisco switch,
you can use portfast. This is a good idea for end nodes that aren't switches and don't need to run the complicated STP protocol and would benefit from the capability to start forwarding traffic immediately.
STP has been greatly enhanced over the years. Here are a few enhancements:
- 802.1w speeds up STP. It's also known as the Rapid Spanning Tree Protocol (RSTP).
- 802.1s allows each VLAN to have a spanning tree.
- PVST and PVST+ are Cisco-proprietary versions of STP that also allow each VLAN to have a spanning tree.