Skip to content

Instantly share code, notes, and snippets.

@jamesacres
Forked from graingert/gist:2830859
Created May 29, 2012 21:40
Show Gist options
  • Select an option

  • Save jamesacres/2830936 to your computer and use it in GitHub Desktop.

Select an option

Save jamesacres/2830936 to your computer and use it in GitHub Desktop.
Finding a communications tree 4
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