tracers+docs: Correcting compilation and installation of trace helpers
Also in this commit an example on how to use trace helpers, including
how to build graphs using R.
diff --git a/examples/graphs/rate-graph.R b/examples/graphs/rate-graph.R
new file mode 100755
index 0000000..6d63298
--- /dev/null
+++ b/examples/graphs/rate-graph.R
@@ -0,0 +1,88 @@
+# Copyright (c) 2012 Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+
+# install.packages ('ggplot2')
+library (ggplot2)
+# install.packages ('scales')
+library (scales)
+
+# install.packages ('doBy')
+library (doBy)
+
+#########################
+# Rate trace processing #
+#########################
+data = read.table ("rate-trace.txt", header=T)
+data$Node = factor (data$Node)
+data$FaceId <- factor(data$FaceId)
+data$Kilobits <- data$Kilobytes * 8
+data$Type = factor (data$Type)
+
+# exlude irrelevant types
+data = subset (data, Type %in% c("InInterests", "OutInterests", "InData", "OutData"))
+
+# combine stats from all faces
+data.combined = summaryBy (. ~ Time + Node + Type, data=data, FUN=sum)
+
+data.root = subset (data.combined, Node == "root")
+data.leaves = subset (data.combined, Node %in% c("leaf-1", "leaf-2", "leaf-3", "leaf-4"))
+
+# graph rates on all nodes in Kilobits
+g.all <- ggplot (data.combined) +
+ geom_point (aes (x=Time, y=Kilobits.sum, color=Type), size=1) +
+ ylab ("Rate [Kbits/s]") +
+ facet_wrap (~ Node)
+
+print (g.all)
+
+# graph rates on the root nodes in Packets
+g.root <- ggplot (data.root) +
+ geom_point (aes (x=Time, y=Kilobits.sum, color=Type), size=2) +
+ geom_line (aes (x=Time, y=Kilobits.sum, color=Type), size=0.5) +
+ ylab ("Rate [Kbits/s]")
+
+print (g.root)
+
+png ("root-rates.png", width=500, height=250)
+print (g.root)
+dev.off ()
+
+###############################
+# Aggreagate trace processing #
+###############################
+
+data = read.table ("aggregate-trace.txt", header=T)
+data$Node = factor (data$Node)
+data$FaceId <- factor(data$FaceId)
+data$Type = factor (data$Type)
+
+# exlude irrelevant types
+data = subset (data, Type %in% c("InInterests", "OutInterests", "InData", "OutData"))
+
+# Aggregate packet stats in 5-second intervals
+data$Time5Sec = 5 * ceiling (data$Time / 5)
+data.combined = summaryBy (. ~ Time5Sec + Node + Type, data=data, FUN=sum)
+
+data.root = subset (data.combined, Node == "root")
+data.leaves = subset (data.combined, Node %in% c("leaf-1", "leaf-2", "leaf-3", "leaf-4"))
+
+# graph rates on all nodes in Packets
+g.all <- ggplot (data.combined) +
+ geom_point (aes (x=Time5Sec, y=Packets.sum, color=Type), size=2) +
+ geom_line (aes (x=Time5Sec, y=Packets.sum, color=Type), size=0.5) +
+ ylab ("Number of transitted packets in 5 secon intervals") +
+ facet_wrap (~ Node)
+
+print (g.all)
+
+# graph rates on the root nodes in Packets
+g.root <- ggplot (data.root) +
+ geom_point (aes (x=Time5Sec, y=Packets.sum, color=Type), size=2) +
+ geom_line (aes (x=Time5Sec, y=Packets.sum, color=Type), size=0.5) +
+ ylab ("Number of transitted packets in 5 secon intervals") +
+ ylim (c(0,2000))
+
+print (g.root)
+
+png ("root-5sec-counts.png", width=500, height=250)
+print (g.root)
+dev.off ()
diff --git a/examples/ndn-tree-tracers.cc b/examples/ndn-tree-tracers.cc
new file mode 100644
index 0000000..b76869a
--- /dev/null
+++ b/examples/ndn-tree-tracers.cc
@@ -0,0 +1,125 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011-2012 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-tree-tracers.cc
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+// for ndn::L3AggregateTracer
+#include <ns3/ndnSIM/utils/tracers/ndn-l3-aggregate-tracer.h>
+
+// for ndn::L3RateTracer
+#include <ns3/ndnSIM/utils/tracers/ndn-l3-rate-tracer.h>
+
+using namespace ns3;
+
+/**
+ * This scenario simulates a tree topology (using topology reader module)
+ *
+ * /------\ /------\ /------\ /------\
+ * |leaf-1| |leaf-2| |leaf-3| |leaf-4|
+ * \------/ \------/ \------/ \------/
+ * ^ ^ ^ ^
+ * | | | |
+ * \ / \ /
+ * \ / \ / 10Mbps / 1ms
+ * \ / \ /
+ * | | | |
+ * v v v v
+ * /-------\ /-------\
+ * | rtr-1 | | rtr-2 |
+ * \-------/ \-------/
+ * ^ ^
+ * | |
+ * \ / 10 Mpbs / 1ms
+ * +--------+ +--------+
+ * | |
+ * v v
+ * /--------\
+ * | root |
+ * \--------/
+ *
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ * ./waf --run=ndn-tree-tracers
+ */
+
+int
+main (int argc, char *argv[])
+{
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ AnnotatedTopologyReader topologyReader ("", 1);
+ topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-tree.txt");
+ topologyReader.Read ();
+
+ // Install CCNx stack on all nodes
+ ndn::StackHelper ccnxHelper;
+ ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
+ ccnxHelper.InstallAll ();
+
+ // Installing global routing interface on all nodes
+ ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
+ ccnxGlobalRoutingHelper.InstallAll ();
+
+ // Getting containers for the consumer/producer
+ Ptr<Node> consumers[4] = { Names::Find<Node> ("leaf-1"), Names::Find<Node> ("leaf-2"),
+ Names::Find<Node> ("leaf-3"), Names::Find<Node> ("leaf-4") };
+ Ptr<Node> producer = Names::Find<Node> ("root");
+
+ for (int i = 0; i < 4; i++)
+ {
+ ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 100 interests a second
+
+ // Each consumer will express unique interests /root/<leaf-name>/<seq-no>
+ consumerHelper.SetPrefix ("/root/" + Names::FindName (consumers[i]));
+ consumerHelper.Install (consumers[i]);
+ }
+
+ ndn::AppHelper producerHelper ("ns3::ndn::Producer");
+ producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
+
+ // Register /root prefix with global routing controller and
+ // install producer that will satisfy Interests in /root namespace
+ ccnxGlobalRoutingHelper.AddOrigins ("/root", producer);
+ producerHelper.SetPrefix ("/root");
+ producerHelper.Install (producer);
+
+ // Calculate and install FIBs
+ ccnxGlobalRoutingHelper.CalculateRoutes ();
+
+ Simulator::Stop (Seconds (20.0));
+
+ boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::L3AggregateTracer> > >
+ aggTracers = ndn::L3AggregateTracer::InstallAll ("aggregate-trace.txt", Seconds (0.5));
+
+ boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::L3RateTracer> > >
+ rateTracers = ndn::L3RateTracer::InstallAll ("rate-trace.txt", Seconds (0.5));
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
diff --git a/examples/wscript b/examples/wscript
index 5c478a7..67cf5ca 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -19,3 +19,6 @@
'custom-strategies/custom-strategy.cc',
'ndn-congestion-alt-topo-plugin.cc'
]
+
+ obj = bld.create_ns3_program('ndn-tree-tracers', ['ndnSIM'])
+ obj.source = 'ndn-tree-tracers.cc'