MIMIC Perl API Guide

  1. Table of Contents
  2. Requirements
  3. The MIMIC Perl API requires the use of the Perl 5.8.8 or later. Perl is already installed on Solaris and Linux platforms, but will have to be installed on Windows platforms. The MIMIC Perl programs expect the perl executable to be accessible through /usr/local/bin/perl, so you would need to create a symbolic link to the installed executable. MIMIC has been tested with Perl 5.8.8 and later on all supported platforms.

    NOTE: Recent versions of Perl have removed ".", the current working directory, from the @INC include path. If you get these errors:

    Can't locate Mimic.pm in @INC (you may need to install the Mimic module) (@INC contains:
    /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at TestApp.pl line 9.
    BEGIN failed--compilation aborted at TestApp.pl line 9.

    then just supply the -I . command line option to Perl.

    The MIMIC Perl environment is located in the perl/ folder in the MIMIC installation.

  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 commands typed into the mimicsh-perl:

    The mimicsh-perl program is an interactive Perl shell with the MIMIC API built-in. Type the following for this exercise:

    % ./mimicsh-perl
    MIMIC Perl API shell
    Copyright (c) 2001-2013 Gambit Communications, Inc.
    Type "help;" for online help.
    mimicsh-perl> $session->cfg_new();
    mimicsh-perl> $session->cfg_load("agent.cfg");
    mimicsh-perl> $agent = $session->get_agent(1);
    mimicsh-perl> $agent->start();
    mimicsh-perl> exit();

    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 4 commands into a file, and running mimicsh-perl with the --script option (the ^D stands for CTL-D):

    % cat > hello.pl
    $agent = $session->get_agent(1);
    % ./mimicsh-perl --script hello.pl

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

  6. Class Reference
  7. The Perl API is modelled after the Java API. All classes and methods have the same name as in Java, except that Perl programming constructs are used. Click here for the generated Java reference documentation.

  8. Examples
    • The mimicsh-perl program is an interactive Perl shell with the MIMIC API built-in. Type "help" for online help.

      MIMIC Perl API shell
      Copyright (c) 2001-2014 Gambit Communications, Inc.
      Type "help;" for online help.
      mimicsh-perl> help
      MIMIC Perl API shell: 
      The syntax of the Perl API is based upon the Java API.
      For details, look at the Java API Guide in the online
      mimicsh-perl> $client = new Mimic::Client();
      mimicsh-perl> $session = $client->open_session("localhost", 9797);
      mimicsh-perl> $agent = $session->get_agent(2);
      mimicsh-perl> $valuespace = $agent->get_valuespace();
      mimicsh-perl> $sysDescr = $valuespace->get_value( "sysDescr", "0", "v" );
      mimicsh-perl> print $sysDescr, "\n";

    • The Script Generator will generate Perl scripts from MIMICView dialogs.

    • The TestApp.pl program tests a large part of the Perl-based MIMIC API. Invoke it with

      % ./mimicsh-perl --script TestApp.pl
      TestApp: test_3510: session: cfgfile = agent.cfg
      TestApp: test_3510: client: OK
      TestApp: config file = agent.cfg
      TestApp: max agents = 100000
      TestApp: last agent = 7
      TestApp: version = 21.00
      TestApp: num clients = 3
      TestApp: configured agents = 1 2 3 4 5 6 7
      TestApp: active data :
      TestApp: configured changed agents = 1 2 3 4 5 6 7