types.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package network
  2. // InterfaceInfo holds comprehensive details about a network interface.
  3. type InterfaceInfo struct {
  4. Index int `json:"index"`
  5. Name string `json:"name"`
  6. Type string `json:"type"` // "ethernet", "vlan", "loopback", "bridge", "dummy", etc.
  7. State string `json:"state"` // "UP", "DOWN", "UNKNOWN"
  8. OperState string `json:"operstate"` // "up", "down", "unknown"
  9. MAC string `json:"mac"`
  10. MTU int `json:"mtu"`
  11. IPv4 []string `json:"ipv4"` // e.g. ["192.168.1.1/24"]
  12. IPv6 []string `json:"ipv6"` // e.g. ["fe80::1/64"]
  13. Flags []string `json:"flags"`
  14. IsVLAN bool `json:"is_vlan"`
  15. VlanID int `json:"vlan_id,omitempty"`
  16. ParentName string `json:"parent_name,omitempty"`
  17. ParentIndex int `json:"parent_index,omitempty"`
  18. Role string `json:"role"` // "WAN", "LAN", "DMZ", "GUEST", "IOT", "MGMT"
  19. Description string `json:"description"`
  20. Stats NetStats `json:"stats"`
  21. Rate TrafficRate `json:"rate"`
  22. }
  23. // NetStats holds packet and byte counters.
  24. type NetStats struct {
  25. RxBytes uint64 `json:"rx_bytes"`
  26. TxBytes uint64 `json:"tx_bytes"`
  27. RxPackets uint64 `json:"rx_packets"`
  28. TxPackets uint64 `json:"tx_packets"`
  29. RxErrors uint64 `json:"rx_errors"`
  30. TxErrors uint64 `json:"tx_errors"`
  31. RxDropped uint64 `json:"rx_dropped"`
  32. TxDropped uint64 `json:"tx_dropped"`
  33. }
  34. // TrafficRate represents real-time network throughput.
  35. type TrafficRate struct {
  36. RxBytesPerSec float64 `json:"rx_bytes_sec"`
  37. TxBytesPerSec float64 `json:"tx_bytes_sec"`
  38. RxHuman string `json:"rx_human"`
  39. TxHuman string `json:"tx_human"`
  40. }
  41. // InterfaceLiveRate holds real-time throughput and cumulative counters for an interface.
  42. type InterfaceLiveRate struct {
  43. Name string `json:"name"`
  44. RxBytesPerSec float64 `json:"rx_bytes_sec"`
  45. TxBytesPerSec float64 `json:"tx_bytes_sec"`
  46. RxHuman string `json:"rx_human"`
  47. TxHuman string `json:"tx_human"`
  48. RxBytes uint64 `json:"rx_bytes"`
  49. TxBytes uint64 `json:"tx_bytes"`
  50. RxPackets uint64 `json:"rx_packets"`
  51. TxPackets uint64 `json:"tx_packets"`
  52. RxErrors uint64 `json:"rx_errors"`
  53. TxErrors uint64 `json:"tx_errors"`
  54. RxDropped uint64 `json:"rx_dropped"`
  55. TxDropped uint64 `json:"tx_dropped"`
  56. }
  57. // TrafficSnapshot represents an instantaneous router-wide live network traffic snapshot.
  58. type TrafficSnapshot struct {
  59. Timestamp int64 `json:"timestamp"`
  60. Interfaces map[string]InterfaceLiveRate `json:"interfaces"`
  61. TotalRxRate float64 `json:"total_rx_bytes_sec"`
  62. TotalTxRate float64 `json:"total_tx_bytes_sec"`
  63. TotalRxHuman string `json:"total_rx_human"`
  64. TotalTxHuman string `json:"total_tx_human"`
  65. }
  66. // CreateVLANRequest specifies parameters for creating an 802.1Q VLAN interface.
  67. type CreateVLANRequest struct {
  68. ParentName string `json:"parent_name"` // e.g. "eth0"
  69. VlanID int `json:"vlan_id"` // 1 - 4094
  70. Name string `json:"name"` // optional, e.g. "eth0.10" or "vlan10"
  71. IPAddress string `json:"ip_address"` // optional CIDR, e.g. "192.168.10.1/24"
  72. MTU int `json:"mtu"` // defaults to 1500
  73. Role string `json:"role"` // "LAN", "DMZ", "GUEST", "IOT"
  74. Description string `json:"description"` // User-friendly label
  75. AutoUp bool `json:"auto_up"` // bring interface UP immediately
  76. }
  77. // UpdateInterfaceRequest specifies parameters for updating interface attributes.
  78. type UpdateInterfaceRequest struct {
  79. Name *string `json:"name,omitempty"`
  80. State *string `json:"state,omitempty"` // "up" or "down"
  81. MTU *int `json:"mtu,omitempty"`
  82. Role *string `json:"role,omitempty"`
  83. Description *string `json:"description,omitempty"`
  84. }
  85. // RenameInterfaceRequest specifies the new name for an interface.
  86. type RenameInterfaceRequest struct {
  87. Name string `json:"name,omitempty"`
  88. NewName string `json:"new_name,omitempty"`
  89. }
  90. // AddIPRequest defines the payload to add an IP address to an interface.
  91. type AddIPRequest struct {
  92. IP string `json:"ip"` // CIDR, e.g. "192.168.20.1/24"
  93. }
  94. // RoleTag defines an organizational label for classifying interfaces.
  95. type RoleTag struct {
  96. ID string `json:"id"`
  97. Name string `json:"name"`
  98. Color string `json:"color"` // e.g. "amber", "blue", "cyan", "emerald", "purple", "rose", "slate", "indigo"
  99. Description string `json:"description"`
  100. Builtin bool `json:"builtin,omitempty"`
  101. }
  102. // RoleTagWithUsage includes assigned interface names and usage count.
  103. type RoleTagWithUsage struct {
  104. RoleTag
  105. AssignedCount int `json:"assigned_count"`
  106. Interfaces []string `json:"interfaces"`
  107. }
  108. // InterfaceMetadata stores custom persistent labels and IP assignments per interface.
  109. type InterfaceMetadata struct {
  110. Role string `json:"role"`
  111. Description string `json:"description"`
  112. IPAddresses []string `json:"ip_addresses,omitempty"`
  113. AutoUp bool `json:"auto_up,omitempty"`
  114. }
  115. // MetadataStore is written to disk to preserve user labels across restarts.
  116. type MetadataStore struct {
  117. Interfaces map[string]InterfaceMetadata `json:"interfaces"`
  118. Roles []RoleTag `json:"roles,omitempty"`
  119. }