Reputation: 3151
My compound module is multiple layers as show in the attached figure.
Here Layer2 has a cPacketQueue
buffer and I want the Layer1 module to directly insert packets into this cPacketQueue
of Layer2. Layer1 and Layer2 gates are connected unidirecttionally as show in the figure.
Layer1Gate --> Layer2Gate
UPDATED:
Layer 1
creates Packets with different priorities (0-7)
and injects to 8
different cPacketQueues
in Layer2
named as priorityBuffers[i]
, (i is the index).
The Layer2
then sends self messages in intervals of 10ns
to poll all these buffers in each iteration
and send
the packets.
This is all I am doing now. It works fine. But I know 10ns polling is definitely not an efficient way to do this and achieve QoS. So requesting for a better alternative.
Upvotes: 1
Views: 586
Reputation: 7002
I suggest adding a ControlInfo
object with priority to every packet from Layer1
, send the packet using send()
command, then checking ControlInfo
of received packet in Layer2
, and insert the packet into a specific queue.
Firstly, one should define a class for ControlInfo
, for example in common.h
:
// common.h
class PriorityControlInfo : public cObject {
public:
int priority;
};
Then in C++ code of Layer1
simple module:
#include "common.h"
// ...
// in the method where packet is created
cPacket * packet = new cPacket();
PriorityControlInfo * info = new PriorityControlInfo();
info->priority = 2; // 2 is desired queue number
packet->setControlInfo(info);
send (packet, "out");
And finally in Layer2
:
#include "common.h"
// ...
void Layer2::handleMessage(cMessage *msg) {
cPacket *packet = dynamic_cast<cPacket *>(msg);
if (packet) {
cObject * ci = packet->removeControlInfo();
if (ci) {
PriorityControlInfo * info = check_and_cast<PriorityControlInfo*>(ci);
int queue = info->priority;
EV << "Received packet to " << static_cast<int> (queue) << " queue.\n";
priorityBuffers[queue].insert(packet);
EV << priorityBuffers[queue].info() << endl;
}
}
}
According to using of self messages: I do not understand clearly what is your intention.
Layer2
should send a packet immediately after receiving it? If yes why do you use a buffer? In that situation instead of inserting a packet to a buffer, Layer2
should just send it to the Layer3
.Layer2
should do something else after receiving a packet and inserting it in a buffer? If yes, just call this action (function) in the above handleMessage()
.In the both above variants there is no need to use self messages.
Upvotes: 2