From 937d563f3151ce80b6927010a0196b53b6cbb0da Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Fri, 10 Dec 2021 14:41:56 +0100 Subject: [PATCH 1/2] traffic stream fixes --- src/bbl_a10nsp.c | 4 +++- src/bbl_l2tp.c | 4 +++- src/bbl_stream.c | 52 +++++++++++++++++++++++++----------------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/bbl_a10nsp.c b/src/bbl_a10nsp.c index 5a6c6e7d..cc574a73 100644 --- a/src/bbl_a10nsp.c +++ b/src/bbl_a10nsp.c @@ -272,7 +272,9 @@ bbl_a10nsp_pppoes_handler(bbl_interface_s *interface, stream = *search; stream->packets_rx++; stream->rx_len = eth->length; - stream->rx_priority = ((bbl_ipv4_t*)eth->next)->tos; + stream->rx_priority = ipv4->tos; + stream->rx_outer_vlan_pbit = eth->vlan_outer_priority; + stream->rx_inner_vlan_pbit = eth->vlan_inner_priority; timespec_sub(&delay, ð->timestamp, &bbl->timestamp); delay_nsec = delay.tv_sec * 1e9 + delay.tv_nsec; if(delay_nsec > stream->max_delay_ns) { diff --git a/src/bbl_l2tp.c b/src/bbl_l2tp.c index 49d50eee..b3197c52 100644 --- a/src/bbl_l2tp.c +++ b/src/bbl_l2tp.c @@ -1026,7 +1026,9 @@ bbl_l2tp_data_rx(bbl_ethernet_header_t *eth, bbl_l2tp_t *l2tp, bbl_interface_s * stream = *search; stream->packets_rx++; stream->rx_len = eth->length; - stream->rx_priority = ((bbl_ipv4_t*)eth->next)->tos; + stream->rx_priority = ipv4->tos; + stream->rx_outer_vlan_pbit = eth->vlan_outer_priority; + stream->rx_inner_vlan_pbit = eth->vlan_inner_priority; timespec_sub(&delay, ð->timestamp, &bbl->timestamp); delay_nsec = delay.tv_sec * 1e9 + delay.tv_nsec; if(delay_nsec > stream->max_delay_ns) { diff --git a/src/bbl_stream.c b/src/bbl_stream.c index 134284a3..e142b0da 100644 --- a/src/bbl_stream.c +++ b/src/bbl_stream.c @@ -148,6 +148,7 @@ bbl_stream_build_access_pppoe_packet(bbl_stream *stream) { bbl.outer_vlan_id = session->vlan_key.outer_vlan_id; bbl.inner_vlan_id = session->vlan_key.inner_vlan_id; bbl.flow_id = stream->flow_id; + bbl.tos = config->priority; bbl.direction = BBL_DIRECTION_UP; switch (stream->config->type) { @@ -263,10 +264,10 @@ bbl_stream_build_a10nsp_pppoe_packet(bbl_stream *stream) { eth.qinq = a10nsp_if->qinq; eth.vlan_outer = a10nsp_session->s_vlan; } - eth.vlan_outer_priority = config->vlan_priority; eth.vlan_inner = session->vlan_key.inner_vlan_id; - eth.vlan_inner_priority = config->vlan_priority; eth.vlan_three = session->access_third_vlan; + eth.vlan_outer_priority = config->vlan_priority; + eth.vlan_inner_priority = config->vlan_priority; eth.type = ETH_TYPE_PPPOE_SESSION; eth.next = &pppoe; pppoe.session_id = session->pppoe_session_id; @@ -280,7 +281,7 @@ bbl_stream_build_a10nsp_pppoe_packet(bbl_stream *stream) { bbl.outer_vlan_id = session->vlan_key.outer_vlan_id; bbl.inner_vlan_id = session->vlan_key.inner_vlan_id; bbl.flow_id = stream->flow_id; - + bbl.tos = config->priority; switch (stream->config->type) { case STREAM_IPV4: pppoe.protocol = PROTOCOL_IPV4; @@ -388,10 +389,10 @@ bbl_stream_build_access_ipoe_packet(bbl_stream *stream) { eth.src = session->client_mac; eth.qinq = session->access_config->qinq; eth.vlan_outer = session->vlan_key.outer_vlan_id; - eth.vlan_outer_priority = config->vlan_priority; eth.vlan_inner = session->vlan_key.inner_vlan_id; - eth.vlan_inner_priority = config->vlan_priority; eth.vlan_three = session->access_third_vlan; + eth.vlan_inner_priority = config->vlan_priority; + eth.vlan_outer_priority = config->vlan_priority; udp.src = BBL_UDP_PORT; udp.dst = BBL_UDP_PORT; @@ -403,6 +404,7 @@ bbl_stream_build_access_ipoe_packet(bbl_stream *stream) { bbl.outer_vlan_id = session->vlan_key.outer_vlan_id; bbl.inner_vlan_id = session->vlan_key.inner_vlan_id; bbl.flow_id = stream->flow_id; + bbl.tos = config->priority; bbl.direction = BBL_DIRECTION_UP; switch (stream->config->type) { @@ -519,6 +521,7 @@ bbl_stream_build_network_packet(bbl_stream *stream) { bbl.inner_vlan_id = session->vlan_key.inner_vlan_id; } bbl.flow_id = stream->flow_id; + bbl.tos = config->priority; bbl.direction = BBL_DIRECTION_DOWN; switch (stream->config->type) { case STREAM_IPV4: @@ -667,6 +670,7 @@ bbl_stream_build_l2tp_packet(bbl_stream *stream) { bbl.outer_vlan_id = session->vlan_key.outer_vlan_id; bbl.inner_vlan_id = session->vlan_key.inner_vlan_id; bbl.flow_id = stream->flow_id; + bbl.tos = config->priority; bbl.direction = BBL_DIRECTION_DOWN; bbl.sub_type = BBL_SUB_TYPE_IPV4; if (config->length > 76) { @@ -1177,6 +1181,7 @@ bbl_stream_add(bbl_ctx_s *ctx, bbl_access_config_s *access_config, bbl_session_s bbl_stream *stream; bbl_stream *session_stream; bbl_stream_thread *thread; + bbl_interface_s *network_if; dict_insert_result result; @@ -1184,28 +1189,25 @@ bbl_stream_add(bbl_ctx_s *ctx, bbl_access_config_s *access_config, bbl_session_s long timer_nsec = 0; config = ctx->config.stream_config; - - /* * - * The corresponding network interfaces will be selected - * in the following order: - * - "network-interface" from stream section - * - "network-interface" from access interface section - * - first network interface from network section (default) - */ - bbl_interface_s *network_if; - if(config->network_interface) { - network_if = bbl_get_network_interface(ctx, config->network_interface); - } else if(config->a10nsp_interface) { - network_if = bbl_get_a10nsp_interface(ctx, config->a10nsp_interface); - } else { - network_if = session->network_interface; - } - if(!network_if) { - return false; - } - while(config) { if(config->stream_group_id == access_config->stream_group_id) { + /* * + * The corresponding network interfaces will be selected + * in the following order: + * - "network-interface" from stream section + * - "network-interface" from access interface section + * - first network interface from network section (default) + */ + if(config->network_interface) { + network_if = bbl_get_network_interface(ctx, config->network_interface); + } else if(config->a10nsp_interface) { + network_if = bbl_get_a10nsp_interface(ctx, config->a10nsp_interface); + } else { + network_if = session->network_interface; + } + if(!network_if) { + return false; + } if(!network_if) { LOG(ERROR, "Failed to add stream because of missing network interface\n"); return false; From 963624a34495b208c9fc39745de9c777f9ac8422 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Tue, 14 Dec 2021 11:09:54 +0100 Subject: [PATCH 2/2] add new start-delay config opton --- docs/config.md | 1 + src/bbl.c | 12 ++++++++++++ src/bbl_config.c | 4 ++++ src/bbl_ctx.h | 3 +++ 4 files changed, 20 insertions(+) diff --git a/docs/config.md b/docs/config.md index 26a317b1..404c60d1 100644 --- a/docs/config.md +++ b/docs/config.md @@ -450,6 +450,7 @@ Attribute | Description | Default `start-rate` | Setup request rate in sessions per second | 400 `stop-rate` | Teardown request rate in sessions per second | 400 `iterate-vlan-outer` | Iterate on outer VLAN first | false +`start-delay` | Wait N seconds after all interface are resolved before starting sessions | 0 Per default sessions are created by iteration over inner VLAN range first and outer VLAN second. Which can be changed by `iterate-vlan-outer` to iterate on outer VLAN first and inner VLAN second. diff --git a/src/bbl.c b/src/bbl.c index b7772a5d..15c525b4 100644 --- a/src/bbl.c +++ b/src/bbl.c @@ -246,6 +246,9 @@ bbl_ctrl_job (timer_s *timer) int rate = 0; uint32_t i; + struct timespec timestamp; + struct timespec time_diff; + /* Setup phase ... * Wait for all network interfaces to be resolved. */ if(g_init_phase && !g_teardown) { @@ -268,6 +271,7 @@ bbl_ctrl_job (timer_s *timer) } g_init_phase = false; LOG(INFO, "All network interfaces resolved\n"); + clock_gettime(CLOCK_MONOTONIC, &ctx->timestamp_resolved); } if(ctx->sessions_outstanding) ctx->sessions_outstanding--; @@ -307,6 +311,14 @@ bbl_ctrl_job (timer_s *timer) } } } else { + /* Wait N seconds (default 0) before we start to setup sessions. */ + if(ctx->config.sessions_start_delay) { + clock_gettime(CLOCK_MONOTONIC, ×tamp); + timespec_sub(&time_diff, ×tamp, &ctx->timestamp_resolved); + if(time_diff.tv_sec < ctx->config.sessions_start_delay) { + return; + } + } /* Iterate over all idle session (list of pending sessions) * and start as much as permitted per interval based on max * outstanding and setup rate. Sessions started will be removed diff --git a/src/bbl_config.c b/src/bbl_config.c index 6093b8c5..a774d5e2 100644 --- a/src/bbl_config.c +++ b/src/bbl_config.c @@ -879,6 +879,10 @@ json_parse_config (json_t *root, bbl_ctx_s *ctx) { if (json_is_boolean(value)) { ctx->config.iterate_outer_vlan = json_boolean_value(value); } + value = json_object_get(section, "start-delay"); + if (json_is_number(value)) { + ctx->config.sessions_start_delay = json_number_value(value); + } } /* IPoE Configuration */ diff --git a/src/bbl_ctx.h b/src/bbl_ctx.h index 9d09368f..b65d2a9e 100644 --- a/src/bbl_ctx.h +++ b/src/bbl_ctx.h @@ -36,6 +36,7 @@ typedef struct bbl_ctx_ struct timespec timestamp_start; struct timespec timestamp_stop; + struct timespec timestamp_resolved; uint32_t sessions; uint32_t sessions_pppoe; @@ -169,6 +170,8 @@ typedef struct bbl_ctx_ uint32_t sessions_max_outstanding; uint16_t sessions_start_rate; uint16_t sessions_stop_rate; + uint16_t sessions_start_delay; + bool iterate_outer_vlan; /* Static */