simple_repeater: per-origin advert window + fairness dry-run (tth #2, #1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-02 09:40:20 +01:00
1 parent af1714db08
commit 910bee899a
7 files changed
+351 -11

No files matched your search

+53 -4
View File
@@ -737,6 +737,9 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
// `fairness grid` -- busiest deny buckets per category (what we shed).
// `fairness cap <group> <sender> <advert>` -- burst caps, 0 = default.
// `fairness refill <group_s> <sender_s> <advert_s>` -- refill interval secs, 0 = default.
// `fairness advert [<hours>|clear]` -- per-origin advert window (0 = off).
// `fairness dryrun [on|off]` -- count verdicts, forward anyway.
// `fairness air` -- estimated airtime shed per reason.
// All tuning is persisted, so a mast reboot keeps it.
bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_max) {
if (memcmp(command, "fairness", 8) != 0 || (command[8] != 0 && command[8] != ' ')) return false;
@@ -745,11 +748,54 @@ bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_m
if (strcmp(arg, "on") == 0 || strcmp(arg, "off") == 0) {
_prefs.fairness_enabled = (arg[1] == 'n') ? 1 : 0;
fairness_limiter.setBucketsEnabled(_prefs.fairness_enabled);
savePrefs();
snprintf(reply, reply_max, "OK - fairness %s", _prefs.fairness_enabled ? "on" : "off");
return true;
}
if (strcmp(arg, "dryrun") == 0 || strcmp(arg, "dryrun on") == 0 || strcmp(arg, "dryrun off") == 0) {
if (arg[6] == ' ') {
_prefs.fair_dry_run = (arg[8] == 'n') ? 1 : 0;
fairness_limiter.setDryRun(_prefs.fair_dry_run);
savePrefs();
}
snprintf(reply, reply_max, "%sfairness dry-run %s", arg[6] == ' ' ? "OK - " : "",
fairness_limiter.dryRun() ? "on" : "off");
return true;
}
if (strcmp(arg, "advert") == 0 || strncmp(arg, "advert ", 7) == 0) {
AdvertWindow& w = fairness_limiter.advertWindow();
if (strcmp(arg, "advert clear") == 0) {
w.clear();
} else if (arg[6] == ' ') {
char* end = NULL;
long h = strtol(arg + 7, &end, 10);
if (end == arg + 7 || *end != 0 || h < 0 || h > ADVERT_WINDOW_MAX_HOURS) {
snprintf(reply, reply_max, "Err - fairness advert <0-%d hours>|clear", ADVERT_WINDOW_MAX_HOURS);
return true;
}
_prefs.fair_advert_hours = (uint16_t)h;
w.setHours(_prefs.fair_advert_hours);
savePrefs();
}
snprintf(reply, reply_max, "advert window %uh%s, held %u (%us air), cache %d/%d, evicted %u",
(uint32_t)w.hours(), fairness_limiter.dryRun() ? " DRY-RUN" : "", fairness_limiter.deniedWindow(),
fairness_limiter.shedAirtimeMs(FAIR_SHED_WINDOW) / 1000, w.count(), w.capacity(), w.evicted());
return true;
}
if (strcmp(arg, "air") == 0) {
snprintf(reply, reply_max, "shed air%s: group %us sender %us advert %us window %us",
fairness_limiter.dryRun() ? " (dry-run, would be)" : "",
fairness_limiter.shedAirtimeMs(FAIR_SHED_GROUP) / 1000,
fairness_limiter.shedAirtimeMs(FAIR_SHED_SENDER) / 1000,
fairness_limiter.shedAirtimeMs(FAIR_SHED_ADVERT) / 1000,
fairness_limiter.shedAirtimeMs(FAIR_SHED_WINDOW) / 1000);
return true;
}
if (strcmp(arg, "grid") == 0) {
char grid[180];
fairness_limiter.formatGrid(grid, sizeof(grid));
@@ -799,16 +845,16 @@ bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_m
}
if (arg[0] != 0) {
strcpy(reply, "Err - fairness [on|off|grid|cap ...|refill ...]");
strcpy(reply, "Err - fairness [on|off|grid|cap|refill|advert|dryrun|air]");
return true;
}
// bare `fairness` -- stats + current caps/refills
snprintf(reply, reply_max,
"fairness: %s, denied group %u/sender %u/advert %u; cap %u/%u/%u; refill %u/%u/%us",
_prefs.fairness_enabled ? "on" : "OFF",
"fairness: %s%s, denied group %u/sender %u/advert %u/window %u; cap %u/%u/%u; refill %u/%u/%us",
_prefs.fairness_enabled ? "on" : "OFF", fairness_limiter.dryRun() ? " DRY-RUN" : "",
fairness_limiter.deniedGroup(), fairness_limiter.deniedSenderNormal(),
fairness_limiter.deniedSenderLow(),
fairness_limiter.deniedSenderLow(), fairness_limiter.deniedWindow(),
(uint32_t)fairness_limiter.groupCap(), (uint32_t)fairness_limiter.senderNormalCap(),
(uint32_t)fairness_limiter.senderLowCap(),
(uint32_t)(fairGroupRefillMs() / 1000), (uint32_t)(fairSenderRefillMs() / 1000),
@@ -1404,6 +1450,9 @@ void MyMesh::begin(FILESYSTEM *fs) {
fairness_limiter.setGroupCap(_prefs.fair_group_cap);
fairness_limiter.setSenderNormalCap(_prefs.fair_sender_cap);
fairness_limiter.setSenderLowCap(_prefs.fair_advert_cap);
fairness_limiter.setBucketsEnabled(_prefs.fairness_enabled);
fairness_limiter.setDryRun(_prefs.fair_dry_run);
fairness_limiter.advertWindow().setHours(_prefs.fair_advert_hours);
// Fairness buckets start with just ONE token (not the full cap): a repeater
// stuck in a crash loop must not hand out a fresh burst on every boot.
+7 -2
View File
@@ -369,9 +369,14 @@ protected:
#endif
// CUSTOM (TeTeHacko): FairnessLimiter veto. mesh::Mesh consults this as the
// LAST condition of every forward decision, so a token is only taken for a
// packet that would otherwise transmit. Runtime kill switch in prefs.
// packet that would otherwise transmit. Buckets have a runtime kill switch
// (`fairness on|off`), the advert window its own (`fairness advert 0`).
// What gets shed is also summed as airtime -- in dry-run, what WOULD be.
bool takeForwardingRateLimit(const mesh::Packet* packet) override {
return !_prefs.fairness_enabled || fairness_limiter.allowPacket(packet);
bool ok = fairness_limiter.allowPacket(packet, _ms->getMillis());
FairShed why = fairness_limiter.lastShed();
if (why != FAIR_SHED_NONE) fairness_limiter.addShedAirtime(why, _radio->getEstAirtimeFor(packet->getRawLength()));
return ok;
}
const char* getLogDateTime() override;
void logRxRaw(float snr, float rssi, const uint8_t raw[], int len) override;
+84
View File
@@ -0,0 +1,84 @@
#pragma once
// CUSTOM (TeTeHacko): per-origin advert window, ported from DutchMeshCore's
// AdvertLimiter (Dutch-MeshCore/MeshCore d26421b0, examples/simple_repeater/
// AdvertLimiter.h; same MIT licence as this tree). Behaviour is theirs, names
// and the eviction counter are ours.
//
// Each origin's flood advert is forwarded at most once per window, so a node
// that re-advertises every minute (CP1 on the CZ mesh, since 30. 10. 2026:
// a flood advert every 60 s, seen by 40-90 observers each) stops being
// re-flooded by this repeater while it still stays reachable through it once
// per window. FairnessLimiter's advert bucket cannot do that:
// it is keyed on 7 bits of the key, so the chatty node and ~8 innocent ones
// share a bucket, and loosening it for them lets the chatty one through.
//
// Origins are keyed on the first 4 bytes of the advert's public key (payload
// starts with it). Fixed ring of ADVERT_WINDOW_SIZE entries: once full, the
// oldest entry is overwritten -- that origin gets a free pass next time. RAM
// only, so after a reboot every origin gets one free pass. Time is millis and
// compared with unsigned subtraction, so it survives the 49-day wrap.
// Header-only and dependency-free so it runs in the native tests.
#include <stdint.h>
#include <string.h>
#ifndef ADVERT_WINDOW_SIZE
#define ADVERT_WINDOW_SIZE 256 // 8 B each => 2 KB RAM
#endif
#define ADVERT_WINDOW_KEY_LEN 4
#define ADVERT_WINDOW_MAX_HOURS 720 // 30 days; keeps hours*3600*1000 inside uint32
class AdvertWindow {
struct Entry {
uint8_t key[ADVERT_WINDOW_KEY_LEN];
uint32_t seen_ms;
};
Entry _cache[ADVERT_WINDOW_SIZE];
uint16_t _count = 0; // entries in use
uint16_t _head = 0; // next entry to overwrite once the cache is full
uint16_t _hours = 0; // 0 = off
uint32_t _evicted = 0; // origins forgotten because the ring was full
public:
AdvertWindow() { memset(_cache, 0, sizeof(_cache)); }
void setHours(uint16_t hours) { _hours = hours > ADVERT_WINDOW_MAX_HOURS ? ADVERT_WINDOW_MAX_HOURS : hours; }
uint16_t hours() const { return _hours; }
int count() const { return _count; }
int capacity() const { return ADVERT_WINDOW_SIZE; }
// Non-zero = the ring is too small for the mesh: origins fall out before
// their window ends and get a pass they should not have had.
uint32_t evicted() const { return _evicted; }
void clear() { _count = 0; _head = 0; }
// True when the advert from `key` may be forwarded now (and records it),
// false when the same origin already passed inside the current window.
bool allow(const uint8_t* key, uint32_t now_ms) {
if (_hours == 0 || key == nullptr) return true;
uint32_t window_ms = (uint32_t)_hours * 3600UL * 1000UL;
for (int i = 0; i < _count; i++) {
Entry& e = _cache[i];
if (memcmp(e.key, key, ADVERT_WINDOW_KEY_LEN) != 0) continue;
if (now_ms - e.seen_ms < window_ms) return false; // unsigned: wrap-safe
e.seen_ms = now_ms; // window elapsed: pass, and start a new window
return true;
}
Entry* e;
if (_count < ADVERT_WINDOW_SIZE) {
e = &_cache[_count++];
} else {
e = &_cache[_head]; // overwrite the oldest entry
_head = (uint16_t)((_head + 1) % ADVERT_WINDOW_SIZE);
_evicted++;
}
memcpy(e->key, key, ADVERT_WINDOW_KEY_LEN);
e->seen_ms = now_ms;
return true;
}
};
+4
View File
@@ -89,6 +89,8 @@ public:
// FairnessLimiter runtime tuning; 0 = use the firmware build default.
uint8_t fair_group_cap = 0, fair_sender_cap = 0, fair_advert_cap = 0;
uint16_t fair_group_refill_s = 0, fair_sender_refill_s = 0, fair_advert_refill_s = 0;
uint16_t fair_advert_hours = 0; // per-origin advert window, hours; 0 = off
uint8_t fair_dry_run = 0; // count FairnessLimiter verdicts, forward anyway
private:
class RadioPrefs : public CommonRadioPrefs {
@@ -216,6 +218,8 @@ private:
def("fair_grf", _parent->fair_group_refill_s);
def("fair_srf", _parent->fair_sender_refill_s);
def("fair_arf", _parent->fair_advert_refill_s);
def("fair_advh", _parent->fair_advert_hours);
def("fair_dry", _parent->fair_dry_run);
}
public:
RepeatPrefs(NodePrefs* parent) : _parent(parent) { }
+20 -4
View File
@@ -94,7 +94,8 @@ void FairnessLimiter::refillSenderLow() {
}
}
bool FairnessLimiter::allowPacket(const mesh::Packet* pkt) {
bool FairnessLimiter::allowPacket(const mesh::Packet* pkt, uint32_t now_ms) {
last_shed = FAIR_SHED_NONE;
// Don't limit versions we don't understand.
if (pkt->getPayloadVer() != PAYLOAD_VER_1) {
return true;
@@ -110,11 +111,26 @@ bool FairnessLimiter::allowPacket(const mesh::Packet* pkt) {
uint8_t hash[1] = { 0x00 };
auto type = pkt->getPayloadType();
// Per-origin advert window -- flood adverts only, ahead of the buckets. The
// payload starts with the origin's public key.
if (type == PAYLOAD_TYPE_ADVERT && pkt->isRouteFlood() && pkt->payload_len >= ADVERT_WINDOW_KEY_LEN
&& !advert_window.allow(pkt->payload, now_ms)) {
denied_window++;
MESH_DEBUG_PRINTLN("FAIR, advert window origin=%02X%02X%02X%02X dry=%u", (uint32_t)pkt->payload[0],
(uint32_t)pkt->payload[1], (uint32_t)pkt->payload[2], (uint32_t)pkt->payload[3],
(uint32_t)dry_run);
return shed(FAIR_SHED_WINDOW);
}
if (!buckets_enabled) {
return true;
}
// Packets by group channel hash
if (type == PAYLOAD_TYPE_GRP_TXT || type == PAYLOAD_TYPE_GRP_DATA) {
if (pkt->payload_len < 1) return true; // malformed, not ours to judge
hash[0] = pkt->payload[0];
return takeGroup(hash);
return takeGroup(hash) || shed(FAIR_SHED_GROUP);
}
// Packets with a plaintext 1-byte src hash at payload[1] (see Mesh.cpp,
@@ -123,13 +139,13 @@ bool FairnessLimiter::allowPacket(const mesh::Packet* pkt) {
type == PAYLOAD_TYPE_TXT_MSG || type == PAYLOAD_TYPE_ANON_REQ) {
if (pkt->payload_len < 2) return true; // malformed, not ours to judge
hash[0] = pkt->payload[1];
return takeSenderNormal(hash);
return takeSenderNormal(hash) || shed(FAIR_SHED_SENDER);
}
if (type == PAYLOAD_TYPE_ADVERT) {
if (pkt->payload_len < 1) return true; // malformed, not ours to judge
hash[0] = pkt->payload[0]; // first byte of sender pub key
return takeSenderLow(hash);
return takeSenderLow(hash) || shed(FAIR_SHED_ADVERT);
}
// Not classified (allowed through):
+40 -1
View File
@@ -18,6 +18,7 @@
#include <Packet.h>
#include <stdint.h>
#include "AdvertWindow.h"
// Sender hashes 0x00 and 0xFF are NOT special here. Our firmware never creates
// such an identity (re-roll on create, validatePrivateKey() on import), but the
@@ -85,6 +86,10 @@
* Until a V2 protocol provides new means of limiting, the goal is a "better than
* nothing" reduction in wasteful repeats, freeing airtime for useful repeats.
*/
// Why a packet was shed (lastShed()). WINDOW = per-origin advert window.
enum FairShed : uint8_t { FAIR_SHED_NONE = 0, FAIR_SHED_GROUP, FAIR_SHED_SENDER, FAIR_SHED_ADVERT, FAIR_SHED_WINDOW,
FAIR_SHED_N };
class FairnessLimiter {
// Capacity of when a bucket is full. Runtime-settable (setGroupCap etc.) so
// limits can be loosened over RF admin without a reflash -- 0 to a setter
@@ -104,6 +109,22 @@ class FairnessLimiter {
uint16_t sender_normal_deny[SENDER_NORMAL_MAP_SIZE] = {};
uint16_t sender_low_deny[SENDER_LOW_MAP_SIZE] = {};
// Per-origin advert window (issue #2), runs ahead of the advert bucket so a
// repeat advert never takes a token a legitimate one would need.
AdvertWindow advert_window;
uint32_t denied_window = 0;
// Buckets on/off (`fairness on|off`); the window has its own switch (hours).
bool buckets_enabled = true;
// Dry-run (issue #1): every verdict is counted as if enforced, but the packet
// is forwarded anyway -- sizes a setting on a live mast before it bites.
bool dry_run = false;
FairShed last_shed = FAIR_SHED_NONE;
// Estimated airtime of what was shed (or would have been, in dry-run), ms,
// per FairShed reason. Fed by the caller, which owns the radio.
uint32_t shed_air_ms[FAIR_SHED_N] = {};
bool shed(FairShed why) { last_shed = why; return dry_run; }
public:
FairnessLimiter() {}
@@ -120,7 +141,25 @@ public:
* would otherwise be forwarded, and only once per packet.
* \returns true if the packet should be forwarded
*/
bool allowPacket(const mesh::Packet* pkt);
bool allowPacket(const mesh::Packet* pkt, uint32_t now_ms);
// Without a clock: the advert window sees every call at t=0. For tests and
// callers that never enable the window.
bool allowPacket(const mesh::Packet* pkt) { return allowPacket(pkt, 0); }
// What the LAST allowPacket() call shed (FAIR_SHED_NONE = passed on its
// merits). In dry-run it is set although allowPacket() returned true.
FairShed lastShed() const { return last_shed; }
void addShedAirtime(FairShed why, uint32_t ms) { if (why < FAIR_SHED_N) shed_air_ms[why] += ms; }
uint32_t shedAirtimeMs(FairShed why) const { return why < FAIR_SHED_N ? shed_air_ms[why] : 0; }
void setBucketsEnabled(bool on) { buckets_enabled = on; }
bool bucketsEnabled() const { return buckets_enabled; }
void setDryRun(bool on) { dry_run = on; }
bool dryRun() const { return dry_run; }
AdvertWindow& advertWindow() { return advert_window; }
const AdvertWindow& advertWindow() const { return advert_window; }
uint32_t deniedWindow() const { return denied_window; }
// Inspect stats
uint32_t deniedSenderNormal() const { return denied_sender_normal; }
@@ -196,6 +196,149 @@ TEST(FairnessLimiter, GridIsNonDestructive) {
EXPECT_STREQ(a, b); // repeated calls give the same picture
}
// ── per-origin advert window (issue #2) and dry-run (issue #1) ──────────────
static Packet makeAdvert(uint8_t k0, uint8_t k1 = 0xAA) {
return makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_ADVERT, {k0, k1, 0x01, 0x02, 0x03});
}
static const uint32_t HOUR = 3600UL * 1000UL;
TEST(AdvertWindow, OffByDefault) {
FairnessLimiter fl;
fl.setBucketsEnabled(false); // isolate the window from the buckets
Packet a = makeAdvert(0xDF);
for (int i = 0; i < 10; i++) EXPECT_TRUE(fl.allowPacket(&a, i * 60000));
EXPECT_EQ(fl.deniedWindow(), 0u);
}
TEST(AdvertWindow, OncePerWindowPerOrigin) {
FairnessLimiter fl;
fl.setBucketsEnabled(false);
fl.advertWindow().setHours(12);
Packet cp1 = makeAdvert(0xDF), other = makeAdvert(0x42);
EXPECT_TRUE(fl.allowPacket(&cp1, 0));
for (int m = 1; m < 12 * 60; m++) EXPECT_FALSE(fl.allowPacket(&cp1, m * 60000UL)); // every minute
EXPECT_EQ(fl.lastShed(), FAIR_SHED_WINDOW);
EXPECT_TRUE(fl.allowPacket(&other, 5 * HOUR)); // a different origin is unaffected
EXPECT_EQ(fl.lastShed(), FAIR_SHED_NONE);
EXPECT_TRUE(fl.allowPacket(&cp1, 12 * HOUR)); // window over: one more pass
EXPECT_FALSE(fl.allowPacket(&cp1, 12 * HOUR + 1));
EXPECT_EQ(fl.deniedWindow(), 12u * 60 - 1 + 1);
}
TEST(AdvertWindow, KeyIsFourBytesOfPubkey) {
FairnessLimiter fl;
fl.setBucketsEnabled(false);
fl.advertWindow().setHours(1);
Packet a = makeAdvert(0xDF, 0x33), b = makeAdvert(0xDF, 0x34); // same 1st byte only
EXPECT_TRUE(fl.allowPacket(&a, 0));
EXPECT_TRUE(fl.allowPacket(&b, 0));
}
TEST(AdvertWindow, DirectAndShortAdvertsUntouched) {
FairnessLimiter fl;
fl.setBucketsEnabled(false);
fl.advertWindow().setHours(24);
Packet d = makePacket(ROUTE_TYPE_DIRECT, PAYLOAD_TYPE_ADVERT, {0xDF, 0x33, 1, 2});
Packet s = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_ADVERT, {0xDF, 0x33});
for (int i = 0; i < 3; i++) {
EXPECT_TRUE(fl.allowPacket(&d, 0));
EXPECT_TRUE(fl.allowPacket(&s, 0));
}
EXPECT_EQ(fl.deniedWindow(), 0u);
}
TEST(AdvertWindow, SurvivesMillisWrap) {
FairnessLimiter fl;
fl.setBucketsEnabled(false);
fl.advertWindow().setHours(1);
Packet a = makeAdvert(0xDF);
uint32_t t0 = 0xFFFFFFFFu - 1000;
EXPECT_TRUE(fl.allowPacket(&a, t0));
EXPECT_FALSE(fl.allowPacket(&a, t0 + 30 * 60000UL)); // wrapped, still inside the hour
EXPECT_TRUE(fl.allowPacket(&a, t0 + HOUR));
}
TEST(AdvertWindow, FullRingEvictsOldestAndCountsIt) {
FairnessLimiter fl;
fl.setBucketsEnabled(false);
AdvertWindow& w = fl.advertWindow();
w.setHours(24);
for (int i = 0; i < w.capacity() + 1; i++) {
Packet a = makeAdvert((uint8_t)(i & 0xFF), (uint8_t)(i >> 8));
EXPECT_TRUE(fl.allowPacket(&a, 0));
}
EXPECT_EQ(w.count(), w.capacity());
EXPECT_EQ(w.evicted(), 1u);
Packet first = makeAdvert(0, 0); // the evicted one passes again
EXPECT_TRUE(fl.allowPacket(&first, 1000));
Packet last = makeAdvert((uint8_t)(w.capacity() & 0xFF), (uint8_t)(w.capacity() >> 8));
EXPECT_FALSE(fl.allowPacket(&last, 1000)); // a recent one is still held
}
TEST(AdvertWindow, HeldAdvertDoesNotTakeABucketToken) {
FairnessLimiter fl;
fl.refillSenderLow(); // 1 advert token per bucket
fl.advertWindow().setHours(1);
Packet cp1 = makeAdvert(0x5F); // 0x5F and 0xDF share a 7-bit bucket
Packet innocent = makeAdvert(0xDF);
EXPECT_TRUE(fl.allowPacket(&cp1, 0)); // takes the only token
fl.refillSenderLow();
EXPECT_FALSE(fl.allowPacket(&cp1, 60000)); // held by the window, token untouched
EXPECT_TRUE(fl.allowPacket(&innocent, 60000));
EXPECT_EQ(fl.deniedSenderLow(), 0u);
}
TEST(DryRun, CountsButForwards) {
FairnessLimiter fl; // zero tokens everywhere
fl.setDryRun(true);
fl.advertWindow().setHours(1);
Packet g = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, {0xEF, 0, 0});
EXPECT_TRUE(fl.allowPacket(&g, 0));
EXPECT_EQ(fl.lastShed(), FAIR_SHED_GROUP);
EXPECT_EQ(fl.deniedGroup(), 1u);
Packet a = makeAdvert(0xDF);
fl.refillSenderLow();
EXPECT_TRUE(fl.allowPacket(&a, 0)); // first: passes on its merits
EXPECT_EQ(fl.lastShed(), FAIR_SHED_NONE);
EXPECT_TRUE(fl.allowPacket(&a, 1000)); // repeat: would be held
EXPECT_EQ(fl.lastShed(), FAIR_SHED_WINDOW);
EXPECT_EQ(fl.deniedWindow(), 1u);
}
TEST(DryRun, SameVerdictsAsEnforcing) {
// Dry-run must predict enforcement exactly: a shed packet takes no token
// and records no window entry in either mode.
FairnessLimiter real, dry;
dry.setDryRun(true);
real.advertWindow().setHours(2);
dry.advertWindow().setHours(2);
real.refillSenderLow();
dry.refillSenderLow();
uint32_t t = 0;
for (int i = 0; i < 200; i++, t += 47000) {
Packet a = makeAdvert((uint8_t)(i % 3 == 0 ? 0xDF : i), 0x10);
if (i % 40 == 0) { real.refillSenderLow(); dry.refillSenderLow(); }
bool r = real.allowPacket(&a, t);
dry.allowPacket(&a, t);
EXPECT_EQ(r, real.lastShed() == FAIR_SHED_NONE);
EXPECT_EQ(real.lastShed(), dry.lastShed()) << "i=" << i;
}
EXPECT_EQ(real.deniedWindow(), dry.deniedWindow());
EXPECT_EQ(real.deniedSenderLow(), dry.deniedSenderLow());
}
TEST(DryRun, ShedAirtimeAccumulatesPerReason) {
FairnessLimiter fl;
fl.addShedAirtime(FAIR_SHED_WINDOW, 900);
fl.addShedAirtime(FAIR_SHED_WINDOW, 850);
fl.addShedAirtime(FAIR_SHED_GROUP, 300);
fl.addShedAirtime(FAIR_SHED_N, 99999); // out of range: ignored
EXPECT_EQ(fl.shedAirtimeMs(FAIR_SHED_WINDOW), 1750u);
EXPECT_EQ(fl.shedAirtimeMs(FAIR_SHED_GROUP), 300u);
EXPECT_EQ(fl.shedAirtimeMs(FAIR_SHED_SENDER), 0u);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();