Skip to content

Commit

Permalink
Bluetooth: Mesh: enable access responses randomization
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alxelax committed Jan 12, 2024
1 parent e5b3231 commit 9a3793c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
5 changes: 3 additions & 2 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -657,14 +658,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
Expand Down
7 changes: 5 additions & 2 deletions subsys/bluetooth/mesh/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down Expand Up @@ -1504,6 +1504,7 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple
return ACCESS_STATUS_MESSAGE_NOT_UNDERSTOOD;
}

ctx->rnd_delay = true;
net_buf_simple_save(buf, &state);
err = op->func(model, ctx, buf);
net_buf_simple_restore(buf, &state);
Expand Down Expand Up @@ -1578,7 +1579,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);
}
Expand Down
11 changes: 8 additions & 3 deletions tests/bsim/bluetooth/mesh/src/test_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 0 additions & 6 deletions tests/bsim/bluetooth/mesh/src/test_persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 0 additions & 10 deletions tests/bsim/bluetooth/mesh/src/test_provision.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a3793c

Please sign in to comment.