Tracing window size in CcnxConsumerWindow
diff --git a/apps/ccnx-consumer-window.cc b/apps/ccnx-consumer-window.cc
index 57ca8f5..d244061 100644
--- a/apps/ccnx-consumer-window.cc
+++ b/apps/ccnx-consumer-window.cc
@@ -46,6 +46,10 @@
StringValue ("1000"),
MakeUintegerAccessor (&CcnxConsumerWindow::GetWindow, &CcnxConsumerWindow::SetWindow),
MakeUintegerChecker<uint32_t> ())
+
+ .AddTraceSource ("WindowTrace",
+ "Window that controls how many outstanding interests are allowed",
+ MakeTraceSourceAccessor (&CcnxConsumerWindow::m_window))
;
return tid;
@@ -71,7 +75,7 @@
void
CcnxConsumerWindow::ScheduleNextPacket ()
{
- if (m_window == 0 || m_inFlight >= m_window)
+ if (m_window == static_cast<uint32_t> (0) || m_inFlight >= m_window)
{
if (!m_sendEvent.IsRunning ())
m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S) * 0.1), &CcnxConsumer::SendPacket, this);
@@ -106,7 +110,7 @@
CcnxConsumer::OnNack (interest);
if (m_inFlight > 0) m_inFlight--;
- if (m_window > 0)
+ if (m_window > static_cast<uint32_t> (0))
{
// m_window = 0.5 * m_window;//m_window - 1;
m_window = m_window - 1;
diff --git a/apps/ccnx-consumer-window.h b/apps/ccnx-consumer-window.h
index 47099f6..716608d 100644
--- a/apps/ccnx-consumer-window.h
+++ b/apps/ccnx-consumer-window.h
@@ -23,6 +23,7 @@
#define CCNX_CONSUMER_WINDOW_H
#include "ccnx-consumer.h"
+#include "ns3/traced-value.h"
namespace ns3
{
@@ -70,7 +71,7 @@
GetWindow () const;
protected:
- uint32_t m_window;
+ TracedValue<uint32_t> m_window;
uint32_t m_inFlight;
};
diff --git a/examples/congestion-pop.cc b/examples/congestion-pop.cc
index 0c65860..0a512cb 100644
--- a/examples/congestion-pop.cc
+++ b/examples/congestion-pop.cc
@@ -28,6 +28,7 @@
#include "ns3/random-variable.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
+#include "ns3/config-store.h"
#include <iostream>
#include <sstream>
@@ -256,6 +257,10 @@
Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040"));
+ Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
+ Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
+ Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
+
uint32_t maxRuns = 1;
uint32_t startRun = 0;
CommandLine cmd;
@@ -263,6 +268,9 @@
cmd.AddValue ("runs", "Number of runs", maxRuns);
cmd.Parse (argc, argv);
+ // ConfigStore config;
+ // config.ConfigureDefaults ();
+
for (uint32_t run = startRun; run < startRun + maxRuns; run++)
{
Config::SetGlobal ("RngRun", IntegerValue (run));
@@ -299,7 +307,9 @@
// traceHelper.EnableRateL3All (prefix + "rate-trace.log");
// traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log");
+ traceHelper.EnableWindowsAll (prefix + "windows.log");
+ // config.ConfigureAttributes ();
experiment.Run (Seconds (200.0));
}
diff --git a/helper/ccnx-trace-helper.cc b/helper/ccnx-trace-helper.cc
index 1742462..92c20f7 100644
--- a/helper/ccnx-trace-helper.cc
+++ b/helper/ccnx-trace-helper.cc
@@ -40,6 +40,7 @@
#include "tracers/ccnx-rate-l3-tracer.h"
#include "tracers/ccnx-seqs-app-tracer.h"
#include "tracers/ipv4-seqs-app-tracer.h"
+#include "tracers/ccnx-consumer-window-tracer.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-content-object-header.h"
@@ -57,6 +58,7 @@
: m_l3RateTrace (0)
, m_appSeqsTrace (0)
, m_ipv4AppSeqsTrace (0)
+ , m_windowsTrace (0)
{
}
@@ -66,6 +68,7 @@
if (m_l3RateTrace != 0) delete m_l3RateTrace;
if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
+ if (m_windowsTrace != 0) delete m_windowsTrace;
if (m_apps.size () > 0)
{
@@ -286,5 +289,43 @@
}
}
+void
+CcnxTraceHelper::EnableWindowsAll (const std::string &windowTrace)
+{
+ NS_LOG_FUNCTION (this);
+ m_windowsTrace = new ofstream (windowTrace.c_str (), ios::trunc);
+
+ for (NodeList::Iterator node = NodeList::Begin ();
+ node != NodeList::End ();
+ node++)
+ {
+ ObjectVectorValue apps;
+ (*node)->GetAttribute ("ApplicationList", apps);
+
+ NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+
+ uint32_t appId = 0;
+ for (ObjectVectorValue::Iterator app = apps.Begin ();
+ app != apps.End ();
+ app++, appId++)
+ {
+ if ((*app)->GetInstanceTypeId ().GetName () == "ns3::CcnxConsumerWindow")
+ {
+ Ptr<CcnxConsumerWindowTracer> trace = Create<CcnxConsumerWindowTracer> (boost::ref(*m_windowsTrace),
+ *node,
+ lexical_cast<string> (appId));
+ m_windows.push_back (trace);
+ }
+ }
+
+ }
+
+ if (m_windows.size () > 0)
+ {
+ m_windows.front ()->PrintHeader (*m_windowsTrace);
+ *m_windowsTrace << "\n";
+ }
+}
+
} // namespace ns3
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index 4079f9c..544c887 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -31,6 +31,7 @@
class CcnxAppTracer;
class CcnxL3Tracer;
class Ipv4AppTracer;
+class CcnxConsumerWindowTracer;
class CcnxTraceHelper
{
@@ -93,6 +94,12 @@
*/
void
EnableIpv4SeqsAppAll (const std::string &appSeqsTrace = "app-seqs.log");
+
+ /**
+ * @brief Enable tracing of window changes in CcnxConsumerWindow
+ */
+ void
+ EnableWindowsAll (const std::string &windowTrace = "windows.log");
private:
std::string m_appTrace;
@@ -109,6 +116,9 @@
std::list<Ptr<Ipv4AppTracer> > m_ipv4AppSeqs;
std::ostream *m_ipv4AppSeqsTrace;
+
+ std::list<Ptr<CcnxConsumerWindowTracer> > m_windows;
+ std::ostream *m_windowsTrace;
};
diff --git a/helper/tracers/ccnx-consumer-window-tracer.cc b/helper/tracers/ccnx-consumer-window-tracer.cc
new file mode 100644
index 0000000..e2bf877
--- /dev/null
+++ b/helper/tracers/ccnx-consumer-window-tracer.cc
@@ -0,0 +1,86 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnx-consumer-window-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/names.h"
+#include "ns3/simulator.h"
+
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+using namespace boost;
+
+namespace ns3 {
+
+CcnxConsumerWindowTracer::CcnxConsumerWindowTracer (std::ostream &os, Ptr<Node> node, const std::string &appId)
+ : m_appId (appId)
+ , m_nodePtr (node)
+ , m_os (os)
+{
+ m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+
+ Connect ();
+
+ string name = Names::FindName (node);
+ if (!name.empty ())
+ {
+ m_node = name;
+ }
+}
+
+void
+CcnxConsumerWindowTracer::Connect ()
+{
+ Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::CcnxConsumerWindow/WindowTrace",
+ MakeCallback (&CcnxConsumerWindowTracer::OnWindowChange, this));
+}
+
+
+void
+CcnxConsumerWindowTracer::PrintHeader (std::ostream &os) const
+{
+ os << "Time\t"
+ << "Node\t"
+ << "AppId\t"
+ << "Window";
+}
+
+void
+CcnxConsumerWindowTracer::Print (std::ostream &os) const
+{
+ // do nothing
+}
+
+void
+CcnxConsumerWindowTracer::OnWindowChange (std::string context,
+ uint32_t oldValue, uint32_t newValue)
+{
+ m_os
+ << Simulator::Now ().ToDouble (Time::S) << "\t"
+ << m_node << "\t"
+ << m_appId << "\t"
+ << newValue << endl;
+}
+
+} // namespace ns3
diff --git a/helper/tracers/ccnx-consumer-window-tracer.h b/helper/tracers/ccnx-consumer-window-tracer.h
new file mode 100644
index 0000000..b178ee1
--- /dev/null
+++ b/helper/tracers/ccnx-consumer-window-tracer.h
@@ -0,0 +1,69 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 UCLA
+ *
+ * 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef CCNX_CONSUMER_WINDOW_TRACER_H
+#define CCNX_CONSUMER_WINDOW_TRACER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+
+namespace ns3 {
+
+class Node;
+
+class CcnxConsumerWindowTracer : public SimpleRefCount<CcnxConsumerWindowTracer>
+{
+public:
+ CcnxConsumerWindowTracer (std::ostream &os, Ptr<Node> node, const std::string &appId = "*");
+ virtual ~CcnxConsumerWindowTracer () { };
+
+ void
+ Connect ();
+
+ virtual void
+ PrintHeader (std::ostream &os) const;
+
+ virtual void
+ Print (std::ostream &os) const;
+
+ virtual void
+ OnWindowChange (std::string context,
+ uint32_t oldValue, uint32_t newValue);
+
+protected:
+ std::string m_appId;
+ std::string m_node;
+ Ptr<Node> m_nodePtr;
+ std::ostream& m_os;
+};
+
+inline std::ostream&
+operator << (std::ostream &os, const CcnxConsumerWindowTracer &tracer)
+{
+ os << "# ";
+ tracer.PrintHeader (os);
+ os << "\n";
+ tracer.Print (os);
+ return os;
+}
+
+} // namespace ns3
+
+#endif // CCNX_CONSUMER_WINDOW_TRACER_H
diff --git a/wscript b/wscript
index b3470df..bbdda36 100644
--- a/wscript
+++ b/wscript
@@ -61,6 +61,7 @@
"helper/tracers/ipv4-app-tracer.h",
"helper/tracers/ccnx-app-tracer.h",
"helper/tracers/ccnx-l3-tracer.h",
+ "helper/tracers/ccnx-consumer-window-tracer.h",
"helper/ccnx-face-container.h",
"apps/ccnx-app.h",