OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2015 Bucknell University |
| 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: Li Li (ll024@bucknell.edu) |
| 19 */ |
| 20 |
| 21 #ifndef TIME_AVERAGING_COLLECTOR_H |
| 22 #define TIME_AVERAGING_COLLECTOR_H |
| 23 |
| 24 #include "ns3/object.h" |
| 25 #include "ns3/collector.h" |
| 26 #include "ns3/event-id.h" |
| 27 #include "ns3/type-id.h" |
| 28 #include "ns3/traced-value.h" |
| 29 #include "ns3/nstime.h" |
| 30 |
| 31 namespace ns3 { |
| 32 |
| 33 /** |
| 34 * \ingroup collectors |
| 35 * \brief TimeAveragingCollector class collects a single trace of |
| 36 * double-valued data and outputs the time-averaged value (i.e. a rate) every· |
| 37 * measurement period. |
| 38 */ |
| 39 class TimeAveragingCollector : public Collector |
| 40 { |
| 41 public: |
| 42 /** |
| 43 * \brief Get the type ID |
| 44 * \return the object TypeId |
| 45 */ |
| 46 static TypeId GetTypeId (void); |
| 47 |
| 48 /** |
| 49 * \brief Constructs a TimeAveragingCollector object |
| 50 */ |
| 51 TimeAveragingCollector (); |
| 52 |
| 53 virtual ~TimeAveragingCollector (); |
| 54 |
| 55 /** |
| 56 * \brief Collects the double values produced by the upstream probes |
| 57 * |
| 58 * \param oldValue previous value produced by a Probe |
| 59 * \param newValue new value produced by a Probe |
| 60 */ |
| 61 void TraceSinkDouble (double oldValue, double newValue); |
| 62 |
| 63 /** |
| 64 * \brief Sets the time period to report data |
| 65 * |
| 66 * \param period a variable of type Time to indicate the period |
| 67 */ |
| 68 void SetPeriod (Time period); |
| 69 |
| 70 /** |
| 71 * \brief Gets the time period to report data |
| 72 * |
| 73 * \return the time period to report data |
| 74 */ |
| 75 Time GetPeriod () const; |
| 76 |
| 77 /** |
| 78 * \brief Override DataCollectionObject::Enable() to schedule the very· |
| 79 * first event whenever the collector is enabled. This method will |
| 80 * also cancel any previously scheduled event if one exists. |
| 81 *·· |
| 82 * \sa ns3::DataCollectionObject::Enable |
| 83 */ |
| 84 void Enable (void); |
| 85 private: |
| 86 // the output data trace source |
| 87 TracedCallback<double, double> m_output; |
| 88 |
| 89 /** |
| 90 * \brief Reports data to downstream objects |
| 91 */ |
| 92 void ReportData (void); |
| 93 |
| 94 /** |
| 95 * \brief Does necessary work every time the period has changed |
| 96 */ |
| 97 void PeriodChanged (void); |
| 98 |
| 99 // a double value to keep track of the double value |
| 100 // received by the trace sink |
| 101 double m_doubleValue; |
| 102 |
| 103 // the period to output data |
| 104 Time m_period; |
| 105 |
| 106 // The event ID used to keep track of the scheduled event |
| 107 EventId m_reportEventId; |
| 108 |
| 109 // a boolean value showing whether or not an event has been scheduled |
| 110 bool m_hasReportBeenScheduled; |
| 111 |
| 112 // an integer value to keep track of the number of data points received |
| 113 // in one batch (in between two TraceSink calls) |
| 114 int m_batchCount; |
| 115 |
| 116 }; |
| 117 |
| 118 |
| 119 } // namespace ns3 |
| 120 |
| 121 #endif // TIME_AVERAGING_COLLECTOR_H |
OLD | NEW |