blob: 3893d33651d7b2b25728ebdbc5aa01fc06b91d14 [file] [log] [blame]
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#include "ndn-app-delay-tracer.h"
22#include "ns3/node.h"
23#include "ns3/packet.h"
24#include "ns3/config.h"
25#include "ns3/names.h"
26#include "ns3/callback.h"
27
28#include "ns3/ndn-app.h"
29#include "ns3/ndn-interest.h"
30#include "ns3/ndn-content-object.h"
31#include "ns3/simulator.h"
32#include "ns3/node-list.h"
33#include "ns3/log.h"
34
35#include <boost/lexical_cast.hpp>
36#include <boost/make_shared.hpp>
37
38#include <fstream>
39
40NS_LOG_COMPONENT_DEFINE ("ndn.AppDelayTracer");
41
42using namespace std;
43
44namespace ns3 {
45namespace ndn {
46
47
48boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > >
49AppDelayTracer::InstallAll (const std::string &file)
50{
51 using namespace boost;
52 using namespace std;
53
54 std::list<Ptr<AppDelayTracer> > tracers;
55 boost::shared_ptr<std::ofstream> outputStream = make_shared<std::ofstream> ();
56
57 outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
58 if (!outputStream->is_open ())
59 return boost::make_tuple (outputStream, tracers);
60
61 for (NodeList::Iterator node = NodeList::Begin ();
62 node != NodeList::End ();
63 node++)
64 {
65 NS_LOG_DEBUG ("Node: " << (*node)->GetId ());
66
67 Ptr<AppDelayTracer> trace = Create<AppDelayTracer> (outputStream, *node);
68 tracers.push_back (trace);
69 }
70
71 if (tracers.size () > 0)
72 {
73 // *m_l3RateTrace << "# "; // not necessary for R's read.table
74 tracers.front ()->PrintHeader (*outputStream);
75 *outputStream << "\n";
76 }
77
78 return boost::make_tuple (outputStream, tracers);
79}
80
81//////////////////////////////////////////////////////////////////////////////
82//////////////////////////////////////////////////////////////////////////////
83//////////////////////////////////////////////////////////////////////////////
84
85AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
86: m_nodePtr (node)
87, m_os (os)
88{
89 m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
90
91 Connect ();
92
93 string name = Names::FindName (node);
94 if (!name.empty ())
95 {
96 m_node = name;
97 }
98}
99
100AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
101: m_node (node)
102, m_os (os)
103{
104 Connect ();
105}
106
107AppDelayTracer::~AppDelayTracer ()
108{
109};
110
111
112void
113AppDelayTracer::Connect ()
114{
115 Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/LastRetransmittedInterestDataDelay",
116 MakeCallback (&AppDelayTracer::LastRetransmittedInterestDataDelay, this));
117
Alexander Afanasyevb9faa442013-01-18 19:53:43 -0800118 Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/FirstInterestDataDelay",
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800119 MakeCallback (&AppDelayTracer::FirstInterestDataDelay, this));
120}
121
122void
123AppDelayTracer::PrintHeader (std::ostream &os) const
124{
125 os << "Node" << "\t"
126 << "AppId" << "\t"
127 << "SeqNo" << "\t"
128
129 << "Type" << "\t"
130 << "DelayS" << "\t"
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800131 << "DelayUS" << "\t"
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800132 << "RetxCount" << "\t"
133 << "HopCount" << "";
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800134}
135
136void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800137AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount)
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800138{
139 *m_os << m_node << "\t"
140 << app->GetId () << "\t"
141 << seqno << "\t"
142 << "LastDelay" << "\t"
143 << delay.ToDouble (Time::S) << "\t"
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800144 << delay.ToDouble (Time::US) << "\t"
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800145 << 1 << "\t"
146 << hopCount << "\n";
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800147}
148
149void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800150AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount)
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800151{
152 *m_os << m_node << "\t"
153 << app->GetId () << "\t"
154 << seqno << "\t"
155 << "FullDelay" << "\t"
156 << delay.ToDouble (Time::S) << "\t"
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800157 << delay.ToDouble (Time::US) << "\t"
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800158 << retxCount << "\t"
159 << hopCount << "\n";
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800160}
161
162
163} // namespace ndn
164} // namespace ns3