Search code examples
omnet++inet

Omnet++ : changing the location of function didn't work as expected


I am actually trying to edit the etherhost2 function to send to several destinations and I reached a point where it is possible only for the first time.

In the original code the function is working properly by just moving the two functions sendBurstPackets() and scheduleNextPacket(simTime()) in if condition with destMACAddress = resolveDestMACAddress() those two functions are only called once.

Does that mean that destMacAddress is set once through the whole simulation?

Original Code

void EtherTrafGen::handleMessage(cMessage *msg)
{
    if (!isNodeUp())
        throw cRuntimeError("Application is not running");
    if (msg->isSelfMessage()) {
        if (msg->getKind() == START) {
            destMACAddress = resolveDestMACAddress();
            // if no dest address given, nothing to do
            if (destMACAddress.isUnspecified())
                return;
        }
        sendBurstPackets();
        scheduleNextPacket(simTime());
    }
    else
        receivePacket(check_and_cast<cPacket *>(msg));
}

My Changes

void EtherTrafGen::handleMessage(cMessage *msg)
{
    if (!isNodeUp())
        throw cRuntimeError("Application is not running");
    if (msg->isSelfMessage()) {
        if (msg->getKind() == START) {
if (!multipacket)
            {
                destMACAddress = resolveDestMACAddress();
                sendBurstPackets();
                scheduleNextPacket(simTime());
            }
            // if no dest address given, nothing to do
            if (destMACAddress.isUnspecified())
                return;
        }
    }
    else
        receivePacket(check_and_cast<cPacket *>(msg));
}

Solution

  • The first message is only true for that condition (msg->getKind() == START), which means the the mac is set once for each host through the whole simulation. Removing that condition made it work.

    I am worried if there are other self messages that might be mistaken with that function. Would be better to have separate EtherHost app that only works for my simulation.

    If there is an idea how to look at all self messages, I would appreciate if some one informed me.