From bdd4c2d3fcfd8eb7ad3bd4f2d5b6318997359bd2 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Tue, 11 Oct 2022 21:18:14 +0000 Subject: [PATCH] fix session traffic --- code/bngblaster/src/bbl_config.c | 7 +++++-- code/bngblaster/src/bbl_stream.c | 34 ++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/code/bngblaster/src/bbl_config.c b/code/bngblaster/src/bbl_config.c index 648895f0..410d55db 100644 --- a/code/bngblaster/src/bbl_config.c +++ b/code/bngblaster/src/bbl_config.c @@ -1369,17 +1369,20 @@ json_parse_stream(json_t *stream, bbl_stream_config_s *stream_config) if(stream_config->stream_group_id == 0 && stream_config->direction != BBL_DIRECTION_DOWN) { - fprintf(stderr, "JSON config error: Invalid value for stream->direction (must be downstream for RAW streams)\n"); + fprintf(stderr, "JSON config error: Invalid value for stream->direction (must be downstream for RAW streams)\n"); return false; } if(json_unpack(stream, "{s:s}", "network-interface", &s) == 0) { stream_config->network_interface = strdup(s); } - if(json_unpack(stream, "{s:s}", "a10nsp-interface", &s) == 0) { stream_config->a10nsp_interface = strdup(s); } + if(stream_config->network_interface && stream_config->a10nsp_interface) { + fprintf(stderr, "JSON config error: Not allowed to set stream->network-interface and stream->a10nsp-interface\n"); + return false; + } value = json_object_get(stream, "source-port"); if(value) { diff --git a/code/bngblaster/src/bbl_stream.c b/code/bngblaster/src/bbl_stream.c index 1a7419d6..bd2cbb81 100644 --- a/code/bngblaster/src/bbl_stream.c +++ b/code/bngblaster/src/bbl_stream.c @@ -1425,8 +1425,30 @@ bbl_stream_session_add(bbl_stream_config_s *config, bbl_session_s *session) } } + if(config->session_traffic && !(network_interface || a10nsp_interface)) { + /* Skip session traffic if no network/a10nsp interface is found. */ + return true; + } + tx_interval = SEC / config->pps; if(config->direction & BBL_DIRECTION_UP) { + if(config->type == BBL_SUB_TYPE_IPV4) { + if(!((network_interface && network_interface->ip.address) || + config->ipv4_destination_address || + config->ipv4_network_address || + a10nsp_interface)) { + LOG(ERROR, "Failed to add stream %s (upstream) because of missing IPv4 destination address\n", config->name); + return false; + } + } else { + if(!((network_interface && *(uint64_t*)network_interface->ip6.address) || + *(uint64_t*)config->ipv6_destination_address || + *(uint64_t*)config->ipv6_network_address || + a10nsp_interface)) { + LOG(ERROR, "Failed to add stream %s (upstream) because of missing IPv6 destination address\n", config->name); + return false; + } + } stream = calloc(1, sizeof(bbl_stream_s)); stream->endpoint = &g_endpoint; stream->flow_id = g_ctx->flow_id++; @@ -1467,11 +1489,11 @@ bbl_stream_session_add(bbl_stream_config_s *config, bbl_session_s *session) g_ctx->stats.session_traffic_flows++; session->session_traffic.flows++; LOG(DEBUG, "Session traffic stream %s (upstream) added to %s (access) with %lf PPS\n", - access_interface->name, config->name, config->pps); + config->name, access_interface->name, config->pps); } else { g_ctx->stats.stream_traffic_flows++; LOG(DEBUG, "Traffic stream %s (upstream) added to %s (access) with %lf PPS\n", - access_interface->name, config->name, config->pps); + config->name, access_interface->name, config->pps); } } if(config->direction & BBL_DIRECTION_DOWN) { @@ -1516,11 +1538,11 @@ bbl_stream_session_add(bbl_stream_config_s *config, bbl_session_s *session) g_ctx->stats.session_traffic_flows++; session->session_traffic.flows++; LOG(DEBUG, "Session traffic stream %s (downstream) added to %s (network) with %lf PPS\n", - network_interface->name, config->name, config->pps); + config->name, network_interface->name, config->pps); } else { g_ctx->stats.stream_traffic_flows++; LOG(DEBUG, "Traffic stream %s (downstream) added to %s (network) with %lf PPS\n", - network_interface->name, config->name, config->pps); + config->name, network_interface->name, config->pps); } } else if(a10nsp_interface) { stream->a10nsp_interface = a10nsp_interface; @@ -1530,11 +1552,11 @@ bbl_stream_session_add(bbl_stream_config_s *config, bbl_session_s *session) g_ctx->stats.session_traffic_flows++; session->session_traffic.flows++; LOG(DEBUG, "Session traffic stream %s (downstream) added to %s (a10nsp) with %lf PPS\n", - network_interface->name, config->name, config->pps); + config->name, network_interface->name, config->pps); } else { g_ctx->stats.stream_traffic_flows++; LOG(DEBUG, "Traffic stream %s (downstream) added to %s (a10nsp) with %lf PPS\n", - network_interface->name, config->name, config->pps); + config->name, network_interface->name, config->pps); } } else { LOG(ERROR, "Failed to add stream %s (downstream) because of missing interface\n", config->name);