Bug 1983 - FlowMonitor returns containers copies instead of references
authorTommaso Pecorella <tommaso.pecorella@unifi.it>
Fri, 19 Sep 2014 21:25:48 +0200
changeset 10962 8beb54fffadc
parent 10961 de4573473570
child 10963 44a4d3139cfa
Bug 1983 - FlowMonitor returns containers copies instead of references
RELEASE_NOTES
examples/wireless/wifi-hidden-terminal.cc
src/flow-monitor/bindings/modulegen__gcc_ILP32.py
src/flow-monitor/bindings/modulegen__gcc_LP64.py
src/flow-monitor/model/flow-monitor.cc
src/flow-monitor/model/flow-monitor.h
--- a/RELEASE_NOTES	Fri Sep 19 21:23:55 2014 +0200
+++ b/RELEASE_NOTES	Fri Sep 19 21:25:48 2014 +0200
@@ -24,6 +24,7 @@
 
 Bugs fixed
 ----------
+- Bug 1983 - FlowMonitor returns containers copies instead of references.
 - Bug 1991 - PcapFileWrapper::CaptureSize attribute (snaplen) has no effect.
 
 Known issues
--- a/examples/wireless/wifi-hidden-terminal.cc	Fri Sep 19 21:23:55 2014 +0200
+++ b/examples/wireless/wifi-hidden-terminal.cc	Fri Sep 19 21:25:48 2014 +0200
@@ -149,7 +149,7 @@
   // 10. Print per flow statistics
   monitor->CheckForLostPackets ();
   Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
-  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
+  FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats ();
   for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
     {
       // first 2 FlowIds are for ECHO apps, we don't want to display them
--- a/src/flow-monitor/bindings/modulegen__gcc_ILP32.py	Fri Sep 19 21:23:55 2014 +0200
+++ b/src/flow-monitor/bindings/modulegen__gcc_ILP32.py	Fri Sep 19 21:25:48 2014 +0200
@@ -4239,14 +4239,14 @@
     cls.add_method('CheckForLostPackets', 
                    'void', 
                    [param('ns3::Time', 'maxDelay')])
-    ## flow-monitor.h (module 'flow-monitor'): std::vector<ns3::Ptr<ns3::FlowProbe>, std::allocator<ns3::Ptr<ns3::FlowProbe> > > ns3::FlowMonitor::GetAllProbes() const [member function]
+    ## flow-monitor.h (module 'flow-monitor'): std::vector<ns3::Ptr<ns3::FlowProbe>, std::allocator<ns3::Ptr<ns3::FlowProbe> > > const & ns3::FlowMonitor::GetAllProbes() const [member function]
     cls.add_method('GetAllProbes', 
-                   'std::vector< ns3::Ptr< ns3::FlowProbe > >', 
-                   [], 
-                   is_const=True)
-    ## flow-monitor.h (module 'flow-monitor'): std::map<unsigned int, ns3::FlowMonitor::FlowStats, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, ns3::FlowMonitor::FlowStats> > > ns3::FlowMonitor::GetFlowStats() const [member function]
+                   'std::vector< ns3::Ptr< ns3::FlowProbe > > const &', 
+                   [], 
+                   is_const=True)
+    ## flow-monitor.h (module 'flow-monitor'): std::map<unsigned int, ns3::FlowMonitor::FlowStats, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, ns3::FlowMonitor::FlowStats> > > const & ns3::FlowMonitor::GetFlowStats() const [member function]
     cls.add_method('GetFlowStats', 
-                   'std::map< unsigned int, ns3::FlowMonitor::FlowStats >', 
+                   'std::map< unsigned int, ns3::FlowMonitor::FlowStats > const &', 
                    [], 
                    is_const=True)
     ## flow-monitor.h (module 'flow-monitor'): ns3::TypeId ns3::FlowMonitor::GetInstanceTypeId() const [member function]
--- a/src/flow-monitor/bindings/modulegen__gcc_LP64.py	Fri Sep 19 21:23:55 2014 +0200
+++ b/src/flow-monitor/bindings/modulegen__gcc_LP64.py	Fri Sep 19 21:25:48 2014 +0200
@@ -4239,14 +4239,14 @@
     cls.add_method('CheckForLostPackets', 
                    'void', 
                    [param('ns3::Time', 'maxDelay')])
-    ## flow-monitor.h (module 'flow-monitor'): std::vector<ns3::Ptr<ns3::FlowProbe>, std::allocator<ns3::Ptr<ns3::FlowProbe> > > ns3::FlowMonitor::GetAllProbes() const [member function]
+    ## flow-monitor.h (module 'flow-monitor'): std::vector<ns3::Ptr<ns3::FlowProbe>, std::allocator<ns3::Ptr<ns3::FlowProbe> > > const & ns3::FlowMonitor::GetAllProbes() const [member function]
     cls.add_method('GetAllProbes', 
-                   'std::vector< ns3::Ptr< ns3::FlowProbe > >', 
-                   [], 
-                   is_const=True)
-    ## flow-monitor.h (module 'flow-monitor'): std::map<unsigned int, ns3::FlowMonitor::FlowStats, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, ns3::FlowMonitor::FlowStats> > > ns3::FlowMonitor::GetFlowStats() const [member function]
+                   'std::vector< ns3::Ptr< ns3::FlowProbe > > const &', 
+                   [], 
+                   is_const=True)
+    ## flow-monitor.h (module 'flow-monitor'): std::map<unsigned int, ns3::FlowMonitor::FlowStats, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, ns3::FlowMonitor::FlowStats> > > const & ns3::FlowMonitor::GetFlowStats() const [member function]
     cls.add_method('GetFlowStats', 
-                   'std::map< unsigned int, ns3::FlowMonitor::FlowStats >', 
+                   'std::map< unsigned int, ns3::FlowMonitor::FlowStats > const &', 
                    [], 
                    is_const=True)
     ## flow-monitor.h (module 'flow-monitor'): ns3::TypeId ns3::FlowMonitor::GetInstanceTypeId() const [member function]
--- a/src/flow-monitor/model/flow-monitor.cc	Fri Sep 19 21:23:55 2014 +0200
+++ b/src/flow-monitor/model/flow-monitor.cc	Fri Sep 19 21:25:48 2014 +0200
@@ -107,7 +107,7 @@
 inline FlowMonitor::FlowStats&
 FlowMonitor::GetStatsForFlow (FlowId flowId)
 {
-  std::map<FlowId, FlowStats>::iterator iter;
+  FlowStatsContainerI iter;
   iter = m_flowStats.find (flowId);
   if (iter == m_flowStats.end ())
     {
@@ -282,7 +282,7 @@
     }
 }
 
-std::map<FlowId, FlowMonitor::FlowStats>
+const FlowMonitor::FlowStatsContainer&
 FlowMonitor::GetFlowStats () const
 {
   return m_flowStats;
@@ -300,8 +300,7 @@
       if (now - iter->second.lastSeenTime >= maxDelay)
         {
           // packet is considered lost, add it to the loss statistics
-          std::map<FlowId, FlowStats>::iterator
-            flow = m_flowStats.find (iter->first.first);
+          FlowStatsContainerI flow = m_flowStats.find (iter->first.first);
           NS_ASSERT (flow != m_flowStats.end ());
           flow->second.lostPackets++;
 
@@ -341,7 +340,8 @@
   m_flowProbes.push_back (probe);
 }
 
-std::vector< Ptr<FlowProbe> >
+
+const FlowMonitor::FlowProbeContainer&
 FlowMonitor::GetAllProbes () const
 {
   return m_flowProbes;
@@ -408,7 +408,7 @@
   indent += 2;
   INDENT (indent); os << "<FlowStats>\n";
   indent += 2;
-  for (std::map<FlowId, FlowStats>::const_iterator flowI = m_flowStats.begin ();
+  for (FlowStatsContainerCI flowI = m_flowStats.begin ();
        flowI != m_flowStats.end (); flowI++)
     {
 
--- a/src/flow-monitor/model/flow-monitor.h	Fri Sep 19 21:23:55 2014 +0200
+++ b/src/flow-monitor/model/flow-monitor.h	Fri Sep 19 21:25:48 2014 +0200
@@ -211,16 +211,30 @@
   void CheckForLostPackets (Time maxDelay);
 
   // --- methods to get the results ---
+
+  /// Container: FlowId, FlowStats
+  typedef std::map<FlowId, FlowStats> FlowStatsContainer;
+  /// Container Iterator: FlowId, FlowStats
+  typedef std::map<FlowId, FlowStats>::iterator FlowStatsContainerI;
+  /// Container Const Iterator: FlowId, FlowStats
+  typedef std::map<FlowId, FlowStats>::const_iterator FlowStatsContainerCI;
+  /// Container: FlowProbe
+  typedef std::vector< Ptr<FlowProbe> > FlowProbeContainer;
+  /// Container Iterator: FlowProbe
+  typedef std::vector< Ptr<FlowProbe> >::iterator FlowProbeContainerI;
+  /// Container Const Iterator: FlowProbe
+  typedef std::vector< Ptr<FlowProbe> >::const_iterator FlowProbeContainerCI;
+
   /// Retrieve all collected the flow statistics.  Note, if the
   /// FlowMonitor has not stopped monitoring yet, you should call
   /// CheckForLostPackets() to make sure all possibly lost packets are
   /// accounted for.
   /// \returns the flows statistics
-  std::map<FlowId, FlowStats> GetFlowStats () const;
+  const FlowStatsContainer& GetFlowStats () const;
 
   /// Get a list of all FlowProbe's associated with this FlowMonitor
   /// \returns a list of all the probes
-  std::vector< Ptr<FlowProbe> > GetAllProbes () const;
+  const FlowProbeContainer& GetAllProbes () const;
 
   /// Serializes the results to an std::ostream in XML format
   /// \param os the output stream
@@ -228,12 +242,14 @@
   /// \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
@@ -257,13 +273,13 @@
   };
 
   /// FlowId --> FlowStats
-  std::map<FlowId, FlowStats> m_flowStats;
+  FlowStatsContainer m_flowStats;
 
   /// (FlowId,PacketId) --> TrackedPacket
   typedef std::map< std::pair<FlowId, FlowPacketId>, TrackedPacket> TrackedPacketMap;
   TrackedPacketMap m_trackedPackets; //!< Tracked packets
   Time m_maxPerHopDelay; //!< Minimum per-hop delay
-  std::vector< Ptr<FlowProbe> > m_flowProbes; //!< all the FlowProbes
+  FlowProbeContainer m_flowProbes; //!< all the FlowProbes
 
   // note: this is needed only for serialization
   std::list<Ptr<FlowClassifier> > m_classifiers; //!< the FlowClassifiers