A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wifi-phy.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef WIFI_PHY_H
22 #define WIFI_PHY_H
23 
24 #include <stdint.h>
25 #include "ns3/callback.h"
26 #include "ns3/packet.h"
27 #include "ns3/object.h"
28 #include "ns3/nstime.h"
29 #include "ns3/ptr.h"
30 #include "wifi-mode.h"
31 #include "wifi-preamble.h"
32 #include "wifi-phy-standard.h"
33 #include "ns3/traced-callback.h"
34 
35 
36 namespace ns3 {
37 
38 class WifiChannel;
39 class NetDevice;
40 
45 {
46 public:
47  virtual ~WifiPhyListener ();
48 
61  virtual void NotifyRxStart (Time duration) = 0;
67  virtual void NotifyRxEndOk (void) = 0;
73  virtual void NotifyRxEndError (void) = 0;
83  virtual void NotifyTxStart (Time duration) = 0;
84 
100  virtual void NotifyMaybeCcaBusyStart (Time duration) = 0;
108  virtual void NotifySwitchingStart (Time duration) = 0;
109 };
110 
111 
117 class WifiPhy : public Object
118 {
119 public:
123  enum State
124  {
136  TX,
140  RX,
145  };
146 
159 
160  static TypeId GetTypeId (void);
161 
162  WifiPhy ();
163  virtual ~WifiPhy ();
164 
165  virtual double GetTxPowerStart (void) const = 0;
166  virtual double GetTxPowerEnd (void) const = 0;
170  virtual uint32_t GetNTxPower (void) const = 0;
171 
176  virtual void SetReceiveOkCallback (RxOkCallback callback) = 0;
181  virtual void SetReceiveErrorCallback (RxErrorCallback callback) = 0;
182 
190  virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel) = 0;
191 
198  virtual void RegisterListener (WifiPhyListener *listener) = 0;
199 
203  virtual bool IsStateIdle (void) = 0;
207  virtual bool IsStateCcaBusy (void) = 0;
211  virtual bool IsStateBusy (void) = 0;
215  virtual bool IsStateRx (void) = 0;
219  virtual bool IsStateTx (void) = 0;
223  virtual bool IsStateSwitching (void) = 0;
227  virtual Time GetStateDuration (void) = 0;
234  virtual Time GetDelayUntilIdle (void) = 0;
235 
236  virtual Time GetLastRxStartTime (void) const = 0;
237 
245  static Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble);
246 
253  static WifiMode GetPlcpHeaderMode (WifiMode payloadMode, WifiPreamble preamble);
254 
261  static uint32_t GetPlcpHeaderDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble);
262 
269  static uint32_t GetPlcpPreambleDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble);
270 
277  static uint32_t GetPayloadDurationMicroSeconds (uint32_t size, WifiMode payloadMode);
278 
296  virtual uint32_t GetNModes (void) const = 0;
315  virtual WifiMode GetMode (uint32_t mode) const = 0;
322  virtual double CalculateSnr (WifiMode txMode, double ber) const = 0;
323 
332  virtual void SetChannelNumber (uint16_t id) = 0;
334  virtual uint16_t GetChannelNumber () const = 0;
335 
336  virtual void ConfigureStandard (enum WifiPhyStandard standard) = 0;
337 
338  virtual Ptr<WifiChannel> GetChannel (void) const = 0;
339 
340  static WifiMode GetDsssRate1Mbps ();
341  static WifiMode GetDsssRate2Mbps ();
342  static WifiMode GetDsssRate5_5Mbps ();
343  static WifiMode GetDsssRate11Mbps ();
344  static WifiMode GetErpOfdmRate6Mbps ();
345  static WifiMode GetErpOfdmRate9Mbps ();
346  static WifiMode GetErpOfdmRate12Mbps ();
347  static WifiMode GetErpOfdmRate18Mbps ();
348  static WifiMode GetErpOfdmRate24Mbps ();
349  static WifiMode GetErpOfdmRate36Mbps ();
350  static WifiMode GetErpOfdmRate48Mbps ();
351  static WifiMode GetErpOfdmRate54Mbps ();
352  static WifiMode GetOfdmRate6Mbps ();
353  static WifiMode GetOfdmRate9Mbps ();
354  static WifiMode GetOfdmRate12Mbps ();
355  static WifiMode GetOfdmRate18Mbps ();
356  static WifiMode GetOfdmRate24Mbps ();
357  static WifiMode GetOfdmRate36Mbps ();
358  static WifiMode GetOfdmRate48Mbps ();
359  static WifiMode GetOfdmRate54Mbps ();
376 
377 
382  void NotifyTxBegin (Ptr<const Packet> packet);
383 
388  void NotifyTxEnd (Ptr<const Packet> packet);
389 
394  void NotifyTxDrop (Ptr<const Packet> packet);
395 
400  void NotifyRxBegin (Ptr<const Packet> packet);
401 
406  void NotifyRxEnd (Ptr<const Packet> packet);
407 
412  void NotifyRxDrop (Ptr<const Packet> packet);
413 
434  void NotifyMonitorSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble,
435  double signalDbm, double noiseDbm);
436 
450  void NotifyMonitorSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble);
451 
460  virtual int64_t AssignStreams (int64_t stream) = 0;
461 
462 
463 private:
471 
479 
487 
495 
503 
510 
521  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t, bool, double, double> m_phyMonitorSniffRxTrace;
522 
533  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t, bool> m_phyMonitorSniffTxTrace;
534 
535 };
536 
541 std::ostream& operator<< (std::ostream& os, enum WifiPhy::State state);
542 
543 } // namespace ns3
544 
545 #endif /* WIFI_PHY_H */