1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2008 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_MAC_H 22 #define WIFI_MAC_H 23 24 #include "ns3/net-device.h" 25 #include "wifi-standards.h" 26 #include "wifi-remote-station-manager.h" 27 #include "qos-utils.h" 28 29 namespace ns3 { 30 31 class Ssid; 32 class Txop; 33 class HtConfiguration; 34 class VhtConfiguration; 35 class HeConfiguration; 36 37 /** 38 * Enumeration for type of station 39 */ 40 enum TypeOfStation 41 { 42 STA, 43 AP, 44 ADHOC_STA, 45 MESH, 46 OCB 47 }; 48 49 /** 50 * \ingroup wifi 51 * \enum WifiMacDropReason 52 * \brief The reason why an MPDU was dropped 53 */ 54 enum WifiMacDropReason : uint8_t 55 { 56 WIFI_MAC_DROP_FAILED_ENQUEUE = 0, 57 WIFI_MAC_DROP_EXPIRED_LIFETIME, 58 WIFI_MAC_DROP_REACHED_RETRY_LIMIT, 59 WIFI_MAC_DROP_QOS_OLD_PACKET 60 }; 61 62 /** 63 * \brief base class for all MAC-level wifi objects. 64 * \ingroup wifi 65 * 66 * This class encapsulates all the low-level MAC functionality 67 * DCA, EDCA, etc) and all the high-level MAC functionality 68 * (association/disassociation state machines). 69 * 70 */ 71 class WifiMac : public Object 72 { 73 public: 74 virtual void DoDispose (); 75 76 /** 77 * \brief Get the type ID. 78 * \return the object TypeId 79 */ 80 static TypeId GetTypeId (void); 81 82 /** 83 * Sets the device this PHY is associated with. 84 * 85 * \param device the device this PHY is associated with 86 */ 87 void SetDevice (const Ptr<NetDevice> device); 88 /** 89 * Return the device this PHY is associated with 90 * 91 * \return the device this PHY is associated with 92 */ 93 Ptr<NetDevice> GetDevice (void) const; 94 95 /** 96 * This method is invoked by a subclass to specify what type of 97 * station it is implementing. This is something that the channel 98 * access functions need to know. 99 * 100 * \param type the type of station. 101 */ 102 virtual void SetTypeOfStation (TypeOfStation type) = 0; 103 /** 104 * Return the type of station. 105 * 106 * \return the type of station. 107 */ 108 virtual TypeOfStation GetTypeOfStation (void) const = 0; 109 110 /** 111 * \param ssid the current SSID of this MAC layer. 112 */ 113 virtual void SetSsid (Ssid ssid) = 0; 114 /** 115 * Enable or disable short slot time feature. 116 * 117 * \param enable true if short slot time is to be supported, 118 * false otherwise 119 */ 120 virtual void SetShortSlotTimeSupported (bool enable) = 0; 121 /** 122 * \brief Sets the interface in promiscuous mode. 123 * 124 * Enables promiscuous mode on the interface. Note that any further 125 * filtering on the incoming frame path may affect the overall 126 * behavior. 127 */ 128 virtual void SetPromisc (void) = 0; 129 130 /** 131 * \return the MAC address associated to this MAC layer. 132 */ 133 virtual Mac48Address GetAddress (void) const = 0; 134 /** 135 * \return the SSID which this MAC layer is going to try to stay in. 136 */ 137 virtual Ssid GetSsid (void) const = 0; 138 /** 139 * \param address the current address of this MAC layer. 140 */ 141 virtual void SetAddress (Mac48Address address) = 0; 142 /** 143 * \return the BSSID of the network this device belongs to. 144 */ 145 virtual Mac48Address GetBssid (void) const = 0; 146 /** 147 * \return whether the device supports short slot time capability. 148 */ 149 virtual bool GetShortSlotTimeSupported (void) const = 0; 150 151 /** 152 * \param packet the packet to send. 153 * \param to the address to which the packet should be sent. 154 * \param from the address from which the packet should be sent. 155 * 156 * The packet should be enqueued in a TX queue, and should be 157 * dequeued as soon as the DCF function determines that 158 * access it granted to this MAC. The extra parameter "from" allows 159 * this device to operate in a bridged mode, forwarding received 160 * frames without altering the source address. 161 */ 162 virtual void Enqueue (Ptr<Packet> packet, Mac48Address to, Mac48Address from) = 0; 163 /** 164 * \param packet the packet to send. 165 * \param to the address to which the packet should be sent. 166 * 167 * The packet should be enqueued in a TX queue, and should be 168 * dequeued as soon as the DCF function determines that 169 * access it granted to this MAC. 170 */ 171 virtual void Enqueue (Ptr<Packet> packet, Mac48Address to) = 0; 172 /** 173 * \return if this MAC supports sending from arbitrary address. 174 * 175 * The interface may or may not support sending from arbitrary address. 176 * This function returns true if sending from arbitrary address is supported, 177 * false otherwise. 178 */ 179 virtual bool SupportsSendFrom (void) const = 0; 180 /** 181 * \param phy the physical layer attached to this MAC. 182 */ 183 virtual void SetWifiPhy (Ptr<WifiPhy> phy) = 0; 184 /** 185 * \return the physical layer attached to this MAC 186 */ 187 virtual Ptr<WifiPhy> GetWifiPhy (void) const = 0; 188 /** 189 * Remove currently attached WifiPhy device from this MAC. 190 */ 191 virtual void ResetWifiPhy (void) = 0; 192 /** 193 * \param stationManager the station manager attached to this MAC. 194 */ 195 virtual void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) = 0; 196 /** 197 * \return the station manager attached to this MAC. 198 */ 199 virtual Ptr<WifiRemoteStationManager> GetWifiRemoteStationManager (void) const = 0; 200 201 /** 202 * This type defines the callback of a higher layer that a 203 * WifiMac(-derived) object invokes to pass a packet up the stack. 204 * 205 * \param packet the packet that has been received. 206 * \param from the MAC address of the device that sent the packet. 207 * \param to the MAC address of the device that the packet is destined for. 208 */ 209 typedef Callback<void, Ptr<const Packet>, Mac48Address, Mac48Address> ForwardUpCallback; 210 211 /** 212 * \param upCallback the callback to invoke when a packet must be 213 * forwarded up the stack. 214 */ 215 virtual void SetForwardUpCallback (ForwardUpCallback upCallback) = 0; 216 /** 217 * \param linkUp the callback to invoke when the link becomes up. 218 */ 219 virtual void SetLinkUpCallback (Callback<void> linkUp) = 0; 220 /** 221 * \param linkDown the callback to invoke when the link becomes down. 222 */ 223 virtual void SetLinkDownCallback (Callback<void> linkDown) = 0; 224 /* Next functions are not pure virtual so non QoS WifiMacs are not 225 * forced to implement them. 226 */ 227 228 /** 229 * \param packet the packet being enqueued 230 * 231 * Public method used to fire a MacTx trace. Implemented for encapsulation purposes. 232 * Note this trace indicates that the packet was accepted by the device only. 233 * The packet may be dropped later (e.g. if the queue is full). 234 */ 235 void NotifyTx (Ptr<const Packet> packet); 236 /** 237 * \param packet the packet being dropped 238 * 239 * Public method used to fire a MacTxDrop trace. 240 * This trace indicates that the packet was dropped before it was queued for 241 * transmission (e.g. when a STA is not associated with an AP). 242 */ 243 void NotifyTxDrop (Ptr<const Packet> packet); 244 /** 245 * \param packet the packet we received 246 * 247 * Public method used to fire a MacRx trace. Implemented for encapsulation purposes. 248 */ 249 void NotifyRx (Ptr<const Packet> packet); 250 /** 251 * \param packet the packet we received promiscuously 252 * 253 * Public method used to fire a MacPromiscRx trace. Implemented for encapsulation purposes. 254 */ 255 void NotifyPromiscRx (Ptr<const Packet> packet); 256 /** 257 * \param packet the packet we received but is not destined for us 258 * 259 * Public method used to fire a MacRxDrop trace. Implemented for encapsulation purposes. 260 */ 261 void NotifyRxDrop (Ptr<const Packet> packet); 262 263 /** 264 * \param standard the wifi standard to be configured 265 * 266 * This method completes the configuration process for a requested PHY standard. 267 * Subclasses should implement this method to configure their DCF queues 268 * according to the requested standard. 269 */ 270 virtual void ConfigureStandard (WifiStandard standard) = 0; 271 272 /** 273 * \return pointer to HtConfiguration if it exists 274 */ 275 Ptr<HtConfiguration> GetHtConfiguration (void) const; 276 /** 277 * \return pointer to VhtConfiguration if it exists 278 */ 279 Ptr<VhtConfiguration> GetVhtConfiguration (void) const; 280 /** 281 * \return pointer to HeConfiguration if it exists 282 */ 283 Ptr<HeConfiguration> GetHeConfiguration (void) const; 284 285 286 protected: 287 /** 288 * \param dcf the DCF to be configured 289 * \param cwmin the minimum contention window for the DCF 290 * \param cwmax the maximum contention window for the DCF 291 * \param isDsss flag to indicate whether PHY is DSSS or HR/DSSS 292 * \param ac the access category for the DCF 293 * 294 * Configure the DCF with appropriate values depending on the given access category. 295 */ 296 void ConfigureDcf (Ptr<Txop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac); 297 298 299 private: 300 Ptr<NetDevice> m_device; ///< Pointer to the device 301 302 /** 303 * The trace source fired when packets come into the "top" of the device 304 * at the L3/L2 transition, before being queued for transmission. 305 * 306 * \see class CallBackTraceSource 307 */ 308 TracedCallback<Ptr<const Packet> > m_macTxTrace; 309 /** 310 * The trace source fired when packets coming into the "top" of the device 311 * are dropped at the MAC layer before being queued for transmission. 312 * 313 * \see class CallBackTraceSource 314 */ 315 TracedCallback<Ptr<const Packet> > m_macTxDropTrace; 316 /** 317 * The trace source fired for packets successfully received by the device 318 * immediately before being forwarded up to higher layers (at the L2/L3 319 * transition). This is a promiscuous trace. 320 * 321 * \see class CallBackTraceSource 322 */ 323 TracedCallback<Ptr<const Packet> > m_macPromiscRxTrace; 324 /** 325 * The trace source fired for packets successfully received by the device 326 * immediately before being forwarded up to higher layers (at the L2/L3 327 * transition). This is a non- promiscuous trace. 328 * 329 * \see class CallBackTraceSource 330 */ 331 TracedCallback<Ptr<const Packet> > m_macRxTrace; 332 /** 333 * The trace source fired when packets coming into the "top" of the device 334 * are dropped at the MAC layer during reception. 335 * 336 * \see class CallBackTraceSource 337 */ 338 TracedCallback<Ptr<const Packet> > m_macRxDropTrace; 339 }; 340 341 } //namespace ns3 342 343 #endif /* WIFI_MAC_H */ 344 345