From c28c6ad1281cdfc1875a9446feb85ba21fc9d90b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 26 Apr 2026 01:16:17 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E6=8B=93?= =?UTF-8?q?=E6=89=91=E6=9E=84=E5=BB=BA=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 输出每个设备的邻居数量和MAC地址数量 - 输出邻居匹配过程(IP/主机名/MAC) - 输出匹配失败的详细信息 - 输出创建的连线详情 --- internal/topology/builder.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)