DESERT 3.5.1
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 "underwater-bpsk.h"
43#include "uwinterference.h"
44#include "mac.h"
45
46#include "clmsg-stats.h"
47#include <phymac-clmsg.h>
48#include <string.h>
49
50#include <rng.h>
51#include <packet.h>
52#include <module.h>
53#include <tclcl.h>
54
55#include <iostream>
56#include <string.h>
57#include <cmath>
58#include <limits>
59#include <climits>
60
61class UwPhysicalStats : public Stats
62{
63public:
68
72 UwPhysicalStats(int mod_id, int stck_id);
73
78 {
79 }
80
86 virtual Stats* clone() const;
87
98 virtual void updateStats(int mod_id, int stck_id, double rx_pwr,
99 double noise_pwr, double interf_pwr, double sinr, double ber, double per, bool error);
100
105 double last_sinr;
106 double last_ber;
107 double last_per;
109};
110
111
112class UnderwaterPhysical : public UnderwaterMPhyBpsk
113{
114
115public:
120
124 virtual ~UnderwaterPhysical();
125
136 virtual int command(int, const char *const *);
143 virtual void recv(Packet *);
144
151 int recvSyncClMsg(ClMessage* m);
152
153protected:
157 virtual void updateInstantaneousStats();
158
165 virtual void endTx(Packet *p);
172 virtual void endRx(Packet *p);
180 virtual void startRx(Packet *p);
187 inline virtual double
188 consumedEnergyTx(const double &_duration)
189 {
190 return (tx_power_ * _duration);
191 }
199 inline virtual double
200 consumedEnergyRx(const double &_duration)
201 {
202 return (rx_power_ * _duration);
203 }
204
216 virtual double getPER(double snr, int nbits, Packet *);
217
230 inline const bool
231 isZero(const double &value) const
232 {
233 return std::fabs(value) < std::numeric_limits<double>::epsilon();
234 }
235
241 inline double
243 {
244 return Tx_Time_;
245 }
246
252 inline double
254 {
255 return Rx_Time_;
256 }
257
263 inline double
265 {
266 return Energy_Tx_;
267 }
268
274 inline double
276 {
277 return Energy_Rx_;
278 }
279
285 inline double
287 {
288 return Transmitted_bytes_;
289 }
290
294 inline void
296 {
298 }
299
303 inline void
308
312 inline void
317
321 inline void
326
330 inline void
332 {
334 }
335
339 inline void
341 {
343 }
344
349 inline int
351 {
352 return tot_pkts_lost;
353 }
354
359 inline int
361 {
362 return tot_ctrl_pkts_lost;
363 }
364
369 inline int
374
379 inline int
384
389 inline int
391 {
392 return collisionCTRL;
393 }
394
399 inline int
401 {
402 return collisionDATA;
403 }
404
410 inline const double
411 log2(const double &_input) const
412 {
413 return (log10(_input) / log10(2));
414 }
415
422 inline const double
423 get_prob_error_symbol_mpsk(const double &_snr, const uint32_t _M) const
424 {
425 return erfc(sqrt(_snr * log2(_M)) * sin(M_PI / _M));
426 }
427
428 // Variables
429 std::string modulation_name_;
433 double Tx_Time_;
435 double Rx_Time_;
437 double
440 double
446 double tx_power_;
447 double rx_power_;
463 std::string Interference_Model;
468private:
469 // Variables
470};
471
472#endif /* UWPHYSICAL_H */
int tot_ctrl_pkts_lost
Total number of CTRL pkts lost.
Definition uwphysical.h:451
virtual void endRx(Packet *p)
Handles the end of a packet reception.
void incrTot_pkts_lost()
Increment the number of packets discarded.
Definition uwphysical.h:295
std::string Interference_Model
Interference calcuation mode chosen: CHUNK model or MEANPOWER model.
Definition uwphysical.h:463
int tot_pkts_lost
Total number of packets lost.
Definition uwphysical.h:449
virtual double consumedEnergyTx(const double &_duration)
Compute the energy (in Joule) spent by the modem in transmission.
Definition uwphysical.h:188
UnderwaterPhysical()
Constructor of UnderwaterPhysical class.
int recvSyncClMsg(ClMessage *m)
recv syncronous cross layer messages to require an operation from another module
double tx_power_
Power required in transmission.
Definition uwphysical.h:446
virtual double consumedEnergyRx(const double &_duration)
Compute the energy (in Joule) spent by the modem in reception.
Definition uwphysical.h:200
double Tx_Time_
Time (in seconds) spent by the node in transmission.
Definition uwphysical.h:433
uwinterference * interference_
Pointer to the interference model module.
Definition uwphysical.h:467
std::string modulation_name_
Modulation scheme name.
Definition uwphysical.h:429
int collisionCTRL
Total number of CTRL pkts lost due to collision.
Definition uwphysical.h:459
double Get_Energy_Rx()
Returns the energy (in Joule) spent by the node in reception.
Definition uwphysical.h:275
int getError_CtrlPktsInterf()
Definition uwphysical.h:370
virtual void endTx(Packet *p)
Handles the end of a packet transmission.
int errorCtrlPktsInterf
Total number of CTRL pkts lost due to interference.
Definition uwphysical.h:453
void incrErrorCtrlPktsInterf()
Increment the number of CTRL packets discarded due to interference.
Definition uwphysical.h:313
virtual double getPER(double snr, int nbits, Packet *)
Returns the packet error rate by using the length of a packet and the information contained in the pa...
double Energy_Rx_
Energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:441
double Transmitted_bytes_
Number of bytes transmitted.
Definition uwphysical.h:444
virtual void updateInstantaneousStats()
Update the stats before sending them through crosslayer message.
virtual void startRx(Packet *p)
Handles the start of a reception.
virtual void recv(Packet *)
recv method.
const double log2(const double &_input) const
Definition uwphysical.h:411
double Get_Rx_Time()
Returns the time (in seconds) spent by the node in reception.
Definition uwphysical.h:253
double Energy_Tx_
Energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:438
double Get_Energy_Tx()
Returns the energy (in Joule) spent by the node in transmission.
Definition uwphysical.h:264
double rx_power_
Power required in reception.
Definition uwphysical.h:447
void incrCollisionCTRL()
Increment the number of CTRL pkts discarded due to a collision.
Definition uwphysical.h:331
void incrCollisionDATAvsCTRL()
Increment the number of collisions DATA/CTRL.
Definition uwphysical.h:322
double Get_Transmitted_bytes()
Returns the number of bytes transmitted.
Definition uwphysical.h:286
double time_ready_to_end_rx_
Used to keep track of the arrival time.
Definition uwphysical.h:430
const bool isZero(const double &value) const
Evaluates is the number passed as input is equal to zero.
Definition uwphysical.h:231
int collisionDATA
Total number of DATA pkts lost due to collision.
Definition uwphysical.h:461
int collisionDataCTRL
Total number of collisions between DATA pkts and CTRL pkts.
Definition uwphysical.h:456
double Get_Tx_Time()
Returns the time (in seconds) spent by the node in transmission.
Definition uwphysical.h:242
int getCollisionsDATAvsCTRL()
Definition uwphysical.h:380
const double get_prob_error_symbol_mpsk(const double &_snr, const uint32_t _M) const
Definition uwphysical.h:423
double Rx_Time_
Time (in seconds) spent by the node in reception.
Definition uwphysical.h:435
virtual ~UnderwaterPhysical()
Destructor of UnderwaterPhysical class.
virtual int command(int, const char *const *)
TCL command interpreter.
void incrCollisionDATA()
Increment the number of DATA pkts discarded due to a collision.
Definition uwphysical.h:340
void incrTotCrtl_pkts_lost()
Increment the number of CTRL packets discarded.
Definition uwphysical.h:304
UwPhysicalStats()
Constructor of UwPhysicalStats class.
double last_per
BER of the last received packet.
Definition uwphysical.h:107
virtual ~UwPhysicalStats()
Destructor of UwPhysicalStats class.
Definition uwphysical.h:77
double last_rx_power
Definition uwphysical.h:101
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,...
bool has_error
PER of the last received packet.
Definition uwphysical.h:108
double last_ber
SINR of the last received packet.
Definition uwphysical.h:106
double last_noise_power
Power of the last received packet.
Definition uwphysical.h:102
double last_interf_power
Noise power measured on query.
Definition uwphysical.h:104
double last_sinr
Interference power of the last rx packet.
Definition uwphysical.h:105
double instant_noise_power
Noise power of the last received packet.
Definition uwphysical.h:103
Implementation of uwinterference class.