diff --git a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc index 27fe0b084..7009f8ded 100644 --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc @@ -16,6 +16,8 @@ * 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" @@ -129,7 +131,7 @@ Ns3TcpLossTestCase1::DoRun (void) sampleList.push_back (0); sampleList.push_back (1); // This time, we'll explicitly create the error model we want - Ptr pem = CreateObject (); + Ptr pem = CreateObject (); pem->SetList (sampleList); devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); @@ -235,9 +237,9 @@ Ns3TcpLossTestCase2::DoRun (void) std::list sampleList; // Lose first data segment - sampleList.push_back (15); + sampleList.push_back (2); // This time, we'll explicitly create the error model we want - Ptr pem = CreateObject (); + Ptr pem = CreateObject (); pem->SetList (sampleList); devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); @@ -273,7 +275,7 @@ Ns3TcpLossTestSuite::Ns3TcpLossTestSuite () : TestSuite ("ns3-tcp-loss", SYSTEM) { AddTestCase (new Ns3TcpLossTestCase1); - //AddTestCase (new Ns3TcpLossTestCase2); + AddTestCase (new Ns3TcpLossTestCase2); } Ns3TcpLossTestSuite ns3TcpLossTestSuite; diff --git a/src/test/ns3tcp/receive-list-error-model.cc b/src/test/ns3tcp/receive-list-error-model.cc new file mode 100644 index 000000000..3fea3970e --- /dev/null +++ b/src/test/ns3tcp/receive-list-error-model.cc @@ -0,0 +1,105 @@ +/* -*- 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 + * relavent 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 new file mode 100644 index 000000000..52ddab480 --- /dev/null +++ b/src/test/ns3tcp/receive-list-error-model.h @@ -0,0 +1,78 @@ +/* -*- 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 + * relavent 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 a96d09e15..ca94f15c3 100644 --- a/src/test/ns3tcp/wscript +++ b/src/test/ns3tcp/wscript @@ -13,6 +13,7 @@ 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')