package bwtest import ( "time" ) // ServerConfig defines the Bandwidth Test server configuration type ServerConfig struct { Enabled bool `json:"enabled"` Port int `json:"port"` ListenAddr string `json:"listen_addr"` AllowAnonymous bool `json:"allow_anonymous"` } // SessionRequest defines parameters sent by the client to initiate a test type SessionRequest struct { Target string `json:"target"` // Target IP or hostname Port int `json:"port"` // Target control port (default 2000) Protocol string `json:"protocol"` // "udp" or "tcp" Direction string `json:"direction"` // "tx", "rx", "both" BandwidthLimit int64 `json:"bandwidth_limit"` // Target bits/sec (0 = unlimited line-rate) PacketSize int `json:"packet_size"` // Packet payload size in bytes (e.g. 1500) Streams int `json:"streams"` // Number of parallel worker streams (1..8) Duration int `json:"duration"` // Duration in seconds (0 = continuous until stopped) } // SessionHandshake defines the control plane message exchanged between client and server type SessionHandshake struct { Type string `json:"type"` // "request", "accept", "reject", "report", "stop" SessionID string `json:"session_id"` Protocol string `json:"protocol"` // "udp" or "tcp" Direction string `json:"direction"` // "tx", "rx", "both" BandwidthLimit int64 `json:"bandwidth_limit"` // Target bits/sec PacketSize int `json:"packet_size"` Streams int `json:"streams"` Duration int `json:"duration"` UDPPort int `json:"udp_port,omitempty"` Message string `json:"message,omitempty"` RxBytes int64 `json:"rx_bytes,omitempty"` RxPackets int64 `json:"rx_packets,omitempty"` LostPackets int64 `json:"lost_packets,omitempty"` JitterMs float64 `json:"jitter_ms,omitempty"` } // LiveSample represents real-time bandwidth metrics captured at an interval (e.g. every 500ms) type LiveSample struct { Timestamp time.Time `json:"timestamp"` ElapsedSec float64 `json:"elapsed_sec"` TxBps int64 `json:"tx_bps"` RxBps int64 `json:"rx_bps"` TxMbps float64 `json:"tx_mbps"` RxMbps float64 `json:"rx_mbps"` TxPackets int64 `json:"tx_packets"` RxPackets int64 `json:"rx_packets"` TxBytes int64 `json:"tx_bytes"` RxBytes int64 `json:"rx_bytes"` LostPackets int64 `json:"lost_packets"` LossPct float64 `json:"loss_pct"` JitterMs float64 `json:"jitter_ms"` RTTMs float64 `json:"rtt_ms"` } // TestSummary represents the finalized results of a completed bandwidth test type TestSummary struct { DurationSec float64 `json:"duration_sec"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` TotalTxBytes int64 `json:"total_tx_bytes"` TotalRxBytes int64 `json:"total_rx_bytes"` AvgTxMbps float64 `json:"avg_tx_mbps"` AvgRxMbps float64 `json:"avg_rx_mbps"` PeakTxMbps float64 `json:"peak_tx_mbps"` PeakRxMbps float64 `json:"peak_rx_mbps"` TotalTxPackets int64 `json:"total_tx_packets"` TotalRxPackets int64 `json:"total_rx_packets"` TotalLostPackets int64 `json:"total_lost_packets"` AvgLossPct float64 `json:"avg_loss_pct"` AvgJitterMs float64 `json:"avg_jitter_ms"` } // TestStatus provides a complete real-time snapshot of the active client test type TestStatus struct { Running bool `json:"running"` SessionID string `json:"session_id"` Target string `json:"target"` Port int `json:"port"` Protocol string `json:"protocol"` Direction string `json:"direction"` BandwidthLimit int64 `json:"bandwidth_limit"` PacketSize int `json:"packet_size"` Streams int `json:"streams"` Duration int `json:"duration"` StartTime time.Time `json:"start_time"` ElapsedSec float64 `json:"elapsed_sec"` CurrentSample *LiveSample `json:"current_sample,omitempty"` RecentSamples []*LiveSample `json:"recent_samples,omitempty"` Summary *TestSummary `json:"summary,omitempty"` Error string `json:"error,omitempty"` } // ServerStatus provides metrics and status for the local BwTest server daemon type ServerStatus struct { Enabled bool `json:"enabled"` Port int `json:"port"` Running bool `json:"running"` ActiveSessions int `json:"active_sessions"` TotalSessionsServed int64 `json:"total_sessions_served"` TotalBytesProcessed int64 `json:"total_bytes_processed"` Error string `json:"error,omitempty"` } // HistoricalTestRecord stores past test results for review type HistoricalTestRecord struct { ID string `json:"id"` Target string `json:"target"` Protocol string `json:"protocol"` Direction string `json:"direction"` Timestamp time.Time `json:"timestamp"` Summary *TestSummary `json:"summary"` }