Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 1 | /* -*- 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 Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 25 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/simple-ref-count.h" |
| 28 | #include <ns3/nstime.h> |
| 29 | #include <ns3/event-id.h> |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 30 | #include <ns3/node-container.h> |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 31 | |
| 32 | #include <boost/tuple/tuple.hpp> |
| 33 | #include <boost/shared_ptr.hpp> |
| 34 | #include <list> |
| 35 | |
| 36 | namespace ns3 { |
| 37 | |
| 38 | class Node; |
| 39 | class Packet; |
| 40 | |
| 41 | namespace ndn { |
| 42 | |
| 43 | class App; |
| 44 | |
| 45 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 46 | * @ingroup ndn-tracers |
| 47 | * @brief Tracer to obtain application-level delays |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 48 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | class AppDelayTracer : public SimpleRefCount<AppDelayTracer> { |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 50 | public: |
| 51 | /** |
| 52 | * @brief Helper method to install tracers on all simulation nodes |
| 53 | * |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 54 | * @param file File to which traces will be written. If filename is -, then std::out is used |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 55 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 57 | *tuple needs to be preserved |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 58 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | * |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 60 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 61 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | InstallAll(const std::string& file); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 65 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 71 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 72 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 73 | * |
| 74 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 75 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | Install(const NodeContainer& nodes, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 77 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 84 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 85 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 87 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 88 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 89 | * |
| 90 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 91 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | Install(Ptr<Node> node, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 93 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 99 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 100 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 101 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 103 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 104 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 105 | */ |
| 106 | static Ptr<AppDelayTracer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 108 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 116 | Destroy(); |
| 117 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 118 | /** |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 119 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | AppDelayTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 124 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 130 | AppDelayTracer(boost::shared_ptr<std::ostream> os, const std::string& node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * @brief Destructor |
| 134 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 135 | ~AppDelayTracer(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 136 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 143 | PrintHeader(std::ostream& os) const; |
| 144 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 145 | private: |
| 146 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 147 | Connect(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 148 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | 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 Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 156 | private: |
| 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 |