Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.3.4 ###
* :beetle: Fix conformance issue with data-link confirmations. See PR [#359](https://github.com/dnp3/opendnp3/pull/359).
* :beetle: Fix conformance issue select & operate behaviour. See PR [#359](https://github.com/dnp3/opendnp3/pull/359).

### 2.3.3 ###
* :beetle: Fix C# exception on time conversion upon restart command not supported. See issue [#350](https://github.com/dnp3/opendnp3/issues/350).

Expand Down
4 changes: 2 additions & 2 deletions cpp/libs/src/opendnp3/link/PriLinkLayerStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,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 @@ -285,8 +286,7 @@ PriStateBase& PLLS_ConfDataWait::OnTimeout(LinkContext& ctx)

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

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

void Select(const AppSeqNum& currentSeqN, const openpal::MonotonicTimestamp& now, const openpal::RSlice& objects)
{
selected = true;
selectTime = now;
expectedSeq = currentSeqN.Next();
digest = CRC::CalcCrc(objects);
length = objects.Size();
}

void Unselect()
{
selected = false;
}

private:
bool selected = false;
AppSeqNum expectedSeq;
openpal::MonotonicTimestamp selectTime;
uint16_t digest;
Expand Down
4 changes: 4 additions & 0 deletions cpp/libs/src/opendnp3/outstation/OutstationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ IINField OContext::HandleOperate(const openpal::RSlice& objects, HeaderWriter& w
auto result = APDUParser::Parse(objects, handler, &this->logger);
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/opendnp3/src/TestLinkLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,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();

BufferSegment segments(250, IncrementHex(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, IncrementHex(0x00, 250)));
t.link.OnTxReady();

// Timeout original transmission
t.exe->AdvanceTime(cfg.Timeout);
REQUIRE(t.exe->RunMany() > 0);
REQUIRE(t.NumTotalWrites() == 3);

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

// Timeout retransmission, no more retransmission
t.exe->AdvanceTime(cfg.Timeout);
REQUIRE(t.exe->RunMany() > 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/opendnp3/src/TestOutstationCommandResponses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,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