Monday, June 21, 2010

STP- Difference between Link Cost and Port Priority

So, when would you want to change link cost and when would you want to change port priority in your spanning tree layout? Is there a difference?

VOCAB:
STP: Spanning Tree Protocol - Layer 2 loop avoidance protocol
BPDU - Briding Protocol Data Unit: Used by Spanning tree to communicate and determine the tree structure.

Spanning tree is a layer 2 protocol that prevents loops from forming. By sending BPDUs out all switch ports, a layer 2 device communicates with it's neighbors and a "tree" structure is developed. One device is determined as the root and all other switches pick a single lowest cost port, deemed the root port, to connect toward that root switch. All other ports that connect to the root can then be put into a blocking state. By doing this, a loop should never be able to develop.

To create the tree that fits your environment best, you can change all the settings. First set the switch priority to make sure the switch you want will be the root, then you can manipulate the path costs to determine the desired tree structure.

After the root switch is chosen, BPDUs are sent out from the root switch, starting with a cost of 0. As each switch recieves the BPDU, it adds the cost of the link the BPDU just traversed and floods it out the other ports. If a switch receives two or more BPDUs, the following is checked:

Lowest Root Bridge ID - part of choosing the root switch
Lowest Root Path Cost - The link "cost" to send traffic to the root switch as modified by all switches in the path
Lowest Sender Bridge ID - Used as a tie-breaker in the case of identical path costs
Lowest Sender Port ID - Used if all above methods are a tie

The lowest cost option is chosen as a root port. Ports connecting to another switch's root port are designated ports. All other ports leading back to the root can then be blocked.

I know that is a very quick overview of STP but I just wanted to focus on link cost vs port priority. I will likely delve further into other parts of STP at a later time.

So, why not just change path costs or just change bridge or port IDs to manage what your spanning tree looks like and what port is used as the root port. The answer lies in looking at the downstream switches rather than the switch you are configuring. If you have two equal cost connections to the root, you can change the cost of one to be higher or lower, manipulating the tree to your design. But you need to remember that path costs are added to the root path cost in each BPDU, bridge and port priorities are not. This means if you change the path cost to a notably lower cost, the switches further out on the branches will be offered a lower root path cost. If you instead choose your root port by changing the port priority or bridge priority, none of that information is carried along to the later switches.

Changing port/switch priorities can be a much administratively cleaner setup. If you have 50 100MB links, it would make sense for them all to have a cost of 19, or a network wide cost of your choosing rather than a mismatch of costs on each individual switch. That could make determining your path costs much more of a task.

Changing path costs can be useful in situations such as edge switches with uplinkfast. In order to ensure the switch is always chosen as a "leaf" node and is never traversed in a regular STP topology, the port costs are all increased by 3000. This is passed on to any switches further downstream making this switch very undesirable as part of the root path. This wouldn't work if the priorities were the only things increased as they are not passed on to other switches.

No comments: