This python package provides both a ready-to-go JSON link testing program and an extensible API for building JSON-link compliant user programs.
Test program for JSON link protocol over TCP or UDP exchange. It can act as either the Master (aka client) or the Slave (aka server) and can optionally inject arbitrary faults to test responses.
Note: On many installs there top-level script json_link_demo.py that can be used in place of python -m json_link.bin.json_link_tester in the examples below
For a basic UDP slave with max run count of 4 use (from the parent directory for json_link/):
$ python -m json_link.bin.json_link_tester -c4
This runs a JSON link slave using the localhost. After initial handshaking, the simulated run cycle executes every 0.5sec by filling the input (master oriented names) schema with dummy data. If sync messages are received from the master, the latest local data is sent in reply. If run with the basic UDP master, below this produces something like:
JSON Link packet test (v0.9.2a) SLAVE (aka SERVER) mode (waits for data)
Run timestep = 0.500sec
(minimum) Reply Delay = 0.100sec
(raw exchange) Timeout = 0.001sec
Using UDP packets on localhost:50007
Waiting for master to send INIT...
--> Linked with REMOTE: {'modelname': 'json_link_demo.py', 'application': 'Generic_JSON_Link_Master', 'version': '0.9.5a'}
Waiting for START
Run (3/4). Sync count=1
Remote TERMINATED Connection
For a basic UDP master (with max run count) run (from the parent directory for json_link/):
$ python -m json_link.bin.json_link_tester -m -c2
This runs a JSON link master using the localhost. After initial handshaking, the simulated run cycle executes every 1sec by filling the output schema with dummy data and attempting to send a sync message to the slave and use the response. If there is a timeout waiting for the slave, the master run loop continues using the old slave data. If run with the basic UDP slave above, this produces something like:
JSON Link packet test (v0.9.2a) MASTER (aka CLIENT) mode (initiates transfer)
Run timestep = 1.000sec
(minimum) Reply Delay = 0.100sec
(raw exchange) Timeout = 0.001sec
Using UDP packets on localhost:50007
Waiting for slave's INIT response...
--> Linked with REMOTE: {u'version': u'0.9.5a', u'remote': u'Generic JSON Link Slave/Server'}
--> Link STARTed. Remote Data=None
Run (2/2). Sync count=1
TERMINATING: Max Iteration Count (2)
--> Link TERMinated. Final Remote Data=None
A wide range of additional configuration options are available. The complete list is available at the command line with:
$ python -m json_link.bin.json_link_tester -h
Some highlights:
| -t, --tcp | Use TCP sockets |
| -a HOST_ADDR, --host_addr=HOST_ADDR | |
| Host name/IP address (Default: localhost) for SLAVE (aka SERVER) on non-windows use All for all interfaces | |
| -p PORT, --port=PORT | |
| Port Number | |
| --raw | Print Raw packet contents including header (Default=False, print cleaner output) |
| -v VERBOSE, --verbose=VERBOSE | |
| Control level of verbosity for JSON link level output. See –raw for raw_xchg. verbosity requires an integer parameter. 0=no output 1=basic init and run only & errors, 2=add state machine & warnings, 3+=add link- level messages | |
| -r RUN_TIMESTEP, --run_timestep=RUN_TIMESTEP | |
| Run timestep in Sec. Duration of each sub-run in the internal process loop. MASTER: sets to the transmit interval. (default=1.0) SLAVE: time to wait before running using the last received value (default=0.5) | |
| -d DELAY, --delay=DELAY | |
| Minimum delay after rx before tx. Used to simulate a minimum internal synchronous process running time (default=0.1sec) | |
@author: Bryan Palmintier, NREL 2013
WARNING: the API documentation is very rudimentary. Stay tuned as work progresses.