protected List < Link > getFirstPhysicalPath ( List < Link > currentPath , Switch sw , Node dst ) { // Iterate through the current switch's links for ( Link l : net . getConnectedLinks ( sw ) ) { // Wrong link if ( currentPath . contains ( l ) ) { continue ; } // Go through the link currentPath . add ( l ) ; // Check what is after if ( l . getElement ( ) instanceof Node ) { // Node found, path complete if ( l . getElement ( ) . equals ( dst ) ) { return currentPath ; } } else { // Go to the next switch List < Link > recall = getFirstPhysicalPath ( currentPath , l . getSwitch ( ) . equals ( sw ) ? ( Switch ) l . getElement ( ) : l . getSwitch ( ) , dst ) ; // Return the complete path if found if ( ! recall . isEmpty ( ) ) { return recall ; } } // Wrong link, go back currentPath . remove ( currentPath . size ( ) - 1 ) ; } // No path found through this switch return Collections . emptyList ( ) ; }
Recursive method to get the first physical path found from a switch to a destination node .