From 285bb8487017a00bdf791fe46eea0c266b1a159f Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 13 Jul 2016 17:36:01 +0200 Subject: [PATCH] Add LLDP links to graph --- models/graph.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/models/graph.go b/models/graph.go index 073b059..f182be3 100644 --- a/models/graph.go +++ b/models/graph.go @@ -56,6 +56,8 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) { if nodeinfo.VPN { builder.vpn[sourceID] = nil } + + // Batman neighbours for _, batinterface := range nodeinfo.Network.Mesh { interfaces := batinterface.Interfaces addresses := append(append(interfaces.Other, interfaces.Tunnel...), interfaces.Wireless...) @@ -65,12 +67,20 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) { } } } + + // Iterate over local MAC addresses from LLDP + if neighbours := node.Neighbours; neighbours != nil { + for sourceAddr, _ := range neighbours.LLDP { + builder.macToID[sourceAddr] = sourceID + } + } } // Add links for sourceID, node := range nodes { if flag := node.Flags; flag == nil || flag.Online { if neighbours := node.Neighbours; neighbours != nil { + // Batman neighbours for _, batadvNeighbours := range neighbours.Batadv { for targetAddress, link := range batadvNeighbours.Neighbours { if targetID, found := builder.macToID[targetAddress]; found { @@ -78,6 +88,14 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) { } } } + // LLDP + for _, neighbours := range neighbours.LLDP { + for targetAddress, _ := range neighbours { + if targetID, found := builder.macToID[targetAddress]; found { + builder.addLink(targetID, sourceID, 255) + } + } + } } } }