From 2b7c6eafcd1c53022d97ac8c77f73ba79de8884e Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 21 Jan 2018 16:19:39 -0600 Subject: [PATCH] In admin dot, reverse direction of peer links, include the switch port for each link, and sort the output by coords --- src/yggdrasil/admin.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 9c511fc7..4b24193d 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -4,6 +4,7 @@ import "net" import "os" import "bytes" import "fmt" +import "sort" // TODO: Make all of this JSON // TODO: Add authentication @@ -153,10 +154,28 @@ func (a *admin) handleRequest(conn net.Conn) { } infos[info.key] = info } + // Finally, get a sorted list of keys, which we use to organize the output + var keys [][mDepth]switchPort + for _, info := range infos { + keys = append(keys, info.key) + } + less := func(i, j int) bool { + for idx := range keys[i] { + if keys[i][idx] < keys[j][idx] { + return true + } + if keys[i][idx] > keys[j][idx] { + return false + } + } + return false + } + sort.Slice(keys, less) // Now print it all out conn.Write([]byte(fmt.Sprintf("digraph {\n"))) // First set the labels - for _, info := range infos { + for _, key := range keys { + info := infos[key] if info.name == myAddr { conn.Write([]byte(fmt.Sprintf("\"%v\" [ style = \"filled\", label = \"%v\" ];\n", info.key, info.name))) } else { @@ -164,11 +183,19 @@ func (a *admin) handleRequest(conn net.Conn) { } } // Then print the tree structure - for _, info := range infos { + for _, key := range keys { + info := infos[key] if info.key == info.parent { continue } // happens for the root, skip it - conn.Write([]byte(fmt.Sprintf(" \"%+v\" -> \"%+v\";\n", info.key, info.parent))) + for idx := len(info.key) - 1; idx >= 0; idx-- { + port := info.key[idx] + if port == 0 { + continue + } + conn.Write([]byte(fmt.Sprintf(" \"%+v\" -> \"%+v\" [ label = \"%v\" ];\n", info.parent, info.key, port))) + break + } } conn.Write([]byte(fmt.Sprintf("}\n"))) break