blob: 7312225b46edb249979aa76b8de2e0276e01fd33 [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/**
44 * @ingroup ndn
45 * @brief network-layer tracer for aggregate packet counts
46 */
47class AppDelayTracer : public SimpleRefCount<AppDelayTracer>
48{
49public:
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 *
55 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
56 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
57 *
58 */
59 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > >
60 InstallAll (const std::string &file);
61
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 *
68 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
69 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
70 *
71 */
72 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > >
73 Install (const NodeContainer &nodes, const std::string &file);
74
75 /**
76 * @brief Helper method to install tracers on a specific simulation node
77 *
78 * @param nodes Nodes on which to install tracer
79 * @param file File to which traces will be written. If filename is -, then std::out is used
80 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
81 *
82 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
83 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
84 *
85 */
86 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > >
87 Install (Ptr<Node> node, const std::string &file);
88
89 /**
90 * @brief Helper method to install tracers on a specific simulation node
91 *
92 * @param nodes Nodes on which to install tracer
93 * @param outputStream Smart pointer to a stream
94 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
95 *
96 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
97 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
98 */
99 static Ptr<AppDelayTracer>
100 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
101
102 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800103 * @brief Trace constructor that attaches to all applications on the node using node's pointer
104 * @param os reference to the output stream
105 * @param node pointer to the node
106 */
107 AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
108
109 /**
110 * @brief Trace constructor that attaches to all applications on the node using node's name
111 * @param os reference to the output stream
112 * @param nodeName name of the node registered using Names::Add
113 */
114 AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
115
116 /**
117 * @brief Destructor
118 */
119 ~AppDelayTracer ();
120
121 /**
122 * @brief Print head of the trace (e.g., for post-processing)
123 *
124 * @param os reference to output stream
125 */
126 void
127 PrintHeader (std::ostream &os) const;
128
129private:
130 void
131 Connect ();
132
133 void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800134 LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800135
136 void
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800137 FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, int32_t hopCount);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800138
139private:
140 std::string m_node;
141 Ptr<Node> m_nodePtr;
142
143 boost::shared_ptr<std::ostream> m_os;
144};
145
146} // namespace ndn
147} // namespace ns3
148
149#endif // CCNX_CS_TRACER_H