Skip to content

Commit

Permalink
Iotthd 4584 (ARMmbed#2599)
Browse files Browse the repository at this point in the history
* MAC: priority and extra CCA backoffs for expedited forwarding

* Unit tests for blacklisting updated
  • Loading branch information
Jarkko Paso authored Mar 24, 2021
1 parent 60726dc commit ed5209e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_data_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef struct mac_pre_build_frame {
uint8_t stored_cca_cnt;
uint8_t cca_request_restart_cnt;
uint8_t tx_request_restart_cnt;
uint8_t priority;
uint32_t blacklist_start_time_us;
uint16_t blacklist_period_ms;
uint16_t initial_tx_channel;
Expand All @@ -107,7 +108,6 @@ typedef struct mac_pre_build_frame {
bool ExtendedFrameExchange: 1;
bool WaitResponse: 1;
unsigned security_mic_len: 5; //Max possible lengths 0, 4, 8, 16 bytes
unsigned priority: 2;
unsigned stored_priority: 2;
struct mac_pre_build_frame *next; //Pointer for queue purpose
} mac_pre_build_frame_t;
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ typedef struct dev_driver_tx_buffer {
#define MAC_CCA_MAX 8
#define MAC_DEF_MIN_BE 3
#define MAC_DEF_MAX_BE 5
#define MAC_PRIORITY_EF_BACKOFF_MULTIPLIER 2

typedef struct mac_active_scan {
uint8_t pan_id[2];
Expand Down
10 changes: 9 additions & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
buffer->mac_payload = data_req->msdu;
buffer->mac_payload_length = data_req->msduLength;
buffer->cca_request_restart_cnt = rf_mac_setup->cca_failure_restart_max;
// Multiply number of backoffs for higher priority packets
if (buffer->priority == MAC_PD_DATA_EF_PRIORITY) {
buffer->cca_request_restart_cnt *= MAC_PRIORITY_EF_BACKOFF_MULTIPLIER;
}
buffer->tx_request_restart_cnt = rf_mac_setup->tx_failure_restart_max;
//check that header + payload length is not bigger than MAC MTU

Expand Down Expand Up @@ -1548,7 +1552,11 @@ static bool mcps_update_packet_request_restart(protocol_interface_rf_mac_setup_s
}
if (rf_ptr->mac_tx_result == MAC_CCA_FAIL && buffer->cca_request_restart_cnt) {
buffer->cca_request_restart_cnt--;
mcps_set_packet_blacklist(rf_ptr, buffer, rf_ptr->cca_failure_restart_max - buffer->cca_request_restart_cnt);
if (buffer->priority == MAC_PD_DATA_EF_PRIORITY) {
mcps_set_packet_blacklist(rf_ptr, buffer, (rf_ptr->cca_failure_restart_max * MAC_PRIORITY_EF_BACKOFF_MULTIPLIER) - buffer->cca_request_restart_cnt);
} else {
mcps_set_packet_blacklist(rf_ptr, buffer, rf_ptr->cca_failure_restart_max - buffer->cca_request_restart_cnt);
}
return true;
} else if (rf_ptr->mac_tx_result == MAC_TX_FAIL && buffer->tx_request_restart_cnt) {
buffer->tx_request_restart_cnt--;
Expand Down
3 changes: 2 additions & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ typedef enum {
#define MAC_PD_DATA_NORMAL_PRIORITY 0 //Normal MCPS DATA REQ
#define MAC_PD_DATA_MEDIUM_PRIORITY 1 //Indirect Data which is polled
#define MAC_PD_DATA_HIGH_PRIOTITY 2 //Beacon request Beacon response
#define MAC_PD_DATA_TX_IMMEDIATELY 3 //Only for packets whose transmission was interrupted by wrong channel type. E.g. unicast on broadcast channel.
#define MAC_PD_DATA_EF_PRIORITY 3 //Expedited forwarding
#define MAC_PD_DATA_TX_IMMEDIATELY 4 //Only for packets whose transmission was interrupted by wrong channel type. E.g. unicast on broadcast channel.

#define MCPS_SAP_DATA_IND_EVENT 1
#define MCPS_SAP_DATA_CNF_EVENT 2
Expand Down
76 changes: 73 additions & 3 deletions test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,79 @@ bool test_mac_mcps_data_confirmation()
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}



// Test full 4 restarts and give up
nsdynmemlib_stub.returnCounter = 3;
data_req.TxAckReq = true;
fhss_tx_condition = true;
rf_mac_setup->tx_failure_restart_max = 4;
rf_mac_setup->dev_driver->phy_driver->extension = test_rf_extension;
rf_mac_setup->blacklist_min_ms = 20;
rf_mac_setup->blacklist_max_ms = 200;
mcps_sap_data_req_handler(rf_mac_setup, &data_req);
for (int i = 0; i < 4; i++) {
rf_mac_setup->mac_tx_result = MAC_TX_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (!rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}
}
rf_mac_setup->mac_tx_result = MAC_TX_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}
// Test full CCA backoffs and give up
nsdynmemlib_stub.returnCounter = 3;
data_req.TxAckReq = true;
fhss_tx_condition = true;
rf_mac_setup->tx_failure_restart_max = 4;
rf_mac_setup->cca_failure_restart_max = 9;
rf_mac_setup->dev_driver->phy_driver->extension = test_rf_extension;
rf_mac_setup->blacklist_min_ms = 20;
rf_mac_setup->blacklist_max_ms = 200;
mcps_sap_data_req_handler(rf_mac_setup, &data_req);
for (int i = 0; i < 9; i++) {
rf_mac_setup->mac_tx_result = MAC_CCA_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (!rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}
}
rf_mac_setup->mac_tx_result = MAC_CCA_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}
// Test full CCA backoffs for EF priority and give up
nsdynmemlib_stub.returnCounter = 3;
data_req.TxAckReq = true;
fhss_tx_condition = true;
rf_mac_setup->tx_failure_restart_max = 4;
rf_mac_setup->cca_failure_restart_max = 9;
rf_mac_setup->dev_driver->phy_driver->extension = test_rf_extension;
rf_mac_setup->blacklist_min_ms = 20;
rf_mac_setup->blacklist_max_ms = 200;
mcps_sap_data_req_handler(rf_mac_setup, &data_req);
rf_mac_setup->active_pd_data_request->priority = MAC_PD_DATA_EF_PRIORITY;
rf_mac_setup->active_pd_data_request->cca_request_restart_cnt *= MAC_PRIORITY_EF_BACKOFF_MULTIPLIER;
for (int i = 0; i < 9 * MAC_PRIORITY_EF_BACKOFF_MULTIPLIER; i++) {
rf_mac_setup->mac_tx_result = MAC_CCA_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (!rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}
}
rf_mac_setup->mac_tx_result = MAC_CCA_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
if (rf_mac_setup->active_pd_data_request) {
test_mac_rf_mac_class_free(rf_mac_setup);
return false;
}

test_mac_rf_mac_class_free(rf_mac_setup);
return true;
Expand Down

0 comments on commit ed5209e

Please sign in to comment.