gymwipe.networking.physical module¶
Physical-layer-related components
-
calculateEbToN0Ratio
(signalPower, noisePower, bitRate, returnDb=False)[source]¶ Computes \(E_b/N_0 = \frac{S}{N_0 R}\) (the “ratio of signal energy per bit to noise power density per Hertz” [Sta05]) given the signal power \(S_{dBm}\), the noise power \(N_{0_{dBm}}\), and the bit rate \(R\), according to p. 95 of [Sta05].
Parameters: Return type:
-
approxQFunction
(x)[source]¶ Approximates the gaussian Q-Function for \(x \ge 0\) by using the following formula, derived from [KL07]:
\(Q(x)\approx\frac{\left( 1-e^{-1.4x}\right) e^{-\frac{x^{2}}{2}}}{1.135\sqrt{2\pi}x}\)
Parameters: x ( float
) – The \(x\) value to approximate \(Q(x)\) forReturn type: float
-
temperatureToNoisePowerDensity
(temperature)[source]¶ Calculates the noise power density \(N_0\) in W/Hz for a given temperature \(T\) in degrees Celsius according to [Sta05] by using the following formula:
\(N_0 = k (T + 273.15)\) with \(k\) being Boltzmann’s constant
Parameters: temperature ( float
) – The temperature \(T\) in degrees CelsiusReturn type: float
-
wattsToDbm
(watts)[source]¶ Converts a watt value to a dBm value.
Parameters: watts ( float
) – The watt value to be converted
-
milliwattsToDbm
(milliwatts)[source]¶ Converts a milliwatt value to a dBm value.
Parameters: watts – The milliwatt value to be converted
-
dbmToMilliwatts
(milliwatts)[source]¶ Converts a dBm value to a milliwatt value.
Parameters: watts – The dBm value to be converted
-
class
Mcs
(frequencyBandSpec, codeRate)[source]¶ Bases:
abc.ABC
The
Mcs
class represents a Modulation and Coding Scheme. As the MCS (beside frequency band characteristics) determines the relation between Signal-to-Noise Ratio (SNR) and the resulting Bit Error Rate (BER), it offers agetBitErrorRateBySnr()
method that is used by receiving PHY layer instances.Mcs
objects also provide abitRate
and adataRate
attribute, which specify the physical bit rate and the effective data rate of transmissions with the correspondingMcs
.Currently, only BPSK modulation is implemented (see
BpskMcs
for details). SubclassMcs
if you need something more advanced.-
frequencyBandSpec
= None[source]¶ The frequency band specification that determines the bandwidth for which the MCS is operated
-
codeRate
= None[source]¶ The relative amount of transmitted bits that are not used for forward error correction
Type: Fraction
-
calculateBitErrorRate
(signalPower, noisePower, bitRate)[source]¶ Computes the bit error rate for the passed parameters if this modulation and coding scheme is used.
Parameters: Returns: The estimated resulting bit error rate (a float in [0,1])
Return type: float
-
bitRate
[source]¶ The physical bit rate in bps that results from the use of this MCS
Type: float Return type: float
-
-
class
BpskMcs
(frequencyBandSpec, codeRate=Fraction(3, 4))[source]¶ Bases:
gymwipe.networking.physical.Mcs
A Binary Phase-Shift-Keying MCS
-
bitRate
[source]¶ The physical bit rate in bps that results from the use of this MCS
Type: float Return type: float
-
dataRate
[source]¶ The effective data rate in bps that results from the use of this MCS (considers coding overhead)
Type: float Return type: float
-
-
class
Transmission
(sender, power, packet, mcsHeader, mcsPayload, startTime)[source]¶ Bases:
object
A
Transmission
models the process of a device sending a specific packet via a communication frequency band.Note
The proper way to instantiate
Transmission
objects is viaFrequencyBand.transmit()
.-
mcsHeader
= None[source]¶ The modulation and coding scheme used for the transmitted packet’s header
Type: Mcs
-
mcsPayload
= None[source]¶ The modulation and coding scheme used for the transmitted packet’s payload
Type: Mcs
-
headerDuration
= None[source]¶ The time in seconds taken by the transmission of the packet’s header
Type: float
-
payloadDuration
= None[source]¶ The time in seconds taken by the transmission of the packet’s payload
Type: float
-
stopTime
= None[source]¶ The moment in simulated time right after the transmission has completed
Type: float
-
eHeaderCompletes
= None[source]¶ A SimPy event that succeeds at the moment in simulated time right after the packet’s header has been transmitted. The transmission object is provided as the value to the
succeed()
call.Type: Event
-
-
class
FrequencyBandSpec
(frequency=2400000000.0, bandwidth=22000000.0)[source]¶ Bases:
object
A frequency band specification stores a
FrequencyBand
’s frequency and its bandwidth.Parameters:
-
class
AttenuationModel
(frequencyBandSpec, deviceA, deviceB)[source]¶ Bases:
object
An
AttenuationModel
calculates the attenuation (measured in db) of any signal sent from one network device to another. It runs a SimPy process and subscribes to the positionChanged events of theNetworkDevice
instances it belongs to. When the attenuation value changes, theattenuationChanged
event succeeds.Parameters: - frequencyBandSpec (
FrequencyBandSpec
) – The frequency band specification of the correspondingFrequencyBand
- deviceA (
Device
) – Network device a - deviceB (
Device
) – Network device b
Raises: ValueError
– If deviceA is deviceB-
attenuation
= None[source]¶ The attenuation of any signal sent from
NetworkDevice
deviceA toNetworkDevice
deviceB (or vice versa) at the currently simulated time, measured in db.Type: float
-
nAttenuationChanges
= None[source]¶ A notifier that is triggered when the attenuation value changes, providing the new attenuation value.
Type: gymwipe.simtools.Notifier
- frequencyBandSpec (
-
class
PositionalAttenuationModel
(frequencyBandSpec, deviceA, deviceB)[source]¶ Bases:
gymwipe.networking.physical.AttenuationModel
,abc.ABC
An
AttenuationModel
subclass that executes_positionChanged()
whenever one of its two devices changes its position and the distance between the devices does not exceedSTANDBY_THRESHOLD
.-
STANDBY_THRESHOLD
= 3000[source]¶ The minimum distance in metres, that allows the
AttenuationModel
not to react on position changes of its devicesType: float
-
-
class
JoinedAttenuationModel
(frequencyBandSpec, deviceA, deviceB, models)[source]¶ Bases:
gymwipe.networking.physical.AttenuationModel
An
AttenuationModel
that adds the attenuation values of two or more givenAttenuationModel
instances. If the position of one of both devices is changed, it will gather the update notifications of itsAttenuationModel
instances, sum them up and trigger thenAttenuationChanges
notifier only once after the updates (this is implemented using callback priorities). When anAttenuationModel
instance changes its attenuation without reacting to a position update, thenAttenuationChanges
notifier of theJoinedAttenuationModel
will be triggered as a direct consequence.Parameters: - frequencyBandSpec (
FrequencyBandSpec
) – The frequency band specification of the correspondingFrequencyBand
- deviceA (
Device
) – Network device a - deviceB (
Device
) – Network device b - models (
List
[Type
[~AttenuationModel]]) – A non-empty list of theAttenuationModel
subclasses to create aJoinedAttenuationModel
instance of
- frequencyBandSpec (
-
class
AttenuationModelFactory
(frequencyBandSpec, models)[source]¶ Bases:
object
A factory for
AttenuationModel
instances.Parameters: - frequencyBandSpec (
FrequencyBandSpec
) – The frequency band specification of the correspondingFrequencyBand
- models (
List
[~AttenuationModel]) – A non-empty list ofAttenuationModel
subclasses that will be used for instantiating attenuation models.
-
setCustomModels
(deviceA, deviceB, models)[source]¶ Sets the
AttenuationModel
subclasses for signals sent from deviceA to deviceB and vice versa.Note
In order for this method to work, it has to be invoked before an
AttenuationModel
instance is requested for the first time for the specified pair of devices.Parameters: - deviceA (
Device
) – One device - deviceB (
Device
) – Another device - models (
List
[~AttenuationModel]) – A non-empty list ofAttenuationModel
subclasses that will be used for instantiating attenuation models for signals sent from deviceA to deviceB and vice versa
- deviceA (
-
getInstance
(deviceA, deviceB)[source]¶ Returns the
AttenuationModel
for signals sent from deviceA to deviceB and vice versa. If not yet existent, a newAttenuationModel
instance will be created. If the factory was initialized with multipleAttenuationModel
subclasses, aJoinedAttenuationModel
will be handed out.Return type: AttenuationModel
- frequencyBandSpec (
-
class
FrequencyBand
(modelClasses, frequency=2400000000.0, bandwidth=22000000.0)[source]¶ Bases:
object
The
FrequencyBand
class serves as a manager for transmission objects and represents a wireless frequency band. It also offers agetAttenuationModel()
method that returns a frequency-band-specific AttenuationModel for any pair of devices.Parameters: - modelClasses (
List
[~AttenuationModel]) – A non-empty listAttenuationModel
subclasses that will be used for attenuation calculations regarding this frequency band. - frequency (
float
) – The frequency band’s frequency in Hz. Defaults to 2.4 GHz. - bandwidth (
float
) – The frequency band’s bandwidth in Hz. Defaults to 22 MHz (as in IEEE 802.11)
-
spec
= None[source]¶ The frequency band’s specification object
Type: FrequencyBandSpec
-
nNewTransmission
= None[source]¶ A notifier that is triggered when
transmit()
is executed, providing theTransmission
object that represents the transmission.Type: Notifier
-
getAttenuationModel
(deviceA, deviceB)[source]¶ Returns the AttenuationModel instance that provides attenuation values for transmissions between deviceA and deviceB.
Return type: AttenuationModel
-
transmit
(sender, power, packet, mcsHeader, mcsPayload)[source]¶ Simulates the transmission of packet with the given properties. This is achieved by creating a
Transmission
object with the values passed and triggering thetransmissionStarted
event of theFrequencyBand
.Parameters: - sender (
Device
) – The device that transmits - mcs – The modulation and coding scheme to be used (represented by an instance of an Mcs subclass)
- power (
float
) – Transmission power in dBm - brHeader – Header bitrate
- brPayload – Payload bitrate
- packet (
Packet
) –Packet
object representing the packet being transmitted
Return type: Returns: The
Transmission
object representing the transmission- sender (
-
getActiveTransmissions
()[source]¶ Returns a list of transmissions that are currently active.
Return type: List
[Transmission
]
-
getActiveTransmissionsInReach
(receiver, radius)[source]¶ Returns a list of transmissions that are currently active and whose sender is positioned within the radius specified by radius around the receiver.
Parameters: Return type:
-
nNewTransmissionInReach
(receiver, radius)[source]¶ Returns a notifier that is triggered iff a new
Transmission
starts whose sender is positioned within the radius specified by radius around the receiver.Parameters: Return type:
- modelClasses (