13#include "rte/oal/memory/rte_mem_util.h"
17#define MAX_CONFIG_FILE_SIZE 8192U
25 while ((*p !=
'\0') && (isspace((
unsigned char)*p) != 0))
43 while ((*p !=
'\0') && (*p !=
'"'))
45 if (idx + 1U < out_size)
66 val = strtoul(p, &endptr, 10);
71 *out_val = (uint32_t)val;
90 const char *start = q;
91 const char *result = NULL;
93 bool overflow =
false;
95 while ((!overflow) && (*q >=
'0') && (*q <=
'9'))
97 const uint32_t digit = (uint32_t)((uint8_t)*q) - (uint32_t)((uint8_t)
'0');
99 if (value > ((UINT32_MAX - digit) / 10U))
105 value = (value * 10U) + digit;
109 if ((!overflow) && (q != start))
113 if ((*after ==
',') || (*after ==
'}'))
126 return RTE_STATUS_INVALID_PARAM;
129 rte_mem_set(out_cfg, 0,
sizeof(*out_cfg));
130 out_cfg->
site = site;
136 return RTE_STATUS_OK;
143 if ((p != NULL) && (*p ==
','))
151static const char *
extract_into(
const char *p,
char *dest,
size_t dest_size)
156 if ((next != NULL) && (dest != NULL))
158 (void)snprintf(dest, dest_size,
"%.*s", (
int)(dest_size - 1U), text);
169 if ((next != NULL) && (field != NULL))
182 if ((next != NULL) && (field != NULL))
199 uint32_t number = 0U;
202 if (allow_identity && (strcmp(key,
"id") == 0))
206 if (allow_identity && (strcmp(key,
"name") == 0))
210 if (strcmp(key,
"role") == 0)
214 if ((next != NULL) && (ch != NULL))
216 ch->
role = ((strcmp(text,
"CONNECT") == 0) || (strcmp(text,
"connect") == 0))
217 ? RTE_NETLINK_ROLE_CONNECT
218 : RTE_NETLINK_ROLE_LISTEN;
222 if (strcmp(key,
"port") == 0)
226 if ((next != NULL) && (ch != NULL))
228 ch->
port = (uint16_t)number;
232 if (strcmp(key,
"host") == 0)
236 if (strcmp(key,
"message_size") == 0)
240 if (strcmp(key,
"connect_timeout_ms") == 0)
245 if (strcmp(key,
"rcvbuf_bytes") == 0)
249 if (strcmp(key,
"sndbuf_bytes") == 0)
274 rte_mem_set(ch, 0,
sizeof(*ch));
275 if (fixed_name != NULL)
277 (void)snprintf(ch->
name,
sizeof(ch->
name),
"%.*s", (
int)(
sizeof(ch->
name) - 1U), fixed_name);
284 while ((*p !=
'\0') && (*p !=
'}'))
322 while ((*p !=
'\0') && (*p !=
']'))
354 while ((*p !=
'\0') && (*p !=
'}'))
394 if (strcmp(key,
"site") == 0)
405 if (strcmp(key,
"report_period_ms") == 0)
409 if (strcmp(key,
"link_timeout_ms") == 0)
413 if (strcmp(key,
"connect_timeout_ms") == 0)
417 if (strcmp(key,
"reconnect_attempt_timeout_ms") == 0)
421 if (strcmp(key,
"channels") == 0)
442 if ((filepath == NULL) || (out_cfg == NULL))
444 return RTE_STATUS_INVALID_PARAM;
447 fp = fopen(filepath,
"r");
450 return RTE_STATUS_RESOURCE_EXHAUSTED;
453 bytes_read = fread(buffer, 1,
sizeof(buffer) - 1U, fp);
455 buffer[bytes_read] =
'\0';
484 return RTE_STATUS_INVALID_PARAM;
488 return RTE_STATUS_OK;
492 rte_netlink_config_t *out_netlink_cfg)
496 if ((cfg == NULL) || (channel_name == NULL) || (out_netlink_cfg == NULL))
498 return RTE_STATUS_INVALID_PARAM;
506 rte_mem_set(out_netlink_cfg, 0,
sizeof(*out_netlink_cfg));
507 out_netlink_cfg->role = ch->
role;
508 out_netlink_cfg->host = (ch->
role == RTE_NETLINK_ROLE_CONNECT && ch->
host[0] !=
'\0') ? ch->
host : NULL;
509 out_netlink_cfg->port = ch->
port;
515 return RTE_STATUS_OK;
519 return RTE_STATUS_RESOURCE_EXHAUSTED;
523 rte_netlink_config_t *out_netlink_cfg)
527 if ((cfg == NULL) || (channel_id == 0U) || (out_netlink_cfg == NULL))
529 return RTE_STATUS_INVALID_PARAM;
537 rte_mem_set(out_netlink_cfg, 0,
sizeof(*out_netlink_cfg));
538 out_netlink_cfg->role = ch->
role;
539 out_netlink_cfg->host = (ch->
role == RTE_NETLINK_ROLE_CONNECT && ch->
host[0] !=
'\0') ? ch->
host : NULL;
540 out_netlink_cfg->port = ch->
port;
546 return RTE_STATUS_OK;
550 return RTE_STATUS_RESOURCE_EXHAUSTED;
#define RTE_EXAMPLE_C_REPORT_PERIOD_MS
#define RTE_EXAMPLE_RECONNECT_ATTEMPT_TIMEOUT_MS
#define RBC_ENVELOPE_WIRE_SIZE
#define RTE_EXAMPLE_LINK_TIMEOUT_MS
#define RTE_EXAMPLE_CONNECT_TIMEOUT_MS
rte_status_t gateway_c_config_find_channel(const gateway_c_config_t *cfg, const char *channel_name, rte_netlink_config_t *out_netlink_cfg)
static const char * parse_channels_array(const char *p, gateway_c_config_t *cfg)
static const char * extract_string(const char *p, char *out, size_t out_size)
static const char * extract_buffer_size_into(const char *p, uint32_t *field)
rte_status_t gateway_c_config_init_defaults(rte_example_site_t site, gateway_c_config_t *out_cfg)
static const char * skip_separator(const char *p)
#define MAX_CONFIG_FILE_SIZE
static const char * skip_whitespace(const char *p)
static const char * extract_number_into(const char *p, uint32_t *field)
static const char * extract_into(const char *p, char *dest, size_t dest_size)
static const char * parse_channels_object(const char *p, gateway_c_config_t *cfg)
static const char * parse_channel_prop(const char *p, const char *key, gateway_c_config_channel_t *ch, bool allow_identity)
Parses the value of one channel property into ch.
static const char * extract_uint32_checked(const char *p, uint32_t *out_val)
Checked unsigned decimal parse, used for the socket buffer keys (REQ-OAL-NETLINK-015).
static const char * parse_top_level_value(const char *p, const char *key, gateway_c_config_t *cfg)
static const char * extract_uint32(const char *p, uint32_t *out_val)
rte_status_t gateway_c_config_find_channel_by_id(const gateway_c_config_t *cfg, uint32_t channel_id, rte_netlink_config_t *out_netlink_cfg)
static const char * parse_channel_object(const char *p, gateway_c_config_t *cfg, const char *fixed_name)
Parses one channel object; p points at its '{'.
rte_status_t gateway_c_config_load_file(const char *filepath, gateway_c_config_t *out_cfg)
Configuration data structures and parser for Role C Gateway (JSON-based).
#define GATEWAY_C_MAX_CHANNELS
The RBC Train/IL/CTC scenario's shared wire envelope (ADR-029) - one fixed-size struct/frame reused f...
bool site_config_parse(const char *arg, rte_example_site_t *out_site)
Parses a site name argument ("WEST"/"EAST", case-insensitive).
uint32_t connect_timeout_ms
gateway_c_config_timers_t timers
gateway_c_config_channel_t channels[GATEWAY_C_MAX_CHANNELS]
uint32_t reconnect_attempt_timeout_ms
uint32_t connect_timeout_ms
uint32_t report_period_ms