27 #include "ns3/abort.h"
28 #include "ns3/assert.h"
29 #include "ns3/config.h"
31 #include "ns3/get-wildcard-matches.h"
40 m_outputFileNameWithoutExtension (
"gnuplot-helper"),
41 m_title (
"Gnuplot Helper Plot"),
42 m_xLegend (
"X Values"),
43 m_yLegend (
"Y Values"),
44 m_terminalType (
"png")
53 const std::string &title,
54 const std::string &xLegend,
55 const std::string &yLegend,
56 const std::string &terminalType)
59 m_outputFileNameWithoutExtension (outputFileNameWithoutExtension),
63 m_terminalType (terminalType)
78 const std::string &title,
79 const std::string &xLegend,
80 const std::string &yLegend,
81 const std::string &terminalType)
84 << xLegend << yLegend << terminalType);
90 " may be destroyed if no references remain.");
106 const std::string &path,
107 const std::string &probeTraceSource,
108 const std::string &title,
111 NS_LOG_FUNCTION (
this << typeId << path << probeTraceSource << title << keyLocation);
117 aggregator->SetTitle (
m_title +
" \\n\\nProbe Path: " + path);
123 aggregator->SetKeyLocation (keyLocation);
125 std::string pathWithoutLastToken;
126 std::string lastToken;
129 bool pathHasNoWildcards = path.find (
"*") == std::string::npos;
132 size_t lastSlash = path.find_last_of (
"/");
133 if (lastSlash == std::string::npos)
135 pathWithoutLastToken = path;
141 pathWithoutLastToken = path.substr (0, lastSlash);
144 lastToken = path.substr (lastSlash + 1, std::string::npos);
150 uint32_t matchCount = matches.
GetN ();
153 std::string matchIdentifier;
156 if (matchCount == 1 && pathHasNoWildcards)
161 matchIdentifier =
"0";
168 else if (matchCount > 0)
171 for (uint32_t i = 0; i < matchCount; i++)
174 std::ostringstream matchIdentifierStream;
175 matchIdentifierStream << i;
176 matchIdentifier = matchIdentifierStream.str ();
180 std::string wildcardSeparator =
" ";
191 title +
"-" + wildcardMatches);
203 const std::string &probeName,
204 const std::string &path)
225 probe->SetName (probeName);
228 probe->ConnectByPath (path);
234 m_probeMap[probeName] = std::make_pair (probe, typeId);
245 NS_ABORT_MSG (
"That time series adaptor has already been added");
252 timeSeriesAdaptor->Enable ();
262 std::map<std::string, std::pair <Ptr<Probe>, std::string> >::const_iterator mapIterator =
m_probeMap.find (probeName);
267 return mapIterator->second.first;
308 const std::string &matchIdentifier,
309 const std::string &path,
310 const std::string &probeTraceSource,
311 const std::string &title)
313 NS_LOG_FUNCTION (
this << typeId << matchIdentifier << path << probeTraceSource
322 std::ostringstream probeNameStream;
324 std::string probeName = probeNameStream.str ();
327 std::string probeContext = probeName
328 +
"/" + matchIdentifier +
"/" + probeTraceSource;
340 if (
m_probeMap[probeName].second ==
"ns3::DoubleProbe")
342 m_probeMap[probeName].first->TraceConnectWithoutContext
347 else if (
m_probeMap[probeName].second ==
"ns3::BooleanProbe")
349 m_probeMap[probeName].first->TraceConnectWithoutContext
354 else if (
m_probeMap[probeName].second ==
"ns3::PacketProbe")
356 m_probeMap[probeName].first->TraceConnectWithoutContext
361 else if (
m_probeMap[probeName].second ==
"ns3::ApplicationPacketProbe")
363 m_probeMap[probeName].first->TraceConnectWithoutContext
368 else if (
m_probeMap[probeName].second ==
"ns3::Ipv4PacketProbe")
370 m_probeMap[probeName].first->TraceConnectWithoutContext
375 else if (
m_probeMap[probeName].second ==
"ns3::Ipv6PacketProbe")
377 m_probeMap[probeName].first->TraceConnectWithoutContext
382 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger8Probe")
384 m_probeMap[probeName].first->TraceConnectWithoutContext
389 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger16Probe")
391 m_probeMap[probeName].first->TraceConnectWithoutContext
396 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger32Probe")
398 m_probeMap[probeName].first->TraceConnectWithoutContext
405 NS_FATAL_ERROR (
"Unknown probe type " <<
m_probeMap[probeName].second <<
"; need to add support in the helper for this");
409 std::string adaptorTraceSource =
"Output";
416 aggregator->Add2dDataset (probeContext, title);
void ConnectProbeToAggregator(const std::string &typeId, const std::string &matchIdentifier, const std::string &path, const std::string &probeTraceSource, const std::string &title)
Connects the probe to the aggregator.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void PlotProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource, const std::string &title, enum GnuplotAggregator::KeyLocation keyLocation=GnuplotAggregator::KEY_INSIDE)
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to make the plot.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
void SetTypeId(TypeId tid)
void Write2d(std::string context, double x, double y)
Writes a 2D value to a 2D gnuplot dataset.
std::string GetMatchedPath(uint32_t i) const
std::string m_xLegend
Legend for the x axis.
uint32_t m_plotProbeCount
Number of plot probes that have been created.
ObjectFactory m_factory
Used to create the probes and collectors as they are added.
#define NS_FATAL_ERROR(msg)
fatal error handling
std::string m_outputFileNameWithoutExtension
The name of the output file to created without its extension.
void ConfigurePlot(const std::string &outputFileNameWithoutExtension, const std::string &title, const std::string &xLegend, const std::string &yLegend, const std::string &terminalType="png")
Config::MatchContainer LookupMatches(std::string path)
Ptr< GnuplotAggregator > m_aggregator
The aggregator used to make the plots.
Ptr< Object > Create(void) const
void AddProbe(const std::string &typeId, const std::string &probeName, const std::string &path)
Adds a probe to be used to make the plot.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void ConstructAggregator()
Constructs the aggregator.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
uint32_t GetN(void) const
Ptr< GnuplotAggregator > GetAggregator()
Gets the aggregator.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
hold a set of objects which match a specific search string.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
KeyLocation
The location of the key in the plot.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_t valued trace sources.
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< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
std::string m_yLegend
Legend for the y axis.
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_title
Title string to use for this plot.
std::string m_terminalType
Terminal type for the plot.