From 1ff598b75c1a9765098eac1f5a496604dd1d2ed7 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Mon, 17 Mar 2014 19:34:43 +0100 Subject: [PATCH] Bug 1842 - FlowMonitor SerializeToXml should be called by the helper --- RELEASE_NOTES | 3 ++ examples/routing/simple-global-routing.cc | 5 ++-- examples/tcp/tcp-variants-comparison.cc | 5 ++-- examples/wireless/multirate.cc | 5 ++-- .../helper/flow-monitor-helper.cc | 29 +++++++++++++++++++ src/flow-monitor/helper/flow-monitor-helper.h | 26 +++++++++++++++++ 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index d6d287545..fba0bbc0d 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -29,6 +29,8 @@ New user-visible features ``ns3::CqaFfMacScheduler`` object. - SixLowPan model can now use uncompressed IPv6 headers. An option to define the minimum compressed packet size has been added. +- FlowMonitor "SerializeToXml" functions are now directly available + from the Helper. Bugs fixed ---------- @@ -43,6 +45,7 @@ Bugs fixed - Bug 1837 - AODV crashes when using multiple interfaces - Bug 1838 - FlowMonitorHelper must not be copied. - Bug 1841 - FlowMonitor fails to install if IPv4 is not installed in the node +- Bug 1842 - FlowMonitor SerializeToXml should be called by the helper - Bug 1846 - IPv6 should send Destination Unreachable if no route is available - Bug 1852 - cairo-wideint-private.h error cannot find definitions for fixed-width integral types - Bug 1853 - NS_LOG_FUNCTION broken on OSX 10.9 diff --git a/examples/routing/simple-global-routing.cc b/examples/routing/simple-global-routing.cc index 0246a105f..506bd3b74 100644 --- a/examples/routing/simple-global-routing.cc +++ b/examples/routing/simple-global-routing.cc @@ -149,11 +149,10 @@ main (int argc, char *argv[]) p2p.EnablePcapAll ("simple-global-routing"); // Flow Monitor - Ptr flowmon; FlowMonitorHelper flowmonHelper; if (enableFlowMonitor) { - flowmon = flowmonHelper.InstallAll (); + flowmonHelper.InstallAll (); } NS_LOG_INFO ("Run Simulation."); @@ -163,7 +162,7 @@ main (int argc, char *argv[]) if (enableFlowMonitor) { - flowmon->SerializeToXmlFile ("simple-global-routing.flowmon", false, false); + flowmonHelper.SerializeToXmlFile ("simple-global-routing.flowmon", false, false); } Simulator::Destroy (); diff --git a/examples/tcp/tcp-variants-comparison.cc b/examples/tcp/tcp-variants-comparison.cc index 7cc0769c8..ee73a39c2 100644 --- a/examples/tcp/tcp-variants-comparison.cc +++ b/examples/tcp/tcp-variants-comparison.cc @@ -339,11 +339,10 @@ int main (int argc, char *argv[]) LocalLink.EnablePcapAll("TcpVariantsComparison", true); // Flow monitor - Ptr flowMonitor; FlowMonitorHelper flowHelper; if (flow_monitor) { - flowMonitor = flowHelper.InstallAll(); + flowHelper.InstallAll(); } Simulator::Stop (Seconds(stop_time)); @@ -351,7 +350,7 @@ int main (int argc, char *argv[]) if (flow_monitor) { - flowMonitor->SerializeToXmlFile("TcpVariantsComparison.flowmonitor", true, true); + flowHelper.SerializeToXmlFile("TcpVariantsComparison.flowmonitor", true, true); } Simulator::Destroy (); diff --git a/examples/wireless/multirate.cc b/examples/wireless/multirate.cc index 920bb33be..9e4d1a373 100644 --- a/examples/wireless/multirate.cc +++ b/examples/wireless/multirate.cc @@ -508,12 +508,11 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, phy.EnableAsciiAll (ascii.CreateFileStream (GetOutputFileName () + ".tr")); } - Ptr flowmon; FlowMonitorHelper flowmonHelper; if (enableFlowMon) { - flowmon = flowmonHelper.InstallAll (); + flowmonHelper.InstallAll (); } Simulator::Stop (Seconds (totalTime)); @@ -521,7 +520,7 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, if (enableFlowMon) { - flowmon->SerializeToXmlFile ((GetOutputFileName () + ".flomon"), false, false); + flowmonHelper.SerializeToXmlFile ((GetOutputFileName () + ".flomon"), false, false); } Simulator::Destroy (); diff --git a/src/flow-monitor/helper/flow-monitor-helper.cc b/src/flow-monitor/helper/flow-monitor-helper.cc index 1b03b628c..dd55e96e5 100644 --- a/src/flow-monitor/helper/flow-monitor-helper.cc +++ b/src/flow-monitor/helper/flow-monitor-helper.cc @@ -120,5 +120,34 @@ FlowMonitorHelper::InstallAll () return m_flowMonitor; } +void +FlowMonitorHelper::SerializeToXmlStream (std::ostream &os, int indent, bool enableHistograms, bool enableProbes) +{ + if (m_flowMonitor) + { + m_flowMonitor->SerializeToXmlStream (os, indent, enableHistograms, enableProbes); + } +} + +std::string +FlowMonitorHelper::SerializeToXmlString (int indent, bool enableHistograms, bool enableProbes) +{ + std::ostringstream os; + if (m_flowMonitor) + { + m_flowMonitor->SerializeToXmlStream (os, indent, enableHistograms, enableProbes); + } + return os.str (); +} + +void +FlowMonitorHelper::SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes) +{ + if (m_flowMonitor) + { + m_flowMonitor->SerializeToXmlFile (fileName, enableHistograms, enableProbes); + } +} + } // namespace ns3 diff --git a/src/flow-monitor/helper/flow-monitor-helper.h b/src/flow-monitor/helper/flow-monitor-helper.h index aa04a3b9c..46b91b7b2 100644 --- a/src/flow-monitor/helper/flow-monitor-helper.h +++ b/src/flow-monitor/helper/flow-monitor-helper.h @@ -79,6 +79,32 @@ public: */ Ptr GetClassifier (); + /** + * Serializes the results to an std::ostream in XML format + * \param os the output stream + * \param indent number of spaces to use as base indentation level + * \param enableHistograms if true, include also the histograms in the output + * \param enableProbes if true, include also the per-probe/flow pair statistics in the output + */ + void SerializeToXmlStream (std::ostream &os, int indent, bool enableHistograms, bool enableProbes); + + /** + * Same as SerializeToXmlStream, but returns the output as a std::string + * \param indent number of spaces to use as base indentation level + * \param enableHistograms if true, include also the histograms in the output + * \param enableProbes if true, include also the per-probe/flow pair statistics in the output + * \return the XML output as string + */ + std::string SerializeToXmlString (int indent, bool enableHistograms, bool enableProbes); + + /** + * Same as SerializeToXmlStream, but writes to a file instead + * \param fileName name or path of the output file that will be created + * \param enableHistograms if true, include also the histograms in the output + * \param enableProbes if true, include also the per-probe/flow pair statistics in the output + */ + void SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes); + private: /** * \brief Copy constructor