DESERT 3.6.0
Loading...
Searching...
No Matches
uwphysical.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#ifndef UWPHYSICAL_H
40#define UWPHYSICAL_H
41
42#include "clmsg-stats.h"
43#include "underwater-bpsk.h"
44#include "uwinterference.h"
45
46#include <cmath>
47#include <limits>
48
49class UwPhysicalStats : public Stats
50{
51public:
56
60 UwPhysicalStats(int mod_id, int stck_id);
61
65 virtual ~UwPhysicalStats() = default;
66
73 virtual Stats *clone() const;
74
85 virtual void updateStats(int mod_id, int stck_id, double rx_pwr,
86 double noise_pwr, double interf_pwr, double sinr, double ber,
87 double per, bool error);
88
89 bool has_error;
94 double last_sinr;
95 double last_ber;
96 double last_per;
97};
98
99class UnderwaterPhysical : public UnderwaterMPhyBpsk
100{
101
102public:
107
111 virtual ~UnderwaterPhysical();
112
123 virtual int command(int, const char *const *) override;
130 virtual void recv(Packet *) override;
131
139 int recvSyncClMsg(ClMessage *m) override;
140
141protected:
145 virtual void updateInstantaneousStats();
146
153 virtual void endTx(Packet *p) override;
154
161 virtual void endRx(Packet *p) override;
162
170 virtual void startRx(Packet *p) override;
171
178 virtual double
179 consumedEnergyTx(const double &_duration) const
180 {
181 return (tx_power_ * _duration);
182 }
183
191 virtual double
192 consumedEnergyRx(const double &_duration) const
193 {
194 return (rx_power_ * _duration);
195 }
196
208 virtual double getPER(double snr, int nbits, Packet *_p);
209
222 bool
223 isZero(const double &value) const
224 {
225 return std::fabs(value) < std::numeric_limits<double>::epsilon();
226 }
227
233 double
235 {
236 return Tx_Time_;
237 }
238
244 double
246 {
247 return Rx_Time_;
248 }
249
255 double
257 {
258 return Energy_Tx_;
259 }
260
266 double
268 {
269 return Energy_Rx_;
270 }
271
277 double
279 {
280 return Transmitted_bytes_;
281 }
282
286 void
288 {
290 }
291
295 void
300
304 void
309
313 void
318
322 void
324 {
326 }
327
331 void
333 {
335 }
336
340 int
342 {
343 return tot_pkts_lost;
344 }
345
350 int
352 {
353 return tot_ctrl_pkts_lost;
354 }
355
360 int
362 {
363 return errorCtrlPktsInterf;
364 }
365
370 int
372 {
373 return collisionDataCTRL;
374 }
375
380 int
382 {
383 return collisionCTRL;
384 }
385
390 int
392 {
393 return collisionDATA;
394 }
395
401 double
402 log2(const double &_input) const
403 {
404 return (log10(_input) / log10(2));
405 }
406
413 double
414 get_prob_error_symbol_mpsk(const double &_snr, const uint32_t _M) const
415 {
416 return erfc(sqrt(_snr * log2(_M)) * sin(M_PI / _M));
417 }
418
419 std::string modulation_name_;
421 double Tx_Time_;
423 double Rx_Time_;
424 double Energy_Tx_;
426 double Energy_Rx_;
429 double tx_power_;
430 double rx_power_;
441 std::string Interference_Model;
445};
446
447#endif /* UWPHYSICAL_H */
int tot_ctrl_pkts_lost
Total number of CTRL pkts lost.
Definition uwphysical.h:432
void incrTot_pkts_lost()
Increment the number of packets discarded.
Definition uwphysical.h:287
std::string Interference_Model
Interference calcuation mode chosen: CHUNK model or MEANPOWER model.
Definition uwphysical.h:441
int tot_pkts_lost
Total number of packets lost.
Definition uwphysical.h:431
int getCollisionsDATAvsCTRL() const
Definition uwphysical.h:371
UnderwaterPhysical()
Constructor of UnderwaterPhysical class.
double tx_power_
Power required in transmission.
Definition uwphysical.h:429
bool isZero(const double &value) const
Evaluates is the number passed as input is equal to zero.
Definition uwphysical.h:223
double get_prob_error_symbol_mpsk(const double &_snr, const uint32_t _M) const
Definition uwphysical.h:414
double Tx_Time_
Time (in seconds) spent by the node in transmission.
Definition uwphysical.h:421
uwinterference * interference_
Pointer to the interference module.
Definition uwphysical.h:444
std::string modulation_name_
Modulation scheme name.
Definition uwphysical.h:419
virtual double consumedEnergyTx(const double &_duration) const
Compute the energy (in Joule) spent by the modem in transmission.
Definition uwphysical.h:179
int collisionCTRL
Total number of CTRL pkts lost due to collision.
Definition uwphysical.h:437
virtual int command(int, const char *const *) override
TCL command interpreter.
double Get_Energy_Rx() const
Returns the energy (in Joule) spent by the node in reception.
Definition uwphysical.h:267
int getCollisionsCTRL() const
Definition uwphysical.h:381
int errorCtrlPktsInterf
Total number of CTRL pkts lost due to interference.
Definition uwphysical.h:433
void incrErrorCtrlPktsInterf()
Increment the number of CTRL packets discarded due to interference.
Definition uwphysical.h:305
int getError_CtrlPktsInterf() const
Definition uwphysical.h:361
int getTot_CtrlPkts_lost() const
Definition uwphysical.h:351
double Energy_Rx_
Energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:426
double Transmitted_bytes_
Number of bytes transmitted.
Definition uwphysical.h:428
virtual void updateInstantaneousStats()
Update the stats before sending them through crosslayer message.
double Get_Energy_Tx() const
Returns the energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:256
virtual void endTx(Packet *p) override
Handles the end of a packet transmission.
virtual void recv(Packet *) override
recv method.
double Energy_Tx_
Energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:424
double rx_power_
Power required in reception.
Definition uwphysical.h:430
virtual void startRx(Packet *p) override
Handles the start of a reception.
void incrCollisionCTRL()
Increment the number of CTRL pkts discarded due to a collision.
Definition uwphysical.h:323
void incrCollisionDATAvsCTRL()
Increment the number of collisions DATA/CTRL.
Definition uwphysical.h:314
double time_ready_to_end_rx_
Used to keep track of the rx time.
Definition uwphysical.h:420
int collisionDATA
Total number of DATA pkts lost due to collision.
Definition uwphysical.h:439
virtual double consumedEnergyRx(const double &_duration) const
Compute the energy (in Joule) spent by the modem in reception.
Definition uwphysical.h:192
int collisionDataCTRL
Total number of collisions between DATA pkts and CTRL pkts.
Definition uwphysical.h:435
int recvSyncClMsg(ClMessage *m) override
recv syncronous cross layer messages to require an operation from another module
double Get_Tx_Time() const
Returns the time (in seconds) spent by the node in transmission.
Definition uwphysical.h:234
int getTot_pkts_lost() const
Definition uwphysical.h:341
virtual void endRx(Packet *p) override
Handles the end of a packet reception.
double log2(const double &_input) const
Definition uwphysical.h:402
double Rx_Time_
Time (in seconds) spent by the node in reception.
Definition uwphysical.h:423
virtual ~UnderwaterPhysical()
Destructor of UnderwaterPhysical class.
void incrCollisionDATA()
Increment the number of DATA pkts discarded due to a collision.
Definition uwphysical.h:332
virtual double getPER(double snr, int nbits, Packet *_p)
Returns the packet error rate by using the length of a packet and the information contained in the pa...
void incrTotCrtl_pkts_lost()
Increment the number of CTRL packets discarded.
Definition uwphysical.h:296
int getCollisionsDATA() const
Definition uwphysical.h:391
double Get_Transmitted_bytes() const
Returns the number of bytes transmitted.
Definition uwphysical.h:278
double Get_Rx_Time() const
Returns the time (in seconds) spent by the node in reception.
Definition uwphysical.h:245
UwPhysicalStats()
Constructor of UwPhysicalStats class.
double last_per
BER of the last received packet.
Definition uwphysical.h:96
double last_rx_power
True if last packet wasn't correctly received.
Definition uwphysical.h:90
virtual void updateStats(int mod_id, int stck_id, double rx_pwr, double noise_pwr, double interf_pwr, double sinr, double ber, double per, bool error)
Method to update stats with the param of last received packet.
virtual Stats * clone() const
Virtual method used by the Module class in order to copy its stats an a generic fashion,...
virtual ~UwPhysicalStats()=default
Destructor of UwPhysicalStats class.
double last_ber
SINR of the last received packet.
Definition uwphysical.h:95
double last_noise_power
Power of the last received packet.
Definition uwphysical.h:91
double last_interf_power
Noise power measured on query.
Definition uwphysical.h:93
double last_sinr
Interference power of the last rx packet.
Definition uwphysical.h:94
double instant_noise_power
Noise power of the last received packet.
Definition uwphysical.h:92
Implementation of uwinterference class.