|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2005, 2006 INRIA |
|
4 * All rights reserved. |
|
5 * |
|
6 * This program is free software; you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License version 2 as |
|
8 * published by the Free Software Foundation; |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program; if not, write to the Free Software |
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 * |
|
19 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
20 */ |
|
21 #ifndef MAC_LOW_H |
|
22 #define MAC_LOW_H |
|
23 |
|
24 #include <vector> |
|
25 #include <stdint.h> |
|
26 |
|
27 #include "wifi-mac-header.h" |
|
28 #include "wifi-mode.h" |
|
29 #include "ns3/mac48-address.h" |
|
30 #include "ns3/callback.h" |
|
31 #include "ns3/callback-trace-source.h" |
|
32 #include "ns3/event-id.h" |
|
33 #include "ns3/packet.h" |
|
34 #include "ns3/nstime.h" |
|
35 |
|
36 namespace ns3 { |
|
37 |
|
38 class WifiNetDevice; |
|
39 class WifiPhy; |
|
40 class PacketLogger; |
|
41 class MacStations; |
|
42 class MacStation; |
|
43 class MacParameters; |
|
44 |
|
45 class MacLowTransmissionListener { |
|
46 public: |
|
47 MacLowTransmissionListener (); |
|
48 virtual ~MacLowTransmissionListener (); |
|
49 |
|
50 virtual void GotCts (double snr, WifiMode txMode) = 0; |
|
51 virtual void MissedCts (void) = 0; |
|
52 /* Do not rely on the gotAck method to be |
|
53 * given valid parameters when SuperFastAck is |
|
54 * enabled. |
|
55 */ |
|
56 virtual void GotAck (double snr, WifiMode txMode) = 0; |
|
57 virtual void MissedAck (void) = 0; |
|
58 virtual void StartNext (void) = 0; |
|
59 |
|
60 /* Invoked if this transmission was canceled |
|
61 * one way or another. When this method is invoked, |
|
62 * you can assume that the packet has not been passed |
|
63 * down the stack to the PHY. You are responsible |
|
64 * for freeing the packet if you want to. |
|
65 */ |
|
66 virtual void Cancel (void) = 0; |
|
67 }; |
|
68 |
|
69 |
|
70 class MacLowNavListener { |
|
71 public: |
|
72 MacLowNavListener (); |
|
73 virtual ~MacLowNavListener (); |
|
74 virtual void NavStart (Time now, Time duration) = 0; |
|
75 virtual void NavContinue (Time now, Time duration) = 0; |
|
76 virtual void NavReset (Time now, Time duration) = 0; |
|
77 }; |
|
78 |
|
79 class MacLowTransmissionParameters { |
|
80 public: |
|
81 MacLowTransmissionParameters (); |
|
82 |
|
83 /* If ACK is enabled, we wait ACKTimeout for an ACK. |
|
84 */ |
|
85 void EnableAck (void); |
|
86 /* If FastAck is enabled, we: |
|
87 * - wait PIFS after end-of-tx. If idle, report |
|
88 * FastAckMissed. |
|
89 * - if busy at end-of-tx+PIFS, wait end-of-rx |
|
90 * - if Ack ok at end-of-rx, report FastAck ok. |
|
91 * - if Ack not ok at end-of-rx, report FastAckMissed |
|
92 * at end-of-rx+SIFS. |
|
93 * This is really complicated but it is needed for |
|
94 * proper HCCA support. |
|
95 */ |
|
96 void EnableFastAck (void); |
|
97 /* If SuperFastAck is enabled, we: |
|
98 * - if busy at end-of-tx+PIFS, report gotAck |
|
99 * - if idle at end-of-tx+PIFS, report missedAck |
|
100 */ |
|
101 void EnableSuperFastAck (void); |
|
102 /* If RTS is enabled, we wait CTSTimeout for a CTS. |
|
103 * Otherwise, no RTS is sent. |
|
104 */ |
|
105 void EnableRts (void); |
|
106 /* If NextData is enabled, we add the transmission duration |
|
107 * of the nextData to the durationId and we notify the |
|
108 * transmissionListener at the end of the current |
|
109 * transmission + SIFS. |
|
110 */ |
|
111 void EnableNextData (uint32_t size); |
|
112 |
|
113 /* If we enable this, we ignore all other durationId |
|
114 * calculation and simply force the packet's durationId |
|
115 * field to this value. |
|
116 */ |
|
117 void EnableOverrideDurationId (Time durationId); |
|
118 |
|
119 void DisableAck (void); |
|
120 void DisableRts (void); |
|
121 void DisableNextData (void); |
|
122 void DisableOverrideDurationId (void); |
|
123 |
|
124 bool MustWaitAck (void) const; |
|
125 bool MustWaitNormalAck (void) const; |
|
126 bool MustWaitFastAck (void) const; |
|
127 bool MustWaitSuperFastAck (void) const; |
|
128 bool MustSendRts (void) const; |
|
129 bool HasDurationId (void) const; |
|
130 Time GetDurationId (void) const; |
|
131 bool HasNextPacket (void) const; |
|
132 uint32_t GetNextPacketSize (void) const; |
|
133 |
|
134 private: |
|
135 uint32_t m_nextSize; |
|
136 enum { |
|
137 ACK_NONE, |
|
138 ACK_NORMAL, |
|
139 ACK_FAST, |
|
140 ACK_SUPER_FAST |
|
141 } m_waitAck; |
|
142 bool m_sendRts; |
|
143 Time m_overrideDurationId; |
|
144 }; |
|
145 |
|
146 |
|
147 class MacLow { |
|
148 public: |
|
149 typedef Callback<void, Packet , WifiMacHeader const*> MacLowRxCallback; |
|
150 |
|
151 MacLow (); |
|
152 ~MacLow (); |
|
153 |
|
154 void SetInterface (Ptr<WifiNetDevice> interface); |
|
155 void SetPhy (WifiPhy *phy); |
|
156 void SetStations (MacStations *stations); |
|
157 void SetParameters (MacParameters *parameters); |
|
158 void SetRxCallback (MacLowRxCallback callback); |
|
159 void RegisterNavListener (MacLowNavListener *listener); |
|
160 |
|
161 /* This transmission time includes the time required for |
|
162 * the next packet transmission if one was selected. |
|
163 */ |
|
164 Time CalculateTransmissionTime (uint32_t payloadSize, |
|
165 Mac48Address to, |
|
166 MacLowTransmissionParameters const¶meters) const; |
|
167 |
|
168 /* start the transmission of the currently-stored data. */ |
|
169 void StartTransmission (Packet packet, |
|
170 WifiMacHeader const*hdr, |
|
171 MacLowTransmissionParameters parameters, |
|
172 MacLowTransmissionListener *listener); |
|
173 |
|
174 void ReceiveOk (Packet const packet, double rxSnr, WifiMode txMode, WifiMode headerMode); |
|
175 void ReceiveError (Packet const packet, double rxSnr); |
|
176 private: |
|
177 void CancelAllEvents (void); |
|
178 uint32_t GetAckSize (void) const; |
|
179 uint32_t GetRtsSize (void) const; |
|
180 uint32_t GetCtsSize (void) const; |
|
181 Time GetSifs (void) const; |
|
182 Time GetPifs (void) const; |
|
183 Time GetAckTimeout (void) const; |
|
184 Time GetCtsTimeout (void) const; |
|
185 uint32_t GetCurrentSize (void) const; |
|
186 Time NowUs (void) const; |
|
187 MacStation *GetStation (Mac48Address to) const; |
|
188 void ForwardDown (Packet const packet, WifiMacHeader const *hdr, |
|
189 WifiMode txMode); |
|
190 Time CalculateOverallTxTime (uint32_t size, |
|
191 Mac48Address to, |
|
192 MacLowTransmissionParameters const ¶ms) const; |
|
193 WifiMode GetRtsTxMode (Mac48Address to) const; |
|
194 WifiMode GetDataTxMode (Mac48Address to, uint32_t size) const; |
|
195 WifiMode GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const; |
|
196 WifiMode GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const; |
|
197 void NotifyNav (Time at, WifiMacHeader const*hdr); |
|
198 bool IsNavZero (Time at); |
|
199 void MaybeCancelPrevious (void); |
|
200 |
|
201 void NormalAckTimeout (void); |
|
202 void FastAckTimeout (void); |
|
203 void SuperFastAckTimeout (void); |
|
204 void FastAckFailedTimeout (void); |
|
205 void CtsTimeout (void); |
|
206 void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); |
|
207 void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); |
|
208 void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode); |
|
209 void WaitSifsAfterEndTx (void); |
|
210 |
|
211 void SendRtsForPacket (void); |
|
212 void SendDataPacket (void); |
|
213 void SendCurrentTxPacket (void); |
|
214 void StartDataTxTimers (void); |
|
215 |
|
216 Ptr<WifiNetDevice> m_interface; |
|
217 WifiPhy *m_phy; |
|
218 MacStations *m_stations; |
|
219 MacParameters *m_parameters; |
|
220 MacLowRxCallback m_rxCallback; |
|
221 typedef std::vector<MacLowNavListener *>::const_iterator NavListenersCI; |
|
222 typedef std::vector<MacLowNavListener *> NavListeners; |
|
223 NavListeners m_navListeners; |
|
224 |
|
225 EventId m_normalAckTimeoutEvent; |
|
226 EventId m_fastAckTimeoutEvent; |
|
227 EventId m_superFastAckTimeoutEvent; |
|
228 EventId m_fastAckFailedTimeoutEvent; |
|
229 EventId m_ctsTimeoutEvent; |
|
230 EventId m_sendCtsEvent; |
|
231 EventId m_sendAckEvent; |
|
232 EventId m_sendDataEvent; |
|
233 EventId m_waitSifsEvent; |
|
234 |
|
235 Packet m_currentPacket; |
|
236 bool m_hasCurrent; |
|
237 WifiMacHeader m_currentHdr; |
|
238 MacLowTransmissionParameters m_txParams; |
|
239 MacLowTransmissionListener *m_listener; |
|
240 |
|
241 Time m_lastNavStart; |
|
242 Time m_lastNavDuration; |
|
243 |
|
244 CallbackTraceSource<Packet> m_dropError; |
|
245 }; |
|
246 |
|
247 }; // namespace ns3 |
|
248 |
|
249 #endif /* MAC_LOW_H */ |