Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 UCLA |
| 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 IPV4_RATE_L3_TRACER_H |
| 22 | #define IPV4_RATE_L3_TRACER_H |
| 23 | |
| 24 | #include "ipv4-l3-tracer.h" |
| 25 | |
| 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 | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 29 | |
| 30 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 31 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 32 | #include <map> |
| 33 | |
| 34 | namespace ns3 { |
| 35 | |
| 36 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 37 | * @ingroup ndn-tracers |
| 38 | * @brief IPv4 network-layer rate tracer |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 39 | */ |
| 40 | class Ipv4RateL3Tracer : public Ipv4L3Tracer |
| 41 | { |
| 42 | public: |
| 43 | /** |
| 44 | * @brief Network layer tracer constructor |
| 45 | */ |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 46 | Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 47 | virtual ~Ipv4RateL3Tracer (); |
| 48 | |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 49 | /** |
| 50 | * @brief Helper method to install tracers on all simulation nodes |
| 51 | * |
| 52 | * @param file File to which traces will be written |
| 53 | * @param averagingPeriod Defines averaging period for the rate calculation, |
| 54 | * as well as how often data will be written into the trace file (default, every half second) |
| 55 | * |
| 56 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 57 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 58 | * |
| 59 | */ |
| 60 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > > |
| 61 | InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 62 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 63 | /** |
| 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 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 69 | * |
| 70 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 71 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 72 | * |
| 73 | */ |
| 74 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > > |
| 75 | Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 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 |
| 82 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 83 | * |
| 84 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 85 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 86 | * |
| 87 | */ |
| 88 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > > |
| 89 | Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 90 | |
| 91 | /** |
| 92 | * @brief Helper method to install tracers on a specific simulation node |
| 93 | * |
| 94 | * @param nodes Nodes on which to install tracer |
| 95 | * @param outputStream Smart pointer to a stream |
| 96 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 97 | * |
| 98 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 99 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 100 | */ |
| 101 | static Ptr<Ipv4RateL3Tracer> |
| 102 | Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5)); |
| 103 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 104 | void |
| 105 | SetAveragingPeriod (const Time &period); |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 107 | virtual void |
| 108 | PrintHeader (std::ostream &os) const; |
| 109 | |
| 110 | virtual void |
| 111 | Print (std::ostream &os) const; |
| 112 | |
| 113 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 114 | Rx (Ptr<const Packet>, Ptr<Ipv4>, uint32_t); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 115 | |
| 116 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 117 | Tx (Ptr<const Packet>, Ptr<Ipv4>, uint32_t); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 118 | |
| 119 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 120 | Drop (const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 121 | |
| 122 | private: |
| 123 | void |
| 124 | PeriodicPrinter (); |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 126 | void |
| 127 | Reset (); |
| 128 | |
| 129 | private: |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 130 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 131 | Time m_period; |
| 132 | EventId m_printEvent; |
| 133 | |
| 134 | mutable std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> > m_stats; |
| 135 | }; |
| 136 | |
| 137 | } // namespace ns3 |
| 138 | |
| 139 | #endif // IPV4_RATE_L3_TRACER_H |