How States are Decided in a Switch?
In the seven-layer OSI model, the hubs are broadcast devices that operate on layer-1 in half-duplex mode, so only one device can transfer data at a time. To overcome this issue, bridges were introduced. The bridge is used to segment a LAN connection into smaller sub-networks. The bridge stores the MAC address of all the PC’s in a table under its corresponding sub-network and the data will be broadcasted to all the PCs in that sub-network alone. However, most of the bridges have 2 or 4 ports and that becomes a limitation.
To overcome all the above limitations, a combination of bridges and hubs with some added features was introduced and it was a switch. The switch is a multicast device. It can allow PCs connected to it to communicate one-to-one. It has multiple ports also and it can learn which port a MAC address connects to. It has multiple collision domains so that any number of devices can transfer data at a time. It operates in Full-duplex mode. it mostly operates on the Data-link-layer and sometimes on the Network layer as it can be involved in routing also.
Major Switch States:
To overcome redundant links problem protocols, STP (Spanning Tree Protocol) and RSTP (Rapid Spanning Tree Protocol) is used in switches. Both protocols have the same criteria and states but the only difference is that RSTP has more convergence as compared to the STP protocol. The STP algorithm places the ports of switches in the following spanning-tree port states:
- Forwarding State
- Blocking State
The switch can be either a root bridge or a non-root bridge. The root bridge will be chosen by an election process. Only one port in the non-root bridge will be root-port. The root port has the least cost to reach the root bridge and is also called a designated port.
A port in a forwarding state can do the following:
- Learn and update MAC address.
- Transfer the frames
- Process BPDUs (configuration messages ).
All the ports in a root bridge will be in a forwarding state. The designated ports in the non-root bridge will be in a forwarding state.
A port in a blocking state does the following:
- Discards the broadcast messages received.
- Do not transfer any frames.
- Processes only BPDUs.
All the ports of a switch will be in a blocking state initially before and during the election of the root bridge. After the election process, the non-root ports in non-root bridges will be in a blocked state.
How States Are Decided?
The state of the ports is based on the role of the switch or the role of the port.
By the Role of the Switch:
A switch whose role is root bridge can have all its ports in a forwarding state. For a switch to be chosen as a root bridge, an election process will be carried out. The switch that satisfies the conditions of the election process will be considered as root and other segments transfer data through its ports which will be placed in a forwarding state.
Election Process For Root Bridge:
It is the process of choosing a switch in the network as a reference for other switches to decide which of their ports must be in a forwarding state and which must be blocked. For participating in election each switch considers itself as the root bridge and forwards BPDUs (Bridge Protocol Data Units). The BPDU message is a combination of the priority of the ports and the MAC address of the switches which makes up the Bridge ID of a switch. In most cases, the priority of all switches is by default 32768. The switch that meets the following criteria will be considered as the root bridge.
- Condition: Least Bridge ID
- Tie-breaker – 1: Least Priority
- Tie-breaker – 2: Least MAC address
Bridge ID is the combination of priority and MAC address. When bridge ID alone cannot declare the winner the tiebreakers come into the picture. Only one switch can be a root bridge.
By the Role of the Port:
The non-root bridges/switches should have only one port as the root port. These can be considered as the shortest path to reach the root bridge from the non-root bridges. The following will be checked to choose a root port.
1. Condition: Switch port with Least Cost. These port costs are decided based on the speed of the link. Whichever has the least cost will be chosen as the root bridge. The default costs are as follows:
|Speed in the port||Cost|
2. Tie-breaker-1: Forwarding switch with least Bridge ID (combination of priority and MAC address). In case of the same priority, switch with the least MAC address is chosen.
3. Tie-breaker-2: Port with least forwarding port number.
In Fig-1, There are two non-root bridges (switch-2 and switch-3). Each should have a root port. Based on the cost the root ports are selected.
cost from port-20 to root bridge = 4
cost from port-25 to root bridge = 19 (port-25 to switch-3) + 19 (switch-3 to root bridge) = 38
Thus, the least cost port is port-20 and which is the root port and it will be in a forwarding state.
Let us assume, for the same network in Fig-1, all costs are the same, eg: 4. Now the priorities of the switches are compared. In case all switches have the default priority, then the switch with the least MAC address is chosen. What if the MAC address is the same?
Now in Fig-2, the costs, the priorities and the MAC address (just taken for sample in the image) are also the same, as two ports from switch-3 connect to switch-2. Now either port-15 or port-25 of switch-3 has to be the root port. Here whichever port number connects to the least port number of the forwarding switch (switch-2) will be the root port. Here, port-11 is the least number and port-15 of switch-3 connects to it. Thus port-15 will be the root port of switch-3. It will be in a forwarding state.
After choosing the root port, among the leftover ports, a designated port has to be determined. This designated port will be in a forwarding state and the other one will be in a blocking state. The following conditions and tie-breakers are used here also.
1. Condition: Switch port with Least Cost. These port costs are decided based on the speed of the link. Whichever has the least cost will be chosen as the root bridge. The default costs are as follows.
2. Tie-breaker-1: Local switch with least Bridge ID (combination of priority and MAC address). In case of the same priority, switch with the least MAC address is chosen.
3. Tie-breaker-2: Local port with least port number.
Again consider Fig-1, either port-25 from switch-2 or port-27 from-3 has to be in a blocking state. The cost will be 19 for both.
Let us assume the priority is also the same by default. Now let the MAC address of switch-2 be 1002 and the MAC address of switch-3 be 1003. The least one is 1002 and thus port-27 of switch-3 will go to blocking state.
In the case of the same MAC address, whichever port number has the least number wins and becomes the designated port. The root port and designated port will be in a forwarding state and the other one will be a non-designated port in a blocking state.