diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_1_Introduction.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_1_Introduction.adoc index 653199c7..7087b69e 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_1_Introduction.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_1_Introduction.adoc @@ -426,8 +426,8 @@ is used to generate the code for each specific language. In addition to Protobuf datatypes and native programming language datatypes there are also 'Sparkplug datatypes'. These are defined in the link:#payloads_b_google_protocol_buffer_schema[Sparkplug Protobuf Schema]. These datatypes are those -that are used for Sparkplug Metrics. Every Metric must include a Sparkplug Datatype in the NBIRTH or -DBIRTH message depending on whether the Metric is a 'Node level' or 'Device level' metric. Each of +that are used for Sparkplug Metrics. Every Metric must include a Sparkplug Datatype in the NMETA or +DMETA message depending on whether the Metric is a 'Node level' or 'Device level' metric. Each of the Sparkplug Datatypes is then represented by a Google Protobuf datatype. [[introduction_normative_references]] diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_3_Components.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_3_Components.adoc index c2e27975..94de3abe 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_3_Components.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_3_Components.adoc @@ -59,9 +59,10 @@ Sparkplug Edge Node. A Sparkplug Command is a strongly typed, callable function exposed by a Sparkplug Edge Node or Device. A command declares a typed signature consisting of the input arguments it accepts and the -output results it returns, and it is included in the BIRTH certificate alongside the Edge Node's -or Device's other metrics. A Host Application invokes a command using a correlated request/response -exchange so that returned data and error codes can be reliably matched back to the request. Commands +output results it returns, and it is included in the NMETA or DMETA alongside the Edge Node's +or Device's other metric definitions. A Host Application invokes a command using a correlated +request/response exchange so that returned data and error codes can be reliably matched back to the +request. Commands are optional. An Edge Node or Device may expose no commands at all. The structure and behavior of commands are defined in the link:#payloads_p_command[Command Section] and the link:#operational_behavior_commands_typed[Typed Commands and Command Responses Section]. 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..2d214d30 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 value carried in subsequent NDATA messages MUST use the +TypedValue field that the datatype declared for that metric in the NMETA maps to. If it does not, +the Host Application MUST send a rebirth request to the offending Edge Node, following the rules in +the link:#operational_behavior_rebirth[Rebirth Requests] section.*# Rules for Device data (DBIRTH and DDATA) messages: @@ -1671,17 +1672,23 @@ 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 value carried in subsequent DDATA messages MUST use the +TypedValue field that the datatype declared for that metric in the DMETA maps to. If it does not, +the Host Application MUST send a rebirth request to the offending Edge Node, following the rules in +the link:#operational_behavior_rebirth[Rebirth Requests] section.*# +** Non-normative comment: a mismatch is evaluated against the declaration in the NMETA or DMETA, +which a rebirth does not change, so an Edge Node that keeps publishing the same mismatched value +will keep mismatching after the rebirth it triggered. A Host Application is expected to limit the +rate at which it requests rebirths for this condition rather than to request one for every offending +message. [[operational_behavior_commands]] === Commands Commands are used in Sparkplug to allow Sparkplug Host Applications to send data to Sparkplug Edge Nodes. Examples include writing to outputs of Sparkplug Edge Nodes and Devices or to call 'Node -Control' or 'Device Control' commands. Custom command endpoints can be declared in an NBIRTH or -DBIRTH message by an Edge Node or Device that may support functionality such as rebooting an Edge +Control' or 'Device Control' commands. Custom command endpoints can be declared in an NMETA or +DMETA message by an Edge Node or Device that may support functionality such as rebooting an Edge Node or Device. This is up to the Sparkplug implementor to define what functionality can be exposed. Security and access is an important aspect of commands. It may be the case that not all Sparkplug @@ -1768,10 +1775,10 @@ For Edge Node level commands, the following rules must be followed. * [tck-testable tck-id-operational-behavior-commands-ncmd-verb]#[yellow-background]*[tck-id-operational-behavior-commands-ncmd-verb] An Edge Node level command MUST use the NCMD Sparkplug verb.*# * [tck-testable tck-id-operational-behavior-commands-ncmd-metric-name]#[yellow-background]*[tck-id-operational-behavior-commands-ncmd-metric-name] An -NCMD message SHOULD include a metric name that was included in the associated NBIRTH message for the -Edge Node.*# -** Sparkplug Edge Node Applications should be resilient to receiving metrics names that were not -included in the NBIRTH message. +NCMD message SHOULD identify a metric that was defined in the associated NMETA for the Edge +Node.*# +** Sparkplug Edge Node Applications should be resilient to receiving metrics that were not defined +in the NMETA. * [tck-testable tck-id-operational-behavior-commands-ncmd-metric-value]#[yellow-background]*[tck-id-operational-behavior-commands-ncmd-metric-value] An NCMD message MUST include a compatible metric value for the metric name that it is writing to.*# ** In other words, if the metric has a datatype of a boolean the value must be true or false. @@ -1781,10 +1788,9 @@ For Device level commands, the following rules must be followed. * [tck-testable tck-id-operational-behavior-commands-dcmd-verb]#[yellow-background]*[tck-id-operational-behavior-commands-dcmd-verb] A Device level command MUST use the DCMD Sparkplug verb.*# * [tck-testable tck-id-operational-behavior-commands-dcmd-metric-name]#[yellow-background]*[tck-id-operational-behavior-commands-dcmd-metric-name] A -DCMD message SHOULD include a metric name that was included in the associated DBIRTH message for the -Device.*# -** Sparkplug Edge Node Applications should be resilient to receiving metrics names that were not -included in the DBIRTH message. +DCMD message SHOULD identify a metric that was defined in the associated DMETA for the Device.*# +** Sparkplug Edge Node Applications should be resilient to receiving metrics that were not defined +in the DMETA. * [tck-testable tck-id-operational-behavior-commands-dcmd-metric-value]#[yellow-background]*[tck-id-operational-behavior-commands-dcmd-metric-value] A DCMD message MUST include a compatible metric value for the metric name that it is writing to.*# ** In other words, if the metric has a datatype of a boolean the value must be true or false. @@ -1793,7 +1799,7 @@ DCMD message MUST include a compatible metric value for the metric name that it ==== Typed Commands and Command Responses In addition to writing to output metrics, a Host Application can invoke strongly typed commands that -an Edge Node or Device includes as Command metrics in its BIRTH. A command is a callable function +an Edge Node or Device includes as Command metrics in its META. A command is a callable function with a typed signature: it declares the inputs it accepts and the outputs it returns. Invoking a command follows a correlated request/response pattern so that the result, including any returned data or error code, can be reliably matched back to the request that produced it. The structure of a @@ -1804,9 +1810,9 @@ includes the argument values and a correlation_id. The Edge Node executes the co Node publishes an NRESP or DRESP that echoes the correlation_id and carries the execution status and any results. -* [tck-testable tck-id-operational-behavior-command-definition-birth]#[yellow-background]*[tck-id-operational-behavior-command-definition-birth] An -Edge Node MUST include every command it supports as a Command metric in the NBIRTH (for Edge Node -level commands) or DBIRTH (for Device level commands).*# +* [tck-testable tck-id-operational-behavior-command-definition-meta]#[yellow-background]*[tck-id-operational-behavior-command-definition-meta] An +Edge Node MUST include every command it supports as a Command metric in the NMETA (for Edge Node +level commands) or DMETA (for Device level commands).*# * [tck-testable tck-id-operational-behavior-command-request-correlation]#[yellow-background]*[tck-id-operational-behavior-command-request-correlation] A Host Application that invokes a command MUST include a correlation_id in the Command object of the NCMD or DCMD message.*# @@ -1814,7 +1820,8 @@ NCMD or DCMD message.*# that each response can be unambiguously matched to its request. * [tck-testable tck-id-operational-behavior-command-request-arg-datatype]#[yellow-background]*[tck-id-operational-behavior-command-request-arg-datatype] A Host Application that invokes a command MUST supply argument values whose datatypes are compatible -with the argument definitions supplied in the corresponding BIRTH Command Definition.*# +with the argument definitions supplied in the corresponding Command Definition in the NMETA or +DMETA.*# * [tck-testable tck-id-operational-behavior-command-response-verb]#[yellow-background]*[tck-id-operational-behavior-command-response-verb] On receiving a command, an Edge Node MUST publish a command response using the NRESP Sparkplug verb for Edge Node level commands and the DRESP Sparkplug verb for Device level commands.*# @@ -1823,7 +1830,8 @@ command response MUST include the same correlation_id that was included in the c produced it.*# * [tck-testable tck-id-operational-behavior-command-response-results]#[yellow-background]*[tck-id-operational-behavior-command-response-results] On successful execution of a command that defines results, the command response MUST include a result -value for every result that was included in the corresponding BIRTH Command Definition.*# +value for every result that was included in the corresponding Command Definition in the NMETA or +DMETA.*# * [tck-testable tck-id-operational-behavior-command-error-status]#[yellow-background]*[tck-id-operational-behavior-command-error-status] If a command cannot be executed because it is unknown, its arguments are incompatible, or its execution fails, the Edge Node MUST publish a command response with a non-zero status code rather than silently diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc index 40193499..b8646058 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc @@ -245,10 +245,10 @@ message Payload { } message Command { - repeated Metric arguments = 1; // Input argument definitions (NBIRTH/DBIRTH) or supplied argument values (NCMD/DCMD) - omitted for commands that accept no inputs - repeated Metric results = 2; // Result/output argument definitions (NBIRTH/DBIRTH) or returned result values (NRESP/DRESP) - omitted for commands that return no outputs + repeated Metric arguments = 1; // Input argument definitions (NMETA/DMETA) or supplied argument values (NCMD/DCMD) - omitted for commands that accept no inputs + repeated Metric results = 2; // Result/output argument definitions (NMETA/DMETA) or returned result values (NRESP/DRESP) - omitted for commands that return no outputs string correlation_id = 3; // Set on an NCMD/DCMD request and echoed unchanged in the corresponding NRESP/DRESP response - Status status = 4; // Execution status - present in NRESP/DRESP responses, omitted in BIRTH definitions and CMD requests + Status status = 4; // Execution status - present in NRESP/DRESP responses, omitted in META definitions and CMD requests } // An array of scalar values of one type, used both by the array DataTypes and by @@ -313,8 +313,8 @@ message Payload { message Metric { - string name = 1; // Metric name - Required in BIRTH messages, optional in DATA messages if using aliases - uint64 alias = 2; // Metric alias - tied to name on BIRTH and included in all later DATA messages + string name = 1; // Metric name - Required wherever the metric is not identified by an alias assigned in the META + uint64 alias = 2; // Metric alias - tied to the name in the META and used in place of it wherever the metric is reported int64 timestamp = 3; // Metric value change time - the time this metric's value last changed - if omitted, the overall payload timestamp is assumed as the metric value change time DataType datatype = 4; // DataType of the metric/tag value uint32 quality = 5; // Quality code of the metric/tag value - severity in bits 30-31 @@ -326,7 +326,7 @@ message Payload { MetaData metadata = 11; // Metadata for the Metric PropertySet properties = 12; // Properties of the Metric TypedValue value = 13; - Command command = 14; // Command definition (BIRTH), invocation (CMD), or response (RESP) - present when datatype == Command instead of 'value' + Command command = 14; // Command definition (META), invocation (CMD), or response (RESP) - present when datatype == Command instead of 'value' MetricOperation operation = 15; // Only in NMMETA/DMMETA: ADD, UPDATE, or DELETE } @@ -753,7 +753,9 @@ data structures. For example, ‘outputs/A’ would be a metric with a unique id ‘outputs’ folder. There is no limit to the number of folders. However, across the infrastructure of MQTT publishers a defined folder should always remain a folder. ** [tck-testable tck-id-payloads-name-requirement]#[yellow-background]*[tck-id-payloads-name-requirement] The -name MUST be included with every metric unless aliases are being used.*# +name MUST be included with every metric in a full NMETA or DMETA and with every ADD metric in an +NMMETA or DMMETA. In any other message the name MUST be included unless an alias was assigned to +that metric in the NMETA or DMETA.*# ** All UTF-8 characters are allowed in the metric name. However, special characters including but not limited to the following SHOULD NOT be used: . , \ @ # $ % ^ & * ( ) [ ] { } | ! ` ~ : ; ' " < > ?. Many Sparkplug Host Applications may have issues handling these characters. In addition, leading and @@ -761,20 +763,25 @@ trailing whitespace characters and control characters such as NULL (0x00) SHOULD metric names. * *alias* -** This is an unsigned 64-bit integer representing an optional alias for a Sparkplug B payload. -Aliases are optional and not required. *If aliases are used, the following rules apply.* +** This is an unsigned 64-bit integer representing an optional alias for a metric. An alias is +assigned to a metric in the NMETA or DMETA that defines it, and that assignment is what binds the +alias to the metric name. Aliases are optional and are assigned per metric. *If an alias is +assigned, the following rules apply.* *** [tck-testable tck-id-payloads-alias-uniqueness]#[yellow-background]*[tck-id-payloads-alias-uniqueness] If -supplied in an NBIRTH or DBIRTH it MUST be a unique number across this Edge Node's entire set of +supplied in an NMETA or DMETA it MUST be a unique number across this Edge Node's entire set of metrics.*# -**** Non-normative comment: no two metrics for the same Edge Node can have the same alias. Upon being -defined in the NBIRTH or DBIRTH, subsequent messages can supply only the alias instead of the metric -friendly name to reduce overall message size. +**** Non-normative comment: no two metrics for the same Edge Node can have the same alias. Once +assigned in the NMETA or DMETA, the messages that report the metric supply only the alias instead of +the metric friendly name, which reduces overall message size. **** Non-normative comment: In effect, this means a metric alias, when used, must be unique across the entire Edge Node and all of its Sparkplug Devices. -*** [tck-testable tck-id-payloads-alias-birth-requirement]#[yellow-background]*[tck-id-payloads-alias-birth-requirement] NBIRTH -and DBIRTH messages MUST include both a metric name and alias.*# -*** [tck-testable tck-id-payloads-alias-data-cmd-requirement]#[yellow-background]*[tck-id-payloads-alias-data-cmd-requirement] NDATA, -DDATA, NCMD, and DCMD messages MUST only include an alias and the metric name MUST be excluded.*# +*** [tck-testable tck-id-payloads-alias-assigned]#[yellow-background]*[tck-id-payloads-alias-assigned] If +an alias was assigned to a metric in the NMETA or DMETA, any message other than an NMETA, NMMETA, +DMETA, or DMMETA that reports or targets that metric MUST identify it by its alias and MUST omit its +metric name.*# +*** [tck-testable tck-id-payloads-alias-not-assigned]#[yellow-background]*[tck-id-payloads-alias-not-assigned] If +no alias was assigned to a metric in the NMETA or DMETA, any message other than an NMETA, NMMETA, +DMETA, or DMMETA that reports or targets that metric MUST identify it by its metric name.*# * *timestamp* ** This is the timestamp in the form of a signed 64-bit integer representing the number of nanoseconds since epoch (Jan 1, 1970). @@ -817,8 +824,11 @@ link:#payloads_p_datatypes[valid Sparkplug Data Types].*# ** [tck-testable tck-id-payloads-metric-datatype-not-propertyset]#[yellow-background]*[tck-id-payloads-metric-datatype-not-propertyset] The 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.*# +** Non-normative comment: a metric's datatype is carried in the messages that convey metric +definitions. For a full definition set that is the link:#payloads_desc_nmeta[Payload (NMETA)] +section for an Edge Node and the link:#payloads_desc_dmeta[Payload (DMETA)] section for a +Device; for an incremental change it is the link:#payloads_p_nmmeta[NMMETA and DMMETA] section +in this chapter. ** [tck-testable tck-id-payloads-metric-datatype-not-req]#[yellow-background]*[tck-id-payloads-metric-datatype-not-req] The Metric's own datatype field MUST NOT be included with a metric in NDATA or DDATA messages in the Google Protocol Buffers encoding. A metric's datatype is established by the message that defines @@ -1581,10 +1591,12 @@ datatype is _Command_. The same Command object is used in three roles which are which fields are populated: * *Command Definition* -** This is the declaration of a command's typed signature and is included in a BIRTH message, +** This is the declaration of a command's typed signature and is included in a META message, analogous to how a Template Definition supplies the structure of a complex datatype. -*** [tck-testable tck-id-payloads-command-definition-birth]#[yellow-background]*[tck-id-payloads-command-definition-birth] A -Command Definition MUST only be included in NBIRTH or DBIRTH messages.*# +*** [tck-testable tck-id-payloads-command-definition-meta]#[yellow-background]*[tck-id-payloads-command-definition-meta] A +Command Definition MUST only be included in NMETA, NMMETA, DMETA, or DMMETA messages, as the +link:#payloads_desc_nmeta[Payload (NMETA)] and link:#payloads_desc_dmeta[Payload (DMETA)] sections +require.*# *** [tck-testable tck-id-payloads-command-definition-datatype]#[yellow-background]*[tck-id-payloads-command-definition-datatype] A Metric representing a Command MUST have its datatype set to Command.*# *** [tck-testable tck-id-payloads-command-definition-arguments]#[yellow-background]*[tck-id-payloads-command-definition-arguments] If @@ -1602,7 +1614,8 @@ Command Definition MUST omit the correlation_id and status fields.*# ** This is an invocation of a previously defined command and is carried in an NCMD or DCMD message. *** [tck-testable tck-id-payloads-command-request-arguments]#[yellow-background]*[tck-id-payloads-command-request-arguments] A Command Request MUST supply argument values that are datatype compatible with the corresponding -Command Definition included in the immediately previous BIRTH for the Edge Node or Device.*# +Command Definition carried in the NMETA or DMETA that the Edge Node or Device currently +references.*# *** [tck-testable tck-id-payloads-command-request-correlation]#[yellow-background]*[tck-id-payloads-command-request-correlation] A Command Request MUST include a correlation_id.*# *** [tck-testable tck-id-payloads-command-request-no-status]#[yellow-background]*[tck-id-payloads-command-request-no-status] A @@ -1947,6 +1960,12 @@ definition, or to any Template definition MUST result in a different definition consumer MUST be able to recompute the definition identifier from the assembled metadata and obtain a value identical to the one published by the Edge Node.*# +The sections that follow describe the payload of each message type. The per-message requirements +themselves are stated once, in the 'Payload (X)' section of the +link:#topics[Topics] chapter; where a section below restates nothing, it refers to that section +rather than repeating it. What remains here describes the payload components a message is built +from. + [[payloads_p_nmeta]] ==== NMETA @@ -1963,9 +1982,8 @@ messages MUST include a payload timestamp that denotes the time at which the mes * [tck-testable tck-id-payloads-nmeta-defid]#[yellow-background]*[tck-id-payloads-nmeta-defid] NMETA messages MUST include a definition_id equal to the content hash of the metric definitions they contain.*# -* [tck-testable tck-id-payloads-nmeta-metric-defs]#[yellow-background]*[tck-id-payloads-nmeta-metric-defs] For -each metric a full NMETA MUST include the metric name and datatype. The metric alias, properties, and -metadata MAY also be included. Aliases are optional.*# +* The metric definitions a full NMETA carries are as described in the +link:#payloads_desc_nmeta[Payload (NMETA)] section. * [tck-testable tck-id-payloads-nmeta-cmd-metrics]#[yellow-background]*[tck-id-payloads-nmeta-cmd-metrics] A full NMETA MUST include the definition of every Command-datatype metric the Edge Node exposes, including its command argument and result definitions, so that Host Applications can invoke it via @@ -1990,9 +2008,8 @@ messages MUST include a payload timestamp that denotes the time at which the mes * [tck-testable tck-id-payloads-dmeta-defid]#[yellow-background]*[tck-id-payloads-dmeta-defid] DMETA messages MUST include a definition_id equal to the content hash of the metric definitions they contain.*# -* [tck-testable tck-id-payloads-dmeta-metric-defs]#[yellow-background]*[tck-id-payloads-dmeta-metric-defs] For -each metric a full DMETA MUST include the metric name and datatype. The metric alias, properties, and -metadata MAY also be included. Aliases are optional.*# +* The metric definitions a full DMETA carries are as described in the +link:#payloads_desc_dmeta[Payload (DMETA)] section. * [tck-testable tck-id-payloads-dmeta-cmd-metrics]#[yellow-background]*[tck-id-payloads-dmeta-cmd-metrics] A full DMETA MUST include the definition of every Command-datatype metric the Device exposes, including its command argument and result definitions, so that Host Applications can invoke it via DCMD and @@ -2059,10 +2076,8 @@ Edge Node Descriptor in any Sparkplug infrastructure MUST be unique in the syste * [tck-testable tck-id-payloads-nbirth-defid]#[yellow-background]*[tck-id-payloads-nbirth-defid] Every NBIRTH message MUST include a definition_id equal to the content hash of the NMETA that describes this Edge Node, and MUST report values only for metrics defined in that NMETA.*# -* [tck-testable tck-id-payloads-nbirth-metrics]#[yellow-background]*[tck-id-payloads-nbirth-metrics] Each -metric in the NBIRTH MUST include its current value and MUST be identified either by its alias, if an -alias was assigned to it in the referenced NMETA, or otherwise by its metric name. The NBIRTH MUST -NOT be used to convey metric datatype, properties, or metadata.*# +* The metrics an NBIRTH carries, how each one is identified, and the metric structure it does not +convey, are as described in the link:#payloads_desc_nbirth[Payload (NBIRTH)] section. * [tck-testable tck-id-payloads-nbirth-seq]#[yellow-background]*[tck-id-payloads-nbirth-seq] Every NBIRTH message MUST include a sequence number. If no NMETA is published in the BIRTH sequence, the NBIRTH is the first message and its sequence number MUST be 0. If an NMETA is published (sequence @@ -2177,10 +2192,8 @@ Edge Node Descriptor in any Sparkplug infrastructure MUST be unique in the syste * [tck-testable tck-id-payloads-nrebirth-defid]#[yellow-background]*[tck-id-payloads-nrebirth-defid] Every NREBIRTH message MUST include a definition_id equal to the content hash of the NMETA that describes this Edge Node, and MUST report values only for metrics defined in that NMETA.*# -* [tck-testable tck-id-payloads-nrebirth-metrics]#[yellow-background]*[tck-id-payloads-nrebirth-metrics] Each -metric in the NREBIRTH MUST include its current value and MUST be identified either by its alias, if an -alias was assigned to it in the referenced NMETA, or otherwise by its metric name. The NREBIRTH MUST -NOT be used to convey metric datatype, properties, or metadata.*# +* The metrics an NREBIRTH carries, how each one is identified, and the metric structure it does not +convey, are as described in the link:#payloads_desc_nrebirth[Payload (NREBIRTH)] section. * [tck-testable tck-id-payloads-nrebirth-seq-1]#[yellow-background]*[tck-id-payloads-nrebirth-seq-1] Every NREBIRTH message MUST include a sequence number and it MUST have a value between 0 and 9223372036854775807 (inclusive).*# @@ -2297,10 +2310,8 @@ published.*# * [tck-testable tck-id-payloads-dbirth-defid]#[yellow-background]*[tck-id-payloads-dbirth-defid] Every DBIRTH message MUST include a definition_id equal to the content hash of the DMETA that describes this Device, and MUST report values only for metrics defined in that DMETA.*# -* [tck-testable tck-id-payloads-dbirth-metrics]#[yellow-background]*[tck-id-payloads-dbirth-metrics] Each -metric in the DBIRTH MUST include its current value and MUST be identified either by its alias, if an -alias was assigned to it in the referenced DMETA, or otherwise by its metric name. The DBIRTH MUST -NOT be used to convey metric datatype, properties, or metadata.*# +* The metrics a DBIRTH carries, how each one is identified, and the metric structure it does not +convey, are as described in the link:#payloads_desc_dbirth[Payload (DBIRTH)] section. * [tck-testable tck-id-payloads-dbirth-seq]#[yellow-background]*[tck-id-payloads-dbirth-seq] Every DBIRTH message MUST include a sequence number.*# * [tck-testable tck-id-payloads-dbirth-seq-inc]#[yellow-background]*[tck-id-payloads-dbirth-seq-inc] Every @@ -2400,10 +2411,8 @@ published.*# * [tck-testable tck-id-payloads-drebirth-defid]#[yellow-background]*[tck-id-payloads-drebirth-defid] Every DREBIRTH message MUST include a definition_id equal to the content hash of the DMETA that describes this Device, and MUST report values only for metrics defined in that DMETA.*# -* [tck-testable tck-id-payloads-drebirth-metrics]#[yellow-background]*[tck-id-payloads-drebirth-metrics] Each -metric in the DREBIRTH MUST include its current value and MUST be identified either by its alias, if an -alias was assigned to it in the referenced DMETA, or otherwise by its metric name. The DREBIRTH MUST -NOT be used to convey metric datatype, properties, or metadata.*# +* The metrics a DREBIRTH carries, how each one is identified, and the metric structure it does not +convey, are as described in the link:#payloads_desc_drebirth[Payload (DREBIRTH)] section. * [tck-testable tck-id-payloads-drebirth-seq]#[yellow-background]*[tck-id-payloads-drebirth-seq] Every DREBIRTH message MUST include a sequence number.*# * [tck-testable tck-id-payloads-drebirth-seq-inc]#[yellow-background]*[tck-id-payloads-drebirth-seq-inc] Every @@ -2726,7 +2735,7 @@ The NCMD payload tells the Edge Node to write true to the 'DIGITAL_OUT_1' metric DIGITAL_OUT_1 alue should turn true and result in a NDATA message back to the MQTT Server after the DIGITAL_OUT_1 is successfully set to true. -An NCMD message MAY also invoke a strongly typed Command that was included in the NBIRTH. In this +An NCMD message MAY also invoke a strongly typed Command that was included in the NMETA. In this case the metric datatype is Command and the metric carries a Command object with the supplied argument values and a correlation_id. See the link:#payloads_p_command[Command Section] for the full Command Request rules. @@ -2826,7 +2835,7 @@ The DCMD payload tells the Edge Node to start the attached Filler's motor and se As a result, the Filler should begin running and result in a DDATA message back to the MQTT Server after the motor is successfully started. -A DCMD message MAY also invoke a strongly typed Command that was supplied in the DBIRTH, following +A DCMD message MAY also invoke a strongly typed Command that was supplied in the DMETA, following the same Command Request rules as NCMD. See the link:#payloads_p_command[Command Section]. * [tck-testable tck-id-payloads-dcmd-command-correlation]#[yellow-background]*[tck-id-payloads-dcmd-command-correlation] A diff --git a/tck/src/main/java/org/eclipse/sparkplug/tck/test/common/Utils.java b/tck/src/main/java/org/eclipse/sparkplug/tck/test/common/Utils.java index 79962c91..7397bbae 100644 --- a/tck/src/main/java/org/eclipse/sparkplug/tck/test/common/Utils.java +++ b/tck/src/main/java/org/eclipse/sparkplug/tck/test/common/Utils.java @@ -293,9 +293,14 @@ public static boolean hasValue(Metric m) { // A null value is valid return true; } + if (m.hasCommand()) { + // A Command metric's payload is the command field. The Metric datatype is not consulted, + // because a message that conveys no metric structure carries no Metric datatype to read. + return true; + } if (m.hasDatatype() && m.getDatatype() == DataType.Command) { - // A Command metric's payload is the command field - return m.hasCommand(); + // Declared a Command but carries no command field + return false; } return m.hasValue() && m.getValue().getValueCase() != Payload.TypedValue.ValueCase.VALUE_NOT_SET; 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 82755d77..c859db6b 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 @@ -21,7 +21,7 @@ import static org.eclipse.sparkplug.tck.test.common.Constants.TOPIC_PATH_NDATA; import static org.eclipse.sparkplug.tck.test.common.Constants.TOPIC_PATH_NDEATH; import static org.eclipse.sparkplug.tck.test.common.Constants.TOPIC_ROOT_SP_BV_1_0; -import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT; +import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_ALIAS_NOT_ASSIGNED; import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ; import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_METRIC_DATATYPE_VALUE; import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_METRIC_DATATYPE_VALUE_TYPE; @@ -48,7 +48,7 @@ import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_TEMPLATE_REF_DEFINITION; import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_TEMPLATE_REF_INSTANCE; import static org.eclipse.sparkplug.tck.test.common.Requirements.ID_PAYLOADS_TEMPLATE_VERSION; -import static org.eclipse.sparkplug.tck.test.common.Requirements.PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT; +import static org.eclipse.sparkplug.tck.test.common.Requirements.PAYLOADS_ALIAS_NOT_ASSIGNED; import static org.eclipse.sparkplug.tck.test.common.Requirements.PAYLOADS_METRIC_DATATYPE_NOT_REQ; import static org.eclipse.sparkplug.tck.test.common.Requirements.PAYLOADS_METRIC_DATATYPE_VALUE; import static org.eclipse.sparkplug.tck.test.common.Requirements.PAYLOADS_METRIC_DATATYPE_VALUE_TYPE; @@ -124,7 +124,7 @@ public class SendComplexDataTest extends TCKTest { ID_PAYLOADS_METRIC_DATATYPE_VALUE_TYPE, ID_PAYLOADS_METRIC_DATATYPE_VALUE, ID_PAYLOADS_PROPERTYSET_KEYS_ARRAY_SIZE, ID_PAYLOADS_PROPERTYSET_VALUES_ARRAY_SIZE, ID_PAYLOADS_METRIC_PROPERTYVALUE_TYPE_TYPE, ID_PAYLOADS_METRIC_PROPERTYVALUE_TYPE_VALUE, - ID_PAYLOADS_METRIC_PROPERTYVALUE_TYPE_REQ, ID_PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT, + ID_PAYLOADS_METRIC_PROPERTYVALUE_TYPE_REQ, ID_PAYLOADS_ALIAS_NOT_ASSIGNED, ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ, ID_PAYLOADS_NAME_BIRTH_DATA_REQUIREMENT, ID_PAYLOADS_NAME_REQUIREMENT, ID_PAYLOADS_TEMPLATE_IS_DEFINITION, ID_PAYLOADS_TEMPLATE_DEFINITION_IS_DEFINITION, ID_PAYLOADS_TEMPLATE_INSTANCE_IS_DEFINITION, ID_PAYLOADS_TEMPLATE_DEFINITION_REF, @@ -461,22 +461,26 @@ public void checkPropertiesValidType(final @NotNull PublishPacket packet, String @SpecAssertion( section = Sections.PAYLOADS_P_METRIC, - id = ID_PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT) + id = ID_PAYLOADS_ALIAS_NOT_ASSIGNED) public void checkAliasInData(final @NotNull PayloadOrBuilder sparkplugPayload, String topic) { logger.debug( - "Check Req: NDATA, DDATA, NCMD, and DCMD messages MUST only include an alias and the metric name MUST be excluded."); + "Check Req: a metric is identified by its alias if the META assigned one, otherwise by its name."); - boolean isValid = false; + boolean isValid = true; if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA) || topic.contains(TOPIC_PATH_NCMD) || topic.contains(TOPIC_PATH_DCMD)) { + // Every metric must carry exactly one identifier. Which one is correct depends on + // whether the META assigned an alias, which this test cannot see, so this is the + // closest check available until the TCK handles the META messages. for (Metric m : sparkplugPayload.getContent().getMetricsList()) { - if (!m.getIsNull() && ((m.hasAlias() && (!m.hasName() || m.getName().length() == 0)) - || (!m.hasAlias() && (m.hasName() || m.getName().length() > 0)))) - isValid = true; - break; + final boolean hasName = m.hasName() && m.getName().length() > 0; + if (hasName == m.hasAlias()) { + isValid = false; + break; + } } - testResults.put(ID_PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT, - setResult(isValid, PAYLOADS_ALIAS_DATA_CMD_REQUIREMENT)); + Utils.setResultIfNotFail(testResults, isValid, ID_PAYLOADS_ALIAS_NOT_ASSIGNED, + PAYLOADS_ALIAS_NOT_ASSIGNED); } } diff --git a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SessionEstablishmentTest.java b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SessionEstablishmentTest.java index 3193cc89..5409e49a 100644 --- a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SessionEstablishmentTest.java +++ b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SessionEstablishmentTest.java @@ -108,7 +108,7 @@ public class SessionEstablishmentTest extends TCKTest { ID_MESSAGE_FLOW_DEVICE_BIRTH_PUBLISH_DBIRTH_MATCH_EDGE_NODE_TOPIC, ID_PAYLOADS_NBIRTH_BDSEQ_REPEAT, ID_PAYLOADS_NDATA_ORDER, ID_PAYLOADS_DDATA_ORDER, ID_PAYLOADS_ALIAS_UNIQUENESS, ID_TOPICS_NBIRTH_TOPIC, ID_TOPICS_DBIRTH_TOPIC, ID_CASE_SENSITIVITY_METRIC_NAMES, ID_PAYLOADS_NAME_BIRTH_DATA_REQUIREMENT, - ID_PAYLOADS_ALIAS_BIRTH_REQUIREMENT, ID_PAYLOADS_METRIC_DATATYPE_REQ); + ID_PAYLOADS_ALIAS_ASSIGNED, ID_TOPICS_NBIRTH_NO_METADATA, ID_TOPICS_DBIRTH_NO_METADATA); private final @NotNull TCK theTCK; private @NotNull Utilities utilities = null; @@ -394,20 +394,22 @@ public void checkPayloadsNameInDataRequirement(final @NotNull PayloadOrBuilder s @SpecAssertion( section = Sections.PAYLOADS_P_METRIC, - id = ID_PAYLOADS_ALIAS_BIRTH_REQUIREMENT) + id = ID_PAYLOADS_ALIAS_ASSIGNED) @SpecAssertion( section = Sections.PAYLOADS_P_METRIC, id = ID_PAYLOADS_ALIAS_UNIQUENESS) public void checkPayloadsAliasAndNameRequirement(final @NotNull PayloadOrBuilder sparkplugPayload) { logger.debug("Check Req: " - + "if alias is included, NBIRTH and DBIRTH messages MUST include both a metric name and alias."); + + "a metric is identified by its alias if the META assigned one, otherwise by its name."); boolean isValid = true; List metrics = sparkplugPayload.getContent().getMetricsList(); ListIterator metricIterator = metrics.listIterator(); while (metricIterator.hasNext()) { Metric current = metricIterator.next(); - if (current.hasAlias() && !current.hasName()) { + // Exactly one identifier: the alias when the META assigned one, otherwise the name. + // Carrying both, or neither, identifies the metric ambiguously. + if (current.hasAlias() == current.hasName()) { isValid = false; break; } @@ -418,7 +420,7 @@ public void checkPayloadsAliasAndNameRequirement(final @NotNull PayloadOrBuilder aliases.add(alias); } } - testResults.put(ID_PAYLOADS_ALIAS_BIRTH_REQUIREMENT, setResult(isValid, PAYLOADS_ALIAS_BIRTH_REQUIREMENT)); + testResults.put(ID_PAYLOADS_ALIAS_ASSIGNED, setResult(isValid, PAYLOADS_ALIAS_ASSIGNED)); } @SpecAssertion( @@ -537,8 +539,8 @@ public Optional checkWillMessage(final @NotNull ConnectPacket section = Sections.PAYLOADS_P_NDEATH, id = ID_PAYLOADS_NDEATH_BDSEQ) @SpecAssertion( - section = Sections.PAYLOADS_P_METRIC, - id = ID_PAYLOADS_METRIC_DATATYPE_REQ) + section = Sections.PAYLOADS_DESC_NBIRTH, + id = ID_TOPICS_NBIRTH_NO_METADATA) @SpecAssertion( section = Sections.OPERATIONAL_BEHAVIOR_DATA_PUBLISH, id = ID_OPERATIONAL_BEHAVIOR_DATA_PUBLISH_NBIRTH_VALUES) @@ -648,7 +650,9 @@ public void checkNBirth(final @NotNull PublishPacket packet) { metric_names.add(name); } - if (!m.hasName() || !Utils.hasValue(m) || !m.hasDatatype()) { + // Identified by alias when the META assigned one, otherwise by name, so either + // identifier satisfies this; requiring the name would fail every aliased Edge Node. + if (!(m.hasAlias() || m.hasName()) || !Utils.hasValue(m)) { testResults.put(ID_TOPICS_NBIRTH_METRICS, setResult(false, TOPICS_NBIRTH_METRICS)); } else if (testResults.get(ID_TOPICS_NBIRTH_METRICS) == null) { testResults.put(ID_TOPICS_NBIRTH_METRICS, setResult(true, TOPICS_NBIRTH_METRICS)); @@ -673,14 +677,12 @@ public void checkNBirth(final @NotNull PublishPacket packet) { testResults.put(ID_PAYLOADS_NBIRTH_BDSEQ_REPEAT, setResult(birthBdSeq == deathBdSeq, PAYLOADS_NBIRTH_BDSEQ_REPEAT)); - if (testResults.get(ID_PAYLOADS_METRIC_DATATYPE_REQ) == null - || testResults.get(ID_PAYLOADS_METRIC_DATATYPE_REQ).contains(Constants.PASS)) { - logger.debug( - "Check req: The datatype MUST be included with each metric definition in NBIRTH and DBIRTH messages."); - int hasDataTypeCnt = countDataType(metrics); - testResults.put(ID_PAYLOADS_METRIC_DATATYPE_REQ, - setResult(hasDataTypeCnt == metrics.size(), PAYLOADS_METRIC_DATATYPE_REQ)); - } + // A metric's datatype is conveyed in the NMETA and NMMETA, not the NBIRTH, so an NBIRTH + // carrying one violates topics-nbirth-no-metadata. + logger.debug( + "Check req: The NBIRTH MUST NOT be used to convey metric datatype, properties, or metadata."); + Utils.setResultIfNotFail(testResults, countMetadata(metrics) == 0, ID_TOPICS_NBIRTH_NO_METADATA, + TOPICS_NBIRTH_NO_METADATA); logger.debug("Check Req: NBIRTH bdSeq must match bdSeq provided in Will Message payload of connect packet"); testResults.put(ID_PAYLOADS_NBIRTH_BDSEQ, setResult(birthBdSeq != -1, PAYLOADS_NBIRTH_BDSEQ)); testResults.put(ID_TOPICS_NBIRTH_BDSEQ_INCLUDED, setResult(birthBdSeq != -1, TOPICS_NBIRTH_BDSEQ_INCLUDED)); @@ -725,6 +727,9 @@ public void checkNBirth(final @NotNull PublishPacket packet) { @SpecAssertion( section = Sections.PAYLOADS_DESC_DBIRTH, id = ID_TOPICS_DBIRTH_METRICS) + @SpecAssertion( + section = Sections.PAYLOADS_DESC_DBIRTH, + id = ID_TOPICS_DBIRTH_NO_METADATA) @SpecAssertion( section = Sections.OPERATIONAL_BEHAVIOR_DATA_PUBLISH, id = ID_OPERATIONAL_BEHAVIOR_DATA_PUBLISH_DBIRTH_VALUES) @@ -872,15 +877,13 @@ public void checkDBirth(final @NotNull PublishPacket packet) { } } - if (testResults.get(ID_PAYLOADS_METRIC_DATATYPE_REQ) == null - || testResults.get(ID_PAYLOADS_METRIC_DATATYPE_REQ).contains(PASS)) { - logger.debug( - "Check req: The datatype MUST be included with each metric definition in NBIRTH and DBIRTH messages."); - List metrics = sparkplugPayload.getContent().getMetricsList(); - int hasDataTypeCnt = countDataType(metrics); - testResults.put(ID_PAYLOADS_METRIC_DATATYPE_REQ, - setResult(hasDataTypeCnt == metrics.size(), PAYLOADS_METRIC_DATATYPE_REQ)); - } + // A metric's datatype is conveyed in the DMETA and DMMETA, not the DBIRTH, so a DBIRTH + // carrying one violates topics-dbirth-no-metadata. + logger.debug( + "Check req: The DBIRTH MUST NOT be used to convey metric datatype, properties, or metadata."); + Utils.setResultIfNotFail(testResults, + countMetadata(sparkplugPayload.getContent().getMetricsList()) == 0, + ID_TOPICS_DBIRTH_NO_METADATA, TOPICS_DBIRTH_NO_METADATA); checkPayloadsNameInDataRequirement(sparkplugPayload); checkPayloadsAliasAndNameRequirement(sparkplugPayload); @@ -888,7 +891,9 @@ public void checkDBirth(final @NotNull PublishPacket packet) { Set metric_names = new HashSet(); List metrics = sparkplugPayload.getContent().getMetricsList(); for (Metric m : metrics) { - if (!m.hasName() || !Utils.hasValue(m) || !m.hasDatatype()) { + // Identified by alias when the META assigned one, otherwise by name, so either + // identifier satisfies this; requiring the name would fail every aliased Edge Node. + if (!(m.hasAlias() || m.hasName()) || !Utils.hasValue(m)) { testResults.put(ID_TOPICS_DBIRTH_METRICS, setResult(false, TOPICS_DBIRTH_METRICS)); } else if (testResults.get(ID_TOPICS_DBIRTH_METRICS) == null) { testResults.put(ID_TOPICS_DBIRTH_METRICS, setResult(true, TOPICS_DBIRTH_METRICS)); @@ -936,15 +941,19 @@ public void checkDBirth(final @NotNull PublishPacket packet) { } } - private int countDataType(List metrics) { + /** + * Counts the metrics carrying metric structure, which a BIRTH must not convey. The rule names + * datatype, properties and metadata, so all three are counted rather than the datatype alone. + */ + private int countMetadata(List metrics) { if (metrics != null) { - final AtomicInteger hasDataTypeCnt = new AtomicInteger(); + final AtomicInteger metadataCnt = new AtomicInteger(); metrics.forEach(m -> { - if (m.hasDatatype()) { - hasDataTypeCnt.incrementAndGet(); + if (m.hasDatatype() || m.hasProperties() || m.hasMetadata()) { + metadataCnt.incrementAndGet(); } }); - return hasDataTypeCnt.get(); + return metadataCnt.get(); } return 0; }