/*
 * UDP Speed Test - udpst_global.h
 */

#ifndef UDPST_GLOBAL_H
#define UDPST_GLOBAL_H

#define UDPST_AVM_VER     (2)

#define SOFTWARE_VER      "7.4.0"

//----------------------------------------------------------------------------
//
// Protocol version
//
#define BWMGMT_PVER  9 // Protocol version required for bandwidth management
#define PROTOCOL_MIN 8 // Minimum protocol version for backward compatibility
#define PROTOCOL_VER 9 // Protocol version required for bandwidth management

//
// Common
//
typedef int BOOL;
#define TRUE  1 // Boolean true
#define FALSE 0 // Boolean false

//
// General
//
#define SOFTWARE_TITLE    "UDP Speed Test"
#define USTEST_TEXT       "Upstream"
#define DSTEST_TEXT       "Downstream"
#define TIME_FORMAT       "%Y-%m-%d %H:%M:%S"
#define STRING_SIZE       1024 // String buffer size
#define AUTH_KEY_SIZE     32   // Authentication key size
#define HS_DELTA_BACKUP   3    // High-speed delta backup multiplier
#define MAX_EPOLL_EVENTS  8    // Max epoll events handled at one time
#define MAX_CONNECTIONS   128  // Max simultaneous connections
#define AUTH_TIME_WINDOW  150  // Authentication +/- time windows (sec)
#define AUTH_ENFORCE_TIME TRUE // Enforce authentication time window
#define WARNING_MSG_LIMIT 50   // Warning message limit
#define WARNING_NOTRAFFIC 1    // Receive traffic stopped warning threshold (sec)
#define TIMEOUT_NOTRAFFIC (WARNING_NOTRAFFIC + 2)
#define STATUS_SUCCESS    0  // Success (test completed without incident)
#define STATUS_WARNING    1  // Warning or soft error (test runs but with anomaly)
#define STATUS_ERROR      -1 // Failure or hard error (test designated as failure)
// Alternative for INET6_ADDRSTRLEN (allows for '%' and textual Zone ID)
#define INET6_ADDR_STRLEN (INET6_ADDRSTRLEN + 1 + IFNAMSIZ)

// DISABLE_INT_TIMER disables the interval timer when compiling for client
// devices that are unable to support the required clock resolution. Because
// this results in high CPU utilization, it is not recommended for standard
// server operation.
#ifndef DISABLE_INT_TIMER
#define SEND_TIMER_ADJ 75 // Data send timer adjustment (us)
#else
#define SEND_TIMER_ADJ 0 // Set to zero when interval timer is disabled
#endif

//----------------------------------------------------------------------------
//
// Default and min/max parameter values
//
#define DEF_JUMBO_STATUS     TRUE       // Enable/disable jumbo datagram sizes
#define DEF_USE_OWDELVAR     FALSE      // Use one-way delay instead of RTT
#define DEF_IGNORE_OOODUP    FALSE      // Ignore Out-of-Order/Duplicate datagrams
#define DEF_IPTOS_BYTE       0          // IP ToS byte for testing
#define MIN_IPTOS_BYTE       0          //
#define MAX_IPTOS_BYTE       UINT8_MAX  //
#define DEF_SRINDEX_CONF     UINT16_MAX // Sending rate index, <Auto> = UINT16_MAX
#define MIN_SRINDEX_CONF     0          //
#define MAX_SRINDEX_CONF     (MAX_SENDING_RATES - 1)
#define SRIDX_ISSTART_PREFIX '@'        // Prefix char for sending rate starting point
#define DEF_TESTINT_TIME     10         // Test interval time (sec)
#define MIN_TESTINT_TIME     5          //
#define MAX_TESTINT_TIME     3600       //
#define DEF_SUBINT_PERIOD    1          // Sub-interval period (sec)
#define MIN_SUBINT_PERIOD    1          //
#define MAX_SUBINT_PERIOD    10         //
#define DEF_CONTROL_PORT     25000      // Control port
#define MIN_CONTROL_PORT     0          // (0 = Random UDP ephemeral port)
#define MAX_CONTROL_PORT     UINT16_MAX //
#define DEF_BIMODAL_COUNT    0          // Bimodal initial sub-interval count
#define MIN_BIMODAL_COUNT    1          //
#define MAX_BIMODAL_COUNT    (MAX_TESTINT_TIME / MIN_SUBINT_PERIOD)
#define DEF_SOCKET_BUF       1024000        // Socket buffer to request
#define MIN_SOCKET_BUF       0              // (0 = System default/minimum)
#define MAX_SOCKET_BUF       16777216       //
#define DEF_LOW_THRESH       30             // Low delay variation threshold (ms)
#define MIN_LOW_THRESH       1              //
#define MAX_LOW_THRESH       10000          //
#define DEF_UPPER_THRESH     90             // Upper delay variation threshold (ms)
#define MIN_UPPER_THRESH     1              //
#define MAX_UPPER_THRESH     10000          //
#define DEF_TRIAL_INT        50             // Status feedback/trial interval (ms)
#define MIN_TRIAL_INT        5              //
#define MAX_TRIAL_INT        250            //
#define DEF_SLOW_ADJ_TH      3              // Slow adjustment threshold
#define MIN_SLOW_ADJ_TH      1              //
#define MAX_SLOW_ADJ_TH      UINT16_MAX     //
#define DEF_HS_DELTA         10             // High-speed delta (rows)
#define MIN_HS_DELTA         1              //
#define MAX_HS_DELTA         UINT8_MAX      //
#define DEF_SEQ_ERR_TH       10             // Sequence error threshold
#define MIN_SEQ_ERR_TH       0              //
#define MAX_SEQ_ERR_TH       UINT16_MAX     //
#define DEF_LOGFILE_MAX      1000           // Log file max size (KBytes)
#define MIN_LOGFILE_MAX      10             //
#define MAX_LOGFILE_MAX      1000000        //
#define MIN_REQUIRED_BW      1              // Required OR available bandwidth (Mbps)
#define MAX_CLIENT_BW        10000          //
#define MAX_SERVER_BW        100000         //
#define DEF_RA_ALGO          CHTA_RA_ALGO_B // Default rate adjustment algorithm

//----------------------------------------------------------------------------
//
// Sending rate payload, protocol, and buffer sizes
//
#define MAX_SENDING_RATES 1091                   // Max rows in sending rate table
#define BASE_SEND_TIMER1  MIN_INTERVAL_USEC      // Base send timer, transmitter 1 (us)
#define BASE_SEND_TIMER2  1000                   // Base send timer, transmitter 2 (us)
#define MAX_L3_PACKET     1250                   // Max desired L3 packet size
#define MAX_JL3_PACKET    9000                   // Max desired jumbo L3 packet
#define MAX_TL3_PACKET    1500                   // Max desired traditional L3 packet
#define L3DG_OVERHEAD     (8 + 20)               // UDP + IPv4
#define L2DG_OVERHEAD     (8 + 20 + 14)          // UDP + IPv4 + Eth(NoFCS)
#define L1DG_OVERHEAD     (8 + 20 + 18 + 20)     // UDP + IPv4 + Eth(w/FCS) + Preamble/IFG
#define L0DG_OVERHEAD     (8 + 20 + 18 + 20 + 4) // UDP + IPv4 + Eth(w/FCS) + Preamble/IFG + VLAN
#define IPV6_ADDSIZE      20                     // IPv6 additional size (over IPv4)
#define MIN_PAYLOAD_SIZE  (sizeof(struct loadHdr) + IPV6_ADDSIZE)
#define MAX_PAYLOAD_SIZE  (MAX_L3_PACKET - L3DG_OVERHEAD)
#define MAX_JPAYLOAD_SIZE (MAX_JL3_PACKET - L3DG_OVERHEAD)
#define MAX_TPAYLOAD_SIZE (MAX_TL3_PACKET - L3DG_OVERHEAD)
//
// The send buffer needs to contain all the datagram payloads for a burst. The maximum
// burst size that is used with non-jumbo payloads is actually much larger than the maximum
// burst size used with jumbo payloads.
//
#define SND_BUFFER_SIZE (MAX_BURST_SIZE * MAX_TPAYLOAD_SIZE)
#define DEF_BUFFER_SIZE 65536

#endif // UDPST_GLOBAL_H