Files
network-topology-discovery/pkg/models/models.go
T
Your Name 6771858c40 Feat: 支持通过MAC地址进行邻居匹配和拓扑连线
- Neighbor模型添加RemoteMAC字段
- Device模型添加MACAddresses字段
- H3C解析器保存邻居MAC地址和设备所有接口MAC
- 拓扑构建支持三层匹配: IP -> 设备名 -> MAC地址
- 即使ARP表获取失败也能通过MAC地址自动连线
2026-04-26 01:08:14 +08:00

98 lines
3.0 KiB
Go

package models
import "time"
// DeviceType 设备类型
type DeviceType string
const (
DeviceTypeCisco DeviceType = "cisco"
DeviceTypeHuawei DeviceType = "huawei"
DeviceTypeH3C DeviceType = "h3c"
DeviceTypeASA DeviceType = "asa"
DeviceTypeLinux DeviceType = "linux"
DeviceTypeWindows DeviceType = "windows"
)
// Device 网络设备
type Device struct {
ID string `json:"id"`
IP string `json:"ip"`
Type DeviceType `json:"type"`
Hostname string `json:"hostname"`
OSVersion string `json:"os_version"`
Uptime string `json:"uptime"`
Interfaces []Interface `json:"interfaces"`
Neighbors []Neighbor `json:"neighbors"`
MACAddresses []string `json:"mac_addresses,omitempty"` // 设备的所有MAC地址(用于邻居匹配)
LastScanned time.Time `json:"last_scanned"`
ScanStatus string `json:"scan_status"` // success, failed, pending
ErrorMessage string `json:"error_message,omitempty"`
}
// Interface 网络接口
type Interface struct {
Name string `json:"name"`
Description string `json:"description"`
IP string `json:"ip"`
Mask string `json:"mask"`
MAC string `json:"mac"`
Status string `json:"status"` // up, down, admin down
Speed string `json:"speed"`
Duplex string `json:"duplex"`
MTU int `json:"mtu"`
InBytes int64 `json:"in_bytes"`
OutBytes int64 `json:"out_bytes"`
InPackets int64 `json:"in_packets"`
OutPackets int64 `json:"out_packets"`
}
// Neighbor 邻居设备信息
// Neighbor 邻居设备信息
type Neighbor struct {
LocalInterface string `json:"local_interface"`
RemoteDevice string `json:"remote_device"`
RemoteIP string `json:"remote_ip"`
RemoteMAC string `json:"remote_mac,omitempty"` // 新增:邻居MAC地址
RemoteInterface string `json:"remote_interface"`
Protocol string `json:"protocol"` // CDP, LLDP, ARP
}
// ScanTask 扫描任务
type ScanTask struct {
ID string `json:"id"`
Status string `json:"status"` // running, completed, failed
Progress int `json:"progress"`
TotalDevices int `json:"total_devices"`
ScannedDevices int `json:"scanned_devices"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Devices []Device `json:"devices"`
ErrorMessage string `json:"error_message,omitempty"`
}
// TopologyGraph 拓扑图数据
type TopologyGraph struct {
Nodes []TopologyNode `json:"nodes"`
Edges []TopologyEdge `json:"edges"`
}
// TopologyNode 拓扑节点
type TopologyNode struct {
ID string `json:"id"`
IP string `json:"ip"`
Hostname string `json:"hostname"`
Type string `json:"type"`
Icon string `json:"icon"`
}
// TopologyEdge 拓扑边
type TopologyEdge struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
SourceInterface string `json:"source_interface"`
TargetInterface string `json:"target_interface"`
Protocol string `json:"protocol"`
}