helper+utils: Small extension of global routing helper and restoring several IP-based metric collectors, including Ipv4RateL3Tracer
diff --git a/helper/ndn-global-routing-helper.cc b/helper/ndn-global-routing-helper.cc
index 1eb9d1f..135cd4c 100644
--- a/helper/ndn-global-routing-helper.cc
+++ b/helper/ndn-global-routing-helper.cc
@@ -60,7 +60,7 @@
GlobalRoutingHelper::Install (Ptr<Node> node)
{
NS_LOG_LOGIC ("Node: " << node->GetId ());
-
+
Ptr<L3Protocol> ndn = node->GetObject<L3Protocol> ();
NS_ASSERT_MSG (ndn != 0, "Cannot install GlobalRoutingHelper before Ndn is installed on a node");
@@ -70,10 +70,10 @@
NS_LOG_DEBUG ("GlobalRouter is already installed: " << gr);
return; // already installed
}
-
+
gr = CreateObject<GlobalRouter> ();
node->AggregateObject (gr);
-
+
for (uint32_t faceId = 0; faceId < ndn->GetNFaces (); faceId++)
{
Ptr<NetDeviceFace> face = DynamicCast<NetDeviceFace> (ndn->GetFace (faceId));
@@ -82,14 +82,14 @@
NS_LOG_DEBUG ("Skipping non-netdevice face");
continue;
}
-
+
Ptr<NetDevice> nd = face->GetNetDevice ();
if (nd == 0)
{
NS_LOG_DEBUG ("Not a NetDevice associated with NetDeviceFace");
continue;
}
-
+
Ptr<Channel> ch = nd->GetChannel ();
if (ch == 0)
@@ -107,7 +107,7 @@
Ptr<Node> otherNode = otherSide->GetNode ();
NS_ASSERT (otherNode != 0);
-
+
Ptr<GlobalRouter> otherGr = otherNode->GetObject<GlobalRouter> ();
if (otherGr == 0)
{
@@ -126,7 +126,7 @@
Install (ch);
}
grChannel = ch->GetObject<GlobalRouter> ();
-
+
gr->AddIncidency (0, grChannel);
}
}
@@ -143,7 +143,7 @@
gr = CreateObject<GlobalRouter> ();
channel->AggregateObject (gr);
-
+
for (uint32_t deviceId = 0; deviceId < channel->GetNDevices (); deviceId ++)
{
Ptr<NetDevice> dev = channel->GetDevice (deviceId);
@@ -189,7 +189,7 @@
"GlobalRouter is not installed on the node");
Ptr<NameComponents> name = Create<NameComponents> (boost::lexical_cast<NameComponents> (prefix));
- gr->AddLocalPrefix (name);
+ gr->AddLocalPrefix (name);
}
void
@@ -213,16 +213,31 @@
}
void
+GlobalRoutingHelper::AddOriginsForAll ()
+{
+ for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node ++)
+ {
+ Ptr<GlobalRouter> gr = (*node)->GetObject<GlobalRouter> ();
+ string name = Names::FindName (*node);
+
+ if (gr != 0 && !name.empty ())
+ {
+ AddOrigin ("/"+name, *node);
+ }
+ }
+}
+
+void
GlobalRoutingHelper::CalculateRoutes ()
{
/**
* Implementation of route calculation is heavily based on Boost Graph Library
* See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
*/
-
+
BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
-
+
NdnGlobalRouterGraph graph;
typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
@@ -237,7 +252,7 @@
NS_LOG_DEBUG ("Node " << (*node)->GetId () << " does not export GlobalRouter interface");
continue;
}
-
+
DistancesMap distances;
dijkstra_shortest_paths (graph, source,
@@ -259,7 +274,7 @@
Ptr<Fib> fib = source->GetObject<Fib> ();
fib->InvalidateAll ();
NS_ASSERT (fib != 0);
-
+
NS_LOG_DEBUG ("Reachability from Node: " << source->GetObject<Node> ()->GetId ());
for (DistancesMap::iterator i = distances.begin ();
i != distances.end ();
@@ -281,10 +296,10 @@
NS_LOG_DEBUG (" prefix " << prefix << " reachable via face " << *i->second.get<0> ()
<< " with distance " << i->second.get<1> ()
<< " with delay " << i->second.get<2> ());
-
+
Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
-
+
Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
Ptr<Limits> fibLimits = entry->GetObject<Limits> ();
diff --git a/helper/ndn-global-routing-helper.h b/helper/ndn-global-routing-helper.h
index 17493d2..983c7b0 100644
--- a/helper/ndn-global-routing-helper.h
+++ b/helper/ndn-global-routing-helper.h
@@ -48,7 +48,7 @@
void
Install (Ptr<Node> node);
-
+
/**
* @brief Install GlobalRouter interface on nodes
*
@@ -80,7 +80,7 @@
*/
void
AddOrigins (const std::string &prefix, const NodeContainer &nodes);
-
+
/**
* @brief Add `prefix' as origin on node `nodeName'
* @param prefix Prefix that is originated by node, e.g., node is a producer for this prefix
@@ -90,6 +90,12 @@
AddOrigin (const std::string &prefix, const std::string &nodeName);
/**
+ * @brief Add origin to each node based on the node's name (using Names class)
+ */
+ void
+ AddOriginsForAll ();
+
+ /**
* @brief Calculate for every node shortest path trees and install routes to all prefix origins
*/
void
diff --git a/plugins/tracers-broken/tracers/ipv4-app-tracer.cc b/utils/tracers/ipv4-app-tracer.cc
similarity index 100%
rename from plugins/tracers-broken/tracers/ipv4-app-tracer.cc
rename to utils/tracers/ipv4-app-tracer.cc
diff --git a/plugins/tracers-broken/tracers/ipv4-app-tracer.h b/utils/tracers/ipv4-app-tracer.h
similarity index 100%
rename from plugins/tracers-broken/tracers/ipv4-app-tracer.h
rename to utils/tracers/ipv4-app-tracer.h
diff --git a/plugins/tracers-broken/tracers/ipv4-l3-tracer.cc b/utils/tracers/ipv4-l3-tracer.cc
similarity index 94%
rename from plugins/tracers-broken/tracers/ipv4-l3-tracer.cc
rename to utils/tracers/ipv4-l3-tracer.cc
index ed2cb9c..8e36d26 100644
--- a/plugins/tracers-broken/tracers/ipv4-l3-tracer.cc
+++ b/utils/tracers/ipv4-l3-tracer.cc
@@ -20,19 +20,16 @@
#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)
{
diff --git a/plugins/tracers-broken/tracers/ipv4-l3-tracer.h b/utils/tracers/ipv4-l3-tracer.h
similarity index 100%
rename from plugins/tracers-broken/tracers/ipv4-l3-tracer.h
rename to utils/tracers/ipv4-l3-tracer.h
diff --git a/plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.cc b/utils/tracers/ipv4-rate-l3-tracer.cc
similarity index 74%
rename from plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.cc
rename to utils/tracers/ipv4-rate-l3-tracer.cc
index e97ba18..280301d 100644
--- a/plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.cc
+++ b/utils/tracers/ipv4-rate-l3-tracer.cc
@@ -24,12 +24,54 @@
#include "ns3/config.h"
#include "ns3/callback.h"
#include "ns3/simulator.h"
+#include "ns3/node-list.h"
+#include "ns3/node.h"
+#include "ns3/log.h"
#include "ns3/ipv4-header.h"
+#include <boost/lexical_cast.hpp>
+
+using namespace boost;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("Ipv4RateL3Tracer");
+
namespace ns3 {
-
-Ipv4RateL3Tracer::Ipv4RateL3Tracer (std::ostream &os, Ptr<Node> node)
+
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
+Ipv4RateL3Tracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+{
+ std::list<Ptr<Ipv4RateL3Tracer> > tracers;
+ boost::shared_ptr<std::ofstream> outputStream (new std::ofstream ());
+ outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+
+ if (!outputStream->is_open ())
+ return boost::make_tuple (outputStream, tracers);
+
+ for (NodeList::Iterator node = NodeList::Begin ();
+ node != NodeList::End ();
+ node++)
+ {
+ NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+
+ Ptr<Ipv4RateL3Tracer> trace = Create<Ipv4RateL3Tracer> (outputStream, *node);
+ trace->SetAveragingPeriod (averagingPeriod);
+ tracers.push_back (trace);
+ }
+
+ if (tracers.size () > 0)
+ {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front ()->PrintHeader (*outputStream);
+ *outputStream << "\n";
+ }
+
+ return boost::make_tuple (outputStream, tracers);
+}
+
+
+Ipv4RateL3Tracer::Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
: Ipv4L3Tracer (node)
, m_os (os)
{
@@ -52,9 +94,9 @@
void
Ipv4RateL3Tracer::PeriodicPrinter ()
{
- Print (m_os);
+ Print (*m_os);
Reset ();
-
+
m_printEvent = Simulator::Schedule (m_period, &Ipv4RateL3Tracer::PeriodicPrinter, this);
}
diff --git a/plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.h b/utils/tracers/ipv4-rate-l3-tracer.h
similarity index 69%
rename from plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.h
rename to utils/tracers/ipv4-rate-l3-tracer.h
index 454ac14..e624c3d 100644
--- a/plugins/tracers-broken/tracers/ipv4-rate-l3-tracer.h
+++ b/utils/tracers/ipv4-rate-l3-tracer.h
@@ -27,6 +27,7 @@
#include "ns3/event-id.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/shared_ptr.hpp>
#include <map>
namespace ns3 {
@@ -41,12 +42,26 @@
/**
* @brief Network layer tracer constructor
*/
- Ipv4RateL3Tracer (std::ostream &os, Ptr<Node> node);
+ Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
virtual ~Ipv4RateL3Tracer ();
+ /**
+ * @brief Helper method to install tracers on all simulation nodes
+ *
+ * @param file File to which traces will be written
+ * @param averagingPeriod Defines averaging period for the rate calculation,
+ * as well as how often data will be written into the trace file (default, every half second)
+ *
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
+ *
+ */
+ static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
+ InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+
void
SetAveragingPeriod (const Time &period);
-
+
virtual void
PrintHeader (std::ostream &os) const;
@@ -68,12 +83,12 @@
private:
void
PeriodicPrinter ();
-
+
void
Reset ();
private:
- std::ostream& m_os;
+ boost::shared_ptr<std::ostream> m_os;
Time m_period;
EventId m_printEvent;
diff --git a/plugins/tracers-broken/tracers/ipv4-seqs-app-tracer.cc b/utils/tracers/ipv4-seqs-app-tracer.cc
similarity index 100%
rename from plugins/tracers-broken/tracers/ipv4-seqs-app-tracer.cc
rename to utils/tracers/ipv4-seqs-app-tracer.cc
diff --git a/plugins/tracers-broken/tracers/ipv4-seqs-app-tracer.h b/utils/tracers/ipv4-seqs-app-tracer.h
similarity index 97%
rename from plugins/tracers-broken/tracers/ipv4-seqs-app-tracer.h
rename to utils/tracers/ipv4-seqs-app-tracer.h
index 4805968..9ae24ac 100644
--- a/plugins/tracers-broken/tracers/ipv4-seqs-app-tracer.h
+++ b/utils/tracers/ipv4-seqs-app-tracer.h
@@ -21,7 +21,7 @@
#ifndef IPV4_SEQS_APP_TRACER_H
#define IPV4_SEQS_APP_TRACER_H
-#include "ns3/ipv4-app-tracer.h"
+#include "ipv4-app-tracer.h"
namespace ns3 {
@@ -40,7 +40,7 @@
virtual void
Rx (std::string context,
const Ipv4Header &, Ptr<const Packet>, uint32_t);
-
+
virtual void
Tx (std::string context,
const Ipv4Header &, Ptr<const Packet>, uint32_t);