MIMIC Javascript API Guide

  1. Table of Contents
  2. Requirements
  3. The MIMIC Javascript API exports 2 separate paradigms:

    Both APIs require a Javascript enabled browser to be used. The browser acts as a client to the Javascript API Server detailed below.

  4. Class Reference
  5. Synchronous API

    The synchronous Javascript API is modelled after the Java API with these differences:

    • All the Session class methods implementing global management commands are grouped under mimic_ and have prefix mimic_ followed by the Session class method name, e.g.,

      mimic_get_max()
      

    • All the Agent class methods are grouped under mimic_agent_ and have prefix mimic_agent_ followed by the Agent class method name, e.g.

      mimic_agent_get_host()
      

    • All the Valuespace class methods are grouped under mimic_agent_valuespace_ and have prefix mimic_agent_valuespace_ followed by the Valuespace class method name, e.g.

      mimic_agent_valuespace_get_info()
      

    The Javascript API commands can be written in two additional formats:

    • The equivalent of mimic_ is mimic. or m., thus we can also write the global commands as mimic. or m. followed by the Java method name, e.g.

      mimic.get_max()
      m.get_max()
      

    • The equivalent of mimic_agent_ is mimic.agent. and m.a., thus we can also write the Agent commands as mimic.agent. or m.a. followed by the Java method name, e.g.

      mimic.agent.get_host()
      m.a.get_host()
      

    • The equivalent of mimic_agent_valuespace is mimic.agent.valuespace and m.a.vs, thus we can also write the Valuespace commands as mimic.agent.valuepace or m.a.vs followed by the Java method name, e.g.

      mimic.agent.valuespace.get_info()
      m.a.vs.get_info()
      

    Asynchronous API

    The asynchronous Javascript API is modelled after the synchronous methods above, but every method is of type async.

    To make clear distinction, the asynchronous method name is prefixed with async_.

    e.g. a method named as mimic_get_max will be available in the asynchronous API as async_mimic_get_max

  6. Javascript API Server
  7. The Javascript API Server needs to be running in order to execute the Javascript API commands. The steps to start the Javascript API Server are as follows:

    • Open the command prompt on your machine and set the current working directory to the folder where the jsapiserver.jar file is located in your machine, by default in the java/jsapiserver/ folder of your MIMIC install area..

    • Then type the command

      java -jar jsapiserver.jar --cors
      
      

      to start the Javascript API Server.

    • Usage is given below:

      Usage: java -jar jsapiserver.jar
       --host | -h <ip-addr>        ip address to listen on for web server
       --port | -p <port>           port to listen on for web server
       --mimichost | -mh <ip-addr>  address of mimic host
       --mimicport | -mp <port>     port to connect to on mimic host
       --cors                       add Access-Control-Allow-Origin header to response
       --verbose | -v               enable verbose mode
      

  8. Examples
  9. Synchronous API

    • The testapp.js program is an small test program to exercise the synchronous MIMIC Javascript API.

      You can invoke it by clicking on the link to testapp.html which includes the testapp.js.

      If you get the error message

      No response from server location 'http://127.0.0.1:8080'
      
      

      then you need to run the JS API Server as detailed above, and point the testapp.html URL to it by appending ?jsapiserver=YOUR-SERVER&jsapiport=YOUR-PORT where YOUR-SERVER is the IP address of the system where you are running the server and YOUR-PORT is the port.

      Once it works you'll get the output like this:

      MIMIC JS API Server location set to: http://YOUR-SERVER:YOUR-PORT
      Connection to MIMICD version 19.00 is active
      test_3510 : test_3510: session: cfgfile = 
      test_session_get : config file = 
      test_session_get : version = 19.00
      test_session_get : max agents = 100000
      test_session_get : protocols = snmpv1,snmpv2c,snmpv2,snmpv3,MQTT,NETFLOW,SYSLOG
      test_session_get : last agent = 12400
      test_session_get : clients = 20
      test_session_get : configured list = 1,2,3,4,5,6,7,8,9,10
      test_session_get : active list = 
      test_session_get : changed config agents = 1,2,3,4,5,6,7,8,9,10
      test_session_get : interfaces = {p4p1}
      test_session_get : cfg file changed = 1
      test_session_get : privdir = /home/uwe/mimic/
      test_session_get : product = 29
      test_session_get : net address = 192.9.200.14
      test_session_get : net dev = 
      test_session_get : expiration = ok
      test_session_get : licensing = "{MIMIC Simulator Universal v19.00
       built Jul 19 2018 10:46:47
       Copyright (c) 1997-2018 Gambit Communications, Inc.
       Evaluation license, expires 8/26/2019
       Running 64-bit
       machine x86_64
       OS Linux 3.14.27-100.fc19.x86_64
       4 CPUs}"
      ...
      

    • The MIMICview-JS GUI is a package downloadable with the Update Wizard and provides a web-based interface to MIMIC.

    • The open-source node-red-contrib-mimic package for Node-RED on Github integrates MIMIC with Node-RED via the Javascript API.

    Asynchronous API

    • The asynchronous API can be used in two different ways.

      1. Async API generator script

        Using mimic-api-clientside-async-patch.js is suggested when the user intends to use both Sync and Async API methods.

        This results in loading the Sync API, followed by auto generation of the Async API. Both (Sync and Async) APIs become available and can be used as necessary/suitable.

      2. Pre-created Async API

        Using mimic-api-clientside-async.js is suggested when user does not intend to use any of the Synchronous API methods.

      Study the comments in testappasync.html for better understanding.

      Note: Use either of these, do not use both these ways at the same time.

      The testapp-async.js program is an small test program to exercise the asynchronous MIMIC Javascript API.

      You can invoke it by clicking on the link to testappasync.html which includes the testapp-async.js and testapp-async-utilities.js.

      If you get the error message

      Error from server location 'http://127.0.0.1:8080': Error: TypeError: NetworkError when
      attempting to fetch resource.
      
      

      then you need to run the JS API Server as detailed above, and point the testapp.html URL to it by appending ?jsapiserver=YOUR-SERVER&jsapiport=YOUR-PORT where YOUR-SERVER is the IP address of the system where you are running the server and YOUR-PORT is the port.

      Once it works you'll get the output like this:

      MIMIC JS API Server location set to: http://YOUR-SERVER:YOUR-PORT
      Connection to MIMICD is active
      test_3510 : test_3510: session: cfgfile = 
      test_session_get : config file = 
      test_session_get : max agents = 100000
      test_session_get : last agent = 10
      test_session_get : version = 18
      test_session_get : num clients = 2
      test_session_get : configured agents = 1,2,3,4,5,6,7,8,9,10
      test_session_get : configured changed agents = 1,2,3,4,5,6,7,8,9,10
      test_session_get : log file = 
      test_session_get : interfaces = {p4p1}
      test_session_get : protocols =snmpv1,snmpv2c,snmpv2,snmpv3,MQTT,NETFLOW,SYSLOG
      test_session_get : product = 29
      test_session_get : net address = 192.9.200.14
      test_session_get : net dev = 
      test_session_get : expiration = ok
      test_session_get : licensing = "{MIMIC Simulator Universal v18.00
       built Jul 19 2018 10:46:47
       Copyright (c) 1997-2018 Gambit Communications, Inc.
       Evaluation license, expires 8/26/2018
       Running 64-bit
       machine x86_64
       OS Linux 3.14.27-100.fc19.x86_64
       4 CPUs}"
      ...