omnetpypy.front_end.channel
This module implements the Channel()
class,
which implements advanced connectivity between ports in the simulation.
- class omnetpypy.front_end.channel.Channel(name, identifier=None, delay=None, loss_prob=None)[source]
Bases:
SimulatedEntity
Channels are used to apply operations on messages travelling between connected ports. They can apply noise, delays, losses, and other custom operations to the messages.
Channels always have two ports, named “A” and “B”. The channel forwards messages from port “A” to port “B”, and vice versa, after applying the specified delay and loss probability.
Subclasses can override the methods
process_message()
to apply more complex and asymmetric operations on the messages passing through the channel.- Parameters:
- namestr
The name of the channel. This name should be unique within the simulation.
- identifierint or None, optional
The identifier of the channel. This identifier should be unique within the simulation. If
None
, the identifier will be automatically generated.- delayfloat or None, optional
The delay to be applied to the messages passing through the channel. If
None
, no delay is applied.- loss_probfloat or None, optional
The probability of loss to be applied to the messages passing through the channel. If
None
, no loss is applied.
- Attributes:
- delayfloat or None
The delay to be applied to the messages passing through the channel. If
None
, no delay is applied.- loss_probfloat or None
The probability of loss to be applied to the messages passing through the channel. If
None
, no loss is applied.
- apply_loss(message, port_name)[source]
Apply loss to the message, based on an arbitrary loss probability distribution.
- Parameters:
- messageMessage
The message to be delayed.
- port_namestr
The port from which the message was received.
- Returns:
- bool
True if the message should be lost, False otherwise.
- generate_delay(message, port_name)[source]
Generate a delay for the message, based on an arbitrary delay distribution.
- Parameters:
- messageMessage
The message to be delayed.
- port_namestr
The port from which the message was received.
- Returns:
- float or None
The delay to be applied to the message. If None or zero, the message will be sent immediately.
- handle_message(message, port_name)[source]
Handle a message received from a port. First, it processes the message by calling the method
process_message()
, then it applies the optional delay and loss probability, and finally it sends the message out of the other port (if not lost).- Parameters:
- messageMessage
The message to be handled.
- port_namestr
The port from which the message was received.