Skip to content

Commit

Permalink
Added calculation of LLC and LLC EAPOL message queue average (ARMmbed…
Browse files Browse the repository at this point in the history
…#2582)

Adaptation, LLC and LLC EAPOL average queues are summed and authentication
init/reject propability is calculated based on that.
  • Loading branch information
Mika Leppänen committed Mar 5, 2021
1 parent 7f7c01a commit fa20fb9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
56 changes: 46 additions & 10 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -105,7 +105,7 @@ static void ws_bootstrap_nw_frame_counter_read(protocol_interface_info_entry_t *
static void ws_bootstrap_nw_info_updated(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, uint16_t pan_version, char *network_name);
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, auth_result_e result, uint8_t *target_eui_64);
static const uint8_t *ws_bootstrap_authentication_next_target(protocol_interface_info_entry_t *cur, const uint8_t *previous_eui_64, uint16_t *pan_id);
static bool ws_bootstrap_congestion_get(protocol_interface_info_entry_t *interface_ptr, uint16_t active_supp);
static bool ws_bootstrap_eapol_congestion_get(protocol_interface_info_entry_t *interface_ptr, uint16_t active_supp);
static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t *cur);
static ws_nud_table_entry_t *ws_nud_entry_discover(protocol_interface_info_entry_t *cur, void *neighbor);
static void ws_nud_entry_remove(protocol_interface_info_entry_t *cur, mac_neighbor_table_entry_t *entry_ptr);
Expand Down Expand Up @@ -2332,7 +2332,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
ret_val = -4;
goto init_fail;
}
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_authentication_next_target, &ws_bootstrap_nw_key_set, &ws_bootstrap_nw_key_clear, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_nw_frame_counter_set, &ws_bootstrap_nw_frame_counter_read, &ws_bootstrap_pan_version_increment, &ws_bootstrap_nw_info_updated, &ws_bootstrap_congestion_get) < 0) {
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_authentication_next_target, &ws_bootstrap_nw_key_set, &ws_bootstrap_nw_key_clear, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_nw_frame_counter_set, &ws_bootstrap_nw_frame_counter_read, &ws_bootstrap_pan_version_increment, &ws_bootstrap_nw_info_updated, &ws_bootstrap_eapol_congestion_get) < 0) {
ret_val = -4;
goto init_fail;
}
Expand Down Expand Up @@ -3215,15 +3215,41 @@ static const uint8_t *ws_bootstrap_authentication_next_target(protocol_interface
return previous_eui_64;
}

static bool ws_bootstrap_congestion_get(protocol_interface_info_entry_t *interface_ptr, uint16_t active_supp)
static void ws_bootstrap_eapol_congestion_init(protocol_interface_info_entry_t *cur)
{
if (interface_ptr == NULL || interface_ptr->random_early_detection == NULL) {
random_early_detection_free(cur->llc_random_early_detection);
cur->llc_random_early_detection = NULL;

if (cur->llc_random_early_detection == NULL) {
cur->llc_random_early_detection = random_early_detection_create(
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_min,
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_max,
100, RED_AVERAGE_WEIGHT_EIGHTH);
}

random_early_detection_free(cur->llc_eapol_random_early_detection);
cur->llc_eapol_random_early_detection = NULL;

if (cur->llc_eapol_random_early_detection == NULL) {
cur->llc_eapol_random_early_detection = random_early_detection_create(
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_min,
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_max,
100, RED_AVERAGE_WEIGHT_EIGHTH);
}
}

static bool ws_bootstrap_eapol_congestion_get(protocol_interface_info_entry_t *cur, uint16_t active_supp)
{
if (cur == NULL || cur->random_early_detection == NULL || cur->llc_random_early_detection == NULL || cur->llc_eapol_random_early_detection == NULL) {
return false;
}

bool return_value = false;
static struct red_info_s *red_info = NULL;
uint16_t average = 0;
uint16_t adaptation_average = 0;
uint16_t llc_average = 0;
uint16_t llc_eapol_average = 0;
uint16_t average_sum = 0;
uint8_t active_max = 0;

//TODO implement API for HEAP info request
Expand All @@ -3248,6 +3274,13 @@ static bool ws_bootstrap_congestion_get(protocol_interface_info_entry_t *interfa
active_max = 50;
}

// Read the values for adaptation and LLC queues
adaptation_average = random_early_detetction_aq_read(cur->random_early_detection);
llc_average = random_early_detetction_aq_read(cur->llc_random_early_detection);
llc_eapol_average = random_early_detetction_aq_read(cur->llc_eapol_random_early_detection);
// Calculate combined average
average_sum = adaptation_average + llc_average + llc_eapol_average;

// Maximum for active supplicants based on memory reached, fail
if (active_supp >= active_max) {
return_value = true;
Expand All @@ -3261,20 +3294,20 @@ static bool ws_bootstrap_congestion_get(protocol_interface_info_entry_t *interfa

if (red_info == NULL) {
red_info = random_early_detection_create(
interface_ptr->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_min,
interface_ptr->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_max,
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_min,
cur->ws_info->cfg->sec_prot.max_simult_sec_neg_tx_queue_max,
100, RED_AVERAGE_WEIGHT_DISABLED);
}
if (red_info == NULL) {
goto congestion_get_end;
}

average = random_early_detetction_aq_read(interface_ptr->random_early_detection);
average = random_early_detetction_aq_calc(red_info, average);
// Check drop probability
average_sum = random_early_detetction_aq_calc(red_info, average_sum);
return_value = random_early_detection_congestion_check(red_info);

congestion_get_end:
tr_info("Active supplicant limit, active: %i max: %i averageQ: %i drop: %s", active_supp, active_max, average, return_value ? "T" : "F");
tr_info("Active supplicant limit, active: %i max: %i summed averageQ: %i adapt averageQ: %i LLC averageQ: %i LLC EAPOL averageQ: %i drop: %s", active_supp, active_max, average_sum, adaptation_average, llc_average, llc_eapol_average, return_value ? "T" : "F");

return return_value;
}
Expand Down Expand Up @@ -3628,6 +3661,9 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
// Set PAE port to 10254 and authenticator relay to 10253 (and to own ll address)
ws_pae_controller_authenticator_start(cur, PAE_AUTH_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);

// Initialize eapol congestion tracking
ws_bootstrap_eapol_congestion_init(cur);

// Set retry configuration for bootstrap ready state
ws_bootstrap_configure_max_retries(cur, WS_MAX_FRAME_RETRIES, WS_NUMBER_OF_CHANNEL_RETRIES);

Expand Down
11 changes: 11 additions & 0 deletions source/6LoWPAN/ws/ws_llc_data_service.c
Expand Up @@ -41,6 +41,7 @@
#include "Security/eapol/eapol_helper.h"
#include "Service_Libs/etx/etx.h"
#include "fhss_ws_extension.h"
#include "Service_Libs/random_early_detection/random_early_detection_api.h"

#ifdef HAVE_WS

Expand Down Expand Up @@ -109,6 +110,7 @@ typedef struct {
ws_neighbor_temp_list_t active_eapol_temp_neigh;
ws_neighbor_temp_list_t free_temp_neigh;
llc_message_list_t llc_eap_pending_list; /**< Active Message list */
uint16_t llc_eap_pending_list_size; /**< EAPOL active Message list size */
bool active_eapol_session: 1; /**< Indicating active EAPOL message */
} temp_entriest_t;

Expand Down Expand Up @@ -245,6 +247,7 @@ static void llc_message_free(llc_message_t *message, llc_data_base_t *llc_base)
ns_list_remove(&llc_base->llc_message_list, message);
ns_dyn_mem_free(message);
llc_base->llc_message_list_size--;
random_early_detetction_aq_calc(llc_base->interface_ptr->llc_random_early_detection, llc_base->llc_message_list_size);
}

static void llc_message_id_allocate(llc_message_t *message, llc_data_base_t *llc_base, bool mpx_user)
Expand Down Expand Up @@ -534,6 +537,8 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
if (message) {
//Start A pending EAPOL
ns_list_remove(&base->temp_entries->llc_eap_pending_list, message);
base->temp_entries->llc_eap_pending_list_size--;
random_early_detetction_aq_calc(base->interface_ptr->llc_eapol_random_early_detection, base->temp_entries->llc_eap_pending_list_size);
ws_llc_mpx_eapol_send(base, message);
}
} else {
Expand Down Expand Up @@ -1020,6 +1025,7 @@ static void ws_llc_lowpan_mpx_data_request(llc_data_base_t *base, mpx_user_t *us
//Add To active list
llc_message_id_allocate(message, base, true);
base->llc_message_list_size++;
random_early_detetction_aq_calc(base->interface_ptr->llc_random_early_detection, base->llc_message_list_size);
ns_list_add_to_end(&base->llc_message_list, message);

mcps_data_req_t data_req;
Expand Down Expand Up @@ -1147,6 +1153,7 @@ static void ws_llc_mpx_eapol_send(llc_data_base_t *base, llc_message_t *message)
mcps_data_req_t data_req;
llc_message_id_allocate(message, base, true);
base->llc_message_list_size++;
random_early_detetction_aq_calc(base->interface_ptr->llc_random_early_detection, base->llc_message_list_size);
ns_list_add_to_end(&base->llc_message_list, message);
message->eapol_temporary = ws_llc_eapol_temp_entry_set(base, message->dst_address);
ws_llc_eapol_data_req_init(&data_req, message);
Expand Down Expand Up @@ -1240,6 +1247,8 @@ static void ws_llc_mpx_eapol_request(llc_data_base_t *base, mpx_user_t *user_cb,
if (base->temp_entries->active_eapol_session) {
//Move to pending list
ns_list_add_to_end(&base->temp_entries->llc_eap_pending_list, message);
base->temp_entries->llc_eap_pending_list_size++;
random_early_detetction_aq_calc(base->interface_ptr->llc_eapol_random_early_detection, base->temp_entries->llc_eap_pending_list_size);
} else {
ws_llc_mpx_eapol_send(base, message);
}
Expand Down Expand Up @@ -1351,6 +1360,7 @@ static void ws_llc_clean(llc_data_base_t *base)
ns_list_remove(&base->temp_entries->llc_eap_pending_list, message);
ns_dyn_mem_free(message);
}
base->temp_entries->llc_eap_pending_list_size = 0;
base->temp_entries->active_eapol_session = false;
memset(&base->ie_params, 0, sizeof(llc_ie_params_t));

Expand Down Expand Up @@ -1683,6 +1693,7 @@ int8_t ws_llc_asynch_request(struct protocol_interface_info_entry *interface, as
//Add To active list
llc_message_id_allocate(message, base, false);
base->llc_message_list_size++;
random_early_detetction_aq_calc(base->interface_ptr->llc_random_early_detection, base->llc_message_list_size);
ns_list_add_to_end(&base->llc_message_list, message);
message->messsage_type = request->message_type;

Expand Down
2 changes: 2 additions & 0 deletions source/NWK_INTERFACE/Include/protocol.h
Expand Up @@ -448,6 +448,8 @@ struct protocol_interface_info_entry {
br_info_t *border_router_setup;
struct load_balance_api *lb_api;
struct red_info_s *random_early_detection;
struct red_info_s *llc_random_early_detection;
struct red_info_s *llc_eapol_random_early_detection;
neigh_cache_s neigh_cache;
pan_blaclist_cache_s pan_blaclist_cache;
pan_coordinator_blaclist_cache_s pan_cordinator_black_list;
Expand Down
Expand Up @@ -36,6 +36,7 @@ TEST_SRC_FILES = \
../../stub/iphc_decompress_stub.c \
../../stub/fhss_config_stub.c \
../../stub/eapol_helper_stub.c \
../../random_early_detection_stub.c \


include ../../MakefileWorker.mk
Expand Down
Expand Up @@ -35,6 +35,8 @@
#include "6LoWPAN/ws/ws_neighbor_class.h"
#include "6LoWPAN/ws/ws_common.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "Service_Libs/random_early_detection/random_early_detection_api.h"
#include "Service_Libs/random_early_detection/random_early_detection.h"
#include "nsdynmemLIB_stub.h"
#include "mac_ie_lib_stub.h"
#include "ws_mpx_header_stub.h"
Expand All @@ -43,6 +45,7 @@
#include "ws_neighbour_class_stub.h"
#include "ws_ie_lib_stub.h"
#include "address_stub.h"
#include "random_early_detection_stub.h"
#include "fhss_ws_extension.h"

static mcps_data_indication_ext *data_indication_cb;
Expand Down

0 comments on commit fa20fb9

Please sign in to comment.