Extend repeater flood control and logging reliability
This commit is contained in:
1 parent
683fa64c8b
commit
a05acd72be
12 files changed
+2132
-192
No files matched your search
@@ -34,6 +34,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_mqtt_prefs_codec` | `src/helpers/MQTTPrefsStorage.h`, `src/helpers/MQTTPrefsCodec.h` | binary pre-slot/3-slot/6-slot migration fixtures; v1 header integrity; downgrade preservation |
|
||||
| `test_mqtt_prefs_atomic_store` | `src/helpers/MQTTPrefsAtomicStore.h` | transactional MQTT writes and legacy `/node_prefs` handoff; exact short-write detection; begin/finish/rename failure cleanup; original-file preservation |
|
||||
| `test_mqtt_payload_builder` | `src/helpers/MQTTPayloadBuilder.cpp` | status/packet/raw JSON contracts; optional fields; escaping; RX metrics and path; score handling; exact buffer bounds; maximum representative payloads |
|
||||
| `test_flood_filter_policy` | `src/helpers/FloodFilterPolicy.h` | unordered 3-byte and 2-byte-prefix blacklist matching; match thresholds; repeated path-entry semantics; `require=region` and per-channel scope-gate truth tables; fast/slow scope timing; adding, replacing, and preserving packet scope |
|
||||
| `test_utils` | `src/Utils.cpp` | `Utils::toHex` (upstream) |
|
||||
|
||||
## Conventions (and how to add a suite)
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/FloodFilterPolicy.h>
|
||||
|
||||
static mesh::Packet makeFloodPacket(uint8_t hash_size,
|
||||
const uint8_t* path,
|
||||
uint8_t path_hops) {
|
||||
mesh::Packet packet;
|
||||
packet.header = ROUTE_TYPE_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT);
|
||||
packet.setPathHashSizeAndCount(hash_size, path_hops);
|
||||
memcpy(packet.path, path, hash_size * path_hops);
|
||||
packet.payload_len = 0;
|
||||
return packet;
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, ThreeBytePathMatchesOneExactIdInAnyPosition) {
|
||||
const uint8_t blacklist[][3] = {
|
||||
{0x10, 0x20, 0x30},
|
||||
{0xAA, 0xBB, 0xCC},
|
||||
{0x70, 0x80, 0x90},
|
||||
};
|
||||
const uint8_t path[] = {
|
||||
0x01, 0x02, 0x03,
|
||||
0x70, 0x80, 0x90,
|
||||
0x04, 0x05, 0x06,
|
||||
};
|
||||
mesh::Packet packet = makeFloodPacket(3, path, 3);
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 3));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, ThreeBytePathRequiresAnExactThirdByte) {
|
||||
const uint8_t blacklist[][3] = {{0xAA, 0xBB, 0xCC}};
|
||||
const uint8_t path[] = {0xAA, 0xBB, 0xCD};
|
||||
mesh::Packet packet = makeFloodPacket(3, path, 1);
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 1));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, TwoBytePathRequiresTwoMatchingEntries) {
|
||||
const uint8_t blacklist[][3] = {
|
||||
{0xAA, 0xBB, 0x01},
|
||||
{0x11, 0x22, 0x02},
|
||||
};
|
||||
const uint8_t one_match_path[] = {
|
||||
0xAA, 0xBB,
|
||||
0x33, 0x44,
|
||||
};
|
||||
const uint8_t two_match_path[] = {
|
||||
0x11, 0x22,
|
||||
0x33, 0x44,
|
||||
0xAA, 0xBB,
|
||||
};
|
||||
mesh::Packet one_match = makeFloodPacket(2, one_match_path, 2);
|
||||
mesh::Packet two_matches = makeFloodPacket(2, two_match_path, 3);
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&one_match, &blacklist[0][0], 2));
|
||||
EXPECT_TRUE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&two_matches, &blacklist[0][0], 2));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, OnePathEntryCountsOnceWhenIdsSharePrefix) {
|
||||
const uint8_t blacklist[][3] = {
|
||||
{0xAA, 0xBB, 0x01},
|
||||
{0xAA, 0xBB, 0x02},
|
||||
};
|
||||
const uint8_t path[] = {0xAA, 0xBB};
|
||||
mesh::Packet packet = makeFloodPacket(2, path, 1);
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 2));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, RepeatedTwoBytePathEntriesCountSeparately) {
|
||||
const uint8_t blacklist[][3] = {{0xAA, 0xBB, 0x01}};
|
||||
const uint8_t path[] = {
|
||||
0xAA, 0xBB,
|
||||
0xAA, 0xBB,
|
||||
};
|
||||
mesh::Packet packet = makeFloodPacket(2, path, 2);
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 1));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, OneBytePathsNeverMatch) {
|
||||
const uint8_t blacklist[][3] = {{0xAA, 0xBB, 0xCC}};
|
||||
const uint8_t path[] = {0xAA, 0xAA, 0xAA};
|
||||
mesh::Packet packet = makeFloodPacket(1, path, 3);
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 1));
|
||||
}
|
||||
|
||||
TEST(FloodFilterBlacklist, Esp32MaximumListIncludesTheLastEntry) {
|
||||
uint8_t blacklist[255][3];
|
||||
for (uint16_t i = 0; i < 255; i++) {
|
||||
blacklist[i][0] = (uint8_t)i;
|
||||
blacklist[i][1] = (uint8_t)(i ^ 0xA5);
|
||||
blacklist[i][2] = (uint8_t)(i ^ 0x5A);
|
||||
}
|
||||
const uint8_t path[] = {
|
||||
blacklist[254][0],
|
||||
blacklist[254][1],
|
||||
blacklist[254][2],
|
||||
};
|
||||
mesh::Packet packet = makeFloodPacket(3, path, 1);
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::pathMatchesBlacklist(
|
||||
&packet, &blacklist[0][0], 255));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, RegionRequirementHasTheExpectedTruthTable) {
|
||||
EXPECT_TRUE(FloodFilterPolicy::scopeRuleAllowed(false, false));
|
||||
EXPECT_TRUE(FloodFilterPolicy::scopeRuleAllowed(false, true));
|
||||
EXPECT_FALSE(FloodFilterPolicy::scopeRuleAllowed(true, false));
|
||||
EXPECT_TRUE(FloodFilterPolicy::scopeRuleAllowed(true, true));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, SlowTimingFlagRoundTripsWithoutChangingSelector) {
|
||||
const uint8_t selector = 16;
|
||||
const uint8_t stored =
|
||||
FloodFilterPolicy::encodeScopeSelector(selector, true);
|
||||
|
||||
EXPECT_EQ(selector, FloodFilterPolicy::scopeSelectorValue(stored));
|
||||
EXPECT_TRUE(FloodFilterPolicy::scopeUsesSlowTiming(stored));
|
||||
EXPECT_FALSE(FloodFilterPolicy::scopeUsesSlowTiming(
|
||||
FloodFilterPolicy::encodeScopeSelector(selector, false)));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, OnlyChangedFastRulesReceiveFastTrackTreatment) {
|
||||
EXPECT_TRUE(FloodFilterPolicy::fastTrackScopeChange(true, false));
|
||||
EXPECT_FALSE(FloodFilterPolicy::fastTrackScopeChange(true, true));
|
||||
EXPECT_FALSE(FloodFilterPolicy::fastTrackScopeChange(false, false));
|
||||
EXPECT_FALSE(FloodFilterPolicy::fastTrackScopeChange(false, true));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, SlowTimingUsesMaximumTxDelayFactor) {
|
||||
EXPECT_EQ(2, FloodFilterPolicy::SLOW_SCOPE_TX_DELAY_FACTOR);
|
||||
EXPECT_EQ(1000U, FloodFilterPolicy::slowScopeMaxDelay(100));
|
||||
EXPECT_EQ(FloodFilterPolicy::MAX_DISPATCH_DELAY,
|
||||
FloodFilterPolicy::slowScopeMaxDelay(0xFFFFFFFFU));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, SlowTimingDoublesRxDelayBaseWithMinimumOfTwo) {
|
||||
EXPECT_FLOAT_EQ(2.0f, FloodFilterPolicy::slowScopeRxDelayBase(0.0f));
|
||||
EXPECT_FLOAT_EQ(2.0f, FloodFilterPolicy::slowScopeRxDelayBase(0.5f));
|
||||
EXPECT_FLOAT_EQ(2.0f, FloodFilterPolicy::slowScopeRxDelayBase(1.0f));
|
||||
EXPECT_FLOAT_EQ(4.0f, FloodFilterPolicy::slowScopeRxDelayBase(2.0f));
|
||||
EXPECT_FLOAT_EQ(20.0f, FloodFilterPolicy::slowScopeRxDelayBase(10.0f));
|
||||
EXPECT_FLOAT_EQ(24.0f, FloodFilterPolicy::slowScopeRxDelayBase(12.0f));
|
||||
EXPECT_FLOAT_EQ(40.0f, FloodFilterPolicy::slowScopeRxDelayBase(20.0f));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, ChannelRequirementTableKeepsLegacyGlobalBehaviorWhenEmpty) {
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_USE_GLOBAL,
|
||||
FloodFilterPolicy::channelScopeGate(false, true, true, false, false));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, ChannelRequirementTableDoesNotChangeOtherPayloadTypes) {
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_USE_GLOBAL,
|
||||
FloodFilterPolicy::channelScopeGate(true, false, false, false, false));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, UnlistedGroupChannelsBypassOnlyTheScopeGate) {
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_BYPASS,
|
||||
FloodFilterPolicy::channelScopeGate(true, true, false, false, false));
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_BYPASS,
|
||||
FloodFilterPolicy::channelScopeGate(true, true, false, true, false));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, ListedChannelsRequireAnAllowedIncomingScope) {
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_REQUIRED_REJECTED,
|
||||
FloodFilterPolicy::channelScopeGate(true, true, true, false, true));
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_REQUIRED_REJECTED,
|
||||
FloodFilterPolicy::channelScopeGate(true, true, true, true, false));
|
||||
EXPECT_EQ(
|
||||
FloodFilterPolicy::CHANNEL_SCOPE_REQUIRED_ALLOWED,
|
||||
FloodFilterPolicy::channelScopeGate(true, true, true, true, true));
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, AddsScopeToUnscopedFloodWithoutChangingPayloadType) {
|
||||
mesh::Packet packet;
|
||||
packet.header = ROUTE_TYPE_FLOOD | (PAYLOAD_TYPE_GRP_TXT << PH_TYPE_SHIFT);
|
||||
packet.transport_codes[0] = 0;
|
||||
packet.transport_codes[1] = 0;
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::setTransportScope(&packet, 0x1234));
|
||||
EXPECT_EQ(ROUTE_TYPE_TRANSPORT_FLOOD, packet.getRouteType());
|
||||
EXPECT_EQ(PAYLOAD_TYPE_GRP_TXT, packet.getPayloadType());
|
||||
EXPECT_EQ(0x1234, packet.transport_codes[0]);
|
||||
EXPECT_EQ(0, packet.transport_codes[1]);
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, ReplacesExistingScopeAndClearsSecondaryCode) {
|
||||
mesh::Packet packet;
|
||||
packet.header =
|
||||
ROUTE_TYPE_TRANSPORT_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT);
|
||||
packet.transport_codes[0] = 0x1111;
|
||||
packet.transport_codes[1] = 0x2222;
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::setTransportScope(&packet, 0x3333));
|
||||
EXPECT_EQ(0x3333, packet.transport_codes[0]);
|
||||
EXPECT_EQ(0, packet.transport_codes[1]);
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, ExistingExactScopeIsANoOp) {
|
||||
mesh::Packet packet;
|
||||
packet.header =
|
||||
ROUTE_TYPE_TRANSPORT_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT);
|
||||
packet.transport_codes[0] = 0x3333;
|
||||
packet.transport_codes[1] = 0;
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::setTransportScope(&packet, 0x3333));
|
||||
EXPECT_EQ(0x3333, packet.transport_codes[0]);
|
||||
EXPECT_EQ(0, packet.transport_codes[1]);
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, MatchingPrimaryStillChangesWhenSecondaryIsPresent) {
|
||||
mesh::Packet packet;
|
||||
packet.header =
|
||||
ROUTE_TYPE_TRANSPORT_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT);
|
||||
packet.transport_codes[0] = 0x3333;
|
||||
packet.transport_codes[1] = 0x4444;
|
||||
|
||||
EXPECT_TRUE(FloodFilterPolicy::setTransportScope(&packet, 0x3333));
|
||||
EXPECT_EQ(0x3333, packet.transport_codes[0]);
|
||||
EXPECT_EQ(0, packet.transport_codes[1]);
|
||||
}
|
||||
|
||||
TEST(FloodFilterScope, DirectPacketsAreNeverConvertedToFlood) {
|
||||
mesh::Packet packet;
|
||||
packet.header =
|
||||
ROUTE_TYPE_DIRECT | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT);
|
||||
packet.transport_codes[0] = 0x1111;
|
||||
packet.transport_codes[1] = 0x2222;
|
||||
|
||||
EXPECT_FALSE(FloodFilterPolicy::setTransportScope(&packet, 0x3333));
|
||||
EXPECT_EQ(ROUTE_TYPE_DIRECT, packet.getRouteType());
|
||||
EXPECT_EQ(0x1111, packet.transport_codes[0]);
|
||||
EXPECT_EQ(0x2222, packet.transport_codes[1]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -9,15 +9,25 @@ public:
|
||||
|
||||
class TestRadio : public mesh::Radio {
|
||||
public:
|
||||
uint8_t pending_rx[MAX_TRANS_UNIT];
|
||||
int pending_rx_len = 0;
|
||||
int send_starts = 0;
|
||||
bool receiving = false;
|
||||
bool in_recv_mode = true;
|
||||
int soft_recoveries = 0;
|
||||
int hard_recoveries = 0;
|
||||
int cad_set_calls = 0;
|
||||
bool cad_enabled = false;
|
||||
unsigned long last_irq = 0;
|
||||
bool recovery_result = true;
|
||||
|
||||
int recvRaw(uint8_t*, int) override { return 0; }
|
||||
int recvRaw(uint8_t* dest, int max_len) override {
|
||||
if (pending_rx_len == 0) return 0;
|
||||
int len = pending_rx_len < max_len ? pending_rx_len : max_len;
|
||||
memcpy(dest, pending_rx, len);
|
||||
pending_rx_len = 0;
|
||||
return len;
|
||||
}
|
||||
uint32_t getEstAirtimeFor(int) override { return 1; }
|
||||
float packetScore(float, int) override { return 0; }
|
||||
bool startSendRaw(const uint8_t*, int) override { send_starts++; return true; }
|
||||
@@ -25,6 +35,10 @@ public:
|
||||
void onSendFinished() override { }
|
||||
bool isInRecvMode() const override { return in_recv_mode; }
|
||||
bool isReceiving() override { return receiving; }
|
||||
void setCADEnabled(bool enable) override {
|
||||
cad_set_calls++;
|
||||
cad_enabled = enable;
|
||||
}
|
||||
unsigned long getLastRadioInterruptMillis() const override { return last_irq; }
|
||||
bool recoverRadio(bool hard) override {
|
||||
if (hard) {
|
||||
@@ -34,13 +48,35 @@ public:
|
||||
}
|
||||
return recovery_result;
|
||||
}
|
||||
|
||||
void queueRx(const uint8_t* raw, int len) {
|
||||
ASSERT_NE(raw, nullptr);
|
||||
ASSERT_GT(len, 0);
|
||||
ASSERT_LE(len, MAX_TRANS_UNIT);
|
||||
memcpy(pending_rx, raw, len);
|
||||
pending_rx_len = len;
|
||||
}
|
||||
};
|
||||
|
||||
class TestDispatcher : public mesh::Dispatcher {
|
||||
RxReservePacketManager& manager;
|
||||
|
||||
protected:
|
||||
mesh::DispatcherAction onRecvPacket(mesh::Packet*) override { return ACTION_RELEASE; }
|
||||
mesh::DispatcherAction onRecvPacket(mesh::Packet*) override {
|
||||
received_packets++;
|
||||
return ACTION_RELEASE;
|
||||
}
|
||||
int calcRxDelay(float score, uint32_t air_time) const override {
|
||||
return forced_rx_delay >= 0
|
||||
? forced_rx_delay
|
||||
: mesh::Dispatcher::calcRxDelay(score, air_time);
|
||||
}
|
||||
bool shouldBypassRxDelay(const mesh::Packet*) override {
|
||||
return bypass_rx_delay;
|
||||
}
|
||||
bool getCADEnabled() const override {
|
||||
return configured_cad_enabled;
|
||||
}
|
||||
void onSendFail(mesh::Packet* packet) override {
|
||||
failed_packet = packet;
|
||||
free_count_during_failure = manager.getFreeCount();
|
||||
@@ -49,6 +85,10 @@ protected:
|
||||
public:
|
||||
mesh::Packet* failed_packet = nullptr;
|
||||
int free_count_during_failure = -1;
|
||||
int received_packets = 0;
|
||||
int forced_rx_delay = -1;
|
||||
bool bypass_rx_delay = false;
|
||||
bool configured_cad_enabled = false;
|
||||
|
||||
TestDispatcher(TestRadio& radio, TestClock& clock, RxReservePacketManager& mgr)
|
||||
: mesh::Dispatcher(radio, clock, mgr), manager(mgr) { }
|
||||
@@ -124,6 +164,71 @@ TEST(Dispatcher, ParserAcceptsACompletePacketWithEmptyPayload) {
|
||||
EXPECT_EQ(0U, packet.payload_len);
|
||||
}
|
||||
|
||||
TEST(Dispatcher, FloodPacketWaitsForConfiguredRxDelayWithoutBypass) {
|
||||
RxReservePacketManager manager(4, 1);
|
||||
TestClock clock;
|
||||
TestRadio radio;
|
||||
TestDispatcher dispatcher(radio, clock, manager);
|
||||
dispatcher.forced_rx_delay = 1000;
|
||||
dispatcher.begin();
|
||||
const uint8_t raw[] = {
|
||||
ROUTE_TYPE_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT), 0, 0x42
|
||||
};
|
||||
|
||||
clock.now = 100;
|
||||
radio.queueRx(raw, sizeof(raw));
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(0, dispatcher.received_packets);
|
||||
|
||||
clock.now = 1099;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(0, dispatcher.received_packets);
|
||||
|
||||
clock.now = 1100;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(1, dispatcher.received_packets);
|
||||
}
|
||||
|
||||
TEST(Dispatcher, ScopeRewriteHookBypassesConfiguredRxDelay) {
|
||||
RxReservePacketManager manager(4, 1);
|
||||
TestClock clock;
|
||||
TestRadio radio;
|
||||
TestDispatcher dispatcher(radio, clock, manager);
|
||||
dispatcher.forced_rx_delay = 1000;
|
||||
dispatcher.bypass_rx_delay = true;
|
||||
dispatcher.begin();
|
||||
const uint8_t raw[] = {
|
||||
ROUTE_TYPE_FLOOD | (PAYLOAD_TYPE_GRP_DATA << PH_TYPE_SHIFT), 0, 0x42
|
||||
};
|
||||
|
||||
clock.now = 100;
|
||||
radio.queueRx(raw, sizeof(raw));
|
||||
dispatcher.loop();
|
||||
|
||||
EXPECT_EQ(1, dispatcher.received_packets);
|
||||
EXPECT_EQ(4, manager.getFreeCount());
|
||||
}
|
||||
|
||||
TEST(Dispatcher, ConfiguredCadStateIsPropagatedToTheRadio) {
|
||||
RxReservePacketManager manager(4, 1);
|
||||
TestClock clock;
|
||||
TestRadio radio;
|
||||
TestDispatcher dispatcher(radio, clock, manager);
|
||||
dispatcher.configured_cad_enabled = true;
|
||||
dispatcher.begin();
|
||||
|
||||
clock.now = 1;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(1, radio.cad_set_calls);
|
||||
EXPECT_TRUE(radio.cad_enabled);
|
||||
|
||||
dispatcher.configured_cad_enabled = false;
|
||||
clock.now = 2002;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(2, radio.cad_set_calls);
|
||||
EXPECT_FALSE(radio.cad_enabled);
|
||||
}
|
||||
|
||||
TEST(StaticPoolPacketManager, ReportsEarliestQueueTimesWithoutDequeuing) {
|
||||
StaticPoolPacketManager manager(8);
|
||||
mesh::Packet* later = manager.allocNew();
|
||||
@@ -366,7 +471,7 @@ TEST(StaticPoolPacketManager, RxDelayEqualPathsPreferNarrowerLocalScope) {
|
||||
manager.free(manager.getNextInbound(200));
|
||||
}
|
||||
|
||||
TEST(Dispatcher, QueueWakeDelayIncludesSchedulesAndChannelBackoff) {
|
||||
TEST(Dispatcher, QueueWakeDelayIncludesSchedulesAndAdaptiveChannelBackoff) {
|
||||
RxReservePacketManager manager(8, 4);
|
||||
TestClock clock;
|
||||
clock.now = 100;
|
||||
@@ -393,11 +498,62 @@ TEST(Dispatcher, QueueWakeDelayIncludesSchedulesAndChannelBackoff) {
|
||||
EXPECT_EQ(200U, delay_millis);
|
||||
EXPECT_FALSE(dispatcher.queuedWorkDue());
|
||||
|
||||
clock.now = 800;
|
||||
mesh::Packet* second = dispatcher.obtainNewPacket();
|
||||
ASSERT_NE(second, nullptr);
|
||||
second->header = ROUTE_TYPE_DIRECT | (PAYLOAD_TYPE_RAW_CUSTOM << PH_TYPE_SHIFT);
|
||||
second->payload[0] = 0x43;
|
||||
second->payload_len = 1;
|
||||
ASSERT_TRUE(dispatcher.sendPacket(second, 0));
|
||||
|
||||
clock.now = 801;
|
||||
dispatcher.loop();
|
||||
ASSERT_TRUE(dispatcher.nextQueueWakeDelay(delay_millis));
|
||||
EXPECT_EQ(100U, delay_millis);
|
||||
EXPECT_FALSE(dispatcher.queuedWorkDue());
|
||||
|
||||
clock.now = 901;
|
||||
radio.receiving = false;
|
||||
EXPECT_TRUE(dispatcher.queuedWorkDue());
|
||||
}
|
||||
|
||||
TEST(Dispatcher, GrowingQueueShortensCADBusyCeiling) {
|
||||
RxReservePacketManager manager(8, 1);
|
||||
TestClock clock;
|
||||
clock.now = 100;
|
||||
TestRadio radio;
|
||||
radio.receiving = true;
|
||||
TestDispatcher dispatcher(radio, clock, manager);
|
||||
dispatcher.begin();
|
||||
|
||||
mesh::Packet* first = dispatcher.obtainNewPacket();
|
||||
ASSERT_NE(first, nullptr);
|
||||
first->header = ROUTE_TYPE_DIRECT | (PAYLOAD_TYPE_RAW_CUSTOM << PH_TYPE_SHIFT);
|
||||
first->payload[0] = 0x40;
|
||||
first->payload_len = 1;
|
||||
ASSERT_TRUE(dispatcher.sendPacket(first, 0));
|
||||
clock.now = 101;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(0, radio.send_starts);
|
||||
|
||||
for (uint8_t i = 1; i < 4; i++) {
|
||||
mesh::Packet* packet = dispatcher.obtainNewPacket();
|
||||
ASSERT_NE(packet, nullptr);
|
||||
packet->header = ROUTE_TYPE_DIRECT | (PAYLOAD_TYPE_RAW_CUSTOM << PH_TYPE_SHIFT);
|
||||
packet->payload[0] = (uint8_t)(0x40 + i);
|
||||
packet->payload_len = 1;
|
||||
ASSERT_TRUE(dispatcher.sendPacket(packet, 0));
|
||||
}
|
||||
EXPECT_EQ(4, manager.getOutboundCount(clock.now));
|
||||
|
||||
// Four ready packets reduce the normal four-second CAD ceiling to one
|
||||
// second, measured from the original busy observation.
|
||||
clock.now = 1102;
|
||||
dispatcher.loop();
|
||||
EXPECT_EQ(1, radio.send_starts);
|
||||
EXPECT_EQ(3, manager.getOutboundCount(clock.now));
|
||||
EXPECT_TRUE(dispatcher.getErrFlags() & ERR_EVENT_CAD_TIMEOUT);
|
||||
}
|
||||
|
||||
TEST(Dispatcher, SilentRadioEscalatesFromSoftToHardRecovery) {
|
||||
RxReservePacketManager manager(8, 4);
|
||||
TestClock clock;
|
||||
|
||||
Reference in new issue
Block a user