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
70namespace ns3 {
71
72class Packet;
73
115class ErrorModel : public Object
116{
117public:
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
152private:
158 virtual bool DoCorrupt (Ptr<Packet> p) = 0;
162 virtual void DoReset (void) = 0;
163
164 bool m_enable;
165};
166
183{
184public:
189 static TypeId GetTypeId (void);
190
192 virtual ~RateErrorModel ();
193
198 {
202 };
203
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
237private:
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{
300public:
305 static TypeId GetTypeId (void);
306
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
339private:
340 virtual bool DoCorrupt (Ptr<Packet> p);
341 virtual void DoReset (void);
342
343 double m_burstRate;
346
353
354};
355
356
380{
381public:
386 static TypeId GetTypeId (void);
388 virtual ~ListErrorModel ();
389
393 std::list<uint32_t> GetList (void) const;
399 void SetList (const std::list<uint32_t> &packetlist);
400
401private:
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{
428public:
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
448private:
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
459
460};
461
466{
467public:
472 static TypeId GetTypeId (void);
473
475 virtual ~BinaryErrorModel ();
476
477private:
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
The simplest error model, corrupts even packets and does not corrupt odd ones.
Definition: error-model.h:466
uint8_t m_counter
internal state counter.
Definition: error-model.h:481
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:556
virtual ~BinaryErrorModel()
Definition: error-model.cc:571
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:590
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:577
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:339
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:405
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:362
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:291
Ptr< RandomVariableStream > m_burstSize
the number of packets being flagged as errored
Definition: error-model.h:345
virtual ~BurstErrorModel()
Definition: error-model.cc:319
uint32_t m_currentBurstSz
the current burst size
Definition: error-model.h:352
double m_burstRate
the burst error event
Definition: error-model.h:343
void SetBurstRate(double rate)
Definition: error-model.cc:332
uint32_t m_counter
keep track of the number of packets being errored until it reaches m_burstSize
Definition: error-model.h:351
double GetBurstRate(void) const
Definition: error-model.cc:325
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 SetRandomBurstSize(Ptr< RandomVariableStream > burstSz)
Definition: error-model.cc:346
General error model that can be used to corrupt packets.
Definition: error-model.h:116
bool m_enable
True if the error model is enabled.
Definition: error-model.h:164
bool IsEnabled(void) const
Definition: error-model.cc:139
virtual ~ErrorModel()
Definition: error-model.cc:101
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:82
void Disable(void)
Disable the error model.
Definition: error-model.cc:132
void Enable(void)
Enable the error model.
Definition: error-model.cc:125
void Reset(void)
Reset any state associated with the error model.
Definition: error-model.cc:118
virtual bool DoCorrupt(Ptr< Packet > p)=0
Corrupt a packet according to the specified model.
virtual void DoReset(void)=0
Re-initialize any state.
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
Provide a list of Packet uids to corrupt.
Definition: error-model.h:380
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:458
std::list< uint32_t > GetList(void) const
Definition: error-model.cc:441
virtual ~ListErrorModel()
Definition: error-model.cc:435
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:448
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:478
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:420
std::list< uint32_t >::const_iterator PacketListCI
Typedef: packet Uid list const iterator.
Definition: error-model.h:408
std::list< uint32_t > PacketList
Typedef: packet Uid list.
Definition: error-model.h:406
A base class which provides memory management and object aggregation.
Definition: object.h:88
Determine which packets are errored corresponding to an underlying distribution, rate,...
Definition: error-model.h:183
double m_rate
Error rate.
Definition: error-model.h:260
virtual bool DoCorruptByte(Ptr< Packet > p)
Corrupt a packet (Byte unit).
Definition: error-model.cc:260
void SetRate(double rate)
Definition: error-model.cc:208
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:230
ErrorUnit
Error unit.
Definition: error-model.h:198
virtual bool DoCorruptBit(Ptr< Packet > p)
Corrupt a packet (bit unit).
Definition: error-model.cc:269
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
enum ErrorUnit m_unit
Error rate unit.
Definition: error-model.h:259
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:151
virtual ~RateErrorModel()
Definition: error-model.cc:181
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:278
Ptr< RandomVariableStream > m_ranvar
rng stream
Definition: error-model.h:262
void SetUnit(enum ErrorUnit error_unit)
Definition: error-model.cc:194
virtual bool DoCorruptPkt(Ptr< Packet > p)
Corrupt a packet (packet unit).
Definition: error-model.cc:253
double GetRate(void) const
Definition: error-model.cc:201
void SetRandomVariable(Ptr< RandomVariableStream >)
Definition: error-model.cc:215
Provide a list of Packets to corrupt.
Definition: error-model.h:427
std::list< uint32_t > PacketList
Typedef: packet sequence number list.
Definition: error-model.h:453
static TypeId GetTypeId(void)
Get the type ID.
Definition: error-model.cc:490
virtual void DoReset(void)
Re-initialize any state.
Definition: error-model.cc:547
std::list< uint32_t >::const_iterator PacketListCI
Typedef: packet sequence number list const iterator.
Definition: error-model.h:455
uint32_t m_timesInvoked
number of times the error model has been invoked
Definition: error-model.h:458
PacketList m_packetList
container of sequence number of packets to corrupt
Definition: error-model.h:457
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
Definition: error-model.cc:527
std::list< uint32_t > GetList(void) const
Definition: error-model.cc:513
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:520
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.