FlowMonitor start/stop methods
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Thu, 30 Apr 2009 18:43:24 +0100
changeset 3942 dce52b9bcdad
parent 3941 009dc59d7502
child 3943 c2952541de20
FlowMonitor start/stop methods
bindings/python/callbacks_list.py
bindings/python/ns3_module_flow_monitor.py
examples/flowmon.py
src/contrib/flow-monitor/design.txt
src/contrib/flow-monitor/flow-monitor.cc
src/contrib/flow-monitor/flow-monitor.h
--- a/bindings/python/callbacks_list.py	Thu Apr 30 16:17:06 2009 +0100
+++ b/bindings/python/callbacks_list.py	Thu Apr 30 18:43:24 2009 +0100
@@ -5,10 +5,10 @@
     ['void', 'ns3::Ptr<ns3::Socket>', 'ns3::Address const&', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
     ['bool', 'ns3::Ptr<ns3::Socket>', 'ns3::Address const&', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
     ['void', 'ns3::Ptr<ns3::Packet>', 'ns3::Mac48Address', 'ns3::Mac48Address', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
+    ['bool', 'std::string', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
     ['bool', 'ns3::Ptr<ns3::NetDevice>', 'ns3::Ptr<ns3::Packet const>', 'unsigned short', 'ns3::Address const&', 'ns3::Address const&', 'ns3::NetDevice::PacketType'],
     ['bool', 'ns3::Ptr<ns3::NetDevice>', 'ns3::Ptr<ns3::Packet const>', 'unsigned short', 'ns3::Address const&', 'ns3::empty', 'ns3::empty'],
     ['void', 'ns3::Ptr<ns3::NetDevice>', 'ns3::Ptr<ns3::Packet const>', 'unsigned short', 'ns3::Address const&', 'ns3::Address const&', 'ns3::NetDevice::PacketType'],
     ['void', 'ns3::Ptr<ns3::Packet>', 'double', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
     ['void', 'ns3::Ptr<ns3::Packet>', 'double', 'ns3::WifiMode', 'ns3::WifiPreamble', 'ns3::empty', 'ns3::empty'],
-    ['bool', 'std::string', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
 ]
--- a/bindings/python/ns3_module_flow_monitor.py	Thu Apr 30 16:17:06 2009 +0100
+++ b/bindings/python/ns3_module_flow_monitor.py	Thu Apr 30 18:43:24 2009 +0100
@@ -174,6 +174,22 @@
                    is_const=True, is_virtual=True)
     ## flow-monitor.h: ns3::FlowMonitor::FlowMonitor() [constructor]
     cls.add_constructor([])
+    ## flow-monitor.h: void ns3::FlowMonitor::Start(ns3::Time const & time) [member function]
+    cls.add_method('Start', 
+                   'void', 
+                   [param('ns3::Time const &', 'time')])
+    ## flow-monitor.h: void ns3::FlowMonitor::Stop(ns3::Time const & time) [member function]
+    cls.add_method('Stop', 
+                   'void', 
+                   [param('ns3::Time const &', 'time')])
+    ## flow-monitor.h: void ns3::FlowMonitor::StartRightNow() [member function]
+    cls.add_method('StartRightNow', 
+                   'void', 
+                   [])
+    ## flow-monitor.h: void ns3::FlowMonitor::StopRightNow() [member function]
+    cls.add_method('StopRightNow', 
+                   'void', 
+                   [])
     ## flow-monitor.h: void ns3::FlowMonitor::AddProbe(ns3::Ptr<ns3::FlowProbe> probe) [member function]
     cls.add_method('AddProbe', 
                    'void', 
--- a/examples/flowmon.py	Thu Apr 30 16:17:06 2009 +0100
+++ b/examples/flowmon.py	Thu Apr 30 18:43:24 2009 +0100
@@ -97,6 +97,7 @@
             
     #internet.EnablePcapAll("wifi-olsr")
     flowmon_helper = ns3.FlowMonitorHelper()
+    #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31)))
     monitor = flowmon_helper.InstallAll()
 
     ns3.Simulator.Stop(ns3.Seconds(44.0))
--- a/src/contrib/flow-monitor/design.txt	Thu Apr 30 16:17:06 2009 +0100
+++ b/src/contrib/flow-monitor/design.txt	Thu Apr 30 18:43:24 2009 +0100
@@ -34,7 +34,7 @@
 
 TODO:
 
-  1. Configurable time when to start/stop monitor.
+  1. Configurable time when to start/stop monitor. ***DONE***
   2. Possibly, detect packet losses also via "drop" trace sources
   3. FlowMonitor::FlowStats: add time duration metrics: first flow timestamp, last flow timestamp
       > to calculate bitrates...
--- a/src/contrib/flow-monitor/flow-monitor.cc	Thu Apr 30 16:17:06 2009 +0100
+++ b/src/contrib/flow-monitor/flow-monitor.cc	Thu Apr 30 18:43:24 2009 +0100
@@ -42,6 +42,10 @@
                    TimeValue (Seconds (10.0)),
                    MakeTimeAccessor (&FlowMonitor::m_maxPerHopDelay),
                    MakeTimeChecker ())
+    .AddAttribute ("StartTime", ("The time when the monitoring starts."),
+                   TimeValue (Seconds (0.0)),
+                   MakeTimeAccessor (&FlowMonitor::Start),
+                   MakeTimeChecker ())
     ;
   return tid;
 }
@@ -53,6 +57,7 @@
 }
 
 FlowMonitor::FlowMonitor ()
+ : m_enabled (false)
 {
 }
 
@@ -84,6 +89,10 @@
 void
 FlowMonitor::ReportFirstTx (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t packetId, uint32_t packetSize)
 {
+  if (!m_enabled)
+    {
+      return;
+    }
   TrackedPacket &tracked = m_trackedPackets[std::make_pair (flowId, packetId)];
   tracked.firstSeenTime = Simulator::Now ();
   tracked.lastSeenTime = tracked.firstSeenTime;
@@ -100,6 +109,10 @@
 void
 FlowMonitor::ReportForwarding (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t packetId, uint32_t packetSize)
 {
+  if (!m_enabled)
+    {
+      return;
+    }
   std::pair<FlowId, FlowPacketId> key (flowId, packetId);
   TrackedPacketMap::iterator tracked = m_trackedPackets.find (key);
   if (tracked == m_trackedPackets.end ())
@@ -120,6 +133,10 @@
 void
 FlowMonitor::ReportLastRx (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t packetId, uint32_t packetSize)
 {
+  if (!m_enabled)
+    {
+      return;
+    }
   TrackedPacketMap::iterator tracked = m_trackedPackets.find (std::make_pair (flowId, packetId));
   if (tracked == m_trackedPackets.end ())
     {
@@ -207,5 +224,51 @@
 }
 
 
+void
+FlowMonitor::Start (const Time &time)
+{
+  if (m_enabled)
+    {
+      return;
+    }
+  Simulator::Cancel (m_startEvent);
+  m_startEvent = Simulator::Schedule (time, &FlowMonitor::StartRightNow, Ptr<FlowMonitor> (this));
+}
+
+void
+FlowMonitor::Stop (const Time &time)
+{
+  if (!m_enabled)
+    {
+      return;
+    }
+  Simulator::Cancel (m_stopEvent);
+  m_stopEvent = Simulator::Schedule (time, &FlowMonitor::StopRightNow, Ptr<FlowMonitor> (this));
+}
+
+
+void
+FlowMonitor::StartRightNow ()
+{
+  if (m_enabled)
+    {
+      return;
+    }
+  m_enabled = true;
+}
+
+
+void
+FlowMonitor::StopRightNow ()
+{
+  if (!m_enabled)
+    {
+      return;
+    }
+  m_enabled = false;
+  CheckForLostPackets ();
+}
+
+
 } // namespace ns3
 
--- a/src/contrib/flow-monitor/flow-monitor.h	Thu Apr 30 16:17:06 2009 +0100
+++ b/src/contrib/flow-monitor/flow-monitor.h	Thu Apr 30 18:43:24 2009 +0100
@@ -29,6 +29,7 @@
 #include "ns3/flow-probe.h"
 #include "ns3/flow-classifier.h"
 #include "ns3/nstime.h"
+#include "ns3/event-id.h"
 
 namespace ns3 {
 
@@ -53,6 +54,11 @@
   TypeId GetInstanceTypeId () const;
   FlowMonitor ();
 
+  void Start (const Time &time);
+  void Stop (const Time &time);
+  void StartRightNow ();
+  void StopRightNow ();
+
   // --- methods to be used by the FlowMonitorProbe's only ---
   void AddProbe (Ptr<FlowProbe> probe);
   void ReportFirstTx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
@@ -91,6 +97,10 @@
   Time m_maxPerHopDelay;
   std::vector< Ptr<FlowProbe> > m_flowProbes;
 
+  EventId m_startEvent;
+  EventId m_stopEvent;
+  bool m_enabled;
+
   FlowStats& GetStatsForFlow (FlowId flowId);
   void PeriodicCheckForLostPackets ();
 };