src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/apps/ndn-app.cpp b/apps/ndn-app.cpp
index 1c62745..f353e62 100644
--- a/apps/ndn-app.cpp
+++ b/apps/ndn-app.cpp
@@ -30,137 +30,135 @@
#include "ns3/ndn-app-face.hpp"
#include "ns3/ndn-forwarding-strategy.hpp"
-NS_LOG_COMPONENT_DEFINE ("ndn.App");
+NS_LOG_COMPONENT_DEFINE("ndn.App");
namespace ns3 {
namespace ndn {
-
-NS_OBJECT_ENSURE_REGISTERED (App);
-
+
+NS_OBJECT_ENSURE_REGISTERED(App);
+
TypeId
-App::GetTypeId (void)
+App::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::App")
- .SetGroupName ("Ndn")
- .SetParent<Application> ()
- .AddConstructor<App> ()
+ static TypeId tid = TypeId("ns3::ndn::App")
+ .SetGroupName("Ndn")
+ .SetParent<Application>()
+ .AddConstructor<App>()
- .AddTraceSource ("ReceivedInterests", "ReceivedInterests",
- MakeTraceSourceAccessor (&App::m_receivedInterests))
-
- .AddTraceSource ("ReceivedNacks", "ReceivedNacks",
- MakeTraceSourceAccessor (&App::m_receivedNacks))
-
- .AddTraceSource ("ReceivedDatas", "ReceivedDatas",
- MakeTraceSourceAccessor (&App::m_receivedDatas))
+ .AddTraceSource("ReceivedInterests", "ReceivedInterests",
+ MakeTraceSourceAccessor(&App::m_receivedInterests))
- .AddTraceSource ("TransmittedInterests", "TransmittedInterests",
- MakeTraceSourceAccessor (&App::m_transmittedInterests))
+ .AddTraceSource("ReceivedNacks", "ReceivedNacks",
+ MakeTraceSourceAccessor(&App::m_receivedNacks))
- .AddTraceSource ("TransmittedDatas", "TransmittedDatas",
- MakeTraceSourceAccessor (&App::m_transmittedDatas))
- ;
+ .AddTraceSource("ReceivedDatas", "ReceivedDatas",
+ MakeTraceSourceAccessor(&App::m_receivedDatas))
+
+ .AddTraceSource("TransmittedInterests", "TransmittedInterests",
+ MakeTraceSourceAccessor(&App::m_transmittedInterests))
+
+ .AddTraceSource("TransmittedDatas", "TransmittedDatas",
+ MakeTraceSourceAccessor(&App::m_transmittedDatas));
return tid;
}
-
-App::App ()
- : m_active (false)
- , m_face (0)
+
+App::App()
+ : m_active(false)
+ , m_face(0)
{
}
-
-App::~App ()
+
+App::~App()
{
}
void
-App::DoDispose (void)
+App::DoDispose(void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
// Unfortunately, this causes SEGFAULT
// The best reason I see is that apps are freed after ndn stack is removed
- // StopApplication ();
- Application::DoDispose ();
+ // StopApplication ();
+ Application::DoDispose();
}
uint32_t
-App::GetId () const
+App::GetId() const
{
if (m_face == 0)
return (uint32_t)-1;
else
- return m_face->GetId ();
+ return m_face->GetId();
}
void
-App::OnInterest (Ptr<const Interest> interest)
+App::OnInterest(Ptr<const Interest> interest)
{
- NS_LOG_FUNCTION (this << interest);
- m_receivedInterests (interest, this, m_face);
+ NS_LOG_FUNCTION(this << interest);
+ m_receivedInterests(interest, this, m_face);
}
void
-App::OnNack (Ptr<const Interest> interest)
+App::OnNack(Ptr<const Interest> interest)
{
- NS_LOG_FUNCTION (this << interest);
- m_receivedNacks (interest, this, m_face);
+ NS_LOG_FUNCTION(this << interest);
+ m_receivedNacks(interest, this, m_face);
}
void
-App::OnData (Ptr<const Data> contentObject)
+App::OnData(Ptr<const Data> contentObject)
{
- NS_LOG_FUNCTION (this << contentObject);
- m_receivedDatas (contentObject, this, m_face);
+ NS_LOG_FUNCTION(this << contentObject);
+ m_receivedDatas(contentObject, this, m_face);
}
// Application Methods
-void
-App::StartApplication () // Called at time specified by Start
+void
+App::StartApplication() // Called at time specified by Start
{
- NS_LOG_FUNCTION_NOARGS ();
-
- NS_ASSERT (m_active != true);
+ NS_LOG_FUNCTION_NOARGS();
+
+ NS_ASSERT(m_active != true);
m_active = true;
- NS_ASSERT_MSG (GetNode ()->GetObject<L3Protocol> () != 0,
- "Ndn stack should be installed on the node " << GetNode ());
+ NS_ASSERT_MSG(GetNode()->GetObject<L3Protocol>() != 0,
+ "Ndn stack should be installed on the node " << GetNode());
// step 1. Create a face
- m_face = CreateObject<AppFace> (/*Ptr<App> (this)*/this);
-
+ m_face = CreateObject<AppFace>(/*Ptr<App> (this)*/ this);
+
// step 2. Add face to the Ndn stack
- GetNode ()->GetObject<L3Protocol> ()->AddFace (m_face);
+ GetNode()->GetObject<L3Protocol>()->AddFace(m_face);
// step 3. Enable face
- m_face->SetUp (true);
+ m_face->SetUp(true);
}
-
-void
-App::StopApplication () // Called at time specified by Stop
-{
- NS_LOG_FUNCTION_NOARGS ();
- if (!m_active) return; //don't assert here, just return
-
- NS_ASSERT (GetNode ()->GetObject<L3Protocol> () != 0);
+void
+App::StopApplication() // Called at time specified by Stop
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ if (!m_active)
+ return; // don't assert here, just return
+
+ NS_ASSERT(GetNode()->GetObject<L3Protocol>() != 0);
m_active = false;
// step 1. Disable face
- m_face->SetUp (false);
+ m_face->SetUp(false);
// step 2. Remove face from Ndn stack
- GetNode ()->GetObject<L3Protocol> ()->RemoveFace (m_face);
+ GetNode()->GetObject<L3Protocol>()->RemoveFace(m_face);
// step 3. Destroy face
- if (m_face->GetReferenceCount () != 1)
- {
- NS_LOG_ERROR ("Please a bug report on https://github.com/NDN-Routing/ndnSIM/issues");
- NS_LOG_ERROR ("At this point, nobody else should have referenced this face, but we have "
- << m_face->GetReferenceCount () << " references");
-
- }
+ if (m_face->GetReferenceCount() != 1) {
+ NS_LOG_ERROR("Please a bug report on https://github.com/NDN-Routing/ndnSIM/issues");
+ NS_LOG_ERROR("At this point, nobody else should have referenced this face, but we have "
+ << m_face->GetReferenceCount() << " references");
+ }
// NS_ASSERT_MSG (m_face->GetReferenceCount ()==2,
// "At this point, nobody else should have referenced this face, but we have "
// << m_face->GetReferenceCount () << " references");
diff --git a/apps/ndn-app.hpp b/apps/ndn-app.hpp
index 2157a7f..edede34 100644
--- a/apps/ndn-app.hpp
+++ b/apps/ndn-app.hpp
@@ -44,83 +44,86 @@
/**
* @ingroup ndn-apps
* @brief Base class that all NDN applications should be derived from.
- *
+ *
* The class implements virtual calls onInterest, onNack, and onData
*/
-class App: public Application
-{
+class App : public Application {
public:
- static TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* @brief Default constructor
*/
- App ();
- virtual ~App ();
+ App();
+ virtual ~App();
/**
* @brief Get application ID (ID of applications face)
*/
uint32_t
- GetId () const;
-
+ GetId() const;
+
/**
* @brief Method that will be called every time new Interest arrives
* @param interest Interest header
- * @param packet "Payload" of the interests packet. The actual payload should be zero, but packet itself
+ * @param packet "Payload" of the interests packet. The actual payload should be zero, but
+ * packet itself
* may be useful to get packet tags
*/
virtual void
- OnInterest (Ptr<const Interest> interest);
+ OnInterest(Ptr<const Interest> interest);
/**
* @brief Method that will be called every time new NACK arrives
* @param interest Interest header
*/
virtual void
- OnNack (Ptr<const Interest> interest);
-
+ OnNack(Ptr<const Interest> interest);
+
/**
* @brief Method that will be called every time new Data arrives
* @param contentObject Data header
- * @param payload payload (potentially virtual) of the Data packet (may include packet tags of original packet)
+ * @param payload payload (potentially virtual) of the Data packet (may include packet tags of
+ * original packet)
*/
virtual void
- OnData (Ptr<const Data> contentObject);
-
+ OnData(Ptr<const Data> contentObject);
+
protected:
/**
* @brief Do cleanup when application is destroyed
*/
virtual void
- DoDispose ();
+ DoDispose();
// inherited from Application base class. Originally they were private
virtual void
- StartApplication (); ///< @brief Called at time specified by Start
+ StartApplication(); ///< @brief Called at time specified by Start
virtual void
- StopApplication (); ///< @brief Called at time specified by Stop
+ StopApplication(); ///< @brief Called at time specified by Stop
protected:
- bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
- Ptr<Face> m_face; ///< @brief automatically created application face through which application communicates
+ bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication
+ /// and StopApplication)
+ Ptr<Face> m_face; ///< @brief automatically created application face through which application
+ /// communicates
- TracedCallback<Ptr<const Interest>,
- Ptr<App>, Ptr<Face> > m_receivedInterests; ///< @brief App-level trace of received Interests
+ TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
+ m_receivedInterests; ///< @brief App-level trace of received Interests
- TracedCallback<Ptr<const Interest>,
- Ptr<App>, Ptr<Face> > m_receivedNacks; ///< @brief App-level trace of received NACKs
+ TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
+ m_receivedNacks; ///< @brief App-level trace of received NACKs
- TracedCallback<Ptr<const Data>,
- Ptr<App>, Ptr<Face> > m_receivedDatas; ///< @brief App-level trace of received Data
+ TracedCallback<Ptr<const Data>, Ptr<App>, Ptr<Face>>
+ m_receivedDatas; ///< @brief App-level trace of received Data
+ TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
+ m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
- TracedCallback<Ptr<const Interest>,
- Ptr<App>, Ptr<Face> > m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
-
- TracedCallback<Ptr<const Data>,
- Ptr<App>, Ptr<Face> > m_transmittedDatas; ///< @brief App-level trace of transmitted Data
+ TracedCallback<Ptr<const Data>, Ptr<App>, Ptr<Face>>
+ m_transmittedDatas; ///< @brief App-level trace of transmitted Data
};
} // namespace ndn
diff --git a/apps/ndn-consumer-batches.cpp b/apps/ndn-consumer-batches.cpp
index db158c5..b7406ae 100644
--- a/apps/ndn-consumer-batches.cpp
+++ b/apps/ndn-consumer-batches.cpp
@@ -30,69 +30,70 @@
#include "../utils/batches.hpp"
-NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerBatches");
+NS_LOG_COMPONENT_DEFINE("ndn.ConsumerBatches");
namespace ns3 {
namespace ndn {
-
-NS_OBJECT_ENSURE_REGISTERED (ConsumerBatches);
-
-TypeId
-ConsumerBatches::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::ndn::ConsumerBatches")
- .SetGroupName ("Ndn")
- .SetParent<Consumer> ()
- .AddConstructor<ConsumerBatches> ()
- .AddAttribute ("Batches", "Batches to schedule. Should be vector, containing pairs of time and amount",
- // TypeId::ATTR_SET,
- StringValue (""),
- MakeBatchesAccessor (&ConsumerBatches::m_batches),
- MakeBatchesChecker ())
- ;
+NS_OBJECT_ENSURE_REGISTERED(ConsumerBatches);
+
+TypeId
+ConsumerBatches::GetTypeId(void)
+{
+ static TypeId tid =
+ TypeId("ns3::ndn::ConsumerBatches")
+ .SetGroupName("Ndn")
+ .SetParent<Consumer>()
+ .AddConstructor<ConsumerBatches>()
+
+ .AddAttribute("Batches",
+ "Batches to schedule. Should be vector, containing pairs of time and amount",
+ // TypeId::ATTR_SET,
+ StringValue(""), MakeBatchesAccessor(&ConsumerBatches::m_batches),
+ MakeBatchesChecker());
return tid;
}
-ConsumerBatches::ConsumerBatches ()
- : m_initial (true)
+ConsumerBatches::ConsumerBatches()
+ : m_initial(true)
{
}
void
-ConsumerBatches::StartApplication ()
+ConsumerBatches::StartApplication()
{
- Consumer::StartApplication ();
-
+ Consumer::StartApplication();
+
// std::cout << "Batches: " << batches << "\n";
- for (Batches::const_iterator i = m_batches.begin (); i != m_batches.end (); i++)
- {
- Simulator::ScheduleWithContext (GetNode ()->GetId (), i->get<0> (), &ConsumerBatches::AddBatch, this, i->get<1> ());
- }
+ for (Batches::const_iterator i = m_batches.begin(); i != m_batches.end(); i++) {
+ Simulator::ScheduleWithContext(GetNode()->GetId(), i->get<0>(), &ConsumerBatches::AddBatch,
+ this, i->get<1>());
+ }
}
void
-ConsumerBatches::AddBatch (uint32_t amount)
+ConsumerBatches::AddBatch(uint32_t amount)
{
// std::cout << Simulator::Now () << " adding batch of " << amount << "\n";
m_seqMax += amount;
- m_rtt->ClearSent (); // this is important, otherwise RTT estimation for the new batch will be affected by previous batch history
+ m_rtt->ClearSent(); // this is important, otherwise RTT estimation for the new batch will be
+ // affected by previous batch history
m_initial = true;
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-ConsumerBatches::ScheduleNextPacket ()
+ConsumerBatches::ScheduleNextPacket()
{
- if (!m_sendEvent.IsRunning ())
- {
- Time delay = Seconds (0);
- if (!m_initial) delay = m_rtt->RetransmitTimeout ();
-
- m_initial = false;
- m_sendEvent = Simulator::Schedule (delay, &Consumer::SendPacket, this);
- }
+ if (!m_sendEvent.IsRunning()) {
+ Time delay = Seconds(0);
+ if (!m_initial)
+ delay = m_rtt->RetransmitTimeout();
+
+ m_initial = false;
+ m_sendEvent = Simulator::Schedule(delay, &Consumer::SendPacket, this);
+ }
}
///////////////////////////////////////////////////
diff --git a/apps/ndn-consumer-batches.hpp b/apps/ndn-consumer-batches.hpp
index 979108e..0c7c25d 100644
--- a/apps/ndn-consumer-batches.hpp
+++ b/apps/ndn-consumer-batches.hpp
@@ -32,15 +32,15 @@
* @ingroup ndn-apps
* \brief Ndn application for sending out Interest packets in batches
*/
-class ConsumerBatches: public Consumer
-{
-public:
- static TypeId GetTypeId ();
-
+class ConsumerBatches : public Consumer {
+public:
+ static TypeId
+ GetTypeId();
+
/**
- * \brief Default constructor
+ * \brief Default constructor
*/
- ConsumerBatches ();
+ ConsumerBatches();
// From App
// virtual void
@@ -58,16 +58,18 @@
private:
virtual void
- StartApplication (); ///< @brief Called at time specified by Start
-
+ StartApplication(); ///< @brief Called at time specified by Start
+
void
- AddBatch (uint32_t amount);
+ AddBatch(uint32_t amount);
+
protected:
/**
- * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
+ * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
+ * protocol
*/
virtual void
- ScheduleNextPacket ();
+ ScheduleNextPacket();
private:
bool m_initial;
diff --git a/apps/ndn-consumer-cbr.cpp b/apps/ndn-consumer-cbr.cpp
index 90e46d5..c9c81b9 100644
--- a/apps/ndn-consumer-cbr.cpp
+++ b/apps/ndn-consumer-cbr.cpp
@@ -34,105 +34,95 @@
#include "ns3/ndn-interest.hpp"
#include "ns3/ndn-data.hpp"
-NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerCbr");
+NS_LOG_COMPONENT_DEFINE("ndn.ConsumerCbr");
namespace ns3 {
namespace ndn {
-
-NS_OBJECT_ENSURE_REGISTERED (ConsumerCbr);
-
+
+NS_OBJECT_ENSURE_REGISTERED(ConsumerCbr);
+
TypeId
-ConsumerCbr::GetTypeId (void)
+ConsumerCbr::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::ConsumerCbr")
- .SetGroupName ("Ndn")
- .SetParent<Consumer> ()
- .AddConstructor<ConsumerCbr> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::ConsumerCbr")
+ .SetGroupName("Ndn")
+ .SetParent<Consumer>()
+ .AddConstructor<ConsumerCbr>()
- .AddAttribute ("Frequency", "Frequency of interest packets",
- StringValue ("1.0"),
- MakeDoubleAccessor (&ConsumerCbr::m_frequency),
- MakeDoubleChecker<double> ())
-
- .AddAttribute ("Randomize", "Type of send time randomization: none (default), uniform, exponential",
- StringValue ("none"),
- MakeStringAccessor (&ConsumerCbr::SetRandomize, &ConsumerCbr::GetRandomize),
- MakeStringChecker ())
+ .AddAttribute("Frequency", "Frequency of interest packets", StringValue("1.0"),
+ MakeDoubleAccessor(&ConsumerCbr::m_frequency), MakeDoubleChecker<double>())
- .AddAttribute ("MaxSeq",
- "Maximum sequence number to request",
- IntegerValue (std::numeric_limits<uint32_t>::max ()),
- MakeIntegerAccessor (&ConsumerCbr::m_seqMax),
- MakeIntegerChecker<uint32_t> ())
+ .AddAttribute("Randomize",
+ "Type of send time randomization: none (default), uniform, exponential",
+ StringValue("none"),
+ MakeStringAccessor(&ConsumerCbr::SetRandomize, &ConsumerCbr::GetRandomize),
+ MakeStringChecker())
+
+ .AddAttribute("MaxSeq", "Maximum sequence number to request",
+ IntegerValue(std::numeric_limits<uint32_t>::max()),
+ MakeIntegerAccessor(&ConsumerCbr::m_seqMax), MakeIntegerChecker<uint32_t>())
;
return tid;
}
-
-ConsumerCbr::ConsumerCbr ()
- : m_frequency (1.0)
- , m_firstTime (true)
- , m_random (0)
+
+ConsumerCbr::ConsumerCbr()
+ : m_frequency(1.0)
+ , m_firstTime(true)
+ , m_random(0)
{
- NS_LOG_FUNCTION_NOARGS ();
- m_seqMax = std::numeric_limits<uint32_t>::max ();
+ NS_LOG_FUNCTION_NOARGS();
+ m_seqMax = std::numeric_limits<uint32_t>::max();
}
-ConsumerCbr::~ConsumerCbr ()
+ConsumerCbr::~ConsumerCbr()
{
if (m_random)
delete m_random;
}
void
-ConsumerCbr::ScheduleNextPacket ()
+ConsumerCbr::ScheduleNextPacket()
{
// double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
// std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
- if (m_firstTime)
- {
- m_sendEvent = Simulator::Schedule (Seconds (0.0),
- &Consumer::SendPacket, this);
- m_firstTime = false;
- }
- else if (!m_sendEvent.IsRunning ())
- m_sendEvent = Simulator::Schedule (
- (m_random == 0) ?
- Seconds(1.0 / m_frequency)
- :
- Seconds(m_random->GetValue ()),
- &Consumer::SendPacket, this);
+ if (m_firstTime) {
+ m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::SendPacket, this);
+ m_firstTime = false;
+ }
+ else if (!m_sendEvent.IsRunning())
+ m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
+ : Seconds(m_random->GetValue()),
+ &Consumer::SendPacket, this);
}
void
-ConsumerCbr::SetRandomize (const std::string &value)
+ConsumerCbr::SetRandomize(const std::string& value)
{
if (m_random)
delete m_random;
- if (value == "uniform")
- {
- m_random = new UniformVariable (0.0, 2 * 1.0 / m_frequency);
- }
- else if (value == "exponential")
- {
- m_random = new ExponentialVariable (1.0 / m_frequency, 50 * 1.0 / m_frequency);
- }
+ if (value == "uniform") {
+ m_random = new UniformVariable(0.0, 2 * 1.0 / m_frequency);
+ }
+ else if (value == "exponential") {
+ m_random = new ExponentialVariable(1.0 / m_frequency, 50 * 1.0 / m_frequency);
+ }
else
m_random = 0;
- m_randomType = value;
+ m_randomType = value;
}
std::string
-ConsumerCbr::GetRandomize () const
+ConsumerCbr::GetRandomize() const
{
return m_randomType;
}
-
///////////////////////////////////////////////////
// Process incoming packets //
///////////////////////////////////////////////////
diff --git a/apps/ndn-consumer-cbr.hpp b/apps/ndn-consumer-cbr.hpp
index ebe015f..47134b6 100644
--- a/apps/ndn-consumer-cbr.hpp
+++ b/apps/ndn-consumer-cbr.hpp
@@ -31,17 +31,17 @@
* @ingroup ndn-apps
* @brief Ndn application for sending out Interest packets at a "constant" rate (Poisson process)
*/
-class ConsumerCbr: public Consumer
-{
-public:
- static TypeId GetTypeId ();
-
+class ConsumerCbr : public Consumer {
+public:
+ static TypeId
+ GetTypeId();
+
/**
- * \brief Default constructor
+ * \brief Default constructor
* Sets up randomizer function and packet sequence number
*/
- ConsumerCbr ();
- virtual ~ConsumerCbr ();
+ ConsumerCbr();
+ virtual ~ConsumerCbr();
// From NdnApp
// virtual void
@@ -56,25 +56,26 @@
protected:
/**
- * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
+ * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
+ * protocol
*/
virtual void
- ScheduleNextPacket ();
+ ScheduleNextPacket();
/**
* @brief Set type of frequency randomization
* @param value Either 'none', 'uniform', or 'exponential'
*/
void
- SetRandomize (const std::string &value);
+ SetRandomize(const std::string& value);
/**
* @brief Get type of frequency randomization
* @returns either 'none', 'uniform', or 'exponential'
*/
std::string
- GetRandomize () const;
-
+ GetRandomize() const;
+
private:
// void
// UpdateMean ();
@@ -87,12 +88,12 @@
// DataRate
// GetDesiredRate () const;
-
+
protected:
- double m_frequency; // Frequency of interest packets (in hertz)
- bool m_firstTime;
- RandomVariable *m_random;
- std::string m_randomType;
+ double m_frequency; // Frequency of interest packets (in hertz)
+ bool m_firstTime;
+ RandomVariable* m_random;
+ std::string m_randomType;
};
} // namespace ndn
diff --git a/apps/ndn-consumer-window.cpp b/apps/ndn-consumer-window.cpp
index a4a6ad5..595842c 100644
--- a/apps/ndn-consumer-window.cpp
+++ b/apps/ndn-consumer-window.cpp
@@ -30,93 +30,92 @@
#include "ns3/ndn-data.hpp"
#include "ns3/ndn-interest.hpp"
-NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerWindow");
+NS_LOG_COMPONENT_DEFINE("ndn.ConsumerWindow");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (ConsumerWindow);
+NS_OBJECT_ENSURE_REGISTERED(ConsumerWindow);
TypeId
-ConsumerWindow::GetTypeId (void)
+ConsumerWindow::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::ConsumerWindow")
- .SetGroupName ("Ndn")
- .SetParent<Consumer> ()
- .AddConstructor<ConsumerWindow> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::ConsumerWindow")
+ .SetGroupName("Ndn")
+ .SetParent<Consumer>()
+ .AddConstructor<ConsumerWindow>()
- .AddAttribute ("Window", "Initial size of the window",
- StringValue ("1"),
- MakeUintegerAccessor (&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
- MakeUintegerChecker<uint32_t> ())
+ .AddAttribute("Window", "Initial size of the window", StringValue("1"),
+ MakeUintegerAccessor(&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("PayloadSize", "Average size of content object size (to calculate interest generation rate)",
- UintegerValue (1040),
- MakeUintegerAccessor (&ConsumerWindow::GetPayloadSize, &ConsumerWindow::SetPayloadSize),
- MakeUintegerChecker<uint32_t>())
+ .AddAttribute("PayloadSize",
+ "Average size of content object size (to calculate interest generation rate)",
+ UintegerValue(1040), MakeUintegerAccessor(&ConsumerWindow::GetPayloadSize,
+ &ConsumerWindow::SetPayloadSize),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("Size",
- "Amount of data in megabytes to request, relying on PayloadSize parameter (alternative to MaxSeq attribute)",
- DoubleValue (-1), // don't impose limit by default
- MakeDoubleAccessor (&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
- MakeDoubleChecker<double> ())
+ .AddAttribute("Size", "Amount of data in megabytes to request, relying on PayloadSize "
+ "parameter (alternative to MaxSeq attribute)",
+ DoubleValue(-1), // don't impose limit by default
+ MakeDoubleAccessor(&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
+ MakeDoubleChecker<double>())
- .AddAttribute ("MaxSeq",
- "Maximum sequence number to request (alternative to Size attribute, would activate only if Size is -1). "
- "The parameter is activated only if Size negative (not set)",
- IntegerValue (std::numeric_limits<uint32_t>::max ()),
- MakeUintegerAccessor (&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
- MakeUintegerChecker<uint32_t> ())
+ .AddAttribute("MaxSeq", "Maximum sequence number to request (alternative to Size attribute, "
+ "would activate only if Size is -1). "
+ "The parameter is activated only if Size negative (not set)",
+ IntegerValue(std::numeric_limits<uint32_t>::max()),
+ MakeUintegerAccessor(&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("InitialWindowOnTimeout", "Set window to initial value when timeout occurs",
- BooleanValue (true),
- MakeBooleanAccessor (&ConsumerWindow::m_setInitialWindowOnTimeout),
- MakeBooleanChecker ())
+ .AddAttribute("InitialWindowOnTimeout", "Set window to initial value when timeout occurs",
+ BooleanValue(true),
+ MakeBooleanAccessor(&ConsumerWindow::m_setInitialWindowOnTimeout),
+ MakeBooleanChecker())
- .AddTraceSource ("WindowTrace",
- "Window that controls how many outstanding interests are allowed",
- MakeTraceSourceAccessor (&ConsumerWindow::m_window))
- .AddTraceSource ("InFlight",
- "Current number of outstanding interests",
- MakeTraceSourceAccessor (&ConsumerWindow::m_inFlight))
- ;
+ .AddTraceSource("WindowTrace",
+ "Window that controls how many outstanding interests are allowed",
+ MakeTraceSourceAccessor(&ConsumerWindow::m_window))
+ .AddTraceSource("InFlight", "Current number of outstanding interests",
+ MakeTraceSourceAccessor(&ConsumerWindow::m_inFlight));
return tid;
}
-ConsumerWindow::ConsumerWindow ()
- : m_payloadSize (1040)
- , m_inFlight (0)
+ConsumerWindow::ConsumerWindow()
+ : m_payloadSize(1040)
+ , m_inFlight(0)
{
}
void
-ConsumerWindow::SetWindow (uint32_t window)
+ConsumerWindow::SetWindow(uint32_t window)
{
m_initialWindow = window;
m_window = m_initialWindow;
}
uint32_t
-ConsumerWindow::GetWindow () const
+ConsumerWindow::GetWindow() const
{
return m_initialWindow;
}
uint32_t
-ConsumerWindow::GetPayloadSize () const
+ConsumerWindow::GetPayloadSize() const
{
return m_payloadSize;
}
void
-ConsumerWindow::SetPayloadSize (uint32_t payload)
+ConsumerWindow::SetPayloadSize(uint32_t payload)
{
m_payloadSize = payload;
}
double
-ConsumerWindow::GetMaxSize () const
+ConsumerWindow::GetMaxSize() const
{
if (m_seqMax == 0)
return -1.0;
@@ -125,28 +124,27 @@
}
void
-ConsumerWindow::SetMaxSize (double size)
+ConsumerWindow::SetMaxSize(double size)
{
m_maxSize = size;
- if (m_maxSize < 0)
- {
- m_seqMax = 0;
- return;
- }
+ if (m_maxSize < 0) {
+ m_seqMax = 0;
+ return;
+ }
m_seqMax = floor(1.0 + m_maxSize * 1024.0 * 1024.0 / m_payloadSize);
- NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
+ NS_LOG_DEBUG("MaxSeqNo: " << m_seqMax);
// std::cout << "MaxSeqNo: " << m_seqMax << "\n";
}
uint32_t
-ConsumerWindow::GetSeqMax () const
+ConsumerWindow::GetSeqMax() const
{
return m_seqMax;
}
void
-ConsumerWindow::SetSeqMax (uint32_t seqMax)
+ConsumerWindow::SetSeqMax(uint32_t seqMax)
{
if (m_maxSize < 0)
m_seqMax = seqMax;
@@ -154,31 +152,30 @@
// ignore otherwise
}
-
void
-ConsumerWindow::ScheduleNextPacket ()
+ConsumerWindow::ScheduleNextPacket()
{
- if (m_window == static_cast<uint32_t> (0))
- {
- Simulator::Remove (m_sendEvent);
+ if (m_window == static_cast<uint32_t>(0)) {
+ Simulator::Remove(m_sendEvent);
- NS_LOG_DEBUG ("Next event in " << (std::min<double> (0.5, m_rtt->RetransmitTimeout ().ToDouble (Time::S))) << " sec");
- m_sendEvent = Simulator::Schedule (Seconds (std::min<double> (0.5, m_rtt->RetransmitTimeout ().ToDouble (Time::S))),
- &Consumer::SendPacket, this);
+ NS_LOG_DEBUG(
+ "Next event in " << (std::min<double>(0.5, m_rtt->RetransmitTimeout().ToDouble(Time::S)))
+ << " sec");
+ m_sendEvent =
+ Simulator::Schedule(Seconds(
+ std::min<double>(0.5, m_rtt->RetransmitTimeout().ToDouble(Time::S))),
+ &Consumer::SendPacket, this);
+ }
+ else if (m_inFlight >= m_window) {
+ // simply do nothing
+ }
+ else {
+ if (m_sendEvent.IsRunning()) {
+ Simulator::Remove(m_sendEvent);
}
- else if (m_inFlight >= m_window)
- {
- // simply do nothing
- }
- else
- {
- if (m_sendEvent.IsRunning ())
- {
- Simulator::Remove (m_sendEvent);
- }
- m_sendEvent = Simulator::ScheduleNow (&Consumer::SendPacket, this);
- }
+ m_sendEvent = Simulator::ScheduleNow(&Consumer::SendPacket, this);
+ }
}
///////////////////////////////////////////////////
@@ -186,58 +183,58 @@
///////////////////////////////////////////////////
void
-ConsumerWindow::OnData (Ptr<const Data> contentObject)
+ConsumerWindow::OnData(Ptr<const Data> contentObject)
{
- Consumer::OnData (contentObject);
+ Consumer::OnData(contentObject);
m_window = m_window + 1;
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-ConsumerWindow::OnNack (Ptr<const Interest> interest)
+ConsumerWindow::OnNack(Ptr<const Interest> interest)
{
- Consumer::OnNack (interest);
+ Consumer::OnNack(interest);
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
- if (m_window > static_cast<uint32_t> (0))
- {
- // m_window = 0.5 * m_window;//m_window - 1;
- m_window = std::max<uint32_t> (0, m_window - 1);
- }
+ if (m_window > static_cast<uint32_t>(0)) {
+ // m_window = 0.5 * m_window;//m_window - 1;
+ m_window = std::max<uint32_t>(0, m_window - 1);
+ }
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-ConsumerWindow::OnTimeout (uint32_t sequenceNumber)
+ConsumerWindow::OnTimeout(uint32_t sequenceNumber)
{
- if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
+ if (m_inFlight > static_cast<uint32_t>(0))
+ m_inFlight--;
- if (m_setInitialWindowOnTimeout)
- {
- // m_window = std::max<uint32_t> (0, m_window - 1);
- m_window = m_initialWindow;
- }
+ if (m_setInitialWindowOnTimeout) {
+ // m_window = std::max<uint32_t> (0, m_window - 1);
+ m_window = m_initialWindow;
+ }
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
- Consumer::OnTimeout (sequenceNumber);
+ NS_LOG_DEBUG("Window: " << m_window << ", InFlight: " << m_inFlight);
+ Consumer::OnTimeout(sequenceNumber);
}
void
-ConsumerWindow::WillSendOutInterest (uint32_t sequenceNumber)
+ConsumerWindow::WillSendOutInterest(uint32_t sequenceNumber)
{
- m_inFlight ++;
- Consumer::WillSendOutInterest (sequenceNumber);
+ m_inFlight++;
+ Consumer::WillSendOutInterest(sequenceNumber);
}
-
} // namespace ndn
} // namespace ns3
diff --git a/apps/ndn-consumer-window.hpp b/apps/ndn-consumer-window.hpp
index 886621e..923cae0 100644
--- a/apps/ndn-consumer-window.hpp
+++ b/apps/ndn-consumer-window.hpp
@@ -32,70 +32,72 @@
* @ingroup ndn-apps
* \brief Ndn application for sending out Interest packets (window-based)
*
- * !!! ATTENTION !!! This is highly experimental and relies on experimental features of the simulator.
+ * !!! ATTENTION !!! This is highly experimental and relies on experimental features of the
+ *simulator.
* Behavior may be unpredictable if used incorrectly.
*/
-class ConsumerWindow: public Consumer
-{
+class ConsumerWindow : public Consumer {
public:
- static TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* \brief Default constructor
*/
- ConsumerWindow ();
+ ConsumerWindow();
// From App
// virtual void
// OnInterest (const Ptr<const Interest> &interest);
virtual void
- OnNack (Ptr<const Interest> interest);
+ OnNack(Ptr<const Interest> interest);
virtual void
- OnData (Ptr<const Data> contentObject);
+ OnData(Ptr<const Data> contentObject);
virtual void
- OnTimeout (uint32_t sequenceNumber);
+ OnTimeout(uint32_t sequenceNumber);
virtual void
- WillSendOutInterest (uint32_t sequenceNumber);
+ WillSendOutInterest(uint32_t sequenceNumber);
protected:
/**
- * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
+ * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
+ * protocol
*/
virtual void
- ScheduleNextPacket ();
+ ScheduleNextPacket();
private:
virtual void
- SetWindow (uint32_t window);
+ SetWindow(uint32_t window);
uint32_t
- GetWindow () const;
+ GetWindow() const;
virtual void
- SetPayloadSize (uint32_t payload);
+ SetPayloadSize(uint32_t payload);
uint32_t
- GetPayloadSize () const;
+ GetPayloadSize() const;
double
- GetMaxSize () const;
+ GetMaxSize() const;
void
- SetMaxSize (double size);
+ SetMaxSize(double size);
uint32_t
- GetSeqMax () const;
+ GetSeqMax() const;
void
- SetSeqMax (uint32_t seqMax);
+ SetSeqMax(uint32_t seqMax);
private:
uint32_t m_payloadSize; // expected payload size
- double m_maxSize; // max size to request
+ double m_maxSize; // max size to request
uint32_t m_initialWindow;
bool m_setInitialWindowOnTimeout;
diff --git a/apps/ndn-consumer-zipf-mandelbrot.cpp b/apps/ndn-consumer-zipf-mandelbrot.cpp
index a88befb..806b8e3 100644
--- a/apps/ndn-consumer-zipf-mandelbrot.cpp
+++ b/apps/ndn-consumer-zipf-mandelbrot.cpp
@@ -28,47 +28,45 @@
#include <math.h>
-
-NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerZipfMandelbrot");
+NS_LOG_COMPONENT_DEFINE("ndn.ConsumerZipfMandelbrot");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (ConsumerZipfMandelbrot);
+NS_OBJECT_ENSURE_REGISTERED(ConsumerZipfMandelbrot);
TypeId
-ConsumerZipfMandelbrot::GetTypeId (void)
+ConsumerZipfMandelbrot::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::ConsumerZipfMandelbrot")
- .SetGroupName ("Ndn")
- .SetParent<ConsumerCbr> ()
- .AddConstructor<ConsumerZipfMandelbrot> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::ConsumerZipfMandelbrot")
+ .SetGroupName("Ndn")
+ .SetParent<ConsumerCbr>()
+ .AddConstructor<ConsumerZipfMandelbrot>()
- .AddAttribute ("NumberOfContents", "Number of the Contents in total",
- StringValue ("100"),
- MakeUintegerAccessor (&ConsumerZipfMandelbrot::SetNumberOfContents, &ConsumerZipfMandelbrot::GetNumberOfContents),
- MakeUintegerChecker<uint32_t> ())
+ .AddAttribute("NumberOfContents", "Number of the Contents in total", StringValue("100"),
+ MakeUintegerAccessor(&ConsumerZipfMandelbrot::SetNumberOfContents,
+ &ConsumerZipfMandelbrot::GetNumberOfContents),
+ MakeUintegerChecker<uint32_t>())
- .AddAttribute ("q", "parameter of improve rank",
- StringValue ("0.7"),
- MakeDoubleAccessor (&ConsumerZipfMandelbrot::SetQ, &ConsumerZipfMandelbrot::GetQ),
- MakeDoubleChecker<double> ())
-
- .AddAttribute ("s", "parameter of power",
- StringValue ("0.7"),
- MakeDoubleAccessor (&ConsumerZipfMandelbrot::SetS, &ConsumerZipfMandelbrot::GetS),
- MakeDoubleChecker<double> ())
- ;
+ .AddAttribute("q", "parameter of improve rank", StringValue("0.7"),
+ MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetQ,
+ &ConsumerZipfMandelbrot::GetQ),
+ MakeDoubleChecker<double>())
+
+ .AddAttribute("s", "parameter of power", StringValue("0.7"),
+ MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetS,
+ &ConsumerZipfMandelbrot::GetS),
+ MakeDoubleChecker<double>());
return tid;
}
-
ConsumerZipfMandelbrot::ConsumerZipfMandelbrot()
- : m_N (100) // needed here to make sure when SetQ/SetS are called, there is a valid value of N
- , m_q (0.7)
- , m_s (0.7)
- , m_SeqRng (0.0, 1.0)
+ : m_N(100) // needed here to make sure when SetQ/SetS are called, there is a valid value of N
+ , m_q(0.7)
+ , m_s(0.7)
+ , m_SeqRng(0.0, 1.0)
{
// SetNumberOfContents is called by NS-3 object system during the initialization
}
@@ -78,135 +76,133 @@
}
void
-ConsumerZipfMandelbrot::SetNumberOfContents (uint32_t numOfContents)
+ConsumerZipfMandelbrot::SetNumberOfContents(uint32_t numOfContents)
{
m_N = numOfContents;
- NS_LOG_DEBUG (m_q << " and " << m_s << " and " << m_N);
+ NS_LOG_DEBUG(m_q << " and " << m_s << " and " << m_N);
- m_Pcum = std::vector<double> (m_N + 1);
+ m_Pcum = std::vector<double>(m_N + 1);
m_Pcum[0] = 0.0;
- for (uint32_t i=1; i<=m_N; i++)
- {
- m_Pcum[i] = m_Pcum[i-1] + 1.0 / std::pow(i+m_q, m_s);
- }
+ for (uint32_t i = 1; i <= m_N; i++) {
+ m_Pcum[i] = m_Pcum[i - 1] + 1.0 / std::pow(i + m_q, m_s);
+ }
- for (uint32_t i=1; i<=m_N; i++)
- {
- m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
- NS_LOG_LOGIC ("Cumulative probability [" << i << "]=" << m_Pcum[i]);
+ for (uint32_t i = 1; i <= m_N; i++) {
+ m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
+ NS_LOG_LOGIC("Cumulative probability [" << i << "]=" << m_Pcum[i]);
}
}
uint32_t
-ConsumerZipfMandelbrot::GetNumberOfContents () const
+ConsumerZipfMandelbrot::GetNumberOfContents() const
{
return m_N;
}
void
-ConsumerZipfMandelbrot::SetQ (double q)
+ConsumerZipfMandelbrot::SetQ(double q)
{
m_q = q;
- SetNumberOfContents (m_N);
+ SetNumberOfContents(m_N);
}
double
-ConsumerZipfMandelbrot::GetQ () const
+ConsumerZipfMandelbrot::GetQ() const
{
return m_q;
}
void
-ConsumerZipfMandelbrot::SetS (double s)
+ConsumerZipfMandelbrot::SetS(double s)
{
m_s = s;
- SetNumberOfContents (m_N);
+ SetNumberOfContents(m_N);
}
double
-ConsumerZipfMandelbrot::GetS () const
+ConsumerZipfMandelbrot::GetS() const
{
return m_s;
}
void
-ConsumerZipfMandelbrot::SendPacket() {
- if (!m_active) return;
+ConsumerZipfMandelbrot::SendPacket()
+{
+ if (!m_active)
+ return;
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
- uint32_t seq=std::numeric_limits<uint32_t>::max (); //invalid
+ uint32_t seq = std::numeric_limits<uint32_t>::max(); // invalid
// std::cout << Simulator::Now ().ToDouble (Time::S) << "s max -> " << m_seqMax << "\n";
- while (m_retxSeqs.size ())
- {
- seq = *m_retxSeqs.begin ();
- m_retxSeqs.erase (m_retxSeqs.begin ());
+ while (m_retxSeqs.size()) {
+ seq = *m_retxSeqs.begin();
+ m_retxSeqs.erase(m_retxSeqs.begin());
- // NS_ASSERT (m_seqLifetimes.find (seq) != m_seqLifetimes.end ());
- // if (m_seqLifetimes.find (seq)->time <= Simulator::Now ())
- // {
+ // NS_ASSERT (m_seqLifetimes.find (seq) != m_seqLifetimes.end ());
+ // if (m_seqLifetimes.find (seq)->time <= Simulator::Now ())
+ // {
- // NS_LOG_DEBUG ("Expire " << seq);
- // m_seqLifetimes.erase (seq); // lifetime expired. Trying to find another unexpired sequence number
- // continue;
- // }
- NS_LOG_DEBUG("=interest seq "<<seq<<" from m_retxSeqs");
- break;
+ // NS_LOG_DEBUG ("Expire " << seq);
+ // m_seqLifetimes.erase (seq); // lifetime expired. Trying to find another unexpired
+ // sequence number
+ // continue;
+ // }
+ NS_LOG_DEBUG("=interest seq " << seq << " from m_retxSeqs");
+ break;
+ }
+
+ if (seq == std::numeric_limits<uint32_t>::max()) // no retransmission
+ {
+ if (m_seqMax != std::numeric_limits<uint32_t>::max()) {
+ if (m_seq >= m_seqMax) {
+ return; // we are totally done
+ }
}
- if (seq == std::numeric_limits<uint32_t>::max ()) //no retransmission
- {
- if (m_seqMax != std::numeric_limits<uint32_t>::max ())
- {
- if (m_seq >= m_seqMax)
- {
- return; // we are totally done
- }
- }
-
- seq = ConsumerZipfMandelbrot::GetNextSeq();
- m_seq ++;
- }
+ seq = ConsumerZipfMandelbrot::GetNextSeq();
+ m_seq++;
+ }
// std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << seq << "\n";
//
- Ptr<Name> nameWithSequence = Create<Name> (m_interestName);
- nameWithSequence->appendSeqNum (seq);
+ Ptr<Name> nameWithSequence = Create<Name>(m_interestName);
+ nameWithSequence->appendSeqNum(seq);
//
- Ptr<Interest> interest = Create<Interest> ();
- interest->SetNonce (m_rand.GetValue ());
- interest->SetName (nameWithSequence);
+ Ptr<Interest> interest = Create<Interest>();
+ interest->SetNonce(m_rand.GetValue());
+ interest->SetName(nameWithSequence);
// NS_LOG_INFO ("Requesting Interest: \n" << *interest);
- NS_LOG_INFO ("> Interest for " << seq<<", Total: "<<m_seq<<", face: "<<m_face->GetId());
- NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");
+ NS_LOG_INFO("> Interest for " << seq << ", Total: " << m_seq << ", face: " << m_face->GetId());
+ NS_LOG_DEBUG("Trying to add " << seq << " with " << Simulator::Now() << ". already "
+ << m_seqTimeouts.size() << " items");
- m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
- m_seqFullDelay.insert (SeqTimeout (seq, Simulator::Now ()));
+ m_seqTimeouts.insert(SeqTimeout(seq, Simulator::Now()));
+ m_seqFullDelay.insert(SeqTimeout(seq, Simulator::Now()));
- m_seqLastDelay.erase (seq);
- m_seqLastDelay.insert (SeqTimeout (seq, Simulator::Now ()));
+ m_seqLastDelay.erase(seq);
+ m_seqLastDelay.insert(SeqTimeout(seq, Simulator::Now()));
- m_seqRetxCounts[seq] ++;
+ m_seqRetxCounts[seq]++;
- m_rtt->SentSeq (SequenceNumber32 (seq), 1);
+ m_rtt->SentSeq(SequenceNumber32(seq), 1);
FwHopCountTag hopCountTag;
- interest->GetPayload ()->AddPacketTag (hopCountTag);
+ interest->GetPayload()->AddPacketTag(hopCountTag);
- m_transmittedInterests (interest, this, m_face);
- m_face->ReceiveInterest (interest);
+ m_transmittedInterests(interest, this, m_face);
+ m_face->ReceiveInterest(interest);
- ConsumerZipfMandelbrot::ScheduleNextPacket ();
+ ConsumerZipfMandelbrot::ScheduleNextPacket();
}
-
uint32_t
ConsumerZipfMandelbrot::GetNextSeq()
{
@@ -214,42 +210,36 @@
double p_sum = 0;
double p_random = m_SeqRng.GetValue();
- while (p_random == 0)
- {
- p_random = m_SeqRng.GetValue();
- }
- //if (p_random == 0)
- NS_LOG_LOGIC("p_random="<<p_random);
- for (uint32_t i=1; i<=m_N; i++)
- {
- p_sum = m_Pcum[i]; //m_Pcum[i] = m_Pcum[i-1] + p[i], p[0] = 0; e.g.: p_cum[1] = p[1], p_cum[2] = p[1] + p[2]
- if (p_random <= p_sum)
- {
- content_index = i;
- break;
- } //if
- } //for
- //content_index = 1;
- NS_LOG_DEBUG("RandomNumber="<<content_index);
+ while (p_random == 0) {
+ p_random = m_SeqRng.GetValue();
+ }
+ // if (p_random == 0)
+ NS_LOG_LOGIC("p_random=" << p_random);
+ for (uint32_t i = 1; i <= m_N; i++) {
+ p_sum = m_Pcum[i]; // m_Pcum[i] = m_Pcum[i-1] + p[i], p[0] = 0; e.g.: p_cum[1] = p[1],
+ // p_cum[2] = p[1] + p[2]
+ if (p_random <= p_sum) {
+ content_index = i;
+ break;
+ } // if
+ } // for
+ // content_index = 1;
+ NS_LOG_DEBUG("RandomNumber=" << content_index);
return content_index;
}
void
-ConsumerZipfMandelbrot::ScheduleNextPacket() {
+ConsumerZipfMandelbrot::ScheduleNextPacket()
+{
- if (m_firstTime)
- {
- m_sendEvent = Simulator::Schedule (Seconds (0.0),
- &ConsumerZipfMandelbrot::SendPacket, this);
- m_firstTime = false;
- }
- else if (!m_sendEvent.IsRunning ())
- m_sendEvent = Simulator::Schedule (
- (m_random == 0) ?
- Seconds(1.0 / m_frequency)
- :
- Seconds(m_random->GetValue ()),
- &ConsumerZipfMandelbrot::SendPacket, this);
+ if (m_firstTime) {
+ m_sendEvent = Simulator::Schedule(Seconds(0.0), &ConsumerZipfMandelbrot::SendPacket, this);
+ m_firstTime = false;
+ }
+ else if (!m_sendEvent.IsRunning())
+ m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
+ : Seconds(m_random->GetValue()),
+ &ConsumerZipfMandelbrot::SendPacket, this);
}
} /* namespace ndn */
diff --git a/apps/ndn-consumer-zipf-mandelbrot.hpp b/apps/ndn-consumer-zipf-mandelbrot.hpp
index 302427b..ee192db 100644
--- a/apps/ndn-consumer-zipf-mandelbrot.hpp
+++ b/apps/ndn-consumer-zipf-mandelbrot.hpp
@@ -18,7 +18,6 @@
* Author: Xiaoke Jiang <shock.jiang@gmail.com>
*/
-
#ifndef NDN_CONSUMER_ZIPF_MANDELBROT_H_
#define NDN_CONSUMER_ZIPF_MANDELBROT_H_
@@ -42,54 +41,57 @@
* @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion
*
* The class implements an app which requests contents following Zipf-Mandelbrot Distribution
- * Here is the explaination of Zipf-Mandelbrot Distribution: http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law
+ * Here is the explaination of Zipf-Mandelbrot Distribution:
+ *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law
*/
-class ConsumerZipfMandelbrot: public ConsumerCbr
-{
+class ConsumerZipfMandelbrot : public ConsumerCbr {
public:
- static TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* \brief Default constructor
* Sets up randomized Number Generator (RNG)
* Note: m_seq of its parent class ConsumerCbr here is used to record the interest number
*/
- ConsumerZipfMandelbrot ();
- virtual ~ConsumerZipfMandelbrot ();
+ ConsumerZipfMandelbrot();
+ virtual ~ConsumerZipfMandelbrot();
- virtual void SendPacket();
- uint32_t GetNextSeq();
+ virtual void
+ SendPacket();
+ uint32_t
+ GetNextSeq();
protected:
virtual void
- ScheduleNextPacket ();
+ ScheduleNextPacket();
private:
void
- SetNumberOfContents (uint32_t numOfContents);
+ SetNumberOfContents(uint32_t numOfContents);
uint32_t
- GetNumberOfContents () const;
+ GetNumberOfContents() const;
void
- SetQ (double q);
+ SetQ(double q);
double
- GetQ () const;
+ GetQ() const;
void
- SetS (double s);
+ SetS(double s);
double
- GetS () const;
+ GetS() const;
private:
- uint32_t m_N; //number of the contents
- double m_q; //q in (k+q)^s
- double m_s; //s in (k+q)^s
- std::vector<double> m_Pcum; //cumulative probability
+ uint32_t m_N; // number of the contents
+ double m_q; // q in (k+q)^s
+ double m_s; // s in (k+q)^s
+ std::vector<double> m_Pcum; // cumulative probability
- UniformVariable m_SeqRng; //RNG
+ UniformVariable m_SeqRng; // RNG
};
} /* namespace ndn */
diff --git a/apps/ndn-consumer.cpp b/apps/ndn-consumer.cpp
index e94f751..fabbe95 100644
--- a/apps/ndn-consumer.cpp
+++ b/apps/ndn-consumer.cpp
@@ -40,286 +40,276 @@
#include "ns3/names.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.Consumer");
+NS_LOG_COMPONENT_DEFINE("ndn.Consumer");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (Consumer);
+NS_OBJECT_ENSURE_REGISTERED(Consumer);
TypeId
-Consumer::GetTypeId (void)
+Consumer::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::Consumer")
- .SetGroupName ("Ndn")
- .SetParent<App> ()
- .AddAttribute ("StartSeq", "Initial sequence number",
- IntegerValue (0),
- MakeIntegerAccessor(&Consumer::m_seq),
- MakeIntegerChecker<int32_t>())
+ static TypeId tid =
+ TypeId("ns3::ndn::Consumer")
+ .SetGroupName("Ndn")
+ .SetParent<App>()
+ .AddAttribute("StartSeq", "Initial sequence number", IntegerValue(0),
+ MakeIntegerAccessor(&Consumer::m_seq), MakeIntegerChecker<int32_t>())
- .AddAttribute ("Prefix","Name of the Interest",
- StringValue ("/"),
- MakeNameAccessor (&Consumer::m_interestName),
- MakeNameChecker ())
- .AddAttribute ("LifeTime", "LifeTime for interest packet",
- StringValue ("2s"),
- MakeTimeAccessor (&Consumer::m_interestLifeTime),
- MakeTimeChecker ())
+ .AddAttribute("Prefix", "Name of the Interest", StringValue("/"),
+ MakeNameAccessor(&Consumer::m_interestName), MakeNameChecker())
+ .AddAttribute("LifeTime", "LifeTime for interest packet", StringValue("2s"),
+ MakeTimeAccessor(&Consumer::m_interestLifeTime), MakeTimeChecker())
- .AddAttribute ("RetxTimer",
- "Timeout defining how frequent retransmission timeouts should be checked",
- StringValue ("50ms"),
- MakeTimeAccessor (&Consumer::GetRetxTimer, &Consumer::SetRetxTimer),
- MakeTimeChecker ())
+ .AddAttribute("RetxTimer",
+ "Timeout defining how frequent retransmission timeouts should be checked",
+ StringValue("50ms"),
+ MakeTimeAccessor(&Consumer::GetRetxTimer, &Consumer::SetRetxTimer),
+ MakeTimeChecker())
- .AddTraceSource ("LastRetransmittedInterestDataDelay", "Delay between last retransmitted Interest and received Data",
- MakeTraceSourceAccessor (&Consumer::m_lastRetransmittedInterestDataDelay))
+ .AddTraceSource("LastRetransmittedInterestDataDelay",
+ "Delay between last retransmitted Interest and received Data",
+ MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay))
- .AddTraceSource ("FirstInterestDataDelay", "Delay between first transmitted Interest and received Data",
- MakeTraceSourceAccessor (&Consumer::m_firstInterestDataDelay))
- ;
+ .AddTraceSource("FirstInterestDataDelay",
+ "Delay between first transmitted Interest and received Data",
+ MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay));
return tid;
}
-Consumer::Consumer ()
- : m_rand (0, std::numeric_limits<uint32_t>::max ())
- , m_seq (0)
- , m_seqMax (0) // don't request anything
+Consumer::Consumer()
+ : m_rand(0, std::numeric_limits<uint32_t>::max())
+ , m_seq(0)
+ , m_seqMax(0) // don't request anything
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
- m_rtt = CreateObject<RttMeanDeviation> ();
+ m_rtt = CreateObject<RttMeanDeviation>();
}
void
-Consumer::SetRetxTimer (Time retxTimer)
+Consumer::SetRetxTimer(Time retxTimer)
{
m_retxTimer = retxTimer;
- if (m_retxEvent.IsRunning ())
- {
- // m_retxEvent.Cancel (); // cancel any scheduled cleanup events
- Simulator::Remove (m_retxEvent); // slower, but better for memory
- }
+ if (m_retxEvent.IsRunning()) {
+ // m_retxEvent.Cancel (); // cancel any scheduled cleanup events
+ Simulator::Remove(m_retxEvent); // slower, but better for memory
+ }
// schedule even with new timeout
- m_retxEvent = Simulator::Schedule (m_retxTimer,
- &Consumer::CheckRetxTimeout, this);
+ m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this);
}
Time
-Consumer::GetRetxTimer () const
+Consumer::GetRetxTimer() const
{
return m_retxTimer;
}
void
-Consumer::CheckRetxTimeout ()
+Consumer::CheckRetxTimeout()
{
- Time now = Simulator::Now ();
+ Time now = Simulator::Now();
- Time rto = m_rtt->RetransmitTimeout ();
+ Time rto = m_rtt->RetransmitTimeout();
// NS_LOG_DEBUG ("Current RTO: " << rto.ToDouble (Time::S) << "s");
- while (!m_seqTimeouts.empty ())
+ while (!m_seqTimeouts.empty()) {
+ SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
+ m_seqTimeouts.get<i_timestamp>().begin();
+ if (entry->time + rto <= now) // timeout expired?
{
- SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
- m_seqTimeouts.get<i_timestamp> ().begin ();
- if (entry->time + rto <= now) // timeout expired?
- {
- uint32_t seqNo = entry->seq;
- m_seqTimeouts.get<i_timestamp> ().erase (entry);
- OnTimeout (seqNo);
- }
- else
- break; // nothing else to do. All later packets need not be retransmitted
+ uint32_t seqNo = entry->seq;
+ m_seqTimeouts.get<i_timestamp>().erase(entry);
+ OnTimeout(seqNo);
}
+ else
+ break; // nothing else to do. All later packets need not be retransmitted
+ }
- m_retxEvent = Simulator::Schedule (m_retxTimer,
- &Consumer::CheckRetxTimeout, this);
+ m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this);
}
// Application Methods
void
-Consumer::StartApplication () // Called at time specified by Start
+Consumer::StartApplication() // Called at time specified by Start
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
// do base stuff
- App::StartApplication ();
+ App::StartApplication();
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
void
-Consumer::StopApplication () // Called at time specified by Stop
+Consumer::StopApplication() // Called at time specified by Stop
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
// cancel periodic packet generation
- Simulator::Cancel (m_sendEvent);
+ Simulator::Cancel(m_sendEvent);
// cleanup base stuff
- App::StopApplication ();
+ App::StopApplication();
}
void
-Consumer::SendPacket ()
+Consumer::SendPacket()
{
- if (!m_active) return;
+ if (!m_active)
+ return;
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
- uint32_t seq=std::numeric_limits<uint32_t>::max (); //invalid
+ uint32_t seq = std::numeric_limits<uint32_t>::max(); // invalid
- while (m_retxSeqs.size ())
- {
- seq = *m_retxSeqs.begin ();
- m_retxSeqs.erase (m_retxSeqs.begin ());
- break;
+ while (m_retxSeqs.size()) {
+ seq = *m_retxSeqs.begin();
+ m_retxSeqs.erase(m_retxSeqs.begin());
+ break;
+ }
+
+ if (seq == std::numeric_limits<uint32_t>::max()) {
+ if (m_seqMax != std::numeric_limits<uint32_t>::max()) {
+ if (m_seq >= m_seqMax) {
+ return; // we are totally done
+ }
}
- if (seq == std::numeric_limits<uint32_t>::max ())
- {
- if (m_seqMax != std::numeric_limits<uint32_t>::max ())
- {
- if (m_seq >= m_seqMax)
- {
- return; // we are totally done
- }
- }
-
- seq = m_seq++;
- }
+ seq = m_seq++;
+ }
//
- Ptr<Name> nameWithSequence = Create<Name> (m_interestName);
- nameWithSequence->appendSeqNum (seq);
+ Ptr<Name> nameWithSequence = Create<Name>(m_interestName);
+ nameWithSequence->appendSeqNum(seq);
//
- Ptr<Interest> interest = Create<Interest> ();
- interest->SetNonce (m_rand.GetValue ());
- interest->SetName (nameWithSequence);
- interest->SetInterestLifetime (m_interestLifeTime);
+ Ptr<Interest> interest = Create<Interest>();
+ interest->SetNonce(m_rand.GetValue());
+ interest->SetName(nameWithSequence);
+ interest->SetInterestLifetime(m_interestLifeTime);
// NS_LOG_INFO ("Requesting Interest: \n" << *interest);
- NS_LOG_INFO ("> Interest for " << seq);
+ NS_LOG_INFO("> Interest for " << seq);
- WillSendOutInterest (seq);
+ WillSendOutInterest(seq);
FwHopCountTag hopCountTag;
- interest->GetPayload ()->AddPacketTag (hopCountTag);
+ interest->GetPayload()->AddPacketTag(hopCountTag);
- m_transmittedInterests (interest, this, m_face);
- m_face->ReceiveInterest (interest);
+ m_transmittedInterests(interest, this, m_face);
+ m_face->ReceiveInterest(interest);
- ScheduleNextPacket ();
+ ScheduleNextPacket();
}
///////////////////////////////////////////////////
// Process incoming packets //
///////////////////////////////////////////////////
-
void
-Consumer::OnData (Ptr<const Data> data)
+Consumer::OnData(Ptr<const Data> data)
{
- if (!m_active) return;
+ if (!m_active)
+ return;
- App::OnData (data); // tracing inside
+ App::OnData(data); // tracing inside
- NS_LOG_FUNCTION (this << data);
+ NS_LOG_FUNCTION(this << data);
// NS_LOG_INFO ("Received content object: " << boost::cref(*data));
- uint32_t seq = data->GetName ().get (-1).toSeqNum ();
- NS_LOG_INFO ("< DATA for " << seq);
+ uint32_t seq = data->GetName().get(-1).toSeqNum();
+ NS_LOG_INFO("< DATA for " << seq);
int hopCount = -1;
FwHopCountTag hopCountTag;
- if (data->GetPayload ()->PeekPacketTag (hopCountTag))
- {
- hopCount = hopCountTag.Get ();
- }
+ if (data->GetPayload()->PeekPacketTag(hopCountTag)) {
+ hopCount = hopCountTag.Get();
+ }
- SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find (seq);
- if (entry != m_seqLastDelay.end ())
- {
- m_lastRetransmittedInterestDataDelay (this, seq, Simulator::Now () - entry->time, hopCount);
- }
+ SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq);
+ if (entry != m_seqLastDelay.end()) {
+ m_lastRetransmittedInterestDataDelay(this, seq, Simulator::Now() - entry->time, hopCount);
+ }
- entry = m_seqFullDelay.find (seq);
- if (entry != m_seqFullDelay.end ())
- {
- m_firstInterestDataDelay (this, seq, Simulator::Now () - entry->time, m_seqRetxCounts[seq], hopCount);
- }
+ entry = m_seqFullDelay.find(seq);
+ if (entry != m_seqFullDelay.end()) {
+ m_firstInterestDataDelay(this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq],
+ hopCount);
+ }
- m_seqRetxCounts.erase (seq);
- m_seqFullDelay.erase (seq);
- m_seqLastDelay.erase (seq);
+ m_seqRetxCounts.erase(seq);
+ m_seqFullDelay.erase(seq);
+ m_seqLastDelay.erase(seq);
- m_seqTimeouts.erase (seq);
- m_retxSeqs.erase (seq);
+ m_seqTimeouts.erase(seq);
+ m_retxSeqs.erase(seq);
- m_rtt->AckSeq (SequenceNumber32 (seq));
+ m_rtt->AckSeq(SequenceNumber32(seq));
}
void
-Consumer::OnNack (Ptr<const Interest> interest)
+Consumer::OnNack(Ptr<const Interest> interest)
{
- if (!m_active) return;
+ if (!m_active)
+ return;
- App::OnNack (interest); // tracing inside
+ App::OnNack(interest); // tracing inside
// NS_LOG_DEBUG ("Nack type: " << interest->GetNack ());
// NS_LOG_FUNCTION (interest->GetName ());
// NS_LOG_INFO ("Received NACK: " << boost::cref(*interest));
- uint32_t seq = interest->GetName ().get (-1).toSeqNum ();
- NS_LOG_INFO ("< NACK for " << seq);
+ uint32_t seq = interest->GetName().get(-1).toSeqNum();
+ NS_LOG_INFO("< NACK for " << seq);
// std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n";
// put in the queue of interests to be retransmitted
// NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
- m_retxSeqs.insert (seq);
+ m_retxSeqs.insert(seq);
// NS_LOG_INFO ("After: " << m_retxSeqs.size ());
- m_seqTimeouts.erase (seq);
+ m_seqTimeouts.erase(seq);
- m_rtt->IncreaseMultiplier (); // Double the next RTO ??
- ScheduleNextPacket ();
+ m_rtt->IncreaseMultiplier(); // Double the next RTO ??
+ ScheduleNextPacket();
}
void
-Consumer::OnTimeout (uint32_t sequenceNumber)
+Consumer::OnTimeout(uint32_t sequenceNumber)
{
- NS_LOG_FUNCTION (sequenceNumber);
- // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " << m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n";
+ NS_LOG_FUNCTION(sequenceNumber);
+ // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " <<
+ // m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n";
- m_rtt->IncreaseMultiplier (); // Double the next RTO
- m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1); // make sure to disable RTT calculation for this sample
- m_retxSeqs.insert (sequenceNumber);
- ScheduleNextPacket ();
+ m_rtt->IncreaseMultiplier(); // Double the next RTO
+ m_rtt->SentSeq(SequenceNumber32(sequenceNumber),
+ 1); // make sure to disable RTT calculation for this sample
+ m_retxSeqs.insert(sequenceNumber);
+ ScheduleNextPacket();
}
void
-Consumer::WillSendOutInterest (uint32_t sequenceNumber)
+Consumer::WillSendOutInterest(uint32_t sequenceNumber)
{
- NS_LOG_DEBUG ("Trying to add " << sequenceNumber << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");
+ NS_LOG_DEBUG("Trying to add " << sequenceNumber << " with " << Simulator::Now() << ". already "
+ << m_seqTimeouts.size() << " items");
- m_seqTimeouts.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
- m_seqFullDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
+ m_seqTimeouts.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
+ m_seqFullDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
- m_seqLastDelay.erase (sequenceNumber);
- m_seqLastDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
+ m_seqLastDelay.erase(sequenceNumber);
+ m_seqLastDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
- m_seqRetxCounts[sequenceNumber] ++;
+ m_seqRetxCounts[sequenceNumber]++;
- m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1);
+ m_rtt->SentSeq(SequenceNumber32(sequenceNumber), 1);
}
-
} // namespace ndn
} // namespace ns3
diff --git a/apps/ndn-consumer.hpp b/apps/ndn-consumer.hpp
index d0f82cc..83ece12 100644
--- a/apps/ndn-consumer.hpp
+++ b/apps/ndn-consumer.hpp
@@ -44,158 +44,168 @@
* @ingroup ndn-apps
* \brief NDN application for sending out Interest packets
*/
-class Consumer: public App
-{
+class Consumer : public App {
public:
- static TypeId GetTypeId ();
+ static TypeId
+ GetTypeId();
/**
* \brief Default constructor
* Sets up randomizer function and packet sequence number
*/
- Consumer ();
- virtual ~Consumer () {};
+ Consumer();
+ virtual ~Consumer(){};
// From App
// virtual void
// OnInterest (const Ptr<const Interest> &interest);
virtual void
- OnNack (Ptr<const Interest> interest);
+ OnNack(Ptr<const Interest> interest);
virtual void
- OnData (Ptr<const Data> contentObject);
+ OnData(Ptr<const Data> contentObject);
/**
* @brief Timeout event
* @param sequenceNumber time outed sequence number
*/
virtual void
- OnTimeout (uint32_t sequenceNumber);
+ OnTimeout(uint32_t sequenceNumber);
/**
* @brief Actually send packet
*/
void
- SendPacket ();
+ SendPacket();
/**
- * @brief An event that is fired just before an Interest packet is actually send out (send is inevitable)
+ * @brief An event that is fired just before an Interest packet is actually send out (send is
+ *inevitable)
*
- * The reason for "before" even is that in certain cases (when it is possible to satisfy from the local cache),
- * the send call will immediately return data, and if "after" even was used, this after would be called after
+ * The reason for "before" even is that in certain cases (when it is possible to satisfy from the
+ *local cache),
+ * the send call will immediately return data, and if "after" even was used, this after would be
+ *called after
* all processing of incoming data, potentially producing unexpected results.
*/
virtual void
- WillSendOutInterest (uint32_t sequenceNumber);
-
+ WillSendOutInterest(uint32_t sequenceNumber);
+
protected:
// from App
virtual void
- StartApplication ();
+ StartApplication();
virtual void
- StopApplication ();
+ StopApplication();
/**
- * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
+ * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
+ * protocol
*/
virtual void
- ScheduleNextPacket () = 0;
+ ScheduleNextPacket() = 0;
/**
* \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
*/
void
- CheckRetxTimeout ();
+ CheckRetxTimeout();
/**
* \brief Modifies the frequency of checking the retransmission timeouts
* \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
*/
void
- SetRetxTimer (Time retxTimer);
+ SetRetxTimer(Time retxTimer);
/**
* \brief Returns the frequency of checking the retransmission timeouts
* \return Timeout defining how frequent retransmission timeouts should be checked
*/
Time
- GetRetxTimer () const;
+ GetRetxTimer() const;
protected:
UniformVariable m_rand; ///< @brief nonce generator
- uint32_t m_seq; ///< @brief currently requested sequence number
- uint32_t m_seqMax; ///< @brief maximum number of sequence number
- EventId m_sendEvent; ///< @brief EventId of pending "send packet" event
- Time m_retxTimer; ///< @brief Currently estimated retransmission timer
- EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
+ uint32_t m_seq; ///< @brief currently requested sequence number
+ uint32_t m_seqMax; ///< @brief maximum number of sequence number
+ EventId m_sendEvent; ///< @brief EventId of pending "send packet" event
+ Time m_retxTimer; ///< @brief Currently estimated retransmission timer
+ EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
Ptr<RttEstimator> m_rtt; ///< @brief RTT estimator
- Time m_offTime; ///< \brief Time interval between packets
- Name m_interestName; ///< \brief NDN Name of the Interest (use Name)
- Time m_interestLifeTime; ///< \brief LifeTime for interest packet
+ Time m_offTime; ///< \brief Time interval between packets
+ Name m_interestName; ///< \brief NDN Name of the Interest (use Name)
+ Time m_interestLifeTime; ///< \brief LifeTime for interest packet
-/// @cond include_hidden
+ /// @cond include_hidden
/**
* \struct This struct contains sequence numbers of packets to be retransmitted
*/
- struct RetxSeqsContainer :
- public std::set<uint32_t> { };
+ struct RetxSeqsContainer : public std::set<uint32_t> {
+ };
- RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
+ RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
/**
* \struct This struct contains a pair of packet sequence number and its timeout
*/
- struct SeqTimeout
- {
- SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
+ struct SeqTimeout {
+ SeqTimeout(uint32_t _seq, Time _time)
+ : seq(_seq)
+ , time(_time)
+ {
+ }
uint32_t seq;
Time time;
};
-/// @endcond
+ /// @endcond
-/// @cond include_hidden
- class i_seq { };
- class i_timestamp { };
-/// @endcond
+ /// @cond include_hidden
+ class i_seq {
+ };
+ class i_timestamp {
+ };
+ /// @endcond
-/// @cond include_hidden
+ /// @cond include_hidden
/**
* \struct This struct contains a multi-index for the set of SeqTimeout structs
*/
- struct SeqTimeoutsContainer :
- public boost::multi_index::multi_index_container<
- SeqTimeout,
- boost::multi_index::indexed_by<
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<i_seq>,
- boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
- >,
- boost::multi_index::ordered_non_unique<
- boost::multi_index::tag<i_timestamp>,
- boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
- >
- >
- > { } ;
+ struct SeqTimeoutsContainer
+ : public boost::multi_index::
+ multi_index_container<SeqTimeout,
+ boost::multi_index::
+ indexed_by<boost::multi_index::
+ ordered_unique<boost::multi_index::tag<i_seq>,
+ boost::multi_index::
+ member<SeqTimeout, uint32_t,
+ &SeqTimeout::seq>>,
+ boost::multi_index::
+ ordered_non_unique<boost::multi_index::
+ tag<i_timestamp>,
+ boost::multi_index::
+ member<SeqTimeout, Time,
+ &SeqTimeout::time>>>> {
+ };
- SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
+ SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
SeqTimeoutsContainer m_seqLastDelay;
SeqTimeoutsContainer m_seqFullDelay;
std::map<uint32_t, uint32_t> m_seqRetxCounts;
- TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
- Time /* delay */, int32_t /*hop count*/> m_lastRetransmittedInterestDataDelay;
- TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
- Time /* delay */, uint32_t /*retx count*/,
- int32_t /*hop count*/> m_firstInterestDataDelay;
+ TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */, Time /* delay */, int32_t /*hop count*/>
+ m_lastRetransmittedInterestDataDelay;
+ TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */, Time /* delay */,
+ uint32_t /*retx count*/, int32_t /*hop count*/> m_firstInterestDataDelay;
-/// @endcond
+ /// @endcond
};
} // namespace ndn
diff --git a/apps/ndn-producer.cpp b/apps/ndn-producer.cpp
index 605b082..67a5043 100644
--- a/apps/ndn-producer.cpp
+++ b/apps/ndn-producer.cpp
@@ -38,119 +38,114 @@
#include <boost/lambda/bind.hpp>
namespace ll = boost::lambda;
-NS_LOG_COMPONENT_DEFINE ("ndn.Producer");
+NS_LOG_COMPONENT_DEFINE("ndn.Producer");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (Producer);
+NS_OBJECT_ENSURE_REGISTERED(Producer);
TypeId
-Producer::GetTypeId (void)
+Producer::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::Producer")
- .SetGroupName ("Ndn")
- .SetParent<App> ()
- .AddConstructor<Producer> ()
- .AddAttribute ("Prefix","Prefix, for which producer has the data",
- StringValue ("/"),
- MakeNameAccessor (&Producer::m_prefix),
- MakeNameChecker ())
- .AddAttribute ("Postfix", "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
- StringValue ("/"),
- MakeNameAccessor (&Producer::m_postfix),
- MakeNameChecker ())
- .AddAttribute ("PayloadSize", "Virtual payload size for Content packets",
- UintegerValue (1024),
- MakeUintegerAccessor (&Producer::m_virtualPayloadSize),
- MakeUintegerChecker<uint32_t> ())
- .AddAttribute ("Freshness", "Freshness of data packets, if 0, then unlimited freshness",
- TimeValue (Seconds (0)),
- MakeTimeAccessor (&Producer::m_freshness),
- MakeTimeChecker ())
- .AddAttribute ("Signature", "Fake signature, 0 valid signature (default), other values application-specific",
- UintegerValue (0),
- MakeUintegerAccessor (&Producer::m_signature),
- MakeUintegerChecker<uint32_t> ())
- .AddAttribute ("KeyLocator", "Name to be used for key locator. If root, then key locator is not used",
- NameValue (),
- MakeNameAccessor (&Producer::m_keyLocator),
- MakeNameChecker ())
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::Producer")
+ .SetGroupName("Ndn")
+ .SetParent<App>()
+ .AddConstructor<Producer>()
+ .AddAttribute("Prefix", "Prefix, for which producer has the data", StringValue("/"),
+ MakeNameAccessor(&Producer::m_prefix), MakeNameChecker())
+ .AddAttribute(
+ "Postfix",
+ "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
+ StringValue("/"), MakeNameAccessor(&Producer::m_postfix), MakeNameChecker())
+ .AddAttribute("PayloadSize", "Virtual payload size for Content packets", UintegerValue(1024),
+ MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
+ MakeUintegerChecker<uint32_t>())
+ .AddAttribute("Freshness", "Freshness of data packets, if 0, then unlimited freshness",
+ TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness),
+ MakeTimeChecker())
+ .AddAttribute(
+ "Signature",
+ "Fake signature, 0 valid signature (default), other values application-specific",
+ UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature),
+ MakeUintegerChecker<uint32_t>())
+ .AddAttribute("KeyLocator",
+ "Name to be used for key locator. If root, then key locator is not used",
+ NameValue(), MakeNameAccessor(&Producer::m_keyLocator), MakeNameChecker());
return tid;
}
-Producer::Producer ()
+Producer::Producer()
{
// NS_LOG_FUNCTION_NOARGS ();
}
// inherited from Application base class.
void
-Producer::StartApplication ()
+Producer::StartApplication()
{
- NS_LOG_FUNCTION_NOARGS ();
- NS_ASSERT (GetNode ()->GetObject<Fib> () != 0);
+ NS_LOG_FUNCTION_NOARGS();
+ NS_ASSERT(GetNode()->GetObject<Fib>() != 0);
- App::StartApplication ();
+ App::StartApplication();
- NS_LOG_DEBUG ("NodeID: " << GetNode ()->GetId ());
+ NS_LOG_DEBUG("NodeID: " << GetNode()->GetId());
- Ptr<Fib> fib = GetNode ()->GetObject<Fib> ();
+ Ptr<Fib> fib = GetNode()->GetObject<Fib>();
- Ptr<fib::Entry> fibEntry = fib->Add (m_prefix, m_face, 0);
+ Ptr<fib::Entry> fibEntry = fib->Add(m_prefix, m_face, 0);
- fibEntry->UpdateStatus (m_face, fib::FaceMetric::NDN_FIB_GREEN);
+ fibEntry->UpdateStatus(m_face, fib::FaceMetric::NDN_FIB_GREEN);
// // make face green, so it will be used primarily
// StaticCast<fib::FibImpl> (fib)->modify (fibEntry,
// ll::bind (&fib::Entry::UpdateStatus,
- // ll::_1, m_face, fib::FaceMetric::NDN_FIB_GREEN));
+ // ll::_1, m_face,
+ // fib::FaceMetric::NDN_FIB_GREEN));
}
void
-Producer::StopApplication ()
+Producer::StopApplication()
{
- NS_LOG_FUNCTION_NOARGS ();
- NS_ASSERT (GetNode ()->GetObject<Fib> () != 0);
+ NS_LOG_FUNCTION_NOARGS();
+ NS_ASSERT(GetNode()->GetObject<Fib>() != 0);
- App::StopApplication ();
+ App::StopApplication();
}
-
void
-Producer::OnInterest (Ptr<const Interest> interest)
+Producer::OnInterest(Ptr<const Interest> interest)
{
- App::OnInterest (interest); // tracing inside
+ App::OnInterest(interest); // tracing inside
- NS_LOG_FUNCTION (this << interest);
+ NS_LOG_FUNCTION(this << interest);
- if (!m_active) return;
+ if (!m_active)
+ return;
- Ptr<Data> data = Create<Data> (Create<Packet> (m_virtualPayloadSize));
- Ptr<Name> dataName = Create<Name> (interest->GetName ());
- dataName->append (m_postfix);
- data->SetName (dataName);
- data->SetFreshness (m_freshness);
- data->SetTimestamp (Simulator::Now());
+ Ptr<Data> data = Create<Data>(Create<Packet>(m_virtualPayloadSize));
+ Ptr<Name> dataName = Create<Name>(interest->GetName());
+ dataName->append(m_postfix);
+ data->SetName(dataName);
+ data->SetFreshness(m_freshness);
+ data->SetTimestamp(Simulator::Now());
- data->SetSignature (m_signature);
- if (m_keyLocator.size () > 0)
- {
- data->SetKeyLocator (Create<Name> (m_keyLocator));
- }
+ data->SetSignature(m_signature);
+ if (m_keyLocator.size() > 0) {
+ data->SetKeyLocator(Create<Name>(m_keyLocator));
+ }
- NS_LOG_INFO ("node("<< GetNode()->GetId() <<") respodning with Data: " << data->GetName ());
+ NS_LOG_INFO("node(" << GetNode()->GetId() << ") respodning with Data: " << data->GetName());
// Echo back FwHopCountTag if exists
FwHopCountTag hopCountTag;
- if (interest->GetPayload ()->PeekPacketTag (hopCountTag))
- {
- data->GetPayload ()->AddPacketTag (hopCountTag);
- }
+ if (interest->GetPayload()->PeekPacketTag(hopCountTag)) {
+ data->GetPayload()->AddPacketTag(hopCountTag);
+ }
- m_face->ReceiveData (data);
- m_transmittedDatas (data, this, m_face);
+ m_face->ReceiveData(data);
+ m_transmittedDatas(data, this, m_face);
}
} // namespace ndn
diff --git a/apps/ndn-producer.hpp b/apps/ndn-producer.hpp
index 7905b9b..11ebc56 100644
--- a/apps/ndn-producer.hpp
+++ b/apps/ndn-producer.hpp
@@ -40,24 +40,24 @@
* size and name same as in Interest.cation, which replying every incoming Interest
* with Data packet with a specified size and name same as in Interest.
*/
-class Producer : public App
-{
+class Producer : public App {
public:
static TypeId
- GetTypeId (void);
+ GetTypeId(void);
- Producer ();
+ Producer();
// inherited from NdnApp
- void OnInterest (Ptr<const Interest> interest);
+ void
+ OnInterest(Ptr<const Interest> interest);
protected:
// inherited from Application base class.
virtual void
- StartApplication (); // Called at time specified by Start
+ StartApplication(); // Called at time specified by Start
virtual void
- StopApplication (); // Called at time specified by Stop
+ StopApplication(); // Called at time specified by Stop
private:
Name m_prefix;