omnetpypy.examples.ping_pong

This toy simulation module implements a simple ping-pong protocol. The simulation consists of two modules, a PingModule and a PongModule, which send messages to each other in a ping-pong fashion. The PingModule sends a message to the PongModule, which then sends a message back to the PingModule. This process is repeated for a specified number of times.

class omnetpypy.examples.ping_pong.__init__.PingPongModule(name, identifier, delay=5)[source]

Bases: SimpleModule

The Ping Pong Module. The behavior between the Ping and Pong modules is the same except for who sends the first message (Ping). This differentiation is handled in the initialize method through the name.

Parameters:
namestr

The name of the module. Either “ping” or “pong”.

identifierint

The identifier of the module. This identifier should be unique within the simulation.

delayint, optional

The delay in seconds between receiving and sending a message. The default is 5s.

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:
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 is a self message scheduled by this module.

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.