程序无响应:OMNet ++

时间:2012-07-04 19:10:27

标签: omnet++

下面是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++;

        }

1 个答案:

答案 0 :(得分:1)

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

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

当tic“out”门发出信息时,toc“in”门和toc“out”门信息toc“in”gate,所以它将绕圈旋转。

我不明白你在模块源代码中想要做什么。我将回到最新的OMNeT ++版本的示例TicToc项目,并密切关注连接如何与彼此交谈。这更像是你想要的连接:

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

所以它是tic - toc - tac。