src/devices/mesh/mesh-wifi-interface-mac.h
changeset 5129 5688b8da4526
parent 5126 8e06088a785d
child 5130 b5062e8e0da1
equal deleted inserted replaced
5128:d6e168eba404 5129:5688b8da4526
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /* 
     2 /*
     3  * Copyright (c) 2009 IITP RAS
     3  * Copyright (c) 2009 IITP RAS
     4  * 
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     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
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     7  * published by the Free Software Foundation;
     8  *
     8  *
     9  * This program is distributed in the hope that it will be useful,
     9  * This program is distributed in the hope that it will be useful,
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    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
    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
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  * 
    17  *
    18  * Authors: Kirill Andreev <andreev@iitp.ru>
    18  * Authors: Kirill Andreev <andreev@iitp.ru>
    19  *          Pavel Boyko <boyko@iitp.ru>
    19  *          Pavel Boyko <boyko@iitp.ru>
    20  */
    20  */
    21 
    21 
    22 #ifndef MESHWIFIINTERFACEMAC_H_
    22 #ifndef MESHWIFIINTERFACEMAC_H_
    32 #include "ns3/wifi-remote-station-manager.h"
    32 #include "ns3/wifi-remote-station-manager.h"
    33 #include "ns3/wifi-mac.h"
    33 #include "ns3/wifi-mac.h"
    34 #include "ns3/mesh-wifi-interface-mac-plugin.h"
    34 #include "ns3/mesh-wifi-interface-mac-plugin.h"
    35 #include "ns3/event-id.h"
    35 #include "ns3/event-id.h"
    36 #include "qos-utils.h"
    36 #include "qos-utils.h"
    37 namespace ns3 {
    37 namespace ns3
       
    38 {
    38 
    39 
    39 class WifiMacHeader;
    40 class WifiMacHeader;
    40 class DcaTxop;
    41 class DcaTxop;
    41 class WifiPhy;
    42 class WifiPhy;
    42 class DcfManager;
    43 class DcfManager;
    44 class MacLow;
    45 class MacLow;
    45 /**
    46 /**
    46  * \ingroup mesh
    47  * \ingroup mesh
    47  *
    48  *
    48  * \brief Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins mechanism.
    49  * \brief Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins mechanism.
    49  * 
    50  *
    50  * Now only three output queues are used:
    51  * Now only three output queues are used:
    51  *  - beacons (PIFS and no backoff),
    52  *  - beacons (PIFS and no backoff),
    52  *  - background traffic,
    53  *  - background traffic,
    53  *  - management and priority traffic.
    54  *  - management and priority traffic.
    54  *  
    55  *
    55  */
    56  */
    56 class MeshWifiInterfaceMac : public WifiMac
    57 class MeshWifiInterfaceMac : public WifiMac
    57 {
    58 {
    58 public:
    59 public:
    59   /// Never forget to support typeid
    60   /// Never forget to support typeid
    60   static TypeId  GetTypeId ();
    61   static TypeId GetTypeId ();
    61   /// C-tor
    62   /// C-tor
    62   MeshWifiInterfaceMac ();
    63   MeshWifiInterfaceMac ();
    63   /// D-tor
    64   /// D-tor
    64   virtual ~MeshWifiInterfaceMac ();
    65   virtual ~MeshWifiInterfaceMac ();
    65   
    66 
    66   ///\name Inherited from WifiMac
    67   ///\name Inherited from WifiMac
    67   //\{
    68   //\{
    68   virtual void  SetSlot (Time slotTime);
    69   virtual void  SetSlot (Time slotTime);
    69   virtual void  SetSifs (Time sifs);
    70   virtual void  SetSifs (Time sifs);
    70   virtual void  SetPifs (Time pifs);
    71   virtual void  SetPifs (Time pifs);
    89   virtual Mac48Address GetBssid () const;
    90   virtual Mac48Address GetBssid () const;
    90   virtual Ssid  GetSsid () const;
    91   virtual Ssid  GetSsid () const;
    91   virtual void  SetAddress (Mac48Address address);
    92   virtual void  SetAddress (Mac48Address address);
    92   virtual void  SetSsid (Ssid ssid);
    93   virtual void  SetSsid (Ssid ssid);
    93   //\}
    94   //\}
    94   
    95 
    95   ///\name Each mesh point interfaces must know the mesh point address
    96   ///\name Each mesh point interfaces must know the mesh point address
    96   //\{
    97   //\{
    97   void SetMeshPointAddress (Mac48Address);
    98   void SetMeshPointAddress (Mac48Address);
    98   Mac48Address GetMeshPointAddress () const;
    99   Mac48Address GetMeshPointAddress () const;
    99   //\}
   100   //\}
   103   void SetRandomStartDelay (Time interval);
   104   void SetRandomStartDelay (Time interval);
   104   /// Set interval between two successive beacons
   105   /// Set interval between two successive beacons
   105   void SetBeaconInterval (Time interval);
   106   void SetBeaconInterval (Time interval);
   106   /// \return interval between two beacons
   107   /// \return interval between two beacons
   107   Time GetBeaconInterval () const;
   108   Time GetBeaconInterval () const;
   108   /** 
   109   /**
   109    * \brief Next beacon frame time
   110    * \brief Next beacon frame time
   110    * 
   111    *
   111    * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer management protocol in 802.11s)
   112    * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer management protocol in 802.11s)
   112    */ 
   113    */
   113   Time GetTbtt () const;
   114   Time GetTbtt () const;
   114   /**
   115   /**
   115    * \brief Shift TBTT.
   116    * \brief Shift TBTT.
   116    * 
   117    *
   117    * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer management protocol in 802.11s)
   118    * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer management protocol in 802.11s)
   118    * 
   119    *
   119    * \attention User of ShiftTbtt () must take care to not shift it to the past. 
   120    * \attention User of ShiftTbtt () must take care to not shift it to the past.
   120    */
   121    */
   121   void ShiftTbtt (Time shift);
   122   void ShiftTbtt (Time shift);
   122   //\}
   123   //\}
   123   
   124 
   124   ///\name Plugins
   125   ///\name Plugins
   125   //\{
   126   //\{
   126   /// Install plugin. TODO return unique ID to allow unregister plugins
   127   /// Install plugin. TODO return unique ID to allow unregister plugins
   127   void InstallPlugin (Ptr<MeshWifiInterfaceMacPlugin> plugin);
   128   void InstallPlugin (Ptr<MeshWifiInterfaceMacPlugin> plugin);
   128   //\}
   129   //\}
   129   
   130 
   130   /** \name Channel switching
   131   /** \name Channel switching
   131    * 
   132    *
   132    * Channel center frequency = Channel starting frequency + 5 * channel_id (MHz), 
   133    * Channel center frequency = Channel starting frequency + 5 * channel_id (MHz),
   133    * where Starting channel frequency is standard-dependent as defined in IEEE 802.11-2007 17.3.8.3.2.
   134    * where Starting channel frequency is standard-dependent as defined in IEEE 802.11-2007 17.3.8.3.2.
   134    * 
   135    *
   135    * Number of channels to use must be limited elsewhere. 
   136    * Number of channels to use must be limited elsewhere.
   136    */
   137    */
   137   //\{
   138   //\{
   138   /// Current channel Id
   139   /// Current channel Id
   139   uint16_t GetFrequencyChannel () const;
   140   uint16_t GetFrequencyChannel () const;
   140   /// Switch channel
   141   /// Switch channel
   141   void SwitchFrequencyChannel (uint16_t new_id);
   142   void SwitchFrequencyChannel (uint16_t new_id);
   142   //\}
   143   //\}
   143   
   144 
   144   /// To be used by plugins sending management frames.
   145   /// To be used by plugins sending management frames.
   145   void SendManagementFrame(Ptr<Packet> frame, const WifiMacHeader& hdr);
   146   void SendManagementFrame(Ptr<Packet> frame, const WifiMacHeader& hdr);
   146   /// \return true if rates are supported
   147   /// \return true if rates are supported
   147   bool CheckSupportedRates(SupportedRates rates) const;
   148   bool CheckSupportedRates(SupportedRates rates) const;
   148   /// \return list of supported bitrates
   149   /// \return list of supported bitrates
   163   Ptr<DcaTxop> GetQueue (AccessClass ac);
   164   Ptr<DcaTxop> GetQueue (AccessClass ac);
   164   /// Frame receive handler
   165   /// Frame receive handler
   165   void  Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
   166   void  Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
   166   /// Forward frame to mesh point
   167   /// Forward frame to mesh point
   167   virtual void ForwardUp (Ptr<Packet> packet, Mac48Address src, Mac48Address dst);
   168   virtual void ForwardUp (Ptr<Packet> packet, Mac48Address src, Mac48Address dst);
   168   /// Send frame. Frame is supposed to be tagged by routing information. TODO: clarify this point 
   169   /// Send frame. Frame is supposed to be tagged by routing information. TODO: clarify this point
   169   void  ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to);
   170   void  ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to);
   170   /// Send beacon
   171   /// Send beacon
   171   void SendBeacon ();
   172   void SendBeacon ();
   172   /// Schedule next beacon
   173   /// Schedule next beacon
   173   void ScheduleNextBeacon ();
   174   void ScheduleNextBeacon ();
   174   /// Get current beaconing status
   175   /// Get current beaconing status
   175   bool GetBeaconGeneration () const;
   176   bool GetBeaconGeneration () const;
   176   /// Real d-tor
   177   /// Real d-tor
   177   virtual void DoDispose ();
   178   virtual void DoDispose ();
   178   
   179 
   179 private:
   180 private:
   180   ///\name Wifi MAC internals
   181   ///\name Wifi MAC internals
   181   //\{
   182   //\{
   182   typedef std::map<AccessClass, Ptr<DcaTxop> > Queues;
   183   typedef std::map<AccessClass, Ptr<DcaTxop> > Queues;
   183   Queues m_queues;
   184   Queues m_queues;
   184   Ptr<DcaTxop>   m_beaconDca;
   185   Ptr<DcaTxop> m_beaconDca;
   185   Ptr<WifiRemoteStationManager> m_stationManager;
   186   Ptr<WifiRemoteStationManager> m_stationManager;
   186   Ptr<WifiPhy>   m_phy;
   187   Ptr<WifiPhy> m_phy;
   187   Callback<void, Ptr<Packet>, Mac48Address, Mac48Address>  m_upCallback;
   188   Callback<void, Ptr<Packet> , Mac48Address, Mac48Address> m_upCallback;
   188   //\}
   189   //\}
   189   
   190 
   190   ///\name Wifi timing intervals
   191   ///\name Wifi timing intervals
   191   //\{
   192   //\{
   192   Time m_slot;
   193   Time m_slot;
   193   Time m_sifs;
   194   Time m_sifs;
   194   Time m_pifs;
   195   Time m_pifs;
   195   Time m_ackTimeout;
   196   Time m_ackTimeout;
   196   Time m_ctsTimeout;
   197   Time m_ctsTimeout;
   197   Time m_eifsNoDifs;
   198   Time m_eifsNoDifs;
   198   //\}
   199   //\}
   199   
   200 
   200   ///\name Mesh timing intervals 
   201   ///\name Mesh timing intervals
   201   //\{
   202   //\{
   202   /// Beaconing interval.
   203   /// Beaconing interval.
   203   Time m_beaconInterval;
   204   Time m_beaconInterval;
   204   /// Maximum delay before first beacon
   205   /// Maximum delay before first beacon
   205   Time m_randomStart;
   206   Time m_randomStart;
   206   /// Time for the next frame
   207   /// Time for the next frame
   207   Time m_tbtt;
   208   Time m_tbtt;
   208   //\}
   209   //\}
   209   
   210 
   210   /// DCF implementation
   211   /// DCF implementation
   211   DcfManager* m_dcfManager;
   212   DcfManager* m_dcfManager;
   212   /// Middle MAC sublayer
   213   /// Middle MAC sublayer
   213   MacRxMiddle* m_rxMiddle;
   214   MacRxMiddle* m_rxMiddle;
   214   /// Low MAC sublayer
   215   /// Low MAC sublayer
   217   Mac48Address m_address;
   218   Mac48Address m_address;
   218   /// Mesh point address
   219   /// Mesh point address
   219   Mac48Address m_mpAddress;
   220   Mac48Address m_mpAddress;
   220   /// SSID
   221   /// SSID
   221   Ssid m_meshId;
   222   Ssid m_meshId;
   222   
   223 
   223   /// "Timer" for the next beacon 
   224   /// "Timer" for the next beacon
   224   EventId m_beaconSendEvent;
   225   EventId m_beaconSendEvent;
   225   
   226 
   226   typedef std::vector< Ptr<MeshWifiInterfaceMacPlugin> > PluginList; 
   227   typedef std::vector<Ptr<MeshWifiInterfaceMacPlugin> > PluginList;
   227   /// List of all installed plugins
   228   /// List of all installed plugins
   228   PluginList m_plugins;
   229   PluginList m_plugins;
   229   Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > m_linkMetricCallback;
   230   Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > m_linkMetricCallback;
   230   ///\name Statistics:
   231   ///\name Statistics:
   231   ///\{
   232   ///\{
   234     uint16_t recvBeacons;
   235     uint16_t recvBeacons;
   235     uint32_t sentFrames;
   236     uint32_t sentFrames;
   236     uint32_t sentBytes;
   237     uint32_t sentBytes;
   237     uint32_t recvFrames;
   238     uint32_t recvFrames;
   238     uint32_t recvBytes;
   239     uint32_t recvBytes;
   239     void Print (std::ostream & os) const;
   240     void
       
   241     Print (std::ostream & os) const;
   240     Statistics ();
   242     Statistics ();
   241   };
   243   };
   242   Statistics m_stats;
   244   Statistics m_stats;
   243   ///\}
   245   ///\}
   244 
   246