add snmpv3 topology discovery with q-bridge support
This commit is contained in:
15
nodes.go
15
nodes.go
@@ -58,6 +58,10 @@ func NewNodes() *Nodes {
|
||||
}
|
||||
|
||||
func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, parentPort, childPort, source string) {
|
||||
n.UpdateWithParent(nil, ips, macs, parentPort, childPort, source)
|
||||
}
|
||||
|
||||
func (n *Nodes) UpdateWithParent(parentIP net.IP, ips []net.IP, macs []net.HardwareAddr, parentPort, childPort, source string) {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
|
||||
@@ -65,6 +69,13 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, parentPort, childP
|
||||
return
|
||||
}
|
||||
|
||||
parentID := 0
|
||||
if parentIP != nil {
|
||||
if id, exists := n.ipIndex[parentIP.String()]; exists {
|
||||
parentID = id
|
||||
}
|
||||
}
|
||||
|
||||
existingIDs := map[int]bool{}
|
||||
|
||||
for _, ip := range ips {
|
||||
@@ -86,7 +97,7 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, parentPort, childP
|
||||
n.nodes[targetID] = &Node{
|
||||
IPs: map[string]net.IP{},
|
||||
MACs: map[string]net.HardwareAddr{},
|
||||
ParentID: 0,
|
||||
ParentID: parentID,
|
||||
LocalPort: childPort,
|
||||
ParentPort: parentPort,
|
||||
}
|
||||
@@ -105,7 +116,7 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, parentPort, childP
|
||||
merging = append(merging, n.nodes[ids[i]].String())
|
||||
n.mergeNodes(targetID, ids[i])
|
||||
}
|
||||
log.Printf("[%s] merged nodes %v into %s", source, merging, n.nodes[targetID])
|
||||
log.Printf("merged nodes %v into %s (via %s)", merging, n.nodes[targetID], source)
|
||||
}
|
||||
|
||||
node := n.nodes[targetID]
|
||||
|
||||
Reference in New Issue
Block a user