65 #include "error-model.h"
67 #include "ns3/packet.h"
68 #include "ns3/assert.h"
70 #include "ns3/boolean.h"
72 #include "ns3/double.h"
73 #include "ns3/string.h"
74 #include "ns3/pointer.h"
80 NS_OBJECT_ENSURE_REGISTERED (ErrorModel);
82 TypeId ErrorModel::GetTypeId (
void)
84 static TypeId tid = TypeId (
"ns3::ErrorModel")
86 .AddAttribute (
"IsEnabled",
"Whether this ErrorModel is enabled or not.",
88 MakeBooleanAccessor (&ErrorModel::m_enable),
89 MakeBooleanChecker ())
94 ErrorModel::ErrorModel () :
100 ErrorModel::~ErrorModel ()
111 result = DoCorrupt (p);
150 TypeId RateErrorModel::GetTypeId (
void)
154 .AddConstructor<RateErrorModel> ()
155 .AddAttribute (
"ErrorUnit",
"The error unit",
157 MakeEnumAccessor (&RateErrorModel::m_unit),
158 MakeEnumChecker (ERROR_UNIT_BIT,
"ERROR_UNIT_BIT",
159 ERROR_UNIT_BYTE,
"ERROR_UNIT_BYTE",
160 ERROR_UNIT_PACKET,
"ERROR_UNIT_PACKET"))
161 .AddAttribute (
"ErrorRate",
"The error rate.",
163 MakeDoubleAccessor (&RateErrorModel::m_rate),
164 MakeDoubleChecker<double> ())
165 .AddAttribute (
"RanVar",
"The decision variable attached to this error model.",
166 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
167 MakePointerAccessor (&RateErrorModel::m_ranvar),
168 MakePointerChecker<RandomVariableStream> ())
174 RateErrorModel::RateErrorModel ()
179 RateErrorModel::~RateErrorModel ()
184 RateErrorModel::ErrorUnit
237 case ERROR_UNIT_PACKET:
238 return DoCorruptPkt (p);
239 case ERROR_UNIT_BYTE:
240 return DoCorruptByte (p);
242 return DoCorruptBit (p);
251 RateErrorModel::DoCorruptPkt (Ptr<Packet> p)
254 return (m_ranvar->
GetValue () < m_rate);
258 RateErrorModel::DoCorruptByte (Ptr<Packet> p)
262 double per = 1 - std::pow (1.0 - m_rate, static_cast<double> (p->GetSize ()));
263 return (m_ranvar->
GetValue () < per);
267 RateErrorModel::DoCorruptBit (Ptr<Packet> p)
271 double per = 1 - std::pow (1.0 - m_rate, static_cast<double> (8 * p->GetSize ()) );
272 return (m_ranvar->
GetValue () < per);
276 RateErrorModel::DoReset (
void)
287 NS_OBJECT_ENSURE_REGISTERED (BurstErrorModel);
289 TypeId BurstErrorModel::GetTypeId (
void)
291 static TypeId tid = TypeId (
"ns3::BurstErrorModel")
293 .AddConstructor<BurstErrorModel> ()
294 .AddAttribute (
"ErrorRate",
"The burst error event.",
296 MakeDoubleAccessor (&BurstErrorModel::m_burstRate),
297 MakeDoubleChecker<double> ())
298 .AddAttribute (
"BurstStart",
"The decision variable attached to this error model.",
299 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
300 MakePointerAccessor (&BurstErrorModel::m_burstStart),
301 MakePointerChecker<RandomVariableStream> ())
302 .AddAttribute (
"BurstSize",
"The number of packets being corrupted at one drop.",
303 StringValue (
"ns3::UniformRandomVariable[Min=1|Max=4]"),
304 MakePointerAccessor (&BurstErrorModel::m_burstSize),
305 MakePointerChecker<RandomVariableStream> ())
311 BurstErrorModel::BurstErrorModel () : m_counter (0), m_currentBurstSz (0)
316 BurstErrorModel::~BurstErrorModel ()
339 m_burstStart = ranVar;
346 m_burstSize = burstSz;
366 double ranVar = m_burstStart ->
GetValue();
368 if (ranVar < m_burstRate)
372 NS_LOG_DEBUG (
"new burst size selected: " << m_currentBurstSz);
373 if (m_currentBurstSz == 0)
384 if (m_counter < m_currentBurstSz)
402 BurstErrorModel::DoReset (
void)
406 m_currentBurstSz = 0;
415 NS_OBJECT_ENSURE_REGISTERED (ListErrorModel);
417 TypeId ListErrorModel::GetTypeId (
void)
419 static TypeId tid = TypeId (
"ns3::ListErrorModel")
420 .SetParent<ErrorModel> ()
421 .AddConstructor<ListErrorModel> ()
426 ListErrorModel::ListErrorModel ()
431 ListErrorModel::~ListErrorModel ()
447 m_packetList = packetlist;
461 uint32_t uid = p->
GetUid ();
462 for (PacketListCI i = m_packetList.begin ();
463 i != m_packetList.end (); i++)
474 ListErrorModel::DoReset (
void)
477 m_packetList.clear ();
484 NS_OBJECT_ENSURE_REGISTERED (ReceiveListErrorModel);
486 TypeId ReceiveListErrorModel::GetTypeId (
void)
488 static TypeId tid = TypeId (
"ns3::ReceiveListErrorModel")
489 .SetParent<ErrorModel> ()
490 .AddConstructor<ReceiveListErrorModel> ()
496 ReceiveListErrorModel::ReceiveListErrorModel () :
502 ReceiveListErrorModel::~ReceiveListErrorModel ()
518 m_packetList = packetlist;
530 for (PacketListCI i = m_packetList.begin ();
531 i != m_packetList.end (); i++)
533 if (m_timesInvoked - 1 == *i)
542 ReceiveListErrorModel::DoReset (
void)
545 m_packetList.clear ();
std::list< uint32_t > GetList(void) const
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
hold variables of type string
std::list< uint32_t > GetList(void) const
uint64_t GetUid(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
void SetRandomVariable(Ptr< RandomVariableStream >)
General error model that can be used to corrupt packets.
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
void SetRandomBurstSize(Ptr< RandomVariableStream >)
virtual uint32_t GetInteger(void)=0
Returns a random integer integer from the underlying distribution.
bool IsEnabled(void) const
hold variables of type 'enum'
int64_t AssignStreams(int64_t stream)
void SetRate(double rate)
double GetRate(void) const
void SetList(const std::list< uint32_t > &packetlist)
#define NS_ASSERT_MSG(condition, message)
void SetUnit(enum ErrorUnit error_unit)
double GetBurstRate(void) const
#define NS_LOG_DEBUG(msg)
bool IsCorrupt(Ptr< Packet > pkt)
void SetList(const std::list< uint32_t > &packetlist)
void SetRandomVariable(Ptr< RandomVariableStream >)
int64_t AssignStreams(int64_t stream)
Determine which packets are errored corresponding to an underlying distribution, rate, and unit.
Hold an floating point type.
RateErrorModel::ErrorUnit GetUnit(void) const
a unique identifier for an interface.
void SetBurstRate(double rate)
TypeId SetParent(TypeId tid)