Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Conformance fixes [develop] #356

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/lib/src/link/PriLinkLayerStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ PriStateBase& PLLS_ConfDataWait::OnNack(LinkContext& ctx, bool rxBuffFull)

PriStateBase& PLLS_ConfDataWait::Failure(LinkContext& ctx)
{
ctx.isRemoteReset = false;
ctx.CancelTimer();
ctx.CompleteSendOperation();
return PLLS_Idle::Instance();
Expand All @@ -284,8 +285,7 @@ PriStateBase& PLLS_ConfDataWait::OnTimeout(LinkContext& ctx)

SIMPLE_LOG_BLOCK(ctx.logger, flags::WARN, "Confirmed data final timeout, no retries remain");
ctx.listener->OnStateChange(LinkStatus::UNRESET);
ctx.CompleteSendOperation();
return PLLS_Idle::Instance();
return Failure(ctx);
}

////////////////////////////////////////////////////////
Expand Down
9 changes: 8 additions & 1 deletion cpp/lib/src/outstation/ControlState.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ControlState
const TimeDuration& timeout,
const ser4cpp::rseq_t& objects) const
{
if (expectedSeq.Equals(seq))
if (selected && expectedSeq.Equals(seq))
{
if (selectTime <= now)
{
Expand Down Expand Up @@ -77,13 +77,20 @@ class ControlState

void Select(const AppSeqNum& currentSeqN, const Timestamp& now, const ser4cpp::rseq_t& objects)
{
selected = true;
selectTime = now;
expectedSeq = currentSeqN.Next();
digest = CRC::CalcCrc(objects);
length = objects.length();
}

void Unselect()
{
selected = false;
}

private:
bool selected = false;
AppSeqNum expectedSeq;
Timestamp selectTime;
uint16_t digest = 0;
Expand Down
4 changes: 4 additions & 0 deletions cpp/lib/src/outstation/OutstationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ IINField OContext::HandleOperate(const ser4cpp::rseq_t& objects, HeaderWriter& w
this->shouldCheckForUnsolicited = true;
return (result == ParseResult::OK) ? handler.Errors() : IINFromParseResult(result);
}
else
{
this->control.Unselect();
}

return this->HandleCommandWithConstant(objects, writer, result);
}
Expand Down
40 changes: 40 additions & 0 deletions cpp/tests/unit/TestLinkLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,46 @@ TEST_CASE(SUITE("ConfirmedDataRetry"))
REQUIRE(t.upper->GetCounters().numTxReady == 1);
}

TEST_CASE(SUITE("ConfirmedDataFailureResetsLink"))
{
LinkConfig cfg = LinkLayerTest::DefaultConfig();
cfg.NumRetry = 1;
cfg.UseConfirms = true;

LinkLayerTest t(cfg);
t.link.OnLowerLayerUp();

MockTransportSegment segments(250, HexConversions::increment_hex(0, 250), cfg.GetAddresses());
t.link.Send(segments);
t.link.OnTxReady();
REQUIRE(t.NumTotalWrites() == 1); // Should now be waiting for an ACK with active timer

t.OnFrame(LinkFunction::SEC_ACK, false, false, false, 1, 1024);
REQUIRE(t.NumTotalWrites() == 2);

REQUIRE(t.PopLastWriteAsHex() == LinkHex::ConfirmedUserData(true, true, 1024, 1, HexConversions::increment_hex(0x00, 250)));
t.link.OnTxReady();

// Timeout original transmission
t.exe->advance_time(cfg.Timeout.value);
REQUIRE(t.exe->run_many() > 0);
REQUIRE(t.NumTotalWrites() == 3);

REQUIRE(t.PopLastWriteAsHex() == LinkHex::ConfirmedUserData(true, true, 1024, 1, HexConversions::increment_hex(0x00, 250)));
t.link.OnTxReady();

// Timeout retransmission, no more retransmission
t.exe->advance_time(cfg.Timeout.value);
REQUIRE(t.exe->run_many() > 0);
REQUIRE(t.NumTotalWrites() == 3);

// When sending something else, then reset link state
t.link.Send(segments);
t.link.OnTxReady();
REQUIRE(t.NumTotalWrites() == 4); // Should now be waiting for an ACK with active timer
REQUIRE(t.PopLastWriteAsHex() == LinkHex::ResetLinkStates(true, 1024, 1));
}

TEST_CASE(SUITE("ResetLinkRetries"))
{
LinkConfig cfg = LinkLayerTest::DefaultConfig();
Expand Down
9 changes: 9 additions & 0 deletions cpp/tests/unit/TestOutstationCommandResponses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,21 @@ TEST_CASE(SUITE("SelectOperateGapInSequenceNumber"))
t.SendToOutstation("C0 03 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 00");
REQUIRE(t.lower->PopWriteAsHex()
== "C0 81 80 00 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 00"); // 0x00 status == CommandStatus::SUCCESS
REQUIRE(1 == t.cmdHandler->NumInvocations());
t.OnTxReady();

// operate
t.SendToOutstation("C2 04 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 00");
REQUIRE(t.lower->PopWriteAsHex()
== "C2 81 80 00 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 02"); // 0x02 no select
REQUIRE(1 == t.cmdHandler->NumInvocations());
t.OnTxReady();

// Proper operate should not be accepted
t.SendToOutstation("C1 04 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 00");
REQUIRE(t.lower->PopWriteAsHex()
== "C1 81 80 00 0C 01 17 01 03 01 01 01 00 00 00 01 00 00 00 02"); // 0x02 no select
REQUIRE(1 == t.cmdHandler->NumInvocations());
t.OnTxReady();
}

Expand Down