Omnet++ Communication between three node(or more than three)

407 views Asked by At

so I want to configure how the three node communicate with each other but in two ways. I tried different method but all was error different and it didn't run even the simulation but this code run the simulation GUI but Not able to run the simulation

first NO:
Node 1 --> Node 2 --> Node 3 --> Node 1 --> terminate & display round trip time
Second NO:
Node 1 --> Node 2 --> Node 3 --> Node 1
Node 1 <-- Node 2 <-- Node 3 <-- Node 1

the code is below

.NED File code

network Network
{
    @display("bgb=437,321");

    types:
        simple Test
        {
            gates:
                input input_gate[];
                output output_gate[];
        }

    submodules:
        Node0: Test {
            @display("p=43,85");
        }
        Node1: Test {
            @display("p=173,54");
        }
        test: Test {
            @display("p=183,172");
        }

    connections:


        Node0.output_gate++ --> Node1.input_gate++;
        Node1.output_gate++ --> test.input_gate++;
        test.output_gate++ --> Node0.input_gate++;
        test.output_gate++ --> Node1.input_gate++;
        Node1.output_gate++ --> Node0.input_gate++;
        Node0.output_gate++ --> test.input_gate++;
}

.CC Code:

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

using namespace omnetpp;
class Test : public cSimpleModule
{
  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;

};

Define_Module(Test);


void Test::initialize()
{

    if (strcmp("Node0", getName()) == 0) {
        cMessage *msg = new cMessage("tictocMsg");
                send(msg,"output_gate");


    }
}

void Test::handleMessage(cMessage *msg){
        send(msg,"output_gate");
}
1

There are 1 answers

0
Rudi On

In the network you configure the connections between the nodes, not a route that a packet must travel. So that part is not correct. In fact every node must be connected to every other node and then you have to implement your routing logic in the .cc file.

The first scenario is relatively easy because you really just receive the message and send out on the output gate. but you must use a single gate (not a vector gate). That way your current .cc code would work.

The second scenario is a bit more complicated. In that case any received message should be sent out on the other gate, so you have to check the incoming message's gate.