Index: src/stats/model/scaling-collector.cc |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/stats/model/scaling-collector.cc |
@@ -0,0 +1,96 @@ |
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
+/* |
+ * Copyright (c) 2015 Bucknell University |
+ * |
+ * This program is free software; you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 2 as |
+ * published by the Free Software Foundation; |
+ * |
+ * This program is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with this program; if not, write to the Free Software |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
+ * |
+ * Author: Li Li (ll024@bucknell.edu) |
+ */ |
+ |
+#include "ns3/object.h" |
+#include "ns3/log.h" |
+#include "ns3/simulator.h" |
+#include "ns3/scaling-collector.h" |
+ |
+NS_LOG_COMPONENT_DEFINE ("ScalingCollector"); |
+ |
+namespace ns3 { |
+ |
+NS_OBJECT_ENSURE_REGISTERED (ScalingCollector); |
+ |
+TypeId |
+ScalingCollector::GetTypeId (void) |
+{ |
+ static TypeId tid = TypeId ("ns3::ScalingCollector") |
+ .SetParent<Collector> () |
+ .AddConstructor<ScalingCollector> () |
+ .AddAttribute ("ScalingFactor", |
+ "Input data will be scaled by multiplying by this quantity", |
+ DoubleValue (1.0), |
+ MakeDoubleAccessor (&ScalingCollector::m_scalingFactor), |
+ MakeDoubleChecker<double> ()) |
+ .AddTraceSource ("Output", |
+ "The double value received by the trace sink after scaling", |
+ MakeTraceSourceAccessor (&ScalingCollector::m_output), |
+ "ns3::DataCollectionObject::CollectorTraceCallback") |
+ ; |
+ return tid; |
+} |
+ |
+ScalingCollector::ScalingCollector () |
+ : Collector () |
+{ |
+ NS_LOG_FUNCTION (this); |
+} |
+ |
+ScalingCollector::~ScalingCollector () |
+{ |
+ NS_LOG_FUNCTION (this); |
+} |
+ |
+void |
+ScalingCollector::TraceSinkDouble (double oldValue, double newValue) |
+{ |
+ NS_LOG_FUNCTION (this << oldValue << newValue); |
+ if (!IsEnabled ()) |
+ { |
+ NS_LOG_DEBUG ("Collector not enabled"); |
+ return; |
+ } |
+ |
+ // scale the value received by multiplying it with the scaling |
+ // factor, and store the data in m_doubleValue |
+ m_doubleValue = newValue * m_scalingFactor; |
+ |
+ // Report data to downstream objects |
+ ReportData (); |
+} |
+ |
+void |
+ScalingCollector::ReportData (void) |
+{ |
+ NS_LOG_FUNCTION (this); |
+ if (!IsEnabled ()) |
+ { |
+ return; |
+ } |
+ // get current simulation time |
+ double time = Simulator::Now ().GetSeconds (); |
+ |
+ // report the time and the newly received value to downstream |
+ // objects |
+ m_output (time, m_doubleValue); |
+} |
+ |
+} //namespace ns3 |