Let: msg = control message received p = port on which the message msg was received /* =========================================== Check for better root =========================================== */ if ( msg.rootID < bridge.rootID ) { /* ===================================== Update state variables ===================================== */ bridge.rootID = msg.rootID; bridge.distance = msg.distance + 1; status[p] = R; // This is the root port for ( all ports q ≠ incoming port p ) { status[q] = D; // Other ports are now designated } /* ===================================== Forward new state to neighbors ===================================== */ for ( all ports q ≠ incoming port p ) { send (bridge.ID, bridge.rootID, bridge.distance) on port q; } } /* =========================================== Check for shorter path to root bridge =========================================== */ else if ( msg.rootID == bridge.rootID && msg.distance + 1 < bridge.distance ) { /* ===================================== Update state variables ===================================== */ bridge.rootID = msg.rootID; bridge.distance = msg.distance + 1; status[p] = R; // This is the root port for ( all ports q ≠ incoming port p ) { status[q] = D; // Other ports are now designated } /* ===================================== Forward new state to neighbors ===================================== */ for ( all ports q ≠ incoming port p ) { send (bridge.ID, bridge.rootID, bridge.distance) on port q; } } /* =========================================== Check for farthest node in even cycle =========================================== */ else if ( msg.rootID == bridge.rootID && msg.distance + 1 == bridge.distance ) { if ( status[p] != R ) status[p] = B; // Block the incoming port } /* =========================================== Check for farthest node in odd cycle =========================================== */ else if ( msg.rootID == bridge.rootID && msg.distance == bridge.distance ) { if ( msg.ID < bridge.ID ) status[p] = B; // Block the incoming port } else { // Do nothing, ignore a worse configuration } |
|
Result:
|
|
|
|
Observed that:
|