From 156d07e7e8882dcab77c6ee1d1593ee627adaef4 Mon Sep 17 00:00:00 2001 From: genofire Date: Sat, 9 Jul 2022 20:20:48 +0200 Subject: [PATCH] fix LLDP handling for https://github.com/freifunk-gluon/packages/pull/189 --- data/neighbours.go | 11 +---------- database/influxdb/node_test.go | 2 +- output/meshviewer/graph.go | 2 +- runtime/nodes.go | 14 ++++++++++++++ runtime/testdata/node1.json | 6 +++--- runtime/testdata/node3.json | 6 +++--- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/data/neighbours.go b/data/neighbours.go index b45aea4..d6454a8 100644 --- a/data/neighbours.go +++ b/data/neighbours.go @@ -4,7 +4,7 @@ package data type Neighbours struct { Batadv map[string]BatadvNeighbours `json:"batadv"` Babel map[string]BabelNeighbours `json:"babel"` - LLDP map[string]LLDPNeighbours `json:"lldp"` + LLDP map[string][]string `json:"lldp"` //WifiNeighbours map[string]WifiNeighbours `json:"wifi"` NodeID string `json:"node_id"` } @@ -22,12 +22,6 @@ type BatmanLink struct { Tq int `json:"tq"` } -// LLDPLink struct -type LLDPLink struct { - Name string `json:"name"` - Description string `json:"descr"` -} - // BabelLink struct type BabelLink struct { // How need this: @@ -53,6 +47,3 @@ type BabelNeighbours struct { type WifiNeighbours struct { Neighbours map[string]WifiLink `json:"neighbours"` } - -// LLDPNeighbours struct -type LLDPNeighbours map[string]LLDPLink diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 8ae136a..5b784b3 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -98,7 +98,7 @@ func TestToInflux(t *testing.T) { }, }, }, - LLDP: map[string]data.LLDPNeighbours{ + LLDP: map[string][]string{ "b-interface-mac": {}, }, }, diff --git a/output/meshviewer/graph.go b/output/meshviewer/graph.go index ccde442..9d34d5b 100644 --- a/output/meshviewer/graph.go +++ b/output/meshviewer/graph.go @@ -103,7 +103,7 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) { } // LLDP for _, neighbours := range neighbours.LLDP { - for targetAddress := range neighbours { + for _, targetAddress := range neighbours { if targetID, found := builder.macToID[targetAddress]; found { builder.addLink(targetID, sourceID, 255, false) } diff --git a/runtime/nodes.go b/runtime/nodes.go index 082631e..37cf0a6 100644 --- a/runtime/nodes.go +++ b/runtime/nodes.go @@ -151,6 +151,20 @@ func (nodes *Nodes) NodeLinks(node *Node) (result []Link) { } } } + for portmac, neighmacs := range neighbours.LLDP { + for _, neighmac := range neighmacs { + if neighbourID := nodes.ifaceToNodeID[neighmac]; neighbourID != "" { + result = append(result, Link{ + SourceID: neighbours.NodeID, + SourceAddress: portmac, + TargetID: neighbourID, + TargetAddress: neighmac, + // TODO maybe change LLDP for link quality / 100M or 1GE + TQ: 1.0, + }) + } + } + } return result } diff --git a/runtime/testdata/node1.json b/runtime/testdata/node1.json index 76ef542..3d4b325 100644 --- a/runtime/testdata/node1.json +++ b/runtime/testdata/node1.json @@ -33,9 +33,9 @@ } }, "lldp": { - "a2": { - "c2": {} - } + "a2": [ + "c2" + ] } } diff --git a/runtime/testdata/node3.json b/runtime/testdata/node3.json index 13c579f..bb6ea05 100644 --- a/runtime/testdata/node3.json +++ b/runtime/testdata/node3.json @@ -28,9 +28,9 @@ } }, "lldp": { - "c2": { - "a2": {} - } + "c2": [ + "a2" + ] } }