move receive-list-error-model to src/common/error-model

This commit is contained in:
Josh Pelkey
2010-05-05 16:04:31 -04:00
parent 679d30c60d
commit cdf032d7a9
7 changed files with 110 additions and 187 deletions

View File

@@ -298,5 +298,73 @@ ListErrorModel::DoReset (void)
m_packetList.clear();
}
//
// ReceiveListErrorModel
//
NS_OBJECT_ENSURE_REGISTERED (ReceiveListErrorModel);
TypeId ReceiveListErrorModel::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::ReceiveListErrorModel")
.SetParent<ErrorModel> ()
.AddConstructor<ReceiveListErrorModel> ()
;
return tid;
}
ReceiveListErrorModel::ReceiveListErrorModel () :
m_timesInvoked (0)
{
NS_LOG_FUNCTION_NOARGS ();
}
ReceiveListErrorModel::~ReceiveListErrorModel ()
{
NS_LOG_FUNCTION_NOARGS ();
}
std::list<uint32_t>
ReceiveListErrorModel::GetList (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_packetList;
}
void
ReceiveListErrorModel::SetList (const std::list<uint32_t> &packetlist)
{
NS_LOG_FUNCTION_NOARGS ();
m_packetList = packetlist;
}
bool
ReceiveListErrorModel::DoCorrupt (Ptr<Packet> p)
{
NS_LOG_FUNCTION_NOARGS ();
if (!IsEnabled ())
{
return false;
}
m_timesInvoked += 1;
for (PacketListCI i = m_packetList.begin ();
i != m_packetList.end (); i++)
{
if (m_timesInvoked - 1 == *i)
{
return true;
}
}
return false;
}
void
ReceiveListErrorModel::DoReset (void)
{
NS_LOG_FUNCTION_NOARGS ();
m_packetList.clear();
}
} //namespace ns3

View File

@@ -229,6 +229,48 @@ private:
};
/**
* \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;
};
} //namespace ns3
#endif

View File

@@ -16,8 +16,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "receive-list-error-model.h"
#include "ns3/log.h"
#include "ns3/abort.h"
#include "ns3/test.h"

View File

@@ -1,105 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* 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
*
* This code should be moved to src/common/error-model.h during ns-3.9
* release cycle with some minor modifications, such as adding GetTypeId
* method and logging to all methods. This can be done by uncommenting
* relevant code below.
*/
#include "ns3/packet.h"
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/random-variable.h"
#include "ns3/boolean.h"
#include "ns3/enum.h"
#include "ns3/double.h"
#include "receive-list-error-model.h"
namespace ns3 {
//
// ReceiveListErrorModel
//
//NS_OBJECT_ENSURE_REGISTERED (ReceiveListErrorModel);
/*
TypeId ReceiveListErrorModel::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::ReceiveListErrorModel")
.SetParent<ErrorModel> ()
.AddConstructor<ReceiveListErrorModel> ()
;
return tid;
}
*/
ReceiveListErrorModel::ReceiveListErrorModel () :
m_timesInvoked (0)
{
//NS_LOG_FUNCTION_NOARGS ();
}
ReceiveListErrorModel::~ReceiveListErrorModel ()
{
//NS_LOG_FUNCTION_NOARGS ();
}
std::list<uint32_t>
ReceiveListErrorModel::GetList (void) const
{
//NS_LOG_FUNCTION_NOARGS ();
return m_packetList;
}
void
ReceiveListErrorModel::SetList (const std::list<uint32_t> &packetlist)
{
//NS_LOG_FUNCTION_NOARGS ();
m_packetList = packetlist;
}
bool
ReceiveListErrorModel::DoCorrupt (Ptr<Packet> p)
{
//NS_LOG_FUNCTION_NOARGS ();
if (!IsEnabled ())
{
return false;
}
m_timesInvoked += 1;
for (PacketListCI i = m_packetList.begin ();
i != m_packetList.end (); i++)
{
if (m_timesInvoked - 1 == *i)
{
return true;
}
}
return false;
}
void
ReceiveListErrorModel::DoReset (void)
{
//NS_LOG_FUNCTION_NOARGS ();
m_packetList.clear();
}
} //namespace ns3

View File

@@ -1,78 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* 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
*
* This code should be moved to src/common/error-model.h during ns-3.9
* release cycle with some minor modifications, such as adding GetTypeId
* method and logging to all methods. This can be done by uncommenting
* relevant code below.
*/
#ifndef RECEIVE_LIST_ERROR_MODEL_H
#define RECEIVE_LIST_ERROR_MODEL_H
#include <list>
#include "ns3/error-model.h"
#include "ns3/object.h"
#include "ns3/random-variable.h"
namespace ns3 {
class Packet;
/**
* \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:
/* uncomment GetTypeId when moving to src/common/error-model.h */
//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;
};
} //namespace ns3
#endif

View File

@@ -13,7 +13,6 @@ def build(bld):
ns3tcp.source = [
'ns3tcp-socket-writer.cc',
'ns3tcp-loss-test-suite.cc',
'receive-list-error-model.cc',
]
if bld.env['NSC_ENABLED']:
ns3tcp.source.append ('ns3tcp-interop-test-suite.cc')

View File

@@ -37,7 +37,6 @@
#include "ns3/error-model.h"
#include "ns3/pointer.h"
#include "../ns3tcp/ns3tcp-socket-writer.h"
#include "../ns3tcp/receive-list-error-model.h"
using namespace ns3;