diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_5_Operational_Behavior.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_5_Operational_Behavior.adoc index 6e93e2da..5eba4000 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_5_Operational_Behavior.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_5_Operational_Behavior.adoc @@ -1645,9 +1645,10 @@ long as they have different timestamps. all metrics where is_historical=false, NBIRTH and NDATA messages MUST keep metric values in chronological order in the list of metrics in the payload.*# * [tck-testable tck-id-operational-behavior-data-publish-node-metric-datatype]#[yellow-background]*[tck-id-operational-behavior-data-publish-node-metric-datatype] For -all metrics in an NBIRTH, the datatype and corresponding protobuf datatype MUST NOT change in -subsequent NDATA messages. If it does, the Host Application MUST send a rebirth request to the -offending Edge Node.*# +all metrics defined in an NMETA, the datatype MUST NOT change other than in an NMMETA that updates +that definition. What a Host Application does with a message that carries a datatype disagreeing +with the definition is described in the +link:#payloads_p_metric[Metric] section of the Payloads chapter.*# Rules for Device data (DBIRTH and DDATA) messages: @@ -1671,9 +1672,10 @@ long as they have different timestamps. all metrics where is_historical=false, DBIRTH and DDATA messages MUST keep metric values in chronological order in the list of metrics in the payload.*# * [tck-testable tck-id-operational-behavior-data-publish-device-metric-datatype]#[yellow-background]*[tck-id-operational-behavior-data-publish-device-metric-datatype] For -all metrics in an DBIRTH, the datatype and corresponding protobuf datatype MUST NOT change in -subsequent DDATA messages. If it does, the Host Application MUST send a rebirth request to the -offending Edge Node.*# +all metrics defined in a DMETA, the datatype MUST NOT change other than in a DMMETA that updates +that definition. What a Host Application does with a message that carries a datatype disagreeing +with the definition is described in the +link:#payloads_p_metric[Metric] section of the Payloads chapter.*# [[operational_behavior_commands]] === Commands diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc index ead1c438..8b303923 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc @@ -818,9 +818,40 @@ link:#payloads_p_datatypes[valid Sparkplug Data Types].*# datatype MUST NOT be PropertySet or PropertySetList, which are value types for a property rather than for a metric. A metric's properties are carried in its properties field.*# ** [tck-testable tck-id-payloads-metric-datatype-req]#[yellow-background]*[tck-id-payloads-metric-datatype-req] The -datatype MUST be included with each metric definition in NBIRTH and DBIRTH messages.*# -** [tck-testable tck-id-payloads-metric-datatype-not-req]#[yellow-background]*[tck-id-payloads-metric-datatype-not-req] The -datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages.*# +datatype MUST be included with each metric definition in NMETA and DMETA messages, and in an NMMETA +or DMMETA message that adds or updates a metric definition.*# +** [tck-testable tck-id-payloads-metric-datatype-not-req]#[yellow-background]*[tck-id-payloads-metric-datatype-not-req] A +Metric's own datatype field MUST NOT be included in NDATA or DDATA messages. A metric's datatype is +established by the NMETA or DMETA that defined it, and a change of datatype is published in an +NMMETA or DMMETA rather than alongside a value.*# +*** The same holds for the BIRTH and REBIRTH messages, which carry values rather than definitions. +That is stated for each of those message types in the link:#topics[Topics] chapter and is not +repeated here. +*** Non-normative comment: this governs the Metric's own datatype field and not the datatype of the +TypedValue that carries the value, which selects the field the value occupies and is therefore +structural rather than metadata. In the Google Protocol Buffers encoding the two are separate +fields and only the Metric's is omitted. In the JSON encoding a Metric's TypedValue is flattened, +as the link:#payloads_json_typed_values[Typed Values] section describes, so a metric carrying a +value still has a 'datatype' key; in these messages that key is the TypedValue's datatype. +** [tck-testable tck-id-payloads-metric-datatype-data-ignored]#[yellow-background]*[tck-id-payloads-metric-datatype-data-ignored] A +Sparkplug Host Application MUST ignore a Metric datatype field carried in an NBIRTH, NREBIRTH, +DBIRTH, DREBIRTH, NDATA or DDATA message where it is equal to the datatype established for that +metric by the NMETA or DMETA that defined it.*# +** [tck-testable tck-id-payloads-metric-datatype-data-mismatch]#[yellow-background]*[tck-id-payloads-metric-datatype-data-mismatch] A +Sparkplug Host Application MUST reject such a message where the Metric datatype field differs from +the datatype established for that metric, and MUST NOT apply any metric value from that message.*# +** [tck-testable tck-id-payloads-metric-datatype-data-mismatch-rebirth]#[yellow-background]*[tck-id-payloads-metric-datatype-data-mismatch-rebirth] Having +rejected such a message, a Sparkplug Host Application MUST send a Rebirth Request to the Edge Node, +as described in the link:#operational_behavior_rebirth[Rebirth Request] section.*# +*** Non-normative comment: a conforming publisher never sends a Metric datatype field alongside a +value, so these govern what a Host Application does with a non-conforming one. Ignoring a matching +datatype keeps a harmless redundancy from breaking interoperability, while a differing one is a +genuine disagreement about the metric's type. Rejecting the message alone would leave the two sides +out of step indefinitely, since the Host Application's datatype for that metric is then known to +disagree with what the Edge Node is sending, so a Rebirth re-establishes it. This is the same +response the specification gives to an unresolved sequence gap. They are stated for a Host +Application because it is the party that can request a Rebirth, and NCMD and DCMD are out of scope +because a Command invocation is identified by a metric datatype of Command. * *quality* ** This defines the quality of the value associated with the metric. It is defined in the link:#payloads_p_quality[Quality] section. This property is optional and is only required if the @@ -3754,7 +3785,12 @@ Google Protocol Buffers encoding, the two MUST be equal, and the same applies to [tck-testable tck-id-payloads-json-typedvalue-carries-both]#[yellow-background]*[tck-id-payloads-json-typedvalue-carries-both] The single 'datatype' and 'is_null' key a flattened JSON value carries represents both, so an application converting a JSON payload to the Google Protocol Buffers encoding MUST set the Metric -field and the TypedValue field from it.*# +field and the TypedValue field from it, except that in a message which MUST NOT carry a Metric +datatype it sets the TypedValue field only.*# +Non-normative comment: the exception is for the BIRTH, REBIRTH and DATA messages, which carry +values rather than definitions. Setting the Metric datatype there from the flattened key would +produce a Protocol Buffers payload that breaks the rule the JSON payload was keeping, since the one +JSON key stands for both fields while only one of them is permitted in those messages. [tck-testable tck-id-payloads-json-parameter-is-null]#[yellow-background]*[tck-id-payloads-json-parameter-is-null] A Template.Parameter whose value is null MUST carry 'is_null' set to true and omit 'value', as any diff --git a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java index 191832cb..661827ff 100644 --- a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java +++ b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java @@ -486,10 +486,12 @@ public void checkAliasInData(final @NotNull PayloadOrBuilder sparkplugPayload, S id = ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ) public void checkMetricsDataTypeNotRec(final @NotNull PayloadOrBuilder sparkplugPayload, String topic) { logger.debug( - "Check Req: The datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages."); + "Check Req: A Metric's own datatype field MUST NOT be included in NBIRTH, DBIRTH, NDATA, or DDATA messages."); boolean isValid = true; - if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA) || topic.contains(TOPIC_PATH_NCMD) - || topic.contains(TOPIC_PATH_DCMD)) { + // The Metric's own datatype field, a separate field from the TypedValue's, which stays. + // NCMD and DCMD are out of scope: a Command invocation is identified by a datatype of Command. + if (topic.contains(TOPIC_PATH_NBIRTH) || topic.contains(TOPIC_PATH_DBIRTH) + || topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA)) { for (Metric m : sparkplugPayload.getContent().getMetricsList()) { if (m.hasDatatype()) { logger.info("On topic={} - Invalid payload: {}", topic, sparkplugPayload); @@ -498,7 +500,7 @@ public void checkMetricsDataTypeNotRec(final @NotNull PayloadOrBuilder sparkplug } } testResults.put(ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ, - Utils.setShouldResult(isValid, PAYLOADS_METRIC_DATATYPE_NOT_REQ)); + Utils.setResult(isValid, PAYLOADS_METRIC_DATATYPE_NOT_REQ)); } }