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" |
| 28 | |
| 29 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 30 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 31 | #include <map> |
| 32 | |
| 33 | namespace ns3 { |
| 34 | |
| 35 | /** |
| 36 | * @ingroup ccnx |
| 37 | * @brief CCNx network-layer rate tracer |
| 38 | */ |
| 39 | class Ipv4RateL3Tracer : public Ipv4L3Tracer |
| 40 | { |
| 41 | public: |
| 42 | /** |
| 43 | * @brief Network layer tracer constructor |
| 44 | */ |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 45 | Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 46 | virtual ~Ipv4RateL3Tracer (); |
| 47 | |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 48 | /** |
| 49 | * @brief Helper method to install tracers on all simulation nodes |
| 50 | * |
| 51 | * @param file File to which traces will be written |
| 52 | * @param averagingPeriod Defines averaging period for the rate calculation, |
| 53 | * as well as how often data will be written into the trace file (default, every half second) |
| 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 | */ |
| 59 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > > |
| 60 | InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 61 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 62 | void |
| 63 | SetAveragingPeriod (const Time &period); |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 65 | virtual void |
| 66 | PrintHeader (std::ostream &os) const; |
| 67 | |
| 68 | virtual void |
| 69 | Print (std::ostream &os) const; |
| 70 | |
| 71 | virtual void |
| 72 | Rx (std::string context, |
| 73 | Ptr<const Packet>, Ptr<Ipv4>, uint32_t); |
| 74 | |
| 75 | virtual void |
| 76 | Tx (std::string context, |
| 77 | Ptr<const Packet>, Ptr<Ipv4>, uint32_t); |
| 78 | |
| 79 | virtual void |
| 80 | Drop (std::string context, |
| 81 | const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t); |
| 82 | |
| 83 | private: |
| 84 | void |
| 85 | PeriodicPrinter (); |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 87 | void |
| 88 | Reset (); |
| 89 | |
| 90 | private: |
Alexander Afanasyev | 4916586 | 2013-01-31 00:38:20 -0800 | [diff] [blame] | 91 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame] | 92 | Time m_period; |
| 93 | EventId m_printEvent; |
| 94 | |
| 95 | mutable std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> > m_stats; |
| 96 | }; |
| 97 | |
| 98 | } // namespace ns3 |
| 99 | |
| 100 | #endif // IPV4_RATE_L3_TRACER_H |