void Txc15::initialize()
{
int n = par("pkt"); //number of packets that node 0 will transmit
double x; //this will contain the time when the next packet will be transmitted
hopCountStats.setName("hopCountStats");
hopCountStats.setRangeAutoUpper(0, 10, 1.5);
hopCountVector.setName("HopCount");
// Module 0 sends the first message
if (getIndex()==0) // NOTE: if you comment this line and the other two "{" and "}" every node will transmit packets randomly
{
TicTocMsg15 *msg[n]; // a vector of messages
// Multiple messages from node 0
for (i=0;i<=n-1;i++) {
msg[i] = generateMessage();
x = exponential(2); //here i extract the next instant when the packet will be scheduled
EV << "pkt " << msg[i] << " will be transmitted in " << x << " seconds!\n";
scheduleAt(0.0+x, msg[i]);
}
}
}
Let me know if you like this solution or you have a better one :)