简体   繁体   English

在OMNet ++中两次接收到信号

[英]Signals are received twice in OMNet++

I have created my own OMNet++ Listener class as follows: 我创建了自己的OMNet ++侦听器类,如下所示:

headerfile 头文件

#ifndef MYFRAMELISTENER_H_
#define MYFRAMELISTENER_H_



#include <clistener.h>
#include <vector>

class MyFrameListener : public cListener{
public:
    int tempDelmeJustForTest;
    simsignal_t signalIDArray[14];
    int index;
public:
    MyFrameListener();
    virtual ~MyFrameListener();

    virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
};

#endif /* MYFRAMELISTENER_H_ */

cc File 抄送文件

MyFrameListener::MyFrameListener() {
    this->tempDelmeJustForTest = 0;
}

MyFrameListener::~MyFrameListener() {
}

void MyFrameListener::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj){
        tempDelmeJustForTest++;
}

SimpleModule cc file : SimpleModule cc文件

void ListenersModule::initialize()
{
    // TODO - Generated method body
    frameListener = new MyFrameListener();
    //subscribe("packetReceivedFromLower",frameListener);
    simulation.getSystemModule()->subscribe("packetReceivedFromLower",frameListener);
}


void ListenersModule::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
}


void ListenersModule::finish(){
    //simulation.getSystemModule()->unsubscribe("packetReceivedFromLower",frameListener);
    recordScalar("My Listened Values", this->frameListener->tempDelmeJustForTest);
}

Here, I am trying to count the number of Ethernet frames received in EtherMACFullDuplex by incrementing the tempDelmeJustForTest variable. 在这里,我试图通过增加tempDelmeJustForTest变量来计算EtherMACFullDuplex接收到的以太网帧的数量。

EtherMACFullDuplex is a module located in inet/src/inet/linklayer/ethernet/EtherMACFullDuplex.cc and it is used to create the Ethernet phy port. EtherMACFullDuplex是位于inet/src/inet/linklayer/ethernet/EtherMACFullDuplex.cc ,用于创建Ethernet phy端口。

This class has a function as shown below: 该类具有如下功能:

void EtherMACFullDuplex::processReceivedDataFrame(EtherFrame *frame)
{
    emit(packetReceivedFromLowerSignal, frame);

    // strip physical layer overhead (preamble, SFD) from frame
    frame->setByteLength(frame->getFrameByteLength());

    // statistics
    unsigned long curBytes = frame->getByteLength();
    numFramesReceivedOK++;
    numBytesReceivedOK += curBytes;
    emit(rxPkOkSignal, frame);

    numFramesPassedToHL++;
    emit(packetSentToUpperSignal, frame);
    // pass up to upper layer
    EV_INFO << "Sending " << frame << " to upper layer.\n";
    send(frame, "upperLayerOut");
}

It emits a signal "packetReceivedFromLower" and my listner has subscribed to it as shown in the above code. 它发出一个信号“ packetReceivedFromLower”,并且我的列表器已订阅它,如上面的代码所示。

Problem is the counter shows tempDelmeJustForTest = 12 when the sender sends only 6 Ethernet Frames . 问题是当发送方仅发送6个以太网帧时,计数器显示tempDelmeJustForTest = 12 Why ? 为什么呢

在此处输入图片说明

Also, I am project referencing Core4Inet project other than the Inet project. 另外,我正在引用Inet项目以外的Core4Inet项目。

I am guessing you are overhearing the signal emitted by the MAC layer of the destination host and the MAC layer of the switch. 我猜您正在监听目标主机的MAC层和交换机的MAC层发出的信号。

By subscribing not just at your own module, but at the module returned by simulation.getSystemModule() , you are overhearing all signals of type packetReceivedFromLower emitted anywhere in the simulation. 通过不仅订阅您自己的模块,还订阅了simulation.getSystemModule()返回的模块,您可以监听模拟中任何地方发出的所有packetReceivedFromLower类型的信号。 The "Subscribing to Signals" chapter of the user manual has more information on this mechanism. 用户手册“订阅信号”一章提供了有关此机制的更多信息。

If you want to know where the signal you are overhearing was emitted from, you can use the source parameter of your receiveSignal method. 如果您想知道监听到的信号是从哪里发出的,则可以使用receiveSignal方法的source参数。

The counter tempDelmeJustForTest shows 12 when the sender sends 6 Ethernet Frames, because the method processReceivedDataFrame is involved 6 times in your switch and 6 times in destination host. 当发送方发送6个以太网帧时,计数器tempDelmeJustForTest显示12,因为processReceivedDataFrame在您的交换机中涉及6次,在目标主机中涉及6次。
The command: 命令:

simulation.getSystemModule()->subscribe("packetReceivedFromLower",frameListener);

means that the listener will receive the signal from any element (ie including switch). 表示监听器将接收来自任何元素(包括开关)的信号。
You can check which module sent a signal by adding one line in receiveSignal() : 您可以通过在receiveSignal()添加一行来检查哪个模块发送了信号:

void MyFrameListener::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj){
  EV << "Signal from " << source->getFullPath() << endl;     
  tempDelmeJustForTest++;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM