gymwipe.networking.messages module

The messages module provides classes for network packet representations and inter-module communication.

The following classes are used for transmission simulation:

Transmittable(value[, byteSize]) The Transmittable class provides a byteSize attribute allowing the simulated sending of Transmittable objects via a frequency band.
FakeTransmittable(byteSize) A Transmittable implementation that sets its value to None.
Packet(header, payload[, trailer]) The Packet class represents packets.
SimpleMacHeader(sourceMAC, destMAC, flag) A class for representing MAC packet headers
SimpleNetworkHeader(sourceMAC, destMAC) Since no network protocol is implemented in Gym-WiPE, there is a need for some interim way to specify source and destination addresses in packets that are passed to the SimpleMAC layer.

The following classes are used for inter-module communication:

Message(type[, args]) A class used for the exchange of arbitrary messages between components.
StackMessageTypes An enumeration of control message types to be used for the exchange of Message objects between network stack layers.
class Transmittable(value, byteSize=None)[source]

Bases: object

The Transmittable class provides a byteSize attribute allowing the simulated sending of Transmittable objects via a frequency band.

value[source]

The object that has been passed to the constructor as value

Type:Any
byteSize[source]

The transmittable’s byteSize as it was passed to the constructor

Parameters:
  • value (Any) – The object of which the string representation will be used
  • byteSize – The number of bytes that are simulated to be transmitted when the data represented by this Transmittable is sent via a frequency band. Defaults to the length of the UTF-8 encoding of str(value).
bitSize[source]

byteSize \(\times 8\)

Return type:int
transmissionTime(bitrate)[source]

Returns the time in seconds needed to transmit the data represented by the Transmittable at the specified bit rate.

Parameters:bitrate (float) – The bitrate in bps
Return type:float
class FakeTransmittable(byteSize)[source]

Bases: gymwipe.networking.messages.Transmittable

A Transmittable implementation that sets its value to None. It can be helpful for test applications when the data itself is irrelevant and only its size has to be considered.

Parameters:byteSize (int) – The number of bytes that the FakeTransmittable represents
class Packet(header, payload, trailer=None)[source]

Bases: gymwipe.networking.messages.Transmittable

The Packet class represents packets. A Packet consists of a header, a payload and an optional trailer. Packets can be nested by providing them as payloads to the packet constructor.

header[source]

The object representing the Packet’s header

Type:Transmittable
payload[source]

The object representing the Packet’s payload. Might be another Packet.

Type:Transmittable
trailer[source]

The object representing the Packet’s trailer (defaults to None)

Type:Transmittable
__str__()[source]

Return str(self).

class SimpleMacHeader(sourceMAC, destMAC, flag)[source]

Bases: gymwipe.networking.messages.Transmittable

A class for representing MAC packet headers

sourceMAC[source]

The 6-byte-long source MAC address

Type:bytes
destMAC[source]

The 6-byte-long destination MAC address

Type:bytes
flag[source]

A single byte flag (stored as an integer in range(256))

Type:int
class SimpleNetworkHeader(sourceMAC, destMAC)[source]

Bases: gymwipe.networking.messages.Transmittable

Since no network protocol is implemented in Gym-WiPE, there is a need for some interim way to specify source and destination addresses in packets that are passed to the SimpleMAC layer. Therefore, a SimpleNetworkHeader holds a source and a destination MAC address. The destination address is used by the SimpleMAC layer.

sourceMAC[source]

The 6-byte-long source MAC address

Type:bytes
destMAC[source]

The 6-byte-long destination MAC address

Type:bytes
class Message(type, args=None)[source]

Bases: object

A class used for the exchange of arbitrary messages between components. A Message can be used to simulate both asynchronous and synchronous function calls.

type[source]

An enumeration object that defines the message type

Type:Enum
args[source]

A dictionary containing the message’s arguments

Type:Dict[str, Any]
eProcessed[source]

A SimPy event that is triggered when setProcessed() is called. This is useful for simulating synchronous function calls and also allows for return values (an example is provided in setProcessed()).

Type:Event
setProcessed(returnValue=None)[source]

Makes the eProcessed event succeed.

Parameters:returnValue (Optional[Any]) – If specified, will be used as the value of the eProcessed event.

Examples

If returnValue is specified, SimPy processes can use Signals for simulating synchronous function calls with return values like this:

signal = Signal(myType, {"key", value})
gate.output.send(signal)
value = yield signal.eProcessed
# value now contains the returnValue that setProcessed() was called with
class StackMessageTypes[source]

Bases: enum.Enum

An enumeration of control message types to be used for the exchange of Message objects between network stack layers.

RECEIVE = 0[source]
SEND = 1[source]
ASSIGN = 2[source]