gymwipe.networking.construction module¶
The construction module provides classes for building network stack representations. The concept of modules, compound modules, and gates is borrowed from the OMNeT++ model structure, which is described in [VH08].
-
class
Gate
(name, owner=None)[source]¶ Bases:
object
Gates provide features for the transfer of arbitrary objects. They can be connected to each other and offer a
send()
method that passes an object to all connected gates, as shown in the figure below, where connections are depicted as arrows.Gates emulate the transmission of objects via connections by calling
send()
on their connected gates as illustrated below.-
nReceives
[source]¶ A notifier that is triggered when
send()
is called, providing the value passed tosend()
Type: gymwipe.simtools.Notifier
-
nConnectsTo
[source]¶ A notifier that is triggered when
connectTo()
is called, providing the gate passed toconnectTo()
Type: Notifier
-
-
class
Port
(name, owner=None)[source]¶ Bases:
object
A
Port
simplifies the setup of bidirectional connections by wrapping an input and an outputGate
and offering two connection methods:biConnectWith()
andbiConnectProxy()
.Parameters: -
biConnectWith
(port)[source]¶ Shorthand for
self.output.connectTo(port.input) port.output.connectTo(self.input)
Creates a bidirectional connection between this port an the passed port. If indicates input gates and indicates output gates, the resulting connection between two ports can be visualized like this:
Parameters: port ( Port
) – ThePort
to establish the bidirectional connection to
-
biConnectProxy
(port)[source]¶ Shorthand for
self.output.connectTo(port.output) port.input.connectTo(self.input)
If indicates input gates and indicates output gates, the resulting connection between two ports can be visualized like this:
Parameters: port ( Port
) – ThePort
to establish the bidirectional proxy connection to
-
-
class
GateListener
(gateName, validTypes=None, blocking=True, queued=False)[source]¶ Bases:
object
A factory for decorators that allow to call a module’s method (or process a SimPy generator method) whenever a specified gate of a
Module
receives an object. The received object is provided to the decorated method as a parameter.Note
In order to make this work for a class’ methods, you have to decorate that class’ constructor with @PortListener.setup.
Examples
A
Module
’s method using this decorator could look like this:@GateListener("myPortIn") def myPortInListener(self, obj): # This method is processed whenever self.gates["myPortIn"] # receives an object and all previously created instances # have been processed. yield SimMan.timeout(1)
Parameters: - gateName (
str
) – The index of the module’sGate
to listen on - validTypes (
Union
[type
,Tuple
[type
],None
]) – If this argument is provided, aTypeError
will be raised when an object received via the specifiedGate
is not of thetype
/ one of the types specified. - blocking (
bool
) – Set this toFalse
if you decorate a SimPy generator method and want it to be processed for each received object, regardless of whether an instance of the generator is still being processed or not. By default, only one instance of the decorated generator method is run at a time (blocking isTrue
). - queued (
bool
) – If you decorate a SimPy generator method, blocking isTrue
, and you set queued toTrue
, an object received while an instance of the generator is being processed will be queued. Sequentially, a new generator instance will then be processed for every queued object as soon as a previous generator instance has been processed. Using queued, you can, for example, react to multiple objects that are received at the same simulated time, while only having one instance of a subscribed generator method processed at a time. Queued defaults toFalse
.
-
static
setup
(function)[source]¶ A decorator to be used for the constructors of
Module
subclasses that apply theGateListener
decorator.
- gateName (
-
class
Module
(name, owner=None)[source]¶ Bases:
object
Modules are used to model components that interact with each other, as for example network stack layers. A module has a number of ports and gates that can be used to exchange data with it and connect it to other modules. Modules provide the methods
_addPort()
and_addGate()
that allow to add ports and gates, which can be accessed via theports
and thegates
dictionaries.Note
Modules may have both ports (for bidirectional connections) and individual gates (for unidirectional connections). When a port is added by
_addPort()
, its two gates are also added to thegates
dictionary.
-
class
CompoundModule
(name, owner=None)[source]¶ Bases:
gymwipe.networking.construction.Module
A
CompoundModule
is aModule
that contains an arbitrary number of submodules (Module
objects) which can be connected with each other and their parent module’s gates and ports. Submodules are added using_addSubmodule()
and can be accessed via thesubmodules
dictionary.Note
When subclassing
CompoundModule
, do not directly implement functionalities in your subclass, but wrap them in submodules to ensure modularity. Also, do not connect a CompoundModule’s submodules to anything else than other submodules or the CompoundModule itself for the same reason.