examples: Adding example for the experimental support of PIT aggregate stats
diff --git a/examples/ndn-simple-with-pit-operation-stats.cc b/examples/ndn-simple-with-pit-operation-stats.cc
new file mode 100644
index 0000000..26c3f8e
--- /dev/null
+++ b/examples/ndn-simple-with-pit-operation-stats.cc
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012-2013 University of California, Los Angeles
+ *
+ * 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>
+ */
+// ndn-simple-with-pit-operation-stats.cc
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+#include "ns3/ndnSIM/model/pit/ndn-pit-impl.h"
+#include "ns3/ndnSIM/utils/trie/persistent-policy.h"
+// #include "ns3/ndnSIM/utils/trie/random-policy.h"
+// #include "ns3/ndnSIM/utils/trie/lru-policy.h"
+#include "ns3/ndnSIM/utils/trie/multi-policy.h"
+#include "ns3/ndnSIM/utils/trie/aggregate-stats-policy.h"
+
+using namespace ns3;
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ * +----------+ 1Mbps +--------+ 1Mbps +----------+
+ * | consumer | <------------> | router | <------------> | producer |
+ * +----------+ 10ms +--------+ 10ms +----------+
+ *
+ *
+ * Consumer requests data from producer with frequency 10 interests per second
+ * (interests contain constantly increasing sequence number).
+ *
+ * For every received interest, producer replies with a data packet, containing
+ * 1024 bytes of virtual payload.
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ * ./waf --run=ndn-simple-with-pit-operation-stats
+ */
+
+typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::persistent_policy_traits,
+ ndn::ndnSIM::aggregate_stats_policy_traits > > PersistentWithCountsTraits;
+// typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::random_policy_traits,
+// ndn::ndnSIM::aggregate_stats_policy_traits > > RandomWithCountsTraits;
+// typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::lru_policy_traits,
+// ndn::ndnSIM::aggregate_stats_policy_traits > > LruWithCountsTraits;
+
+void
+PeriodicStatsPrinter (Ptr<Node> node, Time next)
+{
+ if (DynamicCast<ndn::pit::PitImpl<PersistentWithCountsTraits> > (node->GetObject<ndn::Pit> ()) == 0)
+ {
+ std::cerr << "Invalid PIT class, please correct the scenario" << std::endl;
+ return;
+ }
+
+ // "ns3::ndn::pit::Persistent::AggregateStats"
+ ndn::pit::PitImpl<PersistentWithCountsTraits>::super::policy_container &policy =
+ DynamicCast<ndn::pit::PitImpl<PersistentWithCountsTraits> > (node->GetObject<ndn::Pit> ())->GetPolicy ();
+
+ std::cout << Simulator::Now ().ToDouble (Time::S) << "\t"
+ << node->GetId () << "\t"
+ << policy.get<1> ().GetUpdates () << "\t"
+ << policy.get<1> ().GetInserts () << "\t"
+ << policy.get<1> ().GetLookups () << "\t"
+ << policy.get<1> ().GetErases () << "\n";
+
+ policy.get<1> ().ResetStats ();
+
+ Simulator::Schedule (next, PeriodicStatsPrinter, node, next);
+}
+
+int
+main (int argc, char *argv[])
+{
+ // setting default parameters for PointToPoint links and channels
+ Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
+ Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
+ Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
+
+ // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Creating nodes
+ NodeContainer nodes;
+ nodes.Create (3);
+
+ // Connecting nodes using two links
+ PointToPointHelper p2p;
+ p2p.Install (nodes.Get (0), nodes.Get (1));
+ p2p.Install (nodes.Get (1), nodes.Get (2));
+
+ // Install CCNx stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes (true);
+ ndnHelper.SetPit ("ns3::ndn::pit::Persistent::AggregateStats");
+ ndnHelper.InstallAll ();
+
+ // set up periodic PIT stats printer on node 1
+ std::cout << "Time" << "\t"
+ << "NodeId" << "\t"
+ << "Updates" << "\t"
+ << "Inserts" << "\t"
+ << "Lookups" << "\t"
+ << "Erases" << "\n";
+ Simulator::Schedule (Seconds (1), PeriodicStatsPrinter, nodes.Get (1), Seconds (1));
+
+ // Installing applications
+
+ // Consumer
+ ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+ // Consumer will request /prefix/0, /prefix/1, ...
+ consumerHelper.SetPrefix ("/prefix");
+ consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
+ consumerHelper.Install (nodes.Get (0)); // first node
+
+ // Producer
+ ndn::AppHelper producerHelper ("ns3::ndn::Producer");
+ // Producer will reply to all requests starting with /prefix
+ producerHelper.SetPrefix ("/prefix");
+ producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
+ producerHelper.Install (nodes.Get (2)); // last node
+
+ Simulator::Stop (Seconds (20.0));
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
diff --git a/examples/wscript b/examples/wscript
index 965eb25..f2879db 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -56,3 +56,6 @@
obj = bld.create_ns3_program('ndn-simple-with-pcap', ['ndnSIM'])
obj.source = 'ndn-simple-with-pcap.cc'
+
+ obj = bld.create_ns3_program('ndn-simple-with-pit-operation-stats', ['ndnSIM'])
+ obj.source = 'ndn-simple-with-pit-operation-stats.cc'
diff --git a/model/pit/ndn-pit-impl.h b/model/pit/ndn-pit-impl.h
index 024054a..26e3a6b 100644
--- a/model/pit/ndn-pit-impl.h
+++ b/model/pit/ndn-pit-impl.h
@@ -88,7 +88,7 @@
virtual Ptr<Entry>
Find (const Name &prefix);
-
+
virtual Ptr<Entry>
Create (Ptr<const Interest> header);
@@ -113,6 +113,9 @@
const typename super::policy_container &
GetPolicy () const { return super::getPolicy (); }
+ typename super::policy_container &
+ GetPolicy () { return super::getPolicy (); }
+
protected:
void RescheduleCleaning ();
void CleanExpired ();
@@ -137,7 +140,7 @@
Ptr<ForwardingStrategy> m_forwardingStrategy;
static LogComponent g_log; ///< @brief Logging variable
-
+
// indexes
typedef
boost::intrusive::multiset<entry,
diff --git a/utils/trie/aggregate-stats-policy.h b/utils/trie/aggregate-stats-policy.h
index c8d9dea..ce466dd 100644
--- a/utils/trie/aggregate-stats-policy.h
+++ b/utils/trie/aggregate-stats-policy.h
@@ -105,7 +105,7 @@
}
inline void
- resetStats ()
+ ResetStats ()
{
m_updates = 0;
m_inserts = 0;