omnetpypy.front_end.simple_module
This module implements the SimpleModule abstract class.
The class has the same semantic as its homonym in omnet++, and it is meant to be subclassed by the user to define its custom simulation modules.
- class omnetpypy.front_end.simple_module.SimpleModule(name, identifier, port_names)[source]
Bases:
SimulatedEntity
This class is an abstract class that represents a simple module in the simulation. Simple modules are the basic building blocks of the simulation model. They can send and receive messages through their ports, and they can be connected to other modules through channels connecting their ports. The behavior of a simple module is defined by how it handles incoming messages. The user should subclass this class to define custom simulation modules.
Simple modules are also in charge of recording metrics samples. The user can call the method
emit_metric()
at any time to record a metric sample.See
SimulatedEntity
for inherited attributes.- Parameters:
- namestr
The name of the module. This name should be unique within the simulation.
- identifierint
The identifier of the module. This identifier should be unique within the simulation.
- port_nameslist of str
The names of the ports of the module.
- connect(local_port, remote_entity, remote_port, channel=None)[source]
Connect a port of this module to a port of another remote entity. The output of a port will be fed as input to the other port (up to the intermediate actions of a channel, if any).
- Parameters:
- local_portstr
The name of the local port to be connected.
- remote_entity
SimulatedEntity
The remote entity to which the port will be connected.
- remote_portstr
The name of the remote port to be connected.
- channel
Channel
or None, optional The channel through which the connection will be made, if any. If set, the local port is connected to the “A” port of the channel, and the “B” port of the channel is connected to the remote port.
- emit_metric(name, value)[source]
Record a metric sample in the simulation context. The metric name must be defined in the main configuration file.
- Parameters:
- namestr
The name of the metric. The metric name must be defined in the simulation configuration.
- valueAny
The value of the metric sample
- abstract handle_message(message, port_name)[source]
Handle a message received as input to a port. This method must be implemented by every subclass to define the behavior of the custom module.
- Parameters:
- message
Message
The message to be processed.
- port_namestr or None
The name of the port on which the message was received. If
None
, the message is a self message scheduled by this module.
- message