Skip to main content

Add parameters

Setting up parameters for a module in OMNeT++ always consists of three steps:

  1. Define the parameter in the module NED file. For example, in Node.ned:
simple Node
{
    parameters:
        int triggerYellow; 
        @display("b=60,10,rect,blue,black,2");
    gates:
        inout my_gate;
}
  1. Set the value of the parameter before starting the simulation in omnetpp.ini:
SingleNodeNetwork.node1.triggerYellow = 200
SingleNodeNetwork.node2.triggerYellow = 500
  1. Use the parameter value in the code. For example, in Node.cc:
scheduleAt(par("triggerYellow"), msg_to_trigger);

In this way, we have defined a parameter for the module Node that we can setup and use instead of a random value or a fixed value to initialize the first message for each node. When you run this simulation, you can see the different values of the same parameter in the modules view: