0

下面是 C++ 和 .ned 文件代码。我有 3 个模块 tic、tac 和 toc。我希望消息只遍历每个模块一次,但是在几个事件之后程序变得无响应?具体来说,当消息经过几次迭代后到达 toc 时!如果还有其他解决方法,请告诉我。对不起,我是新手。

 void Txc1::handleMessage(cMessage *msg)
    {
        counter++;
        int n= gateSize("out");
        int k = intuniform(0,gateSize("out")-1);
        cGate *arrivalGate = msg->getArrivalGate();
        cGate *depGate = msg ->getSenderGate();
        if(arrivalGate != NULL)
        {
        int gate = arrivalGate->getIndex();
        int gate_out = depGate ->getIndex();
        EV<<"Arrival Gate: "<<gate<<endl;
        EV<<"Departure Gate: "<<gate_out<<endl;
        if(n >= 2)
        {
        while(gate==k){
        k = gate_out;
        }
        }
        }
        else
        EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
        send(msg, "out", k);
    }


-----.NED-------

simple Txc1
{
    gates:
        input in[];
        output out[];
}

network Tictoc1
{
    submodules:
        tic: Txc1;
        toc: Txc1;
        tac: Txc1;
    connections:
        tic.out++ --> {  delay = 100ms; } --> toc.in++;
        tic.in++ <-- {  delay = 100ms; } <-- toc.out++;
        toc.out++ --> {  delay = 100ms; } --> tac.in++;
        tac.in++ <-- {  delay = 100ms; } <-- toc.out++;
         tac.out++ --> {  delay = 100ms; } --> toc.in++;

        }
4

1 回答 1

1

看起来 tic 和 toc 将永远相互交谈:

tic.out++ --> {  delay = 100ms; } --> toc.in++;
tic.in++ <-- {  delay = 100ms; } <-- toc.out++;

由于 tic “out” 门向 toc “in” 门发送消息,并且 toc “out” 门向 toc “in” 门发送消息,因此它只会绕圈转。

我不明白您在模块源代码中到底要做什么。我会回到带有最新 OMNeT++ 版本的示例 TicToc 项目,并仔细查看连接如何相互通信。这更多是您想要的连接:

tic.out++ --> {  delay = 100ms; } --> toc.in++;
tac.in++ <-- {  delay = 100ms; } <-- toc.out++;
tac.out++ --> { delay = 100ms; } --> tic.in++;

所以它是tic - toc - tac。

于 2013-03-01T12:45:55.457 回答