The MIMIC CoAP Protocol Module is an optional facility that simulates the Internet of Things (IoT) Constrained Application Protocol (CoAP) standard as detailed on IETF RFC 7252 . Each MIMIC agent instance configured with CoAP acts as a server
Compatibility with various clients and applications is documented in the section below.
CoAP support is made available in MIMIC as an optional dynamically loadable module. Starting with MIMIC 18.00, you can use the Protocol Wizard to install the CoAP module. If you prefer to enable CoAP by hand, you need to do the following:
INFO - COAP : Loaded protocol from < path-to-DLL > INFO - COAP v18.00
Once CoAP is loaded, any agent instance configured to support the CoAP protocol will be able to respond to requests from clients.
If the CoAP module is enabled, then Agent->Add, Agent->Configure and Agent->Paste dialogs will display COAP as an additional checkbox in the Advanced pane along with the SNMP protocols. On selecting the checkbox a new COAP pane will appear.
This CoAP configuration pane lets the user configure the parameters for a CoAP session:
This optional parameter specifies the non-encrypted, server UDP port to use. If set to 0, this port is disabled. The default port is 5683.
This mandatory parameter specifies the CoAP rule file, to determine the response for each REST command with URI. You will not be able to start the agent unless this parameter is set.
The rule file is detailed below. You can edit rule files directly.
This optional parameter specifies the DTLS-encrypted, server UDP port to use. If set to 0, this port is disabled.The default port is 5684.
This optional parameter specifies the keystore file to use. If the keystore file is not set, the DTLS CoAP agent can not receive encrypted commands because the agent needs the correct key to decrypt encrypted traffic.
A few new commands and some enhanced old commands can be used from the MIMICShell to control the CoAP functionality. Here is a synopsis:
This command lets the user gather the self-defining list of arguments required and their particulars. The parameters are detailed above. A sample exchange for this command would be:
mimicsh> mimic protocol msg COAP get args {{primary_port} {Primary Port} {integer} {} {optional} {5683}} {{rule} {Rule File} {file} {scripts/coap {{*.rul {coap rule files} {edit yes} {new yes}}} - both} {mandatory} {}} {{secure_port} {Secure Port} {integer} {} {optional} {5684}} {{keystore} {Key Store} {file} {config/coap {{*.db {Key store files} {edit yes} {new yes}}} - both} {optional} {samplekeystore.db}}
This command lets the user look at the protocols currently configured on the agent. A sample exchange for this command would be:
mimicsh> mimic agent get protocol snmpv1,snmpv2c,COAP
This command lets the user change the protocol setting for an agent. A sample exchange for this command would be:
mimicsh> mimic agent get protocol snmpv1 mimicsh> mimic agent set protocol snmpv1,COAP mimicsh> mimic agent get protocol snmpv1,COAP
This command lets the user get the current argument settings. A sample exchange for this command would be:
mimicsh> mimic agent protocol msg COAP get config {primary_port=5683} {rule=iot-eclipse-org.rul} {secure_port=0} {keystore=samplekeystore.db}
This command lets the user change the current argument settings of all CoAP sessions for an agent. A sample exchange for this command would be:
mimicsh> mimic agent protocol msg COAP get config {primary_port=5683} {rule=iot-eclipse-org.rul} {secure_port=0} {keystore=samplekeystore.db} mimicsh> mimic agent protocol msg COAP set config \{secure_port=5684\} mimicsh> mimic agent protocol msg COAP get config {primary_port=5683} {rule=iot-eclipse-org.rul} {secure_port=5684} {keystore=samplekeystore.db} mimicsh> mimic agent protocol msg COAP set config \{rule=ikea-e1526.cfg\} mimicsh> mimic agent protocol msg COAP get config {primary_port=5683} {rule=ikea-e1526.cfg} {secure_port=5684} {keystore=samplekeystore.db}
This command lets the user change the CoAP tracing configuration for an agent. A sample exchange would be:
mimicsh> mimic agent assign 1 mimicsh> mimic agent protocol msg COAP get trace 0 mimicsh> mimic agent protocol msg COAP set trace 1 mimicsh> mimic agent protocol msg COAP get trace 1and the log would show:
INFO 01/05.09:42:35 - agent 1 trace enabled for COAP INFO 01/05.09:42:51 - agent 1 loaded device INFO 01/05.09:42:51 - COAP[AGT=1]: rules database initialized INFO 01/05.09:42:51 - COAP [AGT=1]: server started ...
Returns CoAP statistics information:
In order, the statistic values are:
A sample exchange for these commands would be:
mimicsh> mimic protocol msg COAP get stats_hdr {{connect} {Connect}} {{disconnect} {Disconnect}} {{published} {Published}} {{pktSnt} {PktSent}} {{pktRcv} {PktRcvd}} {{pktDisc} {PktDisc}} mimicsh> mimic agent protocol msg COAP get statistics 1 0 18 18 18 0
CoAP responses to be returned by the simulated sensor are specified by the rule file(s) loaded into the agent instance.
The rules database is a ASCII text file and the loader reads and sources any Tcl scripts as associated. The contents of the file are used to initialize data structures that will then be used to return a response string (output) for a given request REST command. In the absence of a match, a CoAP error is returned.
The rules database is located in the scripts/coap/ directory in the MIMIC directory hierarchy. Any custom Tcl scripts also need to be in this same directory.
NOTE: rules and script files are cached, and modifications to them will only be reloaded by the parser when the rule file modification time is newer than what is in the cache.
The rules database is made of a series of rule blocks. A rule block must have 1 request_header field and either one response or one response_script field.
version = 18.00 rule = { request_header = GET /15011/9063/ response_script = ikea-e1526.mtcl::generate_key } rule = { request_header = GET /15001/ response = [65536,65537,65538,65539,65540,65541,65542] }
Any Tcl procedure invoked will have a predefined set of global variables passed to it which identify the current environment.
This variable holds the POST command data received from the CoAP client.
Click here for the compatibility document. If you get an error, you need to download the optional update package with the Update Wizard.