In this post, I start with a packet generator which simply generate a packet per given period of time.
This will introduce minimum number of files needed to write an Omnet application (cc c++ source file, the network descriptor : ned and the launcher : omnetpp.ini)
Tool: Omnetpp 4.xx (which is built over eclipse)
Not too much speech, let's get our hands dirty.


Periodic packet generator
input : number of packets to generate
Steps: Define a cpp file generator.cc
Define_Module(generator);
#include <omnetpp.h>
class generator : public cSimpleModule
{
private:
int nbPackets, packetCount;
cMessage*generateMsg;
protected:
virtual void initialize()
{
nbPackets=par("totalPackets");
packetCount=0;
generateMsg=new cMessage("selfMsg");
scheduleAt(simTime()+1,generateMsg);
}
virtual void handleMessage(cMessage *msg)
{
EV<<"generated the msg"<packetCount++;
if(packetCount<nbpackets)
scheduleAt(simTime()+1,generateMsg);
}
virtual void finish()
{
if (generateMsg!=NULL)
delete generateMsg;
}
};
The last line instructs the omnet tool to use this source as "generator"
Now let's build the network
generator.ned
package1;
simple generator
{
parameters:
int totalPackets = default(100);
@display("i=msg/job");
}
network one
{
submodules:
gen:generator;
}
Now let's write the launcher file: omnetpp.ini
network = one
**.gen.totalPackets = 10
Build and run
Just right click "one" project and from build menu, build it.
Right click on omnetpp.ini and run the same.
Output is shown below.




