View | Details | Raw Unified | Return to bug 375
Collapse All | Expand All

(-)a/bindings/python/ns3_module_simulator.py (-5 lines)
 Lines 291-301    Link Here 
291
                   'ns3::Time', 
291
                   'ns3::Time', 
292
                   [], 
292
                   [], 
293
                   is_static=True)
293
                   is_static=True)
294
    ## simulator.h: static void ns3::Simulator::Run() [member function]
295
    cls.add_method('Run', 
296
                   'void', 
297
                   [], 
298
                   is_static=True, unblock_threads=True)
299
    ## simulator.h: static void ns3::Simulator::RunOneEvent() [member function]
294
    ## simulator.h: static void ns3::Simulator::RunOneEvent() [member function]
300
    cls.add_method('RunOneEvent', 
295
    cls.add_method('RunOneEvent', 
301
                   'void', 
296
                   'void', 
(-)a/bindings/python/ns3module_helpers.cc (+47 lines)
 Lines 279-281    Link Here 
279
    return Py_None;
279
    return Py_None;
280
}
280
}
281
281
282
283
PyObject *
284
_wrap_Simulator_Run(PyNs3Simulator *PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs,
285
                    PyObject **return_exception)
286
{
287
    const char *keywords[] = {"signal_check_frequency", NULL};
288
    int signal_check_frequency = 100;
289
    
290
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "|i", (char **) keywords, &signal_check_frequency)) {
291
        PyObject *exc_type, *traceback;
292
        PyErr_Fetch(&exc_type, return_exception, &traceback);
293
        Py_XDECREF(exc_type);
294
        Py_XDECREF(traceback);
295
        return NULL;
296
    }
297
298
    PyThreadState *py_thread_state = NULL;
299
300
    if (signal_check_frequency == -1)
301
    {
302
        if (PyEval_ThreadsInitialized ())
303
            py_thread_state = PyEval_SaveThread();
304
        ns3::Simulator::Run();
305
        if (py_thread_state)
306
            PyEval_RestoreThread(py_thread_state);
307
    } else {
308
        while (!ns3::Simulator::IsFinished())
309
        {        
310
            if (PyEval_ThreadsInitialized())
311
                py_thread_state = PyEval_SaveThread();
312
313
            for (int n = signal_check_frequency; n > 0; --n)
314
            {        
315
                ns3::Simulator::RunOneEvent();
316
            }
317
            
318
            if (py_thread_state)
319
                PyEval_RestoreThread(py_thread_state);
320
            PyErr_CheckSignals();
321
            if (PyErr_Occurred())
322
                return NULL;
323
        }
324
    }
325
    Py_INCREF(Py_None);
326
    return Py_None;
327
}
328
(-)a/bindings/python/ns3modulegen_core_customizations.py (+3 lines)
 Lines 285-290    Link Here 
285
285
286
    ## Simulator::ScheduleDestroy(callback, ...user..args...)
286
    ## Simulator::ScheduleDestroy(callback, ...user..args...)
287
    Simulator.add_custom_method_wrapper("ScheduleDestroy", "_wrap_Simulator_ScheduleDestroy",
287
    Simulator.add_custom_method_wrapper("ScheduleDestroy", "_wrap_Simulator_ScheduleDestroy",
288
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
289
290
    Simulator.add_custom_method_wrapper("Run", "_wrap_Simulator_Run",
288
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
291
                                        flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
289
292
290
293
(-)a/bindings/python/ns3modulescan.py (-2 / +2 lines)
 Lines 150-160    Link Here 
150
            and pygccxml_definition.name.startswith('Schedule'):
150
            and pygccxml_definition.name.startswith('Schedule'):
151
        global_annotations['ignore'] = None
151
        global_annotations['ignore'] = None
152
152
153
    # unblock python threads for Simulator::Run
153
    # manually wrapped
154
    if isinstance(pygccxml_definition, member_function_t) \
154
    if isinstance(pygccxml_definition, member_function_t) \
155
            and pygccxml_definition.parent.name == 'Simulator' \
155
            and pygccxml_definition.parent.name == 'Simulator' \
156
            and pygccxml_definition.name == 'Run':
156
            and pygccxml_definition.name == 'Run':
157
        global_annotations['unblock_threads'] = True
157
        global_annotations['ignore'] = True
158
158
159
159
160
    ## classes
160
    ## classes
(-)a/examples/csma-bridge.py (-4 / +6 lines)
 Lines 102-108    Link Here 
102
    app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
102
    app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
103
    # Start the application
103
    # Start the application
104
    app.Start(ns3.Seconds(1.0))
104
    app.Start(ns3.Seconds(1.0))
105
    app.Stop(ns3.Seconds(10.0))
105
    #app.Stop(ns3.Seconds(10.0))
106
106
107
    # Create an optional packet sink to receive these packets
107
    # Create an optional packet sink to receive these packets
108
    sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
108
    sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
 Lines 117-123    Link Here 
117
                       ns3.AddressValue(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
117
                       ns3.AddressValue(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
118
    app = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
118
    app = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
119
    app.Start(ns3.Seconds(1.1))
119
    app.Start(ns3.Seconds(1.1))
120
    app.Stop(ns3.Seconds(10.0))
120
    #app.Stop(ns3.Seconds(10.0))
121
121
122
    app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
122
    app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
123
    app.Start (ns3.Seconds (0.0))
123
    app.Start (ns3.Seconds (0.0))
 Lines 138-150    Link Here 
138
    # and can be read by the "tcpdump -r" command(use "-tt" option to
138
    # and can be read by the "tcpdump -r" command(use "-tt" option to
139
    # display timestamps correctly)
139
    # display timestamps correctly)
140
    #
140
    #
141
    ns3.CsmaHelper.EnablePcapAll("csma-bridge")
141
    #ns3.CsmaHelper.EnablePcapAll("csma-bridge")
142
142
143
    #
143
    #
144
    # Now, do the actual simulation.
144
    # Now, do the actual simulation.
145
    #
145
    #
146
    #print "Run Simulation."
146
    #print "Run Simulation."
147
    ns3.Simulator.Run()
147
    #import threading
148
    ns3.Simulator.Stop(ns3.Seconds(100))
149
    ns3.Simulator.Run(signal_check_frequency=100)
148
    ns3.Simulator.Destroy()
150
    ns3.Simulator.Destroy()
149
    #print "Done."
151
    #print "Done."
150
152
(-)a/src/simulator/default-simulator-impl.cc (-1 / +1 lines)
 Lines 124-130    Link Here 
124
bool 
124
bool 
125
DefaultSimulatorImpl::IsFinished (void) const
125
DefaultSimulatorImpl::IsFinished (void) const
126
{
126
{
127
  return m_events->IsEmpty ();
127
  return m_events->IsEmpty () || m_stop;
128
}
128
}
129
129
130
uint64_t
130
uint64_t

Return to bug 375