A Discrete-Event Network Simulator
API
error-model.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 University of Washington
3  * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * This file incorporates work covered by the following copyright and
20  * permission notice:
21  *
22  * Copyright (c) 1997 Regents of the University of California.
23  * All rights reserved.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution.
33  * 3. Neither the name of the University nor of the Laboratory may be used
34  * to endorse or promote products derived from this software without
35  * specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  * Contributed by the Daedalus Research Group, UC Berkeley
50  * (http://daedalus.cs.berkeley.edu)
51  *
52  * This code has been ported from ns-2 (queue/errmodel.{cc,h}
53  */
54 
55 /* BurstErrorModel additions
56  *
57  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
58  * ResiliNets Research Group https://resilinets.org/
59  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
60  */
61 
62 #ifndef ERROR_MODEL_H
63 #define ERROR_MODEL_H
64 
65 #include "ns3/object.h"
66 #include "ns3/random-variable-stream.h"
67 
68 #include <list>
69 
70 namespace ns3
71 {
72 
73 class Packet;
74 
116 class ErrorModel : public Object
117 {
118  public:
123  static TypeId GetTypeId();
124 
125  ErrorModel();
126  ~ErrorModel() override;
127 
135  bool IsCorrupt(Ptr<Packet> pkt);
139  void Reset();
143  void Enable();
147  void Disable();
151  bool IsEnabled() const;
152 
153  private:
159  virtual bool DoCorrupt(Ptr<Packet> p) = 0;
163  virtual void DoReset() = 0;
164 
165  bool m_enable;
166 };
167 
184 {
185  public:
190  static TypeId GetTypeId();
191 
192  RateErrorModel();
193  ~RateErrorModel() override;
194 
199  {
203  };
204 
212  void SetUnit(ErrorUnit error_unit);
213 
217  double GetRate() const;
221  void SetRate(double rate);
222 
227 
236  int64_t AssignStreams(int64_t stream);
237 
238  private:
239  bool DoCorrupt(Ptr<Packet> p) override;
245  virtual bool DoCorruptPkt(Ptr<Packet> p);
251  virtual bool DoCorruptByte(Ptr<Packet> p);
257  virtual bool DoCorruptBit(Ptr<Packet> p);
258  void DoReset() override;
259 
261  double m_rate;
262 
264 };
265 
299 {
300  public:
305  static TypeId GetTypeId();
306 
307  BurstErrorModel();
308  ~BurstErrorModel() override;
309 
313  double GetBurstRate() const;
317  void SetBurstRate(double rate);
318 
323 
328 
337  int64_t AssignStreams(int64_t stream);
338 
339  private:
340  bool DoCorrupt(Ptr<Packet> p) override;
341  void DoReset() override;
342 
343  double m_burstRate;
346 
351  uint32_t m_counter;
352  uint32_t m_currentBurstSz;
353 };
354 
378 {
379  public:
384  static TypeId GetTypeId();
385  ListErrorModel();
386  ~ListErrorModel() override;
387 
391  std::list<uint64_t> GetList() const;
397  void SetList(const std::list<uint64_t>& packetlist);
398 
399  private:
400  bool DoCorrupt(Ptr<Packet> p) override;
401  void DoReset() override;
402 
404  typedef std::list<uint64_t> PacketList;
406  typedef std::list<uint64_t>::const_iterator PacketListCI;
407 
409 };
410 
424 {
425  public:
430  static TypeId GetTypeId();
432  ~ReceiveListErrorModel() override;
433 
437  std::list<uint32_t> GetList() const;
443  void SetList(const std::list<uint32_t>& packetlist);
444 
445  private:
446  bool DoCorrupt(Ptr<Packet> p) override;
447  void DoReset() override;
448 
450  typedef std::list<uint32_t> PacketList;
452  typedef std::list<uint32_t>::const_iterator PacketListCI;
453 
455  uint32_t m_timesInvoked;
456 };
457 
462 {
463  public:
468  static TypeId GetTypeId();
469 
471  ~BinaryErrorModel() override;
472 
473  private:
474  bool DoCorrupt(Ptr<Packet> p) override;
475  void DoReset() override;
476 
477  uint8_t m_counter;
478 };
479 
480 } // namespace ns3
481 #endif
The simplest error model, corrupts even packets and does not corrupt odd ones.
Definition: error-model.h:462
uint8_t m_counter
internal state counter.
Definition: error-model.h:477
void DoReset() override
Re-initialize any state.
Definition: error-model.cc:593
~BinaryErrorModel() override
Definition: error-model.cc:574
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:561
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Definition: error-model.cc:580
Determine which bursts of packets are errored corresponding to an underlying distribution,...
Definition: error-model.h:299
Ptr< RandomVariableStream > m_burstStart
the error decision variable
Definition: error-model.h:344
void SetRandomVariable(Ptr< RandomVariableStream > ranVar)
Definition: error-model.cc:349
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Definition: error-model.cc:372
Ptr< RandomVariableStream > m_burstSize
the number of packets being flagged as errored
Definition: error-model.h:345
uint32_t m_currentBurstSz
the current burst size
Definition: error-model.h:352
double GetBurstRate() const
Definition: error-model.cc:335
void DoReset() override
Re-initialize any state.
Definition: error-model.cc:415
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:298
double m_burstRate
the burst error event
Definition: error-model.h:343
void SetBurstRate(double rate)
Definition: error-model.cc:342
uint32_t m_counter
keep track of the number of packets being errored until it reaches m_burstSize
Definition: error-model.h:351
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:363
~BurstErrorModel() override
Definition: error-model.cc:329
void SetRandomBurstSize(Ptr< RandomVariableStream > burstSz)
Definition: error-model.cc:356
General error model that can be used to corrupt packets.
Definition: error-model.h:117
bool m_enable
True if the error model is enabled.
Definition: error-model.h:165
void Reset()
Reset any state associated with the error model.
Definition: error-model.cc:119
void Enable()
Enable the error model.
Definition: error-model.cc:126
bool IsEnabled() const
Definition: error-model.cc:140
~ErrorModel() override
Definition: error-model.cc:102
virtual bool DoCorrupt(Ptr< Packet > p)=0
Corrupt a packet according to the specified model.
virtual void DoReset()=0
Re-initialize any state.
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:83
void Disable()
Disable the error model.
Definition: error-model.cc:133
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:108
Provide a list of Packet uids to corrupt.
Definition: error-model.h:378
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Definition: error-model.cc:466
~ListErrorModel() override
Definition: error-model.cc:443
void DoReset() override
Re-initialize any state.
Definition: error-model.cc:485
std::list< uint64_t > PacketList
Typedef: packet Uid list.
Definition: error-model.h:404
void SetList(const std::list< uint64_t > &packetlist)
Definition: error-model.cc:456
std::list< uint64_t > GetList() const
Definition: error-model.cc:449
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:429
PacketList m_packetList
container of Uid of packets to corrupt
Definition: error-model.h:408
std::list< uint64_t >::const_iterator PacketListCI
Typedef: packet Uid list const iterator.
Definition: error-model.h:406
A base class which provides memory management and object aggregation.
Definition: object.h:89
Determine which packets are errored corresponding to an underlying distribution, rate,...
Definition: error-model.h:184
double m_rate
Error rate.
Definition: error-model.h:261
virtual bool DoCorruptByte(Ptr< Packet > p)
Corrupt a packet (Byte unit).
Definition: error-model.cc:267
ErrorUnit m_unit
Error rate unit.
Definition: error-model.h:260
void SetRate(double rate)
Definition: error-model.cc:215
ErrorUnit
Error unit.
Definition: error-model.h:199
void DoReset() override
Re-initialize any state.
Definition: error-model.cc:285
virtual bool DoCorruptBit(Ptr< Packet > p)
Corrupt a packet (bit unit).
Definition: error-model.cc:276
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:229
void SetUnit(ErrorUnit error_unit)
Definition: error-model.cc:201
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:153
~RateErrorModel() override
Definition: error-model.cc:188
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Definition: error-model.cc:237
Ptr< RandomVariableStream > m_ranvar
rng stream
Definition: error-model.h:263
virtual bool DoCorruptPkt(Ptr< Packet > p)
Corrupt a packet (packet unit).
Definition: error-model.cc:260
void SetRandomVariable(Ptr< RandomVariableStream >)
Definition: error-model.cc:222
RateErrorModel::ErrorUnit GetUnit() const
Definition: error-model.cc:194
double GetRate() const
Definition: error-model.cc:208
Provide a list of Packets to corrupt.
Definition: error-model.h:424
std::list< uint32_t > PacketList
Typedef: packet sequence number list.
Definition: error-model.h:450
void DoReset() override
Re-initialize any state.
Definition: error-model.cc:552
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Definition: error-model.cc:533
std::list< uint32_t >::const_iterator PacketListCI
Typedef: packet sequence number list const iterator.
Definition: error-model.h:452
static TypeId GetTypeId()
Get the type ID.
Definition: error-model.cc:498
uint32_t m_timesInvoked
number of times the error model has been invoked
Definition: error-model.h:455
std::list< uint32_t > GetList() const
Definition: error-model.cc:519
PacketList m_packetList
container of sequence number of packets to corrupt
Definition: error-model.h:454
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:526
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.