use DFS to parse link topology