From cdf032d7a9c1275b7c8b2e4fc4dcfb2f87255a48 Mon Sep 17 00:00:00 2001 From: Josh Pelkey Date: Wed, 5 May 2010 16:04:31 -0400 Subject: [PATCH] move receive-list-error-model to src/common/error-model --- src/common/error-model.cc | 68 +++++++++++++ src/common/error-model.h | 42 ++++++++ src/test/ns3tcp/ns3tcp-loss-test-suite.cc | 2 - src/test/ns3tcp/receive-list-error-model.cc | 105 -------------------- src/test/ns3tcp/receive-list-error-model.h | 78 --------------- src/test/ns3tcp/wscript | 1 - src/test/nsctcp/nsctcp-loss-test-suite.cc | 1 - 7 files changed, 110 insertions(+), 187 deletions(-) delete mode 100644 src/test/ns3tcp/receive-list-error-model.cc delete mode 100644 src/test/ns3tcp/receive-list-error-model.h diff --git a/src/common/error-model.cc b/src/common/error-model.cc index 02bfac62d..df5c83e29 100644 --- a/src/common/error-model.cc +++ b/src/common/error-model.cc @@ -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 () + .AddConstructor () + ; + return tid; +} + + +ReceiveListErrorModel::ReceiveListErrorModel () : + m_timesInvoked (0) +{ + NS_LOG_FUNCTION_NOARGS (); +} + +ReceiveListErrorModel::~ReceiveListErrorModel () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +std::list +ReceiveListErrorModel::GetList (void) const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_packetList; +} + +void +ReceiveListErrorModel::SetList (const std::list &packetlist) +{ + NS_LOG_FUNCTION_NOARGS (); + m_packetList = packetlist; +} + +bool +ReceiveListErrorModel::DoCorrupt (Ptr 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 diff --git a/src/common/error-model.h b/src/common/error-model.h index 6f8df9e03..eeab72406 100644 --- a/src/common/error-model.h +++ b/src/common/error-model.h @@ -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 GetList (void) const; + /** + * \param packetlist The list of packets to error. + * + * This method overwrites any previously provided list. + */ + void SetList (const std::list &packetlist); + +private: + virtual bool DoCorrupt (Ptr p); + virtual void DoReset (void); + + typedef std::list PacketList; + typedef std::list::const_iterator PacketListCI; + + PacketList m_packetList; + uint32_t m_timesInvoked; + +}; + } //namespace ns3 #endif diff --git a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc index 19f603140..b07e12f64 100644 --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc @@ -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" diff --git a/src/test/ns3tcp/receive-list-error-model.cc b/src/test/ns3tcp/receive-list-error-model.cc deleted file mode 100644 index 6a50ef3fc..000000000 --- a/src/test/ns3tcp/receive-list-error-model.cc +++ /dev/null @@ -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 () - .AddConstructor () - ; - return tid; -} -*/ - -ReceiveListErrorModel::ReceiveListErrorModel () : - m_timesInvoked (0) -{ - //NS_LOG_FUNCTION_NOARGS (); -} - -ReceiveListErrorModel::~ReceiveListErrorModel () -{ - //NS_LOG_FUNCTION_NOARGS (); -} - -std::list -ReceiveListErrorModel::GetList (void) const -{ - //NS_LOG_FUNCTION_NOARGS (); - return m_packetList; -} - -void -ReceiveListErrorModel::SetList (const std::list &packetlist) -{ - //NS_LOG_FUNCTION_NOARGS (); - m_packetList = packetlist; -} - -bool -ReceiveListErrorModel::DoCorrupt (Ptr 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 diff --git a/src/test/ns3tcp/receive-list-error-model.h b/src/test/ns3tcp/receive-list-error-model.h deleted file mode 100644 index 0d0cd9ca8..000000000 --- a/src/test/ns3tcp/receive-list-error-model.h +++ /dev/null @@ -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 -#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 GetList (void) const; - /** - * \param packetlist The list of packets to error. - * - * This method overwrites any previously provided list. - */ - void SetList (const std::list &packetlist); - -private: - virtual bool DoCorrupt (Ptr p); - virtual void DoReset (void); - - typedef std::list PacketList; - typedef std::list::const_iterator PacketListCI; - - PacketList m_packetList; - uint32_t m_timesInvoked; - -}; - - -} //namespace ns3 -#endif diff --git a/src/test/ns3tcp/wscript b/src/test/ns3tcp/wscript index ca94f15c3..a96d09e15 100644 --- a/src/test/ns3tcp/wscript +++ b/src/test/ns3tcp/wscript @@ -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') diff --git a/src/test/nsctcp/nsctcp-loss-test-suite.cc b/src/test/nsctcp/nsctcp-loss-test-suite.cc index 8f3c0434d..c7aba31f4 100644 --- a/src/test/nsctcp/nsctcp-loss-test-suite.cc +++ b/src/test/nsctcp/nsctcp-loss-test-suite.cc @@ -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;