Adding IPv4 rate tracer
diff --git a/examples/congestion-zoom.cc b/examples/congestion-zoom.cc
index 087a266..35b3c0c 100644
--- a/examples/congestion-zoom.cc
+++ b/examples/congestion-zoom.cc
@@ -126,7 +126,7 @@
CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow");
consumerHelper.SetPrefix ("/" + lexical_cast<string> (server->GetId ()));
- consumerHelper.SetAttribute ("Size", StringValue ("100.0"));
+ consumerHelper.SetAttribute ("Size", StringValue ("2.0"));
CcnxAppHelper producerHelper ("ns3::CcnxProducer");
producerHelper.SetPrefix ("/" + lexical_cast<string> (server->GetId ()));
@@ -145,6 +145,26 @@
{
ApplicationContainer apps;
+ Ptr<Node> client = Names::Find<Node> (prefix, lexical_cast<string> ("client"));
+ Ptr<Node> server = Names::Find<Node> (prefix, lexical_cast<string> ("server"));
+
+ Ptr<Ipv4> ipv4 = client->GetObject<Ipv4> ();
+
+ // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
+ PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), 1024));
+
+ BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
+ InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), 1024));
+ // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl;
+ producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets
+
+ apps.Add
+ (consumerHelper.Install (client));
+
+ apps.Add
+ (producerHelper.Install (server));
+
// uint32_t streamId = 0;
// const static uint32_t base_port = 10;
// for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
@@ -221,7 +241,7 @@
{
experiment.ConfigureTopology ();
experiment.InstallCcnxStack ();
- ApplicationContainer apps = experiment.AddCcnxApplications ();
+ experiment.AddCcnxApplications ();
// for (uint32_t i = 0; i < apps.GetN () / 2; i++)
// {
@@ -232,42 +252,43 @@
CcnxTraceHelper traceHelper;
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");
+ // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log");
+ // traceHelper.EnableWindowsAll (prefix + "windows.log");
// config.ConfigureAttributes ();
experiment.Run (Seconds (50.0));
// experiment.reader->SavePositions ("pos.log");
}
- // cout << "TCP experiment\n";
- // // TCP
- // {
- // experiment.ConfigureTopology ();
- // experiment.InstallIpStack ();
- // ApplicationContainer apps = experiment.AddTcpApplications ();
+ cout << "TCP experiment\n";
+ // TCP
+ {
+ experiment.ConfigureTopology ();
+ experiment.InstallIpStack ();
+ experiment.AddTcpApplications ();
- // CcnxTraceHelper traceHelper;
- // traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log");
- // traceHelper.EnableWindowsTcpAll (prefix + "tcp-windows.log");
+ CcnxTraceHelper traceHelper;
+ traceHelper.EnableIpv4RateL3All (prefix + "ipv4-rate-trace.log");
+ // traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log");
+ // traceHelper.EnableWindowsTcpAll (prefix + "tcp-windows.log");
- // for (uint32_t i = 0; i < apps.GetN () / 2; i++)
- // {
- // apps.Get (i*2)->SetStartTime (Seconds (1+i));
+ // for (uint32_t i = 0; i < apps.GetN () / 2; i++)
+ // {
+ // apps.Get (i*2)->SetStartTime (Seconds (1+i));
- // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i));
+ // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i));
- // // cout << "Node: " << apps.Get (i*2 + 1)->GetNode ()->GetId () << "\n";
- // // care only about BulkSender
- // Simulator::Schedule (Seconds (1+i+0.01),
- // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2)->GetNode ());
+ // // cout << "Node: " << apps.Get (i*2 + 1)->GetNode ()->GetId () << "\n";
+ // // care only about BulkSender
+ // Simulator::Schedule (Seconds (1+i+0.01),
+ // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2)->GetNode ());
- // Simulator::Schedule (Seconds (1+i+0.01),
- // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2 + 1)->GetNode ());
- // }
+ // Simulator::Schedule (Seconds (1+i+0.01),
+ // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2 + 1)->GetNode ());
+ // }
- // experiment.Run (Seconds (50.0));
- // }
+ experiment.Run (Seconds (50.0));
+ }
return 0;
}
diff --git a/helper/ccnx-trace-helper.cc b/helper/ccnx-trace-helper.cc
index 0e958fa..bb53be9 100644
--- a/helper/ccnx-trace-helper.cc
+++ b/helper/ccnx-trace-helper.cc
@@ -41,6 +41,7 @@
#include "tracers/ccnx-aggregate-l3-tracer.h"
#include "tracers/ccnx-rate-l3-tracer.h"
#include "tracers/ccnx-seqs-app-tracer.h"
+#include "tracers/ipv4-rate-l3-tracer.h"
#include "tracers/ipv4-seqs-app-tracer.h"
#include "tracers/ccnx-consumer-window-tracer.h"
#include "tracers/ccnx-path-weight-tracer.h"
@@ -76,6 +77,7 @@
if (m_windowsTrace != 0) delete m_windowsTrace;
if (m_windowsTcpTrace != 0) delete m_windowsTcpTrace;
if (m_pathWeightsTrace != 0) delete m_pathWeightsTrace;
+ if (m_ipv4RateTrace != 0) delete m_ipv4RateTrace;
if (m_apps.size () > 0)
{
@@ -203,7 +205,7 @@
NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node);
- trace->SetAveragingPeriod (Seconds (0.5));
+ trace->SetAveragingPeriod (Seconds (0.2));
m_l3Rates.push_back (trace);
}
@@ -216,6 +218,32 @@
}
void
+CcnxTraceHelper::EnableIpv4RateL3All (const std::string &file)
+{
+ NS_LOG_FUNCTION (this);
+ m_ipv4RateTrace = new ofstream (file.c_str (), ios::trunc);
+
+ for (NodeList::Iterator node = NodeList::Begin ();
+ node != NodeList::End ();
+ node++)
+ {
+ NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+
+ Ptr<Ipv4RateL3Tracer> trace = Create<Ipv4RateL3Tracer> (boost::ref(*m_ipv4RateTrace), *node);
+ trace->SetAveragingPeriod (Seconds (0.2));
+ m_ipv4Rates.push_back (trace);
+ }
+
+ if (m_ipv4Rates.size () > 0)
+ {
+ // *m_ipv4RateTrace << "# "; // not necessary for R's read.table
+ m_ipv4Rates.front ()->PrintHeader (*m_ipv4RateTrace);
+ *m_ipv4RateTrace << "\n";
+ }
+}
+
+
+void
CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace)
{
NS_LOG_FUNCTION (this);
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index 59f0a53..aa9cd30 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -31,6 +31,7 @@
class Node;
class CcnxAppTracer;
class CcnxL3Tracer;
+class Ipv4L3Tracer;
class Ipv4AppTracer;
class WindowTracer;
class CcnxPathWeightTracer;
@@ -99,6 +100,12 @@
EnableIpv4SeqsAppAll (const std::string &appSeqsTrace = "app-seqs.log");
/**
+ * @brief Enable network-level IPv4 rate tracing on all IPv4-enabled nodes
+ */
+ void
+ EnableIpv4RateL3All (const std::string &ipv4RateTrace = "ipv4-rate.log");
+
+ /**
* @brief Enable tracing of window changes in CcnxConsumerWindow
*/
void
@@ -136,6 +143,9 @@
std::list<Ptr<CcnxAppTracer> > m_appSeqs;
std::ostream *m_appSeqsTrace;
+ std::list<Ptr<Ipv4L3Tracer> > m_ipv4Rates;
+ std::ostream *m_ipv4RateTrace;
+
std::list<Ptr<Ipv4AppTracer> > m_ipv4AppSeqs;
std::ostream *m_ipv4AppSeqsTrace;
diff --git a/helper/tracers/ipv4-l3-tracer.cc b/helper/tracers/ipv4-l3-tracer.cc
new file mode 100644
index 0000000..ed2cb9c
--- /dev/null
+++ b/helper/tracers/ipv4-l3-tracer.cc
@@ -0,0 +1,61 @@
+/* -*- 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 "ipv4-l3-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/names.h"
+#include "ns3/callback.h"
+#include "ns3/ccnx-app.h"
+#include "ns3/ccnx-face.h"
+
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+
+namespace ns3 {
+
+Ipv4L3Tracer::Ipv4L3Tracer (Ptr<Node> node)
+: m_nodePtr (node)
+{
+ m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+
+ Connect ();
+
+ string name = Names::FindName (node);
+ if (!name.empty ())
+ {
+ m_node = name;
+ }
+}
+
+void
+Ipv4L3Tracer::Connect ()
+{
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/Tx",
+ MakeCallback (&Ipv4L3Tracer::Tx, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/Rx",
+ MakeCallback (&Ipv4L3Tracer::Rx, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/Drop",
+ MakeCallback (&Ipv4L3Tracer::Drop, this));
+}
+
+} // namespace ns3
diff --git a/helper/tracers/ipv4-l3-tracer.h b/helper/tracers/ipv4-l3-tracer.h
new file mode 100644
index 0000000..e5f3c74
--- /dev/null
+++ b/helper/tracers/ipv4-l3-tracer.h
@@ -0,0 +1,90 @@
+/* -*- 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 IPV4_L3_TRACER_H
+#define IPV4_L3_TRACER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/ipv4-l3-protocol.h"
+
+namespace ns3 {
+
+class Node;
+
+class Ipv4L3Tracer : public SimpleRefCount<Ipv4L3Tracer>
+{
+public:
+ Ipv4L3Tracer (Ptr<Node> node);
+ virtual ~Ipv4L3Tracer () { };
+
+ void
+ Connect ();
+
+ virtual void
+ PrintHeader (std::ostream &os) const = 0;
+
+ virtual void
+ Print (std::ostream &os) const = 0;
+
+ virtual void
+ Rx (std::string context,
+ Ptr<const Packet>, Ptr<Ipv4>, uint32_t) = 0;
+
+ virtual void
+ Tx (std::string context,
+ Ptr<const Packet>, Ptr<Ipv4>, uint32_t) = 0;
+
+ virtual void
+ Drop (std::string context,
+ const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t) = 0;
+
+protected:
+ std::string m_node;
+ Ptr<Node> m_nodePtr;
+
+ struct Stats
+ {
+ void Reset ()
+ {
+ m_in = 0;
+ m_out = 0;
+ m_drop = 0;
+ }
+
+ uint64_t m_in;
+ uint64_t m_out;
+ uint64_t m_drop;
+ };
+};
+
+inline std::ostream&
+operator << (std::ostream &os, const Ipv4L3Tracer &tracer)
+{
+ os << "# ";
+ tracer.PrintHeader (os);
+ os << "\n";
+ tracer.Print (os);
+ return os;
+}
+
+} // namespace ns3
+
+#endif // IPV4_L3_TRACER_H
diff --git a/helper/tracers/ipv4-rate-l3-tracer.cc b/helper/tracers/ipv4-rate-l3-tracer.cc
new file mode 100644
index 0000000..e97ba18
--- /dev/null
+++ b/helper/tracers/ipv4-rate-l3-tracer.cc
@@ -0,0 +1,142 @@
+/* -*- 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 "ipv4-rate-l3-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/simulator.h"
+
+#include "ns3/ipv4-header.h"
+
+namespace ns3 {
+
+Ipv4RateL3Tracer::Ipv4RateL3Tracer (std::ostream &os, Ptr<Node> node)
+ : Ipv4L3Tracer (node)
+ , m_os (os)
+{
+ SetAveragingPeriod (Seconds (1.0));
+}
+
+Ipv4RateL3Tracer::~Ipv4RateL3Tracer ()
+{
+ m_printEvent.Cancel ();
+}
+
+void
+Ipv4RateL3Tracer::SetAveragingPeriod (const Time &period)
+{
+ m_period = period;
+ m_printEvent.Cancel ();
+ m_printEvent = Simulator::Schedule (m_period, &Ipv4RateL3Tracer::PeriodicPrinter, this);
+}
+
+void
+Ipv4RateL3Tracer::PeriodicPrinter ()
+{
+ Print (m_os);
+ Reset ();
+
+ m_printEvent = Simulator::Schedule (m_period, &Ipv4RateL3Tracer::PeriodicPrinter, this);
+}
+
+void
+Ipv4RateL3Tracer::PrintHeader (std::ostream &os) const
+{
+ os << "Time" << "\t"
+
+ << "Node" << "\t"
+ << "Interface" << "\t"
+
+ << "Type" << "\t"
+ << "Packets" << "\t"
+ << "Kilobytes";
+}
+
+void
+Ipv4RateL3Tracer::Reset ()
+{
+ for (std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
+ stats != m_stats.end ();
+ stats++)
+ {
+ stats->second.get<0> ().Reset ();
+ stats->second.get<1> ().Reset ();
+ }
+}
+
+const double alpha = 0.8;
+
+#define STATS(INDEX) stats->second.get<INDEX> ()
+#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
+
+#define PRINTER(printName, fieldName) \
+STATS(2).fieldName = /*new value*/alpha * RATE(0, fieldName) + /*old value*/(1-alpha) * STATS(2).fieldName; \
+STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
+ \
+os << time.ToDouble (Time::S) << "\t" \
+ << m_node << "\t" \
+ << stats->first << "\t" \
+ << printName << "\t" \
+ << STATS(2).fieldName << "\t" \
+ << STATS(3).fieldName << "\n";
+
+void
+Ipv4RateL3Tracer::Print (std::ostream &os) const
+{
+ for (std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
+ stats != m_stats.end ();
+ stats++)
+ {
+ Time time = Simulator::Now ();
+
+ PRINTER ("In", m_in);
+ PRINTER ("Out", m_out);
+ PRINTER ("Drop", m_drop);
+ }
+}
+
+void
+Ipv4RateL3Tracer::Rx (std::string context,
+ Ptr<const Packet> packet, Ptr<Ipv4> ipv4, uint32_t iface)
+{
+ m_stats[iface].get<0> ().m_in ++;
+ m_stats[iface].get<1> ().m_in += packet->GetSize ();
+}
+
+void
+Ipv4RateL3Tracer::Tx (std::string context,
+ Ptr<const Packet> packet, Ptr<Ipv4> ipv4, uint32_t iface)
+{
+ m_stats[iface].get<0> ().m_out ++;
+ m_stats[iface].get<1> ().m_out += packet->GetSize ();
+}
+
+void
+Ipv4RateL3Tracer::Drop (std::string context,
+ const Ipv4Header &header, Ptr<const Packet> packet, Ipv4L3Protocol::DropReason, Ptr<Ipv4> ipv4, uint32_t iface)
+{
+ m_stats[iface].get<0> ().m_drop ++;
+ m_stats[iface].get<1> ().m_drop += packet->GetSize ();
+}
+
+
+} // namespace ns3
diff --git a/helper/tracers/ipv4-rate-l3-tracer.h b/helper/tracers/ipv4-rate-l3-tracer.h
new file mode 100644
index 0000000..454ac14
--- /dev/null
+++ b/helper/tracers/ipv4-rate-l3-tracer.h
@@ -0,0 +1,85 @@
+/* -*- 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 IPV4_RATE_L3_TRACER_H
+#define IPV4_RATE_L3_TRACER_H
+
+#include "ipv4-l3-tracer.h"
+
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+
+#include <boost/tuple/tuple.hpp>
+#include <map>
+
+namespace ns3 {
+
+/**
+ * @ingroup ccnx
+ * @brief CCNx network-layer rate tracer
+ */
+class Ipv4RateL3Tracer : public Ipv4L3Tracer
+{
+public:
+ /**
+ * @brief Network layer tracer constructor
+ */
+ Ipv4RateL3Tracer (std::ostream &os, Ptr<Node> node);
+ virtual ~Ipv4RateL3Tracer ();
+
+ void
+ SetAveragingPeriod (const Time &period);
+
+ virtual void
+ PrintHeader (std::ostream &os) const;
+
+ virtual void
+ Print (std::ostream &os) const;
+
+ virtual void
+ Rx (std::string context,
+ Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
+
+ virtual void
+ Tx (std::string context,
+ Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
+
+ virtual void
+ Drop (std::string context,
+ const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t);
+
+private:
+ void
+ PeriodicPrinter ();
+
+ void
+ Reset ();
+
+private:
+ std::ostream& m_os;
+ Time m_period;
+ EventId m_printEvent;
+
+ mutable std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
+};
+
+} // namespace ns3
+
+#endif // IPV4_RATE_L3_TRACER_H
diff --git a/wscript b/wscript
index db6d4d6..034a24b 100644
--- a/wscript
+++ b/wscript
@@ -59,6 +59,7 @@
"helper/ccnx-header-helper.h",
"helper/ccnx-trace-helper.h",
"helper/tracers/ipv4-app-tracer.h",
+ "helper/tracers/ipv4-l3-tracer.h",
"helper/tracers/ccnx-app-tracer.h",
"helper/tracers/ccnx-l3-tracer.h",
"helper/tracers/ccnx-consumer-window-tracer.h",