This commit is contained in:
genofire 2022-07-09 20:20:48 +02:00
parent c5703e0975
commit 156d07e7e8
6 changed files with 23 additions and 18 deletions

View File

@ -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

View File

@ -98,7 +98,7 @@ func TestToInflux(t *testing.T) {
},
},
},
LLDP: map[string]data.LLDPNeighbours{
LLDP: map[string][]string{
"b-interface-mac": {},
},
},

View File

@ -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)
}

View File

@ -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
}

View File

@ -33,9 +33,9 @@
}
},
"lldp": {
"a2": {
"c2": {}
}
"a2": [
"c2"
]
}
}

View File

@ -28,9 +28,9 @@
}
},
"lldp": {
"c2": {
"a2": {}
}
"c2": [
"a2"
]
}
}