--- a/src/contrib/stats/basic-data-calculators.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __BASIC_DATA_CALCULATORS_H__
-#define __BASIC_DATA_CALCULATORS_H__
-
-#include "data-calculator.h"
-#include "data-output-interface.h"
-
-namespace ns3 {
-
- //------------------------------------------------------------
- //--------------------------------------------
- template <typename T = uint32_t>
- class MinMaxAvgTotalCalculator : public DataCalculator,
- public StatisticalSummary {
- public:
- MinMaxAvgTotalCalculator();
- virtual ~MinMaxAvgTotalCalculator();
-
- void Update(const T i);
-
- virtual void Output(DataOutputCallback &callback) const;
-
- long getCount() const { return m_count; }
- double getSum() const { return m_total; }
- double getMin() const { return m_min; }
- double getMax() const { return m_max; }
- double getMean() const { return m_total / (double)m_count; }
- double getStddev() const { return NaN; } // unsupported
- double getVariance() const { return NaN; } // unsupported
- double getSqrSum() const { return NaN; } // unsupported
-
- protected:
- virtual void DoDispose(void);
-
- uint32_t m_count;
- T m_total, m_min, m_max;
-
- // end MinMaxAvgTotalCalculator
- };
-
- //----------------------------------------------
- template <typename T>
- MinMaxAvgTotalCalculator<T>::MinMaxAvgTotalCalculator()
- {
- m_count = 0;
- m_total = 0;
- m_min = ~0;
- m_max = 0;
- }
-
- template <typename T>
- MinMaxAvgTotalCalculator<T>::~MinMaxAvgTotalCalculator()
- {
- }
- template <typename T>
- void
- MinMaxAvgTotalCalculator<T>::DoDispose(void)
- {
- DataCalculator::DoDispose();
- // MinMaxAvgTotalCalculator::DoDispose
- }
-
- template <typename T>
- void
- MinMaxAvgTotalCalculator<T>::Update(const T i)
- {
- if (m_enabled) {
- m_total += i;
-
- if (i < m_min)
- m_min = i;
-
- if (i > m_max)
- m_max = i;
-
- m_count++;
- }
- // end MinMaxAvgTotalCalculator::Update
- }
-
- template <typename T>
- void
- MinMaxAvgTotalCalculator<T>::Output(DataOutputCallback &callback) const
- {
- callback.OutputStatistic(m_context, m_key, this);
- }
-
-
- //------------------------------------------------------------
- //--------------------------------------------
- template <typename T = uint32_t>
- class CounterCalculator : public DataCalculator {
- public:
- CounterCalculator();
- virtual ~CounterCalculator();
-
- void Update();
- void Update(const T i);
-
- T GetCount() const;
-
- virtual void Output(DataOutputCallback &callback) const;
-
- protected:
- virtual void DoDispose(void);
-
- T m_count;
-
- // end CounterCalculator
- };
-
-
- //--------------------------------------------
- template <typename T>
- CounterCalculator<T>::CounterCalculator() :
- m_count(0)
- {
- }
-
- template <typename T>
- CounterCalculator<T>::~CounterCalculator()
- {
- }
- template <typename T>
- void
- CounterCalculator<T>::DoDispose(void)
- {
- DataCalculator::DoDispose();
- // CounterCalculator::DoDispose
- }
-
- template <typename T>
- void
- CounterCalculator<T>::Update()
- {
- if (m_enabled) {
- m_count++;
- }
- // end CounterCalculator::Update
- }
-
- template <typename T>
- void
- CounterCalculator<T>::Update(const T i)
- {
- if (m_enabled) {
- m_count += i;
- }
- // end CounterCalculator::Update
- }
-
- template <typename T>
- T
- CounterCalculator<T>::GetCount() const
- {
- return m_count;
- // end CounterCalculator::GetCount
- }
-
- template <typename T>
- void
- CounterCalculator<T>::Output(DataOutputCallback &callback) const
- {
- callback.OutputSingleton(m_context, m_key, m_count);
- // end CounterCalculator::Output
- }
-
- // end namespace ns3
-};
-
-
-#endif // __BASIC_DATA_CALCULATORS_H__
--- a/src/contrib/stats/data-calculator.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include "ns3/log.h"
-#include "ns3/simulator.h"
-
-#include "data-calculator.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("DataCalculator");
-
-static double zero = 0;
-const double ns3::NaN = zero / zero;
-
-//--------------------------------------------------------------
-//----------------------------------------------
-DataCalculator::DataCalculator() :
- m_enabled(true)
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-
-DataCalculator::~DataCalculator()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-
-void
-DataCalculator::DoDispose(void)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- Simulator::Cancel(m_startEvent);
- Simulator::Cancel(m_stopEvent);
-
- Object::DoDispose();
- // DataCalculator::DoDispose
-}
-
-//----------------------------------------------
-void
-DataCalculator::SetKey(const std::string key)
-{
- m_key = key;
- // end DataCalculator::SetKey
-}
-
-std::string
-DataCalculator::GetKey() const
-{
- return m_key;
- // end DataCalculator::GetKey
-}
-
-//----------------------------------------------
-void
-DataCalculator::SetContext(const std::string context)
-{
- m_context = context;
- // end DataCalculator::SetContext
-}
-
-std::string
-DataCalculator::GetContext() const
-{
- return m_context;
- // end DataCalculator::GetContext
-}
-//----------------------------------------------
-void
-DataCalculator::Enable()
-{
- m_enabled = true;
- // end DataCalculator::Enable
-}
-
-void
-DataCalculator::Disable()
-{
- m_enabled = false;
- // end DataCalculator::Disable
-}
-
-bool
-DataCalculator::GetEnabled() const
-{
- return m_enabled;
- // end DataCalculator::GetEnabled
-}
-
-//----------------------------------------------
-void
-DataCalculator::Start(const Time& startTime)
-{
-
- m_startEvent = Simulator::Schedule(startTime,
- &DataCalculator::Enable, this);
-
- // end DataCalculator::Start
-}
-
-void
-DataCalculator::Stop(const Time& stopTime)
-{
- m_stopEvent = Simulator::Schedule(stopTime,
- &DataCalculator::Disable, this);
- // end DataCalculator::Stop
-}
--- a/src/contrib/stats/data-calculator.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __DATA_CALCULATOR_H__
-#define __DATA_CALCULATOR_H__
-
-#include "ns3/object.h"
-#include "ns3/nstime.h"
-#include "ns3/simulator.h"
-
-namespace ns3 {
- extern const double NaN;
- inline bool isNaN(double x) { return x != x; }
-
- class DataOutputCallback;
-
- class StatisticalSummary {
- public:
- /**
- * Destructor
- */
- virtual ~StatisticalSummary ()
- {
- }
- /**
- * Returns the number of the observations.
- */
- virtual long getCount() const = 0;
-
- /**
- * Returns the sum of the values.
- * @see getWeightedSum()
- */
- virtual double getSum() const = 0;
-
- /**
- * Returns the sum of the squared values.
- * @see getWeightedSqrSum()
- */
- virtual double getSqrSum() const = 0;
-
- /**
- * Returns the minimum of the values.
- */
- virtual double getMin() const = 0;
-
- /**
- * Returns the maximum of the values.
- */
- virtual double getMax() const = 0;
-
- /**
- * Returns the mean of the (weighted) observations.
- */
- virtual double getMean() const = 0;
-
- /**
- * Returns the standard deviation of the (weighted) observations.
- */
- virtual double getStddev() const = 0;
-
- /**
- * Returns the variance of the (weighted) observations.
- */
- virtual double getVariance() const = 0;
- };
-
- //------------------------------------------------------------
- //--------------------------------------------
- class DataCalculator : public Object {
- public:
- DataCalculator();
- virtual ~DataCalculator();
-
- bool GetEnabled() const;
- void Enable();
- void Disable();
-
- void SetKey(const std::string key);
- std::string GetKey() const;
-
- void SetContext(const std::string context);
- std::string GetContext() const;
-
- virtual void Start(const Time& startTime);
- virtual void Stop(const Time& stopTime);
-
- virtual void Output(DataOutputCallback &callback) const = 0;
-
- protected:
- bool m_enabled; // Descendant classes *must* check & respect m_enabled!
-
- std::string m_key;
- std::string m_context;
-
- virtual void DoDispose(void);
-
- private:
- EventId m_startEvent;
- EventId m_stopEvent;
-
- // end class DataCalculator
- };
-
-
- // end namespace ns3
-};
-
-
-#endif // __DATA_CALCULATOR_H__
--- a/src/contrib/stats/data-collector.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include "ns3/object.h"
-#include "ns3/log.h"
-
-#include "data-collector.h"
-#include "data-calculator.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("DataCollector");
-
-//--------------------------------------------------------------
-//----------------------------------------------
-DataCollector::DataCollector() {
- NS_LOG_FUNCTION_NOARGS();
- // end DataCollector::DataCollector
-}
-
-DataCollector::~DataCollector() {
- NS_LOG_FUNCTION_NOARGS();
- // end DataCollector::~DataCollector
-}
-
-void DataCollector::DoDispose() {
- NS_LOG_FUNCTION_NOARGS();
-
- m_calcList.clear();
- m_metadata.clear();
-
- Object::DoDispose();
- // end DataCollector::DoDispose
-}
-
-void
-DataCollector::DescribeRun(std::string experiment,
- std::string strategy,
- std::string input,
- std::string runID,
- std::string description)
-{
-
- m_experimentLabel = experiment;
- m_strategyLabel = strategy;
- m_inputLabel = input;
- m_runLabel = runID;
- m_description = description;
-
- // end DataCollector::DescribeRun
-}
-
-void
-DataCollector::AddDataCalculator(Ptr<DataCalculator> datac)
-{
-
- m_calcList.push_back(datac);
-
- // end DataCollector::AddDataCalculator
-}
-
-DataCalculatorList::iterator
-DataCollector::DataCalculatorBegin()
-{
- return m_calcList.begin();
- // end DataCollector::DataCalculatorBegin
-}
-DataCalculatorList::iterator
-DataCollector::DataCalculatorEnd()
-{
- return m_calcList.end();
- // end DataCollector::DataCalculatorEnd
-}
-
-void
-DataCollector::AddMetadata(std::string key, std::string value)
-{
- std::pair<std::string, std::string> blob(key, value);
- m_metadata.push_back(blob);
- // end DataCollector::AddMetadata
-}
-void
-DataCollector::AddMetadata(std::string key, uint32_t value)
-{
- std::stringstream st;
- st << value;
-
- std::pair<std::string, std::string> blob(key, st.str());
- m_metadata.push_back(blob);
- // end DataCollector::AddMetadata
-}
-void
-DataCollector::AddMetadata(std::string key, double value)
-{
- std::stringstream st;
- st << value;
-
- std::pair<std::string, std::string> blob(key, st.str());
- m_metadata.push_back(blob);
- // end DataCollector::AddMetadata
-}
-
-MetadataList::iterator
-DataCollector::MetadataBegin()
-{
- return m_metadata.begin();
- // end DataCollector::MetadataBegin
-}
-MetadataList::iterator
-DataCollector::MetadataEnd()
-{
- return m_metadata.end();
- // end DataCollector::MetadataEnd
-}
--- a/src/contrib/stats/data-collector.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __DATA_COLLECTOR_H__
-#define __DATA_COLLECTOR_H__
-
-#include <list>
-#include <string>
-
-#include "ns3/object.h"
-
-namespace ns3 {
-
- class DataCalculator;
-
- //------------------------------------------------------------
- //--------------------------------------------
- typedef std::list<Ptr<DataCalculator> > DataCalculatorList;
- typedef std::list<std::pair<std::string, std::string> > MetadataList;
-
- class DataCollector : public Object {
- public:
- DataCollector();
- virtual ~DataCollector();
-
- void DescribeRun(std::string experiment,
- std::string strategy,
- std::string input,
- std::string runID,
- std::string description = "");
-
- std::string GetExperimentLabel() const { return m_experimentLabel; }
- std::string GetStrategyLabel() const { return m_strategyLabel; }
- std::string GetInputLabel() const { return m_inputLabel; }
- std::string GetRunLabel() const { return m_runLabel; }
- std::string GetDescription() const { return m_description; }
-
- void AddMetadata(std::string key, std::string value);
- void AddMetadata(std::string key, double value);
- void AddMetadata(std::string key, uint32_t value);
- MetadataList::iterator MetadataBegin();
- MetadataList::iterator MetadataEnd();
-
- void AddDataCalculator(Ptr<DataCalculator> datac);
- DataCalculatorList::iterator DataCalculatorBegin();
- DataCalculatorList::iterator DataCalculatorEnd();
-
- protected:
- virtual void DoDispose();
-
- private:
- std::string m_experimentLabel;
- std::string m_strategyLabel;
- std::string m_inputLabel;
- std::string m_runLabel;
- std::string m_description;
-
- MetadataList m_metadata;
- DataCalculatorList m_calcList;
-
- // end class DataCollector
- };
-
- // end namespace ns3
-};
-
-#endif // __DATA_COLLECTOR_H__
--- a/src/contrib/stats/data-output-interface.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include "ns3/log.h"
-
-#include "data-output-interface.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("DataOutputInterface");
-
-
-//--------------------------------------------------------------
-//----------------------------------------------
-DataOutputInterface::DataOutputInterface()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-DataOutputInterface::~DataOutputInterface()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-void
-DataOutputInterface::DoDispose()
-{
- NS_LOG_FUNCTION_NOARGS();
-
- Object::DoDispose();
- // end DataOutputInterface::DoDispose
-}
-
-void
-DataOutputInterface::SetFilePrefix(const std::string prefix)
-{
- m_filePrefix = prefix;
-}
-
-std::string
-DataOutputInterface::GetFilePrefix() const
-{
- return m_filePrefix;
-}
--- a/src/contrib/stats/data-output-interface.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __DATA_OUTPUT_INTERFACE_H__
-#define __DATA_OUTPUT_INTERFACE_H__
-
-#include "ns3/object.h"
-#include "ns3/nstime.h"
-#include "ns3/data-calculator.h"
-
-namespace ns3 {
-
- class DataCollector;
-
- //------------------------------------------------------------
- //--------------------------------------------
- class DataOutputInterface : public Object {
- public:
- DataOutputInterface();
- virtual ~DataOutputInterface();
-
- virtual void Output(DataCollector &dc) = 0;
-
- void SetFilePrefix(const std::string prefix);
- std::string GetFilePrefix() const;
-
- protected:
- virtual void DoDispose();
-
- std::string m_filePrefix;
-
- // end class DataOutputInterface
- };
-
- class DataOutputCallback {
- public:
- virtual ~DataOutputCallback() {}
-
- virtual void OutputStatistic(std::string key,
- std::string variable,
- const StatisticalSummary *statSum) = 0;
-
- virtual void OutputSingleton(std::string key,
- std::string variable,
- int val) = 0;
-
- virtual void OutputSingleton(std::string key,
- std::string variable,
- uint32_t val) = 0;
-
- virtual void OutputSingleton(std::string key,
- std::string variable,
- double val) = 0;
-
- virtual void OutputSingleton(std::string key,
- std::string variable,
- std::string val) = 0;
-
- virtual void OutputSingleton(std::string key,
- std::string variable,
- Time val) = 0;
- // end class DataOutputCallback
- };
-
- // end namespace ns3
-};
-
-
-#endif // __DATA_OUTPUT_INTERFACE_H__
--- a/src/contrib/stats/omnet-data-output.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,214 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include <fstream>
-#include <cstdlib>
-
-#include "ns3/log.h"
-#include "ns3/nstime.h"
-
-#include "data-collector.h"
-#include "data-calculator.h"
-#include "omnet-data-output.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("OmnetDataOutput");
-
-
-//--------------------------------------------------------------
-//----------------------------------------------
-OmnetDataOutput::OmnetDataOutput()
-{
- m_filePrefix = "data";
-
- NS_LOG_FUNCTION_NOARGS();
-}
-OmnetDataOutput::~OmnetDataOutput()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-void
-OmnetDataOutput::DoDispose()
-{
- NS_LOG_FUNCTION_NOARGS();
-
- DataOutputInterface::DoDispose();
- // end OmnetDataOutput::DoDispose
-}
-
-//----------------------------------------------
-
-inline bool isNumeric(const std::string& s) {
- char *endp;
- double unused = strtod(s.c_str(), &endp); // declared with warn_unused_result
- unused = unused; // quiet compiler
- return endp == s.c_str() + s.size();
-}
-
-void
-OmnetDataOutput::Output(DataCollector &dc)
-{
-
- std::ofstream scalarFile;
- std::string fn = m_filePrefix +"-"+dc.GetRunLabel()+ ".sca";
- scalarFile.open(fn.c_str(), std::ios_base::out);
-
- // TODO add timestamp to the runlevel
- scalarFile << "run " << dc.GetRunLabel() << std::endl;
- scalarFile << "attr experiment \"" << dc.GetExperimentLabel()
- << "\"" << std::endl;
- scalarFile << "attr strategy \"" << dc.GetStrategyLabel()
- << "\"" << std::endl;
- scalarFile << "attr measurement \"" << dc.GetInputLabel()
- << "\"" << std::endl;
- scalarFile << "attr description \"" << dc.GetDescription()
- << "\"" << std::endl;
-
- for (MetadataList::iterator i = dc.MetadataBegin();
- i != dc.MetadataEnd(); i++) {
- std::pair<std::string, std::string> blob = (*i);
- scalarFile << "attr \"" << blob.first << "\" \"" << blob.second << "\""
- << std::endl;
- }
-
- scalarFile << std::endl;
- if (isNumeric(dc.GetInputLabel())) {
- scalarFile << "scalar . measurement \"" << dc.GetInputLabel()
- << "\"" << std::endl;
- }
- for (MetadataList::iterator i = dc.MetadataBegin();
- i != dc.MetadataEnd(); i++) {
- std::pair<std::string, std::string> blob = (*i);
- if (isNumeric(blob.second)) {
- scalarFile << "scalar . \"" << blob.first << "\" \"" << blob.second << "\""
- << std::endl;
- }
- }
- OmnetOutputCallback callback(&scalarFile);
-
- for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
- i != dc.DataCalculatorEnd(); i++) {
- (*i)->Output(callback);
- }
-
- scalarFile << std::endl << std::endl;
- scalarFile.close();
-
- // end OmnetDataOutput::Output
-}
-
-
-OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback
- (std::ostream *scalar) :
- m_scalar(scalar)
-{
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputStatistic(std::string context,
- std::string name,
- const StatisticalSummary *statSum)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "statistic " << context << " " << name << std::endl;
- if (!isNaN(statSum->getCount()))
- (*m_scalar) << "field count " << statSum->getCount() << std::endl;
- if (!isNaN(statSum->getSum()))
- (*m_scalar) << "field sum " << statSum->getSum() << std::endl;
- if (!isNaN(statSum->getMean()))
- (*m_scalar) << "field mean " << statSum->getMean() << std::endl;
- if (!isNaN(statSum->getMin()))
- (*m_scalar) << "field min " << statSum->getMin() << std::endl;
- if (!isNaN(statSum->getMax()))
- (*m_scalar) << "field max " << statSum->getMax() << std::endl;
- if (!isNaN(statSum->getSqrSum()))
- (*m_scalar) << "field sqrsum " << statSum->getSqrSum() << std::endl;
- if (!isNaN(statSum->getStddev()))
- (*m_scalar) << "field stddev " << statSum->getStddev() << std::endl;
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
- std::string name,
- int val)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
- // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
- std::string name,
- uint32_t val)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
- // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
- std::string name,
- double val)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
- // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
- std::string name,
- std::string val)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
- // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
-}
-
-void
-OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
- std::string name,
- Time val)
-{
- if (context == "")
- context = ".";
- if (name == "")
- name = "\"\"";
- (*m_scalar) << "scalar " << context << " " << name << " " << val.GetTimeStep() << std::endl;
- // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
-}
--- a/src/contrib/stats/omnet-data-output.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __OMNET_DATA_OUTPUT_H__
-#define __OMNET_DATA_OUTPUT_H__
-
-#include "ns3/nstime.h"
-
-#include "data-output-interface.h"
-
-namespace ns3 {
-
-
- //------------------------------------------------------------
- //--------------------------------------------
- class OmnetDataOutput : public DataOutputInterface {
- public:
- OmnetDataOutput();
- virtual ~OmnetDataOutput();
-
- virtual void Output(DataCollector &dc);
-
- protected:
- virtual void DoDispose();
-
- private:
- class OmnetOutputCallback : public DataOutputCallback {
- public:
- OmnetOutputCallback(std::ostream *scalar);
-
- void OutputStatistic(std::string context,
- std::string name,
- const StatisticalSummary *statSum);
-
- void OutputSingleton(std::string context,
- std::string name,
- int val);
-
- void OutputSingleton(std::string context,
- std::string name,
- uint32_t val);
-
- void OutputSingleton(std::string context,
- std::string name,
- double val);
-
- void OutputSingleton(std::string context,
- std::string name,
- std::string val);
-
- void OutputSingleton(std::string context,
- std::string name,
- Time val);
-
- private:
- std::ostream *m_scalar;
- // end class OmnetOutputCallback
- };
-
- // end class OmnetDataOutput
- };
-
- // end namespace ns3
-};
-
-
-#endif // __OMNET_DATA_OUTPUT_H__
--- a/src/contrib/stats/packet-data-calculators.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include "ns3/log.h"
-#include "ns3/packet.h"
-#include "ns3/mac48-address.h"
-
-#include "basic-data-calculators.h"
-#include "packet-data-calculators.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("PacketDataCalculators");
-
-
-//--------------------------------------------------------------
-//----------------------------------------------
-PacketCounterCalculator::PacketCounterCalculator()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-
-PacketCounterCalculator::~PacketCounterCalculator()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-void
-PacketCounterCalculator::DoDispose(void)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- CounterCalculator<uint32_t>::DoDispose();
- // PacketCounterCalculator::DoDispose
-}
-
-void
-PacketCounterCalculator::PacketUpdate(std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- CounterCalculator<uint32_t>::Update();
-
- // PacketCounterCalculator::Update
-}
-void
-PacketCounterCalculator::FrameUpdate(std::string path,
- Ptr<const Packet> packet,
- Mac48Address realto)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- CounterCalculator<uint32_t>::Update();
-
- // PacketCounterCalculator::Update
-}
-
-
-
-
-//--------------------------------------------------------------
-//----------------------------------------------
-PacketSizeMinMaxAvgTotalCalculator::PacketSizeMinMaxAvgTotalCalculator()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-
-PacketSizeMinMaxAvgTotalCalculator::~PacketSizeMinMaxAvgTotalCalculator()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-void
-PacketSizeMinMaxAvgTotalCalculator::DoDispose(void)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- MinMaxAvgTotalCalculator<uint32_t>::DoDispose();
- // end PacketSizeMinMaxAvgTotalCalculator::DoDispose
-}
-
-void
-PacketSizeMinMaxAvgTotalCalculator::PacketUpdate(std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
-
- // end PacketSizeMinMaxAvgTotalCalculator::Update
-}
-void
-PacketSizeMinMaxAvgTotalCalculator::FrameUpdate(std::string path,
- Ptr<const Packet> packet,
- Mac48Address realto)
-{
- NS_LOG_FUNCTION_NOARGS();
-
- MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
-
- // end PacketSizeMinMaxAvgTotalCalculator::Update
-}
--- a/src/contrib/stats/packet-data-calculators.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __PACKET_DATA_CALCULATORS_H__
-#define __PACKET_DATA_CALCULATORS_H__
-
-#include "ns3/packet.h"
-#include "ns3/mac48-address.h"
-
-#include "data-calculator.h"
-
-namespace ns3 {
-
- class PacketCounterCalculator : public CounterCalculator<uint32_t> {
- public:
- PacketCounterCalculator();
- virtual ~PacketCounterCalculator();
-
- void PacketUpdate(std::string path, Ptr<const Packet> packet);
- void FrameUpdate(std::string path, Ptr<const Packet> packet,
- Mac48Address realto);
-
- protected:
- virtual void DoDispose(void);
-
- // end class PacketCounterCalculator
- };
-
-
- class PacketSizeMinMaxAvgTotalCalculator :
- public MinMaxAvgTotalCalculator<uint32_t> {
- public:
- PacketSizeMinMaxAvgTotalCalculator();
- virtual ~PacketSizeMinMaxAvgTotalCalculator();
-
- void PacketUpdate(std::string path, Ptr<const Packet> packet);
- void FrameUpdate(std::string path, Ptr<const Packet> packet,
- Mac48Address realto);
-
- protected:
- virtual void DoDispose(void);
-
- // end class PacketSizeMinMaxAvgTotalCalculator
- };
-
-
- // end namespace ns3
-};
-
-
-#endif // __PACKET_DATA_CALCULATORS_H__
--- a/src/contrib/stats/sqlite-data-output.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,248 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include <sstream>
-
-#include <sqlite3.h>
-
-#include "ns3/log.h"
-#include "ns3/nstime.h"
-
-#include "data-collector.h"
-#include "data-calculator.h"
-#include "sqlite-data-output.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("SqliteDataOutput");
-
-//--------------------------------------------------------------
-//----------------------------------------------
-SqliteDataOutput::SqliteDataOutput()
-{
- m_filePrefix = "data";
- NS_LOG_FUNCTION_NOARGS();
-}
-SqliteDataOutput::~SqliteDataOutput()
-{
- NS_LOG_FUNCTION_NOARGS();
-}
-void
-SqliteDataOutput::DoDispose()
-{
- NS_LOG_FUNCTION_NOARGS();
-
- DataOutputInterface::DoDispose();
- // end SqliteDataOutput::DoDispose
-}
-
-int
-SqliteDataOutput::Exec(std::string exe) {
- int res;
- char **result;
- int nrows, ncols;
- char *errMsg = 0;
-
- NS_LOG_INFO("executing '" << exe << "'");
-
- res = sqlite3_get_table(m_db,
- exe.c_str(),
- &result, &nrows, &ncols,
- &errMsg);
-
- if (res != SQLITE_OK) {
- NS_LOG_ERROR("sqlite3 error: \"" << errMsg << "\"");
- /*
- } else {
- // std::cout << "nrows " << nrows << " ncols " << ncols << std::endl;
-
- if (nrows > 0) {
- for (int i = 0; i < ncols; i++) {
- std::cout << " " << result[i];
- }
- std::cout << std::endl;
-
- for (int r = 1; r <= nrows; r++) {
- for (int c = 0; c < ncols; c++) {
- std::cout << " " << result[(r*ncols)+c];
- }
- std::cout << std::endl;
- }
- std::cout << std::endl;
- }
- */
- }
-
- sqlite3_free_table(result);
- return res;
-
- // end SqliteDataOutput::Exec
-}
-
-//----------------------------------------------
-void
-SqliteDataOutput::Output(DataCollector &dc)
-{
- std::string m_dbFile = m_filePrefix + ".db";
-
- if (sqlite3_open(m_dbFile.c_str(), &m_db)) {
- NS_LOG_ERROR("Could not open sqlite3 database \"" << m_dbFile << "\"");
- NS_LOG_ERROR("sqlite3 error \"" << sqlite3_errmsg(m_db) << "\"");
- sqlite3_close(m_db);
- // TODO: Better error reporting, management!
- return;
- }
-
- std::string run = dc.GetRunLabel();
-
- Exec("create table if not exists Experiments (run, experiment, strategy, input, description text)");
- Exec("insert into Experiments (run,experiment,strategy,input,description) values ('" +
- run + "', '" +
- dc.GetExperimentLabel() + "', '" +
- dc.GetStrategyLabel() + "', '" +
- dc.GetInputLabel() + "', '" +
- dc.GetDescription() + "')");
-
- Exec("create table if not exists Metadata ( run text, key text, value)");
-
- for (MetadataList::iterator i = dc.MetadataBegin();
- i != dc.MetadataEnd(); i++) {
- std::pair<std::string, std::string> blob = (*i);
- Exec("insert into Metadata (run,key,value) values ('" +
- run + "', '" +
- blob.first + "', '" +
- blob.second + "')");
- }
-
- Exec("BEGIN");
- SqliteOutputCallback callback(this, run);
- for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
- i != dc.DataCalculatorEnd(); i++) {
- (*i)->Output(callback);
- }
- Exec("COMMIT");
-
- sqlite3_close(m_db);
-
- // end SqliteDataOutput::Output
-}
-
-SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
- (Ptr<SqliteDataOutput> owner, std::string run) :
- m_owner(owner),
- m_runLabel(run)
-{
-
- m_owner->Exec("create table if not exists Singletons ( run text, name text, variable text, value )");
-
- // end SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
-}
-
-void
-SqliteDataOutput::SqliteOutputCallback::OutputStatistic(std::string key,
- std::string variable,
- const StatisticalSummary *statSum)
-{
- OutputSingleton(key,variable+"-count", (double)statSum->getCount());
- if (!isNaN(statSum->getSum()))
- OutputSingleton(key,variable+"-total", statSum->getSum());
- if (!isNaN(statSum->getMax()))
- OutputSingleton(key,variable+"-max", statSum->getMax());
- if (!isNaN(statSum->getMin()))
- OutputSingleton(key,variable+"-min", statSum->getMin());
- if (!isNaN(statSum->getSqrSum()))
- OutputSingleton(key,variable+"-sqrsum", statSum->getSqrSum());
- if (!isNaN(statSum->getStddev()))
- OutputSingleton(key,variable+"-stddev", statSum->getStddev());
-}
-
-
-void
-SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
- std::string variable,
- int val)
-{
-
- std::stringstream sstr;
- sstr << "insert into Singletons (run,name,variable,value) values ('" <<
- m_runLabel << "', '" <<
- key << "', '" <<
- variable << "', " <<
- val << ")";
- m_owner->Exec(sstr.str());
-
- // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
-}
-void
-SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
- std::string variable,
- uint32_t val)
-{
- std::stringstream sstr;
- sstr << "insert into Singletons (run,name,variable,value) values ('" <<
- m_runLabel << "', '" <<
- key << "', '" <<
- variable << "', " <<
- val << ")";
- m_owner->Exec(sstr.str());
- // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
-}
-void
-SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
- std::string variable,
- double val)
-{
- std::stringstream sstr;
- sstr << "insert into Singletons (run,name,variable,value) values ('" <<
- m_runLabel << "', '" <<
- key << "', '" <<
- variable << "', " <<
- val << ")";
- m_owner->Exec(sstr.str());
- // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
-}
-void
-SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
- std::string variable,
- std::string val)
-{
- std::stringstream sstr;
- sstr << "insert into Singletons (run,name,variable,value) values ('" <<
- m_runLabel << "', '" <<
- key << "', '" <<
- variable << "', '" <<
- val << "')";
- m_owner->Exec(sstr.str());
- // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
-}
-void
-SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
- std::string variable,
- Time val)
-{
- std::stringstream sstr;
- sstr << "insert into Singletons (run,name,variable,value) values ('" <<
- m_runLabel << "', '" <<
- key << "', '" <<
- variable << "', " <<
- val.GetTimeStep() << ")";
- m_owner->Exec(sstr.str());
- // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
-}
--- a/src/contrib/stats/sqlite-data-output.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __SQLITE_DATA_OUTPUT_H__
-#define __SQLITE_DATA_OUTPUT_H__
-
-#include "ns3/nstime.h"
-
-#include "data-output-interface.h"
-
-#define STATS_HAS_SQLITE3
-
-class sqlite3;
-
-namespace ns3 {
-
- //------------------------------------------------------------
- //--------------------------------------------
- class SqliteDataOutput : public DataOutputInterface {
- public:
- SqliteDataOutput();
- virtual ~SqliteDataOutput();
-
- virtual void Output(DataCollector &dc);
-
- protected:
- virtual void DoDispose();
-
- private:
- class SqliteOutputCallback : public DataOutputCallback {
- public:
- SqliteOutputCallback(Ptr<SqliteDataOutput> owner, std::string run);
-
- void OutputStatistic(std::string key,
- std::string variable,
- const StatisticalSummary *statSum);
-
- void OutputSingleton(std::string key,
- std::string variable,
- int val);
-
- void OutputSingleton(std::string key,
- std::string variable,
- uint32_t val);
-
- void OutputSingleton(std::string key,
- std::string variable,
- double val);
-
- void OutputSingleton(std::string key,
- std::string variable,
- std::string val);
-
- void OutputSingleton(std::string key,
- std::string variable,
- Time val);
-
- private:
- Ptr<SqliteDataOutput> m_owner;
- std::string m_runLabel;
-
- // end class SqliteOutputCallback
- };
-
-
- sqlite3 *m_db;
- int Exec(std::string exe);
-
- // end class SqliteDataOutput
- };
-
- // end namespace ns3
-};
-
-
-#endif // __SQLITE_DATA_OUTPUT_H__
--- a/src/contrib/stats/time-data-calculators.cc Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#include "ns3/log.h"
-#include "ns3/nstime.h"
-
-#include "time-data-calculators.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE("TimeDataCalculators");
-
-
-//--------------------------------------------------------------
-//----------------------------------------------
-TimeMinMaxAvgTotalCalculator::TimeMinMaxAvgTotalCalculator()
-{
- m_count = 0;
-}
-TimeMinMaxAvgTotalCalculator::~TimeMinMaxAvgTotalCalculator()
-{
-}
-void
-TimeMinMaxAvgTotalCalculator::DoDispose(void)
-{
- DataCalculator::DoDispose();
- // TimeMinMaxAvgTotalCalculator::DoDispose
-}
-
-void
-TimeMinMaxAvgTotalCalculator::Update(const Time i)
-{
- if (m_enabled) {
- if (m_count) {
- m_total += i;
-
- if (i < m_min)
- m_min = i;
-
- if (i > m_max)
- m_max = i;
-
- } else {
- m_min = i;
- m_max = i;
- m_total = i;
- }
- m_count++;
-
- }
- // end TimeMinMaxAvgTotalCalculator::Update
-}
-void
-TimeMinMaxAvgTotalCalculator::Output(DataOutputCallback &callback) const
-{
- callback.OutputSingleton(m_context, m_key + "-count", m_count);
- if (m_count > 0) {
- callback.OutputSingleton(m_context, m_key + "-total", m_total);
- callback.OutputSingleton(m_context, m_key + "-average", m_total/Scalar(m_count));
- callback.OutputSingleton(m_context, m_key + "-max", m_max);
- callback.OutputSingleton(m_context, m_key + "-min", m_min);
- }
- // end TimeMinMaxAvgTotalCalculator::Output
-}
--- a/src/contrib/stats/time-data-calculators.h Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
- */
-
-#ifndef __TIME_DATA_CALCULATORS_H__
-#define __TIME_DATA_CALCULATORS_H__
-
-#include "ns3/nstime.h"
-
-#include "data-calculator.h"
-#include "data-output-interface.h"
-
-namespace ns3 {
-
- //------------------------------------------------------------
- //--------------------------------------------
- /**
- * Unfortunately, templating the base MinMaxAvgTotalCalculator to
- * operate over Time values isn't straightforward. The main issues
- * are setting the maximum value, which can be worked around easily
- * as it done here, and dividing to get the average, which is not as
- * easily worked around.
- */
- class TimeMinMaxAvgTotalCalculator : public DataCalculator {
- public:
- TimeMinMaxAvgTotalCalculator();
- virtual ~TimeMinMaxAvgTotalCalculator();
-
- void Update(const Time i);
-
- virtual void Output(DataOutputCallback &callback) const;
-
- protected:
- virtual void DoDispose(void);
-
- uint32_t m_count;
- Time m_total, m_min, m_max;
-
- // end class TimeMinMaxAvgTotalCalculator
- };
-
- // end namespace ns3
-};
-
-
-#endif // __TIME_DATA_CALCULATORS_H__
--- a/src/contrib/stats/wscript Fri Mar 04 09:59:42 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-def configure(conf):
- conf.env['SQLITE_STATS'] = conf.check(lib='sqlite3', define_name='SQLITE3', uselib='SQLITE3')
- conf.report_optional_feature("SqliteDataOutput", "SQlite stats data output",
- conf.env['SQLITE_STATS'],
- "library 'sqlite3' not found")
-
-
-def build(bld):
- obj = bld.create_ns3_module('stats', ['network'])
- obj.source = [
- 'data-calculator.cc',
- 'packet-data-calculators.cc',
- 'time-data-calculators.cc',
- 'data-output-interface.cc',
- 'omnet-data-output.cc',
- 'data-collector.cc',
- ]
- headers = bld.new_task_gen('ns3header')
- headers.module = 'stats'
- headers.source = [
- 'data-calculator.h',
- 'packet-data-calculators.h',
- 'time-data-calculators.h',
- 'basic-data-calculators.h',
- 'data-output-interface.h',
- 'omnet-data-output.h',
- 'data-collector.h',
- ]
-
- if bld.env['SQLITE_STATS']:
- headers.source.append('sqlite-data-output.h')
- obj.source.append('sqlite-data-output.cc')
- obj.uselib = 'SQLITE3'
--- a/src/contrib/wscript Fri Mar 04 09:59:42 2011 -0800
+++ b/src/contrib/wscript Fri Mar 04 10:56:07 2011 -0800
@@ -16,8 +16,6 @@
"library 'libxml-2.0 >= 2.7' not found")
conf.write_config_header('ns3/contrib-config.h', top=True)
- conf.sub_config('stats')
-
def build(bld):
module = bld.create_ns3_module('contrib', ['core', 'network'])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/basic-data-calculators.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,191 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __BASIC_DATA_CALCULATORS_H__
+#define __BASIC_DATA_CALCULATORS_H__
+
+#include "data-calculator.h"
+#include "data-output-interface.h"
+
+namespace ns3 {
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ template <typename T = uint32_t>
+ class MinMaxAvgTotalCalculator : public DataCalculator,
+ public StatisticalSummary {
+ public:
+ MinMaxAvgTotalCalculator();
+ virtual ~MinMaxAvgTotalCalculator();
+
+ void Update(const T i);
+
+ virtual void Output(DataOutputCallback &callback) const;
+
+ long getCount() const { return m_count; }
+ double getSum() const { return m_total; }
+ double getMin() const { return m_min; }
+ double getMax() const { return m_max; }
+ double getMean() const { return m_total / (double)m_count; }
+ double getStddev() const { return NaN; } // unsupported
+ double getVariance() const { return NaN; } // unsupported
+ double getSqrSum() const { return NaN; } // unsupported
+
+ protected:
+ virtual void DoDispose(void);
+
+ uint32_t m_count;
+ T m_total, m_min, m_max;
+
+ // end MinMaxAvgTotalCalculator
+ };
+
+ //----------------------------------------------
+ template <typename T>
+ MinMaxAvgTotalCalculator<T>::MinMaxAvgTotalCalculator()
+ {
+ m_count = 0;
+ m_total = 0;
+ m_min = ~0;
+ m_max = 0;
+ }
+
+ template <typename T>
+ MinMaxAvgTotalCalculator<T>::~MinMaxAvgTotalCalculator()
+ {
+ }
+ template <typename T>
+ void
+ MinMaxAvgTotalCalculator<T>::DoDispose(void)
+ {
+ DataCalculator::DoDispose();
+ // MinMaxAvgTotalCalculator::DoDispose
+ }
+
+ template <typename T>
+ void
+ MinMaxAvgTotalCalculator<T>::Update(const T i)
+ {
+ if (m_enabled) {
+ m_total += i;
+
+ if (i < m_min)
+ m_min = i;
+
+ if (i > m_max)
+ m_max = i;
+
+ m_count++;
+ }
+ // end MinMaxAvgTotalCalculator::Update
+ }
+
+ template <typename T>
+ void
+ MinMaxAvgTotalCalculator<T>::Output(DataOutputCallback &callback) const
+ {
+ callback.OutputStatistic(m_context, m_key, this);
+ }
+
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ template <typename T = uint32_t>
+ class CounterCalculator : public DataCalculator {
+ public:
+ CounterCalculator();
+ virtual ~CounterCalculator();
+
+ void Update();
+ void Update(const T i);
+
+ T GetCount() const;
+
+ virtual void Output(DataOutputCallback &callback) const;
+
+ protected:
+ virtual void DoDispose(void);
+
+ T m_count;
+
+ // end CounterCalculator
+ };
+
+
+ //--------------------------------------------
+ template <typename T>
+ CounterCalculator<T>::CounterCalculator() :
+ m_count(0)
+ {
+ }
+
+ template <typename T>
+ CounterCalculator<T>::~CounterCalculator()
+ {
+ }
+ template <typename T>
+ void
+ CounterCalculator<T>::DoDispose(void)
+ {
+ DataCalculator::DoDispose();
+ // CounterCalculator::DoDispose
+ }
+
+ template <typename T>
+ void
+ CounterCalculator<T>::Update()
+ {
+ if (m_enabled) {
+ m_count++;
+ }
+ // end CounterCalculator::Update
+ }
+
+ template <typename T>
+ void
+ CounterCalculator<T>::Update(const T i)
+ {
+ if (m_enabled) {
+ m_count += i;
+ }
+ // end CounterCalculator::Update
+ }
+
+ template <typename T>
+ T
+ CounterCalculator<T>::GetCount() const
+ {
+ return m_count;
+ // end CounterCalculator::GetCount
+ }
+
+ template <typename T>
+ void
+ CounterCalculator<T>::Output(DataOutputCallback &callback) const
+ {
+ callback.OutputSingleton(m_context, m_key, m_count);
+ // end CounterCalculator::Output
+ }
+
+ // end namespace ns3
+};
+
+
+#endif // __BASIC_DATA_CALCULATORS_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-calculator.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,126 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+
+#include "data-calculator.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("DataCalculator");
+
+static double zero = 0;
+const double ns3::NaN = zero / zero;
+
+//--------------------------------------------------------------
+//----------------------------------------------
+DataCalculator::DataCalculator() :
+ m_enabled(true)
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+DataCalculator::~DataCalculator()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+void
+DataCalculator::DoDispose(void)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ Simulator::Cancel(m_startEvent);
+ Simulator::Cancel(m_stopEvent);
+
+ Object::DoDispose();
+ // DataCalculator::DoDispose
+}
+
+//----------------------------------------------
+void
+DataCalculator::SetKey(const std::string key)
+{
+ m_key = key;
+ // end DataCalculator::SetKey
+}
+
+std::string
+DataCalculator::GetKey() const
+{
+ return m_key;
+ // end DataCalculator::GetKey
+}
+
+//----------------------------------------------
+void
+DataCalculator::SetContext(const std::string context)
+{
+ m_context = context;
+ // end DataCalculator::SetContext
+}
+
+std::string
+DataCalculator::GetContext() const
+{
+ return m_context;
+ // end DataCalculator::GetContext
+}
+//----------------------------------------------
+void
+DataCalculator::Enable()
+{
+ m_enabled = true;
+ // end DataCalculator::Enable
+}
+
+void
+DataCalculator::Disable()
+{
+ m_enabled = false;
+ // end DataCalculator::Disable
+}
+
+bool
+DataCalculator::GetEnabled() const
+{
+ return m_enabled;
+ // end DataCalculator::GetEnabled
+}
+
+//----------------------------------------------
+void
+DataCalculator::Start(const Time& startTime)
+{
+
+ m_startEvent = Simulator::Schedule(startTime,
+ &DataCalculator::Enable, this);
+
+ // end DataCalculator::Start
+}
+
+void
+DataCalculator::Stop(const Time& stopTime)
+{
+ m_stopEvent = Simulator::Schedule(stopTime,
+ &DataCalculator::Disable, this);
+ // end DataCalculator::Stop
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-calculator.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,127 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __DATA_CALCULATOR_H__
+#define __DATA_CALCULATOR_H__
+
+#include "ns3/object.h"
+#include "ns3/nstime.h"
+#include "ns3/simulator.h"
+
+namespace ns3 {
+ extern const double NaN;
+ inline bool isNaN(double x) { return x != x; }
+
+ class DataOutputCallback;
+
+ class StatisticalSummary {
+ public:
+ /**
+ * Destructor
+ */
+ virtual ~StatisticalSummary ()
+ {
+ }
+ /**
+ * Returns the number of the observations.
+ */
+ virtual long getCount() const = 0;
+
+ /**
+ * Returns the sum of the values.
+ * @see getWeightedSum()
+ */
+ virtual double getSum() const = 0;
+
+ /**
+ * Returns the sum of the squared values.
+ * @see getWeightedSqrSum()
+ */
+ virtual double getSqrSum() const = 0;
+
+ /**
+ * Returns the minimum of the values.
+ */
+ virtual double getMin() const = 0;
+
+ /**
+ * Returns the maximum of the values.
+ */
+ virtual double getMax() const = 0;
+
+ /**
+ * Returns the mean of the (weighted) observations.
+ */
+ virtual double getMean() const = 0;
+
+ /**
+ * Returns the standard deviation of the (weighted) observations.
+ */
+ virtual double getStddev() const = 0;
+
+ /**
+ * Returns the variance of the (weighted) observations.
+ */
+ virtual double getVariance() const = 0;
+ };
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ class DataCalculator : public Object {
+ public:
+ DataCalculator();
+ virtual ~DataCalculator();
+
+ bool GetEnabled() const;
+ void Enable();
+ void Disable();
+
+ void SetKey(const std::string key);
+ std::string GetKey() const;
+
+ void SetContext(const std::string context);
+ std::string GetContext() const;
+
+ virtual void Start(const Time& startTime);
+ virtual void Stop(const Time& stopTime);
+
+ virtual void Output(DataOutputCallback &callback) const = 0;
+
+ protected:
+ bool m_enabled; // Descendant classes *must* check & respect m_enabled!
+
+ std::string m_key;
+ std::string m_context;
+
+ virtual void DoDispose(void);
+
+ private:
+ EventId m_startEvent;
+ EventId m_stopEvent;
+
+ // end class DataCalculator
+ };
+
+
+ // end namespace ns3
+};
+
+
+#endif // __DATA_CALCULATOR_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-collector.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include "ns3/object.h"
+#include "ns3/log.h"
+
+#include "data-collector.h"
+#include "data-calculator.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("DataCollector");
+
+//--------------------------------------------------------------
+//----------------------------------------------
+DataCollector::DataCollector() {
+ NS_LOG_FUNCTION_NOARGS();
+ // end DataCollector::DataCollector
+}
+
+DataCollector::~DataCollector() {
+ NS_LOG_FUNCTION_NOARGS();
+ // end DataCollector::~DataCollector
+}
+
+void DataCollector::DoDispose() {
+ NS_LOG_FUNCTION_NOARGS();
+
+ m_calcList.clear();
+ m_metadata.clear();
+
+ Object::DoDispose();
+ // end DataCollector::DoDispose
+}
+
+void
+DataCollector::DescribeRun(std::string experiment,
+ std::string strategy,
+ std::string input,
+ std::string runID,
+ std::string description)
+{
+
+ m_experimentLabel = experiment;
+ m_strategyLabel = strategy;
+ m_inputLabel = input;
+ m_runLabel = runID;
+ m_description = description;
+
+ // end DataCollector::DescribeRun
+}
+
+void
+DataCollector::AddDataCalculator(Ptr<DataCalculator> datac)
+{
+
+ m_calcList.push_back(datac);
+
+ // end DataCollector::AddDataCalculator
+}
+
+DataCalculatorList::iterator
+DataCollector::DataCalculatorBegin()
+{
+ return m_calcList.begin();
+ // end DataCollector::DataCalculatorBegin
+}
+DataCalculatorList::iterator
+DataCollector::DataCalculatorEnd()
+{
+ return m_calcList.end();
+ // end DataCollector::DataCalculatorEnd
+}
+
+void
+DataCollector::AddMetadata(std::string key, std::string value)
+{
+ std::pair<std::string, std::string> blob(key, value);
+ m_metadata.push_back(blob);
+ // end DataCollector::AddMetadata
+}
+void
+DataCollector::AddMetadata(std::string key, uint32_t value)
+{
+ std::stringstream st;
+ st << value;
+
+ std::pair<std::string, std::string> blob(key, st.str());
+ m_metadata.push_back(blob);
+ // end DataCollector::AddMetadata
+}
+void
+DataCollector::AddMetadata(std::string key, double value)
+{
+ std::stringstream st;
+ st << value;
+
+ std::pair<std::string, std::string> blob(key, st.str());
+ m_metadata.push_back(blob);
+ // end DataCollector::AddMetadata
+}
+
+MetadataList::iterator
+DataCollector::MetadataBegin()
+{
+ return m_metadata.begin();
+ // end DataCollector::MetadataBegin
+}
+MetadataList::iterator
+DataCollector::MetadataEnd()
+{
+ return m_metadata.end();
+ // end DataCollector::MetadataEnd
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-collector.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __DATA_COLLECTOR_H__
+#define __DATA_COLLECTOR_H__
+
+#include <list>
+#include <string>
+
+#include "ns3/object.h"
+
+namespace ns3 {
+
+ class DataCalculator;
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ typedef std::list<Ptr<DataCalculator> > DataCalculatorList;
+ typedef std::list<std::pair<std::string, std::string> > MetadataList;
+
+ class DataCollector : public Object {
+ public:
+ DataCollector();
+ virtual ~DataCollector();
+
+ void DescribeRun(std::string experiment,
+ std::string strategy,
+ std::string input,
+ std::string runID,
+ std::string description = "");
+
+ std::string GetExperimentLabel() const { return m_experimentLabel; }
+ std::string GetStrategyLabel() const { return m_strategyLabel; }
+ std::string GetInputLabel() const { return m_inputLabel; }
+ std::string GetRunLabel() const { return m_runLabel; }
+ std::string GetDescription() const { return m_description; }
+
+ void AddMetadata(std::string key, std::string value);
+ void AddMetadata(std::string key, double value);
+ void AddMetadata(std::string key, uint32_t value);
+ MetadataList::iterator MetadataBegin();
+ MetadataList::iterator MetadataEnd();
+
+ void AddDataCalculator(Ptr<DataCalculator> datac);
+ DataCalculatorList::iterator DataCalculatorBegin();
+ DataCalculatorList::iterator DataCalculatorEnd();
+
+ protected:
+ virtual void DoDispose();
+
+ private:
+ std::string m_experimentLabel;
+ std::string m_strategyLabel;
+ std::string m_inputLabel;
+ std::string m_runLabel;
+ std::string m_description;
+
+ MetadataList m_metadata;
+ DataCalculatorList m_calcList;
+
+ // end class DataCollector
+ };
+
+ // end namespace ns3
+};
+
+#endif // __DATA_COLLECTOR_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-output-interface.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,59 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include "ns3/log.h"
+
+#include "data-output-interface.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("DataOutputInterface");
+
+
+//--------------------------------------------------------------
+//----------------------------------------------
+DataOutputInterface::DataOutputInterface()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+DataOutputInterface::~DataOutputInterface()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+void
+DataOutputInterface::DoDispose()
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ Object::DoDispose();
+ // end DataOutputInterface::DoDispose
+}
+
+void
+DataOutputInterface::SetFilePrefix(const std::string prefix)
+{
+ m_filePrefix = prefix;
+}
+
+std::string
+DataOutputInterface::GetFilePrefix() const
+{
+ return m_filePrefix;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/data-output-interface.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,86 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __DATA_OUTPUT_INTERFACE_H__
+#define __DATA_OUTPUT_INTERFACE_H__
+
+#include "ns3/object.h"
+#include "ns3/nstime.h"
+#include "ns3/data-calculator.h"
+
+namespace ns3 {
+
+ class DataCollector;
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ class DataOutputInterface : public Object {
+ public:
+ DataOutputInterface();
+ virtual ~DataOutputInterface();
+
+ virtual void Output(DataCollector &dc) = 0;
+
+ void SetFilePrefix(const std::string prefix);
+ std::string GetFilePrefix() const;
+
+ protected:
+ virtual void DoDispose();
+
+ std::string m_filePrefix;
+
+ // end class DataOutputInterface
+ };
+
+ class DataOutputCallback {
+ public:
+ virtual ~DataOutputCallback() {}
+
+ virtual void OutputStatistic(std::string key,
+ std::string variable,
+ const StatisticalSummary *statSum) = 0;
+
+ virtual void OutputSingleton(std::string key,
+ std::string variable,
+ int val) = 0;
+
+ virtual void OutputSingleton(std::string key,
+ std::string variable,
+ uint32_t val) = 0;
+
+ virtual void OutputSingleton(std::string key,
+ std::string variable,
+ double val) = 0;
+
+ virtual void OutputSingleton(std::string key,
+ std::string variable,
+ std::string val) = 0;
+
+ virtual void OutputSingleton(std::string key,
+ std::string variable,
+ Time val) = 0;
+ // end class DataOutputCallback
+ };
+
+ // end namespace ns3
+};
+
+
+#endif // __DATA_OUTPUT_INTERFACE_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/omnet-data-output.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,214 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include <fstream>
+#include <cstdlib>
+
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+
+#include "data-collector.h"
+#include "data-calculator.h"
+#include "omnet-data-output.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("OmnetDataOutput");
+
+
+//--------------------------------------------------------------
+//----------------------------------------------
+OmnetDataOutput::OmnetDataOutput()
+{
+ m_filePrefix = "data";
+
+ NS_LOG_FUNCTION_NOARGS();
+}
+OmnetDataOutput::~OmnetDataOutput()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+void
+OmnetDataOutput::DoDispose()
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ DataOutputInterface::DoDispose();
+ // end OmnetDataOutput::DoDispose
+}
+
+//----------------------------------------------
+
+inline bool isNumeric(const std::string& s) {
+ char *endp;
+ double unused = strtod(s.c_str(), &endp); // declared with warn_unused_result
+ unused = unused; // quiet compiler
+ return endp == s.c_str() + s.size();
+}
+
+void
+OmnetDataOutput::Output(DataCollector &dc)
+{
+
+ std::ofstream scalarFile;
+ std::string fn = m_filePrefix +"-"+dc.GetRunLabel()+ ".sca";
+ scalarFile.open(fn.c_str(), std::ios_base::out);
+
+ // TODO add timestamp to the runlevel
+ scalarFile << "run " << dc.GetRunLabel() << std::endl;
+ scalarFile << "attr experiment \"" << dc.GetExperimentLabel()
+ << "\"" << std::endl;
+ scalarFile << "attr strategy \"" << dc.GetStrategyLabel()
+ << "\"" << std::endl;
+ scalarFile << "attr measurement \"" << dc.GetInputLabel()
+ << "\"" << std::endl;
+ scalarFile << "attr description \"" << dc.GetDescription()
+ << "\"" << std::endl;
+
+ for (MetadataList::iterator i = dc.MetadataBegin();
+ i != dc.MetadataEnd(); i++) {
+ std::pair<std::string, std::string> blob = (*i);
+ scalarFile << "attr \"" << blob.first << "\" \"" << blob.second << "\""
+ << std::endl;
+ }
+
+ scalarFile << std::endl;
+ if (isNumeric(dc.GetInputLabel())) {
+ scalarFile << "scalar . measurement \"" << dc.GetInputLabel()
+ << "\"" << std::endl;
+ }
+ for (MetadataList::iterator i = dc.MetadataBegin();
+ i != dc.MetadataEnd(); i++) {
+ std::pair<std::string, std::string> blob = (*i);
+ if (isNumeric(blob.second)) {
+ scalarFile << "scalar . \"" << blob.first << "\" \"" << blob.second << "\""
+ << std::endl;
+ }
+ }
+ OmnetOutputCallback callback(&scalarFile);
+
+ for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
+ i != dc.DataCalculatorEnd(); i++) {
+ (*i)->Output(callback);
+ }
+
+ scalarFile << std::endl << std::endl;
+ scalarFile.close();
+
+ // end OmnetDataOutput::Output
+}
+
+
+OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback
+ (std::ostream *scalar) :
+ m_scalar(scalar)
+{
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputStatistic(std::string context,
+ std::string name,
+ const StatisticalSummary *statSum)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "statistic " << context << " " << name << std::endl;
+ if (!isNaN(statSum->getCount()))
+ (*m_scalar) << "field count " << statSum->getCount() << std::endl;
+ if (!isNaN(statSum->getSum()))
+ (*m_scalar) << "field sum " << statSum->getSum() << std::endl;
+ if (!isNaN(statSum->getMean()))
+ (*m_scalar) << "field mean " << statSum->getMean() << std::endl;
+ if (!isNaN(statSum->getMin()))
+ (*m_scalar) << "field min " << statSum->getMin() << std::endl;
+ if (!isNaN(statSum->getMax()))
+ (*m_scalar) << "field max " << statSum->getMax() << std::endl;
+ if (!isNaN(statSum->getSqrSum()))
+ (*m_scalar) << "field sqrsum " << statSum->getSqrSum() << std::endl;
+ if (!isNaN(statSum->getStddev()))
+ (*m_scalar) << "field stddev " << statSum->getStddev() << std::endl;
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
+ std::string name,
+ int val)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
+ // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
+ std::string name,
+ uint32_t val)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
+ // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
+ std::string name,
+ double val)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
+ // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
+ std::string name,
+ std::string val)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl;
+ // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
+}
+
+void
+OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context,
+ std::string name,
+ Time val)
+{
+ if (context == "")
+ context = ".";
+ if (name == "")
+ name = "\"\"";
+ (*m_scalar) << "scalar " << context << " " << name << " " << val.GetTimeStep() << std::endl;
+ // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/omnet-data-output.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __OMNET_DATA_OUTPUT_H__
+#define __OMNET_DATA_OUTPUT_H__
+
+#include "ns3/nstime.h"
+
+#include "data-output-interface.h"
+
+namespace ns3 {
+
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ class OmnetDataOutput : public DataOutputInterface {
+ public:
+ OmnetDataOutput();
+ virtual ~OmnetDataOutput();
+
+ virtual void Output(DataCollector &dc);
+
+ protected:
+ virtual void DoDispose();
+
+ private:
+ class OmnetOutputCallback : public DataOutputCallback {
+ public:
+ OmnetOutputCallback(std::ostream *scalar);
+
+ void OutputStatistic(std::string context,
+ std::string name,
+ const StatisticalSummary *statSum);
+
+ void OutputSingleton(std::string context,
+ std::string name,
+ int val);
+
+ void OutputSingleton(std::string context,
+ std::string name,
+ uint32_t val);
+
+ void OutputSingleton(std::string context,
+ std::string name,
+ double val);
+
+ void OutputSingleton(std::string context,
+ std::string name,
+ std::string val);
+
+ void OutputSingleton(std::string context,
+ std::string name,
+ Time val);
+
+ private:
+ std::ostream *m_scalar;
+ // end class OmnetOutputCallback
+ };
+
+ // end class OmnetDataOutput
+ };
+
+ // end namespace ns3
+};
+
+
+#endif // __OMNET_DATA_OUTPUT_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/packet-data-calculators.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,118 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/mac48-address.h"
+
+#include "basic-data-calculators.h"
+#include "packet-data-calculators.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("PacketDataCalculators");
+
+
+//--------------------------------------------------------------
+//----------------------------------------------
+PacketCounterCalculator::PacketCounterCalculator()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+PacketCounterCalculator::~PacketCounterCalculator()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+void
+PacketCounterCalculator::DoDispose(void)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ CounterCalculator<uint32_t>::DoDispose();
+ // PacketCounterCalculator::DoDispose
+}
+
+void
+PacketCounterCalculator::PacketUpdate(std::string path,
+ Ptr<const Packet> packet)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ CounterCalculator<uint32_t>::Update();
+
+ // PacketCounterCalculator::Update
+}
+void
+PacketCounterCalculator::FrameUpdate(std::string path,
+ Ptr<const Packet> packet,
+ Mac48Address realto)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ CounterCalculator<uint32_t>::Update();
+
+ // PacketCounterCalculator::Update
+}
+
+
+
+
+//--------------------------------------------------------------
+//----------------------------------------------
+PacketSizeMinMaxAvgTotalCalculator::PacketSizeMinMaxAvgTotalCalculator()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+PacketSizeMinMaxAvgTotalCalculator::~PacketSizeMinMaxAvgTotalCalculator()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+void
+PacketSizeMinMaxAvgTotalCalculator::DoDispose(void)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ MinMaxAvgTotalCalculator<uint32_t>::DoDispose();
+ // end PacketSizeMinMaxAvgTotalCalculator::DoDispose
+}
+
+void
+PacketSizeMinMaxAvgTotalCalculator::PacketUpdate(std::string path,
+ Ptr<const Packet> packet)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
+
+ // end PacketSizeMinMaxAvgTotalCalculator::Update
+}
+void
+PacketSizeMinMaxAvgTotalCalculator::FrameUpdate(std::string path,
+ Ptr<const Packet> packet,
+ Mac48Address realto)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
+
+ // end PacketSizeMinMaxAvgTotalCalculator::Update
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/packet-data-calculators.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,68 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __PACKET_DATA_CALCULATORS_H__
+#define __PACKET_DATA_CALCULATORS_H__
+
+#include "ns3/packet.h"
+#include "ns3/mac48-address.h"
+
+#include "data-calculator.h"
+
+namespace ns3 {
+
+ class PacketCounterCalculator : public CounterCalculator<uint32_t> {
+ public:
+ PacketCounterCalculator();
+ virtual ~PacketCounterCalculator();
+
+ void PacketUpdate(std::string path, Ptr<const Packet> packet);
+ void FrameUpdate(std::string path, Ptr<const Packet> packet,
+ Mac48Address realto);
+
+ protected:
+ virtual void DoDispose(void);
+
+ // end class PacketCounterCalculator
+ };
+
+
+ class PacketSizeMinMaxAvgTotalCalculator :
+ public MinMaxAvgTotalCalculator<uint32_t> {
+ public:
+ PacketSizeMinMaxAvgTotalCalculator();
+ virtual ~PacketSizeMinMaxAvgTotalCalculator();
+
+ void PacketUpdate(std::string path, Ptr<const Packet> packet);
+ void FrameUpdate(std::string path, Ptr<const Packet> packet,
+ Mac48Address realto);
+
+ protected:
+ virtual void DoDispose(void);
+
+ // end class PacketSizeMinMaxAvgTotalCalculator
+ };
+
+
+ // end namespace ns3
+};
+
+
+#endif // __PACKET_DATA_CALCULATORS_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/sqlite-data-output.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,248 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include <sstream>
+
+#include <sqlite3.h>
+
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+
+#include "data-collector.h"
+#include "data-calculator.h"
+#include "sqlite-data-output.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("SqliteDataOutput");
+
+//--------------------------------------------------------------
+//----------------------------------------------
+SqliteDataOutput::SqliteDataOutput()
+{
+ m_filePrefix = "data";
+ NS_LOG_FUNCTION_NOARGS();
+}
+SqliteDataOutput::~SqliteDataOutput()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+void
+SqliteDataOutput::DoDispose()
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ DataOutputInterface::DoDispose();
+ // end SqliteDataOutput::DoDispose
+}
+
+int
+SqliteDataOutput::Exec(std::string exe) {
+ int res;
+ char **result;
+ int nrows, ncols;
+ char *errMsg = 0;
+
+ NS_LOG_INFO("executing '" << exe << "'");
+
+ res = sqlite3_get_table(m_db,
+ exe.c_str(),
+ &result, &nrows, &ncols,
+ &errMsg);
+
+ if (res != SQLITE_OK) {
+ NS_LOG_ERROR("sqlite3 error: \"" << errMsg << "\"");
+ /*
+ } else {
+ // std::cout << "nrows " << nrows << " ncols " << ncols << std::endl;
+
+ if (nrows > 0) {
+ for (int i = 0; i < ncols; i++) {
+ std::cout << " " << result[i];
+ }
+ std::cout << std::endl;
+
+ for (int r = 1; r <= nrows; r++) {
+ for (int c = 0; c < ncols; c++) {
+ std::cout << " " << result[(r*ncols)+c];
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+ */
+ }
+
+ sqlite3_free_table(result);
+ return res;
+
+ // end SqliteDataOutput::Exec
+}
+
+//----------------------------------------------
+void
+SqliteDataOutput::Output(DataCollector &dc)
+{
+ std::string m_dbFile = m_filePrefix + ".db";
+
+ if (sqlite3_open(m_dbFile.c_str(), &m_db)) {
+ NS_LOG_ERROR("Could not open sqlite3 database \"" << m_dbFile << "\"");
+ NS_LOG_ERROR("sqlite3 error \"" << sqlite3_errmsg(m_db) << "\"");
+ sqlite3_close(m_db);
+ // TODO: Better error reporting, management!
+ return;
+ }
+
+ std::string run = dc.GetRunLabel();
+
+ Exec("create table if not exists Experiments (run, experiment, strategy, input, description text)");
+ Exec("insert into Experiments (run,experiment,strategy,input,description) values ('" +
+ run + "', '" +
+ dc.GetExperimentLabel() + "', '" +
+ dc.GetStrategyLabel() + "', '" +
+ dc.GetInputLabel() + "', '" +
+ dc.GetDescription() + "')");
+
+ Exec("create table if not exists Metadata ( run text, key text, value)");
+
+ for (MetadataList::iterator i = dc.MetadataBegin();
+ i != dc.MetadataEnd(); i++) {
+ std::pair<std::string, std::string> blob = (*i);
+ Exec("insert into Metadata (run,key,value) values ('" +
+ run + "', '" +
+ blob.first + "', '" +
+ blob.second + "')");
+ }
+
+ Exec("BEGIN");
+ SqliteOutputCallback callback(this, run);
+ for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
+ i != dc.DataCalculatorEnd(); i++) {
+ (*i)->Output(callback);
+ }
+ Exec("COMMIT");
+
+ sqlite3_close(m_db);
+
+ // end SqliteDataOutput::Output
+}
+
+SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
+ (Ptr<SqliteDataOutput> owner, std::string run) :
+ m_owner(owner),
+ m_runLabel(run)
+{
+
+ m_owner->Exec("create table if not exists Singletons ( run text, name text, variable text, value )");
+
+ // end SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
+}
+
+void
+SqliteDataOutput::SqliteOutputCallback::OutputStatistic(std::string key,
+ std::string variable,
+ const StatisticalSummary *statSum)
+{
+ OutputSingleton(key,variable+"-count", (double)statSum->getCount());
+ if (!isNaN(statSum->getSum()))
+ OutputSingleton(key,variable+"-total", statSum->getSum());
+ if (!isNaN(statSum->getMax()))
+ OutputSingleton(key,variable+"-max", statSum->getMax());
+ if (!isNaN(statSum->getMin()))
+ OutputSingleton(key,variable+"-min", statSum->getMin());
+ if (!isNaN(statSum->getSqrSum()))
+ OutputSingleton(key,variable+"-sqrsum", statSum->getSqrSum());
+ if (!isNaN(statSum->getStddev()))
+ OutputSingleton(key,variable+"-stddev", statSum->getStddev());
+}
+
+
+void
+SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
+ std::string variable,
+ int val)
+{
+
+ std::stringstream sstr;
+ sstr << "insert into Singletons (run,name,variable,value) values ('" <<
+ m_runLabel << "', '" <<
+ key << "', '" <<
+ variable << "', " <<
+ val << ")";
+ m_owner->Exec(sstr.str());
+
+ // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
+}
+void
+SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
+ std::string variable,
+ uint32_t val)
+{
+ std::stringstream sstr;
+ sstr << "insert into Singletons (run,name,variable,value) values ('" <<
+ m_runLabel << "', '" <<
+ key << "', '" <<
+ variable << "', " <<
+ val << ")";
+ m_owner->Exec(sstr.str());
+ // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
+}
+void
+SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
+ std::string variable,
+ double val)
+{
+ std::stringstream sstr;
+ sstr << "insert into Singletons (run,name,variable,value) values ('" <<
+ m_runLabel << "', '" <<
+ key << "', '" <<
+ variable << "', " <<
+ val << ")";
+ m_owner->Exec(sstr.str());
+ // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
+}
+void
+SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
+ std::string variable,
+ std::string val)
+{
+ std::stringstream sstr;
+ sstr << "insert into Singletons (run,name,variable,value) values ('" <<
+ m_runLabel << "', '" <<
+ key << "', '" <<
+ variable << "', '" <<
+ val << "')";
+ m_owner->Exec(sstr.str());
+ // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
+}
+void
+SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
+ std::string variable,
+ Time val)
+{
+ std::stringstream sstr;
+ sstr << "insert into Singletons (run,name,variable,value) values ('" <<
+ m_runLabel << "', '" <<
+ key << "', '" <<
+ variable << "', " <<
+ val.GetTimeStep() << ")";
+ m_owner->Exec(sstr.str());
+ // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/sqlite-data-output.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __SQLITE_DATA_OUTPUT_H__
+#define __SQLITE_DATA_OUTPUT_H__
+
+#include "ns3/nstime.h"
+
+#include "data-output-interface.h"
+
+#define STATS_HAS_SQLITE3
+
+class sqlite3;
+
+namespace ns3 {
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ class SqliteDataOutput : public DataOutputInterface {
+ public:
+ SqliteDataOutput();
+ virtual ~SqliteDataOutput();
+
+ virtual void Output(DataCollector &dc);
+
+ protected:
+ virtual void DoDispose();
+
+ private:
+ class SqliteOutputCallback : public DataOutputCallback {
+ public:
+ SqliteOutputCallback(Ptr<SqliteDataOutput> owner, std::string run);
+
+ void OutputStatistic(std::string key,
+ std::string variable,
+ const StatisticalSummary *statSum);
+
+ void OutputSingleton(std::string key,
+ std::string variable,
+ int val);
+
+ void OutputSingleton(std::string key,
+ std::string variable,
+ uint32_t val);
+
+ void OutputSingleton(std::string key,
+ std::string variable,
+ double val);
+
+ void OutputSingleton(std::string key,
+ std::string variable,
+ std::string val);
+
+ void OutputSingleton(std::string key,
+ std::string variable,
+ Time val);
+
+ private:
+ Ptr<SqliteDataOutput> m_owner;
+ std::string m_runLabel;
+
+ // end class SqliteOutputCallback
+ };
+
+
+ sqlite3 *m_db;
+ int Exec(std::string exe);
+
+ // end class SqliteDataOutput
+ };
+
+ // end namespace ns3
+};
+
+
+#endif // __SQLITE_DATA_OUTPUT_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/time-data-calculators.cc Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,81 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+
+#include "time-data-calculators.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("TimeDataCalculators");
+
+
+//--------------------------------------------------------------
+//----------------------------------------------
+TimeMinMaxAvgTotalCalculator::TimeMinMaxAvgTotalCalculator()
+{
+ m_count = 0;
+}
+TimeMinMaxAvgTotalCalculator::~TimeMinMaxAvgTotalCalculator()
+{
+}
+void
+TimeMinMaxAvgTotalCalculator::DoDispose(void)
+{
+ DataCalculator::DoDispose();
+ // TimeMinMaxAvgTotalCalculator::DoDispose
+}
+
+void
+TimeMinMaxAvgTotalCalculator::Update(const Time i)
+{
+ if (m_enabled) {
+ if (m_count) {
+ m_total += i;
+
+ if (i < m_min)
+ m_min = i;
+
+ if (i > m_max)
+ m_max = i;
+
+ } else {
+ m_min = i;
+ m_max = i;
+ m_total = i;
+ }
+ m_count++;
+
+ }
+ // end TimeMinMaxAvgTotalCalculator::Update
+}
+void
+TimeMinMaxAvgTotalCalculator::Output(DataOutputCallback &callback) const
+{
+ callback.OutputSingleton(m_context, m_key + "-count", m_count);
+ if (m_count > 0) {
+ callback.OutputSingleton(m_context, m_key + "-total", m_total);
+ callback.OutputSingleton(m_context, m_key + "-average", m_total/Scalar(m_count));
+ callback.OutputSingleton(m_context, m_key + "-max", m_max);
+ callback.OutputSingleton(m_context, m_key + "-min", m_min);
+ }
+ // end TimeMinMaxAvgTotalCalculator::Output
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/model/time-data-calculators.h Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Drexel 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: Joe Kopena (tjkopena@cs.drexel.edu)
+ */
+
+#ifndef __TIME_DATA_CALCULATORS_H__
+#define __TIME_DATA_CALCULATORS_H__
+
+#include "ns3/nstime.h"
+
+#include "data-calculator.h"
+#include "data-output-interface.h"
+
+namespace ns3 {
+
+ //------------------------------------------------------------
+ //--------------------------------------------
+ /**
+ * Unfortunately, templating the base MinMaxAvgTotalCalculator to
+ * operate over Time values isn't straightforward. The main issues
+ * are setting the maximum value, which can be worked around easily
+ * as it done here, and dividing to get the average, which is not as
+ * easily worked around.
+ */
+ class TimeMinMaxAvgTotalCalculator : public DataCalculator {
+ public:
+ TimeMinMaxAvgTotalCalculator();
+ virtual ~TimeMinMaxAvgTotalCalculator();
+
+ void Update(const Time i);
+
+ virtual void Output(DataOutputCallback &callback) const;
+
+ protected:
+ virtual void DoDispose(void);
+
+ uint32_t m_count;
+ Time m_total, m_min, m_max;
+
+ // end class TimeMinMaxAvgTotalCalculator
+ };
+
+ // end namespace ns3
+};
+
+
+#endif // __TIME_DATA_CALCULATORS_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stats/wscript Fri Mar 04 10:56:07 2011 -0800
@@ -0,0 +1,35 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def configure(conf):
+ conf.env['SQLITE_STATS'] = conf.check(lib='sqlite3', define_name='SQLITE3', uselib='SQLITE3')
+ conf.report_optional_feature("SqliteDataOutput", "SQlite stats data output",
+ conf.env['SQLITE_STATS'],
+ "library 'sqlite3' not found")
+
+
+def build(bld):
+ obj = bld.create_ns3_module('stats', ['network'])
+ obj.source = [
+ 'model/data-calculator.cc',
+ 'model/packet-data-calculators.cc',
+ 'model/time-data-calculators.cc',
+ 'model/data-output-interface.cc',
+ 'model/omnet-data-output.cc',
+ 'model/data-collector.cc',
+ ]
+ headers = bld.new_task_gen('ns3header')
+ headers.module = 'stats'
+ headers.source = [
+ 'model/data-calculator.h',
+ 'model/packet-data-calculators.h',
+ 'model/time-data-calculators.h',
+ 'model/basic-data-calculators.h',
+ 'model/data-output-interface.h',
+ 'model/omnet-data-output.h',
+ 'model/data-collector.h',
+ ]
+
+ if bld.env['SQLITE_STATS']:
+ headers.source.append('model/sqlite-data-output.h')
+ obj.source.append('model/sqlite-data-output.cc')
+ obj.uselib = 'SQLITE3'
--- a/src/wscript Fri Mar 04 09:59:42 2011 -0800
+++ b/src/wscript Fri Mar 04 10:56:07 2011 -0800
@@ -38,7 +38,7 @@
'mobility',
'wifi',
'helper',
- 'contrib/stats',
+ 'stats',
'uan',
'spectrum',
'mesh',