node.timer module¶
Module timer contains node.timer.NodeTimer class which allows nodes
to create timers. Creating a timer from a node is simple, the following is an example:
## create a timer within a node
my_node.timer = NodeTimer(my_node, duration=10)
my_node.timer.start()
...
## in own Scenario class, on_event() callback
def on_event(self, sim_time, event_obj):
if event_obj==Event.TIMER_EXPIRED: # a timer expired?
this_node = event_obj.get("node") # get the node that started the timer
the_timer = event_obj.get("timer") # get the timer instance if needed
# then do something...
Note
Created by: CH Foh (2021)
-
class
node.timer.NodeTimer(node, duration)¶ Bases:
objectThis is the class specifying a node timer. A timer is in an idle state when created. Use start() method to trigger the timer, and the timer transits to running state. Use is_running() method to check if the timer is still running. Once expired, the timer will transit back to idle state. To stop a running timer, use kill() method to force the timer to transit to killed state. While a killed timer is still running, it will automatically return back to idle state when it expires, and will not trigger an event since the timer is already killed.
Methods
Use this method to return the node that hosts this timer.
Use this method to check if this timer is killed.
Use this method to check if this timer is currently running.
kill()Use this method to kill a running timer.
sim__set_running_flag(running_flag)This method is used by simulation engine to set the running flag.
start([delay])Use this method to start this timer.
-
__init__(node, duration)¶ This is the default constructor.
- Parameters
- node
node.node.BaseNodesubclass The node that hosts this timer.
- durationfloat
The run duration of this timer.
- node
-
start(delay=0)¶ Use this method to start this timer. A killed timer can be restarted by using this method.
- Parameters
- delayfloat, optional, default=0
Specify a delay start.
-
get_hosting_node()¶ Use this method to return the node that hosts this timer.
- Returns
- node.node.BaseNode subclass
It returns the node instance hosting this timer.
-
kill()¶ Use this method to kill a running timer. To be effective, this method must be called before the timer has expired. When a timer is started, a corresponding process is scheduled in the event queue. Killing the timer won’t remove the process from the event queue. Internally, the method will set a flag in this class indicating that the timer is killed. Once the corresponding process is called, if the timer is killed, the event simply stops relaying the event to the user simulation to achieve the same effect of getting the timer killed.
-
is_killed()¶ Use this method to check if this timer is killed.
-
is_running()¶ Use this method to check if this timer is currently running.
-
sim__set_running_flag(running_flag)¶ This method is used by simulation engine to set the running flag. It should not be used by user simulation.
- Parameters
- running_flagbool
The the running flag.
-