- 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()
- if not has_event_occurred[0]:
- raise RuntimeError('Event could not be scheduled : %s %s ' \
- % (repr(func), repr(args)))
+ 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:
+ # schedule the event in the Simulator
+ self._schedule_event(self._condition, self._set_ns3_attribute,
+ name, ns3_value, element)
+ else:
+ self._set_ns3_attribute(name, ns3_value, element)
+
+ def _get_attribute(self, name, ns3_value, element):
+ if self.status() == TS.STATUS_STARTED:
+ # schedule the event in the Simulator
+ self._schedule_event(self._condition, self._get_ns3_attribute,
+ name, ns3_value, element)
+ else:
+ self._get_ns3_attribute(name, ns3_value, element)
+
+ def _set_ns3_attribute(self, name, ns3_value, element):
+ element.SetAttribute(name, ns3_value)
+
+ def _get_ns3_attribute(self, name, ns3_value, element):
+ element.GetAttribute(name, ns3_value)
+
+ def _stop_simulation(self, time):
+ if self.status() == TS.STATUS_STARTED:
+ # schedule the event in the Simulator
+ self._schedule_event(self._condition, self._stop_ns3_simulation,
+ time)
+ else:
+ self._stop_ns3_simulation(time)
+
+ def _stop_ns3_simulation(self, time = TIME_NOW):
+ if not self.ns3:
+ return
+ if time == TIME_NOW:
+ self.ns3.Simulator.Stop()
+ else:
+ self.ns3.Simulator.Stop(self.ns3.Time(time))