raise RuntimeError("Imposible to load shared libraries %s" % str(libs))
libscp = list(libs)
- if not bindings:
- import ns3
- sys.modules["ns3"] = ns3
- return
-
- sys.path.append(bindings)
+ if bindings:
+ sys.path.append(bindings)
+
import ns3_bindings_import as mod
sys.modules["ns3"] = mod
def stop(self, time = TIME_NOW):
super(TestbedController, self).stop(time)
- #self.ns3.Simulator.Stop()
self._stop_simulation(time)
def set(self, guid, name, value, time = TIME_NOW):
filename = self._traces[guid][trace_id]
return os.path.join(self.home_directory, filename)
+ def trace_filename(self, guid, trace_id):
+ return self._traces[guid][trace_id]
+
def follow_trace(self, guid, trace_id, filename):
if not guid in self._traces:
self._traces[guid] = dict()
for element in self._elements.itervalues():
if isinstance(element, self.LOCAL_TYPES):
# graceful shutdown of locally-implemented objects
- element.Cleanup()
+ element.cleanup()
if self.ns3:
- self.ns3.Simulator.Stop()
+ if not self.ns3.Simulator.IsFinished():
+ self.stop()
- # Wait for it to stop, with a 30s timeout
- for i in xrange(300):
- if self.ns3.Simulator.IsFinished():
- break
- time.sleep(0.1)
- #self._stop_simulation("0s")
-
- self._elements.clear()
-
- if self.ns3:
# TODO!!!! SHOULD WAIT UNTIL THE THREAD FINISHES
- # if self._simulator_thread:
- # self._simulator_thread.join()
+ if self._simulator_thread:
+ self._simulator_thread.join()
+
self.ns3.Simulator.Destroy()
+ self._elements.clear()
+
self._ns3 = None
sys.stdout.flush()
sys.stderr.flush()
# bool flag, a list is used as wrapper
has_event_occurred = [False]
condition.acquire()
- if not self.ns3.Simulator.IsFinished():
- self.ns3.Simulator.ScheduleWithContext(contextId, delay, execute_event,
- condition, has_event_occurred, func, *args)
- while not has_event_occurred[0] and not self.ns3.Simulator.IsFinished():
- condition.wait()
- condition.release()
+ try:
+ if not self.ns3.Simulator.IsFinished():
+ self.ns3.Simulator.ScheduleWithContext(contextId, delay, execute_event,
+ condition, has_event_occurred, func, *args)
+ while not has_event_occurred[0] and not self.ns3.Simulator.IsFinished():
+ condition.wait()
+ finally:
+ condition.release()
def _set_attribute(self, name, ns3_value, element):
if self.status() == TS.STATUS_STARTED:
def _configure_ns3_module(self):
simu_impl_type = self._attributes.get_attribute_value(
"SimulatorImplementationType")
+ sched_impl_type = self._attributes.get_attribute_value(
+ "SchedulerType")
checksum = self._attributes.get_attribute_value("ChecksumEnabled")
stop_time = self._attributes.get_attribute_value("StopTime")
if simu_impl_type:
value = mod.StringValue(simu_impl_type)
mod.GlobalValue.Bind ("SimulatorImplementationType", value)
+ if sched_impl_type:
+ value = mod.StringValue(sched_impl_type)
+ mod.GlobalValue.Bind ("SchedulerType", value)
if checksum:
value = mod.BooleanValue(checksum)
mod.GlobalValue.Bind ("ChecksumEnabled", value)