DESERT 4.0.0
uwofdmphy.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
41#ifndef UWOFDMPHY_H
42#define UWOFDMPHY_H
43
44#include "string.h"
45#include "uwofdmphy_hdr.h"
46#include "uwphysical.h"
47#include <ctime>
48#include <iostream>
49#include <map>
50#include <math.h>
51#include <phymac-clmsg.h>
52
53#include "msg-display.h"
54
55extern packet_t PT_MMAC_CTS;
56extern packet_t PT_MMAC_DATA;
57extern packet_t PT_MMAC_RTS;
58extern packet_t PT_MMAC_ACK;
59
60typedef ::std::map<double, double> PdrLut;
61typedef PdrLut::iterator PdrLutIt;
62
74
76{
77
78public:
82 UwOFDMPhy();
83
87 virtual ~UwOFDMPhy();
88
99 virtual int command(int, const char *const *);
100
101 // Initialize parameters inside a node, default all carriers are used
102 void init_ofdm_node(int nn, int cf, int scn, int ID);
103
104 // set the size of a node buffer
105 void setBufferSize(int);
106
107 // Returns number of nodes in the simulation for a given node
108 int getNodeNum() const;
109
110 // Returns Packets sent to Mac Layer
111 int getSentUpPkts();
112
113 // Set number of nodes in the simulation for a given node
114 void setNodeNum(int);
115
116 // Returns total number of SubCarriers available for a given node
117 int getSubCarNum() const;
118
119 // Returns total number of packets lost for low SNR
120 int getLowSnrPktLost() const;
121
122 // Returns total number of packets lost for noise error
123 int getNoiseErrPktLost() const;
124
125 // Returns total number of packets lost for Collision error
126 int getCollErrPktLost() const;
127
128 // Returns total number of packets lost for transmission pending
129 int getTxPenPktLost() const;
130
131 // Returns number of ctrl packets lost for transmission pending
132 int getTxPenCtrlLost() const;
133
134 // Returns total number of packets lost for collision in frequency
135 int getFreqCollPktLost() const;
136
137 // Returns total number of CTRL Packets lost for collision error
138 int getCtrlCErrPktLost() const;
139
140 // Returns total number of CTRL Packets lost for collision in frequency
141 int getCtrlFCollPktLost() const;
142
143 // Returns total number of SubCarriers available for a given node
144 int getModErrPktLost() const;
145
146 // Returns total number of packets sent by phy layer
147 int getPhyPktSent() const;
148
149 // Set number of nodes in the simulation for a given node
150 void setSubCarNum(int);
151
152 // Set node ID
153 void setNodeID(int);
154
155 // Shows chosen subcarriers for a given node
156 void showSubCar();
157
158 // sets subcarriers from outside the class
159 void setSubCar(int, int);
160
161 // sets broken subcarriers from outside simulation
162 void setBrokenCar(int, int);
163
164 int getNodeID() const;
165
166 // Returns the sum of all transmission times
167 double getTransmissionTime() const;
168
169 // True if packets are overlappin in frequency, false otherwise
170 bool freqOverlap(Packet *, bool);
171
172 // True if a transmission is happening
174
175protected:
182 virtual void recv(Packet *);
183
190 virtual void endRx(Packet *p);
191
198 virtual void startRx(Packet *p);
199
207 virtual void endTx(Packet *p);
208
221 virtual double getOFDMPER(double _snr, int _nbits, Packet *);
222
231 virtual double getOFDMNoisePower(Packet *p);
232
241 double getTxDuration(Packet *p);
242
249 void createOFDMhdr(Packet *p);
250
255 void interruptReceptions();
256
260 int recvSyncClMsg(ClMessage *m);
261
265 void plotPktQueue();
266
267private:
274 virtual double getDistance(Packet *);
275
283 virtual double getPropagationDelay(Packet *);
284
288 inline virtual int
290 {
291 return total_delay_;
292 }
293
298 inline string
299 itos(int i)
300 {
301 return std::to_string(i);
302 }
303
308 inline string
309 dtos(double d)
310 {
311 return std::to_string(d);
312 }
313
314 int buffered_pkt_num; // keeps track of number of incoming packet
315 int current_rcvs; // number of packets currently being received
316 int nodeNum_; // indicated the total number of nodes
317 int centerFreq_; // Center frequency of the system
318 int subCarrier_; // indicates maximum number of subcarrier
319 int nodeID_; // corresponding node ID
320 double total_delay_; // total delay. not used eventually. the RX time is
321 // modified to reflect the delay
322 int powerScaling; // 1 if power scales with percentage of used carriers
323
324 int FRAME_BIT; // by default = (9120 info bit +32 CRC bit)
325
326 int bufferSize_; // default
327
328 std::vector<Packet> pktqueue_;
329 std::vector<Packet *> txqueue_;
330 std::vector<double> timesqueue_;
331 std::vector<double>
332 brokenCarriers_; // Keeps top and bottom index of broken carriers
333
334 int sentUpPkts; // number of packets sent to upper layer
335 int lostPackets[8] =
336 {0, 0, 0, 0, 0, 0, 0, 0}; // lost packets divided by reason
337 double totTransTime; // total transmission time of all transmitted packets
338 int phySentPkt_; // number of packets sent into the channel
339
340 // double NoiseSPD_;
341 // double ConsumedEnergy_;
342 // double TxPower_ = 130.0; /// Tx Power in W. Simple adaptations of the
348
349 int tx_busy_; // 1 if a transmission in happening, 0 otherwise
350
351 MsgDisplayer msgDisp; // object of MsgDisplayer type
352};
353
354#endif /* UWOFDMPHY_H */
Definition msg-display.h:44
Definition uwphysical.h:100
Definition uwofdmphy.h:76
int getModErrPktLost() const
Definition uwofdmphy.cpp:1097
int getTxPenPktLost() const
Definition uwofdmphy.cpp:1076
int buffered_pkt_num
Definition uwofdmphy.h:314
virtual void startRx(Packet *p)
Definition uwofdmphy.cpp:374
virtual double getDistance(Packet *)
Definition uwofdmphy.cpp:958
int sentUpPkts
Definition uwofdmphy.h:334
void setSubCarNum(int)
Definition uwofdmphy.cpp:1172
double totTransTime
Definition uwofdmphy.h:337
virtual double getOFDMPER(double _snr, int _nbits, Packet *)
Definition uwofdmphy.cpp:874
int bufferSize_
Definition uwofdmphy.h:326
int FRAME_BIT
Definition uwofdmphy.h:324
int getCollErrPktLost() const
Definition uwofdmphy.cpp:1069
void setNodeNum(int)
Definition uwofdmphy.cpp:1151
std::vector< double > timesqueue_
Definition uwofdmphy.h:330
int phySentPkt_
Definition uwofdmphy.h:338
int powerScaling
Definition uwofdmphy.h:322
UwOFDMPhy()
Definition uwofdmphy.cpp:59
int tx_busy_
Definition uwofdmphy.h:349
double getTxDuration(Packet *p)
Definition uwofdmphy.cpp:811
int nodeID_
Definition uwofdmphy.h:319
virtual int getTotalDelay()
Definition uwofdmphy.h:289
int getCtrlFCollPktLost() const
Definition uwofdmphy.cpp:1104
int current_rcvs
Definition uwofdmphy.h:315
int getSubCarNum() const
Definition uwofdmphy.cpp:1144
virtual int command(int, const char *const *)
Definition uwofdmphy.cpp:85
int subCarrier_
Definition uwofdmphy.h:318
virtual ~UwOFDMPhy()
Definition uwofdmphy.cpp:80
MsgDisplayer msgDisp
Definition uwofdmphy.h:351
void init_ofdm_node(int nn, int cf, int scn, int ID)
Definition uwofdmphy.cpp:182
std::vector< Packet > pktqueue_
Definition uwofdmphy.h:328
void setBrokenCar(int, int)
Definition uwofdmphy.cpp:1178
void setNodeID(int)
Definition uwofdmphy.cpp:1164
void interruptReceptions()
Definition uwofdmphy.cpp:794
void plotPktQueue()
Definition uwofdmphy.cpp:1223
double total_delay_
Definition uwofdmphy.h:320
virtual double getOFDMNoisePower(Packet *p)
Definition uwofdmphy.cpp:934
int getFreqCollPktLost() const
Definition uwofdmphy.cpp:1090
bool freqOverlap(Packet *, bool)
Definition uwofdmphy.cpp:985
int getNodeNum() const
Definition uwofdmphy.cpp:1137
string dtos(double d)
Definition uwofdmphy.h:309
virtual double getPropagationDelay(Packet *)
Definition uwofdmphy.cpp:975
virtual void endTx(Packet *p)
Definition uwofdmphy.cpp:351
int getTxPenCtrlLost() const
Definition uwofdmphy.cpp:1083
double getTransmissionTime() const
Definition uwofdmphy.cpp:1117
void createOFDMhdr(Packet *p)
Definition uwofdmphy.cpp:1013
virtual void recv(Packet *)
Definition uwofdmphy.cpp:204
int lostPackets[8]
Definition uwofdmphy.h:335
std::vector< double > brokenCarriers_
Definition uwofdmphy.h:332
virtual void endRx(Packet *p)
Definition uwofdmphy.cpp:513
int nodeNum_
Definition uwofdmphy.h:316
std::vector< Packet * > txqueue_
Definition uwofdmphy.h:329
int getLowSnrPktLost() const
Definition uwofdmphy.cpp:1055
int centerFreq_
Definition uwofdmphy.h:317
int getPhyPktSent() const
Definition uwofdmphy.cpp:1123
void showSubCar()
Definition uwofdmphy.cpp:1187
int getCtrlCErrPktLost() const
Definition uwofdmphy.cpp:1111
void setSubCar(int, int)
Definition uwofdmphy.cpp:1195
int getSentUpPkts()
Definition uwofdmphy.cpp:1157
void setBufferSize(int)
Definition uwofdmphy.cpp:174
int getNodeID() const
Definition uwofdmphy.cpp:1130
int getNoiseErrPktLost() const
Definition uwofdmphy.cpp:1062
bool txongoing_
Definition uwofdmphy.h:173
int recvSyncClMsg(ClMessage *m)
Definition uwofdmphy.cpp:1202
string itos(int i)
Definition uwofdmphy.h:299
Class that provide the implementation of an object to display messages.
PdrLut::iterator PdrLutIt
Definition uwofdmphy.h:61
errordistribution
Definition uwofdmphy.h:63
@ TXPEN
Definition uwofdmphy.h:67
@ TXPENCTRL
Definition uwofdmphy.h:72
@ LOWSNR
Definition uwofdmphy.h:64
@ MODERR
Definition uwofdmphy.h:69
@ NOISEERR
Definition uwofdmphy.h:65
@ FREQCOLL
Definition uwofdmphy.h:68
@ COLLERR
Definition uwofdmphy.h:66
@ CTRLFERR
Definition uwofdmphy.h:71
@ CTRLCERR
Definition uwofdmphy.h:70
packet_t PT_MMAC_DATA
Definition initlib.cpp:45
packet_t PT_MMAC_CTS
Definition initlib.cpp:42
packet_t PT_MMAC_RTS
Definition initlib.cpp:43
packet_t PT_MMAC_ACK
Definition initlib.cpp:44
::std::map< double, double > PdrLut
Definition uwofdmphy.h:60
Common structures and variables in the protocol.
Definition of UwPhysical class.