Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 19 | |
| 20 | #ifndef CCNX_APP_DELAY_TRACER_H |
| 21 | #define CCNX_APP_DELAY_TRACER_H |
| 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 24 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 25 | #include "ns3/ptr.h" |
| 26 | #include "ns3/simple-ref-count.h" |
| 27 | #include <ns3/nstime.h> |
| 28 | #include <ns3/event-id.h> |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 29 | #include <ns3/node-container.h> |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 30 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 31 | #include <tuple> |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | class AppDelayTracer : public SimpleRefCount<AppDelayTracer> { |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 48 | public: |
| 49 | /** |
| 50 | * @brief Helper method to install tracers on all simulation nodes |
| 51 | * |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 52 | * @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] | 53 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 55 | *tuple needs to be preserved |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 56 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | * |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 58 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 59 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | InstallAll(const std::string& file); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 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 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 69 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 70 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 71 | * |
| 72 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 73 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | Install(const NodeContainer& nodes, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * @brief Helper method to install tracers on a specific simulation node |
| 78 | * |
| 79 | * @param nodes Nodes on which to install tracer |
| 80 | * @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] | 81 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 82 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 83 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 85 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 86 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 87 | * |
| 88 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 89 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | Install(Ptr<Node> node, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * @brief Helper method to install tracers on a specific simulation node |
| 94 | * |
| 95 | * @param nodes Nodes on which to install tracer |
| 96 | * @param outputStream Smart pointer to a stream |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 97 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 98 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 99 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 101 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 102 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 103 | */ |
| 104 | static Ptr<AppDelayTracer> |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 105 | Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * @brief Explicit request to remove all statically created tracers |
| 109 | * |
| 110 | * This method can be helpful if simulation scenario contains several independent run, |
| 111 | * or if it is desired to do a postprocessing of the resulting data |
| 112 | */ |
| 113 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 114 | Destroy(); |
| 115 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 116 | /** |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 117 | * @brief Trace constructor that attaches to all applications on the node using node's pointer |
| 118 | * @param os reference to the output stream |
| 119 | * @param node pointer to the node |
| 120 | */ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 121 | AppDelayTracer(shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * @brief Trace constructor that attaches to all applications on the node using node's name |
| 125 | * @param os reference to the output stream |
| 126 | * @param nodeName name of the node registered using Names::Add |
| 127 | */ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 128 | AppDelayTracer(shared_ptr<std::ostream> os, const std::string& node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * @brief Destructor |
| 132 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 133 | ~AppDelayTracer(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * @brief Print head of the trace (e.g., for post-processing) |
| 137 | * |
| 138 | * @param os reference to output stream |
| 139 | */ |
| 140 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 141 | PrintHeader(std::ostream& os) const; |
| 142 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 143 | private: |
| 144 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | Connect(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 146 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 147 | void |
| 148 | LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount); |
| 149 | |
| 150 | void |
| 151 | FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, |
| 152 | int32_t hopCount); |
| 153 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 154 | private: |
| 155 | std::string m_node; |
| 156 | Ptr<Node> m_nodePtr; |
| 157 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 158 | shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | } // namespace ndn |
| 162 | } // namespace ns3 |
| 163 | |
| 164 | #endif // CCNX_CS_TRACER_H |