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 <aleksandr.khromykh@nordicsemi.no>
This commit is contained in:
Aleksandr Khromykh 2024-01-09 15:22:29 +01:00 committed by Fabio Baltieri
commit 4e7d64b1b4
7 changed files with 31 additions and 25 deletions

View file

@ -639,6 +639,7 @@ config BT_MESH_LABEL_NO_RECOVER
menuconfig BT_MESH_ACCESS_DELAYABLE_MSG menuconfig BT_MESH_ACCESS_DELAYABLE_MSG
bool "Access layer tx delayable message" bool "Access layer tx delayable message"
default y
help help
Enable following of the message transmitting recommendations, the Access layer Enable following of the message transmitting recommendations, the Access layer
specification. The recommendations are optional. specification. The recommendations are optional.
@ -647,6 +648,16 @@ menuconfig BT_MESH_ACCESS_DELAYABLE_MSG
if BT_MESH_ACCESS_DELAYABLE_MSG if BT_MESH_ACCESS_DELAYABLE_MSG
config BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED
bool "The 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 config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT
int "Number of simultaneously delayed messages" int "Number of simultaneously delayed messages"
default 4 default 4
@ -657,14 +668,14 @@ config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT
config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE
int "Maximum delayable message storage chunk" int "Maximum delayable message storage chunk"
default 20 default 10
help help
Size of memory that Access layer uses to split model message to. It allocates 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. a sufficient number of these chunks from the pool to store the full model payload.
config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT
int "Maximum number of available chunks" int "Maximum number of available chunks"
default 20 default 40
help help
The maximum number of available chunks the Access layer allocates to store model payload. 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 It is recommended to keep chunk size equal to the reasonable small value to prevent

View file

@ -922,7 +922,7 @@ static void mod_publish(struct k_work *work)
return; return;
} }
LOG_DBG("%u", k_uptime_get_32()); LOG_DBG("timestamp: %u", k_uptime_get_32());
if (pub->count) { if (pub->count) {
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; 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); net_buf_simple_save(buf, &state);
err = op->func(model, ctx, buf); err = op->func(model, ctx, buf);
net_buf_simple_restore(buf, &state); 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 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, return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr,
cb, cb_data); cb, cb_data);
} }

View file

@ -102,11 +102,15 @@ static bool publish_allow;
static int model1_update(const struct bt_mesh_model *model) static int model1_update(const struct bt_mesh_model *model)
{ {
if (!publish_allow) {
return -1;
}
model->pub->msg->data[1]++; model->pub->msg->data[1]++;
LOG_DBG("New pub: n: %d t: %d", model->pub->msg->data[1], k_uptime_get_32()); 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, 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, LOG_DBG("Recv time: %d delta: %d boundaries: %d/%d", (int32_t)timestamp, time_delta,
lower_boundary, upper_boundary); 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);
} }
} }

View file

@ -455,12 +455,6 @@ static void provisioner_setup(void)
FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status); 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; provisioner_ready = true;
} }

View file

@ -1211,7 +1211,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void)
uint16_t pb_remote_server_addr; uint16_t pb_remote_server_addr;
uint8_t status; uint8_t status;
struct bt_mesh_cdb_node *node; struct bt_mesh_cdb_node *node;
int err;
provisioner_pb_remote_client_setup(); provisioner_pb_remote_client_setup();
@ -1225,15 +1224,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void)
.ttl = 3, .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)); ASSERT_OK(provision_remote(&srv, 2, &srv.addr));
/* Check device key by adding appkey. */ /* Check device key by adding appkey. */

View file

@ -14,4 +14,4 @@ RunTest mesh_access_pub_transmit_delayable_retr_1d1 \
conf=prj_mesh1d1_conf conf=prj_mesh1d1_conf
overlay=overlay_psa_conf overlay=overlay_psa_conf
RunTest mesh_access_pub_transmit_delayable_retr_psa \ RunTest mesh_access_pub_transmit_delayable_retr_psa \
access_tx_period_delayable access_rx_period_delayable access_tx_transmit_delayable access_rx_transmit_delayable

View file

@ -24,7 +24,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh
# Note 3: The proxy transmitting device mandates emitting of the secure # Note 3: The proxy transmitting device mandates emitting of the secure
# network beacons. This allows to check that proxy goes back to normal # 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: # Test procedure:
# 1. (0-20 seconds) A single subnet is active on the TX device with GATT # 1. (0-20 seconds) A single subnet is active on the TX device with GATT