types.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package bwtest
  2. import (
  3. "time"
  4. )
  5. // ServerConfig defines the Bandwidth Test server configuration
  6. type ServerConfig struct {
  7. Enabled bool `json:"enabled"`
  8. Port int `json:"port"`
  9. ListenAddr string `json:"listen_addr"`
  10. AllowAnonymous bool `json:"allow_anonymous"`
  11. }
  12. // SessionRequest defines parameters sent by the client to initiate a test
  13. type SessionRequest struct {
  14. Target string `json:"target"` // Target IP or hostname
  15. Port int `json:"port"` // Target control port (default 2000)
  16. Protocol string `json:"protocol"` // "udp" or "tcp"
  17. Direction string `json:"direction"` // "tx", "rx", "both"
  18. BandwidthLimit int64 `json:"bandwidth_limit"` // Target bits/sec (0 = automatic receiver-feedback pacing for UDP)
  19. PacketSize int `json:"packet_size"` // Packet payload size in bytes (e.g. 1500)
  20. Streams int `json:"streams"` // Number of parallel worker streams (1..8)
  21. Duration int `json:"duration"` // Duration in seconds (0 = continuous until stopped)
  22. }
  23. // SessionHandshake defines the control plane message exchanged between client and server
  24. type SessionHandshake struct {
  25. UDPFeedback string `json:"udp_feedback,omitempty"`
  26. DataFraming string `json:"data_framing,omitempty"`
  27. Type string `json:"type"` // "request", "accept", "reject", "report", "stop"
  28. SessionID string `json:"session_id"`
  29. Protocol string `json:"protocol"` // "udp" or "tcp"
  30. Direction string `json:"direction"` // "tx", "rx", "both"
  31. BandwidthLimit int64 `json:"bandwidth_limit"` // Target bits/sec
  32. PacketSize int `json:"packet_size"`
  33. Streams int `json:"streams"`
  34. Duration int `json:"duration"`
  35. UDPPort int `json:"udp_port,omitempty"`
  36. Message string `json:"message,omitempty"`
  37. RxBytes int64 `json:"rx_bytes,omitempty"`
  38. RxPackets int64 `json:"rx_packets,omitempty"`
  39. LostPackets int64 `json:"lost_packets,omitempty"`
  40. JitterMs float64 `json:"jitter_ms,omitempty"`
  41. }
  42. // LiveSample represents real-time bandwidth metrics captured at an interval (e.g. every 500ms)
  43. type LiveSample struct {
  44. PacketSize int `json:"packet_size"`
  45. OfferedTxMbps float64 `json:"offered_tx_mbps"`
  46. OfferedTxBytes int64 `json:"offered_tx_bytes"`
  47. Timestamp time.Time `json:"timestamp"`
  48. ElapsedSec float64 `json:"elapsed_sec"`
  49. TxBps int64 `json:"tx_bps"`
  50. RxBps int64 `json:"rx_bps"`
  51. TxMbps float64 `json:"tx_mbps"`
  52. RxMbps float64 `json:"rx_mbps"`
  53. TxPackets int64 `json:"tx_packets"`
  54. RxPackets int64 `json:"rx_packets"`
  55. TxBytes int64 `json:"tx_bytes"`
  56. RxBytes int64 `json:"rx_bytes"`
  57. LostPackets int64 `json:"lost_packets"`
  58. LossPct float64 `json:"loss_pct"`
  59. JitterMs float64 `json:"jitter_ms"`
  60. RTTMs float64 `json:"rtt_ms"`
  61. }
  62. // TestSummary represents the finalized results of a completed bandwidth test
  63. type TestSummary struct {
  64. DurationSec float64 `json:"duration_sec"`
  65. StartTime time.Time `json:"start_time"`
  66. EndTime time.Time `json:"end_time"`
  67. TotalTxBytes int64 `json:"total_tx_bytes"`
  68. TotalRxBytes int64 `json:"total_rx_bytes"`
  69. AvgTxMbps float64 `json:"avg_tx_mbps"`
  70. AvgRxMbps float64 `json:"avg_rx_mbps"`
  71. PeakTxMbps float64 `json:"peak_tx_mbps"`
  72. PeakRxMbps float64 `json:"peak_rx_mbps"`
  73. TotalTxPackets int64 `json:"total_tx_packets"`
  74. TotalRxPackets int64 `json:"total_rx_packets"`
  75. TotalLostPackets int64 `json:"total_lost_packets"`
  76. AvgLossPct float64 `json:"avg_loss_pct"`
  77. AvgJitterMs float64 `json:"avg_jitter_ms"`
  78. }
  79. // TestStatus provides a complete real-time snapshot of the active client test
  80. type TestStatus struct {
  81. Running bool `json:"running"`
  82. SessionID string `json:"session_id"`
  83. Target string `json:"target"`
  84. Port int `json:"port"`
  85. Protocol string `json:"protocol"`
  86. Direction string `json:"direction"`
  87. BandwidthLimit int64 `json:"bandwidth_limit"`
  88. PacketSize int `json:"packet_size"`
  89. Streams int `json:"streams"`
  90. Duration int `json:"duration"`
  91. StartTime time.Time `json:"start_time"`
  92. ElapsedSec float64 `json:"elapsed_sec"`
  93. CurrentSample *LiveSample `json:"current_sample,omitempty"`
  94. RecentSamples []*LiveSample `json:"recent_samples,omitempty"`
  95. Summary *TestSummary `json:"summary,omitempty"`
  96. Error string `json:"error,omitempty"`
  97. }
  98. // ServerStatus provides metrics and status for the local BwTest server daemon
  99. type ServerStatus struct {
  100. Enabled bool `json:"enabled"`
  101. Port int `json:"port"`
  102. Running bool `json:"running"`
  103. ActiveSessions int `json:"active_sessions"`
  104. TotalSessionsServed int64 `json:"total_sessions_served"`
  105. TotalBytesProcessed int64 `json:"total_bytes_processed"`
  106. Error string `json:"error,omitempty"`
  107. }
  108. // HistoricalTestRecord stores past test results for review
  109. type HistoricalTestRecord struct {
  110. ID string `json:"id"`
  111. Target string `json:"target"`
  112. Protocol string `json:"protocol"`
  113. Direction string `json:"direction"`
  114. Timestamp time.Time `json:"timestamp"`
  115. Summary *TestSummary `json:"summary"`
  116. }