DESERT 4.0.0
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 */
Definition uwphysical.h:100
int tot_ctrl_pkts_lost
Definition uwphysical.h:432
void incrTot_pkts_lost()
Definition uwphysical.h:287
std::string Interference_Model
Definition uwphysical.h:441
int tot_pkts_lost
Definition uwphysical.h:431
int getCollisionsDATAvsCTRL() const
Definition uwphysical.h:371
UnderwaterPhysical()
Definition uwphysical.cpp:111
double tx_power_
Definition uwphysical.h:429
bool isZero(const double &value) const
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_
Definition uwphysical.h:421
uwinterference * interference_
Definition uwphysical.h:444
std::string modulation_name_
Definition uwphysical.h:419
virtual double consumedEnergyTx(const double &_duration) const
Definition uwphysical.h:179
int collisionCTRL
Definition uwphysical.h:437
virtual int command(int, const char *const *) override
Definition uwphysical.cpp:142
double Get_Energy_Rx() const
Definition uwphysical.h:267
int getCollisionsCTRL() const
Definition uwphysical.h:381
int errorCtrlPktsInterf
Definition uwphysical.h:433
void incrErrorCtrlPktsInterf()
Definition uwphysical.h:305
int getError_CtrlPktsInterf() const
Definition uwphysical.h:361
int getTot_CtrlPkts_lost() const
Definition uwphysical.h:351
double Energy_Rx_
Definition uwphysical.h:426
double Transmitted_bytes_
Definition uwphysical.h:428
virtual void updateInstantaneousStats()
Definition uwphysical.cpp:614
double Get_Energy_Tx() const
Definition uwphysical.h:256
virtual void endTx(Packet *p) override
Definition uwphysical.cpp:303
virtual void recv(Packet *) override
Definition uwphysical.cpp:219
double Energy_Tx_
Definition uwphysical.h:424
double rx_power_
Definition uwphysical.h:430
virtual void startRx(Packet *p) override
Definition uwphysical.cpp:317
void incrCollisionCTRL()
Definition uwphysical.h:323
void incrCollisionDATAvsCTRL()
Definition uwphysical.h:314
double time_ready_to_end_rx_
Definition uwphysical.h:420
int collisionDATA
Definition uwphysical.h:439
virtual double consumedEnergyRx(const double &_duration) const
Definition uwphysical.h:192
int collisionDataCTRL
Definition uwphysical.h:435
int recvSyncClMsg(ClMessage *m) override
Definition uwphysical.cpp:596
double Get_Tx_Time() const
Definition uwphysical.h:234
int getTot_pkts_lost() const
Definition uwphysical.h:341
virtual void endRx(Packet *p) override
Definition uwphysical.cpp:406
double log2(const double &_input) const
Definition uwphysical.h:402
double Rx_Time_
Definition uwphysical.h:423
virtual ~UnderwaterPhysical()
Definition uwphysical.cpp:135
void incrCollisionDATA()
Definition uwphysical.h:332
virtual double getPER(double snr, int nbits, Packet *_p)
Definition uwphysical.cpp:565
void incrTotCrtl_pkts_lost()
Definition uwphysical.h:296
int getCollisionsDATA() const
Definition uwphysical.h:391
double Get_Transmitted_bytes() const
Definition uwphysical.h:278
double Get_Rx_Time() const
Definition uwphysical.h:245
Definition uwphysical.h:50
UwPhysicalStats()
Definition uwphysical.cpp:47
double last_per
Definition uwphysical.h:96
double last_rx_power
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)
Definition uwphysical.cpp:75
virtual Stats * clone() const
Definition uwphysical.cpp:92
virtual ~UwPhysicalStats()=default
bool has_error
Definition uwphysical.h:89
double last_ber
Definition uwphysical.h:95
double last_noise_power
Definition uwphysical.h:91
double last_interf_power
Definition uwphysical.h:93
double last_sinr
Definition uwphysical.h:94
double instant_noise_power
Definition uwphysical.h:92
Definition uwinterference.h:151
Implementation of uwinterference class.