blob: 64b695a5c6d64601fc156848f53f4c0cabdc5728 [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 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047class AppDelayTracer : public SimpleRefCount<AppDelayTracer> {
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080048public:
49 /**
50 * @brief Helper method to install tracers on all simulation nodes
51 *
Alexander Afanasyev5352af32013-07-15 09:51:28 -070052 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080053 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
55 *tuple needs to be preserved
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080056 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 *
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080058 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070059 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 InstallAll(const std::string& file);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080061
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 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
69 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070070 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
71 *
72 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070073 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 Install(const NodeContainer& nodes, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070075
76 /**
77 * @brief Helper method to install tracers on a specific simulation node
78 *
79 * @param nodes Nodes on which to install tracer
80 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 * @param averagingPeriod How often data will be written into the trace file (default, every half
82 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070083 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
85 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070086 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
87 *
88 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070089 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 Install(Ptr<Node> node, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070091
92 /**
93 * @brief Helper method to install tracers on a specific simulation node
94 *
95 * @param nodes Nodes on which to install tracer
96 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 * @param averagingPeriod How often data will be written into the trace file (default, every half
98 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070099 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
101 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700102 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
103 */
104 static Ptr<AppDelayTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -0700106
107 /**
108 * @brief Explicit request to remove all statically created tracers
109 *
110 * This method can be helpful if simulation scenario contains several independent run,
111 * or if it is desired to do a postprocessing of the resulting data
112 */
113 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 Destroy();
115
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700116 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800117 * @brief Trace constructor that attaches to all applications on the node using node's pointer
118 * @param os reference to the output stream
119 * @param node pointer to the node
120 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800121 AppDelayTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800122
123 /**
124 * @brief Trace constructor that attaches to all applications on the node using node's name
125 * @param os reference to the output stream
126 * @param nodeName name of the node registered using Names::Add
127 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 AppDelayTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800129
130 /**
131 * @brief Destructor
132 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800133 ~AppDelayTracer();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800134
135 /**
136 * @brief Print head of the trace (e.g., for post-processing)
137 *
138 * @param os reference to output stream
139 */
140 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 PrintHeader(std::ostream& os) const;
142
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800143private:
144 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 Connect();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800146
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 void
148 LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
149
150 void
151 FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount,
152 int32_t hopCount);
153
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800154private:
155 std::string m_node;
156 Ptr<Node> m_nodePtr;
157
158 boost::shared_ptr<std::ostream> m_os;
159};
160
161} // namespace ndn
162} // namespace ns3
163
164#endif // CCNX_CS_TRACER_H