aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/main.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/utils/main.go b/utils/main.go
index f419292..42adbd6 100644
--- a/utils/main.go
+++ b/utils/main.go
@@ -13,7 +13,7 @@ import (
func main() {
err := work()
if err != nil {
- _, _ = fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err)
+ _, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
@@ -36,12 +36,20 @@ func work() error {
fmt.Printf("digraph {\n")
//fmt.Printf(" layout=dot\n")
//fmt.Printf(" layout=twopi\n")
- fmt.Printf(" layout=circo\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(" 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 {
@@ -59,7 +67,8 @@ func work() error {
for _, n := range networks {
for _, c := range ipam.networks {
if c.parent == n {
- fmt.Printf(" %s -> %s;\n", n.name, c.name)
+ fmt.Printf(" %s -> %s", n.name, c.name)
+ fmt.Printf(";\n")
}
}
}
@@ -88,6 +97,10 @@ type Ipam struct {
networks []*Network
}
+func contains(a, b netip.Prefix) bool {
+ return b.Bits() > a.Bits() && b.Overlaps(a)
+}
+
func (ipam *Ipam) ResolveParents() {
for _, n := range ipam.networks {
log.Printf("network %s/%s", n.name, n.prefix)
@@ -95,14 +108,14 @@ func (ipam *Ipam) ResolveParents() {
if n == p {
continue
}
- //log.Printf("candidate %s/%s", p.name, p.prefix)
- if p.prefix.Contains(n.prefix.Addr()) {
+ log.Printf(" candidate %s/%s", p.name, p.prefix)
+ if contains(p.prefix, n.prefix) {
if n.parent == nil {
- log.Printf("found parent %s/%s", p.name, p.prefix)
+ log.Printf(" found parent %s/%s", p.name, p.prefix)
n.parent = p
} else {
- if n.parent.prefix.Contains(p.prefix.Addr()) {
- log.Printf("found better parent %s/%s", p.name, p.prefix)
+ if n.parent.prefix.Bits() < p.prefix.Bits() {
+ log.Printf(" found better parent %s/%s", p.name, p.prefix)
n.parent = p
}
}