'How to simulate limited RSU capacity in veins?

I have to simulate a scenario with a RSU that has limited processing capacity; it can only process a limited number of messages in a time unit (say 1 second).

I tried to set a counter in the RSU application. the counter is incremented each time the RSU receives a message and decremented after processing it. here is what I have done:

void RSUApp::onBSM(BasicSafetyMessage* bsm)
{
    if(msgCount >= capacity)
    {
        //drop msg
        this->getParentModule()->bubble("capacity limit");
        return;
    }

    msgCount++;

    //process message here

     msgCount--;

}

it seems useless, I tested it using capacity limit=1 and I have 2 vehicles sending messages at the same time. the RSU process both although it should process one and drop the other.

can anyone help me with this?



Solution 1:[1]

In the beginning of the onBSM method the counter is incremented, your logic gets executed and finally the counter gets decremented. All those steps happen at once, meaning in one step of the simulation. This is the reason why you don't see an effect.

What you probably want is a certain amount of "messages" to be processed in a certain time interval (e.g. 500 ms). It could somehow look like this (untested):

if (simTime() <= intervalEnd && msgCount >= capacity)
{
    this->getParentModule()->bubble("capacity limit");
    return;
} else if (simTime() > intervalEnd) {
   intervalEnd = simTime() + YOURINTERVAL;
   msgCount = 0;
}
......

The variable YOURINTERVAL would be time amount of time you like to consider as the interval for your capacity.

Solution 2:[2]

You can use self messaging with scheduleAt(simTime()+delay, yourmessage); the delay will simulate the required processing time.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thardes2
Solution 2 Fady Samann