Creating a pure virtual class CcnxConsumer. CcnxConsumerCbr now
implements constant-rate interest generation.
diff --git a/apps/ccnx-consumer-cbr.cc b/apps/ccnx-consumer-cbr.cc
new file mode 100644
index 0000000..a41753f
--- /dev/null
+++ b/apps/ccnx-consumer-cbr.cc
@@ -0,0 +1,130 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ccnx-consumer-cbr.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/packet.h"
+#include "ns3/callback.h"
+#include "ns3/string.h"
+#include "ns3/boolean.h"
+#include "ns3/uinteger.h"
+#include "ns3/double.h"
+
+#include "ns3/ccnx.h"
+#include "../model/ccnx-local-face.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+#include <boost/ref.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxConsumerCbr");
+
+namespace ns3
+{
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerCbr);
+
+TypeId
+CcnxConsumerCbr::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::CcnxConsumerCbr")
+ .SetParent<CcnxConsumer> ()
+ .AddConstructor<CcnxConsumerCbr> ()
+
+ .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)",
+ StringValue ("100Kbps"),
+ MakeDataRateAccessor (&CcnxConsumerCbr::GetDesiredRate, &CcnxConsumerCbr::SetDesiredRate),
+ MakeDataRateChecker ())
+ ;
+
+ return tid;
+}
+
+CcnxConsumerCbr::CcnxConsumerCbr ()
+ : m_desiredRate ("100Kbps")
+{
+ NS_LOG_FUNCTION_NOARGS ();
+
+ UpdateMean ();
+}
+
+
+void
+CcnxConsumerCbr::UpdateMean ()
+{
+ double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
+ m_randExp = ExponentialVariable (mean, 10000 * mean); // set upper limit to inter-arrival time
+}
+
+void
+CcnxConsumerCbr::SetPayloadSize (uint32_t payload)
+{
+ CcnxConsumer::SetPayloadSize (payload);
+ UpdateMean ();
+}
+
+void
+CcnxConsumerCbr::SetDesiredRate (DataRate rate)
+{
+ m_desiredRate = rate;
+ UpdateMean ();
+}
+
+DataRate
+CcnxConsumerCbr::GetDesiredRate () const
+{
+ return m_desiredRate;
+}
+
+
+void
+CcnxConsumerCbr::ScheduleNextPacket ()
+{
+ if (!m_sendEvent.IsRunning ())
+ m_sendEvent = Simulator::Schedule (
+ Seconds(m_randExp.GetValue ()),
+ &CcnxConsumer::SendPacket, this);
+}
+
+///////////////////////////////////////////////////
+// Process incoming packets //
+///////////////////////////////////////////////////
+
+// void
+// CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+// const Ptr<const Packet> &payload)
+// {
+// CcnxConsumer::OnContentObject (contentObject, payload); // tracing inside
+// }
+
+// void
+// CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest)
+// {
+// CcnxConsumer::OnNack (interest); // tracing inside
+// }
+
+} // namespace ns3
diff --git a/apps/ccnx-consumer-cbr.h b/apps/ccnx-consumer-cbr.h
new file mode 100644
index 0000000..59a06d7
--- /dev/null
+++ b/apps/ccnx-consumer-cbr.h
@@ -0,0 +1,83 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef CCNX_CONSUMER_CBR_H
+#define CCNX_CONSUMER_CBR_H
+
+#include "ccnx-consumer.h"
+
+namespace ns3
+{
+
+/**
+ * @ingroup ccnx
+ * \brief CCNx application for sending out Interest packets at a "constant" rate (Poisson process)
+ */
+class CcnxConsumerCbr: public CcnxConsumer
+{
+public:
+ static TypeId GetTypeId ();
+
+ /**
+ * \brief Default constructor
+ * Sets up randomizer function and packet sequence number
+ */
+ CcnxConsumerCbr ();
+
+ // From CcnxApp
+ // virtual void
+ // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
+
+ // virtual void
+ // OnNack (const Ptr<const CcnxInterestHeader> &interest);
+
+ // virtual void
+ // OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+ // const Ptr<const Packet> &payload);
+
+protected:
+ /**
+ * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
+ */
+ virtual void
+ ScheduleNextPacket ();
+
+private:
+ void
+ UpdateMean ();
+
+ virtual void
+ SetPayloadSize (uint32_t payload);
+
+ void
+ SetDesiredRate (DataRate rate);
+
+ DataRate
+ GetDesiredRate () const;
+
+protected:
+ ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process)
+ DataRate m_desiredRate; // Desired data packet rate
+};
+
+} // namespace ns3
+
+#endif
diff --git a/apps/ccnx-consumer.cc b/apps/ccnx-consumer.cc
index ae56040..fcc1ccf 100644
--- a/apps/ccnx-consumer.cc
+++ b/apps/ccnx-consumer.cc
@@ -53,27 +53,19 @@
{
static TypeId tid = TypeId ("ns3::CcnxConsumer")
.SetParent<CcnxApp> ()
- .AddConstructor<CcnxConsumer> ()
.AddAttribute ("StartSeq", "Initial sequence number",
IntegerValue (0),
MakeIntegerAccessor(&CcnxConsumer::m_seq),
MakeIntegerChecker<int32_t>())
- .AddAttribute ("Size", "Amount of data in megabytes to request (relies on PayloadSize parameter)",
- DoubleValue (-1), // don't impose limit by default
- MakeDoubleAccessor (&CcnxConsumer::GetMaxSize, &CcnxConsumer::SetMaxSize),
- MakeDoubleChecker<double> ())
-
- ///////
.AddAttribute ("PayloadSize", "Average size of content object size (to calculate interest generation rate)",
UintegerValue (1040),
MakeUintegerAccessor (&CcnxConsumer::GetPayloadSize, &CcnxConsumer::SetPayloadSize),
MakeUintegerChecker<uint32_t>())
- .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)",
- StringValue ("100Kbps"),
- MakeDataRateAccessor (&CcnxConsumer::GetDesiredRate, &CcnxConsumer::SetDesiredRate),
- MakeDataRateChecker ())
- ///////
+ .AddAttribute ("Size", "Amount of data in megabytes to request (relies on PayloadSize parameter)",
+ DoubleValue (-1), // don't impose limit by default
+ MakeDoubleAccessor (&CcnxConsumer::GetMaxSize, &CcnxConsumer::SetMaxSize),
+ MakeDoubleChecker<double> ())
.AddAttribute ("Prefix","CcnxName of the Interest",
StringValue ("/"),
@@ -120,13 +112,10 @@
CcnxConsumer::CcnxConsumer ()
: m_rand (0, std::numeric_limits<uint32_t>::max ())
- , m_desiredRate ("10Kbps")
, m_payloadSize (1040)
, m_seq (0)
{
NS_LOG_FUNCTION_NOARGS ();
-
- UpdateMean (); // not necessary (will be called by ns3 object system anyways), but doesn't hurt
}
void
@@ -177,20 +166,6 @@
&CcnxConsumer::CheckRetxTimeout, this);
}
-void
-CcnxConsumer::UpdateMean ()
-{
- double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
- m_randExp = ExponentialVariable (mean, 10000 * mean); // set upper limit to inter-arrival time
-}
-
-void
-CcnxConsumer::SetPayloadSize (uint32_t payload)
-{
- m_payloadSize = payload;
- UpdateMean ();
-}
-
uint32_t
CcnxConsumer::GetPayloadSize () const
{
@@ -198,16 +173,9 @@
}
void
-CcnxConsumer::SetDesiredRate (DataRate rate)
+CcnxConsumer::SetPayloadSize (uint32_t payload)
{
- m_desiredRate = rate;
- UpdateMean ();
-}
-
-DataRate
-CcnxConsumer::GetDesiredRate () const
-{
- return m_desiredRate;
+ m_payloadSize = payload;
}
double
@@ -232,16 +200,6 @@
NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
}
-
-void
-CcnxConsumer::ScheduleNextPacket ()
-{
- if (!m_sendEvent.IsRunning ())
- m_sendEvent = Simulator::Schedule (
- Seconds(m_randExp.GetValue ()),
- &CcnxConsumer::SendPacket, this);
-}
-
// Application Methods
void
CcnxConsumer::StartApplication () // Called at time specified by Start
diff --git a/apps/ccnx-consumer.h b/apps/ccnx-consumer.h
index 9b28a2c..31b4eb9 100644
--- a/apps/ccnx-consumer.h
+++ b/apps/ccnx-consumer.h
@@ -66,6 +66,11 @@
OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
const Ptr<const Packet> &payload);
+
+ // Simulator::Schedule doesn't work with protected members???
+ void
+ SendPacket ();
+
protected:
// from CcnxApp
virtual void
@@ -74,31 +79,12 @@
virtual void
StopApplication ();
-private:
/**
* \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
*/
- void
- ScheduleNextPacket ();
-
- void
- UpdateMean ();
-
- void
- SetPayloadSize (uint32_t payload);
-
- uint32_t
- GetPayloadSize () const;
-
- void
- SetDesiredRate (DataRate rate);
-
- DataRate
- GetDesiredRate () const;
+ virtual void
+ ScheduleNextPacket () = 0;
- void
- SendPacket ();
-
/**
* \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
*/
@@ -119,6 +105,12 @@
Time
GetRetxTimer () const;
+ virtual void
+ SetPayloadSize (uint32_t payload);
+
+ uint32_t
+ GetPayloadSize () const;
+
double
GetMaxSize () const;
@@ -127,11 +119,8 @@
protected:
UniformVariable m_rand; // nonce generator
-
- ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process)
- DataRate m_desiredRate; // Desired data packet rate
uint32_t m_payloadSize; // expected payload size
-
+
uint32_t m_seq;
uint32_t m_seqMax; // maximum number of sequence number
EventId m_sendEvent; // Eventid of pending "send packet" event
diff --git a/examples/congestion-pop.cc b/examples/congestion-pop.cc
index 51a5fa0..18cb26c 100644
--- a/examples/congestion-pop.cc
+++ b/examples/congestion-pop.cc
@@ -144,7 +144,7 @@
Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
- CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
+ CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000