A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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_duplex = false;
94  m_txFrequency = 0;
95  m_rxFrequency = 0;
96 }
97 
99 {
100 }
101 
102 void
104 {
105  m_device = nullptr;
106  m_channel = nullptr;
107 }
108 
109 void
111 {
112  m_channel = channel;
113  DoAttach(channel);
114 }
115 
118 {
119  return m_channel;
120 }
121 
122 void
124 {
125  m_device = device;
126 }
127 
130 {
131  return m_device;
132 }
133 
134 void
136 {
139  "Error while scanning: The PHY state should be PHY_STATE_SCANNING or PHY_STATE_IDLE");
140 
142  m_scanningFrequency = frequency;
144  m_scanningCallback = callback;
145 }
146 
147 void
149 {
151 }
152 
153 void
155 {
156  m_rxCallback = callback;
157 }
158 
161 {
162  return m_rxCallback;
163 }
164 
165 void
166 WimaxPhy::SetDuplex(uint64_t rxFrequency, uint64_t txFrequency)
167 {
168  m_txFrequency = txFrequency;
169  m_rxFrequency = rxFrequency;
170 }
171 
172 void
173 WimaxPhy::SetSimplex(uint64_t frequency)
174 {
175  m_txFrequency = frequency;
176  m_rxFrequency = frequency;
177 }
178 
179 uint64_t
181 {
182  return m_rxFrequency;
183 }
184 
185 uint64_t
187 {
188  return m_txFrequency;
189 }
190 
191 uint64_t
193 {
194  return m_scanningFrequency;
195 }
196 
197 void
199 {
200  m_state = state;
201 }
202 
205 {
206  return m_state;
207 }
208 
209 bool
211 {
212  return m_duplex;
213 }
214 
215 EventId
217 {
219 }
220 
221 void
223 {
225 }
226 
227 void
229 {
230  DoSetDataRates();
231 }
232 
233 uint32_t
235 {
236  return DoGetDataRate(modulationType);
237 }
238 
239 Time
240 WimaxPhy::GetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
241 {
242  return DoGetTransmissionTime(size, modulationType);
243 }
244 
245 uint64_t
246 WimaxPhy::GetNrSymbols(uint32_t size, WimaxPhy::ModulationType modulationType) const
247 {
248  return DoGetNrSymbols(size, modulationType);
249 }
250 
251 uint64_t
252 WimaxPhy::GetNrBytes(uint32_t symbols, WimaxPhy::ModulationType modulationType) const
253 {
254  return DoGetNrBytes(symbols, modulationType);
255 }
256 
257 uint16_t
259 {
260  return DoGetTtg();
261 }
262 
263 uint16_t
265 {
266  return DoGetRtg();
267 }
268 
269 uint8_t
271 {
272  return DoGetFrameDurationCode();
273 }
274 
275 Time
276 WimaxPhy::GetFrameDuration(uint8_t frameDurationCode) const
277 {
278  return DoGetFrameDuration(frameDurationCode);
279 }
280 
281 /*---------------------PHY parameters functions-----------------------*/
282 
283 void
285 {
287 }
288 
289 void
290 WimaxPhy::SetNrCarriers(uint8_t nrCarriers)
291 {
292  m_nrCarriers = nrCarriers;
293 }
294 
295 uint8_t
297 {
298  return m_nrCarriers;
299 }
300 
301 void
303 {
304  m_frameDuration = frameDuration;
305 }
306 
307 Time
309 {
310  return GetFrameDurationSec();
311 }
312 
313 Time
315 {
316  return m_frameDuration;
317 }
318 
319 void
320 WimaxPhy::SetFrequency(uint32_t frequency)
321 {
322  m_frequency = frequency;
323 }
324 
325 uint32_t
327 {
328  return m_frequency;
329 }
330 
331 void
332 WimaxPhy::SetChannelBandwidth(uint32_t channelBandwidth)
333 {
334  m_channelBandwidth = channelBandwidth;
335 }
336 
337 uint32_t
339 {
340  return m_channelBandwidth;
341 }
342 
343 uint16_t
345 {
346  return DoGetNfft();
347 }
348 
349 double
351 {
352  return DoGetSamplingFactor();
353 }
354 
355 double
357 {
358  return DoGetSamplingFrequency();
359 }
360 
361 void
363 {
364  m_psDuration = psDuration;
365 }
366 
367 Time
369 {
370  return m_psDuration;
371 }
372 
373 void
375 {
376  m_symbolDuration = symbolDuration;
377 }
378 
379 Time
381 {
382  return m_symbolDuration;
383 }
384 
385 double
387 {
388  return DoGetGValue();
389 }
390 
391 void
392 WimaxPhy::SetPsPerSymbol(uint16_t psPerSymbol)
393 {
394  m_psPerSymbol = psPerSymbol;
395 }
396 
397 uint16_t
399 {
400  return m_psPerSymbol;
401 }
402 
403 void
404 WimaxPhy::SetPsPerFrame(uint16_t psPerFrame)
405 {
406  m_psPerFrame = psPerFrame;
407 }
408 
409 uint16_t
411 {
412  return m_psPerFrame;
413 }
414 
415 void
416 WimaxPhy::SetSymbolsPerFrame(uint32_t symbolsPerFrame)
417 {
418  m_symbolsPerFrame = symbolsPerFrame;
419 }
420 
421 uint32_t
423 {
424  return m_symbolsPerFrame;
425 }
426 
427 } // 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:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
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:240
Time GetFrameDuration() const
Get the frame duration.
Definition: wimax-phy.cc:308
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
virtual double DoGetGValue() const =0
Get G value.
bool m_duplex
duplex
Definition: wimax-phy.h:472
void SetSymbolDuration(Time symbolDuration)
set the OFDM symbol duration
Definition: wimax-phy.cc:374
Ptr< WimaxChannel > GetChannel() const
Definition: wimax-phy.cc:117
uint32_t GetSymbolsPerFrame() const
Get the number of symbols per frame.
Definition: wimax-phy.cc:422
void SetChannelBandwidth(uint32_t channelBandwidth)
Set the channel bandwidth.
Definition: wimax-phy.cc:332
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:252
virtual uint8_t DoGetFrameDurationCode() const =0
Get frame duration code.
uint64_t m_txFrequency
transmit frequency
Definition: wimax-phy.h:468
~WimaxPhy() override
Definition: wimax-phy.cc:98
void SetDuplex(uint64_t rxFrequency, uint64_t txFrequency)
configure the physical layer in duplex mode
Definition: wimax-phy.cc:166
EventId m_dlChnlSrchTimeoutEvent
DL channel search timeout event.
Definition: wimax-phy.h:471
uint64_t GetRxFrequency() const
Get the reception frequency.
Definition: wimax-phy.cc:180
Time GetFrameDurationSec() const
Get the frame duration This method is redundant with GetFrameDuration ()
Definition: wimax-phy.cc:314
void SetDataRates()
calculates the data rate of each modulation and save them for future use
Definition: wimax-phy.cc:228
uint16_t GetPsPerFrame() const
Get the number of physical slots per frame.
Definition: wimax-phy.cc:410
Time GetSymbolDuration() const
Get the OFDM symbol duration.
Definition: wimax-phy.cc:380
uint8_t GetNrCarriers() const
Get the number of carriers in the physical frame.
Definition: wimax-phy.cc:296
uint32_t m_channelBandwidth
in Hz
Definition: wimax-phy.h:481
Time m_psDuration
in seconds
Definition: wimax-phy.h:482
PhyState GetState() const
Get the state of the device.
Definition: wimax-phy.cc:204
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:110
uint16_t m_psPerFrame
ps per framce
Definition: wimax-phy.h:485
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:320
uint32_t m_symbolsPerFrame
symbols per frame
Definition: wimax-phy.h:486
uint8_t GetFrameDurationCode() const
Get the frame duration code.
Definition: wimax-phy.cc:270
void SetDevice(Ptr< WimaxNetDevice > device)
Set the device in which this physical layer is installed.
Definition: wimax-phy.cc:123
uint64_t m_rxFrequency
receive frequency
Definition: wimax-phy.h:469
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:135
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:416
Ptr< WimaxNetDevice > m_device
the device
Definition: wimax-phy.h:465
void SetScanningCallback() const
calls the scanning call back function
Definition: wimax-phy.cc:222
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:356
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:290
Ptr< WimaxChannel > m_channel
channel
Definition: wimax-phy.h:466
Time GetPsDuration() const
Get the physical slot duration.
Definition: wimax-phy.cc:368
static TypeId GetTypeId()
Get the type ID.
Definition: wimax-phy.cc:42
uint64_t m_scanningFrequency
scanning frequency
Definition: wimax-phy.h:470
void DoDispose() override
Destructor implementation.
Definition: wimax-phy.cc:103
uint32_t GetFrequency() const
Get the frequency on which the device is locked.
Definition: wimax-phy.cc:326
double GetGValue() const
Get the guard interval factor (the ratio TG/Td)
Definition: wimax-phy.cc:386
Ptr< NetDevice > GetDevice() const
Definition: wimax-phy.cc:129
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slots per frame
Definition: wimax-phy.cc:404
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:234
virtual Time DoGetTransmissionTime(uint32_t size, ModulationType modulationType) const =0
Get transmission time.
uint32_t m_frequency
in KHz
Definition: wimax-phy.h:480
virtual Time DoGetFrameDuration(uint8_t frameDurationCode) const =0
Get frame duration.
uint8_t m_nrCarriers
number of carriers
Definition: wimax-phy.h:478
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
Definition: wimax-phy.cc:173
Callback< void, Ptr< const PacketBurst > > m_rxCallback
receive callback function
Definition: wimax-phy.h:475
void SetFrameDuration(Time frameDuration)
Set the frame duration.
Definition: wimax-phy.cc:302
uint64_t GetScanningFrequency() const
Get the scanning frequency.
Definition: wimax-phy.cc:192
Time m_symbolDuration
in seconds
Definition: wimax-phy.h:483
void SetPsDuration(Time psDuration)
set the physical slot duration
Definition: wimax-phy.cc:362
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:246
void EndScanning()
End scanning.
Definition: wimax-phy.cc:148
uint16_t GetPsPerSymbol() const
Get the number of physical slots per symbol.
Definition: wimax-phy.cc:398
void SetState(PhyState state)
set the state of the device
Definition: wimax-phy.cc:198
Callback< void, bool, uint64_t > m_scanningCallback
scanning callback function
Definition: wimax-phy.h:476
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:338
uint16_t m_psPerSymbol
ps per sumbol
Definition: wimax-phy.h:484
EventId GetChnlSrchTimeoutEvent() const
Get channel search timeout event.
Definition: wimax-phy.cc:216
double GetSamplingFactor() const
Get the sampling factor.
Definition: wimax-phy.cc:350
void SetPhyParameters()
computes the Physical parameters and store them
Definition: wimax-phy.cc:284
Time m_frameDuration
in seconds
Definition: wimax-phy.h:479
bool IsDuplex() const
Check if configured in duplex mode.
Definition: wimax-phy.cc:210
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback() const
Definition: wimax-phy.cc:160
void SetPsPerSymbol(uint16_t psPerSymbol)
set the number of physical slots per symbol
Definition: wimax-phy.cc:392
PhyState m_state
state
Definition: wimax-phy.h:473
uint64_t GetTxFrequency() const
Get the transmission frequency.
Definition: wimax-phy.cc:186
uint16_t GetRtg() const
Get the receive/transmit transition gap.
Definition: wimax-phy.cc:264
uint16_t GetTtg() const
Get the transmit/receive transition gap.
Definition: wimax-phy.cc:258
void SetReceiveCallback(Callback< void, Ptr< const PacketBurst >> callback)
set the callback function to call when a burst is received
Definition: wimax-phy.cc:154
uint16_t GetNfft() const
Get the size of the FFT.
Definition: wimax-phy.cc:344
#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
#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:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
channel
Definition: third.py:88
ns3::Time timeout