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.ABCThe
Mcsclass 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.Mcsobjects also provide abitRateand adataRateattribute, which specify the physical bit rate and the effective data rate of transmissions with the correspondingMcs.Currently, only BPSK modulation is implemented (see
BpskMcsfor details). SubclassMcsif 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.McsA 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:
objectA
Transmissionmodels the process of a device sending a specific packet via a communication frequency band.Note
The proper way to instantiate
Transmissionobjects 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:
objectA frequency band specification stores a
FrequencyBand’s frequency and its bandwidth.Parameters:
-
class
AttenuationModel(frequencyBandSpec, deviceA, deviceB)[source]¶ Bases:
objectAn
AttenuationModelcalculates 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 theNetworkDeviceinstances it belongs to. When the attenuation value changes, theattenuationChangedevent 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
NetworkDevicedeviceA toNetworkDevicedeviceB (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.ABCAn
AttenuationModelsubclass 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
AttenuationModelnot to react on position changes of its devicesType: float
-
-
class
JoinedAttenuationModel(frequencyBandSpec, deviceA, deviceB, models)[source]¶ Bases:
gymwipe.networking.physical.AttenuationModelAn
AttenuationModelthat adds the attenuation values of two or more givenAttenuationModelinstances. If the position of one of both devices is changed, it will gather the update notifications of itsAttenuationModelinstances, sum them up and trigger thenAttenuationChangesnotifier only once after the updates (this is implemented using callback priorities). When anAttenuationModelinstance changes its attenuation without reacting to a position update, thenAttenuationChangesnotifier of theJoinedAttenuationModelwill 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 theAttenuationModelsubclasses to create aJoinedAttenuationModelinstance of
- frequencyBandSpec (
-
class
AttenuationModelFactory(frequencyBandSpec, models)[source]¶ Bases:
objectA factory for
AttenuationModelinstances.Parameters: - frequencyBandSpec (
FrequencyBandSpec) – The frequency band specification of the correspondingFrequencyBand - models (
List[~AttenuationModel]) – A non-empty list ofAttenuationModelsubclasses that will be used for instantiating attenuation models.
-
setCustomModels(deviceA, deviceB, models)[source]¶ Sets the
AttenuationModelsubclasses 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
AttenuationModelinstance 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 ofAttenuationModelsubclasses 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
AttenuationModelfor signals sent from deviceA to deviceB and vice versa. If not yet existent, a newAttenuationModelinstance will be created. If the factory was initialized with multipleAttenuationModelsubclasses, aJoinedAttenuationModelwill be handed out.Return type: AttenuationModel
- frequencyBandSpec (
-
class
FrequencyBand(modelClasses, frequency=2400000000.0, bandwidth=22000000.0)[source]¶ Bases:
objectThe
FrequencyBandclass 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 listAttenuationModelsubclasses 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 theTransmissionobject 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
Transmissionobject with the values passed and triggering thetransmissionStartedevent 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) –Packetobject representing the packet being transmitted
Return type: Returns: The
Transmissionobject 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
Transmissionstarts whose sender is positioned within the radius specified by radius around the receiver.Parameters: Return type:
- modelClasses (