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:
objectGates 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.![[thick, gate/.style args={#1}{draw, circle, inner sep=3, outer
sep=0, label=above:{#1}}]
% Gates
\node[gate=Gate1] (g1) at (0,1) {};
\node[gate=Gate2] (g2) at (3,1) {};
\node[gate=Gate3] (g3) at (6,1) {};
% Connections
\draw[->] (g1) -- (g2) node[above,midway] {msg};
\draw[->] (g2) -- (g3) node[above,midway] {msg};
% Commands
\node[below=0.5 of g1] (s1) {send(msg)};
\draw[dashed] (s1) -- (g1);](../_images/tikz-32b982b096b7e20c1262c09fa4dc816e4567d68e.png)
Gates emulate the transmission of objects via connections by calling
send()on their connected gates as illustrated below.![[thick, gate/.style args={#1}{draw, circle, inner sep=3, outer
sep=0, label=above:{#1}}]
% Gates
\node[gate=Gate1] (g1) at (0,1) {};
\node[gate=Gate2] (g2) at (3,1) {};
\node[gate=Gate3] (g3) at (6,1) {};
% Commands
\node[below=0.5 of g1] (s1) {send(msg)};
\node[below=0.5 of g2] (s2) {send(msg)};
\node[below=0.5 of g3] (s3) {send(msg)};
\draw[dashed] (s1) -- (g1);
\draw[dashed] (s2) -- (g2);
\draw[dashed] (s3) -- (g3);
\draw[dashed,->] (s1) -- (s2);
\draw[dashed,->] (s2) -- (s3);](../_images/tikz-640bcbda7efd45ce92e5d12986aee675bef02161.png)
-
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:
objectA
Portsimplifies the setup of bidirectional connections by wrapping an input and an outputGateand 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:![\node (p1in) at (0,0)[draw,circle,inner sep=1.5pt]{};
\node (p1out) at (0,0.4)[draw,circle,fill,inner sep=1.5pt]{};
\node (p2out) at (2,0)[draw,circle,fill,inner sep=1.5pt]{};
\node (p2in) at (2,0.4)[draw,circle,inner sep=1.5pt]{};
\draw[draw=black] (-0.2,-0.2) rectangle ++(0.4,0.8);
\draw[draw=black] (1.8,-0.2) rectangle ++(0.4,0.8);
\draw[->] (p1out) -- (p2in);
\draw[->] (p2out) -- (p1in);](../_images/tikz-3d3a338867c0794adeaae32ce4ec72b8bc01d3f5.png)
Parameters: port ( Port) – ThePortto 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:![\node (p1in) at (0,0)[draw,circle,inner sep=1.5pt]{};
\node (p1out) at (0,0.4)[draw,circle,fill,inner sep=1.5pt]{};
\node (p2out) at (2,0.4)[draw,circle,fill,inner sep=1.5pt]{};
\node (p2in) at (2,0)[draw,circle,inner sep=1.5pt]{};
\draw[draw=black] (-0.2,-0.2) rectangle ++(0.4,0.8);
\draw[draw=black] (1.8,-0.2) rectangle ++(0.4,0.8);
\draw[->] (p1out) -- (p2out);
\draw[->] (p2in) -- (p1in);](../_images/tikz-2d6892ea3032c0e2d02e9999d943005aedf6d408.png)
Parameters: port ( Port) – ThePortto establish the bidirectional proxy connection to
-
-
class
GateListener(gateName, validTypes=None, blocking=True, queued=False)[source]¶ Bases:
objectA factory for decorators that allow to call a module’s method (or process a SimPy generator method) whenever a specified gate of a
Modulereceives 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’sGateto listen on - validTypes (
Union[type,Tuple[type],None]) – If this argument is provided, aTypeErrorwill be raised when an object received via the specifiedGateis not of thetype/ one of the types specified. - blocking (
bool) – Set this toFalseif 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
Modulesubclasses that apply theGateListenerdecorator.
- gateName (
-
class
Module(name, owner=None)[source]¶ Bases:
objectModules 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 theportsand thegatesdictionaries.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 thegatesdictionary.
-
class
CompoundModule(name, owner=None)[source]¶ Bases:
gymwipe.networking.construction.ModuleA
CompoundModuleis aModulethat contains an arbitrary number of submodules (Moduleobjects) 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 thesubmodulesdictionary.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.