diff --git a/cloudevents/extensions/README.md b/cloudevents/extensions/README.md index 0b66ea88d..bb8fb9676 100644 --- a/cloudevents/extensions/README.md +++ b/cloudevents/extensions/README.md @@ -45,11 +45,14 @@ for more information. - [Data Classification](data-classification.md) - [Dataref (Claim Check Pattern)](dataref.md) - [Deprecation](deprecation.md) +- [Descriptor Reference](descriptor.md) - [Distributed Tracing](distributed-tracing.md) - [Expiry Time](expirytime.md) - [OPC UA](opcua.md) +- [OpenUSD](openusd.md) - [Partitioning](partitioning.md) - [Recorded Time](recordedtime.md) - [Sampling](sampledrate.md) - [Sequence](sequence.md) - [Severity](severity.md) +- [Web of Things](wot.md) (Core attribute mapping profile) diff --git a/cloudevents/extensions/descriptor.md b/cloudevents/extensions/descriptor.md new file mode 100644 index 000000000..0b50a3593 --- /dev/null +++ b/cloudevents/extensions/descriptor.md @@ -0,0 +1,139 @@ +# Descriptor Reference + +The `describedby` attribute lets a Producer link to information shared by +several events instead of repeating it in each event. An HTTP `GET` of the +URL returns a JSON object called a Descriptor document. + +The [examples](#examples) show Descriptor documents for pump telemetry +and asset identifiers. + +## Notational Conventions + +As with the main [CloudEvents specification](../spec.md), the key words "MUST", +"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", +"RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as +described in [RFC 2119](https://tools.ietf.org/html/rfc2119). + +However, the scope of these key words is limited to when this extension is +used. An attribute marked as "REQUIRED" needs to be included when the event +uses this extension. + +## Attributes + +### describedby + +- Type: `URI` +- Description: The URL of the Descriptor document for this event. +- Constraints: + - The Producer MUST include `describedby` when using this extension. + - The Producer MUST supply a non-empty absolute HTTP(S) URL without a + fragment. + - The URL MUST support retrieval of the Descriptor document by HTTP `GET`. + A successful response serving the Descriptor document MUST use + `Content-Type: application/json`. + +The hosting implementation is a Publisher choice. A static HTTP server or an +[xRegistry](https://xregistry.io) server can serve the document. + +## Descriptor document + +A Descriptor document MUST be a JSON object. Its top-level property names +MUST be unique within the object. Extensions MAY reserve top-level property +names. An extension that reserves a name specifies the property's value +type and schema, including any nested structure, and defines any selection +rules. The schema can allow any JSON type. For example, an extension that +reserves `age` and defines it as an integer can use `"age": 18`. + +Consumers SHOULD ignore properties they do not recognize, including +extension members within a profile's objects, unless the applicable +profile or deployment requires rejection. Each profile defines which +inputs it needs and how to handle unavailable or invalid inputs. + +For a published Descriptor version, the Publisher MUST keep its properties +and linked representations stable for the intended use and replay and MUST +publish a new version when those inputs change. + +## Descriptor properties + +| Property | Definition | +| --- | --- | +| `schema` | [Payload schema](#schema) | +| `endpoint` | [Endpoint Group](#endpoint) | +| `identifiers` | [Entity aliases](#identifiers) | +| `opcua` | [OPC UA writer metadata](opcua.md#descriptor-property) | +| `thingdescription`, `thingmodel` | [Web of Things properties](wot.md#wot-descriptor-properties) | +| `usdasset` | [OpenUSD asset selection](openusd.md#asset-selection) | + +### Schema + +`schema` is an object. Its REQUIRED `url` MUST be an absolute, +fragment-free HTTP(S) URL of a schema document for the event's `data`. +The OPTIONAL `format` identifies the linked schema's format. When present, +it MUST be a non-empty, case-insensitive string and MUST use the +[xRegistry format identifier][Schema Formats] for formats defined there. +Examples include `JsonSchema/draft-07`, `Avro/1.9`, and `XSD/1.1`. +The rules for the event stream or the protocol binding define how to use +`schema` and `dataschema`. + +### Endpoint + +`endpoint` is an object. Its REQUIRED `url` MUST be an absolute, +fragment-free HTTP(S) URL of an xRegistry [Endpoint Group][Endpoint Group]'s +metadata. + +### Identifiers + +`identifiers` is a non-empty array of aliases for the described entity. +Each alias MUST be an object with exactly two string members: + +| Member | Meaning | +| --- | --- | +| `scheme` | An [absolute URI][Absolute URI] identifying the identifier scheme. | +| `value` | The identifier in that scheme, represented as a string. | + +Two identifiers match only if both strings match exactly. Consumers MUST +NOT normalize either string, including by changing case or percent-encoding. + +## Examples + +### Pump telemetry + +The Descriptor points to the pump's Thing Description and the schema for +the reported data. `opcua` supplies the publisher and writer +identifiers for a stream that uses the combined WoT and OPC UA mapping. + +```json +{ + "thingdescription": { + "pump7": { + "url": "https://devices.example/pump7/td.json", + "affordanceselector": "/properties/processData" + } + }, + "schema": { + "url": "https://schemas.example/pump-process-data/versions/3" + }, + "opcua": { + "opcuapublisherid": "UInt16:12", + "opcuadatasetwriterid": 17 + } +} +``` + +### Asset identifiers + +The Descriptor for Pump 7 gives its serial number and site asset tag. The +serial number retains its leading zeros. + +```json +{ + "identifiers": [ + { "scheme": "https://manufacturer.example/id/serial", "value": "000147" }, + { "scheme": "https://site.example/id/asset-tag", "value": "Pump-7" } + ] +} +``` + +[Endpoint Group]: https://github.com/xregistry/spec/blob/main/endpoint/spec.md +[Absolute URI]: https://www.rfc-editor.org/rfc/rfc3986#section-4.3 +[Schema Formats]: https://github.com/xregistry/spec/blob/main/schema/spec.md#43-schema-formats diff --git a/cloudevents/extensions/opcua.md b/cloudevents/extensions/opcua.md index 95954fb23..bf922e813 100644 --- a/cloudevents/extensions/opcua.md +++ b/cloudevents/extensions/opcua.md @@ -1,11 +1,31 @@ # OPC UA -This extension defines the mapping of [OPC UA](https://reference.opcfoundation.org/Core/Part1/v105/docs/) -[PubSub](https://reference.opcfoundation.org/Core/Part14/v105/docs/) dataset to -CloudEvents to allow seamless routing of OPC UA dataset messages via different -protocols, it therefore provides a recommendation to map known REQUIRED and -OPTIONAL attributes using other extensions as well as defines its own extension -attributes. +This extension lets a Consumer route +[OPC UA](https://reference.opcfoundation.org/Core/Part1/v105/docs/) +[PubSub](https://reference.opcfoundation.org/Core/Part14/v105/docs/) +messages using CloudEvents attributes. A DataSetWriter publishes a +DataSetMessage that carries measurements or an event. The +[HTTP keyframe example](#http-keyframe) shows how `type` identifies a +keyframe and `subject` identifies its writer. + +When Consumers need metadata shared by a stream, the Producer can use +[`describedby`](descriptor.md#describedby) to point to a Descriptor. This +**Processing Descriptor** supplies shared inputs. For example, the +`opcua` object can contain Publisher and DataSetWriter identifiers: + +```json +{ + "opcua": { + "opcuapublisherid": "UInt16:12", + "opcuadatasetwriterid": 17 + } +} +``` + +Values such as the event ID and time stay with each event. The +[OPC UA Descriptor profile](#opc-ua-descriptor-profile) defines the shared +fields. The [combined WoT mapping](#wot-mapping) covers events that also +use the Web of Things (WoT) profile. ## Notational Conventions @@ -14,89 +34,124 @@ As with the main [CloudEvents specification](../spec.md), the key words "MUST", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). -However, the scope of these key words is limited to when this extension is used. -For example, an attribute being marked as "REQUIRED" does not mean it needs to -be in all CloudEvents, rather it needs to be included only when this extension -is being used. +However, the scope of these key words is limited to when this extension is +used. For example, an attribute marked as "REQUIRED" needs to be included +when the event uses this extension and meets the stated conditions. ## Mapping of REQUIRED Attributes ### id -MUST map to [Network Message +The Producer MUST map `id` to [Network Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.3#Table163) field `MessageId`. ### source -MUST either map to [Application +An OPC UA Producer MAY identify the server using its [Application Description](https://reference.opcfoundation.org/Core/Part4/v104/docs/7.1) field -`applicationUri` of the OPC UA server or to a customer configured identifier -like a unified namespace path. +`applicationUri` or a customer-configured identifier such as a unified namespace +path. A Producer MAY include the query parameters defined in +[Publisher and Writer Metadata](#publisher-and-writer-metadata), subject to +that section's requirements for the combined WoT mapping. ### type -MUST map to [Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) -field `MessageType`. +An OPC UA Producer MAY map `type` to the +[Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) +field `MessageType`. For data and event messages without the WoT profile, +the Producer MUST use that native value as `type` when the DataSetMessage +`MessageType` field is absent from `data`. For a retained header, the +native content mask determines whether it carries that field. + +A Producer using the WoT profile MUST instead follow its semantic +event-type rules and the [opcuamessagetype](#opcuamessagetype) requirements +for conveying the native message type. The [WoT mapping section](#wot-mapping) +specifies the combined mapping. ## Mapping of OPTIONAL Attributes ### datacontenttype -MUST be `application/json` for OPC UA PubSub JSON payload and MAY be appended with -`+gzip` when the payload is gzip compressed. +The Producer MUST set `datacontenttype` to `application/json` for OPC UA +PubSub JSON payloads and MAY append `+gzip` when the payload is gzip +compressed. ### dataschema -OPC UA provides type information as part of PubSub metadata messages, for non -OPC UA consumers or when different payload encoding like Avro is used, it is -REQUIRED to provide schema information (based on metadata information) in a -separate format like [JSON schema](https://json-schema.org/specification) or -[Avro schema](https://avro.apache.org/docs/1.11.1/specification/) or others. For -those cases the attribute references the schema and is used for versioning. +PubSub metadata messages carry type information. For non-OPC UA Consumers +or alternate encodings such as Avro, a schema based on that metadata is +REQUIRED. +`dataschema` identifies and versions that schema. + +A Processing Descriptor MAY supply the schema. The Consumer MUST use +`dataschema` when present. Otherwise, the Consumer MUST use the schema at +[`schema.url`][Descriptor Schema] if the Processing Descriptor contains +`schema`. + +The Consumer MUST report a missing REQUIRED schema. An invalid schema property, +invalid selector, unavailable schema, or unsupported format MUST NOT cause +fallback to another schema. If `dataschema` is present, the Consumer MUST +still validate applicable Descriptor selectors and use `dataschema` as the +sole schema input. Producers and Descriptor +publishers SHOULD supply one schema source or identify the same schema in +both. The Producer SHOULD omit `dataschema` when the Descriptor supplies +the schema. The selected schema MUST describe `data`, including the +NetworkMessage envelope if retained. ### subject -For metadata, event and data messages (type one of `ua-metadata`, `ua-keyframe`, -`ua-deltaframe`, `ua-event`), `subject` MUST map to either [Data Set Message -Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) -field `DataSetWriterId` or `DataSetWriterName`. +For metadata, data, and event messages, a Producer MAY map `subject` to +`DataSetWriterId` or `DataSetWriterName` from the [Data Set Message +Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164). +A Producer using the WoT profile MUST instead follow its +[rules for `subject`](wot.md#subject). -For event messages (type equals to `ua-event`) `subject` MUST be appended with -"/" and [Base Event Type](https://reference.opcfoundation.org/Core/Part5/v104/docs/6.4.2) +For a native OPC UA event message (`MessageType` equals `ua-event`), a +Producer using the OPC UA-specific `subject` mapping MUST append "/" and the +[Base Event Type](https://reference.opcfoundation.org/Core/Part5/v104/docs/6.4.2) field `EventId`. ### time -MUST map to [Data Set Message +The Producer MUST map `time` to [Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) field `Timestamp`. ## Mapping for other extensions -The following well-known extensions attributes MUST be used for data messages and -event messages (type one of `ua-keyframe`, `ua-deltaframe`, `ua-event`). +The following well-known extension attributes apply to data and event +messages. The Consumer MUST determine the native message type from the +retained DataSetMessage `MessageType` field when present. Otherwise, the +Consumer MUST use `opcuamessagetype` for the WoT mapping or `type` for the +non-WoT mapping, as specified above. ### sequence -Attribute as defined by [sequence extensions](./sequence.md) MUST map to [Data -Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) -field `SequenceNumber`. +Without WoT, `sequence`, if present, MUST map to the native DataSetMessage +[`SequenceNumber`][UA SequenceNumber]. The Publisher increments it per +DataSetWriter. +The Producer MUST scope `source` to the writer's ordering scope and format +`sequence` so lexical comparison preserves event order, for example by +padding the unsigned decimal value to ten digits. The Producer MUST NOT +use the counter if a reset, rollover or shared source prevents that ordering. + +The [combined mapping](#wot-mapping) defines `sequence` for events using WoT. ### traceparent -Attribute as defined by [distributed-tracing extension](./distributed-tracing.md) -to allow tracing from event publisher towards consumer. +The [Distributed Tracing extension](./distributed-tracing.md#traceparent) +defines `traceparent`. ### tracestate -Attribute as defined by [distributed-tracing extension](./distributed-tracing.md) -MAY be used to allow tracing from event publisher towards consumer. +The [Distributed Tracing extension](./distributed-tracing.md#tracestate) +defines `tracestate`. ### recordedtime -Attribute as defined by [recordedtime extension](./recordedtime.md) to -determine the latency between event publisher towards consumer. +The [Recorded Time extension](./recordedtime.md#recordedtime) defines +`recordedtime`. ## Attributes @@ -106,7 +161,7 @@ determine the latency between event publisher towards consumer. - Description: Links dataset message to the current version of the metadata. Contains value from `MajorVersion` of [Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) field `MetaDataVersion`. - Constraints - - OPTIONAL but MUST NOT be present if `dataschema` is used + - OPTIONAL, subject to the [schema and metadata-version rules](#metadata-versions) ### opcuametadataminorversion @@ -116,7 +171,13 @@ Contains value from `MinorVersion` of [Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) field `MetaDataVersion`. - Constraints - - OPTIONAL but MUST NOT be present if `dataschema` is used + - OPTIONAL, subject to the [schema and metadata-version rules](#metadata-versions) + +Both event attributes map unsigned [VersionTime][UA VersionTime] to +CloudEvents `Integer` (`0` to `2147483647`, inclusive). Producers MUST +preserve the value or report an encoding error, without truncation, wrap +or signed reinterpretation. Descriptor metadata and applicable native +payload representations can preserve the full native range. ### opcuastatus @@ -125,25 +186,331 @@ field `MetaDataVersion`. [Data Set Message Header](https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table164) field `Status`. - Constraints - OPTIONAL - - REQUIRED if status is not _Good_ - - MAY be omitted if status is _Good_ + - REQUIRED if status is not _Good_ and `data` omits the native `Status` field + - The Producer MAY omit this attribute if status is _Good_ or `data` + retains the native `Status` field. + +CloudEvents `Integer` is limited to the signed 32-bit range. If the status +to be conveyed in `opcuastatus` cannot be represented, the Producer MUST +report an error rather than omit it, wrap the value, or report it as _Good_. + +### opcuamessagetype + +- Type: `String` +- Description: Carries the OPC UA PubSub DataSetMessage type when its + `MessageType` field is absent from `data`. +- Constraints + - OPTIONAL + - In combination with the WoT profile, the value is REQUIRED for data and + event messages when `data` omits the DataSetMessage `MessageType` field, + including when other DataSetMessage header fields are retained. + - The Producer MUST omit this attribute when `data` includes the + DataSetMessage `MessageType`. + - The Producer MUST map this attribute to the Data Set Message Header + `MessageType`. + - The value MUST be the native OPC UA message type, such as `ua-keyframe`, + `ua-deltaframe` or `ua-event`. + +### opcuasequence + +- Type: `String` +- Description: Carries the native DataSetMessage sequence counter without + assigning CloudEvents Sequence extension ordering semantics to it. +- Constraints + - OPTIONAL + - The Producer MUST use a canonical unsigned decimal representation in + the range `0` to `4294967295`, inclusive, with no leading zero except + for `0`, when supplying this attribute. + - In combination with the WoT profile, REQUIRED for keyframe, deltaframe + and event messages. + - The Producer MUST map this attribute to the Data Set Message Header + `SequenceNumber`. The + [OPC UA JSON mapping][UA DataSetWriterName] defines this field as `UInt32`; + the String representation retains the full range of that value. + - The Consumer MUST NOT interpret this attribute as a source-wide + sequence unless it independently satisfies the Sequence extension's + requirements. + +## Publisher and Writer Metadata + +The following names identify the OPC UA Publisher and DataSetWriter +when supplied as `source` query parameters or in `opcua`. +The native envelope carries these values under their OPC UA field names. +The [combined WoT mapping](#wot-mapping) defines when the identities are +REQUIRED; in the OPC UA-only mapping these values are OPTIONAL. + +| Name | Value | +| --- | --- | +| `opcuapublisherid` | The native PublisherId, represented as a string. | +| `opcuadatasetwriterid` | The native DataSetWriterId, represented as an integer. | +| `opcuadatasetwritername` | The configured DataSetWriterName, represented as a string. | + +In a full [Part 14 NetworkMessage][UA NetworkMessage], the Consumer obtains the +PublisherId from the NetworkMessage header and the DataSetWriterId or +DataSetWriterName from its single DataSetMessage header. Those fields retain +their native names and encodings. The following representation rules apply to +their equivalents in `source` and the Descriptor. + +`opcuapublisherid` MUST use `:`. The type MUST be `Byte`, +`UInt16`, `UInt32`, `UInt64`, or `String`, as defined for the native +[PublisherId][UA PublisherId]. For an unsigned integer type, the value MUST be +the nonzero unsigned decimal representation within that type's range, without +a sign or leading zeros. For `String`, the value MUST be the unpadded base64url +encoding of the non-empty PublisherId's UTF-8 bytes. If the message encoding +does not preserve the PublisherId's type, the Producer obtains it from +configuration. If the type cannot be determined, the Producer MUST report an +error rather than assign one. + +`opcuadatasetwriterid` MUST map to the native DataSetWriterId. It MUST be in +the range 1 to 65535, inclusive; [OPC UA reserves zero][UA DataSetWriterId] +as a null value. +`opcuadatasetwritername` MUST be non-empty and match the DataSetWriter's +configured name. For JSON message mapping, this is the +[`DataSetWriterName` field][UA DataSetWriterName] when present in the +DataSetMessage; otherwise the Producer obtains it from configuration. + +If both writer values are supplied, they MUST identify the same DataSetWriter. +A writer name MUST uniquely identify the DataSetWriter within the PublisherId +scope. Consumers MUST compare names exactly, without case folding or Unicode +normalization. + +When an identity is supplied in more than one place, the representations MUST +identify the same native Publisher or DataSetWriter. To compare a query or +Descriptor value with an envelope field, the Consumer MUST decode that value and +apply the field's native Part 14 encoding. For example, `UInt16:12` is encoded +as `"12"` in a JSON NetworkMessage. The Consumer MUST report a metadata conflict +and MUST NOT interpret the payload as a conforming OPC UA message if the values +disagree. + +A Consumer MUST report invalid metadata and MUST NOT interpret the payload as +a conforming OPC UA message if a supplied publisher or writer value violates +these representation or range constraints. + +### Source query syntax + +When these values are supplied in `source`, the query parameters carry +stream-constant metadata. The Producer SHOULD omit a query parameter when the +full OPC UA Part 14 NetworkMessage envelope or the selected Descriptor supplies +its value. For each REQUIRED publisher or writer value that neither supplies, +the Producer MUST include the corresponding parameter in `source`. + +The Producer MUST use `name=value` for each of these parameters, with a +non-empty value. It MUST separate them from each other and from preceding +query content with `;`, and place the query before any URI fragment. The three +names are case-sensitive and MUST appear literally, at most once each. Other +parameters MAY appear in any order; a Consumer MUST NOT reject the source +solely because it contains parameters not defined by this extension. + +For these parameter values, the unescaped characters are the [RFC 3986][URI] +`unreserved` characters and `!`, `$`, `'`, `(`, `)`, `*`, `,`, `:`, `@`, +`/`, and `?`. A Producer MUST leave these characters unescaped and +percent-encode the UTF-8 bytes of all other characters using uppercase +hexadecimal digits. In particular, a literal `%`, `;`, `=`, `&`, `+`, or `#` +MUST be encoded. A Producer MUST NOT use form-query encoding or encode a space +as `+`. + +A Consumer MUST split the query at `;` before decoding these values. It MUST +reject an empty or duplicate recognized parameter, an invalid percent escape, +invalid UTF-8, or an unescaped character outside the permitted set. It MUST +percent-decode each value exactly once and MUST NOT interpret `+` as a space. +The writer ID uses unsigned decimal notation without a sign or leading zeros in +the query and an integer in the Descriptor; the other two values use strings in +both places. + +For example, the following source supplies the PublisherId and writer name when +neither the envelope nor the Descriptor supplies them. The writer name is +`Pump&Process`. + +```text +mqtt://site/line/cell/device/sensor?opcuapublisherid=UInt16:12;opcuadatasetwritername=Pump%26Process;site=north +``` + +Changing `source`, including its query parameters, changes the scope +of [event identity](../spec.md#id) and the [Sequence extension](sequence.md). ## General Constraints -- OPC UA messages MUST use `binary-mode` of CloudEvents. -- OPC UA PubSub JSON messages MUST be encoded using non-reversible encoding as -the decoding information is contained in metadata messages or by schema -referenced via `dataschema` attribute. -- Payload of OPC UA PubSub JSON messages MUST NOT contain Network Message Header -and Data Set Header as that information is mapped into CloudEvents attributes. -- OPC UA PubSub JSON messages MUST contain exactly one dataset message. +- The Producer MUST use CloudEvents binary mode for OPC UA messages. +- The Producer MUST use non-reversible encoding for OPC UA PubSub JSON + messages. Metadata messages or a schema referenced by `dataschema` or + selected through a Descriptor supply the decoding information. +- A Producer MAY retain the full Part 14 NetworkMessage envelope in `data`. + Otherwise, the payload MUST omit the NetworkMessage and DataSetMessage + headers and supply their applicable information through the mappings in + this extension. +- The Producer MUST include exactly one DataSetMessage in each OPC UA + PubSub JSON message, even when retaining a full NetworkMessage envelope. + +A Producer MUST supply the REQUIRED CloudEvents attributes and, when the +WoT mapping applies, the per-event `opcuasequence` even with a retained +envelope. +Native message type conveyance follows [type](#type) and +[opcuamessagetype](#opcuamessagetype), according to whether the WoT profile +is used and whether the DataSetMessage `MessageType` field is present. +The Consumer MUST read the native message type from the DataSetMessage +header when the `MessageType` field is present. +Any duplicated native values MUST agree after applying the specified mappings. +The Consumer MUST report a conflict and MUST NOT interpret a message as +conforming to this extension when they disagree. + +## OPC UA Descriptor Profile + +This profile defines Descriptor fields for OPC UA Part 14 Publisher, +DataSetWriter, DataSet and ConfigurationVersion metadata. A Processing +Descriptor is OPTIONAL. The native envelope and event can also carry inputs. + +### Descriptor property + +A message stream here is a configured flow from one Publisher and +DataSetWriter with a defined payload contract. A broker topic or a +CloudEvents `source` can carry several such streams. + +Publishers MUST derive shared values from the native writer and metadata +configuration for the emitted message. When the rules Producers and +Consumers use for the event stream call for a Descriptor to supply writer +metadata, Publishers SHOULD store stream-constant values in the `opcua` +property. The property is a single JSON object that contains those values +inline and MUST omit `url`. When `opcua` supplies shared inputs, the +Descriptor URL MUST identify a fixed version so that replay selects the +same inputs. + +If `opcua` is absent, the Descriptor supplies no writer metadata. +If present, its value MUST conform to the rules below. + +### Shared Stream Metadata in a Descriptor + +Each member in the following table is OPTIONAL in `opcua`. The binding +determines which values the event needs. The Consumer MUST report invalid +metadata for supplied values that violate this profile, including null values. + +| Member of `opcua` | JSON representation | Meaning and conditions | +| --- | --- | --- | +| `opcuapublisherid` | String | The stream's typed native PublisherId, under the rules in [Publisher and Writer Metadata](#publisher-and-writer-metadata). | +| `opcuadatasetwriterid` | Integer, `1` to `65535` | The stream's native DataSetWriterId, when used. | +| `opcuadatasetwritername` | Non-empty String | The stream's exact configured DataSetWriterName, when used. | +| `opcuadatasetname` | Non-empty String | The `Name` of the applicable DataSet metadata. | +| `opcuametadatamajorversion` | Integer, `0` to `4294967295` | The native MajorVersion, when no payload schema is selected. | +| `opcuametadataminorversion` | Integer, `0` to `4294967295` | The native MinorVersion, when no payload schema is selected. | + +Ranges are inclusive. Publisher and writer fields MUST follow [Publisher +and Writer Metadata](#publisher-and-writer-metadata). + +#### Metadata versions + +The Publisher MUST represent each Descriptor metadata-version field as a +JSON integer in the full `VersionTime` (`UInt32`) range. Consumers MUST +compare duplicate values without narrowing and report out-of-range values +as invalid metadata. + +Metadata-version values retain their native [ConfigurationVersion][UA +ConfigurationVersion] meaning. The Publisher MUST apply Part 14's +MajorVersion and MinorVersion update rules independently of Descriptor +versioning. + +When `dataschema` or the Descriptor supplies a schema, Producers MUST NOT +include metadata-version values in CloudEvents context attributes or the +`opcua` property. Native fields retained in `data` are unaffected. + +#### DataSet name + +`opcuadatasetname` belongs only in Descriptor metadata. It MUST equal +`DataSetMetaDataType.Name` from the applicable +[DataSet metadata][UA DataSet Metadata] or its approved configuration. +It is descriptive and can recur across writers. A Consumer MUST obtain +any REQUIRED native identifier independently. Repeated dataset names MUST +match exactly; a mismatch is a metadata conflict. + +### Using shared inputs + +For the listed values, an applicable Descriptor satisfies this extension's +presence requirements for the corresponding field, including those of the +combined WoT mapping. A Producer MAY omit the corresponding event attribute +or source query parameter. + +The Consumer MUST apply the [identity consistency +rules](#publisher-and-writer-metadata) across the query, Descriptor, and +native envelope. If an event attribute and the Descriptor both supply a +metadata version, their typed values MUST agree. On a conflict, the +Consumer MUST report a metadata conflict and +treat the event as nonconforming. If a REQUIRED value is absent from all +applicable locations, the Consumer MUST report missing metadata and treat +the event as nonconforming. + +A Consumer MUST use the selected Processing Descriptor as the sole +Descriptor source for shared schema and native metadata. If `describedby` +is present but the URL is invalid or the Consumer cannot obtain a valid +Descriptor there, the Consumer MUST report the failure and treat the +Descriptor-based inputs as unavailable. +The Consumer MAY still interpret the native payload if the envelope, source +query, and explicit event attributes supply every native requirement. +That result is independent of WoT correlation. + +The Descriptor Publisher MUST NOT change these values in a Descriptor Version +after any Producer is configured with its URL. A change requires a new +Descriptor Version and reconfigured Producers. Consumers MUST NOT retain values +from a previous Descriptor when processing an event that selects another +Descriptor. The OPC UA identifiers determine the writer identity; the +Descriptor version identifies the shared inputs. The Producer MUST apply +the [WoT `type` revision rules](wot.md#type) when the WoT payload contract +changes. + +Values that vary by occurrence remain in each event. In particular, +the Producer MUST supply `opcuamessagetype`, `opcuasequence`, `opcuastatus`, +`id`, and `time` on the event when their respective rules require them. +Consumers MUST obtain these attributes and any tracing, recording time, +and CloudEvents `sequence` values from the event itself. Core attributes +retain their CloudEvents placement and meaning. + +An OPC UA-only event can omit `describedby`. In that case the Producer +MUST supply all REQUIRED OPC UA values through the other applicable locations. +Producers SHOULD use Descriptor metadata only when the intended Consumers +support the agreed mapping. + +JSON integers in this profile preserve the full native ranges. An alternate +serialization or generated schema MUST preserve those same values, or report +an encoding error. For example, an Avro schema needs a type wide enough to +preserve the full UInt32 range. + +The [OPC UA JSON Schema](opcua.schema.json) checks `opcua` when +present. The Consumer MUST verify PublisherId encoding, ranges, and the +event context under the rules above. + +## WoT mapping + +When a CloudEvent uses both this extension and the [WoT profile](wot.md), +[`describedby` is REQUIRED](wot.md#description-selection). The same +Descriptor supplies the WoT selection and any Descriptor-based OPC UA +metadata. For data and event messages, the following mappings take +precedence over the corresponding OPC UA-only mappings: + +- The Producer MUST use the WoT [`type`](wot.md#type) and + [`subject`](wot.md#subject) mappings. The Producer MUST keep the native + `EventId` in the OPC UA event payload. + The Producer MUST convey the native message type under the + [`opcuamessagetype`](#opcuamessagetype) rules. +- The Producer MUST supply the native PublisherId and at least one of + DataSetWriterId and DataSetWriterName. The Producer MUST supply each + value in the envelope, a `source` query parameter, or the Descriptor's + `opcua` property, under + [Publisher and Writer Metadata](#publisher-and-writer-metadata). +- The Producer MUST use [`opcuasequence`](#opcuasequence) for the native + `SequenceNumber`. + If the Producer also supplies CloudEvents `sequence`, it MUST satisfy + the [Sequence extension](sequence.md) independently. The Producer MUST + obtain that value independently of `opcuasequence`. + +All other applicable OPC UA requirements remain in effect. ## Examples +The OPC UA-only examples use writer name `energy-consumption-asset` in +`subject`. Some also supply publisher `UInt16:12` and the writer name in the +`source` query. Those query parameters are OPTIONAL without WoT. + ### Metadata message -The metadata message helps Cloud applications to understand the semantics and -structure of dataset messages. +Cloud applications use the metadata message to interpret the structure and +meaning of DataSetMessages. ```text ------------------ PUBLISH ------------------- @@ -157,7 +524,7 @@ specversion: 1.0 type: ua-metadata time: 2024-03-28T21:56:24Z id: 1234-1234-1234 -source: urn:factory:aggregationserver:opcua +source: https://factory.example.com/aggregationserver/opcua?opcuapublisherid=UInt16:12;opcuadatasetwritername=energy-consumption-asset datacontenttype: application/json; charset=utf-8 subject: energy-consumption-asset .... further attributes ... @@ -178,16 +545,16 @@ subject: energy-consumption-asset ### Telemetry message -The telemetry or data messages contain values of all OPC UA nodes that had -changed in a given period of time (`ua-deltaframe`) or contain values for all -OPC UA nodes that were monitored (`ua-keyframe`). -The complete list of monitored OPC UA nodes as well as the related type -information are defined in the metadata message. The attributes -`opcuametadatamajorversion` and `opcuametadataminorversion` are used to -reference the correct metadata message. The `ua-deltaframe` messages will be -used for hot and/or cold path processing and `ua-keyframe` messages can -additional be used to update last-known-value tables. +A `ua-deltaframe` carries values for OPC UA nodes that changed during a +given interval. A `ua-keyframe` carries values for all monitored nodes. +The metadata message lists those nodes and their types. The +`opcuametadatamajorversion` and `opcuametadataminorversion` attributes +identify the corresponding metadata message. Consumers can process delta +frames on the hot path, the cold path, or both, and can use keyframes to +update last-known-value tables. +This example uses a writer-specific `source` for sequence ordering without +carrying an explicit PublisherId or writer query parameter. ```text ------------------ PUBLISH ------------------- @@ -201,10 +568,10 @@ specversion: 1.0 type: ua-deltaframe time: 2024-03-28T21:56:42Z id: 1235-1235-1235 -source: urn:factory:aggregationserver:opcua +source: https://factory.example.com/aggregationserver/opcua/energy-consumption-asset datacontenttype: application/json; charset=utf-8 subject: energy-consumption-asset -sequence: 7 +sequence: 0000000007 traceparent: 4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00000011 recordedtime: 2024-03-28T21:56:43Z opcuametadatamajorversion: 672338910 @@ -223,9 +590,8 @@ opcuametadataminorversion: 672341762 #### OPC UA PubSub JSON single dataset Message -Using CloudEvents and model the OPC UA PubSub header information as CloudEvent -attributes enables integration into various system (independent from used -protocols) and simplifies the payload structure. +Mapping OPC UA PubSub header fields to CloudEvents attributes simplifies +the payload and lets systems use the same attributes across protocols. ```text { @@ -255,14 +621,13 @@ protocols) and simplifies the payload structure. ### Event message -The event message will contain a single event and the identifier of this event is -added to the `subject` to allow routing it into different systems without parsing -the payload. Events are routed for example in systems like Manufacturing Execution -Systems (MES), Supervisory Control and Data Acquisition systems (SCADA), -Alerting Systems or Operation Technology Operator Terminals (HMI Clients) and -also in hot and/or cold path processing. The attributes -`opcuametadatamajorversion` and `opcuametadataminorversion` are used to -reference the correct metadata message. +The message carries one event. The Producer adds its identifier to +`subject` so systems can route it without parsing the payload. Recipients +include manufacturing execution systems (MES), supervisory control and +data acquisition (SCADA) systems, alerting systems, and operator terminals +(HMI clients). Routing can serve hot-path and cold-path processing. The +`opcuametadatamajorversion` and `opcuametadataminorversion` attributes +identify the corresponding metadata message. ```text ------------------ PUBLISH ------------------- @@ -276,10 +641,10 @@ specversion: 1.0 type: ua-event time: 2024-03-28T21:57:01Z id: 1236-1237-1238 -source: urn:factory:aggregationserver:opcua +source: https://factory.example.com/aggregationserver/opcua?opcuapublisherid=UInt16:12;opcuadatasetwritername=energy-consumption-asset datacontenttype: application/json; charset=utf-8 subject: energy-consumption-asset/444321 -sequence: 18 +sequence: 0000000018 traceparent: caffef3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00000011 recordedtime: 2024-03-28T21:57:01Z opcuametadatamajorversion: 672338910 @@ -298,13 +663,10 @@ opcuametadataminorversion: 672341762 ### Telemetry message with different Encoding -One major benefit of CloudEvents for OPC UA is that it is possible to support -other encoding and external schema, while keeping the same OPC UA information for -routing. - -The example below uses Avro binary encoded payload, with the corresponding schema -referenced by `dataschema`. The `source` will be defined by an customer defined -hierarchical path. +CloudEvents carries the same OPC UA routing information when the payload +uses a different encoding and an external schema. Here the payload uses +Avro binary encoding, `dataschema` identifies its schema, and `source` is +a customer-configured hierarchical path. ```text ------------------ PUBLISH ------------------- @@ -318,11 +680,11 @@ specversion: 1.0 type: ua-keyframe time: 2024-03-28T23:59:59Z id: 6235-7235-8235 -source: bottling-company/amsterdam/FillingArea1/FillingLine9/Cell1/Conveyor +source: bottling-company/amsterdam/FillingArea1/FillingLine9/Cell1/Conveyor?opcuapublisherid=UInt16:12;opcuadatasetwritername=energy-consumption-asset datacontenttype: application/avro subject: energy-consumption-asset dataschema: http://example.com/schemas/energy-consumption-asset/v1.8 -sequence: 3141 +sequence: 0000003141 traceparent: 22222f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00000011 recordedtime: 2024-03-28T23:59:59Z .... further attributes ... @@ -334,3 +696,155 @@ recordedtime: 2024-03-28T23:59:59Z ----------------------------------------------- ``` + +### HTTP keyframe + +This request uses CloudEvents binary mode. The Consumer already has the +OPC UA metadata for this stream. + +```http +POST /events HTTP/1.1 +Host: consumer.example +Content-Type: application/json +Content-Length: 16 +ce-specversion: 1.0 +ce-id: pump7-sample-1 +ce-source: urn:example:pump7 +ce-type: ua-keyframe +ce-subject: pump7-process +ce-time: 2026-10-29T12:00:00Z + +{"Pressure":4.5} +``` + +### WoT and OPC UA telemetry message + +This binary-mode keyframe uses the WoT event type. Its Descriptor selects +the pump's `processData` property and supplies the payload schema, publisher, +and writer metadata. The native OPC UA message type and sequence remain in +the event. This example uses writer ID `17` within publisher `UInt16:12`. + +```text +------------------ PUBLISH ------------------- + +Topic Name: opcua/json/DataSetMessage/pump +Content Type: application/json + +------------- User Properties ---------------- + +specversion: 1.0 +id: ua-message-25460 +source: urn:example:actor:telemetry-service +type: com.example.models.tm.pump.properties.processData.v1 +subject: pump7 +time: 2026-10-29T12:00:00Z +describedby: https://registry.example/descriptorgroups/streams/descriptors/pump7-telemetry/versions/1 +opcuamessagetype: ua-keyframe +opcuasequence: 4294967295 + +------------------ payload ------------------- + +{ + "Speed": 1500, + "Pressure": 4.5 +} + +----------------------------------------------- +``` + +The referenced Descriptor version contains these properties: + +```json +{ + "thingdescription": { + "pump7": { + "url": "https://devices.example/pump7/td.json", + "affordanceselector": "/properties/processData" + } + }, + "schema": { + "url": "https://schemas.example/pump-process-data/versions/3" + }, + "opcua": { + "opcuapublisherid": "UInt16:12", + "opcuadatasetwriterid": 17 + } +} +``` + +The Consumer selects `/properties/processData` from the linked TD. It +retrieves the payload schema at `schema.url` and reads the native identity +from `opcua`. The event's `subject` is available for filtering. + +#### WoT telemetry with a retained NetworkMessage envelope + +This event retains the full Part 14 NetworkMessage envelope. Its PublisherId +and DataSetWriterId satisfy the identity requirements, so `source` needs no +publisher or writer query parameters. Part 14 JSON encodes the configured +PublisherId `UInt16:12` as the string `"12"`. + +`describedby` selects the [WoT example Descriptor](wot.md#pump-telemetry-example) +for the Thing and affordance. `dataschema` takes precedence over that +Descriptor's `schema` property and identifies the envelope's schema. The +event type uses revision `v2` because retaining the envelope changes the +payload contract. + +```text +------------------ PUBLISH ------------------- + +Topic Name: opcua/json/DataSetMessage/pump +Content Type: application/json + +------------- User Properties ---------------- + +specversion: 1.0 +id: ua-message-25461 +source: mqtt://site/line/cell/device/sensor?site=north +type: com.example.models.tm.pump.properties.processData.v2 +describedby: https://devices.example/pump7/descriptors/process-data.json +time: 2026-10-29T12:00:01Z +dataschema: https://schemas.example/pump-process-data-envelope/versions/1 +opcuasequence: 0 + +------------------ payload ------------------- + +{ + "MessageId": "ua-message-25461", + "MessageType": "ua-data", + "PublisherId": "12", + "Messages": [ + { + "DataSetWriterId": 17, + "MessageType": "ua-keyframe", + "SequenceNumber": 0, + "Timestamp": "2026-10-29T12:00:01Z", + "Payload": { + "Speed": 1500, + "Pressure": 4.5 + } + } + ] +} + +----------------------------------------------- +``` + +The rollover from `4294967295` to `0` is carried in `opcuasequence`. The +retained DataSetMessage header supplies the native `MessageType`. + +## Descriptor Retrieval Security + +A Consumer MUST establish trust in the Descriptor before using it as OPC UA +metadata. Publisher authentication and authorization to access the TD or +schema depend on checks independent of the writer metadata. + +[UA DataSetWriterName]: https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.5.4#Table185 +[UA NetworkMessage]: https://reference.opcfoundation.org/specs/OPC-10000-14/v1.05.06/7.2.5.3 +[UA DataSetWriterId]: https://reference.opcfoundation.org/specs/OPC-10000-14/v1.05.06/6.2.4.1 +[UA PublisherId]: https://reference.opcfoundation.org/specs/OPC-10000-14/v1.05.06/6.2.7.1 +[UA SequenceNumber]: https://reference.opcfoundation.org/Core/Part14/v105/docs/7.2.3 +[UA DataSet Metadata]: https://reference.opcfoundation.org/specs/OPC-10000-14/v1.05.06/6.2.3.2.3 +[UA VersionTime]: https://reference.opcfoundation.org/specs/OPC-10000-4/v1.05.07/7.43 +[UA ConfigurationVersion]: https://reference.opcfoundation.org/specs/OPC-10000-14/v1.05.06/6.2.3.2.6 +[URI]: https://www.rfc-editor.org/rfc/rfc3986 +[Descriptor Schema]: descriptor.md#schema diff --git a/cloudevents/extensions/opcua.schema.json b/cloudevents/extensions/opcua.schema.json new file mode 100644 index 000000000..1abdbd9f5 --- /dev/null +++ b/cloudevents/extensions/opcua.schema.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "CloudEvents OPC UA Descriptor property", + "type": "object", + "properties": { + "opcua": { + "type": "object", + "properties": { + "url": false, + "opcuapublisherid": { + "type": "string", + "anyOf": [ + { "pattern": "^(?:Byte|UInt16|UInt32|UInt64):[1-9][0-9]*(?![\\s\\S])" }, + { "pattern": "^String:(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,4})(?![\\s\\S])" } + ] + }, + "opcuadatasetwriterid": { "type": "integer", "minimum": 1, "maximum": 65535 }, + "opcuadatasetwritername": { "type": "string", "minLength": 1 }, + "opcuadatasetname": { "type": "string", "minLength": 1 }, + "opcuametadatamajorversion": { "$ref": "#/$defs/versionTime" }, + "opcuametadataminorversion": { "$ref": "#/$defs/versionTime" } + } + } + }, + "$defs": { + "versionTime": { "type": "integer", "minimum": 0, "maximum": 4294967295 } + } +} diff --git a/cloudevents/extensions/openusd.md b/cloudevents/extensions/openusd.md new file mode 100644 index 000000000..1a4bf2289 --- /dev/null +++ b/cloudevents/extensions/openusd.md @@ -0,0 +1,185 @@ +# OpenUSD + +An event reporting pump telemetry can link to the pump's +[OpenUSD](https://openusd.org/) asset so a Consumer can locate the pump in +a scene. The event's [`describedby`](descriptor.md#describedby) URL points to a +[Descriptor](descriptor.md) with a `usdasset` property. A *prim* is an element +in the OpenUSD scene, such as the pump's scene object. This Descriptor +associates the event with the `/Pump7` prim: + +```json +{ + "usdasset": { + "geometry": { + "url": "https://assets.example/pump7.usda", + "primpath": "/Pump7" + } + } +} +``` + +## Notational Conventions + +As with the main [CloudEvents specification](../spec.md), the key words "MUST", +"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", +"RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as +described in [RFC 2119](https://tools.ietf.org/html/rfc2119). + +However, the scope of these key words is limited to when this extension is +used. For example, an attribute marked as "REQUIRED" needs to be included +when the event uses this extension and meets the stated conditions. + +## Attributes + +### describedby + +[`describedby`](descriptor.md#describedby) is REQUIRED to associate an +event with an OpenUSD asset through this extension. It identifies the +Descriptor that supplies the asset references. Core attributes retain their +CloudEvents meanings. + +## Asset selection + +If the Consumer cannot obtain a valid Descriptor at `describedby`, it MUST +report the failure and leave the event unassociated with an OpenUSD asset. + +`usdasset` is a map of local names to asset reference objects. Each object +has a REQUIRED `url`, an absolute, fragment-free HTTP(S) URL of the +OpenUSD asset itself. + +This extension defines the agreed set of rules for using the Descriptor to +associate an event with OpenUSD assets. Producers and Consumers MAY specify +several names in `usdasset` in the rules they use for the event stream. +The Consumer MUST use the exact names those rules specify. The Consumer +MUST select the sole object in the map if it needs one asset and the rules +specify no name. The Consumer MUST report a missing, invalid, ambiguous, +or unavailable asset when needed. It MUST NOT infer a selection from +`subject`, a filename, or map order. + +### primpath + +- Type: String +- Description: The [absolute OpenUSD prim path][Prim Path] within the stage + composed from the asset at `url`. The stage is the scene formed from + the asset and its dependencies. The path associates the whole event + with that prim and anchors any field mappings. +- Constraints: + - OPTIONAL. Omission selects the asset as a whole. + - The Publisher MUST identify an existing prim in that stage when it + provides `primpath`. Null, empty, root (`/`), relative, and property + paths are invalid, as are paths containing variant selections. + - The Consumer MUST resolve the value as an OpenUSD path. If resolution + fails, it MUST report the failure and leave the prim unselected. + +### Field mappings + +An asset reference can associate individual JSON payload fields with +descendants of the anchor prim. If `fieldmode` or `fieldmappings` is +present, `primpath` is REQUIRED. The Consumer MUST derive field associations +only from these members. The event-level association still comes from +`primpath`. Writing USD property values is outside the scope of this extension. + +The OPTIONAL `fieldmappings` array contains objects with two REQUIRED +string members: + +| Member | Meaning | +| --- | --- | +| `field` | A non-empty [RFC 6901 JSON Pointer][JSON Pointer] in string form, rooted at CloudEvents `data`. | +| `prim` | A relative OpenUSD prim path to an existing descendant of the anchor. Absolute paths, parent traversal (`..`), property paths, and paths containing variant selections are invalid. | + +Duplicate `field` pointers are invalid. The Consumer MUST apply each +mapping independently of its position in the array. The Consumer MUST +skip the mapping for a field the event omits and leave any prior value +unchanged. The Consumer MUST report an invalid mapping or an unresolved +explicit prim target and leave that field unmapped. + +The OPTIONAL string `fieldmode` accepts only `"byname"`. In this mode, +the Consumer matches each top-level member of a JSON object in `data` to a +direct child of the anchor with the exact same name. An explicit mapping for +that field takes precedence. When `fieldmode` is omitted, only explicit +mappings apply. Fields with neither kind of match stay unmapped. + +Mapping an OpenUSD prim to a WoT affordance is outside the scope of this +extension. The Consumer MUST resolve asset dependencies under OpenUSD +rules. + +The [OpenUSD JSON Schema](openusd.schema.json) checks the `usdasset` +property when present. +The Consumer MUST verify path syntax, targets, and pointer uniqueness +under the rules above. + +## Examples + +The following event reports Pump 7 telemetry in HTTP binary mode. Its +`ce-describedby` header identifies the Descriptor that selects the asset and +its pump prim. + +```http +POST /events HTTP/1.1 +Host: consumer.example +Content-Type: application/json +Content-Length: 43 +ce-specversion: 1.0 +ce-id: pump7-telemetry-47 +ce-source: urn:example:asset:pump7 +ce-type: com.example.pump.telemetry +ce-subject: pump7 +ce-describedby: https://registry.example/descriptorgroups/streams/descriptors/pump7-geometry/versions/1 + +{"pressure":4.5,"speed":1200,"status":"ok"} +``` + +The `geometry` object in `usdasset` uses an xRegistry document-view URL for +the asset version and selects `/Pump7` in that asset. The stage contains +`/Pump7/Sensors/PressureGauge`, `/Pump7/pressure`, +and `/Pump7/speed`, but no `/Pump7/status`: + +```json +{ + "usdasset": { + "geometry": { + "url": "https://assets.example/usdassetgroups/line1/usdassets/pump7/versions/2", + "primpath": "/Pump7", + "fieldmode": "byname", + "fieldmappings": [ + { "field": "/pressure", "prim": "Sensors/PressureGauge" } + ] + } + } +} +``` + +The explicit mapping takes precedence and associates `pressure` with +`/Pump7/Sensors/PressureGauge`. By-name matching associates `speed` with +`/Pump7/speed`. The `status` field stays unmapped. Without either field-mapping +member, the event would still describe `/Pump7` as a whole. + +### One event, two assets + +In this example, the rules for the event stream specify both names +below. The Consumer associates the same pump event with the plant layout +and the detailed assembly. Each `primpath` resolves in the stage composed +from its own asset. + +```json +{ + "usdasset": { + "plant-layout": { + "url": "https://assets.example/plant/layout-v4.usda", + "primpath": "/Plant/Line1/Pump7" + }, + "pump-assembly": { + "url": "https://assets.example/pump7/assembly-v2.usda", + "primpath": "/Pump7" + } + } +} +``` + +## Security Considerations + +The Consumer MUST authorize access to the asset and each dependency +separately and apply resource limits during resolution. + +[Prim Path]: https://openusd.org/release/api/class_sdf_path.html +[JSON Pointer]: https://www.rfc-editor.org/rfc/rfc6901 diff --git a/cloudevents/extensions/openusd.schema.json b/cloudevents/extensions/openusd.schema.json new file mode 100644 index 000000000..d2baa2330 --- /dev/null +++ b/cloudevents/extensions/openusd.schema.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "CloudEvents OpenUSD Descriptor property", + "type": "object", + "properties": { + "usdasset": { + "type": "object", + "additionalProperties": { "$ref": "#/$defs/assetReference" } + } + }, + "$defs": { + "assetReference": { + "type": "object", + "required": ["url"], + "properties": { + "url": { + "type": "string", + "format": "uri", + "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://(?:[^/?#@\\s]*@)?(?:\\[[^\\]\\s/?#]+\\]|[^\\[\\]:@/?#\\s]+)(?::[0-9]*)?(?:[/?][^#\\s]*)?(?![\\s\\S])" + }, + "primpath": { + "type": "string", + "pattern": "^/[^/.{}:\\s]+(?:/[^/.{}:\\s]+)*(?![\\s\\S])" + }, + "fieldmode": { "const": "byname" }, + "fieldmappings": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "object", + "required": ["field", "prim"], + "properties": { + "field": { + "type": "string", + "pattern": "^/(?:[^~]|~[01])*(?![\\s\\S])" + }, + "prim": { + "type": "string", + "pattern": "^[^/.{}:\\s]+(?:/[^/.{}:\\s]+)*(?![\\s\\S])" + } + } + } + } + }, + "dependentRequired": { + "fieldmode": ["primpath"], + "fieldmappings": ["primpath"] + } + } + } +} diff --git a/cloudevents/extensions/wot.md b/cloudevents/extensions/wot.md new file mode 100644 index 000000000..ed6b118b3 --- /dev/null +++ b/cloudevents/extensions/wot.md @@ -0,0 +1,275 @@ +# Web of Things + +A Consumer can use a pump's [Web of Things][TD] (WoT) Thing Description +(TD) to identify the source and context of an event. The event's +[`describedby`](descriptor.md#describedby) URL points to a +[Descriptor](descriptor.md) that links to a TD and can identify an +interaction in it, called an *affordance*. + +The [pump telemetry example](#pump-telemetry-example) shows how a Descriptor +selects the `processData` property of Pump 7. + +## Notational Conventions + +As with the main [CloudEvents specification](../spec.md), the key words "MUST", +"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", +"RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as +described in [RFC 2119](https://tools.ietf.org/html/rfc2119). + +However, the scope of these key words is limited to when this profile is +used. For example, an attribute marked as "REQUIRED" needs to be included +when the event uses this profile and meets the stated conditions. + +## Description Selection + +[`describedby`](descriptor.md#describedby) is REQUIRED for this profile. +The Consumer MUST use the Descriptor at that URL as the sole source of +Descriptor properties for the event. The Consumer MUST select the named +object in `thingdescription` if the rules Producers and Consumers use for +the event stream specify a name. Otherwise, `thingdescription` MUST contain +exactly one object, which the Consumer selects. + +The Consumer retrieves the selected TD from its `url` and apply the +selected object's [affordance selector](#affordanceselector), if present, +to identify the affordance. The Publisher MUST make the selected TD +available before configuring Producers to use the Descriptor and SHOULD +link to a specific TD version. + +Correlation fails if `describedby` is missing or invalid, the URL does not +yield a valid Descriptor, or the Consumer cannot select the TD entry or +resolve its TD or selector. The Consumer MUST report the failure and MAY +retain or forward the uncorrelated event. + +## WoT Descriptor properties + +`thingdescription` is a map of names to objects that link to TDs. +A [Thing Model][TM] (TM) defines a reusable model for Things; +`thingmodel` is a map of names to objects that link to TMs. Names are +local to each map and match exactly. Each object has a REQUIRED `url`, an +absolute, fragment-free HTTP(S) URL of the resolved document itself. +For example, a Publisher linking to a document in xRegistry supplies the +document-view URL. + +### affordanceselector + +An object in `thingdescription` MAY include `affordanceselector` to select +an affordance. Omission selects the whole Thing. In `thingmodel`, this +member selects a model declaration; omission selects no individual +declaration. + +When present, the member MUST be a plain [RFC 6901][JSON Pointer] string +of the form `/properties/`, `/actions/`, or `/events/`. +It MUST identify an existing affordance or declaration in the linked +document. The Consumer MUST apply only RFC 6901 string-form decoding. +Null, empty, root, and more deeply nested selectors are invalid. +The Publisher MUST place any annotations defined for the event stream +beside the selector. The rules for the stream define each annotation's +scope, type, and when it can be omitted. + +### Event binding + +A `thingmodel` object MAY contain `type` to associate an event contract +with a TM or one of its declarations. For a Consumer using this binding, +the object's `type` MUST match the decoded event `type` exactly. If the +rules for the event stream specify a name, only the named object can match. +Otherwise, exactly one match is REQUIRED. The Consumer MUST report +missing, ambiguous, or invalid bindings and unavailable TMs. The concrete +TD path and the TM declaration path can differ; derivation uses the model +declaration. + +### planurl + +An object in `thingdescription` or `thingmodel` MAY include `planurl`, an +absolute, fragment-free HTTP(S) URL for the WoT projection plan that +produced the WoT view at `url`. The rules for the event stream define the +plan's format. Consumers using the plan MUST verify that it produced the +linked WoT view. The resolved WoT view remains valid when this OPTIONAL +provenance is unavailable. + +The [WoT JSON Schema](wot.schema.json) validates the shapes of these +properties when present. The Consumer MUST apply the selection rules to +check the linked document and selector target. + +## Mapping Core Context Attributes + +### source + +[`source`](../spec.md#source) identifies the event's originating context +and follows Core's URI-reference rules. The WoT example uses the reporting +telemetry service as `source`. + +### subject + +[`subject`](../spec.md#subject) is OPTIONAL and retains its Core meaning. +For example, a Producer can supply `pump7` to support filtering. WoT +retrieval and correlation use the Descriptor selected by `describedby`. + +### type + +Core [`type`](../spec.md#type) identifies the event contract: the payload +representation, members, types, and semantics. These come from the rules +Producers and Consumers use for the event stream or from the protocol +binding. Things can share a type when they share a contract. The +dot-separated type supports code generation. + +The type MUST contain one or more segments separated by single dots. Each +segment MUST start with an ASCII letter or underscore; the rest can contain +only ASCII letters, digits, and underscores. Generators still handle +language keywords. The last segment MUST be the contract revision `vN`, +with positive decimal `N` and no leading zeros. + +A Producer MAY configure the complete type. Otherwise, it derives the type +from a governing TM and, for an affordance event, the corresponding +model-affordance path. When composition or derivation leaves the mapping +ambiguous, the publication configuration MUST select it explicitly. +A Producer MUST NOT infer the mapping solely from matching names or select +a TM link by position. + +The Producer MUST follow these steps when deriving the type from an +eligible HTTPS TM identifier: + +1. The Producer MUST use an identifier with an ASCII DNS hostname + without empty labels or a trailing root dot. The identifier cannot + contain user information, a port, a query, or a fragment. +2. The Producer MUST lowercase the hostname, reverse its labels, and + join them with dots. +3. The Producer MUST append the TM identifier's path, replacing each `/` + with `.`. +4. The Producer MUST append the model-affordance JSON Pointer path for + an affordance event. The Producer MUST decode its [RFC 6901][JSON Pointer] + token escaping before replacing each `/` with `.`. +5. The Producer MUST append the event-contract revision as the final segment. + +For example, TM `https://models.example.com/tm/pump` and model affordance +`/properties/processData` with event-contract revision 1 produce: + +```text +com.example.models.tm.pump.properties.processData.v1 +``` + +The Producer MUST omit the affordance path from the TM-derived type for +a whole-Thing event. The rules for the event stream define how the +Producer aggregates interaction data into the payload. + +Producers MUST use the same revision for the same event +contract. A Producer MUST use a new revision when the contract changes, +including when a member is added or removed, a member's type or meaning +changes, or the payload envelope changes. This applies even to +backward-compatible changes. A Producer MUST NOT reuse a revision for a +different contract with the same base type. + +For example, adding a `quality` member to +`com.example.models.tm.pump.properties.processData.v1` requires +`com.example.models.tm.pump.properties.processData.v2`, even if Consumers +can ignore the new member. Changing a value or omitting or including an +OPTIONAL member preserves the revision. Changes to `describedby`, a TD +URL, the selected schema, or `subject` require a new revision only if they +change the payload contract. + +The Producer MUST configure a valid complete type when the derivation is +unavailable, produces an invalid symbol, or collides with a different +event contract in the Producer's type namespace. For example, +`/tm/pump.v1` and `/tm/pump/v1` produce the same suffix. + +### dataschema and datacontenttype + +Core [`dataschema`](../spec.md#dataschema) and +[`datacontenttype`](../spec.md#datacontenttype) describe the schema and +media type of `data`. The rules for the event stream or the protocol +binding determine whether an external payload schema is REQUIRED. + +The Consumer MUST use `dataschema` as the sole schema input when present +and MUST still validate applicable Descriptor selectors. Otherwise, the +Consumer MUST use the schema at the Descriptor's +[`schema.url`][Descriptor Schema] when `schema` is present. + +Producers and Descriptor publishers SHOULD supply one schema source or +identify the same schema in both. Producers SHOULD omit `dataschema` +when the Descriptor supplies the schema. + +The Consumer MUST report a missing REQUIRED schema. An invalid schema +property, invalid selector, unavailable schema, or unsupported format +MUST NOT cause fallback to another schema. The selected schema MUST +describe the actual payload, including its encoding and envelope. For +example, a TD URL belongs in `dataschema` only when it identifies the +schema for `data` itself. The rules for the event stream or the protocol +binding map an affordance's DataSchema to the wire payload and can require +a specific schema version independently of the TD version. + +## Pump telemetry example + +This event reports a reading from the `processData` property of Pump 7: + +```json +{ + "specversion": "1.0", + "id": "sample-4711", + "source": "urn:example:actor:telemetry-service", + "type": "com.example.models.tm.pump.properties.processData.v1", + "subject": "pump7", + "describedby": "https://devices.example/pump7/descriptors/process-data.json", + "datacontenttype": "application/json", + "data": { + "Speed": 1500, + "Pressure": 4.5 + } +} +``` + +An HTTP `GET` of `describedby` returns the following Descriptor. The +Consumer resolves the only TD at `url` and evaluates `affordanceselector` +in it. The `schema` property links to the schema for the object in `data`. + +```json +{ + "thingdescription": { + "pump7": { + "url": "https://devices.example/pump7/td.json", + "affordanceselector": "/properties/processData" + } + }, + "schema": { + "url": "https://schemas.example/pump-process-data/versions/3" + } +} +``` + +## Whole-Thing example + +To report the pump's aggregate state, the Producer uses +`com.example.models.tm.pump.v1` as `type` and points `describedby` to a +Descriptor whose TD object omits `affordanceselector`. The `schema` property +links to the schema for the aggregate object, including both `processData` +and `running`. + +```json +{ + "thingdescription": { + "pump7": { + "url": "https://devices.example/pump7/td.json" + } + }, + "schema": { + "url": "https://schemas.example/pump-state/versions/3" + } +} +``` + +## Relationship to Other Extensions + +An event that also uses the [OPC UA extension](opcua.md) MUST follow +its [combined WoT mapping](opcua.md#wot-mapping) for native message types, +sequence counters, and writer identities. + +## Security Considerations + +The Consumer MUST treat context attributes as Producer-supplied values +unless another mechanism authenticates them. The Consumer MUST establish +trust and access independently for each document, its model lineage, and +its dependencies. Correlating an event with an affordance does not +authorize invoking it. + +[TD]: https://www.w3.org/TR/wot-thing-description11/ +[TM]: https://www.w3.org/TR/wot-thing-description11/#thing-model +[JSON Pointer]: https://www.rfc-editor.org/rfc/rfc6901 +[Descriptor Schema]: descriptor.md#schema diff --git a/cloudevents/extensions/wot.schema.json b/cloudevents/extensions/wot.schema.json new file mode 100644 index 000000000..42f600291 --- /dev/null +++ b/cloudevents/extensions/wot.schema.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "CloudEvents WoT Descriptor properties", + "type": "object", + "properties": { + "thingdescription": { + "type": "object", + "additionalProperties": { "$ref": "#/$defs/descriptionLink" } + }, + "thingmodel": { + "type": "object", + "additionalProperties": { "$ref": "#/$defs/modelLink" } + } + }, + "$defs": { + "httpUrl": { + "type": "string", + "format": "uri", + "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://(?:[^/?#@\\s]*@)?(?:\\[[^\\]\\s/?#]+\\]|[^\\[\\]:@/?#\\s]+)(?::[0-9]*)?(?:[/?][^#\\s]*)?(?![\\s\\S])" + }, + "descriptionLink": { + "type": "object", + "required": ["url"], + "properties": { + "url": { "$ref": "#/$defs/httpUrl" }, + "planurl": { "$ref": "#/$defs/httpUrl" }, + "affordanceselector": { + "type": "string", + "pattern": "^/(?:properties|actions|events)/(?:[^~/]|~[01])+(?![\\s\\S])" + } + } + }, + "modelLink": { + "$ref": "#/$defs/descriptionLink", + "properties": { + "type": { + "type": "string", + "pattern": "^(?:[A-Za-z_][A-Za-z0-9_]*\\.)*v[1-9][0-9]*(?![\\s\\S])" + } + } + } + } +}