2007-11-14 20:40:05 -08:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2007 University of Washington
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
2012-05-04 11:27:01 -07:00
|
|
|
*
|
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
|
* permission notice:
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 1997 Regents of the University of California.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. Neither the name of the University nor of the Laboratory may be used
|
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
|
* specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
* Contributed by the Daedalus Research Group, UC Berkeley
|
|
|
|
|
* (http://daedalus.cs.berkeley.edu)
|
|
|
|
|
*
|
2007-11-14 20:40:05 -08:00
|
|
|
* This code has been ported from ns-2 (queue/errmodel.{cc,h}
|
|
|
|
|
*/
|
2012-05-04 11:27:01 -07:00
|
|
|
|
2007-11-14 20:40:05 -08:00
|
|
|
#ifndef ERROR_MODEL_H
|
|
|
|
|
#define ERROR_MODEL_H
|
|
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
#include "ns3/object.h"
|
2008-02-15 20:03:48 +01:00
|
|
|
#include "ns3/random-variable.h"
|
2007-11-14 20:40:05 -08:00
|
|
|
|
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
|
|
|
|
class Packet;
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-10 17:56:47 -07:00
|
|
|
* \ingroup network
|
2008-05-29 23:24:10 -07:00
|
|
|
* \defgroup errormodel Error Model
|
2008-06-04 11:48:52 -07:00
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* \ingroup errormodel
|
2007-11-14 20:40:05 -08:00
|
|
|
* \brief General error model that can be used to corrupt packets
|
|
|
|
|
*
|
|
|
|
|
* This object is used to flag packets as being lost/errored or not.
|
|
|
|
|
* It is part of the Object framework and can be aggregated to
|
|
|
|
|
* other ns3 objects and handled by the Ptr class.
|
|
|
|
|
*
|
2007-12-14 16:05:37 -08:00
|
|
|
* The main method is IsCorrupt(Ptr<Packet> p) which returns true if
|
2007-11-14 20:40:05 -08:00
|
|
|
* the packet is to be corrupted according to the underlying model.
|
|
|
|
|
* Depending on the error model, the packet itself may have its packet
|
|
|
|
|
* data buffer errored or not, or side information may be returned to
|
2010-01-25 09:22:19 +01:00
|
|
|
* the client in the form of a packet tag. (Note: No such error models
|
|
|
|
|
* that actually error the bits in a packet presently exist).
|
2011-05-13 14:57:43 -04:00
|
|
|
* The object can have state (resettable by Reset()).
|
2007-11-14 20:40:05 -08:00
|
|
|
* The object can also be enabled and disabled via two public member functions.
|
|
|
|
|
*
|
|
|
|
|
* Typical code (simplified) to use an ErrorModel may look something like
|
|
|
|
|
* this:
|
|
|
|
|
* \code
|
2008-01-02 09:09:24 +01:00
|
|
|
* Ptr<ErrorModel> rem = CreateObject<RateErrorModel> ();
|
2007-11-14 20:40:05 -08:00
|
|
|
* rem->SetRandomVariable (UniformVariable ());
|
|
|
|
|
* rem->SetRate (0.001);
|
|
|
|
|
* ...
|
2007-11-22 10:30:29 +01:00
|
|
|
* Ptr<Packet> p;
|
2007-11-14 20:40:05 -08:00
|
|
|
* if (rem->IsCorrupt (p))
|
|
|
|
|
* {
|
|
|
|
|
* dropTrace(p);
|
|
|
|
|
* } else {
|
|
|
|
|
* Forward (p);
|
|
|
|
|
* }
|
|
|
|
|
* \endcode
|
|
|
|
|
*
|
2011-05-13 14:57:43 -04:00
|
|
|
* Two practical error models, a ListErrorModel and a RateErrorModel,
|
2007-11-14 20:40:05 -08:00
|
|
|
* are currently implemented.
|
|
|
|
|
*/
|
|
|
|
|
class ErrorModel : public Object
|
|
|
|
|
{
|
|
|
|
|
public:
|
2008-01-15 12:43:07 +01:00
|
|
|
static TypeId GetTypeId (void);
|
2011-05-13 14:57:43 -04:00
|
|
|
|
2007-11-14 20:40:05 -08:00
|
|
|
ErrorModel ();
|
|
|
|
|
virtual ~ErrorModel ();
|
|
|
|
|
|
2011-05-13 14:57:43 -04:00
|
|
|
/**
|
|
|
|
|
* Note: Depending on the error model, this function may or may not
|
|
|
|
|
* alter the contents of the packet upon returning true.
|
|
|
|
|
*
|
|
|
|
|
* \returns true if the Packet is to be considered as errored/corrupted
|
|
|
|
|
* \param pkt Packet to apply error model to
|
|
|
|
|
*/
|
2007-11-22 10:30:29 +01:00
|
|
|
bool IsCorrupt (Ptr<Packet> pkt);
|
2011-05-13 14:57:43 -04:00
|
|
|
/**
|
|
|
|
|
* Reset any state associated with the error model
|
|
|
|
|
*/
|
2007-11-14 20:40:05 -08:00
|
|
|
void Reset (void);
|
2011-05-13 14:57:43 -04:00
|
|
|
/**
|
|
|
|
|
* Enable the error model
|
|
|
|
|
*/
|
2007-11-14 20:40:05 -08:00
|
|
|
void Enable (void);
|
2011-05-13 14:57:43 -04:00
|
|
|
/**
|
|
|
|
|
* Disable the error model
|
|
|
|
|
*/
|
2007-11-14 20:40:05 -08:00
|
|
|
void Disable (void);
|
|
|
|
|
/**
|
|
|
|
|
* \return true if error model is enabled; false otherwise
|
|
|
|
|
*/
|
|
|
|
|
bool IsEnabled (void) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/*
|
|
|
|
|
* These methods must be implemented by subclasses
|
|
|
|
|
*/
|
2007-11-22 10:30:29 +01:00
|
|
|
virtual bool DoCorrupt (Ptr<Packet>) = 0;
|
2007-11-14 20:40:05 -08:00
|
|
|
virtual void DoReset (void) = 0;
|
|
|
|
|
|
2008-07-02 13:21:43 -07:00
|
|
|
bool m_enable;
|
2007-11-14 20:40:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Determine which packets are errored corresponding to an underlying
|
|
|
|
|
* distribution, rate, and unit.
|
|
|
|
|
*
|
|
|
|
|
* This object is used to flag packets as being lost/errored or not.
|
|
|
|
|
* The two parameters that govern the behavior are the rate (or
|
|
|
|
|
* equivalently, the mean duration/spacing between errors), and the
|
|
|
|
|
* unit (which may be per-bit, per-byte, and per-packet).
|
|
|
|
|
* Users can optionally provide a RandomVariable object; the default
|
|
|
|
|
* is to use a Uniform(0,1) distribution.
|
|
|
|
|
|
|
|
|
|
* Reset() on this model will do nothing
|
|
|
|
|
*
|
|
|
|
|
* IsCorrupt() will not modify the packet data buffer
|
|
|
|
|
*/
|
|
|
|
|
class RateErrorModel : public ErrorModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
2008-01-15 12:43:07 +01:00
|
|
|
static TypeId GetTypeId (void);
|
2007-11-14 20:40:05 -08:00
|
|
|
|
|
|
|
|
RateErrorModel ();
|
|
|
|
|
virtual ~RateErrorModel ();
|
|
|
|
|
|
2012-05-01 20:48:34 +02:00
|
|
|
enum ErrorUnit
|
|
|
|
|
{
|
|
|
|
|
ERROR_UNIT_BIT,
|
|
|
|
|
ERROR_UNIT_BYTE,
|
|
|
|
|
ERROR_UNIT_PACKET
|
|
|
|
|
};
|
|
|
|
|
|
2007-11-14 20:40:05 -08:00
|
|
|
/**
|
|
|
|
|
* \returns the ErrorUnit being used by the underlying model
|
|
|
|
|
*/
|
2012-05-01 20:48:34 +02:00
|
|
|
RateErrorModel::ErrorUnit GetUnit (void) const;
|
2007-11-14 20:40:05 -08:00
|
|
|
/**
|
|
|
|
|
* \param error_unit the ErrorUnit to be used by the underlying model
|
|
|
|
|
*/
|
|
|
|
|
void SetUnit (enum ErrorUnit error_unit);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \returns the error rate being applied by the model
|
|
|
|
|
*/
|
|
|
|
|
double GetRate (void) const;
|
|
|
|
|
/**
|
|
|
|
|
* \param rate the error rate to be used by the model
|
|
|
|
|
*/
|
|
|
|
|
void SetRate (double rate);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \param ranvar A random variable distribution to generate random variates
|
|
|
|
|
*/
|
|
|
|
|
void SetRandomVariable (const RandomVariable &ranvar);
|
|
|
|
|
|
|
|
|
|
private:
|
2007-11-22 10:30:29 +01:00
|
|
|
virtual bool DoCorrupt (Ptr<Packet> p);
|
|
|
|
|
virtual bool DoCorruptPkt (Ptr<Packet> p);
|
|
|
|
|
virtual bool DoCorruptByte (Ptr<Packet> p);
|
|
|
|
|
virtual bool DoCorruptBit (Ptr<Packet> p);
|
2007-11-14 20:40:05 -08:00
|
|
|
virtual void DoReset (void);
|
|
|
|
|
|
|
|
|
|
enum ErrorUnit m_unit;
|
|
|
|
|
double m_rate;
|
|
|
|
|
|
2008-02-15 20:03:48 +01:00
|
|
|
RandomVariable m_ranvar;
|
2007-11-14 20:40:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Provide a list of Packet uids to corrupt
|
|
|
|
|
*
|
|
|
|
|
* This object is used to flag packets as being lost/errored or not.
|
|
|
|
|
* A note on performance: the list is assumed to be unordered, and
|
|
|
|
|
* in general, Packet uids received may be unordered. Therefore,
|
|
|
|
|
* each call to IsCorrupt() will result in a walk of the list with
|
|
|
|
|
* the present underlying implementation.
|
|
|
|
|
*
|
|
|
|
|
* Note also that if one wants to target multiple packets from looking
|
|
|
|
|
* at an (unerrored) trace file, the act of erroring a given packet may
|
|
|
|
|
* cause subsequent packet uids to change. For instance, suppose one wants
|
|
|
|
|
* to error packets 11 and 17 on a given device. It may be that erroring
|
|
|
|
|
* packet 11 will cause the subsequent uid stream to change and 17 may no
|
|
|
|
|
* longer correspond to the second packet that one wants to lose. Therefore,
|
|
|
|
|
* be advised that it might take some trial and error to select the
|
|
|
|
|
* right uids when multiple are provided.
|
|
|
|
|
*
|
|
|
|
|
* Reset() on this model will clear the list
|
|
|
|
|
*
|
|
|
|
|
* IsCorrupt() will not modify the packet data buffer
|
|
|
|
|
*/
|
|
|
|
|
class ListErrorModel : public ErrorModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
2008-01-15 12:43:07 +01:00
|
|
|
static TypeId GetTypeId (void);
|
2007-11-14 20:40:05 -08:00
|
|
|
ListErrorModel ();
|
|
|
|
|
virtual ~ListErrorModel ();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \return a copy of the underlying list
|
|
|
|
|
*/
|
|
|
|
|
std::list<uint32_t> GetList (void) const;
|
|
|
|
|
/**
|
|
|
|
|
* \param packetlist The list of packet uids to error.
|
|
|
|
|
*
|
|
|
|
|
* This method overwrites any previously provided list.
|
|
|
|
|
*/
|
|
|
|
|
void SetList (const std::list<uint32_t> &packetlist);
|
|
|
|
|
|
|
|
|
|
private:
|
2007-11-22 10:30:29 +01:00
|
|
|
virtual bool DoCorrupt (Ptr<Packet> p);
|
2007-11-14 20:40:05 -08:00
|
|
|
virtual void DoReset (void);
|
|
|
|
|
|
|
|
|
|
typedef std::list<uint32_t> PacketList;
|
|
|
|
|
typedef std::list<uint32_t>::const_iterator PacketListCI;
|
|
|
|
|
|
|
|
|
|
PacketList m_packetList;
|
2011-05-13 14:57:43 -04:00
|
|
|
|
2007-11-14 20:40:05 -08:00
|
|
|
};
|
|
|
|
|
|
2010-05-05 16:04:31 -04:00
|
|
|
/**
|
|
|
|
|
* \brief Provide a list of Packets to corrupt
|
|
|
|
|
*
|
|
|
|
|
* This model also processes a user-generated list of packets to
|
|
|
|
|
* corrupt, except that the list corresponds to the sequence of
|
|
|
|
|
* received packets as observed by this error model, and not the
|
|
|
|
|
* Packet UID.
|
|
|
|
|
*
|
|
|
|
|
* Reset() on this model will clear the list
|
|
|
|
|
*
|
|
|
|
|
* IsCorrupt() will not modify the packet data buffer
|
|
|
|
|
*/
|
|
|
|
|
class ReceiveListErrorModel : public ErrorModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static TypeId GetTypeId (void);
|
|
|
|
|
ReceiveListErrorModel ();
|
|
|
|
|
virtual ~ReceiveListErrorModel ();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \return a copy of the underlying list
|
|
|
|
|
*/
|
|
|
|
|
std::list<uint32_t> GetList (void) const;
|
|
|
|
|
/**
|
|
|
|
|
* \param packetlist The list of packets to error.
|
|
|
|
|
*
|
|
|
|
|
* This method overwrites any previously provided list.
|
|
|
|
|
*/
|
|
|
|
|
void SetList (const std::list<uint32_t> &packetlist);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual bool DoCorrupt (Ptr<Packet> p);
|
|
|
|
|
virtual void DoReset (void);
|
|
|
|
|
|
|
|
|
|
typedef std::list<uint32_t> PacketList;
|
|
|
|
|
typedef std::list<uint32_t>::const_iterator PacketListCI;
|
|
|
|
|
|
|
|
|
|
PacketList m_packetList;
|
|
|
|
|
uint32_t m_timesInvoked;
|
2011-05-13 14:57:43 -04:00
|
|
|
|
2010-05-05 16:04:31 -04:00
|
|
|
};
|
|
|
|
|
|
2007-11-14 20:40:05 -08:00
|
|
|
|
2011-08-02 17:43:32 -04:00
|
|
|
} // namespace ns3
|
2007-11-14 20:40:05 -08:00
|
|
|
#endif
|