diff --git a/internal/topology/builder.go b/internal/topology/builder.go index 2dabf09..ece453d 100644 --- a/internal/topology/builder.go +++ b/internal/topology/builder.go @@ -55,15 +55,23 @@ func (b *Builder) Build() models.TopologyGraph { // 构建边(基于邻居信息) edgeMap := make(map[string]bool) // 用于去重 for _, device := range b.devices { + fmt.Printf("Building edges for device %s: %d neighbors, %d MAC addresses\n", + device.IP, len(device.Neighbors), len(device.MACAddresses)) + for _, neighbor := range device.Neighbors { // 尝试匹配邻居设备 targetIP := neighbor.RemoteIP + matchMethod := "IP" // 如果没有IP,尝试通过设备名匹配 if targetIP == "" && neighbor.RemoteDevice != "" { + fmt.Printf(" Neighbor %s has no IP, trying hostname match: %s\n", + neighbor.LocalInterface, neighbor.RemoteDevice) for _, d := range b.devices { if d.Hostname == neighbor.RemoteDevice { targetIP = d.IP + matchMethod = "hostname" + fmt.Printf(" Matched by hostname: %s -> %s\n", d.Hostname, d.IP) break } } @@ -71,10 +79,14 @@ func (b *Builder) Build() models.TopologyGraph { // 如果还是没有,尝试通过MAC地址匹配(新增) if targetIP == "" && neighbor.RemoteMAC != "" { + fmt.Printf(" Neighbor %s has no IP/hostname, trying MAC match: %s\n", + neighbor.LocalInterface, neighbor.RemoteMAC) for _, d := range b.devices { for _, mac := range d.MACAddresses { if mac == neighbor.RemoteMAC { targetIP = d.IP + matchMethod = "MAC" + fmt.Printf(" Matched by MAC: %s -> %s\n", mac, d.IP) break } } @@ -85,8 +97,13 @@ func (b *Builder) Build() models.TopologyGraph { } if targetIP == "" { + fmt.Printf(" Neighbor %s could not be matched (RemoteIP=%s, RemoteMAC=%s, RemoteDevice=%s)\n", + neighbor.LocalInterface, neighbor.RemoteIP, neighbor.RemoteMAC, neighbor.RemoteDevice) continue } + + fmt.Printf(" Creating edge: %s (%s) -> %s via %s, matched by %s\n", + device.IP, neighbor.LocalInterface, targetIP, neighbor.RemoteInterface, matchMethod) // 创建唯一的边ID edgeID := fmt.Sprintf("%s-%s-%s", device.IP, neighbor.LocalInterface, targetIP)