26 #include "ns3/abort.h"
28 #include "ns3/config.h"
29 #include "ns3/get-wildcard-matches.h"
40 m_outputFileNameWithoutExtension (
"file-helper"),
41 m_hasHeadingBeenSet (false)
53 m_fileType (fileType),
54 m_outputFileNameWithoutExtension (outputFileNameWithoutExtension),
55 m_hasHeadingBeenSet (false)
78 " may be destroyed if no references remain.");
92 const std::string &path,
93 const std::string &probeTraceSource)
97 std::string pathWithoutLastToken;
98 std::string lastToken;
101 bool pathHasNoWildcards = path.find (
"*") == std::string::npos;
104 size_t lastSlash = path.find_last_of (
"/");
105 if (lastSlash == std::string::npos)
107 pathWithoutLastToken = path;
113 pathWithoutLastToken = path.substr (0, lastSlash);
116 lastToken = path.substr (lastSlash + 1, std::string::npos);
122 uint32_t matchCount = matches.
GetN ();
125 std::string matchIdentifier;
128 bool onlyOneAggregator;
131 if (matchCount == 1 && pathHasNoWildcards)
136 matchIdentifier =
"0";
137 onlyOneAggregator =
true;
145 else if (matchCount > 0)
148 for (uint32_t i = 0; i < matchCount; i++)
151 std::ostringstream matchIdentifierStream;
152 matchIdentifierStream << i;
153 matchIdentifier = matchIdentifierStream.str ();
154 onlyOneAggregator =
false;
158 std::string wildcardSeparator =
"-";
182 const std::string &probeName,
183 const std::string &path)
204 probe->SetName (probeName);
207 probe->ConnectByPath (path);
213 m_probeMap[probeName] = std::make_pair (probe, typeId);
224 NS_ABORT_MSG (
"That time series adaptor has already been added");
231 timeSeriesAdaptor->Enable ();
239 const std::string &outputFileName,
240 bool onlyOneAggregator)
242 NS_LOG_FUNCTION (
this << aggregatorName << outputFileName << onlyOneAggregator);
247 NS_ABORT_MSG (
"That file aggregator has already been added");
252 if (onlyOneAggregator)
263 CreateObject<FileAggregator> (outputFileName,
m_fileType);
278 multipleAggregator->SetHeading (
m_heading);
281 multipleAggregator->Enable ();
293 std::map<std::string, std::pair <Ptr<Probe>, std::string> >::const_iterator mapIterator =
m_probeMap.find (probeName);
298 return mapIterator->second.first;
342 const std::string &outputFileName)
354 bool onlyOneAggregator =
false;
453 const std::string &matchIdentifier,
454 const std::string &path,
455 const std::string &probeTraceSource,
456 const std::string &outputFileNameWithoutExtension,
457 bool onlyOneAggregator)
459 NS_LOG_FUNCTION (
this << typeId << matchIdentifier << path << probeTraceSource
460 << outputFileNameWithoutExtension << onlyOneAggregator);
466 std::ostringstream probeNameStream;
468 std::string probeName = probeNameStream.str ();
471 std::string probeContext = probeName
472 +
"/" + matchIdentifier +
"/" + probeTraceSource;
484 if (
m_probeMap[probeName].second ==
"ns3::DoubleProbe")
486 m_probeMap[probeName].first->TraceConnectWithoutContext
491 else if (
m_probeMap[probeName].second ==
"ns3::BooleanProbe")
493 m_probeMap[probeName].first->TraceConnectWithoutContext
498 else if (
m_probeMap[probeName].second ==
"ns3::PacketProbe")
500 m_probeMap[probeName].first->TraceConnectWithoutContext
505 else if (
m_probeMap[probeName].second ==
"ns3::ApplicationPacketProbe")
507 m_probeMap[probeName].first->TraceConnectWithoutContext
512 else if (
m_probeMap[probeName].second ==
"ns3::Ipv4PacketProbe")
514 m_probeMap[probeName].first->TraceConnectWithoutContext
519 else if (
m_probeMap[probeName].second ==
"ns3::Ipv6PacketProbe")
521 m_probeMap[probeName].first->TraceConnectWithoutContext
526 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger8Probe")
528 m_probeMap[probeName].first->TraceConnectWithoutContext
533 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger16Probe")
535 m_probeMap[probeName].first->TraceConnectWithoutContext
540 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger32Probe")
542 m_probeMap[probeName].first->TraceConnectWithoutContext
549 NS_FATAL_ERROR (
"Unknown probe type " <<
m_probeMap[probeName].second <<
"; need to add support in the helper for this");
554 std::string outputFileName = outputFileNameWithoutExtension +
".txt";
555 AddAggregator (probeContext, outputFileName, onlyOneAggregator);
558 std::string adaptorTraceSource =
"Output";
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
std::string m_3dFormat
Format string for 3D format C-style sprintf() function.
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
std::string m_6dFormat
Format string for 6D format C-style sprintf() function.
std::string m_9dFormat
Format string for 9D format C-style sprintf() function.
void Set4dFormat(const std::string &format)
Sets the 4D format string for the C-style sprintf() function.
std::string m_4dFormat
Format string for 4D format C-style sprintf() function.
Ptr< FileAggregator > m_aggregator
The single aggregator that is always created in the constructor.
void Set8dFormat(const std::string &format)
Sets the 8D format string for the C-style sprintf() function.
void SetTypeId(TypeId tid)
std::string GetMatchedPath(uint32_t i) const
void Set6dFormat(const std::string &format)
Sets the 6D format string for the C-style sprintf() function.
void Set5dFormat(const std::string &format)
Sets the 5D format string for the C-style sprintf() function.
void Set10dFormat(const std::string &format)
Sets the 10D format string for the C-style sprintf() function.
#define NS_FATAL_ERROR(msg)
fatal error handling
std::string m_7dFormat
Format string for 7D format C-style sprintf() function.
void AddProbe(const std::string &typeId, const std::string &probeName, const std::string &path)
Adds a probe to be used to write values to files.
This aggregator sends values it receives to a file.
Config::MatchContainer LookupMatches(std::string path)
void AddAggregator(const std::string &aggregatorName, const std::string &outputFileName, bool onlyOneAggregator)
Adds an aggregator to be used to write values to files.
void Write2d(std::string context, double v1, double v2)
Writes 2 values to the file.
Ptr< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
void Set9dFormat(const std::string &format)
Sets the 9D format string for the C-style sprintf() function.
Ptr< Object > Create(void) const
uint32_t m_fileProbeCount
Number of file probes that have been created.
std::string m_10dFormat
Format string for 10D format C-style sprintf() function.
std::string m_8dFormat
Format string for 8D format C-style sprintf() function.
FileType
The type of file written by the aggregator.
FileHelper()
Constructs a file helper that will create a space separated file named "file-helper.txt" unless it is later configured otherwise.
std::string m_heading
Heading line for the outputfile.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Ptr< FileAggregator > GetAggregatorSingle()
Gets the single aggregator that is always constructed.
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to write the file.
uint32_t GetN(void) const
ObjectFactory m_factory
Used to create the probes and collectors as they are added.
void Set7dFormat(const std::string &format)
Sets the 7D format string for the C-style sprintf() function.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
std::map< std::string, Ptr< FileAggregator > > m_aggregatorMap
Maps aggregator names to aggregators when multiple aggregators are needed.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
enum FileAggregator::FileType m_fileType
Determines the kind of file written by the aggregator.
Ptr< FileAggregator > GetAggregatorMultiple(const std::string &aggregatorName, const std::string &outputFileName)
Gets one of the multiple aggregators from the map.
void SetHeading(const std::string &heading)
Sets the heading string that will be printed on the first line of the file.
void ConfigureFile(const std::string &outputFileNameWithoutExtension, enum FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED)
void Set1dFormat(const std::string &format)
Sets the 1D format string for the C-style sprintf() function.
std::string m_1dFormat
Format string for 1D format C-style sprintf() function.
hold a set of objects which match a specific search string.
void ConnectProbeToAggregator(const std::string &typeId, const std::string &matchIdentifier, const std::string &path, const std::string &probeTraceSource, const std::string &outputFileNameWithoutExtension, bool onlyOneAggregator)
Connects the probe to the aggregator.
std::string m_2dFormat
Format string for 2D format C-style sprintf() function.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
void Set3dFormat(const std::string &format)
Sets the 3D format string for the C-style sprintf() function.
bool m_hasHeadingBeenSet
Indicates if the heading line for the file has been set.
std::string m_5dFormat
Format string for 5D format C-style sprintf() function.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_t valued trace sources.
void WriteProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource)
void TraceSinkDouble(double oldData, double newData)
Trace sink for receiving data from double valued trace sources.
void TraceSinkBoolean(bool oldData, bool newData)
Trace sink for receiving data from bool valued trace sources.
Ptr< T > GetObject(void) const
std::string GetWildcardMatches(const std::string &configPath, const std::string &matchedPath, const std::string &wildcardSeparator)
Returns the text matches from the matched path for each of the wildcards in the Config path...
std::string m_outputFileNameWithoutExtension
The name of the output file to created without its extension.
void Set2dFormat(const std::string &format)
Sets the 2D format string for the C-style sprintf() function.