-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractRadio.h
238 lines (189 loc) · 7.35 KB
/
AbstractRadio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// Copyright (C) 2006 Andras Varga, Levente Meszaros
// Based on the Mobility Framework's SnrEval by Marc Loebbers
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
#ifndef ABSTRACTRADIO_H
#define ABSTRACTRADIO_H
#include "ChannelAccess.h"
#include "RadioState.h"
#include "PhyState.h"
#include "AirFrame_m.h"
#include "IRadioModel.h"
#include "IReceptionModel.h"
#include "SnrList.h"
/**
* Abstract base class for radio modules. Radio modules deal with the
* transmission of frames over a wireless medium (the radio channel).
* See the Radio module's NED documentation for an overview of radio modules.
*
* This class implements common functionality of the radio, and abstracts
* out specific parts into two interfaces, IReceptionModel and IRadioModel.
* The reception model is responsible for modelling path loss, interference
* and antenna gain. The radio model is responsible for calculating frame
* duration, and modelling modulation scheme and possible forward error
* correction. Subclasses have to redefine the <tt>createReceptionModel()</tt>
* and <tt>createRadioModel()</tt> methods to create and return appropriate
* reception model and radio model objects.
*
* <b>History</b>
*
* The implementation is largely based on the Mobility Framework's
* SnrEval and Decider modules. They have been merged into a single
* module, multi-channel support, runtime channel and bitrate switching
* capability added, and all code specific to the physical channel
* and radio characteristics have been factored out into the IReceptionModel
* and IRadioModel classes.
*
* @author Andras Varga, Levente Meszaros
*/
class INET_API AbstractRadio : public ChannelAccess
{
public:
AbstractRadio();
virtual ~AbstractRadio();
protected:
virtual void initialize(int stage);
virtual void finish();
virtual void handleMessage(cMessage *msg);
virtual void handleUpperMsg(AirFrame*);
virtual void handleSelfMsg(cMessage*);
virtual void handleCommand(int msgkind, cPolymorphic *ctrl);
/** @brief Buffer the frame and update noise levels and snr information */
virtual void handleLowerMsgStart(AirFrame *airframe);
/** @brief Unbuffer the frame and update noise levels and snr information */
virtual void handleLowerMsgEnd(AirFrame *airframe);
/** @brief Buffers message for 'transmission time' */
virtual void bufferMsg(AirFrame *airframe);
/** @brief Unbuffers a message after 'transmission time' */
virtual AirFrame *unbufferMsg(cMessage *msg);
/** Sends a message to the upper layer */
virtual void sendUp(AirFrame *airframe);
/** Sends a message to the channel */
virtual void sendDown(AirFrame *airframe);
/** Encapsulates a MAC frame into an Air Frame */
virtual AirFrame *encapsulatePacket(cPacket *msg);
/** Sets the radio state, and also fires change notification */
virtual void setRadioState(RadioState::State newState);
/** Returns the current channel the radio is tuned to */
virtual int getChannelNumber() const {return rs.getChannelNumber();}
/** Updates the SNR information of the relevant AirFrame */
virtual void addNewSnr();
/** Create a new AirFrame */
virtual AirFrame *createAirFrame() {return new AirFrame();}
/**
* Change transmitter and receiver to a new channel.
* This method throws an error if the radio state is transmit.
* Messages that are already sent to the new channel and would
* reach us in the future - thus they are on the air - will be
* received correctly.
*/
virtual void changeChannel(int channel);
/**
* Change the bitrate to the given value. This method throws an error
* if the radio state is transmit.
*/
virtual void setBitrate(double bitrate);
/**
* To be defined to provide a reception model. The reception model
* is responsible for modelling path loss, interference and antenna
* gain.
*/
virtual IReceptionModel *createReceptionModel() = 0;
/**
* To be defined to provide a radio model. The radio model is
* responsible for calculating frame duration, and modelling modulation
* scheme and possible forward error correction.
*/
virtual IRadioModel *createRadioModel() = 0;
protected:
IRadioModel *radioModel;
IReceptionModel *receptionModel;
/** Power used to transmit messages */
double transmitterPower;
/** @name Gate Ids */
//@{
int uppergateOut;
int uppergateIn;
//@}
int maxQueueSize;
//Paolo's stuff
AirFrame *phybuffer;
AirFrame *buffer;
cMessage *reschedule;
cMessage *phybusy;
cMessage *phytimer;
//Uche's stuff for CSMA in Radio
typedef std::list<AirFrame*> FrameList;
FrameList abstracttransmissionQueue;
/**
*
* Struct to store a pointer to the message, rcvdPower AND a SnrList,
* needed in addNewSnr().
*/
struct SnrStruct
{
AirFrame *ptr; ///< pointer to the message this information belongs to
double rcvdPower; ///< received power of the message
SnrList sList; ///< stores SNR over time
};
/**
* State: SnrInfo stores the snrList and the the recvdPower for the
* message currently being received, together with a pointer to the
* message.
*/
SnrStruct snrInfo;
/**
* Typedef used to store received messages together with
* receive power.
*/
typedef std::map<AirFrame*,double> RecvBuff;
/**
* State: A buffer to store a pointer to a message and the related
* receive power.
*/
RecvBuff recvBuff;
/** State: the current RadioState of the NIC; includes channel number */
RadioState rs;
/** State: the current PhyState of the NIC; */
PhyState ps;
/** State: if not -1, we have to switch to that channel once we finished transmitting */
int newChannel;
/** State: if not -1, we have to switch to that bitrate once we finished transmitting */
double newBitrate;
/** State: the current noise level of the channel.*/
double noiseLevel;
/**
* Configuration: The carrier frequency used. It is read from the ChannelControl module.
*/
double carrierFrequency;
/**
* Configuration: Thermal noise on the channel. Can be specified in
* omnetpp.ini. Default: -100 dBm
*/
double thermalNoise;
/**
* Configuration: Defines up to what Power level (in dBm) a message can be
* understood. If the level of a received packet is lower, it is
* only treated as noise. Can be specified in omnetpp.ini. Default:
* -85 dBm
*/
double sensitivity;
int numCollisions;
void box_muller(float m, float s, float & result);
double ranf() {return (double)rand()/(1.0+(double)RAND_MAX);}
// virtual void finish();
};
#endif