Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1388)

Unified Diff: src/stats/helper/file-helper.cc

Issue 245260043: DCF collectors
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/stats/helper/file-helper.cc
===================================================================
--- a/src/stats/helper/file-helper.cc
+++ b/src/stats/helper/file-helper.cc
@@ -26,6 +26,7 @@
#include "ns3/abort.h"
#include "ns3/log.h"
#include "ns3/config.h"
+#include "ns3/collector.h"
#include "ns3/get-wildcard-matches.h"
namespace ns3 {
@@ -40,6 +41,7 @@
m_hasHeadingBeenSet (false)
{
NS_LOG_FUNCTION (this);
+ m_collectorFactory.SetTypeId ("ns3::EventDrivenCollector");
// Note that this does not construct an aggregator. It will be
// constructed later when needed.
@@ -54,6 +56,7 @@
m_hasHeadingBeenSet (false)
{
NS_LOG_FUNCTION (this);
+ m_collectorFactory.SetTypeId ("ns3::EventDrivenCollector");
// Note that this does not construct an aggregator. It will be
// constructed later when needed.
@@ -87,11 +90,44 @@
}
void
+FileHelper::SetCollectorType (std::string collectorType,
+ std::string n0, const AttributeValue &v0,
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7)
+{
+ ObjectFactory factory;
+ factory.SetTypeId (collectorType);
+ factory.Set (n0, v0);
+ factory.Set (n1, v1);
+ factory.Set (n2, v2);
+ factory.Set (n3, v3);
+ factory.Set (n4, v4);
+ factory.Set (n5, v5);
+ factory.Set (n6, v6);
+ factory.Set (n7, v7);
+ m_collectorFactory = factory;
+}
+
+void
FileHelper::WriteProbe (const std::string &typeId,
const std::string &path,
const std::string &probeTraceSource)
{
NS_LOG_FUNCTION (this << typeId << path << probeTraceSource);
+ AddProbe (typeId, path, probeTraceSource);
+}
+
+void
+FileHelper::AddProbe (const std::string &typeId,
+ const std::string &path,
+ const std::string &probeTraceSource)
+{
+ NS_LOG_FUNCTION (this << typeId << path << probeTraceSource);
std::string pathWithoutLastToken;
std::string lastToken;
@@ -134,7 +170,7 @@
// the wildcard matches because the passed in path has none.
matchIdentifier = "0";
onlyOneAggregator = true;
- ConnectProbeToAggregator (typeId,
+ CreateDataCollectionChain (typeId,
matchIdentifier,
path,
probeTraceSource,
@@ -161,7 +197,7 @@
wildcardSeparator);
// Connect the probe to the aggregator for this match.
- ConnectProbeToAggregator (typeId,
+ CreateDataCollectionChain (typeId,
matchIdentifier,
matchedPath,
probeTraceSource,
@@ -177,7 +213,7 @@
}
void
-FileHelper::AddProbe (const std::string &typeId,
+FileHelper::AddProbeToMap (const std::string &typeId,
const std::string &probeName,
const std::string &path)
{
@@ -213,24 +249,21 @@
}
void
-FileHelper::AddTimeSeriesAdaptor (const std::string &adaptorName)
+FileHelper::AddCollector (const std::string &collectorName)
{
- NS_LOG_FUNCTION (this << adaptorName);
+ NS_LOG_FUNCTION (this << collectorName);
- // See if this time series adaptor had already been added.
- if (m_timeSeriesAdaptorMap.count (adaptorName) > 0)
+ Ptr<Collector> collector = DynamicCast<Collector> (m_collectorFactory.Create ());
+ collector->Enable ();
+ // See if this collector had already been added.
+
+ if (m_collectorMap.count (collectorName) > 0)
{
- NS_ABORT_MSG ("That time series adaptor has already been added");
+ NS_ABORT_MSG ("That Collector has already been added");
}
- // Create the time series adaptor.
- Ptr<TimeSeriesAdaptor> timeSeriesAdaptor = CreateObject<TimeSeriesAdaptor> ();
-
- // Enable logging of data for the time series adaptor.
- timeSeriesAdaptor->Enable ();
-
// Add this time series adaptor to the map so that it can be used.
buherman 2015/06/29 08:53:53 time series adaptor -> collector
- m_timeSeriesAdaptorMap[adaptorName] = timeSeriesAdaptor;
+ m_collectorMap[collectorName] = collector;
}
void
@@ -251,7 +284,7 @@
if (onlyOneAggregator)
{
// Get a pointer to the aggregator.
- Ptr<FileAggregator> singleAggregator = GetAggregatorSingle ();
+ Ptr<FileAggregator> singleAggregator = GetAggregator ();
m_aggregatorMap[aggregatorName] = singleAggregator;
return;
@@ -305,6 +338,12 @@
Ptr<FileAggregator>
FileHelper::GetAggregatorSingle ()
{
+ return GetAggregator ();
+}
+
+Ptr<FileAggregator>
+FileHelper::GetAggregator ()
+{
NS_LOG_FUNCTION (this);
// Do a lazy construction of the single aggregator if it hasn't
@@ -448,7 +487,7 @@
}
void
-FileHelper::ConnectProbeToAggregator (const std::string &typeId,
+FileHelper::CreateDataCollectionChain (const std::string &typeId,
const std::string &matchIdentifier,
const std::string &path,
const std::string &probeTraceSource,
@@ -472,102 +511,116 @@
// Add the probe to the map of probes, which will keep the probe in
// memory after this function ends.
- AddProbe (typeId, probeName, path);
+ AddProbeToMap (typeId, probeName, path);
// Because the callbacks to the probes' trace sources don't use the
// probe's context, a unique adaptor needs to be created for each
buherman 2015/06/29 08:53:53 adaptor -> collector
// probe context so that information is not lost.
- AddTimeSeriesAdaptor (probeContext);
+ AddCollector (probeContext);
- // Connect the probe to the adaptor.
- if (m_probeMap[probeName].second == "ns3::DoubleProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkDouble,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::BooleanProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkBoolean,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::PacketProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger32,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::ApplicationPacketProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger32,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::Ipv4PacketProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger32,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::Ipv6PacketProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger32,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::Uinteger8Probe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger8,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::Uinteger16Probe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger16,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::Uinteger32Probe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkUinteger32,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else if (m_probeMap[probeName].second == "ns3::TimeProbe")
- {
- m_probeMap[probeName].first->TraceConnectWithoutContext
- (probeTraceSource,
- MakeCallback (&TimeSeriesAdaptor::TraceSinkDouble,
- m_timeSeriesAdaptorMap[probeContext]));
- }
- else
- {
- NS_FATAL_ERROR ("Unknown probe type " << m_probeMap[probeName].second << "; need to add support in the helper for this");
- }
+ ConnectProbeToCollector (probeTraceSource, probeName, probeContext);
// Add the aggregator to the map of aggregators, which will keep the
// aggregator in memory after this function ends.
std::string outputFileName = outputFileNameWithoutExtension + ".txt";
AddAggregator (probeContext, outputFileName, onlyOneAggregator);
- // Connect the adaptor to the aggregator.
- std::string adaptorTraceSource = "Output";
- m_timeSeriesAdaptorMap[probeContext]->TraceConnect
- (adaptorTraceSource,
+ ConnectCollectorToAggregator (probeContext);
+}
+
+void
+FileHelper::ConnectCollectorToAggregator (const std::string probeContext)
+{
+ // Connect the collector to the aggregator.
+ std::string collectorTraceSource = "Output";
+ m_collectorMap[probeContext]->TraceConnect
+ (collectorTraceSource,
probeContext,
MakeCallback (&FileAggregator::Write2d,
m_aggregatorMap[probeContext]));
}
+void
+FileHelper::ConnectProbeToCollector (const std::string probeTraceSource,
+ const std::string probeName,
+ const std::string probeContext)
+{
+ // Connect the probe to the adaptor.
buherman 2015/06/29 08:53:53 adaptor -> collector
+ if (m_probeMap[probeName].second == "ns3::DoubleProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkDouble,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::BooleanProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkBoolean,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::PacketProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger32,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::ApplicationPacketProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger32,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::Ipv4PacketProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger32,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::Ipv6PacketProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger32,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::Uinteger8Probe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger8,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::Uinteger16Probe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger16,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::Uinteger32Probe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkUinteger32,
+ m_collectorMap[probeContext]));
+ }
+ else if (m_probeMap[probeName].second == "ns3::TimeProbe")
+ {
+ m_probeMap[probeName].first->TraceConnectWithoutContext
+ (probeTraceSource,
+ MakeCallback (&Collector::TraceSinkDouble,
buherman 2015/06/29 08:53:53 TraceSinkDouble -> TraceSinkTime
+ m_collectorMap[probeContext]));
+ }
+ else
+ {
+ NS_FATAL_ERROR ("Unknown probe type " << m_probeMap[probeName].second << "; need to add support in the helper for this");
+ }
+}
+
} // namespace ns3

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b