omnet++veins

Timer-based sending of message


I want to implement a timer-based message scheme in VEINs/OMNeT++. Here is a scenario: one node sends message to many nodes (let's say 5 nodes). Each node after receiving message sets its timer to broadcast message to other nodes in a network basing on its distance from sender node, such that the furthest node, set shortest timer. And when a node receives message from other nodes before its timer expired, it cancels the timer. But if the timer expires and it has not received any message from other nodes it broadcast the message.

I tried followed explanation in this link How to implement timers in Omnet++?

I have declared a timer message in the initialize() function

MyApp::Initialize(int stage)
{
    RstValueEvt = new cMessage("reset value evt");
}

Then onWSM function for receiving message checks if a message is received again, I check the timer event, if it is scheduled I cancel the timer using:

MyApp::onWSM(BaseFrame1609* frame)

infoMsg* wsm = check _and_cast<infoMsg>(frame)

if(wsm.getrecipient==myId)
{
    if(RstValueEvt->isScheduled())
           { cancelEvent(RstValueEvt); }
    else{scheduleAt(simTime()+timer, RstValueEvt);
//creating copy of the message that I need to rebroadcast
cMessage* copyMessage = (cMessage *)infoMsg.dup;

}
}

My issue, is how to make this node broadcast the copy of message(infoMsg) to all nodes in the network when timer expires, that is how to handle this message in handleselfmsg fcn and onWSM fcn?


Solution

  • I suggest the following way to achieve your goal: