Search code examples
omnet++inet

How to control packet generation rate and send interval


I am trying to create an UDP application where the packet generation rate and packet send interval can be controlled separately.

My code is in https://github.com/11187162/udpApp

With the above code, I am not getting the expected outcome and getting the following runtime error:

scheduleAt(): Message (omnetpp::cMessage)sendTimer is currently scheduled, use cancelEvent() before rescheduling -- in module (inet::UdpOwnApp) SensorNetworkShowcaseA.sensor3.app[0] (id=176), at t=0.058384669093s, event #10

The code for handleMessageWhenUp() is given below.

void UdpOwnApp::handleMessageWhenUp(cMessage *msg)
{
    if (msg->isSelfMessage()) {
        ASSERT(msg == selfMsg);
        switch (selfMsg->getKind()) {
            case START:
                processStart();
                break;

            case GENERATE:
                generatePacket();
                break;

            case SEND:
                processSend();
                break;

            case STOP:
                processStop();
                break;

            default:
                throw cRuntimeError("Invalid kind %d in self message", (int)selfMsg->getKind());
        }
    }
    else
        socket.processMessage(msg);
}

Would anyone please help me?

Thank you


Solution

  • You have written that "generation rate and packet send interval can be controlled separately" but you use the same self-message for control generation of packets as well as for sending of the packets. When a self-message is scheduled it cannot be scheduled again.

    Consider adding a new self-message for generation of packets.

    By the way: numGenerate is set to zero and it is never changed.

    EDIT

    Assuming that selfMsg1 is used for generating packets only the following code may be used:

    void UdpOwnApp::handleMessageWhenUp(cMessage *msg) {
          if (msg->isSelfMessage()) {
            if (msg == selfMsg) {
              switch (selfMsg->getKind()) {
                case START:
                    processStart();
                    break;
                case SEND:
                    processSend();
                    break;
                case STOP:
                    processStop();
                    break;
                default:
                    throw cRuntimeError("Invalid kind %d in self message", (int)selfMsg->getKind());
                }
            } else if (msg == selfMsg1) {
                if (selfMsg1->getKind() == GENERATE) {
                    generatePacket();
            }
            }
          }
        else
            socket.processMessage(msg);
    }
    

    And in initialize() you should create an instance of selfMsg1.