Adding sequence number tracer
diff --git a/apps/ccnx-consumer.cc b/apps/ccnx-consumer.cc
index 83bb444..6b63693 100644
--- a/apps/ccnx-consumer.cc
+++ b/apps/ccnx-consumer.cc
@@ -167,6 +167,11 @@
else
break; // nothing else to do. All later packets need not be retransmitted
}
+
+ if (m_retxSeqs.size () > 0)
+ {
+ ScheduleNextPacket ();
+ }
m_retxEvent = Simulator::Schedule (m_retxTimer,
&CcnxConsumer::CheckRetxTimeout, this);
@@ -224,17 +229,17 @@
}
m_seqMax = floor(1.0 + size * 1024.0 * 1024.0 / m_payloadSize);
+ NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
}
void
CcnxConsumer::ScheduleNextPacket ()
{
- // schedule periodic packet generation
-
- m_sendEvent = Simulator::Schedule (
- Seconds(m_randExp.GetValue ()),
- &CcnxConsumer::SendPacket, this);
+ if (!m_sendEvent.IsRunning ())
+ m_sendEvent = Simulator::Schedule (
+ Seconds(m_randExp.GetValue ()),
+ &CcnxConsumer::SendPacket, this);
}
// Application Methods
@@ -264,6 +269,8 @@
void
CcnxConsumer::SendPacket ()
{
+ if (!m_active) return;
+
NS_LOG_FUNCTION_NOARGS ();
boost::mutex::scoped_lock (m_seqTimeoutsGuard);
@@ -283,10 +290,7 @@
{
if (m_seq >= m_seqMax)
{
- if (m_seqTimeouts.size () == 0)
- return; // we are totally done
- else
- ScheduleNextPacket (); // we will probably need to retransmit something in the future
+ return; // we are totally done
}
}
@@ -341,6 +345,8 @@
CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
const Ptr<const Packet> &payload)
{
+ if (!m_active) return;
+
CcnxApp::OnContentObject (contentObject, payload); // tracing inside
NS_LOG_FUNCTION (this << contentObject << payload);
@@ -364,6 +370,8 @@
void
CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest)
{
+ if (!m_active) return;
+
CcnxApp::OnNack (interest); // tracing inside
NS_LOG_DEBUG ("Nack type: " << interest->GetNack ());
@@ -379,6 +387,8 @@
NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
m_retxSeqs.insert (seq);
NS_LOG_INFO ("After: " << m_retxSeqs.size ());
+
+ ScheduleNextPacket ();
}
} // namespace ns3
diff --git a/examples/synthetic-topology.cc b/examples/synthetic-topology.cc
index 11f930f..971bbe1 100644
--- a/examples/synthetic-topology.cc
+++ b/examples/synthetic-topology.cc
@@ -93,6 +93,7 @@
consumerHelper.SetPrefix ("/6");
consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
+ consumerHelper.SetAttribute ("Size", StringValue ("1.0"));
ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "c1"));
consumerHelper.SetPrefix ("/7");
@@ -108,9 +109,9 @@
ApplicationContainer consumers4 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c4"));
consumers.Start (Seconds (0));
- consumers2.Start (Seconds (10));
- consumers3.Start (Seconds (20));
- consumers4.Start (Seconds (30));
+ consumers2.Start (Seconds (2.5));
+ consumers3.Start (Seconds (5));
+ consumers4.Start (Seconds (7.5));
/////////////////////////////////////////////
@@ -146,7 +147,8 @@
// traceHelper.EnableAggregateL3All ();
// traceHelper.SetL3TraceFile ("trace-l3.log");
// traceHelper.SetAppTraceFile ("trace-app.log");
- traceHelper.EnableRateL3All ("rate-trace.log");
+ // traceHelper.EnableRateL3All ("rate-trace.log");
+ traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log");
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
diff --git a/examples/synthetic-topology.txt b/examples/synthetic-topology.txt
index a5c5446..260f6ab 100644
--- a/examples/synthetic-topology.txt
+++ b/examples/synthetic-topology.txt
@@ -16,9 +16,9 @@
#OSPF weight on 04/10/2003 (see http://www.abilene.iu.edu/images/Ab-IGP-topo.jpg)
#x y capacity(kbps) OSPF Delay MaxPackets
c1 n1 10Mbps 1 50ms 200
-c2 n1 10Mbps 1 1ms 200
-c3 n1 10Mbps 1 1ms 200
-n1 n2 1Mbps 1176 1ms 20
+c2 n1 10Mbps 1 10ms 200
+c3 n1 10Mbps 1 100ms 200
+n1 n2 1Mbps 1176 20ms 20
n1 n12 1Mbps 587 1ms 20
n12 n2 1Mbps 846 1ms 20
n2 p1 10Mbps 260 1ms 200
diff --git a/helper/ccnx-trace-helper.cc b/helper/ccnx-trace-helper.cc
index a27ba1a..8a53928 100644
--- a/helper/ccnx-trace-helper.cc
+++ b/helper/ccnx-trace-helper.cc
@@ -38,6 +38,7 @@
#include "tracers/ccnx-aggregate-app-tracer.h"
#include "tracers/ccnx-aggregate-l3-tracer.h"
#include "tracers/ccnx-rate-l3-tracer.h"
+#include "tracers/ccnx-seqs-app-tracer.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-content-object-header.h"
@@ -53,6 +54,7 @@
CcnxTraceHelper::CcnxTraceHelper ()
: m_l3RateTrace (0)
+ , m_appSeqsTrace (0)
{
}
@@ -60,6 +62,7 @@
{
NS_LOG_FUNCTION (this);
if (m_l3RateTrace != 0) delete m_l3RateTrace;
+ if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
if (m_apps.size () > 0)
{
@@ -199,4 +202,46 @@
}
}
+void
+CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace)
+{
+ NS_LOG_FUNCTION (this);
+ m_appSeqsTrace = new ofstream (trace.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++)
+ {
+ NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
+ if ((*app)->GetInstanceTypeId ().GetName () == appName)
+ {
+ Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace),
+ appName,
+ *node,
+ lexical_cast<string> (appId));
+ m_appSeqs.push_back (trace);
+ }
+ }
+
+ }
+
+ if (m_appSeqs.size () > 0)
+ {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace);
+ *m_appSeqsTrace << "\n";
+ }
+}
+
+
} // namespace ns3
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index 54d7405..7a5eaf1 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -76,11 +76,17 @@
EnableAggregateL3All ();
/**
- * @brief Enable network-level CCNx rate tracing on all CCNx nodes (individual file per node)
+ * @brief Enable network-level CCNx rate tracing on all CCNx nodes
*/
void
EnableRateL3All (const std::string &l3RateTrace = "l3-rate.log");
+ /**
+ * @brief Enable app-level CCNx sequence tracing on all CCNx applications
+ */
+ void
+ EnableSeqsAppAll (const std::string &app, const std::string &appSeqsTrace = "app-seqs.log");
+
private:
std::string m_appTrace;
std::list<Ptr<CcnxAppTracer> > m_apps;
@@ -90,6 +96,9 @@
std::list<Ptr<CcnxL3Tracer> > m_l3Rates;
std::ostream *m_l3RateTrace;
+
+ std::list<Ptr<CcnxAppTracer> > m_appSeqs;
+ std::ostream *m_appSeqsTrace;
};
diff --git a/helper/tracers/ccnx-seqs-app-tracer.cc b/helper/tracers/ccnx-seqs-app-tracer.cc
new file mode 100644
index 0000000..5ea636e
--- /dev/null
+++ b/helper/tracers/ccnx-seqs-app-tracer.cc
@@ -0,0 +1,116 @@
+/* -*- 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-seqs-app-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/simulator.h"
+
+#include "ns3/ccnx-app.h"
+#include "ns3/ccnx-face.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+namespace ns3 {
+
+CcnxSeqsAppTracer::CcnxSeqsAppTracer (std::ostream &os, const std::string &app, Ptr<Node> node, const std::string &appId)
+ : CcnxAppTracer (app, node, appId)
+ , m_os (os)
+{
+}
+
+CcnxSeqsAppTracer::CcnxSeqsAppTracer (std::ostream &os, const std::string &app, const std::string &node, const std::string &appId)
+ : CcnxAppTracer (app, node, appId)
+ , m_os (os)
+{
+}
+
+void
+CcnxSeqsAppTracer::Reset ()
+{
+}
+
+void
+CcnxSeqsAppTracer::PrintHeader (std::ostream &os) const
+{
+ os << "Time\t"
+ << "Node\t"
+ << "AppName\t"
+ << "AppId\t"
+ << "Type\t"
+ << "SeqNo";
+}
+
+void
+CcnxSeqsAppTracer::Print (std::ostream &os) const
+{
+}
+
+#define PRINTER(type) \
+ m_os \
+ << Simulator::Now ().ToDouble (Time::S) << "\t" \
+ << m_node << "\t" \
+ << m_app << "\t" \
+ << m_appId << "\t" \
+ << type << "\t" \
+ << header->GetName ().GetLastComponent () << std::endl;
+
+void
+CcnxSeqsAppTracer::OutInterests (std::string context,
+ Ptr<const CcnxInterestHeader> header, Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+ PRINTER ("OutInterest");
+}
+
+void
+CcnxSeqsAppTracer::OutData (std::string context,
+ Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet>,
+ Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+ PRINTER ("OutData");
+}
+
+void
+CcnxSeqsAppTracer::InInterests (std::string context,
+ Ptr<const CcnxInterestHeader> header,
+ Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+ PRINTER ("InInterest");
+}
+
+void
+CcnxSeqsAppTracer::InNacks (std::string context,
+ Ptr<const CcnxInterestHeader> header,
+ Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+ PRINTER ("InNacks");
+}
+
+void
+CcnxSeqsAppTracer::InData (std::string context,
+ Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet>,
+ Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+ PRINTER ("InData");
+}
+
+} // namespace ns3
diff --git a/helper/tracers/ccnx-seqs-app-tracer.h b/helper/tracers/ccnx-seqs-app-tracer.h
new file mode 100644
index 0000000..b0fd618
--- /dev/null
+++ b/helper/tracers/ccnx-seqs-app-tracer.h
@@ -0,0 +1,71 @@
+/* -*- 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>
+ */
+
+#ifndef CCNX_SEQS_APP_TRACER_H
+#define CCNX_SEQS_APP_TRACER_H
+
+#include "ns3/ccnx-app-tracer.h"
+
+namespace ns3 {
+
+class CcnxSeqsAppTracer : public CcnxAppTracer
+{
+public:
+ CcnxSeqsAppTracer (std::ostream &os, const std::string &app, Ptr<Node> node, const std::string &appId = "*");
+ CcnxSeqsAppTracer (std::ostream &os, const std::string &app, const std::string &node, const std::string &appId = "*");
+ virtual ~CcnxSeqsAppTracer () { };
+
+ virtual void
+ PrintHeader (std::ostream &os) const;
+
+ virtual void
+ Print (std::ostream &os) const;
+
+ virtual void
+ OutInterests (std::string context,
+ Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+ virtual void
+ InInterests (std::string context,
+ Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+ virtual void
+ InNacks (std::string context,
+ Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+ virtual void
+ OutData (std::string context,
+ Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+ virtual void
+ InData (std::string context,
+ Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+protected:
+ void
+ Reset ();
+
+protected:
+ std::ostream& m_os;
+};
+
+} // namespace ns3
+
+#endif // CCNX_AGGREGATE_APP_TRACER_H
diff --git a/model/ccnx-name-components.cc b/model/ccnx-name-components.cc
index fd0064f..77ac75c 100644
--- a/model/ccnx-name-components.cc
+++ b/model/ccnx-name-components.cc
@@ -55,6 +55,17 @@
return m_prefix;
}
+std::string
+CcnxNameComponents::GetLastComponent () const
+{
+ if (m_prefix.size () == 0)
+ {
+ return "";
+ }
+
+ return m_prefix.back ();
+}
+
std::list<boost::reference_wrapper<const std::string> >
CcnxNameComponents::GetSubComponents (size_t num) const
{
diff --git a/model/ccnx-name-components.h b/model/ccnx-name-components.h
index fdffe91..58ca927 100644
--- a/model/ccnx-name-components.h
+++ b/model/ccnx-name-components.h
@@ -55,6 +55,9 @@
const std::list<std::string> &
GetComponents () const;
+ std::string
+ GetLastComponent () const;
+
/**
* \brief Get subcomponents of the name, starting with first component
* \param num Number of components to return. Valid value is in range [1, GetComponents ().size ()]