# DataTransferTool Configuration and Test Script
# This file contains configuration and script commands for different types of
# source/sink configurations. The DataTransferTool program can act as several different
# types of nodes in the data platform.

# The first section of the file is for configuration. The order of the parameters
# is not important, the file is read and parsed first and then executed.

# General syntax and information:
#   1. Comments are lines that begin with '#'.
#   2. Spaces at the beginning and the end of the line are ignored.
#   3. Blank lines are ignored.
#   4. All parameters are required unless marked "(OPTIONAL)".
#   5. Timing parameters are numbers followed (with no space) by "ms" for milliseconds, "s" for seconds.


# BEHAVIORS
# ---------
# A node can be a simple hub (specify SERVER).
# A node can be a sink and a source, in which case all data that arrives will be forwarded.
#   This can include fan-out.
# A node can be a sink, aggregator, and a source, in which case all data is aggregated and
#   forwarded (including fan-out).


# PARAMETERS
# ----------

# SET TIME (OPTIONAL)
# Sets the start time of the script. This parameter affects generated data sent by the script.
# If this is not specified then the current computer time is used.
# set-time( YYYY-MM-ddTHH:MM:SSZ )
set-time( 2012-08-20T14:00:00-0700 )

# LOG LEVEL (OPTIONAL)
# Logging for the source is controlled with this parameter. The value is a single level from the
# following list: trace, debug, info, warn, error, fatal
# When specified, messages for the level and all levels above it are included.
# NOTE: Most output requires at least "info" level.
# Default level is info.
log = info

# CONNECTION
# If specified, this will cause a connection to be opened. The port defaults to 3567 (ODP). Otherwise
# a host:port syntax is allowed.
connection = hostname OR IP

# SERVER
# If specified, this will cause a server to be opened on the specified port.
server = 3567

# CONNECTION AND SERVER AUTHENTICATION (OPTIONAL)
# If specified then the connection or server will be secure. If the secret begins with '0x'
# then it will be treated as a shared key, otherwise a password. This is a simplified
# way to specify security information, and assumes that the 'domain' is OID class 6,
# and that the 'oid' is OID class 3. For more advanced configuration, use the individual
# settings for either file-based credential or separate domain/identity/secret. Note
# that passwords are trimmed, so leading/trailing spaces are not supported. If this is required
# then use a credential file.
# TYPE is either connection or server
#   authentication-TYPE = domain:oid:secret
#   authentication-TYPE-file = file (either relative to the script or absolute)
#   authentication-TYPE-domain = formatted-oid
#   authentication-TYPE-identity = formatted-oid
#   authentication-TYPE-key = hex-string
#   authentication-TYPE-password = password
# The first line is equivalent to the following lines.
authentication-connection = domain:oid:secret
authentication-connection-domain = [6:domain]
authentication-connection-identity = [3:oid]
authentication-connection-password = password


# SINK ID (OPTIONAL)
# If the script will source information then it must know where to send the data. The
# sink-id command specifies the OID of the sink. This command may be specified multiple times,
# and if so the program will send to each sink. The OID may include a provider attribute, which
# disables random delivery. If there are no attributes then the program will search for all
# matching sinks and randomly deliver to each.
sink-id = [12:sink]

# SOURCE CONFIGURATION (OPTIONAL)
# This command may appear once, and if so the node becomes a source.
# NOTE: THE ADVERTISE COUNT CURRENTLY HAS NO EFFECT
# source( ID, ADVERTISE COUNT )
source( [12:source], 1 )

# DEVICE (OPTIONAL)
# This command defines a device for a source. It may appear multiple times. The format of the PARAM
# is complicated, formatted as follows:
#   IID/ITEMID/INTERFACEDEF/AGGREGATE
#   IID is the Interface ID in standard form of the property.
#   ITEMID is an integer defining the Item ID of the property.
#   INTERFACEDEF is a hex byte list (spaces and ':' are removed for readability) that defines
#          the type of the property. The type is taken from property item ID 0.
#   AGGREGATE is the numeric representation of the aggregate function (0 for RAW).
# PARENT is either an id or 'null', POSITION is a number or 'null'.
# FILE or DIRECTORY are filename/directory name either absolute or relative to the script location.
#   The files are stored ValueSets, and will be sent from the device repeatedly (without the need
#   of using either generate() or send(). In the case of multiple files, the repeat period of each
#   file is set to the difference of the first and last timestamps from all files. For example,
#   an hour worth of data could be stored in files that were each one minute. The files would
#   be sent every minute, and then the entire sequence would repeat.
# device( ID, PARENT, POSITION, [PARAM, ...] )
# device( ID, PARENT, POSITION, FILE or DIRECTORY )
device ( [12:device], [12:parent], 5, [1:{01}]/1/01 00 01000100000000/0 )
device ( [12:device], [12:parent], 5, filename )
device ( [12:parent], null, null )

# SINK CONFIGURATION (OPTIONAL)
# This command causes the node to become a sink. The number of instances of the sink are created. Note
# that is also possible to put an attribute on the ID with an instance count of 1, and to split the sink
# over multiple scripts.
# sink( ID, INSTANCES )
sink ( [12:sink], 2 )

# AGGREGATOR CONFIGURATION (OPTIONAL)
# The following commands configure an aggregator.
# aggregate-config-X( PERIODMS, AGGREGATECOUNT, SENDCOUNT, MAXDELAY, MAXDETAIL )
# aggregate-type-X( TYPE -> AGG LIST )
# aggregate-property-X( PROPERTY -> AGG LIST )
# aggregate-device-X( DEVICE/PROPERTY -> AGG LIST )
# Multiple aggregators can be created in the same script by using different strings for 'X'.
#    PERIODMS is the number of MS in each time slot. Multiple values in this slot are averaged.
#    AGGREGATECOUNT is the number of slots that are aggregated.
#    SENDCOUNT is the number of aggregates that are grouped in a single send.
#    MAXDELAY is the number of SENDCOUNT periods before data will no longer be accepted.
#    MAXDETAIL is the number of minutes that detail data is kept (for detail requests).
#    TYPE is an integer type identifier, and sets the default aggregation methods for that type.
#    AGG LIST is a comma-separated list of aggregation methods.
#    PROPERTY is the property to aggregate as IID/ITEMID.
#    DEVICE is the OID that the aggregation applies to.
aggregate-config-a( 1000, 60, 10, 2, 4 )
aggregate-type-a ( 0 -> 4 )
aggregate-property-a( [1:{01}]/1 -> 4, 6 )
aggregate-device-a( [12:device]/[1:{01}]/1 -> 9 )


# SCRIPT COMMANDS
# ---------------
# General timing information.
# The script begins executing once all of the required connectivity is established. This is time "zero".
# There are two methods to specify execution of a command:
#   1. "at". This executes a command one time at the specified offset time.
#   2. "every". This executes a command a number of times, starting at an offset and repeating with a delta.
# For example:
#   at 5s <command> execute the command 5 seconds after the script starts.
#   every (5s,1s,4) <command> execute the command starting at 5 seconds, every 1 second, for a total of 4 times.
#     the parameters are (<offset>,<delta>,[<count>]). If the count is not given then it will repeat until the
#     script ends.
# The ordering of script commands is not important, they do not have to be in "time" order.
#   5. All script commands are optional.

# ADVANCE-TIME
# This command instantly advances time by the specified delta. Any generation or commands during that
# period will execute immediately.
# advance-time( DELTA )
advance-time( 3600s )

# WARP-TIME
# This command speeds up or slows down the passing of time in the script.
# warp-time( FACTOR )
warp-time( 2.0 )

# GENERATE
# This command will cause data to be generated for all devices.
# generate()
every (0s,1s,120) generate()

# REQUEST
# This command enables a sink to request detailed data.
# request(source, requestID, deviceID, propertyIID, propertyItemID, start, duration, timeout)
at 10s request([12:myagg], 1, [12:device], [1:{01}], 1, -3s, 60s, 120s)

# CANCEL
# This command cancels the request for detailed data. requestID corresponds to the requestID when the request was made.
# request(source, requestID)
at 30s cancel([12:myagg], 1)

# SEND TOPOLOGY
# This command will cause topology updates to be sent for all devices that do not send data themselves.
# send-topology()
at 0s send-topology()

# SEND
# This command will cause any generated data to be bundled and sent.
# send()
every (5s,5s,25) send()

# ADD
# Enable a device, causing it to send data if it has a definition.
# add( ID )
at 20s add( [12:device-a] )

# REMOVE
# Disable a device, causing it to not send data.
# remove( ID )
at 20s remove( [12:device-a] )

# EXCHANGE
# Exchange the parent and position of two devices.
# exchange( ID_A, ID_B )
at 20s exchange( [12:device-a], [12:device-b] )

# SET
# Set the parent and position of a device.
# set( ID, PARENT, POSITION )
#  PARENT and POSITION may be 'null'
# set( [12:device-a], [12:parent], 5 )
# set( [12:device-a], null, null )
at 20s set ( [12:device-a], [12:parent], null )

# SET-SINK
# Set the sink state.
# set-sink( STATE )
#   STATE may be enable, disable, toggle-enable, break, fix, toggle-break
# every (10s,10s) set-sink( toggle-enable )
# This will toggle the sink on and off every 10 seconds
# Enable/disable are "nice" ways of turning the sink on and off.
# Break/fix are ways of leaving the sink enabled, but unable to receive data. They simulate
#   the effect of a bad application that doesn't acknowledge data.

# STATISTICS
# Show statistics for each sink
# statistics
# every (0s, 60s) statistics
# Dump statistics every 60 seconds.

# EVENT
# This command sends an event from a device. The device must be defined earlier and must not
# be removed when the event is sent. Each time the command is executed it will generate new random
# data for the event parameters if they are not specified.
# The format of the PARAM is complicated, formatted as follows:
#   IID/ITEMID/INTERFACEDEF
#   IID is the Interface ID in standard form of the event.
#   ITEMID is an integer defining the Item ID of the event.
#   INTERFACEDEF is a hex byte list (spaces and ':' are removed for readability) that defines
#          the type of the event. The event ID is used to determine the event type (including parameters).
# DATA is the hex format of the parameters. This is an advanced usage which requires understanding the
#   marshalled data format for the different OpenDOF data types.
# event( ID, PARAM [, DATA] )
at 10s event ( [12:device], [1:{01}]/1/01 00 00 010000 0000 )
at 10s event ( [12:device], [63:{DE02}]/32767/01 04 00010001000000, 00000000 )

# STOP
# This command will stop data generation, but allows queued data to continue to be sent.
at 30s stop

# EXIT
# This command will stop the script and shut-down the program. If this command is not used then the program
# must be stopped manually.
# Make sure to give enough time for the commands to execute.
at 30s exit
