### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »

# bin Package

## `json_link_tester` Module

### json_link_tester

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

#### Basic UDP slave

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

#### Basic UDP master

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

#### Additional Options

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:

##### Transfer Setup

`-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

##### Debugging Information Display

`--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

##### Run timing

`-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)

#### Notes

- Should work with Python 2.6+ and 3.x. Tested with 2.7.2 and 3.3
- Currently only supports IPv4
- The SLAVE will handle connections from any number of masters, BUT since the code is only single threaded each processing (including delay) are blocking. Hence, the SLAVE may miss packets if it is busy processing (or waiting to send) a different reply.

@author: Bryan Palmintier, NREL 2013

`json_link.bin.json_link_tester.``buildMessage`(opt)

`json_link.bin.json_link_tester.``buildReply`(opt, data)

`json_link.bin.json_link_tester.``main`()

`json_link.bin.json_link_tester.``printIO`(prefix, data, suffix='')

`json_link.bin.json_link_tester.``runSimpleMaster`(opt)

`json_link.bin.json_link_tester.``runSimpleSlave`(opt)

### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »