--- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Sun Apr 11 23:15:09 2010 -0700
+++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Mon Apr 12 20:50:04 2010 -0400
@@ -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 @@
sampleList.push_back (0);
sampleList.push_back (1);
// This time, we'll explicitly create the error model we want
- Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> ();
+ Ptr<ReceiveListErrorModel> pem = CreateObject<ReceiveListErrorModel> ();
pem->SetList (sampleList);
devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem));
@@ -235,9 +237,9 @@
std::list<uint32_t> 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<ListErrorModel> pem = CreateObject<ListErrorModel> ();
+ Ptr<ReceiveListErrorModel> pem = CreateObject<ReceiveListErrorModel> ();
pem->SetList (sampleList);
devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem));
@@ -273,7 +275,7 @@
: TestSuite ("ns3-tcp-loss", SYSTEM)
{
AddTestCase (new Ns3TcpLossTestCase1);
- //AddTestCase (new Ns3TcpLossTestCase2);
+ AddTestCase (new Ns3TcpLossTestCase2);
}
Ns3TcpLossTestSuite ns3TcpLossTestSuite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/ns3tcp/receive-list-error-model.cc Mon Apr 12 20:50:04 2010 -0400
@@ -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<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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/ns3tcp/receive-list-error-model.h Mon Apr 12 20:50:04 2010 -0400
@@ -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 <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
--- a/src/test/ns3tcp/wscript Sun Apr 11 23:15:09 2010 -0700
+++ b/src/test/ns3tcp/wscript Mon Apr 12 20:50:04 2010 -0400
@@ -13,6 +13,7 @@
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')