Search and contents

A file-driven OPC UA test server

A small server that offers exactly the OPC UA nodes listed in a text file. It is for standing up a stand-in for a plant's OPC UA server while you build or test a config, so a Node's OPC UA connector (see mes-node-type-opc-ua.md) has nodes to read before the real plant is reachable. It uses the same open62541 library as the sidecar, and adds no other.

This is test tooling, not part of the public API. The options, the file format and the exit codes may change in any release, and the stability policy (public-api-stability.md) does not cover them. It is built where it is wanted and is never installed or provisioned on an appliance.

It speaks Security Policy None only, with anonymous access, on every interface. Run it on a machine and network you trust.

Building it

It needs the open62541 that deployment/install_open62541.sh installs on an appliance, and cmake with a C compiler. From the repository root:

sidecar/node_server/build.sh            # open62541 under /usr/local
sidecar/node_server/build.sh /opt/ua    # open62541 under another prefix

The program is left at sidecar/node_server/build/kindred-opcua-node-server. Nothing is installed.

Setup and the commands in this document

Every command below runs as written once this block has been run in the same shell. It makes a node file and a file with a mistake in it. The commands run from the repository root with the server built.

WORK=$(mktemp -d)
SERVER=sidecar/node_server/build/kindred-opcua-node-server
cat > "$WORK/nodes.txt" <<'NODES'
# id                    type    access  browse name   value
ns=2;s=Line1.State      string  ro      State         RUN
ns=2;s=Line1.Count      uint32  tick    Count         0
ns=2;s=Line1.Setpoint   double  rw      Setpoint      72.5
ns=2;s=Line1.Enabled    boolean ro      Enabled       true
ns=3;i=1001             int16   ro      Offset        -40
NODES
echo 'ns=2;s=Line1.State  uint8  ro  State' > "$WORK/bad.txt"

The node file

One node per line, in this order, separated by spaces or tabs:

<node id>  <type>  <access>  <browse name>  [value]

Blank lines are skipped, and so is a line whose first character after any spaces is #. A byte order mark at the start of the file is ignored. Every node is a single value (not an array) that sits directly under the Objects folder.

FieldMeaning
node id ns=N;i=NUMBER, ns=N;s=TEXT, ns=N;g=GUID or ns=N;b=BASE64, the forms a connector's node_id takes. The namespace index is 1 to 100, and the namespaces up to the highest one used are created. The id cannot contain a space. Two lines cannot share an id.
type One of boolean, int16, uint16, int32, uint32, int64, uint64, float, double, string: the types the sidecar reads.
access ro is read-only. rw can be written by another OPC UA client. tick is read-only and counts up by 1 every interval, for a type that is a number, so that a subscription sees changes. A whole-number type wraps around at the top of its range; a float stops changing at 16777216.
browse name One word. It is also the node's display name. Names are not required to be unique; a repeated one is served as written.
value The rest of the line, without the spaces around it. A string is taken exactly as written, quotes and backslashes included. Left out, it is the type's zero: false, 0 or an empty string. A boolean is true, false, 1 or 0. A number is written in decimal (no hexadecimal), may start with + or (for a signed type) -, and is refused if it is outside its type's range or too small to tell from zero.

A file may hold at most 1000 nodes, 4096 bytes to a line and 1048576 bytes in all, and must hold at least one node. The whole file is checked before anything is served, and an error names the line's number, never its content.

Serving a file

"$SERVER" "$WORK/nodes.txt" --port "${PORT:-4840}" > "$WORK/out.txt" &
SERVER_PID=$!
for _ in $(seq 50); do grep -q listening "$WORK/out.txt" && break; sleep 0.1; done
cat "$WORK/out.txt"
kill -TERM "$SERVER_PID"
wait "$SERVER_PID"

The server prints one line, listening on opc.tcp://0.0.0.0:PORT, N nodes, when it is ready, and nothing else unless something is wrong. Point the connector's endpoint at opc.tcp://HOST:PORT. Stop it with SIGTERM or SIGINT (Ctrl-C); it shuts down at once, whoever is connected, and exits 0.

--port N is the TCP port, 1 to 65535 (default 4840). --interval-ms N is the time between steps of a tick node, 10 to 3600000 (default 200).

A server built from the same file as a plant's node list answers a read of any node in it and refuses any other with BadNodeIdUnknown.

Checking a file

--check reads the file, builds the nodes and exits without listening.

"$SERVER" "$WORK/nodes.txt" --check
"$SERVER" "$WORK/bad.txt" --check

Exit codes

CodeMeaning
0 Stopped by SIGINT or SIGTERM, or --check found the file valid.
2 The file or the options could not be used; nothing was served.
3 The server could not start, usually because the port is taken.

--help prints the usage and exits 0.

Release: v0.11.0