server_pubsub.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright (c) 2017-2018 Fraunhofer IOSB (Author: Andreas Ebner)
  6. * Copyright (c) 2019 Kalycito Infotech Private Limited
  7. */
  8. #ifndef UA_SERVER_PUBSUB_H
  9. #define UA_SERVER_PUBSUB_H
  10. #include <open62541/server.h>
  11. _UA_BEGIN_DECLS
  12. #ifdef UA_ENABLE_PUBSUB
  13. /**
  14. * .. _pubsub:
  15. *
  16. * Publish/Subscribe
  17. * =================
  18. *
  19. * Work in progress!
  20. * This part will be a new chapter later.
  21. *
  22. * TODO: write general PubSub introduction
  23. *
  24. * The Publish/Subscribe (PubSub) extension for OPC UA enables fast and efficient
  25. * 1:m communication. The PubSub extension is protocol agnostic and can be used
  26. * with broker based protocols like MQTT and AMQP or brokerless implementations like UDP-Multicasting.
  27. *
  28. * The PubSub API uses the following scheme:
  29. *
  30. * 1. Create a configuration for the needed PubSub element.
  31. *
  32. * 2. Call the add[element] function and pass in the configuration.
  33. *
  34. * 3. The add[element] function returns the unique nodeId of the internally created element.
  35. *
  36. * Take a look on the PubSub Tutorials for mor details about the API usage.::
  37. *
  38. * +-----------+
  39. * | UA_Server |
  40. * +-----------+
  41. * | |
  42. * | |
  43. * | |
  44. * | | +----------------------+
  45. * | +--> UA_PubSubConnection | UA_Server_addPubSubConnection
  46. * | +----------------------+
  47. * | | |
  48. * | | | +----------------+
  49. * | | +----> UA_WriterGroup | UA_PubSubConnection_addWriterGroup
  50. * | | +----------------+
  51. * | | |
  52. * | | | +------------------+
  53. * | | +----> UA_DataSetWriter | UA_WriterGroup_addDataSetWriter +-+
  54. * | | +------------------+ |
  55. * | | |
  56. * | | +----------------+ | r
  57. * | +---------> UA_ReaderGroup | | e
  58. * | +----------------+ | f
  59. * | |
  60. * | +---------------------------+ |
  61. * +-------> UA_PubSubPublishedDataSet | UA_Server_addPublishedDataSet <-+
  62. * +---------------------------+
  63. * |
  64. * | +-----------------+
  65. * +----> UA_DataSetField | UA_PublishedDataSet_addDataSetField
  66. * +-----------------+
  67. *
  68. * PubSub compile flags
  69. * --------------------
  70. *
  71. * **UA_ENABLE_PUBSUB**
  72. * Enable the experimental OPC UA PubSub support. The option will include the PubSub UDP multicast plugin. Disabled by default.
  73. * **UA_ENABLE_PUBSUB_DELTAFRAMES**
  74. * The PubSub messages differentiate between keyframe (all published values contained) and deltaframe (only changed values contained) messages.
  75. * Deltaframe messages creation consumes some additional ressources and can be disabled with this flag. Disabled by default.
  76. * Compile the human-readable name of the StatusCodes into the binary. Disabled by default.
  77. * **UA_ENABLE_PUBSUB_INFORMATIONMODEL**
  78. * Enable the information model representation of the PubSub configuration. For more details take a look at the following section `PubSub Information Model Representation`. Disabled by default.
  79. *
  80. * PubSub Information Model Representation
  81. * ---------------------------------------
  82. * .. _pubsub_informationmodel:
  83. *
  84. * The complete PubSub configuration is available inside the information model.
  85. * The entry point is the node 'PublishSubscribe, located under the Server node.
  86. * The standard defines for PubSub no new Service set. The configuration can optionally
  87. * done over methods inside the information model. The information model representation
  88. * of the current PubSub configuration is generated automatically. This feature
  89. * can enabled/disable by changing the UA_ENABLE_PUBSUB_INFORMATIONMODEL option.
  90. *
  91. * Connections
  92. * -----------
  93. * The PubSub connections are the abstraction between the concrete transport protocol
  94. * and the PubSub functionality. It is possible to create multiple connections with
  95. * different transport protocols at runtime.
  96. *
  97. * Take a look on the PubSub Tutorials for mor details about the API usage.
  98. */
  99. typedef enum {
  100. UA_PUBSUB_PUBLISHERID_NUMERIC,
  101. UA_PUBSUB_PUBLISHERID_STRING
  102. } UA_PublisherIdType;
  103. typedef struct {
  104. UA_String name;
  105. UA_Boolean enabled;
  106. UA_PublisherIdType publisherIdType;
  107. union { /* std: valid types UInt or String */
  108. UA_UInt32 numeric;
  109. UA_String string;
  110. } publisherId;
  111. UA_String transportProfileUri;
  112. UA_Variant address;
  113. size_t connectionPropertiesSize;
  114. UA_KeyValuePair *connectionProperties;
  115. UA_Variant connectionTransportSettings;
  116. } UA_PubSubConnectionConfig;
  117. UA_StatusCode UA_EXPORT
  118. UA_Server_addPubSubConnection(UA_Server *server,
  119. const UA_PubSubConnectionConfig *connectionConfig,
  120. UA_NodeId *connectionIdentifier);
  121. /* Returns a deep copy of the config */
  122. UA_StatusCode UA_EXPORT
  123. UA_Server_getPubSubConnectionConfig(UA_Server *server,
  124. const UA_NodeId connection,
  125. UA_PubSubConnectionConfig *config);
  126. /* Remove Connection, identified by the NodeId. Deletion of Connection
  127. * removes all contained WriterGroups and Writers. */
  128. UA_StatusCode UA_EXPORT
  129. UA_Server_removePubSubConnection(UA_Server *server, const UA_NodeId connection);
  130. /**
  131. * PublishedDataSets
  132. * -----------------
  133. * The PublishedDataSets (PDS) are containers for the published information. The
  134. * PDS contain the published variables and meta informations. The metadata is
  135. * commonly autogenerated or given as constant argument as part of the template
  136. * functions. The template functions are standard defined and intended for
  137. * configuration tools. You should normally create a empty PDS and call the
  138. * functions to add new fields. */
  139. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members and
  140. * thus no dedicated config structure. */
  141. typedef enum {
  142. UA_PUBSUB_DATASET_PUBLISHEDITEMS,
  143. UA_PUBSUB_DATASET_PUBLISHEDEVENTS,
  144. UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE,
  145. UA_PUBSUB_DATASET_PUBLISHEDEVENTS_TEMPLATE,
  146. } UA_PublishedDataSetType;
  147. typedef struct {
  148. UA_DataSetMetaDataType metaData;
  149. size_t variablesToAddSize;
  150. UA_PublishedVariableDataType *variablesToAdd;
  151. } UA_PublishedDataItemsTemplateConfig;
  152. typedef struct {
  153. UA_NodeId eventNotfier;
  154. UA_ContentFilter filter;
  155. } UA_PublishedEventConfig;
  156. typedef struct {
  157. UA_DataSetMetaDataType metaData;
  158. UA_NodeId eventNotfier;
  159. size_t selectedFieldsSize;
  160. UA_SimpleAttributeOperand *selectedFields;
  161. UA_ContentFilter filter;
  162. } UA_PublishedEventTemplateConfig;
  163. /* Configuration structure for PublishedDataSet */
  164. typedef struct {
  165. UA_String name;
  166. UA_PublishedDataSetType publishedDataSetType;
  167. union {
  168. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members
  169. * and thus no dedicated config structure.*/
  170. UA_PublishedDataItemsTemplateConfig itemsTemplate;
  171. UA_PublishedEventConfig event;
  172. UA_PublishedEventTemplateConfig eventTemplate;
  173. } config;
  174. } UA_PublishedDataSetConfig;
  175. void UA_EXPORT
  176. UA_PublishedDataSetConfig_deleteMembers(UA_PublishedDataSetConfig *pdsConfig);
  177. typedef struct {
  178. UA_StatusCode addResult;
  179. size_t fieldAddResultsSize;
  180. UA_StatusCode *fieldAddResults;
  181. UA_ConfigurationVersionDataType configurationVersion;
  182. } UA_AddPublishedDataSetResult;
  183. UA_AddPublishedDataSetResult UA_EXPORT
  184. UA_Server_addPublishedDataSet(UA_Server *server,
  185. const UA_PublishedDataSetConfig *publishedDataSetConfig,
  186. UA_NodeId *pdsIdentifier);
  187. /* Returns a deep copy of the config */
  188. UA_StatusCode UA_EXPORT
  189. UA_Server_getPublishedDataSetConfig(UA_Server *server, const UA_NodeId pds,
  190. UA_PublishedDataSetConfig *config);
  191. /* Remove PublishedDataSet, identified by the NodeId. Deletion of PDS removes
  192. * all contained and linked PDS Fields. Connected WriterGroups will be also
  193. * removed. */
  194. UA_StatusCode UA_EXPORT
  195. UA_Server_removePublishedDataSet(UA_Server *server, const UA_NodeId pds);
  196. /**
  197. * DataSetFields
  198. * -------------
  199. * The description of published variables is named DataSetField. Each
  200. * DataSetField contains the selection of one information model node. The
  201. * DataSetField has additional parameters for the publishing, sampling and error
  202. * handling process. */
  203. typedef struct{
  204. UA_ConfigurationVersionDataType configurationVersion;
  205. UA_String fieldNameAlias;
  206. UA_Boolean promotedField;
  207. UA_PublishedVariableDataType publishParameters;
  208. } UA_DataSetVariableConfig;
  209. typedef enum {
  210. UA_PUBSUB_DATASETFIELD_VARIABLE,
  211. UA_PUBSUB_DATASETFIELD_EVENT
  212. } UA_DataSetFieldType;
  213. typedef struct {
  214. UA_DataSetFieldType dataSetFieldType;
  215. union {
  216. /* events need other config later */
  217. UA_DataSetVariableConfig variable;
  218. } field;
  219. } UA_DataSetFieldConfig;
  220. void UA_EXPORT
  221. UA_DataSetFieldConfig_deleteMembers(UA_DataSetFieldConfig *dataSetFieldConfig);
  222. typedef struct {
  223. UA_StatusCode result;
  224. UA_ConfigurationVersionDataType configurationVersion;
  225. } UA_DataSetFieldResult;
  226. UA_DataSetFieldResult UA_EXPORT
  227. UA_Server_addDataSetField(UA_Server *server,
  228. const UA_NodeId publishedDataSet,
  229. const UA_DataSetFieldConfig *fieldConfig,
  230. UA_NodeId *fieldIdentifier);
  231. /* Returns a deep copy of the config */
  232. UA_StatusCode UA_EXPORT
  233. UA_Server_getDataSetFieldConfig(UA_Server *server, const UA_NodeId dsf,
  234. UA_DataSetFieldConfig *config);
  235. UA_DataSetFieldResult UA_EXPORT
  236. UA_Server_removeDataSetField(UA_Server *server, const UA_NodeId dsf);
  237. /**
  238. * WriterGroup
  239. * -----------
  240. * All WriterGroups are created within a PubSubConnection and automatically
  241. * deleted if the connection is removed. The WriterGroup is primary used as
  242. * container for :ref:`dsw` and network message settings. The WriterGroup can be
  243. * imagined as producer of the network messages. The creation of network
  244. * messages is controlled by parameters like the publish interval, which is e.g.
  245. * contained in the WriterGroup. */
  246. typedef enum {
  247. UA_PUBSUB_ENCODING_BINARY,
  248. UA_PUBSUB_ENCODING_JSON,
  249. UA_PUBSUB_ENCODING_UADP
  250. } UA_PubSubEncodingType;
  251. typedef struct {
  252. UA_String name;
  253. UA_Boolean enabled;
  254. UA_UInt16 writerGroupId;
  255. UA_Duration publishingInterval;
  256. UA_Double keepAliveTime;
  257. UA_Byte priority;
  258. UA_MessageSecurityMode securityMode;
  259. UA_ExtensionObject transportSettings;
  260. UA_ExtensionObject messageSettings;
  261. size_t groupPropertiesSize;
  262. UA_KeyValuePair *groupProperties;
  263. UA_PubSubEncodingType encodingMimeType;
  264. /* non std. config parameter. maximum count of embedded DataSetMessage in
  265. * one NetworkMessage */
  266. UA_UInt16 maxEncapsulatedDataSetMessageCount;
  267. } UA_WriterGroupConfig;
  268. void UA_EXPORT
  269. UA_WriterGroupConfig_deleteMembers(UA_WriterGroupConfig *writerGroupConfig);
  270. /* Add a new WriterGroup to an existing Connection */
  271. UA_StatusCode UA_EXPORT
  272. UA_Server_addWriterGroup(UA_Server *server, const UA_NodeId connection,
  273. const UA_WriterGroupConfig *writerGroupConfig,
  274. UA_NodeId *writerGroupIdentifier);
  275. /* Returns a deep copy of the config */
  276. UA_StatusCode UA_EXPORT
  277. UA_Server_getWriterGroupConfig(UA_Server *server, const UA_NodeId writerGroup,
  278. UA_WriterGroupConfig *config);
  279. UA_StatusCode UA_EXPORT
  280. UA_Server_updateWriterGroupConfig(UA_Server *server, UA_NodeId writerGroupIdentifier,
  281. const UA_WriterGroupConfig *config);
  282. UA_StatusCode UA_EXPORT
  283. UA_Server_removeWriterGroup(UA_Server *server, const UA_NodeId writerGroup);
  284. /**
  285. * .. _dsw:
  286. *
  287. * DataSetWriter
  288. * -------------
  289. * The DataSetWriters are the glue between the WriterGroups and the
  290. * PublishedDataSets. The DataSetWriter contain configuration parameters and
  291. * flags which influence the creation of DataSet messages. These messages are
  292. * encapsulated inside the network message. The DataSetWriter must be linked
  293. * with an existing PublishedDataSet and be contained within a WriterGroup. */
  294. typedef struct {
  295. UA_String name;
  296. UA_UInt16 dataSetWriterId;
  297. UA_DataSetFieldContentMask dataSetFieldContentMask;
  298. UA_UInt32 keyFrameCount;
  299. UA_ExtensionObject messageSettings;
  300. UA_String dataSetName;
  301. size_t dataSetWriterPropertiesSize;
  302. UA_KeyValuePair *dataSetWriterProperties;
  303. } UA_DataSetWriterConfig;
  304. void UA_EXPORT
  305. UA_DataSetWriterConfig_deleteMembers(UA_DataSetWriterConfig *pdsConfig);
  306. /* Add a new DataSetWriter to a existing WriterGroup. The DataSetWriter must be
  307. * coupled with a PublishedDataSet on creation.
  308. *
  309. * Part 14, 7.1.5.2.1 defines: The link between the PublishedDataSet and
  310. * DataSetWriter shall be created when an instance of the DataSetWriterType is
  311. * created. */
  312. UA_StatusCode UA_EXPORT
  313. UA_Server_addDataSetWriter(UA_Server *server,
  314. const UA_NodeId writerGroup, const UA_NodeId dataSet,
  315. const UA_DataSetWriterConfig *dataSetWriterConfig,
  316. UA_NodeId *writerIdentifier);
  317. /* Returns a deep copy of the config */
  318. UA_StatusCode UA_EXPORT
  319. UA_Server_getDataSetWriterConfig(UA_Server *server, const UA_NodeId dsw,
  320. UA_DataSetWriterConfig *config);
  321. UA_StatusCode UA_EXPORT
  322. UA_Server_removeDataSetWriter(UA_Server *server, const UA_NodeId dsw);
  323. /**
  324. * DataSetReader
  325. * -------------
  326. * DataSetReader can receive NetworkMessages with the DataSet
  327. * of interest sent by the Publisher. DataSetReaders represent
  328. * the configuration necessary to receive and process DataSetMessages
  329. * on the Subscriber side */
  330. /* Parameters for PubSubSecurity */
  331. typedef struct {
  332. UA_Int32 securityMode; /* placeholder datatype 'MessageSecurityMode' */
  333. UA_String securityGroupId;
  334. size_t keyServersSize;
  335. UA_Int32 *keyServers;
  336. } UA_PubSubSecurityParameters;
  337. /* Parameters for PubSub DataSetReader Configuration */
  338. typedef struct {
  339. UA_String name;
  340. UA_Variant publisherId;
  341. UA_UInt16 writerGroupId;
  342. UA_UInt16 dataSetWriterId;
  343. UA_DataSetMetaDataType dataSetMetaData;
  344. UA_DataSetFieldContentMask dataSetFieldContentMask;
  345. UA_Double messageReceiveTimeout;
  346. UA_PubSubSecurityParameters securityParameters;
  347. UA_UadpDataSetReaderMessageDataType messageSettings;
  348. UA_TargetVariablesDataType subscribedDataSetTarget;
  349. } UA_DataSetReaderConfig;
  350. /* Update configuration to the dataSetReader */
  351. UA_StatusCode
  352. UA_Server_DataSetReader_updateConfig(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
  353. UA_NodeId readerGroupIdentifier, const UA_DataSetReaderConfig *config);
  354. /* Get configuration of the dataSetReader */
  355. UA_StatusCode
  356. UA_Server_DataSetReader_getConfig(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
  357. UA_DataSetReaderConfig *config);
  358. /* Return Status Code after creating TargetVariables in Subscriber AddressSpace
  359. * TargetVariables define a list of variable mappings between received DataSet fields
  360. * and the TargetVariables in the Subscriber AddressSpace */
  361. UA_StatusCode
  362. UA_Server_DataSetReader_createTargetVariables(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
  363. UA_TargetVariablesDataType* targetVariables);
  364. /* To Do:Implementation of SubscribedDataSetMirrorType
  365. * UA_StatusCode
  366. * A_PubSubDataSetReader_createDataSetMirror(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
  367. * UA_SubscribedDataSetMirrorDataType* mirror) */
  368. /**
  369. * ReaderGroup
  370. * -----------
  371. * All ReaderGroups are created within a PubSubConnection and automatically
  372. * deleted if the connection is removed. */
  373. /* ReaderGroup configuration */
  374. typedef struct {
  375. UA_String name;
  376. UA_PubSubSecurityParameters securityParameters;
  377. } UA_ReaderGroupConfig;
  378. /* Add DataSetReader to the ReaderGroup */
  379. UA_StatusCode
  380. UA_Server_addDataSetReader(UA_Server *server, UA_NodeId readerGroupIdentifier,
  381. const UA_DataSetReaderConfig *dataSetReaderConfig,
  382. UA_NodeId *readerIdentifier);
  383. /* Remove DataSetReader from ReaderGroup */
  384. UA_StatusCode
  385. UA_Server_removeDataSetReader(UA_Server *server, UA_NodeId readerIdentifier);
  386. /* To Do: Update Configuration of ReaderGroup */
  387. UA_StatusCode
  388. UA_Server_ReaderGroup_updateConfig(UA_Server *server, UA_NodeId readerGroupIdentifier,
  389. const UA_ReaderGroupConfig *config);
  390. /* Get configuraiton of ReaderGroup */
  391. UA_StatusCode
  392. UA_Server_ReaderGroup_getConfig(UA_Server *server, UA_NodeId readerGroupIdentifier,
  393. UA_ReaderGroupConfig *config);
  394. /* Add ReaderGroup to the created connection */
  395. UA_StatusCode
  396. UA_Server_addReaderGroup(UA_Server *server, UA_NodeId connectionIdentifier,
  397. const UA_ReaderGroupConfig *readerGroupConfig,
  398. UA_NodeId *readerGroupIdentifier);
  399. /* Remove ReaderGroup from connection */
  400. UA_StatusCode
  401. UA_Server_removeReaderGroup(UA_Server *server, UA_NodeId groupIdentifier);
  402. #endif /* UA_ENABLE_PUBSUB */
  403. _UA_END_DECLS
  404. #endif /* UA_SERVER_PUBSUB_H */