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

时间:2015-10-07 19:30:56

标签: omnet++

以下是我的3个节点网络的文件

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 ";}

           }}

第一个如果有效,strcmp是&#34; C&#34;。但第二个如果没有。我实际上希望节点B向节点A和C发送两个消息,之后我想将消息从c发送到A和c到B.基本上在初始化时发送两个消息,一个发送到B,一个发送到C.现在我要发送从B到A和B到C的消息 类似地从C到A和C到B我该怎么做?

0 个答案:

没有答案