Bug 2509 - Pyviz doesn't respond to Simulator::Stop ()
Pyviz doesn't respond to Simulator::Stop ()
Status: ASSIGNED
Product: ns-3
Classification: Unclassified
Component: visualizer
unspecified
All All
: P5 normal
Assigned To: Gustavo J. A. M. Carneiro
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-09-23 12:02 EDT by Tom Henderson
Modified: 2017-03-23 03:53 EDT (History)
2 users (show)

See Also:


Attachments
Attempt to stop simulation at given stop time (3.38 KB, patch)
2017-03-21 17:26 EDT, adadeepak8
Details | Diff
Using Time for stop time (3.37 KB, patch)
2017-03-23 03:53 EDT, adadeepak8
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Henderson 2016-09-23 12:02:28 EDT
To reproduce, run Pyviz on a program that has scheduled Simulator::Stop (); it continues beyond that time.
Comment 1 adadeepak8 2017-03-21 17:26:31 EDT
Created attachment 2811 [details]
Attempt to stop simulation at given stop time

Recently, I came across this problem when I was using Simulator::Stop (<time>). The problem seems to be happening because in the current implementation, Stop of VisualSimulatorImpl just affects the loop in Run () of DefaultSimulator and even when that loop terminates due to m_stop being true, the while loop from run of SimulationThread calls it in the next iteration making m_stop false again. 

I am attaching a patch which notifies the SimulationThread of the stop time. The current patch will work only when the stop time is an integer second. Also, once the given time is over the PyViz has to be still closed manually (it will stop at the simulation time but the window does not exit implicitly). If the approach looks fine, I can correct those. 

Thanks,
Ankit
Comment 2 Tom Henderson 2017-03-22 08:41:11 EDT
(In reply to adadeepak8 from comment #1)
> Created attachment 2811 [details]
> Attempt to stop simulation at given stop time
> 
> Recently, I came across this problem when I was using Simulator::Stop
> (<time>). The problem seems to be happening because in the current
> implementation, Stop of VisualSimulatorImpl just affects the loop in Run ()
> of DefaultSimulator and even when that loop terminates due to m_stop being
> true, the while loop from run of SimulationThread calls it in the next
> iteration making m_stop false again. 
> 
> I am attaching a patch which notifies the SimulationThread of the stop time.
> The current patch will work only when the stop time is an integer second.

Rather than maintain m_stopTime as an integer or double, I suggest to try to make it an ns3::Time object, and then use std::ostringstream when you need to convert it to string (e.g. ostringstream str; str << m_stopTime;)

> Also, once the given time is over the PyViz has to be still closed manually
> (it will stop at the simulation time but the window does not exit
> implicitly). If the approach looks fine, I can correct those. 
> 

OK, I suggest to try for a final patch.
Comment 3 adadeepak8 2017-03-23 03:53:24 EDT
Created attachment 2812 [details]
Using Time for stop time

I have changed the data type of m_stopTime to Time.