16#include "rte/oal/memory/rte_mem_util.h"
19#define MAX_LINE_LEN 256U
31 while ((*start !=
'\0') && (isspace((
unsigned char)*start) != 0))
38 (void)memmove(str, start, strlen(start) + 1U);
46 end = str + strlen(str) - 1U;
47 while ((end >= str) && (isspace((
unsigned char)*end) != 0))
70 rte_mem_set(ch, 0,
sizeof(*ch));
71 (void)snprintf(ch->
name,
sizeof(ch->
name),
"%.*s", (
int)(
sizeof(ch->
name) - 1U), name);
83 return RTE_STATUS_INVALID_PARAM;
86 rte_mem_set(out_cfg, 0,
sizeof(*out_cfg));
104 return RTE_STATUS_OK;
111 uint32_t num_val = (uint32_t)strtoul(val, NULL, 10);
113 if (strcmp(key,
"cycle_period_ms") == 0)
117 else if (strcmp(key,
"watchdog_timeout_ms") == 0)
121 else if (strcmp(key,
"checkpoint_max_delay_ms") == 0)
125 else if (strcmp(key,
"checkpoint_relaxed_max_delay_ms") == 0)
129 else if (strcmp(key,
"checkpoint_relax_duration_ms") == 0)
133 else if (strcmp(key,
"checkpoint_reenable_grace_ms") == 0)
137 else if (strcmp(key,
"dual_transfer_timeout_ms") == 0)
141 else if (strcmp(key,
"channel_down_reboot_ms") == 0)
145 else if (strcmp(key,
"link_timeout_ms") == 0)
149 else if (strcmp(key,
"connect_timeout_ms") == 0)
153 else if (strcmp(key,
"reconnect_attempt_timeout_ms") == 0)
157 else if (strcmp(key,
"neg_ack_timeout_ms") == 0)
172 if (strcmp(key,
"id") == 0)
174 ch->
id = (uint32_t)strtoul(val, NULL, 10);
176 else if (strcmp(key,
"role") == 0)
178 if ((strcmp(val,
"LISTEN") == 0) || (strcmp(val,
"listen") == 0))
180 ch->
role = RTE_NETLINK_ROLE_LISTEN;
184 ch->
role = RTE_NETLINK_ROLE_CONNECT;
187 else if (strcmp(key,
"host") == 0)
189 (void)snprintf(ch->
host,
sizeof(ch->
host),
"%.*s", (
int)(
sizeof(ch->
host) - 1U), val);
191 else if (strcmp(key,
"port") == 0)
193 ch->
port = (uint16_t)strtoul(val, NULL, 10);
195 else if (strcmp(key,
"message_size") == 0)
199 else if (strcmp(key,
"connect_timeout_ms") == 0)
214 if (strcmp(key,
"site") == 0)
218 else if (strcmp(key,
"role") == 0)
220 cfg->
is_role_a = ((strcmp(val,
"A") == 0) || (strcmp(val,
"a") == 0));
232 char current_section[64] =
"";
235 if ((filepath == NULL) || (out_cfg == NULL))
237 return RTE_STATUS_INVALID_PARAM;
240 fp = fopen(filepath,
"r");
243 return RTE_STATUS_RESOURCE_EXHAUSTED;
246 while (fgets(line, (
int)
sizeof(line), fp) != NULL)
254 comment = strpbrk(line,
"#;");
267 if ((line[0] ==
'[') && (line[strlen(line) - 1U] ==
']'))
269 line[strlen(line) - 1U] =
'\0';
271 (void)snprintf(current_section,
sizeof(current_section),
"%.*s", (
int)(
sizeof(current_section) - 1U), &line[1]);
274 if (strncmp(current_section,
"channel.", 8) == 0)
286 eq = strchr(line,
'=');
298 if (strcmp(current_section,
"timers") == 0)
302 else if (current_ch != NULL)
313 return RTE_STATUS_OK;
317 rte_netlink_config_t *out_netlink_cfg)
321 if ((cfg == NULL) || (channel_name == NULL) || (out_netlink_cfg == NULL))
323 return RTE_STATUS_INVALID_PARAM;
331 rte_mem_set(out_netlink_cfg, 0,
sizeof(*out_netlink_cfg));
332 out_netlink_cfg->role = ch->
role;
333 out_netlink_cfg->host = (ch->
role == RTE_NETLINK_ROLE_CONNECT && ch->
host[0] !=
'\0') ? ch->
host : NULL;
334 out_netlink_cfg->port = ch->
port;
338 return RTE_STATUS_OK;
342 return RTE_STATUS_RESOURCE_EXHAUSTED;
346 rte_netlink_config_t *out_netlink_cfg)
350 if ((cfg == NULL) || (channel_id == 0U) || (out_netlink_cfg == NULL))
352 return RTE_STATUS_INVALID_PARAM;
360 rte_mem_set(out_netlink_cfg, 0,
sizeof(*out_netlink_cfg));
361 out_netlink_cfg->role = ch->
role;
362 out_netlink_cfg->host = (ch->
role == RTE_NETLINK_ROLE_CONNECT && ch->
host[0] !=
'\0') ? ch->
host : NULL;
363 out_netlink_cfg->port = ch->
port;
367 return RTE_STATUS_OK;
371 return RTE_STATUS_RESOURCE_EXHAUSTED;
static ab_gp_config_channel_t * get_or_create_channel(ab_gp_config_t *cfg, const char *name)
static void apply_channel_setting(ab_gp_config_channel_t *ch, const char *key, const char *val)
static void apply_global_setting(ab_gp_config_t *cfg, const char *key, const char *val)
rte_status_t ab_gp_config_find_channel_by_id(const ab_gp_config_t *cfg, uint32_t channel_id, rte_netlink_config_t *out_netlink_cfg)
Resolves netlink configuration for a channel by numeric ID from the parsed config.
rte_status_t ab_gp_config_load_file(const char *filepath, ab_gp_config_t *out_cfg)
Parses an INI-style configuration file into the static ab_gp_config_t structure.
rte_status_t ab_gp_config_init_defaults(rte_example_site_t site, bool is_role_a, ab_gp_config_t *out_cfg)
Initializes default configuration in memory based on site and role.
static void trim_whitespace(char *str)
static void apply_timer_setting(ab_gp_config_timers_t *timers, const char *key, const char *val)
rte_status_t ab_gp_config_find_channel(const ab_gp_config_t *cfg, const char *channel_name, rte_netlink_config_t *out_netlink_cfg)
Resolves netlink configuration for a named channel from the parsed config.
Zero-dependency, statically-allocated configuration parser for Role A/B.
#define AB_GP_CONFIG_MAX_CHANNELS
#define RTE_EXAMPLE_AB_DUAL_TRANSFER_TIMEOUT_MS
#define RTE_EXAMPLE_RECONNECT_ATTEMPT_TIMEOUT_MS
#define RTE_EXAMPLE_NEG_ACK_TIMEOUT_MS
#define RTE_EXAMPLE_AB_CHECKPOINT_MAX_DELAY_MS
#define RTE_EXAMPLE_AB_WATCHDOG_TIMEOUT_MS
#define RTE_EXAMPLE_CHANNEL_DOWN_REBOOT_MS
#define RTE_EXAMPLE_CHECKPOINT_REENABLE_GRACE_MS
#define RTE_EXAMPLE_CHECKPOINT_RELAX_DURATION_MS
#define RTE_EXAMPLE_AB_CHECKPOINT_RELAXED_MAX_DELAY_MS
#define RTE_EXAMPLE_LINK_TIMEOUT_MS
#define RTE_EXAMPLE_CONNECT_TIMEOUT_MS
#define RTE_EXAMPLE_AB_CYCLE_PERIOD_MS
bool site_config_parse(const char *arg, rte_example_site_t *out_site)
Parses a site name argument ("WEST"/"EAST", case-insensitive).
char host[AB_GP_CONFIG_HOST_MAX_LEN]
uint32_t connect_timeout_ms
char name[AB_GP_CONFIG_NAME_MAX_LEN]
ab_gp_config_channel_t channels[AB_GP_CONFIG_MAX_CHANNELS]
ab_gp_config_timers_t timers
uint32_t checkpoint_relaxed_max_delay_ms
uint32_t dual_transfer_timeout_ms
uint32_t checkpoint_max_delay_ms
uint32_t channel_down_reboot_ms
uint32_t checkpoint_relax_duration_ms
uint32_t neg_ack_timeout_ms
uint32_t reconnect_attempt_timeout_ms
uint32_t checkpoint_reenable_grace_ms
uint32_t connect_timeout_ms
uint32_t watchdog_timeout_ms