Hi,
I am creating a new simulation in OMNET PP where there is a home
node which will create a message and send it to other nodes and after
the message come back to its home node it will get updated.The network
look like this:\
But I am having error in the simulation:
Here is my code of the ned:
simple Sample2
{
parameters:
@signal[arrival](type="long");
@statistic[hopCount](title="hop count"; source="arrival"; record=vector,stats; interpolationmode=none);
@display("i=block/routing");
gates:
inout gate[];
}
//
// TODO documentation
//
network Network
{
submodules:
sample2: Sample2 {
@display("p=6.742423,12.994488");
}
sample1: Sample2 {
@display("p=12.38154,12.38154");
}
sample3: Sample2 {
@display("p=9.185308,17.855553");
}
sample4: Sample2 {
@display("p=5.236484,17.340488");
}
sample5: Sample2 {
@display("p=0.90136206,13.30582");
}
sample6: Sample2 {
@display("p=1.9744121,7.468428");
}
sample7: Sample2 {
@display("p=6.9104424,6.180768");
}
connections:
sample2.gate++ <--> sample1.gate++;
sample2.gate++ <--> sample3.gate++;
sample2.gate++ <--> sample4.gate++;
sample5.gate++ <--> sample2.gate++;
sample6.gate++ <--> sample2.gate++;
sample7.gate++ <--> sample2.gate++;
sample6.gate++ <--> sample7.gate++;
sample7.gate++ <--> sample1.gate++;
sample1.gate++ <--> sample3.gate++;
sample3.gate++ <--> sample4.gate++;
sample4.gate++ <--> sample5.gate++;
sample5.gate++ <--> sample6.gate++;
}
The main code in C++:
/*
* Sample2.cc
*
* Created on: Jun 27, 2016
* Author: subhrajit
*/
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
class Sample2 : public cSimpleModule
{
bool homeNode = false;
int cont = 0;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Sample2);
void Sample2::initialize()
{
if (strcmp("sample2", getName()) == 0) {
// The `ev' object works like `cout' in C++.
EV << "Sending initial message\n";
homeNode = true;
cMessage *msg = new cMessage("Subhrajit");
send(msg, "inout");
}
}
void Sample2::handleMessage(cMessage *msg)
{
if (homeNode)
{
// do something
cont++;
msg->setName("abcd");
}
// msg->getName() is name of the msg object, here it will be "tictocMsg".
EV << "Received message `" << msg->getName() << "', sending it out again\n";
send(msg, "inout");
}
Please help me anyone.
Sincerely,
Subhrajit Majumder