Skip to content

Commit

Permalink
Ensure presence of sequence number, not just default eclipse-sparkplu…
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs-sparkplug committed Feb 28, 2024
1 parent 84a2d72 commit 3bda79e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Copyright (c) 2022 Anja Helmbrecht-Schaar, Ian Craggs
* Copyright (c) 2022, 2024 Anja Helmbrecht-Schaar, Ian Craggs
* <p>
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -341,9 +341,11 @@ public void checkSequenceNumberIncluded(final @NotNull PublishPacket packet, Str
isValid = false;
logger.error("Check req set for : {}", ID_PAYLOADS_SEQUENCE_NUM_ALWAYS_INCLUDED);
} else {
if (result.getSeq() >= 0) {
isValid = true;
} else if (result.getSeq() == seqUnassigned && topic.contains(TOPIC_PATH_NDEATH)) {
if (result.hasSeq()) {
if (result.getSeq() >= 0 && result.getSeq() <= 255) {
isValid = true;
}
} else if (topic.contains(TOPIC_PATH_NDEATH)) {
isValid = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Ian Craggs
* Copyright (c) 2021, 2024 Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -511,7 +511,7 @@ private Boolean[] checkValidPayload(PayloadOrBuilder payload) {
if (payload != null) {
long seqNum = payload.getSeq();
bValidPayload[0] = true;
bValidPayload[1] = (seqNum >= 0 && seqNum <= 255);
bValidPayload[1] = payload.hasSeq() && (seqNum >= 0 && seqNum <= 255);
bValidPayload[2] = payload.hasTimestamp();
bValidPayload[3] = payload.hasTimestamp();
List<Metric> metrics = payload.getMetricsList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Ian Craggs
* Copyright (c) 2021, 2024 Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -630,14 +630,15 @@ public void checkNBirth(final @NotNull PublishPacket packet) {
logger.debug("Check Req: NBIRTH message must have Qos set to 0.");
logger.debug(
"Check Req: Every NBIRTH message MUST include a sequence number and it MUST have a value of 0.");
boolean hasSeq = sparkplugPayload.hasSeq();
seq = sparkplugPayload.getSeq();
testResults.put(ID_PAYLOADS_NBIRTH_SEQ, setResult((seq == 0), PAYLOADS_NBIRTH_SEQ));
testResults.put(ID_TOPICS_NBIRTH_SEQ_NUM, setResult((seq == 0), TOPICS_NBIRTH_SEQ_NUM));
testResults.put(ID_PAYLOADS_NBIRTH_SEQ, setResult((hasSeq && seq == 0), PAYLOADS_NBIRTH_SEQ));
testResults.put(ID_TOPICS_NBIRTH_SEQ_NUM, setResult((hasSeq && seq == 0), TOPICS_NBIRTH_SEQ_NUM));
testResults.put(ID_PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH,
setResult((seq >= 0 && seq <= 255), PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH));
setResult((hasSeq && (seq >= 0 && seq <= 255)), PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH));

testResults.put(ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ,
setResult((seq >= 0 && seq <= 255), MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ));
setResult((hasSeq && (seq >= 0 && seq <= 255)), MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ));

logger.debug(
"Check Req: NBIRTH messages MUST include a payload timestamp that denotes the time at which the message was published.");
Expand Down Expand Up @@ -881,9 +882,8 @@ public void checkDBirth(final @NotNull PublishPacket packet) {
logger.debug("Check Req: DBIRTH must include a sequence number");
prevResult = testResults.getOrDefault(ID_PAYLOADS_DBIRTH_SEQ, NOT_EXECUTED);
if (!prevResult.contains(FAIL)) {
boolean bContains = (sparkplugPayload.getSeq() != -1);
if (prevResult.equals(NOT_EXECUTED)) {
testResults.put(ID_PAYLOADS_DBIRTH_SEQ, setResult(bContains, PAYLOADS_DBIRTH_SEQ));
testResults.put(ID_PAYLOADS_DBIRTH_SEQ, setResult(sparkplugPayload.hasSeq(), PAYLOADS_DBIRTH_SEQ));
}
}

Expand All @@ -894,12 +894,12 @@ public void checkDBirth(final @NotNull PublishPacket packet) {
if (!prevResult.contains(FAIL)) {
boolean bSeqValid = false;
if (seq != 255) {
if (sparkplugPayload.getSeq() == (seq + 1)) {
if (sparkplugPayload.hasSeq() && (sparkplugPayload.getSeq() == (seq + 1))) {
bSeqValid = true;
seq = sparkplugPayload.getSeq();
}
} else {
if (sparkplugPayload.getSeq() == 0) {
if (sparkplugPayload.hasSeq() && (sparkplugPayload.getSeq() == 0)) {
bSeqValid = true;
seq = sparkplugPayload.getSeq();
}
Expand Down

0 comments on commit 3bda79e

Please sign in to comment.