如何直接将数据包注入 OMNet++ 中的另一个模块

How to directly inject packets to another module in OMNet++

我的复合模块是多层的,如附图所示。

这里Layer2 有一个cPacketQueue 缓冲区,我希望Layer1 模块直接将数据包插入Layer2 的这个cPacketQueue。如图所示Layer1和Layer2门单向连接

Layer1Gate --> Layer2Gate

更新:

Layer 1 创建具有不同优先级的数据包 (0-7) 并注入到 8 不同的 cPacketQueues in Layer2 命名为 priorityBuffers[i], (i是指数)。

然后 Layer2intervals of 10ns 中发送自己的消息以轮询每个 iterationsend 数据包中的所有这些缓冲区。

这就是我现在所做的一切。它工作正常。但我知道 10ns 轮询绝对不是执行此操作和实现 QoS 的有效方法。所以请求更好的选择。

我建议为来自 Layer1 的每个数据包添加一个具有优先级的 ControlInfo 对象,使用 send() 命令发送数据包,然后在 ControlInfo 中检查接收到的数据包=17=],并将数据包插入到特定的队列中。
首先,应该为 ControlInfo 定义一个 class,例如 common.h:

// common.h
class PriorityControlInfo : public cObject {
public:
    int priority;
};

然后在Layer1简单模块的C++代码中:

#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");

最后在 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;
        }
    }
}

根据自己留言的使用情况:我不太明白你的用意是什么。

  1. Layer2是否应该在收到数据包后立即发送数据包?如果是,为什么要使用缓冲区?在那种情况下,Layer2 不应该将数据包插入缓冲区,而是将其发送到 Layer3.
  2. Layer2 收到数据包并将其插入缓冲区后是否应该做其他事情?如果是,就在上面handleMessage().
  3. 中调用这个动作(函数)

在上述两种变体中都不需要使用自我消息。