MIMIC OpenAPI Guide

  1. Table of Contents
  2. Requirements
  3. The MIMIC OpenAPI is an optional Update Wizard package, which implements a OpenAPI based REST API to control MIMIC.

    In order to export the MIMIC OpenAPI, you have to run the mimic-openapi-daemon from the linux directory of the MIMIC installation as follows:

    $ ./mimic-openapi-daemon
    Thu Jan 23 14:30:20 EST 2020 - Only plain HTTP is working because tcl-TLS is not available in the system
    
    Thu Jan 23 14:30:20 EST 2020 - Opened socket sock24ceb20 for port 8081
    
    

    If you want to export the OpenAPI via HTTPS, then you also need to download the optional TLSTCL package with Update Wizard.

    If you want to use SwaggerHub community OpenAPI Java SDK, install JDK.

    If you want to use SwaggerHub community OpenAPI Python SDK, install python3 pip3 with certifi like the following procedure.

    [root@localhost test]# subscription-manager repos --enable satellite-tools-6.5-for-rhel-8-x86_64-rpms
    Repository 'satellite-tools-6.5-for-rhel-8-x86_64-rpms' is enabled for this system.
    [root@localhost test]# dnf install python3-pip
    [root@localhost test]# pip3 install certifi
    

  4. Hello, World!
  5. The equivalent to the Hello, World! program for MIMIC is to clear the current lab configuration, equivalent to File->New, load a new configuration like File->Open. , and start the first agent. You can accomplish this with these curl commands:

    curl -ulab:lab123 http://YOURIP:8081/mimic/clear
    curl -ulab:lab123 http://YOURIP:8081/mimic/load/agent.cfg
    curl -ulab:lab123 http://YOURIP:8081/mimic/agent/1/start
    

    where YOURIP is the IP address of your MIMIC system.

    While you are doing this, notice how your MIMICview reacts to each command - it synchronizes with the simulator to keep up with the latest state. When the first agent turns green, it has synchronized to your state. You have seen that you can control MIMIC from any number of clients. using the MIMIC API.

    You can also do this non-interactively by saving these commands into a file, and running it in python (the ^D stands for CTL-D):

    % cat > hello-openapi.py
    import requests
    yourip='YOURIP'
    url='http://'+yourip+':8081'
    auth=('lab','lab123')
    requests.post(url+'/mimic/clear',auth=auth)
    requests.post(url+'/mimic/load/agent.cfg',auth=auth)
    requests.post(url+'/mimic/agent/1/start',auth=auth)
    exit();
    ^D
    
    % python3 hello-openapi.py
    
    

    Again, you need to change YOURIP with the IP address of your MIMIC system.

    The rest of this section details all the possible options and commands.

  6. API Reference
  7. See the definition on SwaggerHub

  8. Examples
    • The TestOpenAPI.java program is an small test program to exercise the MIMIC API. Use File->New and File->Load the default agent.cfg , then run the app like the following example.

      [test@localhost bin]$ pwd
      /usr/local/linux.new.2100B6/bin
      [test@localhost bin]$ mkdir -p ~/mimic/data/sim/Cisco-ASR9000
      [test@localhost bin]$ cp ../scripts/timer.mtcl ~/mimic/data/sim/Cisco-ASR9000
      
      [test@localhost java]$ pwd
      /usr/local/linux.new.2100B6/openapi/java
      [test@localhost java]$ export PATH=/usr/local/jdk-11.0.9/bin/:$PATH
      [test@localhost java]$ export JAVA_HOME=/usr/local/jdk-11.0.9/
      [test@localhost java]$ javac -cp swagger-java-client-1.0.0.jar TestAppOpenAPI.java
      [test@localhost java]$ java -classpath .:lib/gson-2.8.1.jar:lib/gson-fire-1.8.3.jar:lib/okhttp-2.7.5.jar:\
      lib/okio-1.6.0.jar:lib/hamcrest-core-1.3.jar:lib/javax.annotation-api-1.2.jar:\
      lib/junit-4.13.1.jar:lib/logging-interceptor-2.7.5.jar:lib/swagger-annotations-2.0.0.jar:\
      lib/threetenbp-1.3.5.jar:swagger-java-client-1.0.0.jar TestAppOpenAPI
      TestApp: agent 1, started.
      TestApp: agent 1, state 1
      TestApp: agent[1].ifDescr instances = [1, 2, 3, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
      TestApp: agent[1].ifTable, removed instance 24
      TestApp: agent[1].ifInOctets.1 variables = [r]
      
      , or equivalently, in Windows CMD that uses semicolon,
      c:\Apps\Mimic.2110b7\openapi\java>javac -cp swagger-java-client-1.0.0.jar TestAppOpenAPI.java
      c:\Apps\Mimic.2110b7\openapi\java>java -classpath .;C:\apps\Mimic.2110b7\openapi\java\swagger-java-client-1.0.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\okhttp-2.7.5.jar;C:\apps\Mimic.2110b7\openapi\java\lib\okio-1.6.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\gson-fire-1.8.3.jar;C:\apps\Mimic.2110b7\openapi\java\lib\gson-2.8.1.jar;C:\apps\Mimic.2110b7\openapi\java\lib\hamcrest-core-1.3.jar;C:\apps\Mimic.2110b7\openapi\java\lib\javax.annotation-api-1.2.jar;C:\apps\Mimic.2110b7\openapi\java\lib\junit-4.13.1.jar;C:\apps\Mimic.2110b7\openapi\java\lib\logging-interceptor-2.7.5.jar;C:\apps\Mimic.2110b7\openapi\java\lib\swagger-annotations-2.0.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\threetenbp-1.3.5.jar TestAppOpenAPI
      TestApp: agent 1, 2, 3, are on host IP: [45.10.11.1, 10.0.0.2, 10.0.0.3]
      TestApp: agent 1, started.
      TestApp: agent 1, state 1
      
      , or equivalently, in Windows PowerShell that requires additional quotations to escape interpretation of semicolon,
      PS C:\apps\Mimic.2110b7\openapi\java> javac -cp swagger-java-client-1.0.0.jar TestAppOpenAPI.java
      PS C:\apps\Mimic.2110b7\openapi\java> java -classpath ".;C:\apps\Mimic.2110b7\openapi\java\swagger-java-client-1.0.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\okhttp-2.7.5.jar;C:\apps\Mimic.2110b7\openapi\java\lib\okio-1.6.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\gson-fire-1.8.3.jar;C:\apps\Mimic.2110b7\openapi\java\lib\gson-2.8.1.jar;C:\apps\Mimic.2110b7\openapi\java\lib\hamcrest-core-1.3.jar;C:\apps\Mimic.2110b7\openapi\java\lib\javax.annotation-api-1.2.jar;C:\apps\Mimic.2110b7\openapi\java\lib\junit-4.13.1.jar;C:\apps\Mimic.2110b7\openapi\java\lib\logging-interceptor-2.7.5.jar;C:\apps\Mimic.2110b7\openapi\java\lib\swagger-annotations-2.0.0.jar;C:\apps\Mimic.2110b7\openapi\java\lib\threetenbp-1.3.5.jar" TestAppOpenAPI
      TestApp: agent 1, 2, 3, are on host IP: [45.10.11.1, 10.0.0.2, 10.0.0.3]
      TestApp: agent 1, started.
      TestApp: agent 1, state 1
      

    • The test-openapi.py program is another small test program to exercise the MIMIC API.
      File->New and File->Load default agent.cfg , then run the app like the following example.

      [test@localhost python]$ pwd
      /usr/local/linux.new.2100B6/openapi/python
      [test@localhost python]$ mkdir -p $MIMIC_PRIV_DIR/data/sim/Cisco-ASR9000/
      [test@localhost python]$ cp ../../scripts/timer.mtcl $MIMIC_PRIV_DIR/data/sim/Cisco-ASR9000
      [test@localhost python]$ python3 test-openapi.py
      test-openapi: config file = agent.cfg
      test-openapi: max agents = 10000
      test-openapi: last agent = 7
      test-openapi: version = 21.0
      test-openapi: num clients = 2
      
    • Our TCLURL update package provides a Tcl API to the MIMIC OpenAPI. Install it with Update Wizard then follow the instructions in the openapi/tclurl/README_mimic_tclurl.txt file, eg.

      bash-4.4$ export MIMIC_DIR=/usr/local/mimic
      bash-4.4$ ./agentget
      Usage: ./agentget agent_range attribute [--host OpenAPI host[:port]] [--file inputfile]
         Example: ./agentget 1 sim
                  ./agentget 1-10,15,20-100 host
                  ./agentget all read
      
                  [OpenAPI host[:port]] default localhost:8081
                  [inputfile]  arguments read from the file
      bash-4.4$ ./agentget 1-5 read --host 192.9.200.14:8081
      1: public
      2: public
      3: public
      4: public
      5: public
      bash-4.4$ ./agentget 1-5 host --host 192.9.200.14
      1: 10.0.0.1
      2: 10.0.0.2
      3: 10.0.0.3
      4: 10.0.0.4
      5: 10.0.0.5
      

    • You can use any command-line HTTP client such as curl . Eg. if the default agent.cfg lab configuration is loaded:

      $ curl -u lab:lab123 -X GET http://127.0.0.1:8081/mimic/get/max
      20000
      $ curl -u lab:lab123 -X GET --insecure https://127.0.0.1:8444/mimic/get/max
      20000
      $ curl -u lab:lab123 -X GET http://127.0.0.1:8081/mimic/get/last
      7
      $ curl -u lab:lab123 -X GET http://127.0.0.1:8081/mimic/get/cfgfile
      agent.cfg
      $ curl -u lab:lab123 -X GET http://127.0.0.1:8081/mimic/agent/1/get/host
      10.1.120.142
      $ curl -u lab:lab123 -X GET http://127.0.0.1:8081/mimic/agent/7/get/mibs 2> /dev/null \
       | python -mjson.tool
      [
          {
              "device": "sim-10.48.0.1.random",
              "mib": "RFC1213-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "SNMPv2-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "IF-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "EtherLike-MIB",
              "scenario": "1"
          },
          // removed 285 lines of MIBs for brevity
          {
              "device": "sim-10.48.0.1.random",
              "mib": "SNMP-NOTIFICATION-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "SNMP-USER-BASED-SM-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "SNMP-VIEW-BASED-ACM-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "cisco/CISCOTRAP-MIB",
              "scenario": "1"
          },
          {
              "device": "sim-10.48.0.1.random",
              "mib": "cisco/OLD-CISCO-TCP-MIB",
              "scenario": "1"
          }
      ]
      
      
    • The Postman API Client, can be used to do simple queries.

  9. Compatibility
  10. Oracle JDK11.0.9

    OpenJDK 13

    Python 3.6+, pip3 certifi