AddNodes service: support automatic creation of TypeDefinitionNode hierarchy for Variable/Object
Description
Main feature
When adding Variable and Object node, automatically create the TypeDefinitionNode hierarchy of Nodes beneath the new Object or Variable depending on the ModellingRule of each InstanceDeclaration.
Additional features
- The node ids might now be generated for the root node added and are generated for the children nodes. NS index 1 is used, unless the root node id provided is set. In this latter case the same NS index than the root node is used.
- The reciprocal reference from TypeDefinition node to the new instance node is now automatically added unless
S2OPC_NODE_ADD_INVERSE_TYPEDEFis set to FALSE at compile time.
OPC UA specification reference
As specified in part 4 (v1.05.04) §5.8.2.1 AddNodes section:
When a Server creates an instance of a TypeDefinitionNode it shall create the same hierarchy of Nodes beneath the new Object or Variable depending on the ModellingRule of each InstanceDeclaration. All Nodes with a ModellingRule of Mandatory shall be created or an existing Node shall be referenced that conforms to the InstanceDeclaration. The creation of Nodes with other ModellingRules is Server specific.
Implementation choices
- Only children with an 'Aggregates' reference type or sub-type are added. Children with 'Organizes' and 'HasEventSource' reference types are ignored.
- Optional nodes can also be added by setting S2OPC_NODE_ADD_OPTIONAL to TRUE at compile time.
- A failure in child nodes creation lead to a partial creation of the hierarchy, no rollback is done in case of error and failure of operation only occurs in case of the root node creation error.
Note: creation of node types (ObjectType, VariableType, DataType, ReferenceType) remain unsupported.
Code version identification
Current behavior
AddNodes service only adds the single node requested even if the node TypeDefinition provides a hierarchy with Mandatory modelling rule child nodes. AddNodes service only accept to create a node when the requested NodeId is provided by the caller.
Expected behavior
AddNodes service adds the node requested by user and all its children depending on the type definition of the new node added (specific to Variable and Object nodes).
Only the children nodes with mandatory modelling rule in the TypeDefinition are added by default. By setting the S2OPC_NODE_ADD_OPTIONAL compilation variable to TRUE, optional modelling rule ones are also added.
References between an added node and its type are added reciprocally, you can disable the reciprocal reference from type to instance node by setting the compilation variable S2OPC_NODE_ADD_INVERSE_TYPEDEF to FALSE.
Security impact
N/A
Implementation
Principle:
- Add the root node requested to be added by service operation
- Browse the TypeDefinition hierarchy of the variable/object node added recursively and add the child nodes with a mandatory modelling rule (and optional if option
S2OPC_NODE_ADD_OPTIONALis set):- NodeIds are generated in the same NS index than the root node
- Recursion limit is enforced when adding child nodes
NodeId generation principle:
- During initialization of address space in server configuration, the maximum numerical NodeId is sotred
- When generating a new node id, the maximum numerical NodeId + 1 is used and recorded.
- In case of failure (NodeId already used) the operation is repeated until success or maximum number of attempts
SOPC_FRESH_NODEID_MAX_RETRIESis reached. The maximum is computed with moduloUINT32_MAX.
API:
- Add a flag for adding child nodes in AddressSpaceAccess module (accessible to user in MethodCall callback implementation)
- For AddNodes service LOCAL only use in server
S2OPC_NODE_INTERNAL_ADD_CHILD_NODEScan be set to FALSE at compile time to deactivate the automatic creation of child nodes based on TypeDefinition hierarchy. - A status code Uncertain is returned by add node object/variable functions in case the requested node has been created but (partial) failure occurred in creation of child nodes based on TypeDefinition hierarchy. In this latter case, additional information is available in the log warning traces.