1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006,2007 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 YANS_WIFI_CHANNEL_H
22 #define YANS_WIFI_CHANNEL_H
23 
24 #include "ns3/channel.h"
25 
26 namespace ns3 {
27 
28 class NetDevice;
29 class PropagationLossModel;
30 class PropagationDelayModel;
31 class YansWifiPhy;
32 class Packet;
33 class Time;
34 class WifiPpdu;
35 
36 /**
37  * \brief a channel to interconnect ns3::YansWifiPhy objects.
38  * \ingroup wifi
39  *
40  * This class is expected to be used in tandem with the ns3::YansWifiPhy
41  * class and supports an ns3::PropagationLossModel and an
42  * ns3::PropagationDelayModel.  By default, no propagation models are set;
43  * it is the caller's responsibility to set them before using the channel.
44  */
45 class YansWifiChannel : public Channel
46 {
47 public:
48   /**
49    * \brief Get the type ID.
50    * \return the object TypeId
51    */
52   static TypeId GetTypeId (void);
53 
54   YansWifiChannel ();
55   virtual ~YansWifiChannel ();
56 
57   std::size_t GetNDevices (void) const override;
58   Ptr<NetDevice> GetDevice (std::size_t i) const override;
59 
60   /**
61    * Adds the given YansWifiPhy to the PHY list
62    *
63    * \param phy the YansWifiPhy to be added to the PHY list
64    */
65   void Add (Ptr<YansWifiPhy> phy);
66 
67   /**
68    * \param loss the new propagation loss model.
69    */
70   void SetPropagationLossModel (const Ptr<PropagationLossModel> loss);
71   /**
72    * \param delay the new propagation delay model.
73    */
74   void SetPropagationDelayModel (const Ptr<PropagationDelayModel> delay);
75 
76   /**
77    * \param sender the PHY object from which the packet is originating.
78    * \param ppdu the PPDU to send
79    * \param txPowerDbm the TX power associated to the packet, in dBm
80    *
81    * This method should not be invoked by normal users. It is
82    * currently invoked only from YansWifiPhy::StartTx.  The channel
83    * attempts to deliver the PPDU to all other YansWifiPhy objects
84    * on the channel (except for the sender).
85    */
86   void Send (Ptr<YansWifiPhy> sender, Ptr<const WifiPpdu> ppdu, double txPowerDbm) const;
87 
88   /**
89    * Assign a fixed random variable stream number to the random variables
90    * used by this model.  Return the number of streams (possibly zero) that
91    * have been assigned.
92    *
93    * \param stream first stream index to use
94    *
95    * \return the number of stream indices assigned by this model
96    */
97   int64_t AssignStreams (int64_t stream);
98 
99 
100 private:
101   /**
102    * A vector of pointers to YansWifiPhy.
103    */
104   typedef std::vector<Ptr<YansWifiPhy> > PhyList;
105 
106   /**
107    * This method is scheduled by Send for each associated YansWifiPhy.
108    * The method then calls the corresponding YansWifiPhy that the first
109    * bit of the PPDU has arrived.
110    *
111    * \param receiver the device to which the packet is destined
112    * \param ppdu the PPDU being sent
113    * \param txPowerDbm the TX power associated to the packet being sent (dBm)
114    */
115   static void Receive (Ptr<YansWifiPhy> receiver, Ptr<WifiPpdu> ppdu, double txPowerDbm);
116 
117   PhyList m_phyList;                   //!< List of YansWifiPhys connected to this YansWifiChannel
118   Ptr<PropagationLossModel> m_loss;    //!< Propagation loss model
119   Ptr<PropagationDelayModel> m_delay;  //!< Propagation delay model
120 };
121 
122 } //namespace ns3
123 
124 #endif /* YANS_WIFI_CHANNEL_H */
125