A Discrete-Event Network Simulator
API
error-model.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 University of Washington
4  * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  *
20  * This file incorporates work covered by the following copyright and
21  * permission notice:
22  *
23  * Copyright (c) 1997 Regents of the University of California.
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions
28  * are met:
29  * 1. Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  * 2. Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * 3. Neither the name of the University nor of the Laboratory may be used
35  * to endorse or promote products derived from this software without
36  * specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
42  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  *
50  * Contributed by the Daedalus Research Group, UC Berkeley
51  * (http://daedalus.cs.berkeley.edu)
52  *
53  * This code has been ported from ns-2 (queue/errmodel.{cc,h}
54  */
55 
56 /* BurstErrorModel additions
57  *
58  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
59  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
60  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
61  */
62 
63 #ifndef ERROR_MODEL_H
64 #define ERROR_MODEL_H
65 
66 #include <list>
67 #include "ns3/object.h"
68 #include "ns3/random-variable-stream.h"
69 
70 namespace ns3 {
71 
72 class Packet;
73 
115 class ErrorModel : public Object
116 {
117 public:
122  static TypeId GetTypeId (void);
123 
124  ErrorModel ();
125  virtual ~ErrorModel ();
126 
134  bool IsCorrupt (Ptr<Packet> pkt);
138  void Reset (void);
142  void Enable (void);
146  void Disable (void);
150  bool IsEnabled (void) const;
151 
152 private:
158  virtual bool DoCorrupt (Ptr<Packet> p) = 0;
162  virtual void DoReset (void) = 0;
163 
164  bool m_enable;
165 };
166 
183 {
184 public:
189  static TypeId GetTypeId (void);
190 
191  RateErrorModel ();
192  virtual ~RateErrorModel ();
193 
198  {
202  };
203 
207  RateErrorModel::ErrorUnit GetUnit (void) const;
211  void SetUnit (enum ErrorUnit error_unit);
212 
216  double GetRate (void) const;
220  void SetRate (double rate);
221 
226 
235  int64_t AssignStreams (int64_t stream);
236 
237 private:
238  virtual bool DoCorrupt (Ptr<Packet> p);
244  virtual bool DoCorruptPkt (Ptr<Packet> p);
250  virtual bool DoCorruptByte (Ptr<Packet> p);
256  virtual bool DoCorruptBit (Ptr<Packet> p);
257  virtual void DoReset (void);
258 
260  double m_rate;
261 
263 };
264 
265 
299 {
300 public:
305  static TypeId GetTypeId (void);
306 
307  BurstErrorModel ();
308  virtual ~BurstErrorModel ();
309 
313  double GetBurstRate (void) const;
317  void SetBurstRate (double rate);
318 
323 
328 
337  int64_t AssignStreams (int64_t stream);
338 
339 private:
340  virtual bool DoCorrupt (Ptr<Packet> p);
341  virtual void DoReset (void);
342 
343  double m_burstRate;
346 
351  uint32_t m_counter;
352  uint32_t m_currentBurstSz;
353 
354 };
355 
356 
380 {
381 public:
386  static TypeId GetTypeId (void);
387  ListErrorModel ();
388  virtual ~ListErrorModel ();
389 
393  std::list<uint32_t> GetList (void) const;
399  void SetList (const std::list<uint32_t> &packetlist);
400 
401 private:
402  virtual bool DoCorrupt (Ptr<Packet> p);
403  virtual void DoReset (void);
404 
406  typedef std::list<uint32_t> PacketList;
408  typedef std::list<uint32_t>::const_iterator PacketListCI;
409 
411 
412 };
413 
427 {
428 public:
433  static TypeId GetTypeId (void);
435  virtual ~ReceiveListErrorModel ();
436 
440  std::list<uint32_t> GetList (void) const;
446  void SetList (const std::list<uint32_t> &packetlist);
447 
448 private:
449  virtual bool DoCorrupt (Ptr<Packet> p);
450  virtual void DoReset (void);
451 
453  typedef std::list<uint32_t> PacketList;
455  typedef std::list<uint32_t>::const_iterator PacketListCI;
456 
458  uint32_t m_timesInvoked;
459 
460 };
461 
466 {
467 public:
472  static TypeId GetTypeId (void);
473 
474  BinaryErrorModel ();
475  virtual ~BinaryErrorModel ();
476 
477 private:
478  virtual bool DoCorrupt (Ptr<Packet> p);
479  virtual void DoReset (void);
480 
481  uint8_t m_counter;
482 
483 };
484 
485 } // namespace ns3
486 #endif
bool m_enable
True if the error model is enabled.
Definition: error-model.h:164
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:577
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:478
void SetRandomBurstSize(Ptr< RandomVariableStream > burstSz)
Definition: error-model.cc:346
virtual bool DoCorrupt(Ptr< Packet > p)=0
Corrupt a packet according to the specified model.
PacketList m_packetList
container of sequence number of packets to corrupt
Definition: error-model.h:457
double m_rate
Error rate.
Definition: error-model.h:260
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:490
double GetRate(void) const
Definition: error-model.cc:201
PacketList m_packetList
container of Uid of packets to corrupt
Definition: error-model.h:410
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:556
uint8_t m_counter
internal state counter.
Definition: error-model.h:481
General error model that can be used to corrupt packets.
Definition: error-model.h:115
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:405
virtual ~BinaryErrorModel()
Definition: error-model.cc:571
virtual void DoReset(void)=0
Re-initialize any state.
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:151
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:590
virtual ~RateErrorModel()
Definition: error-model.cc:181
std::list< uint32_t >::const_iterator PacketListCI
Typedef: packet sequence number list const iterator.
Definition: error-model.h:455
virtual bool DoCorruptBit(Ptr< Packet > p)
Corrupt a packet (bit unit).
Definition: error-model.cc:269
Ptr< RandomVariableStream > m_burstStart
the error decision variable
Definition: error-model.h:344
std::list< uint32_t > PacketList
Typedef: packet Uid list.
Definition: error-model.h:406
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: error-model.cc:353
void SetRate(double rate)
Definition: error-model.cc:208
Ptr< RandomVariableStream > m_burstSize
the number of packets being flagged as errored
Definition: error-model.h:345
Provide a list of Packet uids to corrupt.
Definition: error-model.h:379
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:527
enum ErrorUnit m_unit
Error rate unit.
Definition: error-model.h:259
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:278
virtual bool DoCorruptByte(Ptr< Packet > p)
Corrupt a packet (Byte unit).
Definition: error-model.cc:260
Ptr< RandomVariableStream > m_ranvar
rng stream
Definition: error-model.h:262
uint32_t m_counter
keep track of the number of packets being errored until it reaches m_burstSize
Definition: error-model.h:351
void Disable(void)
Disable the error model.
Definition: error-model.cc:132
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:362
virtual ~BurstErrorModel()
Definition: error-model.cc:319
uint32_t m_timesInvoked
number of times the error model has been invoked
Definition: error-model.h:458
virtual ~ListErrorModel()
Definition: error-model.cc:435
double GetBurstRate(void) const
Definition: error-model.cc:325
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:291
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:230
void SetRandomVariable(Ptr< RandomVariableStream > ranVar)
Definition: error-model.cc:339
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:520
void Reset(void)
Reset any state associated with the error model.
Definition: error-model.cc:118
std::list< uint32_t > GetList(void) const
Definition: error-model.cc:441
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:547
The simplest error model, corrupts even packets and does not corrupt odd ones.
Definition: error-model.h:465
void SetUnit(enum ErrorUnit error_unit)
Definition: error-model.cc:194
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:420
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:458
virtual bool DoCorruptPkt(Ptr< Packet > p)
Corrupt a packet (packet unit).
Definition: error-model.cc:253
Determine which bursts of packets are errored corresponding to an underlying distribution, burst rate, and burst size.
Definition: error-model.h:298
uint32_t m_currentBurstSz
the current burst size
Definition: error-model.h:352
Provide a list of Packets to corrupt.
Definition: error-model.h:426
std::list< uint32_t > PacketList
Typedef: packet sequence number list.
Definition: error-model.h:453
bool IsCorrupt(Ptr< Packet > pkt)
Note: Depending on the error model, this function may or may not alter the contents of the packet upo...
Definition: error-model.cc:107
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:448
void SetRandomVariable(Ptr< RandomVariableStream >)
Definition: error-model.cc:215
std::list< uint32_t >::const_iterator PacketListCI
Typedef: packet Uid list const iterator.
Definition: error-model.h:408
double m_burstRate
the burst error event
Definition: error-model.h:343
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:82
RateErrorModel::ErrorUnit GetUnit(void) const
Definition: error-model.cc:187
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: error-model.cc:222
bool IsEnabled(void) const
Definition: error-model.cc:139
A base class which provides memory management and object aggregation.
Definition: object.h:87
Determine which packets are errored corresponding to an underlying distribution, rate, and unit.
Definition: error-model.h:182
virtual ~ErrorModel()
Definition: error-model.cc:101
a unique identifier for an interface.
Definition: type-id.h:58
void SetBurstRate(double rate)
Definition: error-model.cc:332
void Enable(void)
Enable the error model.
Definition: error-model.cc:125
ErrorUnit
Error unit.
Definition: error-model.h:197
std::list< uint32_t > GetList(void) const
Definition: error-model.cc:513