author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Sat, 04 Jul 2009 08:15:48 +0200 | |
changeset 4654 | 2eaebe77d66b |
parent 3385 | 75095a51d9e2 |
permissions | -rw-r--r-- |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 University of Washington |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
* Author: Tom Henderson <tomhend@u.washington.edu> |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
* This code has been ported from ns-2 (queue/errmodel.{cc,h} |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
#ifndef ERROR_MODEL_H |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
#define ERROR_MODEL_H |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include <list> |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
#include "ns3/object.h" |
2336
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
26 |
#include "ns3/random-variable.h" |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
namespace ns3 { |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
class Packet; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
/** |
3182 | 33 |
* \ingroup common |
34 |
* \defgroup errormodel Error Model |
|
3222
f61c17b62fd1
bug 202: classes disappeared from doxygen output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3182
diff
changeset
|
35 |
*/ |
f61c17b62fd1
bug 202: classes disappeared from doxygen output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3182
diff
changeset
|
36 |
/** |
f61c17b62fd1
bug 202: classes disappeared from doxygen output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3182
diff
changeset
|
37 |
* \ingroup errormodel |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
* \brief General error model that can be used to corrupt packets |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
* This object is used to flag packets as being lost/errored or not. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
* It is part of the Object framework and can be aggregated to |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
* other ns3 objects and handled by the Ptr class. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
* |
2189
036cf935e7cf
packet pointer police patrolled product preventing presence of prior pattern proactively
Craig Dowell <craigdo@ee.washington.edu>
parents:
1870
diff
changeset
|
44 |
* The main method is IsCorrupt(Ptr<Packet> p) which returns true if |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
* the packet is to be corrupted according to the underlying model. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
* Depending on the error model, the packet itself may have its packet |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
* data buffer errored or not, or side information may be returned to |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
* the client in the form of a packet tag. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
* The object can have state (resettable by Reset()). |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
* The object can also be enabled and disabled via two public member functions. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
* Typical code (simplified) to use an ErrorModel may look something like |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
* this: |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
* \code |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2189
diff
changeset
|
55 |
* Ptr<ErrorModel> rem = CreateObject<RateErrorModel> (); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
* rem->SetRandomVariable (UniformVariable ()); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
* rem->SetRate (0.001); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
* ... |
1870 | 59 |
* Ptr<Packet> p; |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
* if (rem->IsCorrupt (p)) |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
* { |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
* dropTrace(p); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
* } else { |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
* Forward (p); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
* } |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
* \endcode |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
* Two practical error models, a ListErrorModel and a RateErrorModel, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
* are currently implemented. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
71 |
class ErrorModel : public Object |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
{ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
74 |
static TypeId GetTypeId (void); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
ErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
virtual ~ErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
* \returns true if the Packet is to be considered as errored/corrupted |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
* \param pkt Packet to apply error model to |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
*/ |
1870 | 83 |
bool IsCorrupt (Ptr<Packet> pkt); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
* Reset any state associated with the error model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
86 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
87 |
void Reset (void); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
88 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
* Enable the error model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
90 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
91 |
void Enable (void); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
92 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
93 |
* Disable the error model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
94 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
95 |
void Disable (void); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
96 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
* \return true if error model is enabled; false otherwise |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
bool IsEnabled (void) const; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
private: |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
102 |
/* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
* These methods must be implemented by subclasses |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
*/ |
1870 | 105 |
virtual bool DoCorrupt (Ptr<Packet>) = 0; |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
virtual void DoReset (void) = 0; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
|
3371
e472358ea634
do not make m_enable protected
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3222
diff
changeset
|
108 |
bool m_enable; |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
109 |
}; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
111 |
enum ErrorUnit |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
112 |
{ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
EU_BIT, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
EU_BYTE, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
115 |
EU_PKT |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
}; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
118 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
* \brief Determine which packets are errored corresponding to an underlying |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
* distribution, rate, and unit. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
* This object is used to flag packets as being lost/errored or not. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
* The two parameters that govern the behavior are the rate (or |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
124 |
* equivalently, the mean duration/spacing between errors), and the |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
125 |
* unit (which may be per-bit, per-byte, and per-packet). |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
126 |
* Users can optionally provide a RandomVariable object; the default |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
* is to use a Uniform(0,1) distribution. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
129 |
* Reset() on this model will do nothing |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
130 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
* IsCorrupt() will not modify the packet data buffer |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
132 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
class RateErrorModel : public ErrorModel |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
{ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
135 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
136 |
static TypeId GetTypeId (void); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
137 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
138 |
RateErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
139 |
virtual ~RateErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
141 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
142 |
* \returns the ErrorUnit being used by the underlying model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
143 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
144 |
enum ErrorUnit GetUnit (void) const; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
145 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
146 |
* \param error_unit the ErrorUnit to be used by the underlying model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
148 |
void SetUnit (enum ErrorUnit error_unit); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
149 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
150 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
151 |
* \returns the error rate being applied by the model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
double GetRate (void) const; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
154 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
* \param rate the error rate to be used by the model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
void SetRate (double rate); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
160 |
* \param ranvar A random variable distribution to generate random variates |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
161 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
162 |
void SetRandomVariable (const RandomVariable &ranvar); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
164 |
private: |
1870 | 165 |
virtual bool DoCorrupt (Ptr<Packet> p); |
166 |
virtual bool DoCorruptPkt (Ptr<Packet> p); |
|
167 |
virtual bool DoCorruptByte (Ptr<Packet> p); |
|
168 |
virtual bool DoCorruptBit (Ptr<Packet> p); |
|
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
169 |
virtual void DoReset (void); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
170 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
171 |
enum ErrorUnit m_unit; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
172 |
double m_rate; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
173 |
|
2336
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
174 |
RandomVariable m_ranvar; |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
175 |
}; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
176 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
177 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
178 |
* \brief Provide a list of Packet uids to corrupt |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
179 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
180 |
* This object is used to flag packets as being lost/errored or not. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
181 |
* A note on performance: the list is assumed to be unordered, and |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
182 |
* in general, Packet uids received may be unordered. Therefore, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
183 |
* each call to IsCorrupt() will result in a walk of the list with |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
184 |
* the present underlying implementation. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
185 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
186 |
* Note also that if one wants to target multiple packets from looking |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
187 |
* at an (unerrored) trace file, the act of erroring a given packet may |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
188 |
* cause subsequent packet uids to change. For instance, suppose one wants |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
189 |
* to error packets 11 and 17 on a given device. It may be that erroring |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
190 |
* packet 11 will cause the subsequent uid stream to change and 17 may no |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
191 |
* longer correspond to the second packet that one wants to lose. Therefore, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
192 |
* be advised that it might take some trial and error to select the |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
193 |
* right uids when multiple are provided. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
194 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
195 |
* Reset() on this model will clear the list |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
196 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
197 |
* IsCorrupt() will not modify the packet data buffer |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
198 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
199 |
class ListErrorModel : public ErrorModel |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
200 |
{ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
201 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
202 |
static TypeId GetTypeId (void); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
203 |
ListErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
204 |
virtual ~ListErrorModel (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
205 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
206 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
207 |
* \return a copy of the underlying list |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
208 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
209 |
std::list<uint32_t> GetList (void) const; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
210 |
/** |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
211 |
* \param packetlist The list of packet uids to error. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
212 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
213 |
* This method overwrites any previously provided list. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
214 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
215 |
void SetList (const std::list<uint32_t> &packetlist); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
216 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
217 |
private: |
1870 | 218 |
virtual bool DoCorrupt (Ptr<Packet> p); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
219 |
virtual void DoReset (void); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
220 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
221 |
typedef std::list<uint32_t> PacketList; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
222 |
typedef std::list<uint32_t>::const_iterator PacketListCI; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
223 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
224 |
PacketList m_packetList; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
225 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
226 |
}; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
227 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
228 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
229 |
} //namespace ns3 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
230 |
#endif |