blob: d911fc993a6b28c097a4767e3abce4bf911b0ca4 [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#ifndef CCNX_APP_DELAY_TRACER_H
22#define CCNX_APP_DELAY_TRACER_H
23
24#include "ns3/ptr.h"
25#include "ns3/simple-ref-count.h"
26#include <ns3/nstime.h>
27#include <ns3/event-id.h>
Alexander Afanasyev5352af32013-07-15 09:51:28 -070028#include <ns3/node-container.h>
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080029
30#include <boost/tuple/tuple.hpp>
31#include <boost/shared_ptr.hpp>
32#include <list>
33
34namespace ns3 {
35
36class Node;
37class Packet;
38
39namespace ndn {
40
41class App;
42
43/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070044 * @ingroup ndn-tracers
45 * @brief Tracer to obtain application-level delays
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080046 */
47class AppDelayTracer : public SimpleRefCount<AppDelayTracer>
48{
49public:
50 /**
51 * @brief Helper method to install tracers on all simulation nodes
52 *
Alexander Afanasyev5352af32013-07-15 09:51:28 -070053 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080054 *
55 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
56 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
57 *
58 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070059 static void
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080060 InstallAll (const std::string &file);
61
62 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -070063 * @brief Helper method to install tracers on the selected simulation nodes
64 *
65 * @param nodes Nodes on which to install tracer
66 * @param file File to which traces will be written. If filename is -, then std::out is used
67 *
68 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
69 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
70 *
71 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070072 static void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070073 Install (const NodeContainer &nodes, const std::string &file);
74
75 /**
76 * @brief Helper method to install tracers on a specific simulation node
77 *
78 * @param nodes Nodes on which to install tracer
79 * @param file File to which traces will be written. If filename is -, then std::out is used
80 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
81 *
82 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
83 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
84 *
85 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070086 static void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070087 Install (Ptr<Node> node, const std::string &file);
88
89 /**
90 * @brief Helper method to install tracers on a specific simulation node
91 *
92 * @param nodes Nodes on which to install tracer
93 * @param outputStream Smart pointer to a stream
94 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
95 *
96 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
97 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
98 */
99 static Ptr<AppDelayTracer>
100 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -0700101
102 /**
103 * @brief Explicit request to remove all statically created tracers
104 *
105 * This method can be helpful if simulation scenario contains several independent run,
106 * or if it is desired to do a postprocessing of the resulting data
107 */
108 static void
109 Destroy ();
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700110
111 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800112 * @brief Trace constructor that attaches to all applications on the node using node's pointer
113 * @param os reference to the output stream
114 * @param node pointer to the node
115 */
116 AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
117
118 /**
119 * @brief Trace constructor that attaches to all applications on the node using node's name
120 * @param os reference to the output stream
121 * @param nodeName name of the node registered using Names::Add
122 */
123 AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
124
125 /**
126 * @brief Destructor
127 */
128 ~AppDelayTracer ();
129
130 /**
131 * @brief Print head of the trace (e.g., for post-processing)
132 *
133 * @param os reference to output stream
134 */
135 void
136 PrintHeader (std::ostream &os) const;
137
138private:
139 void
140 Connect ();
141
142 void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800143 LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800144
145 void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800146 FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, int32_t hopCount);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800147
148private:
149 std::string m_node;
150 Ptr<Node> m_nodePtr;
151
152 boost::shared_ptr<std::ostream> m_os;
153};
154
155} // namespace ndn
156} // namespace ns3
157
158#endif // CCNX_CS_TRACER_H