aboutsummaryrefslogtreecommitdiff
path: root/utils/networks/networks.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/networks/networks.go')
-rw-r--r--utils/networks/networks.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/networks/networks.go b/utils/networks/networks.go
new file mode 100644
index 0000000..9ecf256
--- /dev/null
+++ b/utils/networks/networks.go
@@ -0,0 +1,55 @@
+package networks
+
+import (
+ "fmt"
+ "slices"
+ Ipam "utils/ipam"
+)
+
+func RunNetworks(ipam *Ipam.Ipam) error {
+ networks := slices.SortedFunc(slices.Values(ipam.Networks), Ipam.CompareNetwork)
+ roots := slices.SortedFunc(slices.Values(ipam.FindRoots()), Ipam.CompareNetwork)
+
+ fmt.Printf("digraph {\n")
+ //fmt.Printf(" layout=dot\n")
+ //fmt.Printf(" layout=twopi\n")
+ fmt.Printf(" layout=fdp\n")
+ //fmt.Printf(" layout=circo\n")
+ //fmt.Printf(" layout=neato\n")
+ //fmt.Printf(" ranksep=3\n")
+ //fmt.Printf(" ratio=auto\n")
+ //fmt.Printf(" rankdir=LR\n")
+ //fmt.Printf(" rankdir=RL\n")
+ fmt.Printf(" rankdir=TB\n")
+ //fmt.Printf(" sep=3\n")
+ //fmt.Printf(" overlap_scaling=-10\n")
+ fmt.Printf("node [len=10];")
+ fmt.Printf("node [shape=box];")
+ fmt.Printf("overlap=false")
+
+ fmt.Printf("\n")
+ fmt.Printf(" # Nodes\n")
+ for _, n := range networks {
+ fmt.Printf(" %s [ label = \"%s\\n%s\"];\n", n.Name, n.Name, n.Prefix)
+ }
+
+ fmt.Printf("\n")
+ fmt.Printf(" # Roots\n")
+ for _, n := range roots {
+ fmt.Printf(" %s [ root = true ];\n", n.Name)
+ }
+
+ fmt.Printf("\n")
+ fmt.Printf(" # Relationships\n")
+ for _, n := range networks {
+ for _, c := range ipam.Networks {
+ if c.Parent == n {
+ fmt.Printf(" %s -> %s", n.Name, c.Name)
+ fmt.Printf(";\n")
+ }
+ }
+ }
+ fmt.Printf("}\n")
+
+ return nil
+}