I am having problem that the sendInterval I am setting is exceeding the limit I set for it.
Below I just added two lines that I am commenting
void EtherTrafGen::scheduleNextPacket(simtime_t previous)
{
simtime_t next;
if (previous == -1) {
next = simTime() <= startTime ? startTime : simTime();
timerMsg->setKind(START);
}
else {
next = previous + sendInterval->doubleValue();
EV << "THE PREVIOUS TIME IS " << previous << " THE SEND INTERVAL IS " << sendInterval->doubleValue() << endl; // Testing
timerMsg->setKind(NEXT);
}
if (stopTime < SIMTIME_ZERO || next < stopTime)
{
scheduleAt(next, timerMsg);
emit(sigSendInterval,sendInterval->doubleValue()); // Vector collect Send Interval Time
}
}
I tested first with fixed sendInterval value
**.Host5.app.sendInterval = 1ms
THE PREVIOUS TIME IS 0.001 THE SEND INTERVAL IS 0.001
THE PREVIOUS TIME IS 0.002 THE SEND INTERVAL IS 0.001
THE PREVIOUS TIME IS 0.003 THE SEND INTERVAL IS 0.001
From that I assumed Previous Time 2 = Previous Time 1 + Send Interval
Second I assumed The interval time is the same as the one in table under Value (The line shown in code)
Then with random sendInterval value
**.Host5.app.sendInterval = uniform(0.99ms,1.01ms)
THE PREVIOUS TIME IS 0.001001856892 THE SEND INTERVAL IS 0.000998752
THE PREVIOUS TIME IS 0.001999544526 THE SEND INTERVAL IS 0.00100136
THE PREVIOUS TIME IS 0.002999144069 THE SEND INTERVAL IS 0.000997365
Previous Time 2 not equal Previous Time 1 + Send Interval
0.001001856892 + 0.000998752 = 0.002000608892
0.002000608892 - 0.001999544526 = 1.064366 usec
The interval time is not the same as the one under Value as shown in the below table
This is causing that the Host is sending out of the range 0.99ms,1.01ms
The parameter sendInterval
is declared in EtherTrafGen.ned
as:
volatile double sendInterval @unit(s);
According to the OMNeT++ Simulation Manual:
The volatile modifier indicates that a parameter is re-read every time a value is needed during simulation.
The variable sendInterval
is declared as a pointer to the object which has access to the sendInterval
parameter. As a consequence, each time one reads the value of sendInterval
, a new random value is returned.
In order to control the current value of sendInterval
I suggest reading it only once and storing the result in temporary variable, for example:
void EtherTrafGen::scheduleNextPacket(simtime_t previous)
{
simtime_t next;
double sendIntervalTemp = sendInterval->doubleValue(); // one time read
if (previous == -1) {
next = simTime() <= startTime ? startTime : simTime();
timerMsg->setKind(START);
}
else {
next = previous + sendIntervalTemp ;
EV << "THE PREVIOUS TIME IS " << previous <<
" THE SEND INTERVAL IS " << sendIntervalTemp << endl; // Testing
timerMsg->setKind(NEXT);
}
if (stopTime < SIMTIME_ZERO || next < stopTime)
{
scheduleAt(next, timerMsg);
emit(sigSendInterval, sendIntervalTemp); // Vector collect Send Interval Time
}
}