You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
279 lines
10 KiB
279 lines
10 KiB
/* |
|
* etcpmon_protocol.h - ETCP Monitor Protocol Definitions |
|
* |
|
* Binary protocol for monitoring ETCP connections |
|
* Format: [2 bytes: msg_size] [1 byte: msg_type] [payload...] |
|
* |
|
* Period: 100ms (10 updates per second) |
|
*/ |
|
|
|
#ifndef ETCPMON_PROTOCOL_H |
|
#define ETCPMON_PROTOCOL_H |
|
|
|
#include <stdint.h> |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
/* ============================================================================ |
|
* Protocol Constants |
|
* ============================================================================ */ |
|
|
|
#define ETCPMON_PROTOCOL_VERSION 1 |
|
#define ETCPMON_MAX_MSG_SIZE 4096 |
|
#define ETCPMON_MAX_CONN_NAME 32 |
|
#define ETCPMON_MAX_CONNECTIONS 256 |
|
#define ETCPMON_MAX_LINKS 16 |
|
|
|
/* Update interval in milliseconds */ |
|
#define ETCPMON_UPDATE_INTERVAL_MS 100 |
|
|
|
/* ============================================================================ |
|
* Message Types |
|
* ============================================================================ */ |
|
|
|
/* Client -> Server commands */ |
|
#define ETCPMON_CMD_LIST_CONN 0x01 /* Request connection list */ |
|
#define ETCPMON_CMD_SELECT_CONN 0x02 /* Select connection by peer_node_id */ |
|
#define ETCPMON_CMD_GET_METRICS 0x03 /* Request metrics for selected */ |
|
#define ETCPMON_CMD_DISCONNECT 0x04 /* Disconnect from monitoring */ |
|
|
|
/* Server -> Client responses */ |
|
#define ETCPMON_RSP_CONN_LIST 0x81 /* Connection list response */ |
|
#define ETCPMON_RSP_METRICS 0x82 /* Metrics response */ |
|
#define ETCPMON_RSP_ERROR 0xFF /* Error response */ |
|
|
|
/* Error codes for RSP_ERROR */ |
|
#define ETCPMON_ERR_INVALID_CMD 0x01 /* Unknown command */ |
|
#define ETCPMON_ERR_INVALID_CONN 0x02 /* Invalid connection ID */ |
|
#define ETCPMON_ERR_NO_CONN_SELECTED 0x03 /* No connection selected */ |
|
#define ETCPMON_ERR_SERVER_BUSY 0x04 /* Server too busy */ |
|
|
|
/* ============================================================================ |
|
* Message Header |
|
* ============================================================================ |
|
* seq_id: 0 = broadcast/unsolicited, 1-255 = request/response pair */ |
|
|
|
#pragma pack(push, 1) |
|
|
|
struct etcpmon_msg_header { |
|
uint16_t size; /* Total message size including header */ |
|
uint8_t type; /* Message type (command or response) */ |
|
uint8_t seq_id; /* Sequence ID: request pairs use same ID */ |
|
}; |
|
|
|
/* ============================================================================ |
|
* Commands (Client -> Server) |
|
* ============================================================================ */ |
|
|
|
/* CMD_LIST_CONN: No payload required */ |
|
|
|
/* CMD_SELECT_CONN: Select connection to monitor */ |
|
struct etcpmon_cmd_select { |
|
uint64_t peer_node_id; /* peer_node_id of connection to monitor */ |
|
}; |
|
|
|
/* CMD_GET_METRICS: No payload required (uses previously selected connection) */ |
|
|
|
/* CMD_DISCONNECT: No payload required */ |
|
|
|
/* ============================================================================ |
|
* Responses (Server -> Client) |
|
* ============================================================================ */ |
|
|
|
/* RSP_CONN_LIST: List of active connections */ |
|
struct etcpmon_conn_info { |
|
uint64_t peer_node_id; /* Connection identifier */ |
|
char name[ETCPMON_MAX_CONN_NAME]; /* Null-terminated name */ |
|
}; |
|
|
|
struct etcpmon_rsp_conn_list { |
|
uint8_t count; /* Number of connections */ |
|
/* Followed by count * struct etcpmon_conn_info */ |
|
}; |
|
|
|
/* RSP_METRICS: Full metrics for ETCP connection and its links */ |
|
|
|
/* ETCP Connection metrics */ |
|
struct etcpmon_etcp_metrics { |
|
uint64_t peer_node_id; /* Connection identifier */ |
|
uint32_t rtt_last; /* Last RTT (0.1ms units) */ |
|
uint32_t rtt_avg_10; /* Average RTT over 10 packets */ |
|
uint32_t rtt_avg_100; /* Average RTT over 100 packets */ |
|
uint32_t jitter; /* Jitter (max-min RTT) */ |
|
uint64_t bytes_sent_total; /* Total bytes sent */ |
|
uint32_t retrans_count; /* Retransmission count */ |
|
uint32_t ack_count; /* ACK packets received */ |
|
uint32_t unacked_bytes; /* Current unacknowledged bytes */ |
|
uint32_t optimal_inflight; /* Target inflight window */ |
|
uint8_t links_count; /* Number of active links */ |
|
|
|
/* Queue metrics */ |
|
uint32_t input_queue_bytes; |
|
uint32_t input_queue_packets; |
|
uint32_t input_send_q_bytes; |
|
uint32_t input_send_q_packets; |
|
uint32_t input_wait_ack_bytes; |
|
uint32_t input_wait_ack_packets; |
|
uint32_t ack_q_bytes; |
|
uint32_t ack_q_packets; |
|
uint32_t recv_q_bytes; |
|
uint32_t recv_q_packets; |
|
uint32_t output_queue_bytes; |
|
uint32_t output_queue_packets; |
|
|
|
/* Error counters */ |
|
uint32_t reinit_count; |
|
uint32_t reset_count; |
|
uint32_t pkt_format_errors; |
|
|
|
/* Timer flags (1 = active, 0 = NULL) */ |
|
uint8_t retrans_timer_active; |
|
uint8_t ack_resp_timer_active; |
|
|
|
/* input_wait_ack queue state */ |
|
uint8_t wait_ack_cb_suspended; |
|
uint8_t wait_ack_cb_set; |
|
uint8_t wait_ack_resume_timeout; |
|
|
|
/* Connection IDs */ |
|
uint32_t next_tx_id; |
|
uint32_t last_rx_id; |
|
uint32_t last_delivered_id; |
|
uint32_t rx_ack_till; |
|
|
|
/* Normalizer */ |
|
uint32_t norm_input_pkts; |
|
uint32_t norm_input_bytes; |
|
uint32_t norm_output_pkts; |
|
uint32_t norm_output_bytes; |
|
uint32_t norm_alloc_errors; |
|
uint32_t norm_logic_errors; |
|
uint16_t norm_frag_size; |
|
uint16_t norm_data_ptr; |
|
uint16_t norm_data_size; |
|
uint64_t norm_in_total_pkts; |
|
uint64_t norm_in_total_bytes; |
|
uint64_t norm_out_total_pkts; |
|
uint64_t norm_out_total_bytes; |
|
|
|
/* ACK debug counters */ |
|
uint32_t cnt_ack_hit_inf; |
|
uint32_t cnt_ack_hit_sndq; |
|
uint32_t cnt_ack_miss; |
|
uint32_t cnt_link_wait; |
|
uint32_t tx_state; |
|
uint32_t debug[8]; |
|
}; |
|
|
|
/* Link metrics */ |
|
struct etcpmon_link_metrics { |
|
uint8_t local_link_id; /* Local link identifier */ |
|
uint8_t status; /* 1 = up, 0 = down */ |
|
uint32_t encrypt_errors; /* Encryption errors */ |
|
uint32_t decrypt_errors; /* Decryption errors */ |
|
uint32_t send_errors; /* Send errors */ |
|
uint32_t recv_errors; /* Receive errors */ |
|
uint64_t total_encrypted; /* Total bytes encrypted/sent */ |
|
uint64_t total_decrypted; /* Total bytes decrypted/received */ |
|
uint32_t bandwidth; /* Configured bandwidth (Kbps) */ |
|
uint32_t nat_changes_count; /* NAT address changes */ |
|
uint32_t rtt_last; /* Last RTT (0.1ms units) */ |
|
uint32_t tt_last; /* Last transmit time (0.1ms units) */ |
|
|
|
/* Timer flags (1 = active, 0 = NULL) */ |
|
uint8_t init_timer_active; |
|
uint8_t keepalive_timer_active; |
|
uint8_t shaper_timer_active; |
|
|
|
/* Keepalive counters */ |
|
uint32_t keepalive_sent; |
|
uint32_t keepalive_recv; |
|
}; |
|
|
|
/* TUN interface metrics */ |
|
struct etcpmon_tun_metrics { |
|
uint64_t bytes_read; /* Bytes read from TUN */ |
|
uint64_t bytes_written; /* Bytes written to TUN */ |
|
uint32_t packets_read; /* Packets read from TUN */ |
|
uint32_t packets_written; /* Packets written to TUN */ |
|
uint32_t read_errors; /* Read error count */ |
|
uint32_t write_errors; /* Write error count */ |
|
|
|
/* Routing statistics */ |
|
uint64_t routed_packets; /* Successfully routed packets */ |
|
uint64_t dropped_packets; /* Dropped packets */ |
|
|
|
/* TUN queues */ |
|
uint32_t tun_in_q_packets; /* Packets in TUN input queue */ |
|
uint32_t tun_in_q_bytes; /* Bytes in TUN input queue */ |
|
uint32_t tun_out_q_packets; /* Packets in TUN output queue */ |
|
uint32_t tun_out_q_bytes; /* Bytes in TUN output queue */ |
|
|
|
/* Routing table */ |
|
uint32_t rt_count; /* Total routes in table */ |
|
uint32_t rt_local; /* Local routes */ |
|
uint32_t rt_learned; /* Learned routes (BGP) */ |
|
}; |
|
|
|
struct etcpmon_rsp_metrics { |
|
struct etcpmon_etcp_metrics etcp; /* ETCP connection metrics */ |
|
struct etcpmon_tun_metrics tun; /* TUN interface metrics */ |
|
/* Followed by etcp.links_count * struct etcpmon_link_metrics */ |
|
}; |
|
|
|
/* RSP_ERROR: Error response */ |
|
struct etcpmon_rsp_error { |
|
uint8_t error_code; /* Error code */ |
|
/* Followed by null-terminated error message string */ |
|
}; |
|
|
|
#pragma pack(pop) |
|
|
|
/* ============================================================================ |
|
* Helper Macros |
|
* ============================================================================ */ |
|
|
|
/* Calculate size of connection list response */ |
|
#define ETCPMON_CONN_LIST_SIZE(count) \ |
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_conn_list) + \ |
|
(count) * sizeof(struct etcpmon_conn_info)) |
|
|
|
/* Calculate size of metrics response */ |
|
#define ETCPMON_METRICS_SIZE(links_count) \ |
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_metrics) + \ |
|
(links_count) * sizeof(struct etcpmon_link_metrics)) |
|
|
|
/* Calculate size of error response */ |
|
#define ETCPMON_ERROR_SIZE(msg_len) \ |
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_error) + (msg_len) + 1) |
|
|
|
/* ============================================================================ |
|
* Utility Functions (optional, for both client and server) |
|
* ============================================================================ */ |
|
|
|
/* Build message header */ |
|
static inline void etcpmon_build_header(struct etcpmon_msg_header* hdr, |
|
uint16_t payload_size, |
|
uint8_t msg_type, |
|
uint8_t seq_id) { |
|
hdr->size = sizeof(struct etcpmon_msg_header) + payload_size; |
|
hdr->type = msg_type; |
|
hdr->seq_id = seq_id; |
|
} |
|
|
|
/* Validate message header */ |
|
static inline int etcpmon_validate_header(const struct etcpmon_msg_header* hdr) { |
|
if (hdr->size < sizeof(struct etcpmon_msg_header) || |
|
hdr->size > ETCPMON_MAX_MSG_SIZE) { |
|
return -1; |
|
} |
|
return 0; |
|
} |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
|
|
#endif /* ETCPMON_PROTOCOL_H */
|
|
|