types.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package dynamicrouting
  2. // BGPInstance represents global BGP settings (/routing bgp instance)
  3. type BGPInstance struct {
  4. Enabled bool `json:"enabled"`
  5. AS uint32 `json:"as"`
  6. RouterID string `json:"router_id"`
  7. HoldTime int `json:"hold_time"` // Default 180
  8. KeepaliveTime int `json:"keepalive_time"` // Default 60
  9. RedistributeConnected bool `json:"redistribute_connected"`
  10. RedistributeStatic bool `json:"redistribute_static"`
  11. RedistributeOSPF bool `json:"redistribute_ospf"`
  12. Running bool `json:"running"`
  13. }
  14. // BGPPeer represents a BGP peer connection (/routing bgp connection / peer)
  15. type BGPPeer struct {
  16. ID string `json:"id"`
  17. Name string `json:"name"`
  18. RemoteAddress string `json:"remote_address"`
  19. RemoteAS uint32 `json:"remote_as"`
  20. LocalAddress string `json:"local_address,omitempty"`
  21. Multihop bool `json:"multihop"`
  22. NexthopSelf bool `json:"nexthop_self"`
  23. Passive bool `json:"passive"`
  24. Password string `json:"password,omitempty"`
  25. Disabled bool `json:"disabled"`
  26. Comment string `json:"comment,omitempty"`
  27. // Runtime telemetry
  28. State string `json:"state,omitempty"` // Established, Active, Connect, Idle
  29. Uptime string `json:"uptime,omitempty"`
  30. PrefixReceived int `json:"prefix_received"`
  31. PrefixSent int `json:"prefix_sent"`
  32. }
  33. // BGPNetwork represents an advertised network (/routing bgp network)
  34. type BGPNetwork struct {
  35. ID string `json:"id"`
  36. Network string `json:"network"` // CIDR, e.g. 10.200.0.0/24
  37. Disabled bool `json:"disabled"`
  38. Comment string `json:"comment,omitempty"`
  39. }
  40. // BGPRoute represents an active BGP route
  41. type BGPRoute struct {
  42. Prefix string `json:"prefix"`
  43. NextHop string `json:"next_hop"`
  44. Metric int `json:"metric"`
  45. Weight int `json:"weight"`
  46. Path string `json:"path"`
  47. Origin string `json:"origin"`
  48. Best bool `json:"best"`
  49. }
  50. // OSPFInstance represents global OSPF settings (/routing ospf instance)
  51. type OSPFInstance struct {
  52. Enabled bool `json:"enabled"`
  53. RouterID string `json:"router_id"`
  54. RedistributeConnected bool `json:"redistribute_connected"`
  55. RedistributeStatic bool `json:"redistribute_static"`
  56. RedistributeBGP bool `json:"redistribute_bgp"`
  57. DefaultMetric int `json:"default_metric"`
  58. Running bool `json:"running"`
  59. }
  60. // OSPFArea represents an OSPF area (/routing ospf area)
  61. type OSPFArea struct {
  62. ID string `json:"id"`
  63. Name string `json:"name"`
  64. AreaID string `json:"area_id"` // e.g. "0.0.0.0" or "0"
  65. AreaType string `json:"area_type"` // default, stub, nssa
  66. Comment string `json:"comment,omitempty"`
  67. }
  68. // OSPFInterface represents an OSPF network/interface template (/routing ospf interface-template)
  69. type OSPFInterface struct {
  70. ID string `json:"id"`
  71. Network string `json:"network"` // CIDR, e.g. "192.168.131.0/24"
  72. Area string `json:"area"` // Area ID e.g. "0.0.0.0"
  73. Interface string `json:"interface,omitempty"` // eth0, vlan10, wg0...
  74. Cost int `json:"cost"` // Metric, default 10
  75. Priority int `json:"priority"` // Default 1
  76. HelloInterval int `json:"hello_interval"` // Default 10
  77. DeadInterval int `json:"dead_interval"` // Default 40
  78. Passive bool `json:"passive"`
  79. AuthType string `json:"auth_type"` // none, simple, md5
  80. AuthKey string `json:"auth_key,omitempty"`
  81. Disabled bool `json:"disabled"`
  82. Comment string `json:"comment,omitempty"`
  83. }
  84. // OSPFNeighbor represents a live OSPF neighbor
  85. type OSPFNeighbor struct {
  86. NeighborID string `json:"neighbor_id"`
  87. Address string `json:"address"`
  88. Interface string `json:"interface"`
  89. Area string `json:"area"`
  90. State string `json:"state"` // Full/DR, Full/Backup, 2-Way...
  91. DeadTimer string `json:"dead_timer"`
  92. }
  93. // OSPFRoute represents an active OSPF route
  94. type OSPFRoute struct {
  95. Prefix string `json:"prefix"`
  96. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  97. Cost int `json:"cost"`
  98. Area string `json:"area"`
  99. NextHop string `json:"next_hop"`
  100. Interface string `json:"interface"`
  101. }
  102. // DynamicRoutingSummary aggregates status for dashboard & badges
  103. type DynamicRoutingSummary struct {
  104. BGPEnabled bool `json:"bgp_enabled"`
  105. BGPRunning bool `json:"bgp_running"`
  106. BGPPeerCount int `json:"bgp_peer_count"`
  107. BGPEstablishedCount int `json:"bgp_established_count"`
  108. OSPFEnabled bool `json:"ospf_enabled"`
  109. OSPFRunning bool `json:"ospf_running"`
  110. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  111. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  112. }
  113. // DynamicConfig stores all dynamic routing data on disk
  114. type DynamicConfig struct {
  115. BGPInstance BGPInstance `json:"bgp_instance"`
  116. BGPPeers []BGPPeer `json:"bgp_peers"`
  117. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  118. OSPFInstance OSPFInstance `json:"ospf_instance"`
  119. OSPFAreas []OSPFArea `json:"ospf_areas"`
  120. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  121. }