omnetpypy.front_end.sim_entity

class omnetpypy.front_end.sim_entity.SimulatedEntity(name, identifier, port_names)[source]

Bases: object

A simulated entity is any active entity belonging to the simulation, such as modules and channels. Every entity may have a set of ports, and must keep a reference to the simulation context.

Parameters:
namestr

The name of the entity. Must be unique within the simulation.

identifierint

The unique identifier of the entity. Must be unique within the simulation.

port_nameslist of str

The names of the ports of the entity.

Attributes:
namestr

The name of the entity.

identifierint

The unique identifier of the entity.

sim_contextSimulation

The simulation where the entity is running. Used to access simulation variables like random number generators and the current simulation time.

parentSimulatedEntity

The parent entity of the current entity. If the entity is a top-level entity, the parent is None.

is_listeningbool

A flag indicating whether the entity is listening for incoming messages.

portsdict of Port

The ports of the entity, indexed by their names.

cancel_scheduled(message)[source]

Cancel a scheduled self message for this entity. Calls internally the method cancel_scheduled().

Parameters:
messageMessage

The message to be cancelled.

handle_message(message, port_name)[source]

Process a message received as input to a port.

Parameters:
messageMessage

The message to be processed.

port_namestr or None

The name of the port on which the message was received. If None, the message was sent by the entity itself (self message).

initialize(step=0)[source]

Initialize the entity right before the beginning of the simulation. This method is automatically called by the simulation context.

The method is called 5 times, once for each step from 0 to 4. The step number is passed as a parameter.

Parameters:
stepint, optional

The initialization step number. Default is 0. This parameter is used to allow entities to perform different initialization actions at different steps, and synchronize with other entities. The steps are numbered from 0 to 4, and the entity has the guarantee that the previous steps have already been executed on all entities of the simulation.

is_scheduled(message)[source]

Check if a message is scheduled as a self message for this entity. Calls internally the method is_scheduled().

Parameters:
messageMessage

The message to be checked.

schedule_message(message, at=None, delay=None)[source]

Schedule a self message to be received by this entity. Calls internally the method schedule_self_message().

Parameters:
messageMessage

The message to be processed.

atfloat or None, optional

The simulation time at which the message should be processed. If None, the delay parameter will be used.

delayfloat or None, optional

The time delay from the current simulation time at which the message should be processed. If None, the at parameter will be used.

send(message, port_name)[source]

Send a message out on a specified port. Calls internally the method tx_output().

Parameters:
messageMessage

The message to be sent.

port_namestr

The name of the port on which the message should be sent.

set_sim_context(sim_context)[source]

Set the simulation context of the entity. Automatically called when the entity is added to the simulation.

Parameters:
sim_contextSimulation

The simulation context where the entity is running.