2
votes

I am new to Omnet++ and I am trying to simulate a Wifi network. I have successfully created a network consisting of an AP and some nodes and all the nodes are able to connect to the AP.

What I want to do is that once all the nodes are connected to the AP, a node (based on its IP address) should send a message to another node in the network. I have created the .msg file with all the required fields and it is successfully compiled by the message compiler to the corresponding _m.h and _m.cc files. I want this message to be sent to the other node. How to proceed with this? Iknow it has to do something with the handleMessage() function but I can't find the file containing that function.

Thanks in advance for any kind of help.

2

2 Answers

0
votes

To send the initial message you will have to use the send() when you initialize you node.

From the tictoc tutorial:

void Txc1::initialize()
{
    // Initialize is called at the beginning of the simulation.
    // To bootstrap the tic-toc-tic-toc process, one of the modules needs
    // to send the first message. Let this be `tic'.

    // Am I Tic or Toc?
    if (strcmp("tic", getName()) == 0)
    {
        // create and send first message on gate "out". "tictocMsg" is an
        // arbitrary string which will be the name of the message object.
        cMessage *msg = new cMessage("tictocMsg");
        send(msg, "out");
    }
}

Then you want the nodes to be able to react. Their reaction can be silent -- just accept the message and delete it, or send another message in return.

For that you will need to implement the handleMessage() function inside the nodes .cc file.

void Txc1::handleMessage(cMessage *msg)
{
    // The handleMessage() method is called whenever a message arrives
    // at the module. Here, we just send it to the other module, through
    // gate `out'. Because both `tic' and `toc' does the same, the message
    // will bounce between the two.
    send(msg, "out");
}
0
votes

You can find the function in the .cc file in the same project or folder. Normally the name of the .cc file is close to the name of the .ned file that caries the details of the host or node or whatever you call it in your project.