Git Product home page Git Product logo

open62541-nodeset-loader's Introduction

open62541

open62541 (http://open62541.org) is an open source implementation of OPC UA (OPC Unified Architecture / IEC 62541) written in the C language. The library is usable with all major compilers and provides the necessary tools to implement dedicated OPC UA clients and servers, or to integrate OPC UA-based communication into existing applications. The open62541 library is platform independent: All platform-specific functionality is implemented via exchangeable plugins for easy porting to different (embedded) targets.

open62541 is licensed under the Mozilla Public License v2.0 (MPLv2). This allows the open62541 library to be combined and distributed with any proprietary software. Only changes to the open62541 library itself need to be licensed under the MPLv2 when copied and distributed. The plugins, as well as the server and client examples are in the public domain (CC0 license). They can be reused under any license and changes do not have to be published.

The library is available in standard source and binary form. In addition, the single-file source distribution merges the entire library into a single .c and .h file that can be easily added to existing projects. Example server and client implementations can be found in the /examples directory or further down on this page.

Open Hub Project Status Build Status Build Status Code Scanning Fuzzing Status codecov

Features

open62541 implements an OPC UA SDK with support for servers, clients and PubSub (publish-subscribe) communication. See the features overview for full details.

  • Core Stack
    • OPC UA binary and JSON encoding
    • TCP-based OPC UA SecureChannel
    • Custom data types (generated from XML definitions)
    • Portable C99 -- architecture-specific code is encapsulated behind standard interfaces
    • Highly configurable with default plugins for encryption (OpenSSL, mbedTLS), access control, historizing, logging, etc.
  • Server
    • Support for all OPC UA services (except the Query service -- not implemented by any SDK)
    • Support for generating information models from standard XML definitions (Nodeset Compiler)
    • Support for adding and removing nodes and references at runtime
    • Support for subscriptions (data-change and event notifications)
  • Client
    • Support for all OPC UA services
    • Support for asynchronous service requests
    • Background handling of subscriptions
  • PubSub
    • PubSub message encoding (binary and JSON)
    • Transport over UDP-multicast, Ethernet, MQTT
    • Runtime configuration via the information model
    • Configurable realtime fast-path

Commercial Use and Official Support

open62541 is licensed under the MPLv2. That is, changes to files under MPLv2 fall under the same open-source license. But the library can be combined with private development from separate files, also if a static binary is produced, without the license affecting the private files. See the full license document for details.

Fraunhofer IOSB maintains open62541 and provides official commercial support. Additional service providers are listed on open62541.org.

Official Certification

The sample server (server_ctt) built using open62541 v1.0 is in conformance with the 'Micro Embedded Device Server' Profile of OPC Foundation supporting OPC UA client/server communication, subscriptions, method calls and security (encryption) with the security policies 'Basic128Rsa15', 'Basic256' and 'Basic256Sha256' and the facets 'method server' and 'node management'. See https://open62541.org/certified-sdk for more details.

PubSub (UADP) is implemented in open62541. But the feature cannot be certified at this point in time (Sep-2019) due to the lack of official test cases and testing tools.

During development, the Conformance Testing Tools (CTT) of the OPC Foundation are regularly applied. The CTT configuration and results are tracked at https://github.com/open62541/open62541-ctt. The OPC UA profiles under regular test in the CTT are currently:

  • Micro Embedded Device Server
  • Method Server Facet
  • Node Management Facet
  • Security Policies
    • Basic128Rsa15
    • Basic256
    • Basic256Sha256
  • User Tokens
    • Anonymous Facet
    • User Name Password Server Facet

See the page on open62541 Features for an in-depth look at the support for the conformance units that make up the OPC UA profiles.

Documentation and Support

A general introduction to OPC UA and the open62541 documentation can be found at http://open62541.org. Past releases of the library can be downloaded at https://github.com/open62541/open62541/releases.

The overall open62541 community handles public support requests on Github and the mailing list. For individual discussion and support, use the following channels:

We want to foster an open and welcoming community. Please take our code of conduct into regard.

Development

As an open source project, new contributors are encouraged to help improve open62541. The file CONTRIBUTING.md aggregates good practices that we expect for code contributions. The following are good starting points for new contributors:

For custom development that shall eventually become part of the open62541 library, please keep one of the core maintainers in the loop.

Dependencies

On most systems, open62541 requires the C standard library only. For dependencies during the build process, see the following list and the build documentation for details.

  • Core Library: The core library has no dependencies besides the C99 standard headers.
  • Default Plugins: The default plugins use the POSIX interfaces for networking and accessing the system clock. Ports to different (embedded) architectures are achieved by customizing the plugins.
  • Building and Code Generation: The build environment is generated via CMake. Some code is auto-generated from XML definitions that are part of the OPC UA standard. The code generation scripts run with both Python 2 and 3.

Note: Some (optional) features are dependent on third-party libraries. These are all listed under the deps/ folder. Depending on the selected feature set, some of these libraries will be included in the resulting library. More information on the third-party libraries can be found in the corresponding deps/README.md

Code Quality

We emphasize code quality. The following quality metrics are continuously checked and are ensured to hold before an official release is made:

  • Zero errors indicated by the Compliance Testing Tool (CTT) of the OPC Foundation for the supported features
  • Zero compiler warnings from GCC/Clang/MSVC with very strict compilation flags
  • Zero issues indicated by unit tests (more than 80% coverage)
  • Zero issues indicated by clang-analyzer, clang-tidy, cpp-check and the Codacy static code analysis tools
  • Zero unresolved issues from fuzzing the library in Google's oss-fuzz infrastructure
  • Zero issues indicated by Valgrind (Linux), DrMemory (Windows) and Clang AddressSanitizer / MemorySanitizer for the CTT tests, unit tests and fuzzing

Installation and code usage

For every release, we provide some pre-packed release packages which you can directly use in your compile infrastructure.

Have a look at the release page and the corresponding attached assets.

A more detailed explanation on how to install the open62541 SDK is given in our documentation. In essence, clone the repository and initialize all the submodules using git submodule update --init --recursive. Then use CMake to configure your build.

Furthermore we provide "pack branches" that are up-to-date with the corresponding base branches, and in addition have the git submodules in-place for a zip download. Here are some direct download links for the current pack branches:

Examples

A complete list of examples can be found in the examples directory. To build the examples, we recommend to install open62541 as mentioned in the previous section. Using the GCC compiler, just run gcc -std=c99 <server.c> -lopen62541 -o server (under Windows you may need to add additionally link against the ws2_32 socket library).

Example Server Implementation

#include <open62541/server.h>

int main(int argc, char** argv)
{
    /* Create a server listening on port 4840 (default) */
    UA_Server *server = UA_Server_new();

    /* Add a variable node to the server */

    /* 1) Define the variable attributes */
    UA_VariableAttributes attr = UA_VariableAttributes_default;
    attr.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");
    UA_Int32 myInteger = 42;
    UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);

    /* 2) Define where the node shall be added with which browsename */
    UA_NodeId newNodeId = UA_NODEID_STRING(1, "the.answer");
    UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
    UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
    UA_NodeId variableType = UA_NODEID_NULL; /* take the default variable type */
    UA_QualifiedName browseName = UA_QUALIFIEDNAME(1, "the answer");

    /* 3) Add the node */
    UA_Server_addVariableNode(server, newNodeId, parentNodeId,
                              parentReferenceNodeId, browseName,
                              variableType, attr, NULL, NULL);

    /* Run the server (until ctrl-c interrupt) */
    UA_StatusCode status = UA_Server_runUntilInterrupt(server);

    /* Clean up */
    UA_Server_delete(server);
    return status == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

Example Client Implementation

#include <stdio.h>
#include <open62541/client.h>
#include <open62541/client_highlevel.h>

int main(int argc, char *argv[])
{
    /* Create a client and connect */
    UA_Client *client = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));
    UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840");
    if(status != UA_STATUSCODE_GOOD) {
        UA_Client_delete(client);
        return status;
    }

    /* Read the value attribute of the node. UA_Client_readValueAttribute is a
     * wrapper for the raw read service available as UA_Client_Service_read. */
    UA_Variant value; /* Variants can hold scalar values and arrays of any type */
    UA_Variant_init(&value);
    status = UA_Client_readValueAttribute(client, UA_NODEID_STRING(1, "the.answer"), &value);
    if(status == UA_STATUSCODE_GOOD &&
       UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_INT32])) {
        printf("the value is: %i\n", *(UA_Int32*)value.data);
    }

    /* Clean up */
    UA_Variant_clear(&value);
    UA_Client_delete(client); /* Disconnects the client internally */
    return status == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

open62541-nodeset-loader's People

Contributors

cldhms avatar goetzgoerisch avatar johanneskauffmann avatar jonasgreen88 avatar jpfr avatar keba-uso avatar martinafelberfem avatar matkonnerth avatar mtyndel avatar murzynj avatar noelgraf avatar paddor avatar rdyhms avatar tobydox avatar xydan83 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

open62541-nodeset-loader's Issues

node overflow is not checked

Currently all sorted nodes are referenced in statically allocated arrays, size of the arrays is defined at compile time. If there are more nodes in the xml than the array size, the import segfaults.

Solution would be to reallocate if the array size is reached.

integrationClient: segfault with release build

started with:
~/git/nodesetLoader/build$ gdb --args backends/open62541/tests/integration/client/integrationClient localhost 4840 out.txt

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7e9187c in UA_NodeId_order (n1=, n2=, n1=, n2=) at /home/matzy/git/open62541/src/ua_types.c:329
329 if(n1->namespaceIndex < n2->namespaceIndex)

branch master with 8a4c6a8

open Backend: use the available information model

At the moment there is a hardcoded list with the hierachical referencetypes stored in the nodeset. Every new referencetype is checked with this list, if it's a subtype of an existing hierachical reference.

If multiple nodesets are loaded, and one of them introduces a new hierachical referencetype, this information gets lost when a new nodeset gets loaded.

example:
nodeset A: introduces new hierachical ReferenceType, typenode is added to addressspace
nodeset B: has reference using this hierachical referenceType node, but this information is not known to the nodeset at the moment

Solution would be to provide the known hierachical references upfront to the nodesetloader.

This todo is related to this issue:
https://github.com/matkonnerth/nodesetLoader/blob/8ef217938fef65570c759d5b8c7bbe7a683da583/src/Nodeset.c#L473

PLCopen nodeset import does not work

It seems that PLCopen nodeset import does not work anymore ?
I have tested with current master. f238d09

Function NodesetLoader_loadFile() returns true
There are no error messages or warnings.

Nodeset DI and testNodeSet.xml could be loaded.
But PLCopen namespace is missing

image

Can you confirm?

todos in productive code -> fix and remove them

backends/open62541/src/Value.c: // TODO: translate namespaceIndex?
backends/open62541/src/Value.c: // TODO: arrays not implemented in frontend
backends/open62541/src/DataTypeImporter.c: // TODO: possible an endless loop
backends/open62541/src/DataTypeImporter.c: // TODO: can we to this in a more clever way?

tests/sort.c://todo: fix this test, memleak in sort nodes
backends/open62541/src/import.c: // todo: is this really necessary??

fix compiler warnings

xmlparser.c:426:31: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
SAXHandler.startElementNs = OnStartElementNs;

assignments
xmlchar* xmlChar;
char* tmp = xmlChar; <--- fix this, do a correct decoding

Description attribute is missing

Sometimes description attribute is missing.
Tested with DI nodeset.
E.g. node: BaseObjectType - TopologyElementType - GroupIdentifier

reference server:
image

test server:
image

ReferenceTypes: Attributes InverseName and Symmetric

Hi!

I think the referencetype attributes InverseName and Symmetric are not properly set.

reference server:
image
Symmetric = false

test server:
image
Symmetric = true

Other examples:
DI nodeset:
Id = ns=2;i=6031 REFERENCETYPE
BrowseName = ns=2;IsOnline

PLCopen:
Id = ns=3;i=4001 REFERENCETYPE
Id = ns=3;i=4002 REFERENCETYPE
Id = ns=3;i=4003 REFERENCETYPE
Id = ns=3;i=4004 REFERENCETYPE
...

EM83: Integration test found difference in JobListElementType

Now it gets interesting, the integration test looks with a big magnifier onto the implementations;)

reference server:

[
Name = PlannedProductionTime
Description = :
DataType = i=11
ValueRank = -1
ArrayDimensions = []
MaxStringLength = 0
IsOptional = 0
]

[
Name = PlannedProductionTime
Description = :
DataType = i=290
ValueRank = -1
ArrayDimensions = []
MaxStringLength = 0
IsOptional = 0
]

Duration is a SubDataType of Double and explicit stated in the nodeset xml:

Planned production time

But in the .bsd there is a the PlannedProductionTime a opc:Double

<opc:StructuredType BaseType="ua:ExtensionObject" Name="JobListElementType">
opc:DocumentationDescription of a job in a job list</opc:Documentation>
<opc:Field TypeName="opc:CharArray" Name="JobName"/>
<opc:Field TypeName="opc:CharArray" Name="JobDescription"/>
<opc:Field TypeName="opc:CharArray" Name="JobClassification"/>
<opc:Field TypeName="opc:CharArray" Name="CustomerName"/>
<opc:Field TypeName="opc:CharArray" Name="ProductionDatasetName"/>
<opc:Field TypeName="opc:CharArray" Name="ProductionDatasetDescription"/>
<opc:Field TypeName="opc:Int32" Name="NoOfMaterial"/>
<opc:Field LengthField="NoOfMaterial" TypeName="opc:CharArray" Name="Material"/>
<opc:Field TypeName="opc:Int32" Name="NoOfProductName"/>
<opc:Field LengthField="NoOfProductName" TypeName="opc:CharArray" Name="ProductName"/>
<opc:Field TypeName="opc:Int32" Name="NoOfProductDescription"/>
<opc:Field LengthField="NoOfProductDescription" TypeName="opc:CharArray" Name="ProductDescription"/>
<opc:Field TypeName="opc:CharArray" Name="JobPriority"/>
<opc:Field TypeName="opc:DateTime" Name="PlannedStart"/>
<opc:Field TypeName="opc:Double" Name="PlannedProductionTime"/>
<opc:Field TypeName="opc:DateTime" Name="LatestEnd"/>
</opc:StructuredType>

From the encoding point of view there is no difference

@MartinaFelberFEM : What's your opinion?

NodeSet with multiple namespaces

Support for multiple namespaces needed?
1 NodeSet contains 2 or more new namespaces.
E.g.: Euromap83 and Euromap77 within 1 XML

Handling of values with types > namespace zero

At the moment value are currently added to the Variable node during parsing of the nodes. This is only possible for values with already known dataypes, e.g. values with namespace 0 datatypes. To support also values with custom datatypes, first all datatypes must be parsed in. A solution would be to parse in all datatypes, and afterwards do the value conversion.

Euromap test: EventNotifier attribute

I think the nodesetLoader does not set the EventNotifier attribute correctly.
At least it does not match with the reference server.
Tested with branch euormap_test

E.g. Object ProductionDatasetLists: BaseObjectType/ProductionDataSetManagementType/ProductionDataSetLists

reference server: EventNotifier = SubscribeToEvents
image

test server: EventNotifier = None
image

xml Definition: Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml

    <UAObject ParentNodeId="ns=1;i=1008" EventNotifier="1" NodeId="ns=1;i=5007" BrowseName="1:ProductionDatasetLists">
        <DisplayName>ProductionDatasetLists</DisplayName>
        <Description>Functions for exchanging information on the available production datasets on client and server</Description>
        <References>
            <Reference ReferenceType="HasComponent">ns=1;i=7005</Reference>
            <Reference ReferenceType="HasModellingRule">i=80</Reference>
            <Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=1008</Reference>
            <Reference ReferenceType="HasTypeDefinition">ns=1;i=1003</Reference>
            <Reference ReferenceType="GeneratesEvent">ns=1;i=1040</Reference>
            <Reference ReferenceType="HasComponent">ns=1;i=7006</Reference>
        </References>
    </UAObject>

The XML definition does not specify the EventNotifier attribute ...
How can you know if you have to set the EventNotifier attribute?
Maybe you have to set it, if the node is of class Object and it has a GeneratesEvent reference?

How can you know if you have to set the EventNotifier attribute for historizing events? (HistoryRead/HistoryWrite)

isAbstract Attribute not set on DataTypes

output from integrationTest:

referenceServer
Id = ns=2;i=6522 DATATYPE
BrowseName = ns=2;FetchResultDataType
DisplayName = :FetchResultDataType
Description = :
WriteMask = 0
UserWriteMask = 0
IsAbstract = 1
DataTypeDefinition =
References: | i=38 ; ns=2;i=6535 | | i=38 ; ns=2;i=6551 | | i=38 ; ns=2;i=15909 | | i=45

testServer
Id = ns=2;i=6522 DATATYPE
BrowseName = ns=2;FetchResultDataType
DisplayName = :FetchResultDataType
Description = :
WriteMask = 0
UserWriteMask = 0
IsAbstract = 0
DataTypeDefinition =
References: | i=38 ; ns=2;i=6535 | | i=38 ; ns=2;i=6551 | | i=38 ; ns=2;i=15909 | | i=45 ;

support multiple nodeset files

For example

namespace 0: opcfoundation
namespace 1: server internal
namespace 2: DI
namespace 3: PlcOpen

should be supported.

Euromap test: "double free or corruption" at server shutdown

Tested with euromap_test branch.
./testServer "$NODESET_PATH_OPEN62541/DI/Opc.Ua.Di.NodeSet2.xml" "$NODESET_PATH_OPEN62541/PLCopen/Opc.Ua.Plc.NodeSet2.xml" "$NODESET_PATH_BACKEND_TESTS/euromap/Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml" "$NODESET_PATH_BACKEND_TESTS/euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml"

Get following output at server shutdown:
[2020-05-11 21:13:06.427 (UTC+0200)] info/network Shutting down the TCP network layer
double free or corruption (!prev)
Aborted (core dumped)

This does not happen when I only load DI and PLCopen nodesets.

valgrind command and output:
valgrind --tool=memcheck --leak-check=full --track-origins=yes --undef-value-errors=yes --show-leak-kinds=all --leak-resolution=high --num-callers=30 ./testServer $NODESET_PATH_OPEN62541/DI/Opc.Ua.Di.NodeSet2.xml $NODESET_PATH_OPEN62541/PLCopen/Opc.Ua.Plc.NodeSet2.xml $NODESET_PATH_BACKEND_TESTS/euromap/Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml $NODESET_PATH_BACKEND_TESTS/euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml

valgrind_euromap_double_free.txt

It seems that there are invalid reads/writes

openBackend: interface dataType import

Currently all memory that the nodesetLoader allocates is also freed by himself, but not in the case, when DataTypes are imported. In this case the, the DataTypeImporter allocates memory for the custom dataTypes and sets the ptr of serverconfig->customDataTypes. The nodesetLoader cannot free up this memory, because it's needed later on for encoding/decoding.

So the question is, if the user of the library should setup upfront the customDataTypeArray and the nodesetLoader uses this memory. If no memory is provided, no dataTypes will be imported (the nodes will be imported, but there will be no UA_DataType for it).

This requires no change of the interface, because the memory could be provided via serverConfig->customDataTypes.

DataType nodes: DataTypeDefinition test

Summary of open questions/issues regarding DataType nodes and their DataTypeDefinition attribute:

Regarding to OpcUa spec 3 the DataTypeDefinition attribute is optional unless the node is

  • derived from Structure
  • derived from Enumeration
  • derived from OptionSet
  • derived from Unsigned integer and provides a HasProperty reference with OptionSetValues reference

image

It seems, that namespace 0 violates the specification, because following nodes of namespace 0, do not provide the DataTypeDefinition attribute:

  • all types derived from Enumeration

  • the DataTypeDefinition structure itself -> we are not sure if this is the case, because the DataType is abstract
    image

  • in general we are not sure if abstract DataType nodes have to provide this attribute or not

TODO: check if other reference server provides the DataTypeDefinition attributes. check if nodeset-compiler has an open issue

Test client: remove duplicate Event types from output

Reference Server:

Addressspace output of reference server seems strange, as there are some nodeIds twice in the output.
E.g.:
Id = ns=4;i=6012 VARIABLE
BrowseName = ns=4;RemoteUserName

Test Server:
BrowseResponse - responseHeader serviceResult is Bad (BadDecodingError) when browsing the test server address space.

Error BrowseReferences failed. Id = ns=4;i=6013
Test finished: failure

This starts one numeric NodeId after the strange double Ids in the output? ns=4;i=6012

Support for structured dataTypes

Currently structured datatypes are supported, but there are no tests or implementation for this cases:

  • Inherit from a custom structured dataType
  • Inherit from a namespace 0 dataType

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.