A Discrete-Event Network Simulator
API
wimax-phy.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18  */
19 
20 #include "wimax-phy.h"
21 
22 #include "wimax-channel.h"
23 #include "wimax-net-device.h"
24 
25 #include "ns3/double.h"
26 #include "ns3/node.h"
27 #include "ns3/packet-burst.h"
28 #include "ns3/packet.h"
29 #include "ns3/pointer.h"
30 #include "ns3/simulator.h"
31 #include "ns3/trace-source-accessor.h"
32 #include "ns3/uinteger.h"
33 
34 namespace ns3
35 {
36 
37 NS_LOG_COMPONENT_DEFINE("WimaxPhy");
38 
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::WimaxPhy")
46  .SetParent<Object>()
47  .SetGroupName("Wimax")
48 
49  // No AddConstructor because this is an abstract class.
50 
51  .AddAttribute("Channel",
52  "Wimax channel",
53  PointerValue(),
55  MakePointerChecker<WimaxChannel>())
56 
57  .AddAttribute(
58  "FrameDuration",
59  "The frame duration in seconds.",
60  TimeValue(Seconds(0.01)),
63 
64  .AddAttribute("Frequency",
65  "The central frequency in KHz.",
66  UintegerValue(5000000),
68  MakeUintegerChecker<uint32_t>(1000000, 11000000))
69 
70  .AddAttribute("Bandwidth",
71  "The channel bandwidth in Hz.",
72  UintegerValue(10000000),
75  MakeUintegerChecker<uint32_t>(5000000, 30000000))
76 
77  ;
78  return tid;
79 }
80 
82  : m_state(PHY_STATE_IDLE),
83  m_nrCarriers(0),
84  m_frameDuration(Seconds(0.01)),
85  m_frequency(5000000),
86  m_channelBandwidth(10000000),
87  m_psDuration(Seconds(0)),
88  m_symbolDuration(Seconds(0)),
89  m_psPerSymbol(0),
90  m_psPerFrame(0),
91  m_symbolsPerFrame(0)
92 {
93  m_mobility = nullptr;
94  m_duplex = 0;
95  m_txFrequency = 0;
96  m_rxFrequency = 0;
97 }
98 
100 {
101 }
102 
103 void
105 {
106  m_device = nullptr;
107  m_channel = nullptr;
108 }
109 
110 void
112 {
113  m_channel = channel;
114  DoAttach(channel);
115 }
116 
119 {
120  return m_channel;
121 }
122 
123 void
125 {
126  m_device = device;
127 }
128 
131 {
132  return m_device;
133 }
134 
135 void
137 {
140  "Error while scanning: The PHY state should be PHY_STATE_SCANNING or PHY_STATE_IDLE");
141 
143  m_scanningFrequency = frequency;
145  m_scanningCallback = callback;
146 }
147 
148 void
150 {
152 }
153 
154 void
156 {
157  m_rxCallback = callback;
158 }
159 
162 {
163  return m_rxCallback;
164 }
165 
166 void
167 WimaxPhy::SetDuplex(uint64_t rxFrequency, uint64_t txFrequency)
168 {
169  m_txFrequency = txFrequency;
170  m_rxFrequency = rxFrequency;
171 }
172 
173 void
174 WimaxPhy::SetSimplex(uint64_t frequency)
175 {
176  m_txFrequency = frequency;
177  m_rxFrequency = frequency;
178 }
179 
180 uint64_t
182 {
183  return m_rxFrequency;
184 }
185 
186 uint64_t
188 {
189  return m_txFrequency;
190 }
191 
192 uint64_t
194 {
195  return m_scanningFrequency;
196 }
197 
198 void
200 {
201  m_state = state;
202 }
203 
206 {
207  return m_state;
208 }
209 
210 bool
212 {
213  return m_duplex;
214 }
215 
216 EventId
218 {
220 }
221 
222 void
224 {
226 }
227 
228 void
230 {
231  DoSetDataRates();
232 }
233 
234 uint32_t
236 {
237  return DoGetDataRate(modulationType);
238 }
239 
240 Time
241 WimaxPhy::GetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
242 {
243  return DoGetTransmissionTime(size, modulationType);
244 }
245 
246 uint64_t
247 WimaxPhy::GetNrSymbols(uint32_t size, WimaxPhy::ModulationType modulationType) const
248 {
249  return DoGetNrSymbols(size, modulationType);
250 }
251 
252 uint64_t
253 WimaxPhy::GetNrBytes(uint32_t symbols, WimaxPhy::ModulationType modulationType) const
254 {
255  return DoGetNrBytes(symbols, modulationType);
256 }
257 
258 uint16_t
260 {
261  return DoGetTtg();
262 }
263 
264 uint16_t
266 {
267  return DoGetRtg();
268 }
269 
270 uint8_t
272 {
273  return DoGetFrameDurationCode();
274 }
275 
276 Time
277 WimaxPhy::GetFrameDuration(uint8_t frameDurationCode) const
278 {
279  return DoGetFrameDuration(frameDurationCode);
280 }
281 
282 /*---------------------PHY parameters functions-----------------------*/
283 
284 void
286 {
288 }
289 
290 void
291 WimaxPhy::SetNrCarriers(uint8_t nrCarriers)
292 {
293  m_nrCarriers = nrCarriers;
294 }
295 
296 uint8_t
298 {
299  return m_nrCarriers;
300 }
301 
302 void
304 {
305  m_frameDuration = frameDuration;
306 }
307 
308 Time
310 {
311  return GetFrameDurationSec();
312 }
313 
314 Time
316 {
317  return m_frameDuration;
318 }
319 
320 void
321 WimaxPhy::SetFrequency(uint32_t frequency)
322 {
323  m_frequency = frequency;
324 }
325 
326 uint32_t
328 {
329  return m_frequency;
330 }
331 
332 void
333 WimaxPhy::SetChannelBandwidth(uint32_t channelBandwidth)
334 {
335  m_channelBandwidth = channelBandwidth;
336 }
337 
338 uint32_t
340 {
341  return m_channelBandwidth;
342 }
343 
344 uint16_t
346 {
347  return DoGetNfft();
348 }
349 
350 double
352 {
353  return DoGetSamplingFactor();
354 }
355 
356 double
358 {
359  return DoGetSamplingFrequency();
360 }
361 
362 void
364 {
365  m_psDuration = psDuration;
366 }
367 
368 Time
370 {
371  return m_psDuration;
372 }
373 
374 void
376 {
377  m_symbolDuration = symbolDuration;
378 }
379 
380 Time
382 {
383  return m_symbolDuration;
384 }
385 
386 double
388 {
389  return DoGetGValue();
390 }
391 
392 void
393 WimaxPhy::SetPsPerSymbol(uint16_t psPerSymbol)
394 {
395  m_psPerSymbol = psPerSymbol;
396 }
397 
398 uint16_t
400 {
401  return m_psPerSymbol;
402 }
403 
404 void
405 WimaxPhy::SetPsPerFrame(uint16_t psPerFrame)
406 {
407  m_psPerFrame = psPerFrame;
408 }
409 
410 uint16_t
412 {
413  return m_psPerFrame;
414 }
415 
416 void
417 WimaxPhy::SetSymbolsPerFrame(uint32_t symbolsPerFrame)
418 {
419  m_symbolsPerFrame = symbolsPerFrame;
420 }
421 
422 uint32_t
424 {
425  return m_symbolsPerFrame;
426 }
427 
430 {
431  return m_mobility;
432 }
433 
434 void
436 {
438 }
439 
440 } // namespace ns3
An identifier for simulation events.
Definition: event-id.h:55
A base class which provides memory management and object aggregation.
Definition: object.h:89
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1423
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
Time GetTransmissionTime(uint32_t size, ModulationType modulationType) const
Get transmission time needed to send bytes at a given modulation.
Definition: wimax-phy.cc:241
Time GetFrameDuration() const
Get the frame duration.
Definition: wimax-phy.cc:309
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
virtual double DoGetGValue() const =0
Get G value.
bool m_duplex
duplex
Definition: wimax-phy.h:482
void SetSymbolDuration(Time symbolDuration)
set the OFDM symbol duration
Definition: wimax-phy.cc:375
virtual void SetMobility(Ptr< Object > mobility)
set the mobility model of the device
Definition: wimax-phy.cc:435
Ptr< WimaxChannel > GetChannel() const
Definition: wimax-phy.cc:118
uint32_t GetSymbolsPerFrame() const
Get the number of symbols per frame.
Definition: wimax-phy.cc:423
void SetChannelBandwidth(uint32_t channelBandwidth)
Set the channel bandwidth.
Definition: wimax-phy.cc:333
uint64_t GetNrBytes(uint32_t symbols, ModulationType modulationType) const
Get the maximum number of bytes that could be carried by symbols symbols using the modulation modulat...
Definition: wimax-phy.cc:253
virtual uint8_t DoGetFrameDurationCode() const =0
Get frame duration code.
uint64_t m_txFrequency
transmit frequency
Definition: wimax-phy.h:478
~WimaxPhy() override
Definition: wimax-phy.cc:99
void SetDuplex(uint64_t rxFrequency, uint64_t txFrequency)
configure the physical layer in duplex mode
Definition: wimax-phy.cc:167
EventId m_dlChnlSrchTimeoutEvent
DL channel search timeout event.
Definition: wimax-phy.h:481
uint64_t GetRxFrequency() const
Get the reception frequency.
Definition: wimax-phy.cc:181
Time GetFrameDurationSec() const
Get the frame duration This method is redundant with GetFrameDuration ()
Definition: wimax-phy.cc:315
void SetDataRates()
calculates the data rate of each modulation and save them for future use
Definition: wimax-phy.cc:229
uint16_t GetPsPerFrame() const
Get the number of physical slots per frame.
Definition: wimax-phy.cc:411
Ptr< Object > m_mobility
modility model
Definition: wimax-phy.h:497
Time GetSymbolDuration() const
Get the OFDM symbol duration.
Definition: wimax-phy.cc:381
uint8_t GetNrCarriers() const
Get the number of carriers in the physical frame.
Definition: wimax-phy.cc:297
uint32_t m_channelBandwidth
in Hz
Definition: wimax-phy.h:491
Time m_psDuration
in seconds
Definition: wimax-phy.h:492
PhyState GetState() const
Get the state of the device.
Definition: wimax-phy.cc:205
virtual void DoSetPhyParameters()=0
Set phy parameters.
virtual uint16_t DoGetTtg() const =0
Get TTG.
void Attach(Ptr< WimaxChannel > channel)
Attach the physical layer to a channel.
Definition: wimax-phy.cc:111
uint16_t m_psPerFrame
ps per framce
Definition: wimax-phy.h:495
virtual uint16_t DoGetNfft() const =0
Get NFFT.
void SetFrequency(uint32_t frequency)
set the frequency on which the device should lock
Definition: wimax-phy.cc:321
uint32_t m_symbolsPerFrame
symbols per frame
Definition: wimax-phy.h:496
uint8_t GetFrameDurationCode() const
Get the frame duration code.
Definition: wimax-phy.cc:271
void SetDevice(Ptr< WimaxNetDevice > device)
Set the device in which this physical layer is installed.
Definition: wimax-phy.cc:124
virtual Ptr< Object > GetMobility()
Get the mobility model of the device.
Definition: wimax-phy.cc:429
uint64_t m_rxFrequency
receive frequency
Definition: wimax-phy.h:479
void StartScanning(uint64_t frequency, Time timeout, Callback< void, bool, uint64_t > callback)
scan a frequency for maximum timeout seconds and call the callback if the frequency can be used
Definition: wimax-phy.cc:136
virtual void DoSetDataRates()=0
Set data rates.
virtual void DoAttach(Ptr< WimaxChannel > channel)=0
Attach channel.
void SetSymbolsPerFrame(uint32_t symbolsPerFrame)
set the number of symbols per frame
Definition: wimax-phy.cc:417
Ptr< WimaxNetDevice > m_device
the device
Definition: wimax-phy.h:475
void SetScanningCallback() const
calls the scanning call back function
Definition: wimax-phy.cc:223
virtual uint64_t DoGetNrSymbols(uint32_t size, ModulationType modulationType) const =0
Get number of symbols.
double GetSamplingFrequency() const
Get the sampling frequency.
Definition: wimax-phy.cc:357
virtual double DoGetSamplingFactor() const =0
Get sampling factor.
virtual uint64_t DoGetNrBytes(uint32_t symbols, ModulationType modulationType) const =0
Get number of bytes.
void SetNrCarriers(uint8_t nrCarriers)
Set the number of carriers in the physical frame.
Definition: wimax-phy.cc:291
Ptr< WimaxChannel > m_channel
channel
Definition: wimax-phy.h:476
Time GetPsDuration() const
Get the physical slot duration.
Definition: wimax-phy.cc:369
static TypeId GetTypeId()
Get the type ID.
Definition: wimax-phy.cc:42
uint64_t m_scanningFrequency
scanning frequency
Definition: wimax-phy.h:480
void DoDispose() override
Destructor implementation.
Definition: wimax-phy.cc:104
uint32_t GetFrequency() const
Get the frequency on which the device is locked.
Definition: wimax-phy.cc:327
double GetGValue() const
Get the guard interval factor (the ratio TG/Td)
Definition: wimax-phy.cc:387
Ptr< NetDevice > GetDevice() const
Definition: wimax-phy.cc:130
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slots per frame
Definition: wimax-phy.cc:405
PhyState
PhyState enumeration.
Definition: wimax-phy.h:66
@ PHY_STATE_SCANNING
Definition: wimax-phy.h:68
uint32_t GetDataRate(ModulationType modulationType) const
Get the data rate corresponding to a modulation type.
Definition: wimax-phy.cc:235
virtual Time DoGetTransmissionTime(uint32_t size, ModulationType modulationType) const =0
Get transmission time.
uint32_t m_frequency
in KHz
Definition: wimax-phy.h:490
virtual Time DoGetFrameDuration(uint8_t frameDurationCode) const =0
Get frame duration.
uint8_t m_nrCarriers
number of carriers
Definition: wimax-phy.h:488
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
Definition: wimax-phy.cc:174
Callback< void, Ptr< const PacketBurst > > m_rxCallback
receive callback function
Definition: wimax-phy.h:485
void SetFrameDuration(Time frameDuration)
Set the frame duration.
Definition: wimax-phy.cc:303
uint64_t GetScanningFrequency() const
Get the scanning frequency.
Definition: wimax-phy.cc:193
Time m_symbolDuration
in seconds
Definition: wimax-phy.h:493
void SetPsDuration(Time psDuration)
set the physical slot duration
Definition: wimax-phy.cc:363
uint64_t GetNrSymbols(uint32_t size, ModulationType modulationType) const
Get the number of symbols needed to transmit size bytes using the modulation modulationType.
Definition: wimax-phy.cc:247
void EndScanning()
End scanning.
Definition: wimax-phy.cc:149
uint16_t GetPsPerSymbol() const
Get the number of physical slots per symbol.
Definition: wimax-phy.cc:399
void SetState(PhyState state)
set the state of the device
Definition: wimax-phy.cc:199
Callback< void, bool, uint64_t > m_scanningCallback
scanning callback function
Definition: wimax-phy.h:486
virtual uint16_t DoGetRtg() const =0
Get RTG.
virtual double DoGetSamplingFrequency() const =0
Get sampling frequency.
virtual uint32_t DoGetDataRate(ModulationType modulationType) const =0
Get data rate.
uint32_t GetChannelBandwidth() const
Get the channel bandwidth.
Definition: wimax-phy.cc:339
uint16_t m_psPerSymbol
ps per sumbol
Definition: wimax-phy.h:494
EventId GetChnlSrchTimeoutEvent() const
Get channel search timeout event.
Definition: wimax-phy.cc:217
double GetSamplingFactor() const
Get the sampling factor.
Definition: wimax-phy.cc:351
void SetPhyParameters()
computes the Physical parameters and store them
Definition: wimax-phy.cc:285
Time m_frameDuration
in seconds
Definition: wimax-phy.h:489
bool IsDuplex() const
Check if configured in duplex mode.
Definition: wimax-phy.cc:211
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback() const
Definition: wimax-phy.cc:161
void SetPsPerSymbol(uint16_t psPerSymbol)
set the number of physical slots per symbol
Definition: wimax-phy.cc:393
PhyState m_state
state
Definition: wimax-phy.h:483
uint64_t GetTxFrequency() const
Get the transmission frequency.
Definition: wimax-phy.cc:187
uint16_t GetRtg() const
Get the receive/transmit transition gap.
Definition: wimax-phy.cc:265
uint16_t GetTtg() const
Get the transmit/receive transition gap.
Definition: wimax-phy.cc:259
void SetReceiveCallback(Callback< void, Ptr< const PacketBurst >> callback)
set the callback function to call when a burst is received
Definition: wimax-phy.cc:155
uint16_t GetNfft() const
Get the size of the FFT.
Definition: wimax-phy.cc:345
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:231
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1424
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:535
channel
Definition: third.py:81
mobility
Definition: third.py:96
ns3::Time timeout