Add jitter to the application
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "ns3/socket.h"
|
#include "ns3/socket.h"
|
||||||
#include "ns3/uinteger.h"
|
#include "ns3/uinteger.h"
|
||||||
#include "ns3/names.h"
|
#include "ns3/names.h"
|
||||||
|
#include "ns3/double.h"
|
||||||
#include "ns3/ethernet-net-device.h"
|
#include "ns3/ethernet-net-device.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -51,6 +52,11 @@ EthernetGenerator::GetTypeId()
|
|||||||
TimeValue(Seconds(0)),
|
TimeValue(Seconds(0)),
|
||||||
MakeTimeAccessor(&EthernetGenerator::m_interframe),
|
MakeTimeAccessor(&EthernetGenerator::m_interframe),
|
||||||
MakeTimeChecker())
|
MakeTimeChecker())
|
||||||
|
.AddAttribute("Jitter",
|
||||||
|
"Jitter arround the period",
|
||||||
|
TimeValue(Seconds(0)),
|
||||||
|
MakeTimeAccessor(&EthernetGenerator::m_jitter),
|
||||||
|
MakeTimeChecker())
|
||||||
.AddAttribute("Offset",
|
.AddAttribute("Offset",
|
||||||
"Time offset between application start and first packet emission",
|
"Time offset between application start and first packet emission",
|
||||||
TimeValue(Seconds(0)),
|
TimeValue(Seconds(0)),
|
||||||
@@ -114,6 +120,11 @@ EthernetGenerator::StartApplication()
|
|||||||
else if(m_payload_size < MIN_PAYLOAD_SIZE){
|
else if(m_payload_size < MIN_PAYLOAD_SIZE){
|
||||||
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);
|
m_sendEvent = Simulator::Schedule(m_offset, &EthernetGenerator::SendBurst, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,10 +139,12 @@ void
|
|||||||
EthernetGenerator::SendBurst()
|
EthernetGenerator::SendBurst()
|
||||||
{
|
{
|
||||||
NS_LOG_FUNCTION(this);
|
NS_LOG_FUNCTION(this);
|
||||||
|
NS_ASSERT(m_randVar != nullptr);
|
||||||
for (int i = 0; i < m_burst_size; i++) {
|
for (int i = 0; i < m_burst_size; i++) {
|
||||||
Simulator::Schedule(m_interframe*i, &EthernetGenerator::Send, this);
|
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
|
void
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "ns3/application.h"
|
#include "ns3/application.h"
|
||||||
#include "ns3/event-id.h"
|
#include "ns3/event-id.h"
|
||||||
#include "ns3/ptr.h"
|
#include "ns3/ptr.h"
|
||||||
|
#include "ns3/random-variable-stream.h"
|
||||||
#include <ns3/traced-callback.h>
|
#include <ns3/traced-callback.h>
|
||||||
#include "ns3/ethernet-net-device.h"
|
#include "ns3/ethernet-net-device.h"
|
||||||
|
|
||||||
@@ -53,8 +54,11 @@ class EthernetGenerator : public Application
|
|||||||
int m_burst_size;
|
int m_burst_size;
|
||||||
Time m_period;
|
Time m_period;
|
||||||
Time m_interframe;
|
Time m_interframe;
|
||||||
|
Time m_jitter;
|
||||||
Time m_offset;
|
Time m_offset;
|
||||||
|
|
||||||
|
Ptr<UniformRandomVariable> m_randVar = nullptr;
|
||||||
|
|
||||||
uint16_t m_vid;
|
uint16_t m_vid;
|
||||||
uint8_t m_pcp;
|
uint8_t m_pcp;
|
||||||
uint8_t m_dei;
|
uint8_t m_dei;
|
||||||
|
|||||||
Reference in New Issue
Block a user