A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  *
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 #ifndef ERROR_MODEL_H
56 #define ERROR_MODEL_H
57 
58 #include <list>
59 #include "ns3/object.h"
60 #include "ns3/random-variable-stream.h"
61 
62 namespace ns3 {
63 
64 class Packet;
65 
107 class ErrorModel : public Object
108 {
109 public:
110  static TypeId GetTypeId (void);
111 
112  ErrorModel ();
113  virtual ~ErrorModel ();
114 
122  bool IsCorrupt (Ptr<Packet> pkt);
126  void Reset (void);
130  void Enable (void);
134  void Disable (void);
138  bool IsEnabled (void) const;
139 
140 private:
141  /*
142  * These methods must be implemented by subclasses
143  */
144  virtual bool DoCorrupt (Ptr<Packet>) = 0;
145  virtual void DoReset (void) = 0;
146 
147  bool m_enable;
148 };
149 
166 {
167 public:
168  static TypeId GetTypeId (void);
169 
170  RateErrorModel ();
171  virtual ~RateErrorModel ();
172 
174  {
178  };
179 
183  RateErrorModel::ErrorUnit GetUnit (void) const;
187  void SetUnit (enum ErrorUnit error_unit);
188 
192  double GetRate (void) const;
196  void SetRate (double rate);
197 
202 
211  int64_t AssignStreams (int64_t stream);
212 
213 private:
214  virtual bool DoCorrupt (Ptr<Packet> p);
215  virtual bool DoCorruptPkt (Ptr<Packet> p);
216  virtual bool DoCorruptByte (Ptr<Packet> p);
217  virtual bool DoCorruptBit (Ptr<Packet> p);
218  virtual void DoReset (void);
219 
221  double m_rate;
222 
224 };
225 
249 {
250 public:
251  static TypeId GetTypeId (void);
252  ListErrorModel ();
253  virtual ~ListErrorModel ();
254 
258  std::list<uint32_t> GetList (void) const;
264  void SetList (const std::list<uint32_t> &packetlist);
265 
266 private:
267  virtual bool DoCorrupt (Ptr<Packet> p);
268  virtual void DoReset (void);
269 
270  typedef std::list<uint32_t> PacketList;
271  typedef std::list<uint32_t>::const_iterator PacketListCI;
272 
274 
275 };
276 
290 {
291 public:
292  static TypeId GetTypeId (void);
294  virtual ~ReceiveListErrorModel ();
295 
299  std::list<uint32_t> GetList (void) const;
305  void SetList (const std::list<uint32_t> &packetlist);
306 
307 private:
308  virtual bool DoCorrupt (Ptr<Packet> p);
309  virtual void DoReset (void);
310 
311  typedef std::list<uint32_t> PacketList;
312  typedef std::list<uint32_t>::const_iterator PacketListCI;
313 
315  uint32_t m_timesInvoked;
316 
317 };
318 
319 
320 } // namespace ns3
321 #endif