blob: d58f517363cb67d3750596fc486b3544d3f05a3b [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 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>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800105 Install(Ptr<Node> node, 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 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800121 AppDelayTracer(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 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800128 AppDelayTracer(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
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800158 shared_ptr<std::ostream> m_os;
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800159};
160
161} // namespace ndn
162} // namespace ns3
163
164#endif // CCNX_CS_TRACER_H