fix(udps): stop packets being dated from an earlier time base
Reported as samples sporadically carrying a previous packet's timestamp: holes on one side of the stream and collisions on the other, in both the Go and the MARTe2 receiver. That it appeared in both is what located it -- the shared cause is upstream of either client. Four independent defects, all of which end in a packet's values being placed at a time that is not theirs. Reassembly slot exhaustion (the "Reassembly slots full; evicting oldest" flood). Chunk size was learnt only from fragment 0, so an out-of-order burst destroyed a packet whose bytes had all arrived and left the slot occupied until the 2 s GC. Slots were keyed on the counter alone, but DATA and CONFIG number independently, so equal counters merged the two streams. The 32-byte received-mask covered 256 of the 512 fragments the client accepts, so a duplicate above 255 was counted as new and the packet was delivered with a hole of stale bytes in it. And one datagram was read per Execute(), which cannot drain a fast producer. Fixed with a pendingTail deferral, (counter, type) keying, a 64-byte mask, a 256-datagram drain, counter-age slot reclamation, and a 1 Hz aggregated warning in place of the per-eviction flood. UDPStreamer dropping whole Accumulate batches. EventSem::ResetWait is Reset-then-Wait, so a Post() landing while the sender thread was inside ServiceClients()/SendData() was destroyed by the next Reset. The batch was then skipped with dataReady false, readyFill was never cleared, and the following flush overwrote it: an entire run of RT cycles never reached the wire. The record of pending work now lives in the buffers rather than in the semaphore edge, which also removes up to UDPS_DATA_WAIT_MS of latency; genuine backpressure overwrites are counted and reported. Against the unfixed code the new test sees 2999/3000 batches never consumed. Period inflation after loss. Accumulated scalars carry no SamplingRate, so the receiver derives dt from the sender-clock gap -- but dividing it by the previous packet's sample count is only right while nothing is lost. One loss doubles the reported period, which spreads a batch a full batch past its own end and into the range the next packet claims. That is the hole and the collision, exactly. Inferring the cycle count from the estimate's own period is not a way out: it has a stable fixed point wherever gap/dt is an integer, so a real rate change locks it at the old one for good (AccumDtGTest.FollowsSustainedRateChange). The packet counter removes the ambiguity, so all three receivers now order on it: a DATA packet that does not advance the counter is dropped rather than delivered, because its values are older than data already handed over. Ordering is on the signed difference so it survives the uint32 wrap, and the sequence resets on reconnect, where the producer's counter restarts independently of ours. The loss count that falls out of the same delta feeds the period estimate as cycles = prevN * (1 + lost), which reduces exactly to gap/prevN when nothing is lost and therefore still tracks a genuine rate change. UDPSClient::AcceptDataCounter (C++), udpsprotocol.SequenceGate (Go), decode_data (C). The C client's existing gap counter was wrap-unsafe and let a stale packet rewind last_counter, which made every subsequent gap wrong; it uses the same code now. Docs/Protocol.md gains an Ordering DATA section stating the requirement for any receiver, including ones outside this repository. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
13fac79400
commit
deabd257e5
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* @file AccumDtGTest.cpp
|
||||
* @brief Tests UDPSEstimateAccumDt, the per-sample period estimator used for
|
||||
* accumulated scalars that carry no SamplingRate.
|
||||
*
|
||||
* The estimator exists because the natural formula — sender-clock gap divided
|
||||
* by the previous packet's sample count — is only correct while no packet is
|
||||
* lost. When one is, the gap covers cycles that count never saw and the period
|
||||
* comes out too large, which spreads the packet's samples past their real end
|
||||
* and into the range the next packet claims. The loss count comes from the
|
||||
* producer's packet counter rather than being inferred from the gap itself, so
|
||||
* these tests pin both sides: the estimate must not move when packets go
|
||||
* missing, and it must still follow a genuine rate change — a cycle count
|
||||
* inferred from the estimate's own period would lock onto the old one.
|
||||
*
|
||||
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
|
||||
* the Development of Fusion Energy ('Fusion for Energy').
|
||||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
|
||||
* by the European Commission - subsequent versions of the EUPL (the "Licence")
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
|
||||
*
|
||||
* @warning Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the Licence permissions and limitations under the Licence.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "UDPSourceSession.h"
|
||||
|
||||
using MARTe::float64;
|
||||
using MARTe::uint32;
|
||||
using StreamHub::UDPSEstimateAccumDt;
|
||||
|
||||
namespace {
|
||||
|
||||
/** A producer emitting batches of BATCH cycles at a period of DT seconds. */
|
||||
const float64 kDt = 1.0e-3;
|
||||
const uint32 kBatch = 10u;
|
||||
const float64 kGap = kDt * static_cast<float64>(kBatch);
|
||||
|
||||
/** Feeds n clean packets and returns the settled estimate. */
|
||||
float64 Warmup(uint32 n, float64 &dtEMA, bool &dtValid) {
|
||||
float64 dt = 0.0;
|
||||
for (uint32 i = 0u; i < n; i++) {
|
||||
dt = UDPSEstimateAccumDt(kGap, kBatch, 0u, dtEMA, dtValid);
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/* The first packet has nothing to go on but the previous sample count, so it
|
||||
* must fall back to gap/prevN rather than to some fixed default. */
|
||||
TEST(AccumDtGTest, BootstrapsFromPreviousSampleCount) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
|
||||
const float64 dt = UDPSEstimateAccumDt(kGap, kBatch, 0u, dtEMA, dtValid);
|
||||
|
||||
EXPECT_TRUE(dtValid);
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-12);
|
||||
}
|
||||
|
||||
/* A clean stream must hold the period steady, not drift. */
|
||||
TEST(AccumDtGTest, SteadyStreamStaysOnPeriod) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
|
||||
const float64 dt = Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-9);
|
||||
}
|
||||
|
||||
/* The regression this whole estimator is for: one packet is lost, so the gap
|
||||
* doubles while prevN does not. Dividing by prevN would report 2x the true
|
||||
* period — enough to walk a 10-sample batch a full batch past its own end. */
|
||||
TEST(AccumDtGTest, LostPacketDoesNotInflatePeriod) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
const float64 dt = UDPSEstimateAccumDt(2.0 * kGap, kBatch, 1u, dtEMA, dtValid);
|
||||
|
||||
/* What the naive formula would have produced. */
|
||||
const float64 naive = (2.0 * kGap) / static_cast<float64>(kBatch);
|
||||
EXPECT_NEAR(2.0 * kDt, naive, 1.0e-12);
|
||||
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-6);
|
||||
}
|
||||
|
||||
/* Several consecutive losses are the same situation, just wider. */
|
||||
TEST(AccumDtGTest, MultiplePacketLossDoesNotInflatePeriod) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
for (uint32 missing = 1u; missing <= 5u; missing++) {
|
||||
const float64 span = static_cast<float64>(missing + 1u) * kGap;
|
||||
const float64 dt = UDPSEstimateAccumDt(span, kBatch, missing, dtEMA,
|
||||
dtValid);
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-6) << "after " << missing << " lost packet(s)";
|
||||
}
|
||||
}
|
||||
|
||||
/* Loss must not leave the estimator poisoned for the packets that follow. */
|
||||
TEST(AccumDtGTest, RecoversToCleanStreamAfterLoss) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
(void) UDPSEstimateAccumDt(3.0 * kGap, kBatch, 2u, dtEMA, dtValid);
|
||||
|
||||
const float64 dt = Warmup(20u, dtEMA, dtValid);
|
||||
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-6);
|
||||
}
|
||||
|
||||
/* A real, sustained rate change must still be followed — the estimator is a
|
||||
* smoother, not a latch. Half the period is exactly on the rejection boundary,
|
||||
* so use a change that lands inside the accepted band. */
|
||||
TEST(AccumDtGTest, FollowsSustainedRateChange) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
const float64 newDt = kDt * 0.75;
|
||||
const float64 newGap = newDt * static_cast<float64>(kBatch);
|
||||
float64 dt = 0.0;
|
||||
for (uint32 i = 0u; i < 400u; i++) {
|
||||
dt = UDPSEstimateAccumDt(newGap, kBatch, 0u, dtEMA, dtValid);
|
||||
}
|
||||
|
||||
EXPECT_NEAR(newDt, dt, 1.0e-6);
|
||||
}
|
||||
|
||||
/* A batch that carries fewer cycles than usual (a time-triggered flush) is not
|
||||
* loss: the gap shrinks with it, so the period must not shrink too. */
|
||||
TEST(AccumDtGTest, ShortBatchDoesNotDeflatePeriod) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
const uint32 shortBatch = 3u;
|
||||
const float64 dt = UDPSEstimateAccumDt(
|
||||
kDt * static_cast<float64>(shortBatch), shortBatch, 0u, dtEMA, dtValid);
|
||||
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-6);
|
||||
}
|
||||
|
||||
/* A gap shorter than one period cannot mean zero cycles; the divisor is
|
||||
* clamped so the estimate can never be driven to infinity. */
|
||||
TEST(AccumDtGTest, SubPeriodGapDoesNotExplode) {
|
||||
float64 dtEMA = 0.0;
|
||||
bool dtValid = false;
|
||||
(void) Warmup(50u, dtEMA, dtValid);
|
||||
|
||||
const float64 dt = UDPSEstimateAccumDt(kDt * 1.0e-3, 1u, 0u, dtEMA, dtValid);
|
||||
|
||||
EXPECT_NEAR(kDt, dt, 1.0e-6);
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
#
|
||||
#############################################################
|
||||
|
||||
OBJSX = TriggerEngineSrc.x BinaryRecorderSrc.x SignalRingBufferGTest.x TriggerEngineGTest.x LTTBGTest.x BinaryRecorderGTest.x BoundsCheckTest.x WSServerBufferTest.x
|
||||
OBJSX = TriggerEngineSrc.x BinaryRecorderSrc.x SignalRingBufferGTest.x TriggerEngineGTest.x LTTBGTest.x BinaryRecorderGTest.x BoundsCheckTest.x WSServerBufferTest.x AccumDtGTest.x
|
||||
|
||||
PACKAGE=Applications
|
||||
ROOT_DIR=../../..
|
||||
|
||||
@@ -225,3 +225,8 @@ TEST(UDPStreamerGTest, TestExecute_MulticastConnectDataDisconnect) {
|
||||
UDPStreamerTest test;
|
||||
ASSERT_TRUE(test.TestExecute_MulticastConnectDataDisconnect());
|
||||
}
|
||||
|
||||
TEST(UDPStreamerGTest, TestAccumulate_EveryPublishedCycleReachesTheWire) {
|
||||
UDPStreamerTest test;
|
||||
ASSERT_TRUE(test.TestAccumulate_EveryPublishedCycleReachesTheWire());
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "RealTimeApplication.h"
|
||||
#include "Sleep.h"
|
||||
#include "StandardParser.h"
|
||||
#include "UDPSClient.h"
|
||||
#include "UDPStreamer.h"
|
||||
#include "UDPStreamerTest.h"
|
||||
|
||||
@@ -1845,3 +1846,298 @@ bool UDPStreamerTest::TestExecute_MulticastConnectDataDisconnect() {
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Accumulate publication continuity */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Four float64 scalars, no quantisation: 32 wire bytes per RT cycle.
|
||||
* With MaxPayloadSize = 60 the accumulate header (8 B HRT + 4 B count) leaves
|
||||
* room for exactly one cycle, so the size condition flushes on every single
|
||||
* Synchronise() — the maximum number of hand-offs to the sender thread, each
|
||||
* one a chance for a promoted batch to be skipped. */
|
||||
#define ACC_FUNCTIONS_BLOCK \
|
||||
" +Functions = {\n" \
|
||||
" Class = ReferenceContainer\n" \
|
||||
" +Writer = {\n" \
|
||||
" Class = UDPStreamerTestOutputGAM\n" \
|
||||
" OutputSignals = {\n" \
|
||||
" A = {\n" \
|
||||
" DataSource = Streamer\n" \
|
||||
" Type = float64\n" \
|
||||
" }\n" \
|
||||
" B = {\n" \
|
||||
" DataSource = Streamer\n" \
|
||||
" Type = float64\n" \
|
||||
" }\n" \
|
||||
" C = {\n" \
|
||||
" DataSource = Streamer\n" \
|
||||
" Type = float64\n" \
|
||||
" }\n" \
|
||||
" D = {\n" \
|
||||
" DataSource = Streamer\n" \
|
||||
" Type = float64\n" \
|
||||
" }\n" \
|
||||
" }\n" \
|
||||
" }\n" \
|
||||
" }\n"
|
||||
|
||||
static const MARTe::char8 *const ACC_CFG_CONTINUITY =
|
||||
"+Test = {\n"
|
||||
" Class = RealTimeApplication\n"
|
||||
ACC_FUNCTIONS_BLOCK
|
||||
" +Data = {\n"
|
||||
" Class = ReferenceContainer\n"
|
||||
" +Streamer = {\n"
|
||||
" Class = UDPStreamer\n"
|
||||
" Port = 44680\n"
|
||||
" MaxPayloadSize = 60\n"
|
||||
" PublishingMode = Accumulate\n"
|
||||
" MinRefreshRate = 1000.0\n"
|
||||
" Signals = {\n"
|
||||
" A = {\n"
|
||||
" Type = float64\n"
|
||||
" }\n"
|
||||
" B = {\n"
|
||||
" Type = float64\n"
|
||||
" }\n"
|
||||
" C = {\n"
|
||||
" Type = float64\n"
|
||||
" }\n"
|
||||
" D = {\n"
|
||||
" Type = float64\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
HF_TAIL_BLOCK;
|
||||
|
||||
namespace {
|
||||
|
||||
/** Cycles driven by TestAccumulate_EveryPublishedCycleReachesTheWire. */
|
||||
static const MARTe::uint32 ACC_CONTINUITY_CYCLES = 3000u;
|
||||
|
||||
/**
|
||||
* @brief Records which RT cycles reached the wire, and how often.
|
||||
*
|
||||
* The test stamps signal A with the cycle index before every Synchronise(),
|
||||
* and the config is sized so each Accumulate batch carries exactly one cycle.
|
||||
* The payload is [8 B HRT][4 B numSamples][A][B][C][D], so A of the single
|
||||
* slot sits at offset 12 and identifies the cycle unambiguously.
|
||||
*
|
||||
* Counting distinct cycles (rather than summing numSamples) is what makes this
|
||||
* able to tell a lost publication from a re-sent one: a sender that never
|
||||
* consumes its ready buffer emits the right *number* of packets while
|
||||
* repeating a stale batch, which shows up here as duplicates plus missing
|
||||
* cycles instead of a clean tally.
|
||||
*/
|
||||
class AccumRampRecorder: public MARTe::UDPSClientListener {
|
||||
public:
|
||||
AccumRampRecorder() :
|
||||
packets(0u), duplicates(0u), malformed(0u) {
|
||||
mux.Create();
|
||||
for (MARTe::uint32 i = 0u; i < ACC_CONTINUITY_CYCLES; i++) {
|
||||
seen[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnUDPSData(const MARTe::uint8 *payload, MARTe::uint32 payloadSize) {
|
||||
MARTe::uint32 n = 0u;
|
||||
MARTe::float64 v = 0.0;
|
||||
if (payloadSize >= 20u) {
|
||||
(void) MARTe::MemoryOperationsHelper::Copy(&n, &payload[8], 4u);
|
||||
(void) MARTe::MemoryOperationsHelper::Copy(&v, &payload[12], 8u);
|
||||
}
|
||||
(void) mux.FastLock();
|
||||
packets++;
|
||||
if ((payloadSize < 20u) || (n != 1u)) {
|
||||
malformed++;
|
||||
}
|
||||
else {
|
||||
MARTe::uint32 idx = static_cast<MARTe::uint32>(v);
|
||||
if ((static_cast<MARTe::float64>(idx) != v) || (idx >= ACC_CONTINUITY_CYCLES)) {
|
||||
malformed++;
|
||||
}
|
||||
else if (seen[idx]) {
|
||||
duplicates++;
|
||||
}
|
||||
else {
|
||||
seen[idx] = true;
|
||||
}
|
||||
}
|
||||
mux.FastUnLock();
|
||||
}
|
||||
|
||||
MARTe::uint32 DistinctCycles() {
|
||||
(void) mux.FastLock();
|
||||
MARTe::uint32 n = 0u;
|
||||
for (MARTe::uint32 i = 0u; i < ACC_CONTINUITY_CYCLES; i++) {
|
||||
if (seen[i]) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
MARTe::uint32 Packets() {
|
||||
(void) mux.FastLock();
|
||||
MARTe::uint32 n = packets;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
MARTe::uint32 Duplicates() {
|
||||
(void) mux.FastLock();
|
||||
MARTe::uint32 n = duplicates;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
MARTe::uint32 Malformed() {
|
||||
(void) mux.FastLock();
|
||||
MARTe::uint32 n = malformed;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
MARTe::FastPollingMutexSem mux;
|
||||
bool seen[ACC_CONTINUITY_CYCLES];
|
||||
MARTe::uint32 packets;
|
||||
MARTe::uint32 duplicates;
|
||||
MARTe::uint32 malformed;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool UDPStreamerTest::TestAccumulate_EveryPublishedCycleReachesTheWire() {
|
||||
using namespace MARTe;
|
||||
|
||||
/* One-cycle batches every 200 us: ~5000 small packets/s, which the sender
|
||||
* thread handles comfortably. The period has to be this short because a
|
||||
* wake-up can only be swallowed while the sender is mid-send; at 1 ms the
|
||||
* sender is always back in its wait before the next Synchronise() and the
|
||||
* defect never fires at all. */
|
||||
const uint32 CYCLES = ACC_CONTINUITY_CYCLES;
|
||||
static const float64 CYCLE_SEC = 200e-6;
|
||||
|
||||
/* Tolerance, as a fraction of CYCLES, for cycles that never reach the wire.
|
||||
* It is not zero: this is an ordinary userspace thread on a general-purpose
|
||||
* kernel, so it can occasionally be descheduled past a 200 us slot, and the
|
||||
* last batch may still be in the accumulation buffer when the loop ends.
|
||||
* It is small because the defect this guards against is not marginal — a
|
||||
* sender that decides what to send from the semaphore edge fails to consume
|
||||
* essentially every batch (~100% here), so a 1% ceiling separates the two
|
||||
* regimes with three orders of magnitude to spare. */
|
||||
const uint32 MAX_LOST = CYCLES / 100u;
|
||||
|
||||
ReferenceT<RealTimeApplication> app = LoadApplication(ACC_CFG_CONTINUITY);
|
||||
bool ok = app.IsValid();
|
||||
if (ok) {
|
||||
ok = (app->PrepareNextState("State1") == ErrorManagement::NoError);
|
||||
}
|
||||
Sleep::MSec(50u);
|
||||
|
||||
AccumRampRecorder counter;
|
||||
UDPSClient client;
|
||||
ReferenceT<UDPStreamer> ds;
|
||||
if (ok) {
|
||||
ConfigurationDatabase clientCfg;
|
||||
ok = clientCfg.Write("ServerAddr", "127.0.0.1");
|
||||
ok = ok && clientCfg.Write("Port", 44680u);
|
||||
ok = ok && clientCfg.Write("SilenceTimeout", 0.0f);
|
||||
ok = ok && clientCfg.Write("KeepAliveInterval", 0u);
|
||||
client.SetListener(&counter);
|
||||
ok = ok && client.Initialise(clientCfg);
|
||||
ok = ok && client.Start();
|
||||
}
|
||||
|
||||
/* Wait for the CONNECT to register on the streamer side. */
|
||||
if (ok) {
|
||||
ds = ObjectRegistryDatabase::Instance()->Find("Test.Data.Streamer");
|
||||
ok = ds.IsValid();
|
||||
}
|
||||
if (ok) {
|
||||
uint32 waited = 0u;
|
||||
while ((waited < 3000u) && !ds->IsClientConnected()) {
|
||||
Sleep::MSec(20u);
|
||||
waited += 20u;
|
||||
}
|
||||
ok = ds->IsClientConnected();
|
||||
}
|
||||
|
||||
/* Signal A carries the cycle index, so every packet identifies exactly
|
||||
* which RT cycle produced it. Synchronise() snapshots the DataSource
|
||||
* memory, so writing straight into it is equivalent to a GAM having
|
||||
* produced the value. */
|
||||
float64 *sigA = NULL_PTR(float64 *);
|
||||
if (ok) {
|
||||
void *addr = NULL_PTR(void *);
|
||||
ok = ds->GetSignalMemoryBuffer(0u, 0u, addr);
|
||||
sigA = reinterpret_cast<float64 *>(addr);
|
||||
ok = ok && (sigA != NULL_PTR(float64 *));
|
||||
}
|
||||
|
||||
/* Drive the RT cycles. */
|
||||
if (ok) {
|
||||
for (uint32 i = 0u; (i < CYCLES) && ok; i++) {
|
||||
*sigA = static_cast<float64>(i);
|
||||
ok = ds->Synchronise();
|
||||
Sleep::Sec(CYCLE_SEC);
|
||||
}
|
||||
}
|
||||
|
||||
/* Let the last packets drain. */
|
||||
Sleep::MSec(300u);
|
||||
|
||||
uint32 distinct = counter.DistinctCycles();
|
||||
uint32 packets = counter.Packets();
|
||||
uint32 duplicates = counter.Duplicates();
|
||||
uint32 malformed = counter.Malformed();
|
||||
uint32 dropped = (ds.IsValid()) ? ds->GetDroppedPublications() : 0u;
|
||||
|
||||
if (ok) {
|
||||
ok = (malformed == 0u);
|
||||
if (!ok) {
|
||||
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
|
||||
"%u of %u DATA packets did not carry exactly one "
|
||||
"decodable cycle index.", malformed, packets);
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
/* A cycle that never arrives is a hole in the consumer's time series. */
|
||||
ok = (distinct + MAX_LOST) >= CYCLES;
|
||||
if (!ok) {
|
||||
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
|
||||
"Accumulate lost cycles: %u of %u reached the wire "
|
||||
"in %u packets (%u duplicates, %u publications "
|
||||
"overwritten before being sent).",
|
||||
distinct, CYCLES, packets, duplicates, dropped);
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
/* A cycle that arrives twice means the sender re-sent a ready buffer it
|
||||
* had already transmitted, which lands the same samples on the receiver
|
||||
* under two different time bases. */
|
||||
ok = (duplicates == 0u);
|
||||
if (!ok) {
|
||||
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
|
||||
"%u of %u DATA packets repeated a cycle already sent.",
|
||||
duplicates, packets);
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
/* Same ceiling from the producer's side: it sees the overwrite directly
|
||||
* and does not depend on the packet reaching the loopback socket. */
|
||||
ok = (dropped <= MAX_LOST);
|
||||
if (!ok) {
|
||||
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
|
||||
"%u of %u publications were overwritten before the "
|
||||
"sender thread took them.", dropped, CYCLES);
|
||||
}
|
||||
}
|
||||
|
||||
(void) client.Stop();
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -234,6 +234,16 @@ public:
|
||||
* @brief Tests full TCP CONNECT → CONFIG → DATA via multicast → DISCONNECT on loopback.
|
||||
*/
|
||||
bool TestExecute_MulticastConnectDataDisconnect();
|
||||
|
||||
/**
|
||||
* @brief Tests that Accumulate publishes every RT cycle it batches.
|
||||
* @details Drives 600 cycles at a rate the sender thread trivially keeps up
|
||||
* with, and sums the numSamples field of every DATA packet that arrives.
|
||||
* A batch promoted to the ready buffer but never sent — because the wake-up
|
||||
* announcing it was swallowed — shows up here as missing cycles, which a
|
||||
* consumer sees as a hole in the time series.
|
||||
*/
|
||||
bool TestAccumulate_EveryPublishedCycleReachesTheWire();
|
||||
};
|
||||
|
||||
#endif /* UDPSTREAMERTEST_H_ */
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "ConfigurationDatabase.h"
|
||||
#include "FastPollingMutexSem.h"
|
||||
#include "InternetHost.h"
|
||||
#include "Sleep.h"
|
||||
#include "UDPSClient.h"
|
||||
@@ -131,6 +132,147 @@ bool WaitForClient(UDPSServer &server, uint32 timeoutMs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Fragment-reassembly test harness */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** Largest reassembled payload the recording listener keeps a copy of. */
|
||||
const uint32 kMaxRecordedBytes = 8192u;
|
||||
/** How many reassembled payloads the recording listener keeps. */
|
||||
const uint32 kMaxRecorded = 16u;
|
||||
|
||||
/**
|
||||
* @brief Listener that records every reassembled DATA/CONFIG payload.
|
||||
*
|
||||
* Callbacks run on the UDPSClient receive thread; the test thread reads the
|
||||
* records after a settle sleep, so both sides take the same lock.
|
||||
*/
|
||||
class RecordingListener: public UDPSClientListener {
|
||||
public:
|
||||
RecordingListener() :
|
||||
dataCount(0u), configCount(0u) {
|
||||
mux.Create();
|
||||
}
|
||||
|
||||
virtual void OnUDPSData(const uint8 *payload, uint32 payloadSize) {
|
||||
Record(dataPayloads, dataSizes, dataCount, payload, payloadSize);
|
||||
}
|
||||
|
||||
virtual void OnUDPSConfig(const uint8 *payload, uint32 payloadSize) {
|
||||
Record(configPayloads, configSizes, configCount, payload, payloadSize);
|
||||
}
|
||||
|
||||
uint32 DataCount() {
|
||||
(void) mux.FastLock();
|
||||
uint32 n = dataCount;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
uint32 ConfigCount() {
|
||||
(void) mux.FastLock();
|
||||
uint32 n = configCount;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
/** @return true iff record @p idx matches @p expected byte for byte. */
|
||||
bool DataMatches(uint32 idx, const uint8 *expected, uint32 expectedSize) {
|
||||
return Matches(dataPayloads, dataSizes, dataCount, idx, expected,
|
||||
expectedSize);
|
||||
}
|
||||
|
||||
bool ConfigMatches(uint32 idx, const uint8 *expected, uint32 expectedSize) {
|
||||
return Matches(configPayloads, configSizes, configCount, idx, expected,
|
||||
expectedSize);
|
||||
}
|
||||
|
||||
uint32 DataSize(uint32 idx) {
|
||||
(void) mux.FastLock();
|
||||
uint32 n = (idx < dataCount) ? dataSizes[idx] : 0u;
|
||||
mux.FastUnLock();
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
void Record(uint8 (&dst)[kMaxRecorded][kMaxRecordedBytes],
|
||||
uint32 (&sizes)[kMaxRecorded], uint32 &count,
|
||||
const uint8 *payload, uint32 payloadSize) {
|
||||
(void) mux.FastLock();
|
||||
if (count < kMaxRecorded) {
|
||||
sizes[count] = payloadSize;
|
||||
uint32 n = (payloadSize < kMaxRecordedBytes) ? payloadSize
|
||||
: kMaxRecordedBytes;
|
||||
memcpy(dst[count], payload, n);
|
||||
count++;
|
||||
}
|
||||
mux.FastUnLock();
|
||||
}
|
||||
|
||||
bool Matches(uint8 (&src)[kMaxRecorded][kMaxRecordedBytes],
|
||||
uint32 (&sizes)[kMaxRecorded], uint32 &count, uint32 idx,
|
||||
const uint8 *expected, uint32 expectedSize) {
|
||||
(void) mux.FastLock();
|
||||
bool ok = (idx < count) && (sizes[idx] == expectedSize) &&
|
||||
(expectedSize <= kMaxRecordedBytes) &&
|
||||
(memcmp(src[idx], expected, expectedSize) == 0);
|
||||
mux.FastUnLock();
|
||||
return ok;
|
||||
}
|
||||
|
||||
FastPollingMutexSem mux;
|
||||
uint8 dataPayloads[kMaxRecorded][kMaxRecordedBytes];
|
||||
uint32 dataSizes[kMaxRecorded];
|
||||
uint32 dataCount;
|
||||
uint8 configPayloads[kMaxRecorded][kMaxRecordedBytes];
|
||||
uint32 configSizes[kMaxRecorded];
|
||||
uint32 configCount;
|
||||
};
|
||||
|
||||
/** Fill @p buf with a position-dependent pattern so misplacement is visible. */
|
||||
void FillPattern(uint8 *buf, uint32 n, uint8 seed) {
|
||||
for (uint32 i = 0u; i < n; i++) {
|
||||
buf[i] = static_cast<uint8>((i * 7u) + seed);
|
||||
}
|
||||
}
|
||||
|
||||
/** Send one UDPS fragment datagram to 127.0.0.1:@p dstPort. */
|
||||
bool SendFragment(BasicUDPSocket &sock, uint16 dstPort, uint8 type,
|
||||
uint32 counter, uint16 fragIdx, uint16 totalFrags,
|
||||
const uint8 *payload, uint32 payloadBytes) {
|
||||
uint8 buf[UDPS_HEADER_SIZE + 2048u];
|
||||
if (payloadBytes > 2048u) {
|
||||
return false;
|
||||
}
|
||||
UDPSBuildHeader(buf, type, counter, fragIdx, totalFrags, payloadBytes);
|
||||
memcpy(&buf[UDPS_HEADER_SIZE], payload, payloadBytes);
|
||||
InternetHost dst(dstPort, "127.0.0.1");
|
||||
(void) sock.SetDestination(dst);
|
||||
uint32 n = UDPS_HEADER_SIZE + payloadBytes;
|
||||
return sock.Write(reinterpret_cast<const char8 *>(buf), n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Bring up a UDPSClient pointed at @p server and learn the ephemeral
|
||||
* port it receives DATA on (the source port of its CONNECT).
|
||||
*
|
||||
* Silence timeout and keepalive are disabled so the session never churns
|
||||
* underneath the fragments the test injects.
|
||||
*/
|
||||
bool StartClientAndLearnPort(UDPSClient &client, ConfigurationDatabase &cfg,
|
||||
BasicUDPSocket &server, uint16 serverPort,
|
||||
uint16 &clientPort) {
|
||||
if (!cfg.Write("ServerAddr", "127.0.0.1")) { return false; }
|
||||
if (!cfg.Write("Port", static_cast<uint32>(serverPort))) { return false; }
|
||||
if (!cfg.Write("SilenceTimeout", 0.0f)) { return false; }
|
||||
if (!cfg.Write("KeepAliveInterval", 0u)) { return false; }
|
||||
if (!client.Initialise(cfg)) { return false; }
|
||||
if (!client.Start()) { return false; }
|
||||
uint8 type = 0xFFu;
|
||||
if (!WaitDatagram(server, 3000, type, clientPort)) { return false; }
|
||||
return (type == UDPS_TYPE_CONNECT) && (clientPort != 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@@ -346,3 +488,277 @@ TEST(UDPSClientGTest, TestSilenceTimeoutSubSecondTriggersReconnect) {
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestReorderedFragmentsAreReassembled) {
|
||||
/* UDP gives no ordering guarantee: the fragments of one packet may arrive
|
||||
* in any order, with nothing lost. Reassembly must not depend on fragment
|
||||
* 0 arriving first — if it does, an out-of-order burst destroys a packet
|
||||
* whose bytes all arrived, and leaves a slot occupied until the 2 s GC,
|
||||
* which is how four slots end up permanently full. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
/* 20-byte payload over three 8-byte chunks: the last one is short, which
|
||||
* is exactly why chunk size has to be learnt from a non-last fragment. */
|
||||
uint8 expected[20];
|
||||
FillPattern(expected, sizeof(expected), 3u);
|
||||
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 7u, 1u, 3u,
|
||||
&expected[8], 8u));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 7u, 2u, 3u,
|
||||
&expected[16], 4u));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 7u, 0u, 3u,
|
||||
&expected[0], 8u));
|
||||
|
||||
Sleep::MSec(400u);
|
||||
|
||||
ASSERT_EQ(listener.DataCount(), 1u)
|
||||
<< "no fragment was lost, yet the packet was not delivered";
|
||||
EXPECT_EQ(listener.DataSize(0u), 20u);
|
||||
EXPECT_TRUE(listener.DataMatches(0u, expected, sizeof(expected)));
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestDataAndConfigWithSameCounterDoNotCollide) {
|
||||
/* DATA and CONFIG carry independent counter sequences, so the same counter
|
||||
* value legitimately appears on both. A reassembly slot keyed on the
|
||||
* counter alone merges the two streams: one payload is delivered under the
|
||||
* wrong type and the other is silently dropped. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
uint8 dataPayload[16];
|
||||
uint8 cfgPayload[16];
|
||||
FillPattern(dataPayload, sizeof(dataPayload), 11u);
|
||||
FillPattern(cfgPayload, sizeof(cfgPayload), 200u);
|
||||
|
||||
/* Same counter (42), interleaved, two fragments each. */
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_CONFIG, 42u, 0u, 2u,
|
||||
&cfgPayload[0], 8u));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 42u, 0u, 2u,
|
||||
&dataPayload[0], 8u));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_CONFIG, 42u, 1u, 2u,
|
||||
&cfgPayload[8], 8u));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 42u, 1u, 2u,
|
||||
&dataPayload[8], 8u));
|
||||
|
||||
Sleep::MSec(400u);
|
||||
|
||||
EXPECT_EQ(listener.ConfigCount(), 1u);
|
||||
EXPECT_TRUE(listener.ConfigMatches(0u, cfgPayload, sizeof(cfgPayload)));
|
||||
ASSERT_EQ(listener.DataCount(), 1u)
|
||||
<< "the DATA packet was swallowed by the CONFIG slot sharing its counter";
|
||||
EXPECT_TRUE(listener.DataMatches(0u, dataPayload, sizeof(dataPayload)));
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestDuplicateHighIndexFragmentDoesNotFakeCompletion) {
|
||||
/* Completion is decided by counting fragments, with a received-bitmask to
|
||||
* reject duplicates. If the mask is narrower than the fragment count the
|
||||
* client accepts, a duplicated high-index fragment is counted twice and
|
||||
* the packet is delivered while a fragment is still missing — a payload
|
||||
* with a hole of stale bytes, reported as valid. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
/* 300 fragments — past the 256 a 32-byte mask covers, but well inside the
|
||||
* 512 the client's own sanity check permits. */
|
||||
const uint16 kTotalFrags = 300u;
|
||||
const uint32 kChunk = 8u;
|
||||
const uint32 kLastChunk = 4u;
|
||||
const uint32 kTotalBytes = ((kTotalFrags - 1u) * kChunk) + kLastChunk;
|
||||
uint8 expected[((kTotalFrags - 1u) * kChunk) + kLastChunk];
|
||||
FillPattern(expected, kTotalBytes, 5u);
|
||||
|
||||
/* Everything except the final fragment, plus one duplicate above 255. */
|
||||
for (uint16 f = 0u; f < (kTotalFrags - 1u); f++) {
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 9u, f,
|
||||
kTotalFrags, &expected[f * kChunk], kChunk));
|
||||
}
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 9u, 260u,
|
||||
kTotalFrags, &expected[260u * kChunk], kChunk));
|
||||
|
||||
Sleep::MSec(500u);
|
||||
|
||||
ASSERT_EQ(listener.DataCount(), 0u)
|
||||
<< "delivered with a fragment still missing (a duplicate was counted "
|
||||
"as a new fragment)";
|
||||
|
||||
/* The genuinely missing fragment completes it, with the right bytes. */
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 9u,
|
||||
kTotalFrags - 1u, kTotalFrags,
|
||||
&expected[(kTotalFrags - 1u) * kChunk],
|
||||
kLastChunk));
|
||||
Sleep::MSec(400u);
|
||||
|
||||
ASSERT_EQ(listener.DataCount(), 1u);
|
||||
EXPECT_EQ(listener.DataSize(0u), kTotalBytes);
|
||||
EXPECT_TRUE(listener.DataMatches(0u, expected, kTotalBytes));
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestStaleDataPacketIsNotDelivered) {
|
||||
/* A DATA packet that arrives after a newer one has already been delivered
|
||||
* carries an older time base. Delivering it makes the consumer place its
|
||||
* samples behind the ones it has: they collide with what is already
|
||||
* plotted, and the range they should have occupied stays empty. The
|
||||
* counter is the only thing that tells the two apart, so the client must
|
||||
* drop anything that does not advance it. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
uint8 pkt[8];
|
||||
FillPattern(pkt, sizeof(pkt), 1u);
|
||||
|
||||
/* 10 and 11 advance the counter; 9 and the repeat of 11 do not. */
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 10u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 11u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 9u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 11u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
|
||||
Sleep::MSec(400u);
|
||||
|
||||
EXPECT_EQ(listener.DataCount(), 2u)
|
||||
<< "a packet older than one already delivered reached the listener";
|
||||
EXPECT_EQ(client.GetStaleDataPackets(), 2u);
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestCounterGapIsReported) {
|
||||
/* Consumers that infer a sample period from the sender-clock gap need to
|
||||
* know how many packets that gap spans; without it a single loss reads as
|
||||
* a halved rate. The gap comes from the counter, and must exclude the
|
||||
* packet being delivered. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
uint8 pkt[8];
|
||||
FillPattern(pkt, sizeof(pkt), 2u);
|
||||
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 100u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
Sleep::MSec(200u);
|
||||
EXPECT_EQ(client.GetLastDataGap(), 0u) << "the first packet lost nothing";
|
||||
|
||||
/* 101, 102 and 103 never arrive. */
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 104u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
Sleep::MSec(200u);
|
||||
EXPECT_EQ(client.GetLastDataGap(), 3u);
|
||||
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA, 105u, 0u, 1u,
|
||||
pkt, sizeof(pkt)));
|
||||
Sleep::MSec(200u);
|
||||
EXPECT_EQ(client.GetLastDataGap(), 0u) << "the gap must not persist";
|
||||
|
||||
EXPECT_EQ(listener.DataCount(), 3u);
|
||||
EXPECT_EQ(client.GetStaleDataPackets(), 0u);
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestCounterWraparoundDoesNotRejectStream) {
|
||||
/* The counter is a uint32 that wraps. Ordering it by plain comparison
|
||||
* would call every packet after the wrap older than 0xFFFFFFFF and reject
|
||||
* the stream permanently, so the ordering has to be done on the signed
|
||||
* difference. */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
RecordingListener listener;
|
||||
UDPSClient client;
|
||||
client.SetListener(&listener);
|
||||
ConfigurationDatabase cfg;
|
||||
uint16 clientPort = 0u;
|
||||
ASSERT_TRUE(StartClientAndLearnPort(client, cfg, server, serverPort,
|
||||
clientPort));
|
||||
|
||||
uint8 pkt[8];
|
||||
FillPattern(pkt, sizeof(pkt), 4u);
|
||||
|
||||
const uint32 counters[4] = { 0xFFFFFFFEu, 0xFFFFFFFFu, 0u, 1u };
|
||||
for (uint32 i = 0u; i < 4u; i++) {
|
||||
ASSERT_TRUE(SendFragment(server, clientPort, UDPS_TYPE_DATA,
|
||||
counters[i], 0u, 1u, pkt, sizeof(pkt)));
|
||||
Sleep::MSec(150u);
|
||||
}
|
||||
|
||||
EXPECT_EQ(listener.DataCount(), 4u)
|
||||
<< "the stream was rejected across the counter wrap";
|
||||
EXPECT_EQ(client.GetStaleDataPackets(), 0u);
|
||||
EXPECT_EQ(client.GetLastDataGap(), 0u);
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user