It's no secret that networks do not like loops.
If a loop is not handled correctly, a packet can flow around
indefinitely and consume resources as it goes
at layer three.
This is handled automatically using the TTL value of the IP
header. At layer two, though we're not so lucky.
So what we do is we add a technology called spanning tree protocol
in this video and the next we're going to see why we need
spanning tree and how it works.
So why do we need spanning tree?
Think about what happens to a layer two network when a broadcast is sent,
the broadcast goes everywhere.
What does that mean for a typology like this one? One switch will forward
the broadcast to the other switches and those switches will pass them on
Eventually, the traffic's looping around forever,
and although it's not shown here, each connected device
will get a copy of the broadcast frame every time it passes through that switch.
Now, that doesn't seem so bad with only three switches.
But if we had just one more, you'll see that the messages aren't just looping,
they're replicating, what we're seeing here is a broadcast storm.
Any traffic these flooded will cause this problem, whether it's broadcast or not.
On top of that, MAC table entries will continually
be updated as they're receiving frames from different sources.
Remember that a Mac can only be associated with a single port.
The one is learned on.
So eventually, all the switches resources will be consumed
and the network will cease to function.
We try to limit broadcast traffic
with VLANs, but the real problem here is that there is a loop
and there is no built-in solution to stop loops at layer two.
So this is where spanning tree comes in.
Its purpose is to find places where there could be a loop
and prevent it from forming in the first place .
It does this by selecting one of the links in the loop and blocking it.
This prevents frames from traveling around the network indefinitely.
But spanning tree is also clever
enough that it will never block too much
devices will always be able to communicate.
Frames can't always be delivered no matter where the destination device is.
The secondary part of spanning tree
is to respond if there are problems or changes in the network.
A link failure in this topology
would leave one which isolated with no way of reaching the rest of the network.
So spanning tree will detect this change and adapt
by enabling the link that originally blocked.
Here are a few quiz questions that you can get started with.
There's going to be plenty of these throughout this video.
We know why we need spanning tree,
So let's now look at how it works.
There are a few different versions of spanning tree.
We're going to focus on the original version for now
just to understand the basics, and then we'll look at the improvements
offered in RSTP later.
The first piece of the spanning-tree puzzle
is the BPDU, or Bridge Protocol Data Unit.
This is a message that's switches start sending out their interfaces
from the moment they come online.
Each switch
will see the BPDUs from other switches.
This is how they initially discover
each other and learn details about their neighbors.
As each switch needs to know about other switches,
they need unique ways to identify themselves.
And this is through the Switch ID.
This is made up of two values.
Bridge priority, and switch's MAC address.
Switches can have more than one Mac address,
but they will select one to represent the switch as a whole.
Cisco's term for this is called the base Mac.
We can find the base Mac by running
'show spanning tree'
Get used to this command as we're going to be using it a lot.
This is a good time to clear one thing up
in spanning tree terms, switches are called bridges.
This goes back to a time before switches existed.
So whenever you see something referring to a bridge, just think of it as a switch.
Here under the Bridge I.D., there is an address.
This is the base Mac.
It's a unique value, so no other switches will have it.
Each switch or bridge also has a priority.
We can see this here as well.
By default, this is 32,768.
Don't worry too much about the rest of what you see here.
We will go through it soon enough.
The main thing is that you can see the Mac and the priority,
and these make up the Bridge I.D..
The bridge priority is a number
from zero to 61,440.
However, you can't just pick any number from this range.
This value needs to be divisible by 4096.
That seems like a bit of a weird requirement, doesn't it?
Well, there is actually a reason for it.
Within the BPDU, is a 16 bit bridge priority field.
The actual priority starts at the 13th bit.
Low bits make up the extended system I.D., which we'll talk about another time.
The point is, we can't just use every value from this 16 bit range
for the bridge priority.
Don't worry too much if it doesn't make a lot of sense yet,
the important part to remember now is that a valid priority
needs to be divisible by 4096.
So as I said, the default bridge priority
is 32,768, which is about halfway through that range.
If we want, we can change its value to something else.
And making that change is really very simple. In configuration mode,
We use these 'spanning-tree' command; enter the VLAN
that we're configuring, which is something you have to do
on Cisco switches. And then give it a priority.
We'll talk about why we might change that priority in a moment.
So the bridge priority and the Switch Mac address make the Switch ID,
this is one of the pieces of information that switches share
with each other when they start sending and receiving BPDUs
It's good to get to know your neighbor.
But there's a little more to it than that.
As the name suggests, spanning tree uses a tree like structure,
with the main links branching out to other switches.
one of the switches in the topology will become the root bridge.
This is the most important place in the topology, and it is decided
based on the bridge ID that we looked at a moment ago.
The switch with the lowest bridge ID becomes the root bridge.
And of course, we can influence this.
We can't change the switch's MAC address,
but we can change the bridge priority as we saw earlier.
If two switches have the same priority,
the lowest Mac address breaks the tie.
When they first come online, every switch thinks that it's the root bridge,
so they'll start telling others which is all about it in their BPDUs.
These messages are sent every two seconds by default.
So when a new switch
comes online and claims to be root, it will send BPDUs.
Keep in mind that in the original spanning tree protocol,
only the bridge would send BPDUs. Other switches would simply forward them
on after receiving them, flooding them through the network
So if a switch start sending BPDUs and it has a better
that is lower bridge ID, its BPDUs
are called superior BPDUs.
If a switch that thinks it's a root bridge receives a superior
BPDU from another switch, it will realize that it
can't be the bridge. In the original spanning tree,
that means it would stop sending BPDUs of its own.
What it will do instead is forward
the superior BPDUs out its other links, if it has any.
In our example, there are no other links to send the BPDUs out
Of course, it
won't send the BPDU on the link that it received it on.
The main takeaway from this is that there is a constant flood of BPDUs
being sent through the switching network.
Now's the time to use these quiz questions to see if you've understood
what we've been talking about so far.
Of course, that's not the end of it.
Using the information learned from
BPDUs, a switch will build something like a map of the network.
Not exactly a full map, though
more like signposts pointing the way to the root bridge.
And that's the key point here.
Spanning tree is all about finding the best path to the bridge.
Think about the switch that we just turned on, which received a superior BPDU.
It received that BPDU on a particular port,
so it knows that this port points the way through to the Root Bridge.
It names this port, the root port.
All switches have a single root port.
The only exception is the bridge, which doesn't have a root port, after all,
it doesn't need a path to the bridge because it is the bridge.
Let's not lose sight of the big picture, though,
spanning tree needs to find loops in the network.
How might it do that? To understand
that we need to know about something called path cost
As you know, each interface has a speed, something like 100 Meg
or one gig. Spanning tree uses this value to assign a cost to a port.
The faster the interface, the lower the cost.
There are two different ways spanning tree
might calculate the cost, the old way and the new way.
The old way isn't so good in modern networks.
It was developed
way back when all interfaces were slow by today's standards.
These days, as most interfaces are fast,
the cost looks very similar on all ports.
So the new method addresses this by using larger cost values.
The key point here is that spanning
tree will assign a cost to every interface.
We've just used some small values
in the topology here to keep things simple.
If we use 'show spanning-tree' again,
we can see the cost on each interface.
Notice that these are gigabit interfaces and the cost is four.
There's not much room to get a smaller cost for faster interfaces is there?
So we
can change the path cost method too long.
This is done in configuration mode with the 'spanning-tree pathcost method long' command
When we look at the cost again, see how they're much bigger?
That doesn't mean that the costs are worse than before.
It just means they calculated differently.
Faster links will still have smaller costs and slower
links will still have larger costs.
Remember that in the original spanning tree,
the Root Bridge continually sends BPDUs
The directly connected switches can see the cost of the interface
they receive the BPDU on, and therefore they'll know how
far away the root bridge is.
They forward the BPDUs on,
but only after they have added this path cost to the message.
When the next switch receives this BPDU,
it will add the cost of its own interface to the value in the BPDU.
Now it knows the distance to the root bridge as well,
and also knows which port is closest to the root bridge.
If there is more than one path to the root bridge,
it can now also know which is the best path.
The port connected to the best path is called the root port
And remember, they can only be one root port per switch. It acts like a signpost
pointing out the direction and the distance to the root bridge.
These two questions
should help to see if you've understood this section.
If not, it might be a good idea to have a quick review before
going on to the next part,
as you really need to understand root ports and path costs for the next section.
We still haven't found loops in the network, have we?
Let's cover that now.
The Root Bridge sends out BPDUs
switches, receive them.
Sometimes a switch may receive BPDUs on a few different ports.
In the example shown here,
the switches found two paths to the bridge.
The BPDU with the shortest path is the superior BPDU.
The BPDU with the longest path
is the inferior BPDU.
Of course, the interface that receives the superior
BPDU is the root port
What about the port that receives the inferior BPDU?
This represents an alternate path to the root bridge.
If there is more than one path to the root bridge, there is a loop.
So congratulations, we have now discovered a loop in our network.
And we simply can't have that.
So one link needs to be blocked, but which one?
It's not too hard to guess, is it? The switch blocks the interface
that represents the longer path cost this way,
the better path is active.
The ports that the spanning tree
algorithm will block are simply called blocked ports.
No traffic
other than BPDUs can flow over these ports.
This process repeats and all switches
for all alternative paths to the root.
Once loops have been blocked, we can see the tree
like structure starting at the root bridge.
Switches also forward on any BPDUs they receive
so other switches can learn a path to the root bridge,
they send them out all interfaces except the root port.
If a port isn't a root port and it isn't a blocking port,
then is called a designated port.
This is a valid path to send traffic on, but it's not a path to the root bridge.
The key points from this section
are: Root ports point toward the root bridge,
designated ports point away from the root bridge.
Here's a few more questions for you to test your understanding
of these concepts.
You might have a question from this.
You might be thinking
it takes time for spanning tree, to find these loops and handle them.
Do we have broadcast storms during this time?
That is a good question.
But spanning tree has a trick for this also.
The process of assigning a path cost and port roles
happens when the interface first comes online.
This could be when powering up a switch, when plugging in a cable
or when we enable a port.
When the interface comes online, spanning tree goes through a few steps.
In the original
version of Spanning Tree, these are known as blocking, listening,
learning and forwarding.
first, the blocking state
for 20 seconds, the switch will not allow any traffic to pass.
Other than BPDUs, of course.
This gives the switch time to determine if this will be a root port
designated or remain blocking to prevent loops.
If it remains blocking, then it won't transition through the remaining states.
Next, the port will spend 15 seconds in the listening state.
This is where the port waits to see if the topology is stable,
that is that the interface isn't constantly going up and down.
third, the port enters
the learning state, which also last 15 seconds
during this time, the switch does what switches do.
it looks at the traffic it receives, and uses it to build or update its MAC table
During this time is still won't be allowed to
for traffic out the interface other than BPDUs.
And finally, the port transitions to the forwarding state.
It can now forward normal traffic.
So notice that with the original spanning tree, as we've discussed here,
it takes about 50 seconds for port to come online line
that is simply not fast enough in a modern network.
In the next video,
we're going to see how newer versions of spanning tree have improved this.
And of course, there are two more questions for you to consider.
Pause now and have a look at them if you can, or come back
later.
So we've got a nice
new topology. Spanning tree has learned where the root bridge is
it's learned the cost of each path and it knows which links the block.
That's great.
But what happens when the topology changes?
Perhaps links are added or removed or there's hardware failures and switches.
The first thing
spanning tree needs to do is to detect these changes.
one way it can determine that something has changed
is if it doesn't receive the BPDUs when it expects to.
Each switch has a timer called the Max Age Timer.
This is ten times the interval at which BPDUs are sent. By default BPDUs
are sent every two seconds.
So the default max age timer is 20 seconds.
If BPDUs are missing on
an interface for the duration of the Max age timer, then the switch knows
that there is a problem of some sort and it will need to adjust the topology.
This means that the spanning tree algorithm needs to run again
and probably make different decisions.
By way of example, we're going to add a new link to our switch.
It's now going to receive BPDUs on two different ports
as BPDUs will travel over all possible paths.
The result is that our switch
now has more than one path to the bridge.
Of course, the switch will need to look at the path cost, it can see that
there is a smaller cost in this BPDU, making the new BPDU superior.
So it will need to make this new interface, the root port.
But remember, there can only be one root port per switch.
So the other port loses its root port status.
Do you know what happens to this port?
Yep, I think you guessed it. As it represents an alternate path to the bridge.
There is a loop and that will need to be blocked.
The switch will also
notify the rest of the topology that there has been a change.
It will do this by sending a special type of bpdu
you called a TCN or topology change notification.
The TCN is sent toward the root bridge.
The bridge then floods its own TCN out through the rest of the topology.
There is a little more to the process, but to keep it simple, the point is
the whole switching network gets notified that there has been a change.
And here are two final questions to consider.
In particular, I recommend paying special attention
to Question twelve.
It's good to develop a few more skills in the lab, if you can.
This lab is focusing on the original spanning tree.
This is about improving the spanning tree topology, including
selecting the best route bridge, selecting back up root bridges,
documenting the topology and changing the cost calculation.
Because Spanning Tree is such an old protocol,
the original version doesn't work so well in modern networks
over the years, there have been a few improvements.
The most common one is rapid spanning tree or RSTP.
Head over to the next video
where we're going to look at how RSTP improves on the original spanning tree.