sim.event module

The module event provides event description. This module provides two classes:

  • BaseEvent: This class is used to derive a new event. It defines commonly used methods for all new events to use.

  • Event: This class is a container holding all events. In the user simulation, this object will be passed to the user during an event. The user simulation can check the type of the event and then use get() method to retrieve further information. For example:

    def on_event(self, sim_time, event_obj): 
    
        ## do the following when a mobility of a node has ended
        if event_obj==Event.MOBILITY_END:
            ## get the node whose mobility has ended and restart
            ## it mobility again with a random delay start
            this_node = event_obj.get("node")
            this_node.get("mobility").restart(random.uniform(0,5))
    

Note

  • Created by: CH Foh (2021)

class sim.event.BaseEvent(event, info={})

Bases: object

This is the base event object class which should not be instantiated. The simulation engine will instantiate an appropriate subclass to trigger an event, which will be delivered to the user simulation. The user simulation will receive an event object during an event, and the event object is a subclass of this base class. The user simulation can tell which subclass by simply checking, say, if event==Event.MOBILITY_END. The user simulation can further get details about the event by using the provided get() method, for example get(“node”) for Event.MOBILITY_END to find out which the mobility of which node has ended.

Methods

get(information)

This method returns additional information about the event based on the input parameter.

__init__(event, info={})

Initialize self. See help(type(self)) for accurate signature.

get(information: str)

This method returns additional information about the event based on the input parameter.

Parameters
informationstr

The information to get.

Returns
any

The value of the requested information. Return None if no such information is carried in this event.

class sim.event.Event

Bases: object

This is a class for an event.

An event object will be passed to the user simulation to describe what event has happened. An event object can be checked for its type directly by using, for example: event==Event.SIM_MOBILITY. The main role of this class is to provide event constants for user simulation and event subclasses for simulation engine to use. Event subclasses are protected and hidden to avoid accidental access by user simulation.

SIM_NONE = <enum.auto object>

This is a NULL event, it is not used.

SIM_MOBILITY = <enum.auto object>

It indicates a user mobility event where all nodes have moved a time step.

SIM_START = <enum.auto object>

It indicates the beginning of the simulation.

SIM_END = <enum.auto object>

It indicates the end of the simulation.

SIM_PAUSE = <enum.auto object>

It indicates the simulation is just paused.

SIM_RESUME = <enum.auto object>

It indicates the simulation is just resumed from pause.

SIM_STOP = <enum.auto object>

It indicates the simulation is stopped.

MOBILITY_END = <enum.auto object>

It indicates a node mobility has ended. Use get(“node”) to retrieve the node.

TIMER_EXPIRED = <enum.auto object>

It indicates a timer initiated by a node has expired. Use the following to retrieve the details:

  • get(“node”): to retrieve the node that initiated the timer.

  • get(“timer”): to retrieve the timer instance.

BUTTON_CLICKED = <enum.auto object>

It indicates a user-defined button has been clicked. Use the following to retrieve the details:

  • get(“id”): to retrieve the control id.