Tracing window size in CcnxConsumerWindow
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