39 * \brief handles interference calculations |
39 * \brief handles interference calculations |
40 */ |
40 */ |
41 class InterferenceHelper |
41 class InterferenceHelper |
42 { |
42 { |
43 public: |
43 public: |
|
44 /** |
|
45 * Signal event for a packet. |
|
46 */ |
44 class Event : public SimpleRefCount<InterferenceHelper::Event> |
47 class Event : public SimpleRefCount<InterferenceHelper::Event> |
45 { |
48 { |
46 public: |
49 public: |
|
50 /** |
|
51 * Create an Event with the given parameters. |
|
52 * |
|
53 * \param size packet size |
|
54 * \param payloadMode Wi-Fi mode used for the payload |
|
55 * \param preamble preamble type |
|
56 * \param duration duration of the signal |
|
57 * \param rxPower the receive power (w) |
|
58 * \param txvector TXVECTOR of the packet |
|
59 */ |
47 Event (uint32_t size, WifiMode payloadMode, |
60 Event (uint32_t size, WifiMode payloadMode, |
48 enum WifiPreamble preamble, |
61 enum WifiPreamble preamble, |
49 Time duration, double rxPower, WifiTxVector txvector); |
62 Time duration, double rxPower, WifiTxVector txvector); |
50 ~Event (); |
63 ~Event (); |
51 |
64 |
|
65 /** |
|
66 * Return the duration of the signal. |
|
67 * |
|
68 * \return the duration of the signal |
|
69 */ |
52 Time GetDuration (void) const; |
70 Time GetDuration (void) const; |
|
71 /** |
|
72 * Return the start time of the signal. |
|
73 * |
|
74 * \return the start time of the signal |
|
75 */ |
53 Time GetStartTime (void) const; |
76 Time GetStartTime (void) const; |
|
77 /** |
|
78 * Return the end time of the signal. |
|
79 * |
|
80 * \return the end time of the signal |
|
81 */ |
54 Time GetEndTime (void) const; |
82 Time GetEndTime (void) const; |
|
83 /** |
|
84 * Return the receive power (w). |
|
85 * |
|
86 * \return the receive power (w) |
|
87 */ |
55 double GetRxPowerW (void) const; |
88 double GetRxPowerW (void) const; |
|
89 /** |
|
90 * Return the size of the packet (bytes). |
|
91 * |
|
92 * \return the size of the packet (bytes) |
|
93 */ |
56 uint32_t GetSize (void) const; |
94 uint32_t GetSize (void) const; |
|
95 /** |
|
96 * Return the Wi-Fi mode used for the payload. |
|
97 * |
|
98 * \return the Wi-Fi mode used for the payload |
|
99 */ |
57 WifiMode GetPayloadMode (void) const; |
100 WifiMode GetPayloadMode (void) const; |
|
101 /** |
|
102 * Return the preamble type of the packet. |
|
103 * |
|
104 * \return the preamble type of the packet |
|
105 */ |
58 enum WifiPreamble GetPreambleType (void) const; |
106 enum WifiPreamble GetPreambleType (void) const; |
|
107 /** |
|
108 * Return the TXVECTOR of the packet. |
|
109 * |
|
110 * \return the TXVECTOR of the packet |
|
111 */ |
59 WifiTxVector GetTxVector (void) const; |
112 WifiTxVector GetTxVector (void) const; |
60 private: |
113 private: |
61 uint32_t m_size; |
114 uint32_t m_size; |
62 WifiMode m_payloadMode; |
115 WifiMode m_payloadMode; |
63 enum WifiPreamble m_preamble; |
116 enum WifiPreamble m_preamble; |
64 Time m_startTime; |
117 Time m_startTime; |
65 Time m_endTime; |
118 Time m_endTime; |
66 double m_rxPowerW; |
119 double m_rxPowerW; |
67 WifiTxVector m_txVector; |
120 WifiTxVector m_txVector; |
68 }; |
121 }; |
|
122 /** |
|
123 * A struct for both SNR and PER |
|
124 */ |
69 struct SnrPer |
125 struct SnrPer |
70 { |
126 { |
71 double snr; |
127 double snr; |
72 double per; |
128 double per; |
73 }; |
129 }; |
74 |
130 |
75 InterferenceHelper (); |
131 InterferenceHelper (); |
76 ~InterferenceHelper (); |
132 ~InterferenceHelper (); |
77 |
133 |
|
134 /** |
|
135 * Set the noise figure. |
|
136 * |
|
137 * \param value noise figure |
|
138 */ |
78 void SetNoiseFigure (double value); |
139 void SetNoiseFigure (double value); |
|
140 /** |
|
141 * Set the error rate model for this interference helper. |
|
142 * |
|
143 * \param rate Error rate model |
|
144 */ |
79 void SetErrorRateModel (Ptr<ErrorRateModel> rate); |
145 void SetErrorRateModel (Ptr<ErrorRateModel> rate); |
80 |
146 |
|
147 /** |
|
148 * Return the noise figure. |
|
149 * |
|
150 * \return the noise figure |
|
151 */ |
81 double GetNoiseFigure (void) const; |
152 double GetNoiseFigure (void) const; |
|
153 /** |
|
154 * Return the error rate model. |
|
155 * |
|
156 * \return Error rate model |
|
157 */ |
82 Ptr<ErrorRateModel> GetErrorRateModel (void) const; |
158 Ptr<ErrorRateModel> GetErrorRateModel (void) const; |
83 |
159 |
84 |
160 |
85 /** |
161 /** |
86 * \param energyW the minimum energy (W) requested |
162 * \param energyW the minimum energy (W) requested |
88 * energy on the medium will be higher than |
164 * energy on the medium will be higher than |
89 * the requested threshold. |
165 * the requested threshold. |
90 */ |
166 */ |
91 Time GetEnergyDuration (double energyW); |
167 Time GetEnergyDuration (double energyW); |
92 |
168 |
93 |
169 /** |
|
170 * Add the packet-related signal to interference helper. |
|
171 * |
|
172 * \param size packet size |
|
173 * \param payloadMode Wi-Fi mode for the payload |
|
174 * \param preamble Wi-Fi preamble for the packet |
|
175 * \param duration the duration of the signal |
|
176 * \param rxPower receive power (w) |
|
177 * \param txvector TXVECTOR of the packet |
|
178 * \return InterferenceHelper::Event |
|
179 */ |
94 Ptr<InterferenceHelper::Event> Add (uint32_t size, WifiMode payloadMode, |
180 Ptr<InterferenceHelper::Event> Add (uint32_t size, WifiMode payloadMode, |
95 enum WifiPreamble preamble, |
181 enum WifiPreamble preamble, |
96 Time duration, double rxPower, WifiTxVector txvector); |
182 Time duration, double rxPower, WifiTxVector txvector); |
97 |
183 |
|
184 /** |
|
185 * Calculate the SNIR at the start of the packet and accumulate |
|
186 * all SNIR changes in the snir vector. |
|
187 * |
|
188 * \param event the event corresponding to the first time the packet arrives |
|
189 * \return struct of SNR and PER |
|
190 */ |
98 struct InterferenceHelper::SnrPer CalculateSnrPer (Ptr<InterferenceHelper::Event> event); |
191 struct InterferenceHelper::SnrPer CalculateSnrPer (Ptr<InterferenceHelper::Event> event); |
|
192 /** |
|
193 * Notify that RX has started. |
|
194 */ |
99 void NotifyRxStart (); |
195 void NotifyRxStart (); |
|
196 /** |
|
197 * Notify that RX has ended. |
|
198 */ |
100 void NotifyRxEnd (); |
199 void NotifyRxEnd (); |
|
200 /** |
|
201 * Erase all events. |
|
202 */ |
101 void EraseEvents (void); |
203 void EraseEvents (void); |
102 private: |
204 private: |
|
205 /** |
|
206 * Noise and Interference (thus Ni) event. |
|
207 */ |
103 class NiChange |
208 class NiChange |
104 { |
209 { |
105 public: |
210 public: |
|
211 /** |
|
212 * Create a NiChange at the given time and the amount of NI change. |
|
213 * |
|
214 * \param time time of the event |
|
215 * \param delta the power |
|
216 */ |
106 NiChange (Time time, double delta); |
217 NiChange (Time time, double delta); |
|
218 /** |
|
219 * Return the event time. |
|
220 * |
|
221 * \return the event time. |
|
222 */ |
107 Time GetTime (void) const; |
223 Time GetTime (void) const; |
|
224 /** |
|
225 * Return the power |
|
226 * |
|
227 * \return the power |
|
228 */ |
108 double GetDelta (void) const; |
229 double GetDelta (void) const; |
|
230 /** |
|
231 * Compare the event time of two NiChange objects (a < o). |
|
232 * |
|
233 * \param o |
|
234 * \return true if a < o.time, false otherwise |
|
235 */ |
109 bool operator < (const NiChange& o) const; |
236 bool operator < (const NiChange& o) const; |
110 private: |
237 private: |
111 Time m_time; |
238 Time m_time; |
112 double m_delta; |
239 double m_delta; |
113 }; |
240 }; |
|
241 /** |
|
242 * typedef for a vector of NiChanges |
|
243 */ |
114 typedef std::vector <NiChange> NiChanges; |
244 typedef std::vector <NiChange> NiChanges; |
|
245 /** |
|
246 * typedef for a list of Events |
|
247 */ |
115 typedef std::list<Ptr<Event> > Events; |
248 typedef std::list<Ptr<Event> > Events; |
116 |
249 |
117 InterferenceHelper (const InterferenceHelper &o); |
250 //InterferenceHelper (const InterferenceHelper &o); |
118 InterferenceHelper &operator = (const InterferenceHelper &o); |
251 //InterferenceHelper &operator = (const InterferenceHelper &o); |
|
252 /** |
|
253 * Append the given Event. |
|
254 * |
|
255 * \param event |
|
256 */ |
119 void AppendEvent (Ptr<Event> event); |
257 void AppendEvent (Ptr<Event> event); |
|
258 /** |
|
259 * Calculate noise and interference power in W. |
|
260 * |
|
261 * \param event |
|
262 * \param ni |
|
263 * \return noise and interference power |
|
264 */ |
120 double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const; |
265 double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const; |
|
266 /** |
|
267 * Calculate SNR (linear ratio) from the given signal power and noise+interference power. |
|
268 * (Mode is not currently used) |
|
269 * |
|
270 * \param signal |
|
271 * \param noiseInterference |
|
272 * \param mode |
|
273 * \return SNR in liear ratio |
|
274 */ |
121 double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const; |
275 double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const; |
122 double CalculateChunkSuccessRate (double snir, Time delay, WifiMode mode) const; |
276 /** |
|
277 * Calculate the success rate of the chunk given the SINR, duration, and Wi-Fi mode. |
|
278 * The duration and mode are used to calculate how many bits are present in the chunk. |
|
279 * |
|
280 * \param snir SINR |
|
281 * \param duration |
|
282 * \param mode |
|
283 * \return the success rate |
|
284 */ |
|
285 double CalculateChunkSuccessRate (double snir, Time duration, WifiMode mode) const; |
|
286 /** |
|
287 * Calculate the error rate of the given packet. The packet can be divided into |
|
288 * multiple chunks (e.g. due to interference from other transmissions). |
|
289 * |
|
290 * \param event |
|
291 * \param ni |
|
292 * \return the error rate of the packet |
|
293 */ |
123 double CalculatePer (Ptr<const Event> event, NiChanges *ni) const; |
294 double CalculatePer (Ptr<const Event> event, NiChanges *ni) const; |
124 |
295 |
125 double m_noiseFigure; /**< noise figure (linear) */ |
296 double m_noiseFigure; /**< noise figure (linear) */ |
126 Ptr<ErrorRateModel> m_errorRateModel; |
297 Ptr<ErrorRateModel> m_errorRateModel; |
127 /// Experimental: needed for energy duration calculation |
298 /// Experimental: needed for energy duration calculation |
128 NiChanges m_niChanges; |
299 NiChanges m_niChanges; |
129 double m_firstPower; |
300 double m_firstPower; |
130 bool m_rxing; |
301 bool m_rxing; |
131 /// Returns an iterator to the first nichange, which is later than moment |
302 /// Returns an iterator to the first nichange, which is later than moment |
132 NiChanges::iterator GetPosition (Time moment); |
303 NiChanges::iterator GetPosition (Time moment); |
|
304 /** |
|
305 * Add NiChange to the list at the appropriate position. |
|
306 * |
|
307 * \param change |
|
308 */ |
133 void AddNiChangeEvent (NiChange change); |
309 void AddNiChangeEvent (NiChange change); |
134 }; |
310 }; |
135 |
311 |
136 } // namespace ns3 |
312 } // namespace ns3 |
137 |
313 |