DESERT 3.5.1
Loading...
Searching...
No Matches
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 "uwphysical.h"
45#include "string.h"
46#include "uwofdmphy_hdr.h"
47#include <math.h>
48#include <iostream>
49#include <map>
50#include <ctime>
51#include <phymac-clmsg.h>
52
53
54#include "msg-display.h"
55
56extern packet_t PT_MMAC_CTS;
57extern packet_t PT_MMAC_DATA;
58extern packet_t PT_MMAC_RTS;
59extern packet_t PT_MMAC_ACK;
60
61typedef ::std::map<double, double> PdrLut;
62typedef PdrLut::iterator PdrLutIt;
63
65
67{
68
69public:
73 UwOFDMPhy();
74
78 virtual ~UwOFDMPhy();
79
90 virtual int command(int, const char *const *);
91
92 //Initialize parameters inside a node, default all carriers are used
93 void init_ofdm_node(int nn, int cf, int scn, int ID);
94
95 //set the size of a node buffer
96 void setBufferSize(int);
97
98 //Returns number of nodes in the simulation for a given node
99 int getNodeNum() const;
100
101 //Returns Packets sent to Mac Layer
102 int getSentUpPkts();
103
104 //Set number of nodes in the simulation for a given node
105 void setNodeNum(int);
106
107 //Returns total number of SubCarriers available for a given node
108 int getSubCarNum() const;
109
110 //Returns total number of packets lost for low SNR
111 int getLowSnrPktLost() const;
112
113 //Returns total number of packets lost for noise error
114 int getNoiseErrPktLost() const;
115
116 //Returns total number of packets lost for Collision error
117 int getCollErrPktLost() const;
118
119 //Returns total number of packets lost for transmission pending
120 int getTxPenPktLost() const;
121
122 //Returns number of ctrl packets lost for transmission pending
123 int getTxPenCtrlLost() const;
124
125 //Returns total number of packets lost for collision in frequency
126 int getFreqCollPktLost() const;
127
128 //Returns total number of CTRL Packets lost for collision error
129 int getCtrlCErrPktLost() const;
130
131 //Returns total number of CTRL Packets lost for collision in frequency
132 int getCtrlFCollPktLost() const;
133
134 //Returns total number of SubCarriers available for a given node
135 int getModErrPktLost() const;
136
137 //Returns total number of packets sent by phy layer
138 int getPhyPktSent() const;
139
140 //Set number of nodes in the simulation for a given node
141 void setSubCarNum(int);
142
143 //Set node ID
144 void setNodeID(int);
145
146 //Shows chosen subcarriers for a given node
147 void showSubCar();
148
149 //sets subcarriers from outside the class
150 void setSubCar(int, int);
151
152 //sets broken subcarriers from outside simulation
153 void setBrokenCar(int, int);
154
155 int getNodeID() const;
156
157 //Returns the sum of all transmission times
158 double getTransmissionTime() const;
159
160 //True if packets are overlappin in frequency, false otherwise
161 bool freqOverlap(Packet*, bool);
162
163 //True if a transmission is happening
165
166protected:
173 virtual void recv(Packet *);
174
181 virtual void endRx(Packet *p);
182
189 virtual void startRx(Packet *p);
190
198 virtual void endTx(Packet *p);
199
212 virtual double getOFDMPER(double _snr, int _nbits, Packet *);
213
222 virtual double getOFDMNoisePower(Packet* p);
223
232 double getTxDuration(Packet* p);
233
240 void createOFDMhdr(Packet* p);
241
246 void interruptReceptions();
247
251 int recvSyncClMsg(ClMessage* m);
252
256 void plotPktQueue();
257
258
259private:
266 virtual double getDistance(Packet *);
267
275 virtual double getPropagationDelay(Packet *);
276
280 inline virtual int
282 {
283 return total_delay_;
284 }
285
290 inline string
291 itos(int i)
292 {
293 return std::to_string(i);
294 }
295
300 inline string
301 dtos(double d)
302 {
303 return std::to_string(d);
304 }
305
306 int buffered_pkt_num; // keeps track of number of incoming packet
307 int current_rcvs; // number of packets currently being received
308 int nodeNum_; // indicated the total number of nodes
309 int centerFreq_; // Center frequency of the system
310 int subCarrier_; // indicates maximum number of subcarrier
311 int nodeID_; // corresponding node ID
312 double total_delay_; // total delay. not used eventually. the RX time is modified to reflect the delay
313 int powerScaling; // 1 if power scales with percentage of used carriers
314
315 int FRAME_BIT; // by default = (9120 info bit +32 CRC bit)
316
317 int bufferSize_; //default
318
319 std::vector<Packet> pktqueue_;
320 std::vector<Packet *> txqueue_;
321 std::vector<double> timesqueue_;
322 std::vector<double> brokenCarriers_; // Keeps top and bottom index of broken carriers
323
324 int sentUpPkts; // number of packets sent to upper layer
325 int lostPackets[8]={0,0,0,0,0,0,0,0}; //lost packets divided by reason
326 double totTransTime; // total transmission time of all transmitted packets
327 int phySentPkt_; // number of packets sent into the channel
328
329 //double NoiseSPD_;
330 //double ConsumedEnergy_;
331 //double TxPower_ = 130.0; /// Tx Power in W. Simple adaptations of the
337
338 int tx_busy_; // 1 if a transmission in happening, 0 otherwise
339
340 MsgDisplayer msgDisp; //object of MsgDisplayer type
341
342};
343
344#endif /* UWOFDMPHY_H */
int getModErrPktLost() const
int getTxPenPktLost() const
int buffered_pkt_num
Definition uwofdmphy.h:306
virtual void startRx(Packet *p)
Handles the start of a packet reception.
virtual double getDistance(Packet *)
Return the distance between source and destination.
int sentUpPkts
Definition uwofdmphy.h:324
void setSubCarNum(int)
double totTransTime
Definition uwofdmphy.h:326
virtual double getOFDMPER(double _snr, int _nbits, Packet *)
Returns the packet error rate by using the length of a packet and the information contained in the pa...
int bufferSize_
Definition uwofdmphy.h:317
int FRAME_BIT
Definition uwofdmphy.h:315
int getCollErrPktLost() const
void setNodeNum(int)
std::vector< double > timesqueue_
Definition uwofdmphy.h:321
int phySentPkt_
Definition uwofdmphy.h:327
int powerScaling
Definition uwofdmphy.h:313
UwOFDMPhy()
Constructor of UwOFDMPhy class.
Definition uwofdmphy.cpp:59
int tx_busy_
transmission power might be carried out just by re-setting this value.
Definition uwofdmphy.h:338
double getTxDuration(Packet *p)
Computes the transmission time duration depending on the used carriers.
int nodeID_
Definition uwofdmphy.h:311
virtual int getTotalDelay()
returns total delay
Definition uwofdmphy.h:281
int getCtrlFCollPktLost() const
int current_rcvs
Definition uwofdmphy.h:307
int getSubCarNum() const
virtual int command(int, const char *const *)
TCL command interpreter.
Definition uwofdmphy.cpp:74
int subCarrier_
Definition uwofdmphy.h:310
virtual ~UwOFDMPhy()
Destructor of UwOFDMPhy class.
Definition uwofdmphy.cpp:70
MsgDisplayer msgDisp
Definition uwofdmphy.h:340
void init_ofdm_node(int nn, int cf, int scn, int ID)
std::vector< Packet > pktqueue_
Definition uwofdmphy.h:319
void setBrokenCar(int, int)
void setNodeID(int)
void interruptReceptions()
Interrupts reception if MAC has other priorities Theoretically should never be called.
void plotPktQueue()
Plots pktqueue elements.
double total_delay_
Definition uwofdmphy.h:312
virtual double getOFDMNoisePower(Packet *p)
Handles the end of a transmission, redefined to scale the power into the carriers.
int getFreqCollPktLost() const
bool freqOverlap(Packet *, bool)
int getNodeNum() const
string dtos(double d)
Definition uwofdmphy.h:301
virtual double getPropagationDelay(Packet *)
Return the propagation delay for the packet.
virtual void endTx(Packet *p)
Handles the end of a transmission, redefined to scale the power into the carriers.
int getTxPenCtrlLost() const
double getTransmissionTime() const
void createOFDMhdr(Packet *p)
Creates an OFDM header for non-OFDM packets.
virtual void recv(Packet *)
recv method.
int lostPackets[8]
Definition uwofdmphy.h:325
std::vector< double > brokenCarriers_
Definition uwofdmphy.h:322
virtual void endRx(Packet *p)
Handles the end of a packet reception.
int nodeNum_
Definition uwofdmphy.h:308
std::vector< Packet * > txqueue_
Definition uwofdmphy.h:320
int getLowSnrPktLost() const
int centerFreq_
Definition uwofdmphy.h:309
int getPhyPktSent() const
void showSubCar()
int getCtrlCErrPktLost() const
void setSubCar(int, int)
int getSentUpPkts()
void setBufferSize(int)
int getNodeID() const
int getNoiseErrPktLost() const
bool txongoing_
Definition uwofdmphy.h:164
int recvSyncClMsg(ClMessage *m)
Handles receiving messages from the MAC layer.
string itos(int i)
Definition uwofdmphy.h:291
Class that provide the implementation of an object to display messages.
PdrLut::iterator PdrLutIt
Definition uwofdmphy.h:62
errordistribution
Definition uwofdmphy.h:64
@ TXPEN
Definition uwofdmphy.h:64
@ TXPENCTRL
Definition uwofdmphy.h:64
@ LOWSNR
Definition uwofdmphy.h:64
@ MODERR
Definition uwofdmphy.h:64
@ NOISEERR
Definition uwofdmphy.h:64
@ FREQCOLL
Definition uwofdmphy.h:64
@ COLLERR
Definition uwofdmphy.h:64
@ CTRLFERR
Definition uwofdmphy.h:64
@ CTRLCERR
Definition uwofdmphy.h:64
::std::map< double, double > PdrLut
Definition uwofdmphy.h:61
Common structures and variables in the protocol.
Definition of UwPhysical class.