0
votes

In omnet ++ while programing tic toc , if there are three nodes and all are connected to one another then how to send tic toc message to a specific node. for example i want to send message first to node A and then Node B and then Node C ; how would i code this.

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

int x=0;

class computerf : public cSimpleModule
{
  protected:

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

Define_Module(computerf);


void computerf::initialize()
{

    if (strcmp("computer1", getName()) == 0)
    {

        cMessage *msg = new cMessage("tictocMsg");
        forwardMessage(msg);
    }
}

void computerf::handleMessage(cMessage *msg)
{

    {
    forwardMessage(msg);
    }

}

void computerf::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    int n = gateSize("out");
        int k = intuniform(0,n-1);

        EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
        send(msg, "out", 1);

    EV <<"n is  "<<n;


}

here in this code forwardMessage function sends message on random gate but i want to send message on specific gate.

this is the .ned file

simple computer
{
    gates:
        input in[2];
        output out[2];


}

//
// TODO documentation
//
network Network
{
    @display("bgb=545,242");
    submodules:
        A: computer {
            @display("p=52,86");
        }
        B: computer {
            @display("p=311,83");
        }
        C: computer {
            @display("p=175,189");
        }
    connections:

        A.out[0] --> B.in[0];
        B.out[0] --> A.in[0];


        A.out[1] --> C.in[1];
        C.out[1] --> A.in[1];


        C.out[0] --> B.in[1];
        B.out[1] --> C.in[0];
}

basically i want node A to send message to node C and Node A to send message to node B simultaneously if i use the hanlde message function void computer::handleMessage(cMessage *msg) {

send(msg, "out",0); //send(msg, "out",0);

} now here in out send(msg, "out",0); i want to specify which "out" i want send message to node C and then to Node B but how?

2

2 Answers

2
votes

The third parameter of the send(msg, "gate", index) is the actual gate index you can use while sending out messages on a vector gate. According to your NED file, send(msg, "out",0); sends the message to B while send(msg, "out",1); sends it to C.

-1
votes

You need to create those gates in Your ned file:

simple Txc
{
    parameters:
        @display("i=block/routing"); // add a default icon
    gates:
        input in1;
        output out1;
        input in2;
        output out2;
}

network Tictoc
{
    submodules:
        tic: Txc {
            parameters:
                @display("i=,cyan"); 
        }
        toc: Txc {
            parameters:
                @display("i=,cyan");  
        }
        toctic: Txc {
            parameters:
                @display("i=,cyan");  
        }
    connections:
        tic.out --> {  delay = 100ms; } --> toc.in;
        tic.in <-- {  delay = 100ms; } <-- toc.out;


        toctic.out2 --> {  delay = 100ms; } --> toc.in2;
        toctic.in2 <-- {  delay = 100ms; } <-- toc.out2;
 //....
}

With this You could send messages like this:

void computerf::forwardMessage(cMessage *msg)
{
   int n = gateSize("out");
     int k = intuniform(0,n-1);

        send(msg, "out1", 1);
//Second message
        send(msg, "out2", 1);
}

Hope this helps.

Best