blob: 6e02f93492191fa3659a6ac0458a3e3f4007cd9d [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080019
20#ifndef CCNX_APP_DELAY_TRACER_H
21#define CCNX_APP_DELAY_TRACER_H
22
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080025#include "ns3/ptr.h"
26#include "ns3/simple-ref-count.h"
27#include <ns3/nstime.h>
28#include <ns3/event-id.h>
Alexander Afanasyev5352af32013-07-15 09:51:28 -070029#include <ns3/node-container.h>
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080030
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080031#include <tuple>
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080032#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 Afanasyevdb64ff12013-01-18 16:37:31 -080054 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070055 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 InstallAll(const std::string& file);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080057
58 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -070059 * @brief Helper method to install tracers on the selected simulation nodes
60 *
61 * @param nodes Nodes on which to install tracer
62 * @param file File to which traces will be written. If filename is -, then std::out is used
63 *
Alexander Afanasyev5352af32013-07-15 09:51:28 -070064 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070065 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 Install(const NodeContainer& nodes, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070067
68 /**
69 * @brief Helper method to install tracers on a specific simulation node
70 *
71 * @param nodes Nodes on which to install tracer
72 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 * @param averagingPeriod How often data will be written into the trace file (default, every half
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -070074 * second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070075 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070076 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 Install(Ptr<Node> node, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070078
79 /**
80 * @brief Helper method to install tracers on a specific simulation node
81 *
82 * @param nodes Nodes on which to install tracer
83 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 * @param averagingPeriod How often data will be written into the trace file (default, every half
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -070085 * second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070086 *
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -070087 * @returns a tuple of reference to output stream and list of tracers.
88 * !!! Attention !!! This tuple needs to be preserved for the lifetime of simulation,
89 * otherwise SEGFAULTs are inevitable
Alexander Afanasyev5352af32013-07-15 09:51:28 -070090 */
91 static Ptr<AppDelayTracer>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080092 Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream);
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070093
94 /**
95 * @brief Explicit request to remove all statically created tracers
96 *
97 * This method can be helpful if simulation scenario contains several independent run,
98 * or if it is desired to do a postprocessing of the resulting data
99 */
100 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 Destroy();
102
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700103 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800104 * @brief Trace constructor that attaches to all applications on the node using node's pointer
105 * @param os reference to the output stream
106 * @param node pointer to the node
107 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800108 AppDelayTracer(shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800109
110 /**
111 * @brief Trace constructor that attaches to all applications on the node using node's name
112 * @param os reference to the output stream
113 * @param nodeName name of the node registered using Names::Add
114 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800115 AppDelayTracer(shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800116
117 /**
118 * @brief Destructor
119 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 ~AppDelayTracer();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800121
122 /**
123 * @brief Print head of the trace (e.g., for post-processing)
124 *
125 * @param os reference to output stream
126 */
127 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 PrintHeader(std::ostream& os) const;
129
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800130private:
131 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 Connect();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800133
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 void
135 LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
136
137 void
138 FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount,
139 int32_t hopCount);
140
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800141private:
142 std::string m_node;
143 Ptr<Node> m_nodePtr;
144
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800145 shared_ptr<std::ostream> m_os;
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800146};
147
148} // namespace ndn
149} // namespace ns3
150
151#endif // CCNX_CS_TRACER_H