Add jitter to the application
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/names.h"
|
||||
#include "ns3/double.h"
|
||||
#include "ns3/ethernet-net-device.h"
|
||||
|
||||
#include <cstdio>
|
||||
@@ -51,6 +52,11 @@ EthernetGenerator::GetTypeId()
|
||||
TimeValue(Seconds(0)),
|
||||
MakeTimeAccessor(&EthernetGenerator::m_interframe),
|
||||
MakeTimeChecker())
|
||||
.AddAttribute("Jitter",
|
||||
"Jitter arround the period",
|
||||
TimeValue(Seconds(0)),
|
||||
MakeTimeAccessor(&EthernetGenerator::m_jitter),
|
||||
MakeTimeChecker())
|
||||
.AddAttribute("Offset",
|
||||
"Time offset between application start and first packet emission",
|
||||
TimeValue(Seconds(0)),
|
||||
@@ -114,6 +120,11 @@ EthernetGenerator::StartApplication()
|
||||
else if(m_payload_size < MIN_PAYLOAD_SIZE){
|
||||
m_payload_size = MIN_PAYLOAD_SIZE;
|
||||
}
|
||||
|
||||
m_randVar = CreateObject<UniformRandomVariable> ();
|
||||
m_randVar->SetAttribute ("Min", DoubleValue ((m_period - m_jitter).GetNanoSeconds()));
|
||||
m_randVar->SetAttribute ("Max", DoubleValue ((m_period + m_jitter).GetNanoSeconds()));
|
||||
|
||||
m_sendEvent = Simulator::Schedule(m_offset, &EthernetGenerator::SendBurst, this);
|
||||
}
|
||||
|
||||
@@ -128,10 +139,12 @@ void
|
||||
EthernetGenerator::SendBurst()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
NS_ASSERT(m_randVar != nullptr);
|
||||
for (int i = 0; i < m_burst_size; i++) {
|
||||
Simulator::Schedule(m_interframe*i, &EthernetGenerator::Send, this);
|
||||
}
|
||||
m_sendEvent = Simulator::Schedule(m_period, &EthernetGenerator::SendBurst, this);
|
||||
Time period = NanoSeconds(m_randVar->GetValue());
|
||||
m_sendEvent = Simulator::Schedule(period, &EthernetGenerator::SendBurst, this);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user