I have a slight issue in creating a priority queue using cPacketQueue containers. I have used the comparative function (shown below within my Switch module) as indicated in previous posts and the manual, but the packets during simulations are not being sorted correctly according to the the runtime delay.
int sw::MyCompareFunc (cObject *a, cObject *b) {
if ((simTime() - (check_and_cast<customeMessage*>(a))->getTimestamp()) < (simTime() - (check_and_cast<customeMessage*>(b))->getTimestamp()))
return -1;
else if ((simTime() - (check_and_cast<customeMessage*>(a))->getTimestamp()) == (simTime() - (check_and_cast<customeMessage*>(b))->getTimestamp()))
return 0;
else
return 1;
}
------------------------------
In my Queue class which I inherit the cPacketQueue, I have this constructor shown below,
------------------------------
myQueue::myQueue(const char *name, CompareFunc cmp) {
this->state = 0;
this->capacity = 0;
this->PacketPurged = 0;
this->setName(name);
}
------------------------------
Then in my Switch module, I create a new queue during initilization time using this,
------------------------------
...
new myQueue ("myName", MyCompareFunc)
...
------------------------------
Every time a packet proceeds to ingress policing at the switch, I insert it into the priority queue and automatically the comparator function should be called to sort the queue, correct?
Many Thanks,
Ahmed