1 #include "generator.h"
2
3 Define_Module( Generator );
4
5 void Generator::activity()
6 {
7 // init counting
8 messageCount = 0;
9
10 // get parameters
11 double rate = par("rate");
12 double lambda = 1/rate;
13 int rg = par("random_generator");
14
15 // create messages
16 for (;;) {
17 // create message and send it
18 cMessage *msg = new cMessage("job");
19 msg->setTimestamp();
20 send(msg, "out");
21 messageCount++;
22
23 // wait for exponential time (poisson process!)
24 double waitTime = exponential(lambda, rg);
25 wait(waitTime);
26 }
27 }
28
29 void Generator::finish()
30 {
31 ev << "Total messages sent: " << messageCount << endl;
32 }
33