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 | |
| 24 | #include "ns3/ptr.h" |
| 25 | #include "ns3/simple-ref-count.h" |
| 26 | #include <ns3/nstime.h> |
| 27 | #include <ns3/event-id.h> |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 28 | #include <ns3/node-container.h> |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 29 | |
| 30 | #include <boost/tuple/tuple.hpp> |
| 31 | #include <boost/shared_ptr.hpp> |
| 32 | #include <list> |
| 33 | |
| 34 | namespace ns3 { |
| 35 | |
| 36 | class Node; |
| 37 | class Packet; |
| 38 | |
| 39 | namespace ndn { |
| 40 | |
| 41 | class App; |
| 42 | |
| 43 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 44 | * @ingroup ndn-tracers |
| 45 | * @brief Tracer to obtain application-level delays |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 46 | */ |
| 47 | class AppDelayTracer : public SimpleRefCount<AppDelayTracer> |
| 48 | { |
| 49 | public: |
| 50 | /** |
| 51 | * @brief Helper method to install tracers on all simulation nodes |
| 52 | * |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 53 | * @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] | 54 | * |
| 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 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 59 | static void |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 60 | InstallAll (const std::string &file); |
| 61 | |
| 62 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 63 | * @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 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 72 | static void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 86 | static void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 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); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * @brief Explicit request to remove all statically created tracers |
| 104 | * |
| 105 | * This method can be helpful if simulation scenario contains several independent run, |
| 106 | * or if it is desired to do a postprocessing of the resulting data |
| 107 | */ |
| 108 | static void |
| 109 | Destroy (); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 112 | * @brief Trace constructor that attaches to all applications on the node using node's pointer |
| 113 | * @param os reference to the output stream |
| 114 | * @param node pointer to the node |
| 115 | */ |
| 116 | AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
| 117 | |
| 118 | /** |
| 119 | * @brief Trace constructor that attaches to all applications on the node using node's name |
| 120 | * @param os reference to the output stream |
| 121 | * @param nodeName name of the node registered using Names::Add |
| 122 | */ |
| 123 | AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node); |
| 124 | |
| 125 | /** |
| 126 | * @brief Destructor |
| 127 | */ |
| 128 | ~AppDelayTracer (); |
| 129 | |
| 130 | /** |
| 131 | * @brief Print head of the trace (e.g., for post-processing) |
| 132 | * |
| 133 | * @param os reference to output stream |
| 134 | */ |
| 135 | void |
| 136 | PrintHeader (std::ostream &os) const; |
| 137 | |
| 138 | private: |
| 139 | void |
| 140 | Connect (); |
| 141 | |
| 142 | void |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 143 | LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 144 | |
| 145 | void |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 146 | FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, int32_t hopCount); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 147 | |
| 148 | private: |
| 149 | std::string m_node; |
| 150 | Ptr<Node> m_nodePtr; |
| 151 | |
| 152 | boost::shared_ptr<std::ostream> m_os; |
| 153 | }; |
| 154 | |
| 155 | } // namespace ndn |
| 156 | } // namespace ns3 |
| 157 | |
| 158 | #endif // CCNX_CS_TRACER_H |