omnetpypy.backends

The omnetpupy backends sub-package is responsible for the connection between the user API and discrete event simulation engines.

The user API is defined in the front end sub-package, and is independent of the simulation engine used. The backends sub-package provides the necessary tools to connect the user API to the simulation engine, and to run the simulation.

class omnetpypy.backends.__init__.Connector(simulation, metrics=None, output_dir=None, repetition=0)[source]

Bases: ABC

This class is an interface to the simulation engine. This is an abstract class, and it is meant to be subclassed by connectors to specific simulation engines.

Parameters:
simulationSimulation

The simulation object that describes the simulation configuration and its context. Used for example to access the random number generators for the simulation.

metricslist of FutureMetric or None, optional

A list of metrics to be recorded during the simulation.

output_dirstr, optional

The output directory where the simulation data will be stored. Default is None, which means that the simulation data will not be stored.

repetitionint, optional

The repetition index of the simulation. Default is 0.

Attributes:
simulationSimulation

The simulation object that describes the simulation configuration and its context. Used for example to access the random number generators for the simulation.

metricslist of FutureMetric or None

A list of metrics to be collected during the simulation. If None, no metrics will be collected.

output_dirstr

The output directory where the simulation data will be stored.

repetitionint

The repetition index of the simulation.

abstract add_entity(entity)[source]

Add an entity to the simulation.

Parameters:
entitySimulatedEntity

The simulation entity to be added to the simulation.

abstract cancel_scheduled(message, entity)[source]

Cancel a scheduled self message for an entity. If the message is not scheduled, nothing happens.

dump_metric(metric)[source]

Dump the metric data to the temporary output file for this repetition.

Parameters:
metricstr

The name of the metric to be dumped.

abstract get_time()[source]

Return the current simulation time. The time unit is determined by the simulation configuration.

abstract is_scheduled(message, entity)[source]

Check if a message is scheduled as a self message for an entity.

Parameters:
messageMessage

The message to be checked.

entitySimulatedEntity

The entity to check, that should receive the self message.

random()[source]

Return the random number generator instantiated for the current simulation.

Returns:
MultiRandom

A random number generator that supports multiple independent streams, powered by an independent seed for each stream.

record_metric(metric, value)[source]

Record a metric value for the current simulation.

Parameters:
metricstr

The name of the metric to be recorded.

valuefloat

The value of the metric to be recorded. If value is a dict or a list and the output file format is csv, it will be turned into a string and stored as is under the “sample” column.

abstract schedule_port_input(port, message)[source]

Schedule the event of a message received by a port.

Parameters:
portPort

The port that receives the message.

messageMessage

The message that received by the port.

abstract schedule_self_message(message, entity, at=None, delay=None)[source]

Schedule a self message to be processed by an entity.

Parameters:
messageMessage

The message to be processed.

entitySimulatedEntity

The entity that will process the message.

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.

abstract start_simulation(until=None)[source]

Start the simulation.

Parameters:
untilfloat or None, optional

The simulation time at which the simulation should stop. If None, the simulation will run until there are no more events to process.