Omnet++ Omnet++;将消息从特定节点发送到其他特定节点

Omnet++ Omnet++;将消息从特定节点发送到其他特定节点,omnet++,Omnet++,下面是由3个节点组成的网络的my.ned文件 simple computer { parameters: gates: input in1; output out1; input in2; output out2; } // // TODO documentation // network Network { @display("bgb=538,302"); submodules:

下面是由3个节点组成的网络的my.ned文件

simple computer
{
    parameters:

    gates:
        input in1;
        output out1;
        input in2;
        output out2;

}

//
// TODO documentation
//
network Network
{
    @display("bgb=538,302");
    submodules:
        A: computer {
            @display("p=30,88");
        }
        B: computer {
            @display("p=344,96");
        }
        C: computer {
            @display("p=209,199");
        }
    connections:

        A.out1 --> B.in1;
        B.out1 --> A.in1;

        A.out2 --> C.in1;
        C.out1 --> A.in2;

        C.out2 --> B.in2;
        B.out2 --> C.in2;
}


#include <string.h>
#include <omnetpp.h>
#include <string>

    int a2b=8; int b2a=8;
    int b2c=2; int c2b=2;
    int a2c=5; int c2a=5;
        char node='x';
        int roundd=0;
        char rec='A';

 int Amatrix[3][3];
 int Bmatrix[3][3];
 int Cmatrix[3][3];

class computer: public cSimpleModule
{
  public:


    virtual void initialize();
    virtual void handleMessage(cMessage *msg);

    void fill()
    {
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<3 ; j++)
            {
                Amatrix[i][j]=Bmatrix[i][j]=Cmatrix[i][j]=0;
            }
        }

    }
    void fillA()
    {

        Amatrix[0][0]=0;Amatrix[0][1]=a2b;Amatrix[0][2]=a2c;
    }
    void fillB()
    {
        Bmatrix[1][0]=a2b;Bmatrix[1][1]=0;Bmatrix[1][2]=b2c;
    }
    void fillC()
       {
           Cmatrix[2][0]=a2c;Cmatrix[2][1]=b2c;Cmatrix[2][2]=0;
       }

};
//----------------------------------------------------------------------

Define_Module(computer);







void computer::initialize()
{

    if ((strcmp("A", getName()) == 0)&&(roundd==0))
    {
       node='A';
       fill();
       fillA();fillB(); fillC(); roundd=1;node='A';
       cMessage *msg = new cMessage("tictocMsg");
       cMessage *ww ; ww=msg;
       EV << "sending message from node    " << node ;
       send(msg, "out1");



       cMessage *copy = (cMessage *) msg->dup();
       send(copy, "out2");
    }

}







void computer::handleMessage(cMessage *msg)
{


           if((strcmp("B", getName()) == 0 )&&(roundd=1)&&(node=='A'))
           {
                   rec='B';
                   EV <<"\n NODE AT WHICH THE MESSAGE IS AT CURRENTLY IS   " << rec <<endl;
                   for(int i=0 ; i<3 ; i++)
                   {
                       Bmatrix[0][i]=Amatrix[0][i];
                   }
           }


           else if((strcmp("C", getName()) == 0)&&(node=='A')&&(roundd==1))
       {
               rec='C';
               EV <<"\n NODE AT WHICH THE MESSAGE IS AT CURRENTLY IS   " << rec <<endl;
               for(int i=0 ; i<3 ; i++)
               {
                 Cmatrix[0][i]=Amatrix[0][i];
               }
               roundd=2;
        }

           if(roundd==2)
           {
               if((strcmp("C", getName()) == 0 )){EV << " node c ";}
               if((strcmp("B", getName()) == 0 )){EV << " node B ";}

           }}
Now in the roundd 2

 if(roundd==2)
           {
               if((strcmp("C", getName()) == 0 )){EV << " node c ";}
               if((strcmp("B", getName()) == 0 )){EV << " node B ";}

           }}
简单计算机
{
参数:
盖茨:
输入in1;
输出out1;
输入in2;
输出输出2;
}
//
//待办事项文档
//
网络
{
@显示(“bgb=538302”);
子模块:
A:电脑{
@显示(“p=30,88”);
}
B:电脑{
@显示(“p=344,96”);
}
C:计算机{
@显示(“p=209199”);
}
连接:
A.out1-->B.in1;
B.out1-->A.in1;
A.out2-->C.in1;
C.out1-->A.in2;
C.out2-->B.in2;
B.out2-->C.in2;
}
#包括
#包括
#包括
int a2b=8;int b2a=8;
int b2c=2;int c2b=2;
int a2c=5;int c2a=5;
char node='x';
int-round=0;
char rec='A';
int Amatrix[3][3];
int Bmatrix[3][3];
int Cmatrix[3][3];
计算机类:公共模块
{
公众:
虚拟空初始化();
虚空handleMessage(cMessage*msg);
填空()
{
对于(int i=0;i可能的重复项)