Bug 2509

Summary: Pyviz doesn't respond to Simulator::Stop ()
Product: ns-3 Reporter: Tom Henderson <tomh>
Component: visualizerAssignee: Gustavo J. A. M. Carneiro <gjcarneiro>
Status: ASSIGNED ---    
Severity: normal CC: adadeepak8, ns-bugs
Priority: P5    
Version: unspecified   
Hardware: All   
OS: All   
Attachments: Attempt to stop simulation at given stop time
Using Time for stop time

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.