From 4c02fe5020950158457c1c95945d026fea2ea76f 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 | 4 ++-- output/meshviewer/graph.go | 2 +- runtime/nodes.go | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/data/neighbours.go b/data/neighbours.go index b45aea47..d6454a89 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 8ae136ab..5a2ad221 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -98,8 +98,8 @@ func TestToInflux(t *testing.T) { }, }, }, - LLDP: map[string]data.LLDPNeighbours{ - "b-interface-mac": {}, + LLDP: map[string][]string{ + "b-interface-mac" }, }, } diff --git a/output/meshviewer/graph.go b/output/meshviewer/graph.go index ccde4422..9d34d5b1 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 082631e1..37cf0a65 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 }