blob: b9c110c39d6fb81765b7dce8fa8bba1d78b5027a [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
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080032#include <tuple>
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080033#include <list>
34
35namespace ns3 {
36
37class Node;
38class Packet;
39
40namespace ndn {
41
42class App;
43
44/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070045 * @ingroup ndn-tracers
46 * @brief Tracer to obtain application-level delays
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080047 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048class AppDelayTracer : public SimpleRefCount<AppDelayTracer> {
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080049public:
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 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
56 *tuple needs to be preserved
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080057 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 *
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080059 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070060 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 InstallAll(const std::string& file);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080062
63 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -070064 * @brief Helper method to install tracers on the selected simulation nodes
65 *
66 * @param nodes Nodes on which to install tracer
67 * @param file File to which traces will be written. If filename is -, then std::out is used
68 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
70 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070071 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
72 *
73 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070074 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 Install(const NodeContainer& nodes, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070076
77 /**
78 * @brief Helper method to install tracers on a specific simulation node
79 *
80 * @param nodes Nodes on which to install tracer
81 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 * @param averagingPeriod How often data will be written into the trace file (default, every half
83 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070084 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
86 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -070087 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
88 *
89 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070090 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 Install(Ptr<Node> node, const std::string& file);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070092
93 /**
94 * @brief Helper method to install tracers on a specific simulation node
95 *
96 * @param nodes Nodes on which to install tracer
97 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 * @param averagingPeriod How often data will be written into the trace file (default, every half
99 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700100 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
102 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700103 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
104 */
105 static Ptr<AppDelayTracer>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800106 Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream);
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -0700107
108 /**
109 * @brief Explicit request to remove all statically created tracers
110 *
111 * This method can be helpful if simulation scenario contains several independent run,
112 * or if it is desired to do a postprocessing of the resulting data
113 */
114 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 Destroy();
116
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700117 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800118 * @brief Trace constructor that attaches to all applications on the node using node's pointer
119 * @param os reference to the output stream
120 * @param node pointer to the node
121 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800122 AppDelayTracer(shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800123
124 /**
125 * @brief Trace constructor that attaches to all applications on the node using node's name
126 * @param os reference to the output stream
127 * @param nodeName name of the node registered using Names::Add
128 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800129 AppDelayTracer(shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800130
131 /**
132 * @brief Destructor
133 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 ~AppDelayTracer();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800135
136 /**
137 * @brief Print head of the trace (e.g., for post-processing)
138 *
139 * @param os reference to output stream
140 */
141 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142 PrintHeader(std::ostream& os) const;
143
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800144private:
145 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 Connect();
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800147
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800148 void
149 LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
150
151 void
152 FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount,
153 int32_t hopCount);
154
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800155private:
156 std::string m_node;
157 Ptr<Node> m_nodePtr;
158
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800159 shared_ptr<std::ostream> m_os;
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800160};
161
162} // namespace ndn
163} // namespace ns3
164
165#endif // CCNX_CS_TRACER_H