Cosimulation
In most respects, invoking a cosimulation in Modeler is similar to invoking an ordinary simulation. All of the parameters necessary for an ordinary simulation apply to cosimulation. To run a cosimulation, however, the external system code must be installed.
When op_runsim -cosim is specified for the simulation program, Modeler uses information from a simulator description file to find the other simulators involved. In addition to the usual Modeler parameters, the necessary parameters for the other simulators can also be specified as arguments to op_runsim or op_mksim.
Compiling Cosimulation Code
Code for a cosimulation can be compiled as for regular simulations, using op_mko.
External code can be compiled using native compilers and custom makefile rules. The directory <reldir>/sys/include must be included among the build directories. The external code:
- Should contain the statement
#include "esa.h" - Cannot use any Modeler APIs other than ESA
Linking Cosimulation Code
There are two ways to generate a cosimulation executable. The simulator description file specifies which method is used and the object files and libraries that should be linked (see Simulator Description File).
Embed the discrete event simulation in a larger program.
Specify this method by setting use_esa_main in the simulator description file to “no”. With this method:
- External code declares
main(). - The executable is created using op_mksim or custom makefile rules. With custom makefiles, you must explicitly mention Riverbed libraries, as follows:
- Windows: opsim.lib (or opsim_opt.lib)
- Linux: -lopsim (-lopsim_opt)
- Riverbed model code is linked in to the executable.
Use an external library in the discrete event simulation.
Specify this method by setting use_esa_main in the simulator description file to “yes”. With this method:
- Modeler declares
main(). - The executable is created using op_mksim for static simulations or op_runsim for dynamic simulations.
- External code is contained in dynamically loaded libraries, using the special entry point
esa_main()invoked by the Riverbed code.
The esa_main() function takes the same arguments as main(), with the prototype:
int
esa_main (int argc, char *argv[])
Simulator Description File
Each external system definition (ESD) model specifies a simulator description file for cosimulations using that ESD. The simulator description file is a text file that tells Modeler how to build the cosimulation. It specifies the object files and libraries that must be linked for a particular OS and kernel type. Simulator description files must be named with the file name suffix .sd and stored in a directory listed in the mod_dirs attribute.
Simulator Description File Format
A simulator description consists of one or more blocks of statements set off by the identifiers start_definition and end_definition, as shown in the following sample (a portion of the hla.sd file supplied with Modeler).
Figure 245: Simulator Description File – Sample Extract
# Simulator Description file for HLA Cosimulation
# This uses the Riverbed-provided HLA module
# Do not modify the following information
start_definition
platform: linux_x86
kernel: development
bitness: 32bit
bind_static_lib: -lophla1516_opt -lfedtime1516 -lrti1516
bind_shobj_lib: -lophla1516_opt -lfedtime1516 -lrti1516
dll_lib: libophla1516_opt.so
end_definition
There can be as many blocks in a simulator description file as needed. When Modeler builds a cosimulation, it looks at the simulator description file to find a block whose platform and kernel statements match the target platform and kernel. It then uses the remaining statements in that block to control the build.
The statements you can use in a simulator description file are described in the following table.
Table 126: Simulator Description File Statements
| Statement | Description | Value |
|---|---|---|
| platform | Intended platform for the cosimulation | “windows”, “linux_x86” |
| bitness | Intended architecture size | “32bit”, “64bit” |
| kernel | Intended kernel type | “development”, “optimized” |
| dll_lib | Cosimulation DLL library | file name of a library for the cosimulation |
| bind_lib | Bind arguments | arguments as used on a command line |
| bind_objs | Bind objects | object file to be bound |
| use_esa_main | Whether the external code declares a function called esa_main() | “yes” – for an external library in a discrete event simulation “no” – for a discrete event simulation embedded in a larger program |
Lines beginning with “#” are comments and can be included anywhere in a simulator description file.
Latency
When running as a cosimulation with SITL or HLA, discrete event simulations reduce CPU usage by going to sleep when there are no events to process and waking up occasionally to check for new events. This works well unless real-time responses are needed (for example, when measuring ping response times). To avoid the latency introduced by OS kernel clock cycles, you can prevent simulations from sleeping by setting the “cosimulation_optimization_mode” preference to low-latency.