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 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 32 | #include <tuple> |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 33 | #include <list> |
| 34 | |
| 35 | namespace ns3 { |
| 36 | |
| 37 | class Node; |
| 38 | class Packet; |
| 39 | |
| 40 | namespace ndn { |
| 41 | |
| 42 | class App; |
| 43 | |
| 44 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 45 | * @ingroup ndn-tracers |
| 46 | * @brief Tracer to obtain application-level delays |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 47 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 48 | class AppDelayTracer : public SimpleRefCount<AppDelayTracer> { |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 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 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 56 | *tuple needs to be preserved |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 57 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 58 | * |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 59 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 60 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | InstallAll(const std::string& file); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 64 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 70 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 71 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 72 | * |
| 73 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 74 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | Install(const NodeContainer& nodes, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 76 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 83 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 84 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 86 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 87 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 88 | * |
| 89 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 90 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | Install(Ptr<Node> node, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 92 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 99 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 100 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 102 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 103 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 104 | */ |
| 105 | static Ptr<AppDelayTracer> |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 106 | Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 107 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | Destroy(); |
| 116 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 117 | /** |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 118 | * @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 Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 122 | AppDelayTracer(shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 123 | |
| 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 Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 129 | AppDelayTracer(shared_ptr<std::ostream> os, const std::string& node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * @brief Destructor |
| 133 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | ~AppDelayTracer(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 135 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 142 | PrintHeader(std::ostream& os) const; |
| 143 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 144 | private: |
| 145 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 146 | Connect(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 147 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 148 | 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 Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 155 | private: |
| 156 | std::string m_node; |
| 157 | Ptr<Node> m_nodePtr; |
| 158 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 159 | shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // namespace ndn |
| 163 | } // namespace ns3 |
| 164 | |
| 165 | #endif // CCNX_CS_TRACER_H |