110 lines
2.5 KiB
C
110 lines
2.5 KiB
C
#ifndef IPERF_H
|
|
#define IPERF_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "led_strip.h" // Needed for the handle type
|
|
|
|
// --- 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)
|
|
|
|
// --- 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_SOCKET_RX_TIMEOUT 10
|
|
#define IPERF_SOCKET_ACCEPT_TIMEOUT 5
|
|
|
|
// --- Buffer Sizes ---
|
|
#define IPERF_UDP_TX_LEN (1470)
|
|
#define IPERF_UDP_RX_LEN (16 << 10)
|
|
#define IPERF_TCP_TX_LEN (16 << 10)
|
|
#define IPERF_TCP_RX_LEN (16 << 10)
|
|
|
|
// --- 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;
|
|
uint8_t type;
|
|
uint32_t dip;
|
|
uint16_t dport;
|
|
uint16_t sport;
|
|
uint32_t interval;
|
|
uint32_t time;
|
|
|
|
// Pacing
|
|
uint32_t pacing_period_us;
|
|
uint32_t burst_count;
|
|
|
|
uint32_t send_len;
|
|
uint32_t buffer_len;
|
|
} iperf_cfg_t;
|
|
|
|
typedef struct {
|
|
uint64_t total_len;
|
|
uint32_t buffer_len;
|
|
uint32_t sockfd;
|
|
uint32_t actual_len;
|
|
uint32_t packet_count;
|
|
uint8_t *buffer;
|
|
uint32_t udp_lost_counter;
|
|
uint32_t udp_packet_counter;
|
|
} iperf_traffic_t;
|
|
|
|
typedef struct {
|
|
int32_t id;
|
|
uint32_t tv_sec;
|
|
uint32_t tv_usec;
|
|
uint32_t id2;
|
|
} udp_datagram;
|
|
|
|
typedef struct {
|
|
int32_t flags;
|
|
int32_t numThreads;
|
|
int32_t mPort;
|
|
int32_t mBufLen;
|
|
int32_t mWinBand;
|
|
int32_t mAmount;
|
|
} client_hdr_v1;
|
|
|
|
#define HEADER_VERSION1 0x80000000
|
|
|
|
// --- Public API ---
|
|
|
|
/**
|
|
* @brief Initialize the LED for Iperf status indication.
|
|
* @param handle The LED strip handle (created in main/status_led).
|
|
*/
|
|
void iperf_init_led(led_strip_handle_t handle);
|
|
|
|
/**
|
|
* @brief Set the target pacing rate in Packets Per Second (PPS).
|
|
* Converts PPS to microsecond interval internally.
|
|
* @param pps Target rate (e.g., 100 = 100 packets/sec)
|
|
*/
|
|
void iperf_set_pps(uint32_t pps);
|
|
|
|
/**
|
|
* @brief Get the current target rate in PPS.
|
|
*/
|
|
uint32_t iperf_get_pps(void);
|
|
|
|
void iperf_start(iperf_cfg_t *cfg);
|
|
void iperf_stop(void);
|
|
|
|
#endif // IPERF_H
|