From 988458385b9e497650e6d888830671aaec2101b4 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 9 Jan 2024 15:22:29 +0100 Subject: [PATCH] Bluetooth: Mesh: enable access responses randomization Enable by default the access layer responses random delays. Commit also adapts all mesh models, samples and babblesim tests to use random delay functionality correctly. Signed-off-by: Aleksandr Khromykh --- subsys/bluetooth/mesh/Kconfig | 15 +++++++++++++-- subsys/bluetooth/mesh/access.c | 10 ++++++++-- tests/bsim/bluetooth/mesh/src/test_access.c | 11 ++++++++--- tests/bsim/bluetooth/mesh/src/test_persistence.c | 6 ------ tests/bsim/bluetooth/mesh/src/test_provision.c | 10 ---------- .../access/access_transmit_delayable.sh | 2 +- .../priv_beacon/proxy_adv_multi_subnet_coex.sh | 2 +- 7 files changed, 31 insertions(+), 25 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 3ac9954d4deea74..8ce83648d7b95a9 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -639,6 +639,7 @@ config BT_MESH_LABEL_NO_RECOVER menuconfig BT_MESH_ACCESS_DELAYABLE_MSG bool "Access layer tx delayable message" + default y help Enable following of the message transmitting recommendations, the Access layer specification. The recommendations are optional. @@ -647,6 +648,16 @@ menuconfig BT_MESH_ACCESS_DELAYABLE_MSG if BT_MESH_ACCESS_DELAYABLE_MSG +config BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED + bool "Enable delayable message in the notification message context" + default y + help + Controls whether the delayable message feature is enabled by default in + the message context of the opcode notifications. This allows the server part of any + model to not bother about additional context configuration to enable the delayable message. + Note that if this is disabled then all foundation models stop using the delayable message + functionality. + config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT int "Number of simultaneously delayed messages" default 4 @@ -657,14 +668,14 @@ config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE int "Maximum delayable message storage chunk" - default 20 + default 10 help Size of memory that Access layer uses to split model message to. It allocates a sufficient number of these chunks from the pool to store the full model payload. config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT int "Maximum number of available chunks" - default 20 + default 40 help The maximum number of available chunks the Access layer allocates to store model payload. It is recommended to keep chunk size equal to the reasonable small value to prevent diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index c3ef6a405544d72..23fbb8e82c2a987 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -922,7 +922,7 @@ static void mod_publish(struct k_work *work) return; } - LOG_DBG("%u", k_uptime_get_32()); + LOG_DBG("timestamp: %u", k_uptime_get_32()); if (pub->count) { pub->count--; @@ -1504,6 +1504,10 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple return ACCESS_STATUS_MESSAGE_NOT_UNDERSTOOD; } + if (IS_ENABLED(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED)) { + ctx->rnd_delay = true; + } + net_buf_simple_save(buf, &state); err = op->func(model, ctx, buf); net_buf_simple_restore(buf, &state); @@ -1578,7 +1582,9 @@ int bt_mesh_model_send(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx } #if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG - if (ctx->rnd_delay) { + /* No sense to use delayable message for unicast loopback. */ + if (ctx->rnd_delay && + !(bt_mesh_has_addr(ctx->addr) && BT_MESH_ADDR_IS_UNICAST(ctx->addr))) { return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr, cb, cb_data); } diff --git a/tests/bsim/bluetooth/mesh/src/test_access.c b/tests/bsim/bluetooth/mesh/src/test_access.c index 5cb7d2e28e1b71f..6967aa6d71c1133 100644 --- a/tests/bsim/bluetooth/mesh/src/test_access.c +++ b/tests/bsim/bluetooth/mesh/src/test_access.c @@ -102,11 +102,15 @@ static bool publish_allow; static int model1_update(const struct bt_mesh_model *model) { - model->pub->msg->data[1]++; + if (!publish_allow) { + return -1; + } + model->pub->msg->data[1]++; LOG_DBG("New pub: n: %d t: %d", model->pub->msg->data[1], k_uptime_get_32()); + k_sem_give(&publish_sem); - return publish_allow ? k_sem_give(&publish_sem), 0 : -1; + return 0; } static int test_msgf_handler(const struct bt_mesh_model *model, @@ -604,7 +608,8 @@ static void recv_delayable_check(int32_t interval, uint8_t count) LOG_DBG("Recv time: %d delta: %d boundaries: %d/%d", (int32_t)timestamp, time_delta, lower_boundary, upper_boundary); - ASSERT_IN_RANGE(time_delta, lower_boundary, upper_boundary + RX_JITTER_MAX); + ASSERT_IN_RANGE(time_delta, lower_boundary - RX_JITTER_MAX, + upper_boundary + RX_JITTER_MAX); } } diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index ec7d838d26aa1f9..4bf1f9faa936b3c 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -455,12 +455,6 @@ static void provisioner_setup(void) FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status); } - err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_PROV_ADDR, - BT_MESH_TRANSMIT(3, 50), &status); - if (err || status != BT_MESH_TRANSMIT(3, 50)) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, status); - } - provisioner_ready = true; } diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 3f566947efac884..9a83f874e1132c9 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -1211,7 +1211,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) uint16_t pb_remote_server_addr; uint8_t status; struct bt_mesh_cdb_node *node; - int err; provisioner_pb_remote_client_setup(); @@ -1225,15 +1224,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) .ttl = 3, }; - /* Set Network Transmit Count state on the remote client greater than on the remote server - * to increase probability of reception responses. - */ - err = bt_mesh_cfg_cli_net_transmit_set(0, current_dev_addr, BT_MESH_TRANSMIT(3, 50), - &status); - if (err || status != BT_MESH_TRANSMIT(3, 50)) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, status); - } - ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); /* Check device key by adding appkey. */ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh index 1622ac49f063ae8..0e966288db0e15b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh @@ -14,4 +14,4 @@ RunTest mesh_access_pub_transmit_delayable_retr_1d1 \ conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_pub_transmit_delayable_retr_psa \ - access_tx_period_delayable access_rx_period_delayable + access_tx_transmit_delayable access_rx_transmit_delayable diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh index 845a8ff7da73ad8..42863a1345882eb 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh @@ -24,7 +24,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Note 3: The proxy transmitting device mandates emitting of the secure # network beacons. This allows to check that proxy goes back to normal -# behavior after device advertises the seure network beacons. +# behavior after the device advertises the secure network beacons. # Test procedure: # 1. (0-20 seconds) A single subnet is active on the TX device with GATT