-
-
Save jamesacres/2830936 to your computer and use it in GitHub Desktop.
Finding a communications tree 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Depth First Graph Traversal | |
| Three Tokens: FORWARD, BACKWARD, EXCLUDED | |
| Three Labels: PARENT, CHILD, UNUSED | |
| Send FORWARD down Ethernet to the root node to start the process. | |
| Function Iterate() | |
| For Each Port In Unlabelled | |
| Label Port CHILD | |
| Send FORWARD down Port | |
| Pending++ | |
| Return | |
| End For | |
| If Pending == 0 //Once every port has been sent FORWARD and has responded | |
| Send BACKWARD to Parent //Only reached if no ports are unlabelled | |
| End If | |
| Return | |
| End Function | |
| Case FORWARD: | |
| If PARENT Not Labelled | |
| Label Incoming-Port PARENT | |
| Pending = 0 //how many ports we are waiting on for their response | |
| Iterate() | |
| Else | |
| Label Incoming-Port UNUSED | |
| Send EXCLUDED down Incoming-Port | |
| End If | |
| Return | |
| End Case | |
| Case EXCLUDED: | |
| Label Incoming-Port UNUSED | |
| Pending-- | |
| Iterate() | |
| End Case | |
| Case BACKWARD: | |
| Pending-- | |
| Iterate() | |
| End Case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment