95 lines
2.4 KiB
C
95 lines
2.4 KiB
C
#ifndef IPERF_H
|
|
#define IPERF_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "led_strip.h"
|
|
|
|
// --- Configuration Flags ---
|
|
#define IPERF_FLAG_CLIENT (1 << 0)
|
|
#define IPERF_FLAG_SERVER (1 << 1)
|
|
#define IPERF_FLAG_TCP (1 << 2)
|
|
#define IPERF_FLAG_UDP (1 << 3)
|
|
|
|
// --- Standard Iperf2 Header Flags (from payloads.h) ---
|
|
#define HEADER_VERSION1 0x80000000
|
|
#define HEADER_EXTEND 0x40000000
|
|
#define HEADER_UDPTESTS 0x20000000
|
|
#define HEADER_SEQNO64B 0x08000000
|
|
|
|
// --- Defaults ---
|
|
#define IPERF_DEFAULT_PORT 5001
|
|
#define IPERF_DEFAULT_INTERVAL 3
|
|
#define IPERF_DEFAULT_TIME 30
|
|
#define IPERF_TRAFFIC_TASK_PRIORITY 4
|
|
#define IPERF_REPORT_TASK_PRIORITY 5
|
|
|
|
#define IPERF_UDP_TX_LEN (1470)
|
|
|
|
// --- NVS Keys ---
|
|
#define NVS_KEY_IPERF_ENABLE "iperf_enabled"
|
|
#define NVS_KEY_IPERF_PERIOD "iperf_period"
|
|
#define NVS_KEY_IPERF_ROLE "iperf_role"
|
|
#define NVS_KEY_IPERF_DST_IP "iperf_dst_ip"
|
|
#define NVS_KEY_IPERF_PORT "iperf_port"
|
|
#define NVS_KEY_IPERF_PROTO "iperf_proto"
|
|
#define NVS_KEY_IPERF_BURST "iperf_burst"
|
|
#define NVS_KEY_IPERF_LEN "iperf_len"
|
|
|
|
typedef struct {
|
|
uint32_t flag;
|
|
uint32_t dip;
|
|
uint16_t dport;
|
|
uint32_t time;
|
|
uint32_t pacing_period_us;
|
|
uint32_t burst_count;
|
|
uint32_t send_len;
|
|
} iperf_cfg_t;
|
|
|
|
// --- Stats Structure ---
|
|
typedef struct {
|
|
bool running;
|
|
uint32_t config_pps;
|
|
uint32_t actual_pps;
|
|
float error_rate;
|
|
} iperf_stats_t;
|
|
|
|
// --- Wire Formats (Strict Layout) ---
|
|
|
|
// 1. Basic UDP Datagram Header (16 bytes)
|
|
// Corresponds to 'struct UDP_datagram' in payloads.h
|
|
typedef struct {
|
|
int32_t id; // Lower 32 bits of seqno
|
|
uint32_t tv_sec; // Seconds
|
|
uint32_t tv_usec; // Microseconds
|
|
int32_t id2; // Upper 32 bits of seqno (when HEADER_SEQNO64B is set)
|
|
} udp_datagram;
|
|
|
|
// 2. Client Header V1 (Used for First Packet Exchange)
|
|
// Corresponds to 'struct client_hdr_v1' in payloads.h
|
|
typedef struct {
|
|
int32_t flags;
|
|
int32_t numThreads;
|
|
int32_t mPort;
|
|
int32_t mBufLen;
|
|
int32_t mWinBand;
|
|
int32_t mAmount;
|
|
} client_hdr_v1;
|
|
|
|
// --- API ---
|
|
|
|
void iperf_init_led(led_strip_handle_t handle);
|
|
void iperf_set_pps(uint32_t pps);
|
|
uint32_t iperf_get_pps(void);
|
|
|
|
// Get snapshot of current stats
|
|
void iperf_get_stats(iperf_stats_t *stats);
|
|
|
|
// Print formatted status to stdout (for CLI/Python)
|
|
void iperf_print_status(void);
|
|
|
|
void iperf_start(iperf_cfg_t *cfg);
|
|
void iperf_stop(void);
|
|
|
|
#endif
|