blob: 72cccec676df61a611ce3b9cb82b97cb668333e3 [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080026#include "ns3/ptr.h"
27#include "ns3/simple-ref-count.h"
28#include <ns3/nstime.h>
29#include <ns3/event-id.h>
Alexander Afanasyev5352af32013-07-15 09:51:28 -070030#include <ns3/node-container.h>
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080031
32#include <boost/tuple/tuple.hpp>
33#include <boost/shared_ptr.hpp>
34#include <list>
35
36namespace ns3 {
37
38class Node;
39class Packet;
40
41namespace ndn {
42
43class App;
44
45/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070046 * @ingroup ndn-tracers
47 * @brief Tracer to obtain application-level delays
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080048 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049class AppDelayTracer : public SimpleRefCount<AppDelayTracer> {
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080050public:
51 /**
52 * @brief Helper method to install tracers on all simulation nodes
53 *
Alexander Afanasyev5352af32013-07-15 09:51:28 -070054 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080055 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
57 *tuple needs to be preserved
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080058 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 *
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080060 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070061 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 InstallAll(const std::string& file);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080063
64 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -070065 * @brief Helper method to install tracers on the selected simulation nodes
66 *
67 * @param nodes Nodes on which to install tracer
68 * @param file File to which traces will be written. If filename is -, then std::out is used
69 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
71 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070072 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
73 *
74 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070075 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 Install(const NodeContainer& nodes, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070077
78 /**
79 * @brief Helper method to install tracers on a specific simulation node
80 *
81 * @param nodes Nodes on which to install tracer
82 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 * @param averagingPeriod How often data will be written into the trace file (default, every half
84 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070085 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
87 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070088 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
89 *
90 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070091 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 Install(Ptr<Node> node, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070093
94 /**
95 * @brief Helper method to install tracers on a specific simulation node
96 *
97 * @param nodes Nodes on which to install tracer
98 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 * @param averagingPeriod How often data will be written into the trace file (default, every half
100 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700101 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
103 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700104 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
105 */
106 static Ptr<AppDelayTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -0700108
109 /**
110 * @brief Explicit request to remove all statically created tracers
111 *
112 * This method can be helpful if simulation scenario contains several independent run,
113 * or if it is desired to do a postprocessing of the resulting data
114 */
115 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 Destroy();
117
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700118 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800119 * @brief Trace constructor that attaches to all applications on the node using node's pointer
120 * @param os reference to the output stream
121 * @param node pointer to the node
122 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 AppDelayTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800124
125 /**
126 * @brief Trace constructor that attaches to all applications on the node using node's name
127 * @param os reference to the output stream
128 * @param nodeName name of the node registered using Names::Add
129 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 AppDelayTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800131
132 /**
133 * @brief Destructor
134 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 ~AppDelayTracer();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800136
137 /**
138 * @brief Print head of the trace (e.g., for post-processing)
139 *
140 * @param os reference to output stream
141 */
142 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800143 PrintHeader(std::ostream& os) const;
144
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800145private:
146 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 Connect();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800148
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 void
150 LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
151
152 void
153 FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount,
154 int32_t hopCount);
155
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800156private:
157 std::string m_node;
158 Ptr<Node> m_nodePtr;
159
160 boost::shared_ptr<std::ostream> m_os;
161};
162
163} // namespace ndn
164} // namespace ns3
165
166#endif // CCNX_CS_TRACER_H