Home > Mobile >  Problem encountered while trying to create dynamic modules in omnet
Problem encountered while trying to create dynamic modules in omnet

Time:12-24

I'm a beginner and I'm learning network simulation with Omnet . I have been trying to create dynamic modules (Clients) and connect it to a staticlly created module (Server) but I'm getting an error with the function getParentModule() saying "use of undeclared identifier 'getParentModule'".

Here is my Server class:

#include "Server.h"
#include <string>


Define_Module(Server);

void create_grp(int num, int id) {
    cModuleType *moduleType = cModuleType::get("c");

    std::string name = "grp"   std::to_string(id);
//Here my error
    cModule *module = moduleType->create(name, getParentModule());

    module->setGateSize("in", 1);
    module->setGateSize("out", 1);

    module->finalizeParameters();
    module->buildInside();
}

void Server::initialize() {
    // TODO Auto-generated constructor stub
    create_grp(3, 2);

}

And here is my .ned file

simple Server
{
    gates:
        inout g1[];
}

simple Admin
{
    parameters:
        int nbr_of_groups_to_create;
        int nbr_of_nodes_in_each_group;

    gates:
        inout g2;
}

simple Client
{
    gates:
        inout g3;
}

network Network
{
    @display("bgb=384,297");
    submodules:
        s: Server {
            @display("i=device/server;p=173,89");
        }

        a: Admin {
            @display("p=264,167;i=device/laptop");
        }

        c[10]: Client {
            @display("i=device/pc;p=79,167");
        }

    connections:
        a.g2 <--> s.g1  ;
        for i=0..9 {
            s.g1   <--> c[i].g3;
        }
}

CodePudding user response:

You have declared create_grp() as a standalone function so it cannot know what is getParentModule(). I recommend declaring create_grp inside your class Server.

  • Related