00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #ifndef DCA_TXOP_H 00022 #define DCA_TXOP_H 00023 00024 #include <stdint.h> 00025 #include "ns3/callback.h" 00026 #include "ns3/packet.h" 00027 #include "ns3/nstime.h" 00028 #include "ns3/object.h" 00029 #include "wifi-mac-header.h" 00030 #include "wifi-mode.h" 00031 #include "wifi-remote-station-manager.h" 00032 00033 namespace ns3 { 00034 00035 class DcfState; 00036 class DcfManager; 00037 class WifiMacQueue; 00038 class MacLow; 00039 class WifiMacParameters; 00040 class MacTxMiddle; 00041 class RandomStream; 00042 class MacStation; 00043 class MacStations; 00044 00045 /** 00046 * \brief handle packet fragmentation and retransmissions. 00047 * 00048 * This class implements the packet fragmentation and 00049 * retransmission policy. It uses the ns3::MacLow and ns3::DcfManager 00050 * helper classes to respectively send packets and decide when 00051 * to send them. Packets are stored in a ns3::WifiMacQueue until 00052 * they can be sent. 00053 * 00054 * The policy currently implemented uses a simple fragmentation 00055 * threshold: any packet bigger than this threshold is fragmented 00056 * in fragments whose size is smaller than the threshold. 00057 * 00058 * The retransmission policy is also very simple: every packet is 00059 * retransmitted until it is either successfully transmitted or 00060 * it has been retransmitted up until the ssrc or slrc thresholds. 00061 * 00062 * The rts/cts policy is similar to the fragmentation policy: when 00063 * a packet is bigger than a threshold, the rts/cts protocol is used. 00064 */ 00065 class DcaTxop : public Object 00066 { 00067 public: 00068 static TypeId GetTypeId (void); 00069 00070 typedef Callback <void, WifiMacHeader const&> TxOk; 00071 typedef Callback <void, WifiMacHeader const&> TxFailed; 00072 00073 DcaTxop (); 00074 ~DcaTxop (); 00075 00076 void SetLow (Ptr<MacLow> low); 00077 void SetManager (DcfManager *manager); 00078 void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> remoteManager); 00079 00080 /** 00081 * \param callback the callback to invoke when a 00082 * packet transmission was completed successfully. 00083 */ 00084 void SetTxOkCallback (TxOk callback); 00085 /** 00086 * \param callback the callback to invoke when a 00087 * packet transmission was completed unsuccessfully. 00088 */ 00089 void SetTxFailedCallback (TxFailed callback); 00090 00091 void SetMaxQueueSize (uint32_t size); 00092 void SetMaxQueueDelay (Time delay); 00093 void SetMinCw (uint32_t minCw); 00094 void SetMaxCw (uint32_t maxCw); 00095 void SetAifsn (uint32_t aifsn); 00096 uint32_t GetMinCw (void) const; 00097 uint32_t GetMaxCw (void) const; 00098 uint32_t GetAifsn (void) const; 00099 00100 /** 00101 * \param packet packet to send 00102 * \param hdr header of packet to send. 00103 * 00104 * Store the packet in the internal queue until it 00105 * can be sent safely. 00106 */ 00107 void Queue (Ptr<const Packet> packet, WifiMacHeader const &hdr); 00108 00109 private: 00110 class TransmissionListener; 00111 class NavListener; 00112 class PhyListener; 00113 class Dcf; 00114 friend class Dcf; 00115 friend class TransmissionListener; 00116 friend class WifiRemoteStation; 00117 00118 // Inherited from ns3::Object 00119 Ptr<MacLow> Low (void); 00120 00121 /* dcf notifications forwarded here */ 00122 bool NeedsAccess (void) const; 00123 void NotifyAccessGranted (void); 00124 void NotifyInternalCollision (void); 00125 void NotifyCollision (void); 00126 /* event handlers */ 00127 void GotCts (double snr, WifiMode txMode); 00128 void MissedCts (void); 00129 void GotAck (double snr, WifiMode txMode); 00130 void MissedAck (void); 00131 void StartNext (void); 00132 void Cancel (void); 00133 00134 void RestartAccessIfNeeded (void); 00135 void StartAccessIfNeeded (void); 00136 bool NeedRts (void); 00137 bool NeedRtsRetransmission (void); 00138 bool NeedDataRetransmission (void); 00139 bool NeedFragmentation (void); 00140 uint32_t GetNextFragmentSize (void); 00141 uint32_t GetFragmentSize (void); 00142 uint32_t GetFragmentOffset (void); 00143 WifiRemoteStation *GetStation (Mac48Address to) const; 00144 bool IsLastFragment (void); 00145 void NextFragment (void); 00146 Ptr<Packet> GetFragmentPacket (WifiMacHeader *hdr); 00147 virtual void DoDispose (void); 00148 00149 Dcf *m_dcf; 00150 DcfManager *m_manager; 00151 TxOk m_txOkCallback; 00152 TxFailed m_txFailedCallback; 00153 Ptr<WifiMacQueue> m_queue; 00154 MacTxMiddle *m_txMiddle; 00155 Ptr <MacLow> m_low; 00156 Ptr<WifiRemoteStationManager> m_stationManager; 00157 TransmissionListener *m_transmissionListener; 00158 RandomStream *m_rng; 00159 00160 00161 bool m_accessOngoing; 00162 Ptr<const Packet> m_currentPacket; 00163 WifiMacHeader m_currentHdr; 00164 uint8_t m_fragmentNumber; 00165 }; 00166 00167 } //namespace ns3 00168 00169 00170 00171 #endif /* DCA_TXOP_H */