- In a layer two network,
one of the major dangers for any administrator
is a switching loop.
This occurs when any frame is flooded into a switch network
that contains redundant links with no protection.
These packets will loop infinitely,
and as they do so,
will consume more and more resources on the switch,
until they are completely exhausted.
Just one frame can crash a modern switch network
in a matter of seconds.
A technology known as Spanning Tree Protocol
was developed to prevent this exact behavior.
There are several flavors of STP,
but at their core,
most seek to find redundant links,
and stop forwarding of frames over them,
thus preventing loops.
STP starts by electing a route bridge.
Imagine the structure of an STP instance as a tree,
hence the name Spanning Tree.
The root bridge is the very base of the tree,
from which everything else grows.
The root bridge,
has all of its up interfaces forwarding traffic.
Every subsequent switch connected at the tree from the root,
will designate one port as their root port.
This is the interface with the least administrative cost
between itself and the root bridge.
Every port that connects
to a root port by the upstream switch,
is called the designated port.
If a port is passing traffic,
it's said to be in the forwarding STP state.
If a port is told by STP that it is redundant,
and should not forward traffic,
it will be in the blocking state.
If an interface is failed or disabled,
it's in the STP disabled state.
STP identifies each switch participating
with an STP bridge ID.
This is an eight byte value,
consisting of two byte priority field,
and the six byte system ID,
which is derived from the MAC address on the switch.
This bridge ID is shared with other switches
via STP messages known as bridge protocol data units.
The spanning tree algorithm,
starts by electing a route bridge.
The route bridge is determined
by the switch with the lowest value for the bridge ID.
This can be influenced by changing the default STP priority
on a switch.
Seeing as though this is the first part of the BID.
Each switch coming online sets its own BID
as the route bridge,
when it begins sending hello messages.
The lowest BID wins,
and at that point,
only the route bridge alone will originate hello messages.
As downstream switches from the route bridge
receive the hello messages,
they will simply read them and pass them along.
Route ports,
are those that are the least cost to reach the route bridge.
Take a look at this diagram.
Switch three has two paths to reach switch one,
which is the root bridge.
Each port has a default STP cost to exit it.
In this example,
port one has a cost of 10 to reach the root bridge.
While the total via switch two is 20.
Since port one's cost is lower,
it's set as the route port,
while port two has set the blocking.
Again,
this value can be manipulated by an administrator,
to influence the root port
decision making process if desired.
Cisco's primary STP flavor of choice
is Rapid per VLAN Spanning Tree Plus,
which I'll be referring to as PVST plus,
or just Rapid moving forward.
While PVST plus shares many similarities
from the original STP implementations,
it adds a new route in designated port mechanism,
as well as speeds up network convergence
during an STP change.
In PVST plus,
when two ports could be used as route ports,
only one will be designated as the root port,
and the other will be designated as an alternate port.
If the root port fails for any reason,
the alternate port will quickly be transitioned to root port
and begin forwarding traffic.
The designated port,
or one that connects to a downstream root port,
now gets a quick transition port.
If there is more than one designated port,
the port that is not forwarding traffic
is known as the backup port.
This too allows for rapid transition
on failure of the designated port.
Rapid also designates different port types,
that perform different functions.
For example,
Edge ports are those that can connect to in user devices.
There are some cheat codes that allow an administrator
to create a better experience for their users.
The PortFast feature,
allows for immediate transition
from blocking to forwarding in a user port.
The PortFast feature,
is designed to connect in user devices only,
not other switches.
Configuring PortFast also tells Rapid STP
that this port is an Edge port,
and thus can enjoy faster access to the network.
STP is the first line of defense
when keeping a switch network loop free.
And thus should be utilized
in all of your switch deployments.