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 | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 54 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 55 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | InstallAll(const std::string& file); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 59 | * @brief Helper method to install tracers on the selected simulation nodes |
| 60 | * |
| 61 | * @param nodes Nodes on which to install tracer |
| 62 | * @param file File to which traces will be written. If filename is -, then std::out is used |
| 63 | * |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 64 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 65 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | Install(const NodeContainer& nodes, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * @brief Helper method to install tracers on a specific simulation node |
| 70 | * |
| 71 | * @param nodes Nodes on which to install tracer |
| 72 | * @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] | 73 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 74 | * second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 75 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 76 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | Install(Ptr<Node> node, const std::string& file); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * @brief Helper method to install tracers on a specific simulation node |
| 81 | * |
| 82 | * @param nodes Nodes on which to install tracer |
| 83 | * @param outputStream Smart pointer to a stream |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 85 | * second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 86 | * |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 87 | * @returns a tuple of reference to output stream and list of tracers. |
| 88 | * !!! Attention !!! This tuple needs to be preserved for the lifetime of simulation, |
| 89 | * otherwise SEGFAULTs are inevitable |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 90 | */ |
| 91 | static Ptr<AppDelayTracer> |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 92 | Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * @brief Explicit request to remove all statically created tracers |
| 96 | * |
| 97 | * This method can be helpful if simulation scenario contains several independent run, |
| 98 | * or if it is desired to do a postprocessing of the resulting data |
| 99 | */ |
| 100 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | Destroy(); |
| 102 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 103 | /** |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 104 | * @brief Trace constructor that attaches to all applications on the node using node's pointer |
| 105 | * @param os reference to the output stream |
| 106 | * @param node pointer to the node |
| 107 | */ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 108 | AppDelayTracer(shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * @brief Trace constructor that attaches to all applications on the node using node's name |
| 112 | * @param os reference to the output stream |
| 113 | * @param nodeName name of the node registered using Names::Add |
| 114 | */ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 115 | AppDelayTracer(shared_ptr<std::ostream> os, const std::string& node); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * @brief Destructor |
| 119 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 120 | ~AppDelayTracer(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * @brief Print head of the trace (e.g., for post-processing) |
| 124 | * |
| 125 | * @param os reference to output stream |
| 126 | */ |
| 127 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | PrintHeader(std::ostream& os) const; |
| 129 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 130 | private: |
| 131 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 132 | Connect(); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | void |
| 135 | LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount); |
| 136 | |
| 137 | void |
| 138 | FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, |
| 139 | int32_t hopCount); |
| 140 | |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 141 | private: |
| 142 | std::string m_node; |
| 143 | Ptr<Node> m_nodePtr; |
| 144 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 145 | shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace ndn |
| 149 | } // namespace ns3 |
| 150 | |
| 151 | #endif // CCNX_CS_TRACER_H |