Search code examples
omnet++

Omnet++ - Accessing parameters of a different module in initialization (.ini) file and using for loop


I need to generate Poisson arrival of traffic and thus need to set the start times of applications in clients accordingly. For this I need two things:

1. access parameters of different modules and use them as input for defining a parameter of another module
2. use a for loop to define parameters of modules

For e.g. - the example below demonstrates what I am trying to do. I have 100 clients and each client has 20 applications. I want to set the start time of the first application of the first client and want to write the rest using a loop.

// iat = interArrivalTime
**.cli[0].app[0].startTime = 1 // define this
**.cli[0].app[1].startTime = <**.cli[0].app[0].startTime> + exponential(<iat>) 
**.cli[0].app[2].startTime = <**.cli[0].app[1].startTime> + exponential(<iat>)
.
.
.
**.cli[n].app[m].startTime = <**.cli[n].app[m-1].startTime> + exponential(<iat>)

I looked at the 'ned' functions but could not find any solution.

Of course I can write a script for hardcoding the start times of several clients, but the script would output a huge file which is very hard to manage if the number of clients and applications are too big.

Thank You!


Solution

  • INI files are basically pattern matchers. Each time a module is initialized, the left side of the = sign on each line in the INI file is matched against the actual module path, beginning from the start of the INI file. On the first match from the beginning, the right side of the line is used as the value of the parameter.

    In short, these are not assignment operations, rather rules telling each module how to initialize their own parameters. For example it is undefined, in what order these lines will be used during the initialization. Something that is earlier in the INI file is nit necessarily used earlier during module initialization. Of course this prevents you referring an other module's parameter. In fact you may not use any other parameters at all.

    In short, INI files are declarative, not procedural constructs so cross references, loops and other procedural constructs cannot be used here.

    If you want to create dependencies between module parameters, you can code that in the initialize() method of your module, by explicitly initializing a parameter from the C++ code. You can access any other module's parameter using C++ APIs.

    Of course, if you don't want to modify existing applications this is not an optimal solution however you can create a separate module that is responsible for your 'procedural' initialization and that separate module can run through all of you applications and set the required parameters as needed. This approach is used at several places in INET where the initialization data must be computed. One notable example is the calculation of routing table information. e.g. Ipv4FlatNetworkConfigurator

    An other approach would be to set up and configure your simulation from a scripting language like python. This is not (yet) supported by OMNeT++ however.

    Long story short, write a configurator module and do your initialization there.