OLD | NEW |
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) 2011 The Boeing Company | 3 * Copyright (c) 2011 The Boeing Company |
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, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
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 * Author: | 18 * Author: |
19 * Gary Pei <guangyu.pei@boeing.com> | 19 * Gary Pei <guangyu.pei@boeing.com> |
20 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de> | 20 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de> |
| 21 * Peishuo Li <pressthunder@gmail.com> |
| 22 * Pjotr Kourzanov <peter.kourzanov@xs4all.nl> |
21 */ | 23 */ |
22 #include "lr-wpan-phy.h" | 24 #include "lr-wpan-phy.h" |
23 #include "lr-wpan-lqi-tag.h" | 25 #include "lr-wpan-lqi-tag.h" |
24 #include "lr-wpan-spectrum-signal-parameters.h" | 26 #include "lr-wpan-spectrum-signal-parameters.h" |
25 #include "lr-wpan-spectrum-value-helper.h" | 27 #include "lr-wpan-spectrum-value-helper.h" |
26 #include "lr-wpan-error-model.h" | 28 #include "lr-wpan-error-model.h" |
27 #include "lr-wpan-net-device.h" | 29 #include "lr-wpan-net-device.h" |
28 #include <ns3/log.h> | 30 #include <ns3/log.h> |
29 #include <ns3/abort.h> | 31 #include <ns3/abort.h> |
30 #include <ns3/simulator.h> | 32 #include <ns3/simulator.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 MakeTraceSourceAccessor (&LrWpanPhy::m_phyTxDropTrace)) | 92 MakeTraceSourceAccessor (&LrWpanPhy::m_phyTxDropTrace)) |
91 .AddTraceSource ("PhyRxBegin", | 93 .AddTraceSource ("PhyRxBegin", |
92 "Trace source indicating a packet has begun being received
from the channel medium by the device", | 94 "Trace source indicating a packet has begun being received
from the channel medium by the device", |
93 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxBeginTrace)) | 95 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxBeginTrace)) |
94 .AddTraceSource ("PhyRxEnd", | 96 .AddTraceSource ("PhyRxEnd", |
95 "Trace source indicating a packet has been completely recei
ved from the channel medium by the device", | 97 "Trace source indicating a packet has been completely recei
ved from the channel medium by the device", |
96 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxEndTrace)) | 98 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxEndTrace)) |
97 .AddTraceSource ("PhyRxDrop", | 99 .AddTraceSource ("PhyRxDrop", |
98 "Trace source indicating a packet has been dropped by the d
evice during reception", | 100 "Trace source indicating a packet has been dropped by the d
evice during reception", |
99 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxDropTrace)) | 101 MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxDropTrace)) |
| 102 .AddTraceSource ("PhyLinkInformation", |
| 103 "Received Power", |
| 104 MakeTraceSourceAccessor (&LrWpanPhy::m_phyLinkInformation)) |
100 ; | 105 ; |
101 return tid; | 106 return tid; |
102 } | 107 } |
103 | 108 |
104 LrWpanPhy::LrWpanPhy (void) | 109 LrWpanPhy::LrWpanPhy (void) |
105 : m_edRequest (), | 110 : m_edRequest (), |
106 m_setTRXState () | 111 m_setTRXState () |
107 { | 112 { |
108 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; | 113 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; |
109 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; | 114 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; |
110 | 115 |
111 // default PHY PIB attributes | 116 // default PHY PIB attributes |
112 m_phyPIBAttributes.phyCurrentChannel = 11; | 117 m_phyPIBAttributes.phyCurrentChannel = 11; |
113 m_phyPIBAttributes.phyTransmitPower = 0; | 118 m_phyPIBAttributes.phyTransmitPower = 0; |
114 m_phyPIBAttributes.phyCurrentPage = 0; | 119 m_phyPIBAttributes.phyCurrentPage = 0; |
115 for (uint32_t i = 0; i < 32; i++) | 120 for (uint32_t i = 0; i < 32; i++) |
116 { | 121 { |
117 m_phyPIBAttributes.phyChannelsSupported[i] = 0x07ffffff; | 122 m_phyPIBAttributes.phyChannelsSupported[i] = 0x07ffffff; |
118 } | 123 } |
119 m_phyPIBAttributes.phyCCAMode = 1; | 124 m_phyPIBAttributes.phyCCAMode = 1; |
| 125 m_phyPIBAttributes.phyLinkFadingBias = 1; |
120 | 126 |
121 SetMyPhyOption (); | 127 SetMyPhyOption (); |
122 | 128 |
123 m_edPower.averagePower = 0.0; | 129 m_edPower.averagePower = 0.0; |
124 m_edPower.lastUpdate = Seconds (0.0); | 130 m_edPower.lastUpdate = Seconds (0.0); |
125 m_edPower.measurementLength = Seconds (0.0); | 131 m_edPower.measurementLength = Seconds (0.0); |
126 | 132 |
127 // default -110 dBm in W for 2.4 GHz | 133 // default -110 dBm in W for 2.4 GHz |
128 m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0; | 134 m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0; |
| 135 // default -95 dBm in W for 2.4 GHz |
| 136 //m_rxSensitivity = pow (10.0, -95 / 10.0) / 1000.0; |
129 LrWpanSpectrumValueHelper psdHelper; | 137 LrWpanSpectrumValueHelper psdHelper; |
130 m_txPsd = psdHelper.CreateTxPowerSpectralDensity (m_phyPIBAttributes.phyTransm
itPower, | 138 m_txPsd = psdHelper.CreateTxPowerSpectralDensity (m_phyPIBAttributes.phyTransm
itPower, |
131 m_phyPIBAttributes.phyCurren
tChannel); | 139 m_phyPIBAttributes.phyCurren
tChannel); |
132 m_noise = psdHelper.CreateNoisePowerSpectralDensity (m_phyPIBAttributes.phyCur
rentChannel); | 140 m_noise = psdHelper.CreateNoisePowerSpectralDensity (m_phyPIBAttributes.phyCur
rentChannel); |
133 m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ()); | 141 m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ()); |
134 m_rxLastUpdate = Seconds (0); | 142 m_rxLastUpdate = Seconds (0); |
| 143 m_currentPacketRxStart = Seconds (0); |
135 Ptr<Packet> none_packet = 0; | 144 Ptr<Packet> none_packet = 0; |
136 Ptr<LrWpanSpectrumSignalParameters> none_params = 0; | 145 Ptr<LrWpanSpectrumSignalParameters> none_params = 0; |
137 m_currentRxPacket = std::make_pair (none_params, true); | 146 m_currentRxPacket = std::make_pair (none_params, true); |
138 m_currentTxPacket = std::make_pair (none_packet, true); | 147 m_currentTxPacket = std::make_pair (none_packet, true); |
139 m_errorModel = 0; | 148 m_errorModel = 0; |
140 | 149 |
141 m_random = CreateObject<UniformRandomVariable> (); | 150 m_random = CreateObject<UniformRandomVariable> (); |
142 m_random->SetAttribute ("Min", DoubleValue (0.0)); | 151 m_random->SetAttribute ("Min", DoubleValue (0.0)); |
143 m_random->SetAttribute ("Max", DoubleValue (1.0)); | 152 m_random->SetAttribute ("Max", DoubleValue (1.0)); |
144 | 153 |
145 | 154 |
| 155 m_randomdatalength = CreateObject<UniformRandomVariable> (); |
| 156 m_randomdatalength->SetAttribute ("Min", DoubleValue (0.0)); |
| 157 m_randomdatalength->SetAttribute ("Max", DoubleValue (127.0)); |
146 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); | 158 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); |
| 159 m_receivedPower = 0; |
147 } | 160 } |
148 | 161 |
149 LrWpanPhy::~LrWpanPhy (void) | 162 LrWpanPhy::~LrWpanPhy (void) |
150 { | 163 { |
151 } | 164 } |
152 | 165 |
153 void | 166 void |
154 LrWpanPhy::DoDispose (void) | 167 LrWpanPhy::DoDispose (void) |
155 { | 168 { |
156 NS_LOG_FUNCTION (this); | 169 NS_LOG_FUNCTION (this); |
157 | 170 |
158 // Cancel pending transceiver state change, if one is in progress. | 171 // Cancel pending transceiver state change, if one is in progress. |
159 m_setTRXState.Cancel (); | 172 m_setTRXState.Cancel (); |
160 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; | 173 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; |
161 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; | 174 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; |
162 | 175 |
163 m_mobility = 0; | 176 m_mobility = 0; |
164 m_device = 0; | 177 m_device = 0; |
165 m_channel = 0; | 178 m_channel = 0; |
166 m_txPsd = 0; | 179 m_txPsd = 0; |
167 m_noise = 0; | 180 m_noise = 0; |
168 m_signal = 0; | 181 m_signal = 0; |
169 m_errorModel = 0; | 182 m_errorModel = 0; |
| 183 m_receivedPower = 0; |
170 m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, ui
nt8_t > (); | 184 m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, ui
nt8_t > (); |
171 m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > (); | 185 m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > (); |
172 m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > (); | 186 m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > (); |
173 m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t
> (); | 187 m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t
> (); |
174 m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumerati
on, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > (); | 188 m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumerati
on, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > (); |
175 m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeratio
n > (); | 189 m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeratio
n > (); |
176 m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumerati
on, LrWpanPibAttributeIdentifier > (); | 190 m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumerati
on, LrWpanPibAttributeIdentifier > (); |
177 | 191 |
178 SpectrumPhy::DoDispose (); | 192 SpectrumPhy::DoDispose (); |
179 } | 193 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 269 } |
256 | 270 |
257 void | 271 void |
258 LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams) | 272 LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams) |
259 { | 273 { |
260 NS_LOG_FUNCTION (this << spectrumRxParams); | 274 NS_LOG_FUNCTION (this << spectrumRxParams); |
261 LrWpanSpectrumValueHelper psdHelper; | 275 LrWpanSpectrumValueHelper psdHelper; |
262 | 276 |
263 | 277 |
264 Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectru
mSignalParameters> (spectrumRxParams); | 278 Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectru
mSignalParameters> (spectrumRxParams); |
265 NS_ASSERT (lrWpanRxParams != 0); | 279 |
266 Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front (); | 280 //It should also consider non lr-wpan signals, as interference |
267 NS_ASSERT (p != 0); | 281 //NS_ASSERT (lrWpanRxParams != 0); |
| 282 Ptr<Packet> p; |
| 283 if (lrWpanRxParams != 0) |
| 284 { |
| 285 p = (lrWpanRxParams->packetBurst->GetPackets ()).front (); |
| 286 NS_ASSERT (p != 0); |
| 287 } |
| 288 |
268 | 289 |
269 if (!m_edRequest.IsExpired ()) | 290 if (!m_edRequest.IsExpired ()) |
270 { | 291 { |
271 // Update the average receive power during ED. | 292 // Update the average receive power during ED. Time now = Simulator::Now (
); |
272 Time now = Simulator::Now (); | 293 Time now = Simulator::Now (); |
273 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_sign
al->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.m
easurementLength.GetTimeStep (); | 294 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_sign
al->GetSignalPsd (),m_phyPIBAttributes.phyCurrentChannel) |
| 295 * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementL
ength.GetTimeStep () * m_phyPIBAttributes.phyLinkFadingBias; |
274 m_edPower.lastUpdate = now; | 296 m_edPower.lastUpdate = now; |
275 } | 297 } |
276 | 298 |
277 // Prevent PHY from receiving another packet while switching the transceiver s
tate. | 299 // Prevent PHY from receiving another packet while switching the transceiver s
tate. |
278 if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ()) | 300 if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning () && lr
WpanRxParams != 0) |
279 { | 301 { |
280 // The specification doesn't seem to refer to BUSY_RX, but vendor | 302 // The specification doesn't seem to refer to BUSY_RX, but vendor |
281 // data sheets suggest that this is a substate of the RX_ON state | 303 // data sheets suggest that this is a substate of the RX_ON state |
282 // that is entered after preamble detection when the digital receiver | 304 // that is entered after preamble detection when the digital receiver |
283 // is enabled. Here, for now, we use BUSY_RX to mark the period between | 305 // is enabled. Here, for now, we use BUSY_RX to mark the period between |
284 // StartRx() and EndRx() states. | 306 // StartRx() and EndRx() states. |
285 | 307 |
286 // We are going to BUSY_RX state when receiving the first bit of an SHR, | 308 // We are going to BUSY_RX state when receiving the first bit of an SHR, |
287 // as opposed to real receivers, which should go to this state only after | 309 // as opposed to real receivers, which should go to this state only after |
288 // successfully receiving the SHR. | 310 // successfully receiving the SHR. |
289 | 311 |
290 // If synchronizing to the packet is possible, change to BUSY_RX state, | 312 // If synchronizing to the packet is possible, change to BUSY_RX state, |
291 // otherwise drop the packet and stay in RX state. The actual synchronizat
ion | 313 // otherwise drop the packet and stay in RX state. The actual synchronizat
ion |
292 // is not modeled. | 314 // is not modeled. |
293 | 315 |
294 // Add any incoming packet to the current interference before checking the | 316 // Add any incoming packet to the current interference before checking the |
295 // SINR. | 317 // SINR. |
296 NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpa
nSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd)) + 30 << "dBm"); | 318 m_receivedPower = 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrW
panRxParams->psd,m_phyPIBAttributes.phyCurrentChannel) |
| 319 * m_phyPIBAttributes.phyLinkFadingBias) + 30; |
| 320 |
| 321 NS_LOG_DEBUG (this << " receiving packet with power: " << m_receivedPower
<< "dBm"); |
| 322 |
297 m_signal->AddSignal (lrWpanRxParams->psd); | 323 m_signal->AddSignal (lrWpanRxParams->psd); |
298 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd (); | 324 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd (); |
299 *interferenceAndNoise -= *lrWpanRxParams->psd; | 325 *interferenceAndNoise -= *lrWpanRxParams->psd; |
300 *interferenceAndNoise += *m_noise; | 326 *interferenceAndNoise += *m_noise; |
301 double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->ps
d) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise); | |
302 | 327 |
303 // Std. 802.15.4-2006, appendix E, Figure E.2 | 328 //double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->
psd,m_phyPIBAttributes.phyCurrentChannel) |
304 // At SNR < -5 the BER is less than 10e-1. | 329 // / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise,m_phyP
IBAttributes.phyCurrentChannel); |
305 // It's useless to even *try* to decode the packet. | 330 double LrWpanSignalPower = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpa
nRxParams->psd,m_phyPIBAttributes.phyCurrentChannel) |
306 if (10 * log10 (sinr) > -5) | 331 *m_phyPIBAttributes.phyLinkFadingBias; |
| 332 |
| 333 m_phyLinkInformation(10*log10(LrWpanSignalPower)+30); |
| 334 |
| 335 if (LrWpanSignalPower >= m_rxSensitivity) |
307 { | 336 { |
308 ChangeTrxState (IEEE_802_15_4_PHY_BUSY_RX); | 337 ChangeTrxState (IEEE_802_15_4_PHY_BUSY_RX); |
309 m_currentRxPacket = std::make_pair (lrWpanRxParams, false); | 338 m_currentRxPacket = std::make_pair (lrWpanRxParams, false); |
| 339 m_phyRxBeginTrace (p); |
| 340 m_currentPacketRxStart = Simulator::Now(); |
| 341 m_rxLastUpdate = Simulator::Now (); |
| 342 } |
| 343 else |
| 344 { |
| 345 NS_LOG_DEBUG("Packet discarded due to low energy: " << LrWpanSignalPow
er); |
| 346 m_phyRxDropTrace (p); |
| 347 } |
| 348 |
| 349 /// Std. 802.15.4-2006, appendix E, Figure E.2 |
| 350 // At SNR < -5 the BER is less than 10e-1. |
| 351 // It's useless to even *try* to decode the packet. |
| 352 /*if (10 * log10 (sinr) > -5) |
| 353 { |
| 354 ChangeTrxState (IEEE_802_15_4_PHY_BUSY_RX); |
| 355 m_currentRxPacket = std::make_pair (lrWpanRxParams, false); |
310 m_phyRxBeginTrace (p); | 356 m_phyRxBeginTrace (p); |
311 | 357 |
312 m_rxLastUpdate = Simulator::Now (); | 358 m_rxLastUpdate = Simulator::Now (); |
313 } | 359 } |
314 else | 360 else |
315 { | 361 { |
| 362 NS_LOG_DEBUG("Packet discarded due to low SINR: " << sinr); |
316 m_phyRxDropTrace (p); | 363 m_phyRxDropTrace (p); |
317 } | 364 }*/ |
318 } | 365 } |
319 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) | 366 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX && lrWpanRxParams != 0) |
320 { | 367 { |
321 // Drop the new packet. | 368 // Drop the new packet. |
322 NS_LOG_DEBUG (this << " packet collision"); | 369 NS_LOG_DEBUG (this << " packet collision"); |
323 m_phyRxDropTrace (p); | 370 m_phyRxDropTrace (p); |
324 | 371 |
325 // Check if we correctly received the old packet up to now. | 372 // Check if we correctly received the old packet up to now. |
326 CheckInterference (); | 373 CheckInterference (IEEE_802_15_4_PPDU_PAYLOAD, lrWpanRxParams); |
327 | 374 |
328 // Add the incoming packet to the current interference after we have | 375 // Add the incoming signal to the current interference after we have |
329 // checked for successfull reception of the current packet for the time | 376 // checked for successfull reception of the current packet for the time |
330 // before the additional interference. | 377 // before the additional interference. |
331 m_signal->AddSignal (lrWpanRxParams->psd); | 378 m_signal->AddSignal (lrWpanRxParams->psd); |
332 } | 379 } |
| 380 else if (lrWpanRxParams == 0) |
| 381 { |
| 382 if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) |
| 383 { |
| 384 CheckInterference (IEEE_802_15_4_PPDU_PAYLOAD, lrWpanRxParams); |
| 385 NS_LOG_DEBUG("Wifi Coming"); |
| 386 NS_LOG_DEBUG("Wifi Signal duration: " << (spectrumRxParams->duration).
GetSeconds()); |
| 387 } |
| 388 |
| 389 m_signal->AddSignal (spectrumRxParams->psd); |
| 390 } |
333 else | 391 else |
334 { | 392 { |
335 // Simply drop the packet. | 393 // Simply drop the packet. |
336 NS_LOG_DEBUG (this << " transceiver not in RX state"); | 394 NS_LOG_DEBUG (this << " transceiver not in RX state"); |
337 m_phyRxDropTrace (p); | 395 m_phyRxDropTrace (p); |
338 | 396 |
339 // Add the signal power to the interference, anyway. | 397 // Add the signal power to the interference, anyway. |
340 m_signal->AddSignal (lrWpanRxParams->psd); | 398 m_signal->AddSignal (lrWpanRxParams->psd); |
341 } | 399 } |
342 | 400 |
343 // Update peak power if CCA is in progress. | 401 // Update peak power if CCA is in progress. |
344 if (!m_ccaRequest.IsExpired ()) | 402 if (!m_ccaRequest.IsExpired ()) |
345 { | 403 { |
346 double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSign
alPsd ()); | 404 double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSign
alPsd (),m_phyPIBAttributes.phyCurrentChannel); |
347 if (m_ccaPeakPower < power) | 405 if (m_ccaPeakPower < power) |
348 { | 406 { |
349 m_ccaPeakPower = power; | 407 m_ccaPeakPower = power; |
350 } | 408 } |
351 } | 409 } |
352 | 410 |
353 // Always call EndRx to update the interference. | 411 // Always call EndRx to update the interference. |
354 // \todo: Do we need to keep track of these events to unschedule them when dis
posing off the PHY? | 412 NS_LOG_DEBUG("Signal duration: " << (spectrumRxParams->duration).GetSeconds())
; |
355 Simulator::Schedule (lrWpanRxParams->duration, &LrWpanPhy::EndRx, this, lrWpan
RxParams); | 413 |
| 414 if(lrWpanRxParams) |
| 415 { |
| 416 m_endRx = Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::End
Rx, this, lrWpanRxParams); |
| 417 Simulator::Schedule (GetSHRTxTime (), &LrWpanPhy::CheckInterference, this,
IEEE_802_15_4_PPDU_SHR, lrWpanRxParams); |
| 418 //NS_LOG_DEBUG("Preamble duration: " << LrWpanPhy::GetSHRTxTime ()); |
| 419 |
| 420 Simulator::Schedule (GetPpduHeaderTxTime (), &LrWpanPhy::CheckInterference
, this, IEEE_802_15_4_PPDU_PHR, lrWpanRxParams); |
| 421 //NS_LOG_DEBUG("Length and Preamble duration: " << LrWpanPhy::GetPpduHeade
rTxTime ()); |
| 422 } |
| 423 else |
| 424 Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this,
lrWpanRxParams); |
| 425 |
356 } | 426 } |
357 | 427 |
358 void | 428 void |
359 LrWpanPhy::CheckInterference (void) | 429 LrWpanPhy::CheckInterference (LrWpanPPDU packetType, Ptr<LrWpanSpectrumSignalPar
ameters> spectrumRxParams) |
360 { | 430 { |
| 431 NS_LOG_FUNCTION (this); |
| 432 NS_LOG_DEBUG("Interference time classification is " << packetType); |
| 433 //NS_LOG_DEBUG("Current state is " << m_trxState); |
361 // Calculate whether packet was lost. | 434 // Calculate whether packet was lost. |
362 LrWpanSpectrumValueHelper psdHelper; | |
363 Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first; | |
364 | 435 |
365 // We are currently receiving a packet. | 436 // We are currently receiving a packet. |
366 if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) | 437 if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) |
367 { | 438 { |
368 // NS_ASSERT (currentRxParams && !m_currentRxPacket.second); | 439 Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.fi
rst; |
| 440 if (currentRxParams && !m_currentRxPacket.second) |
| 441 { |
| 442 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets (
).front (); |
| 443 if (m_errorModel != 0) |
| 444 { |
| 445 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd (
); |
| 446 *interferenceAndNoise -= *currentRxParams->psd; |
| 447 *interferenceAndNoise += *m_noise; |
| 448 double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxP
arams->psd,m_phyPIBAttributes.phyCurrentChannel) |
| 449 * m_phyPIBAttributes.phyLinkFadingBias |
| 450 / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoi
se,m_phyPIBAttributes.phyCurrentChannel); |
369 | 451 |
370 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().fr
ont (); | 452 // How many bits did we receive since the last calculation? |
371 if (m_errorModel != 0) | 453 double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::
MS); |
372 { | 454 uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 100
0)); |
373 // How many bits did we receive since the last calculation? | |
374 double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS); | |
375 uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000)); | |
376 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd (); | |
377 *interferenceAndNoise -= *currentRxParams->psd; | |
378 *interferenceAndNoise += *m_noise; | |
379 double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParam
s->psd) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise); | |
380 double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize)
; | |
381 | 455 |
382 // The LQI is the total packet success rate scaled to 0-255. | 456 double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chun
kSize); |
383 // If not already set, initialize to 255. | |
384 LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ()); | |
385 currentPacket->PeekPacketTag (tag); | |
386 uint8_t lqi = tag.Get (); | |
387 tag.Set (lqi - (per * lqi)); | |
388 currentPacket->ReplacePacketTag (tag); | |
389 | 457 |
390 if (m_random->GetValue () < per) | 458 // The LQI is the total packet success rate scaled to 0-255. |
| 459 // If not already set, initialize to 255. |
| 460 LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ()); |
| 461 currentPacket->PeekPacketTag (tag); |
| 462 uint8_t lqi = tag.Get (); |
| 463 tag.Set (lqi - (per * lqi)); |
| 464 currentPacket->ReplacePacketTag (tag); |
| 465 |
| 466 NS_LOG_DEBUG (this << " Signal power: " |
| 467 << 10 * log10(LrWpanSpectrumValueHelper::TotalAv
gPower (currentRxParams->psd,m_phyPIBAttributes.phyCurrentChannel)) + 30 |
| 468 << "dBm"); |
| 469 NS_LOG_DEBUG (this << " Interference power: " |
| 470 << 10 * log10(LrWpanSpectrumValueHelper::TotalAv
gPower (interferenceAndNoise,m_phyPIBAttributes.phyCurrentChannel)) + 30 |
| 471 << "dBm"); |
| 472 NS_LOG_DEBUG (this << " PER: " << per << " SINR: " << sinr); |
| 473 |
| 474 double randomValue = m_random->GetValue(); |
| 475 NS_LOG_DEBUG (this << " Radom value for per is "<< randomValue); |
| 476 |
| 477 if (randomValue < per) |
| 478 { |
| 479 if (packetType == IEEE_802_15_4_PPDU_PAYLOAD) |
| 480 { |
| 481 m_currentRxPacket.second = true; |
| 482 NS_LOG_DEBUG (this << " Packet will be dropped after receiv
ing due to wrong payload"); |
| 483 } |
| 484 |
| 485 else if(packetType == IEEE_802_15_4_PPDU_SHR) |
| 486 { |
| 487 Ptr<LrWpanSpectrumSignalParameters> none = 0; |
| 488 m_currentRxPacket = std::make_pair (none, true); |
| 489 ChangeTrxState (IEEE_802_15_4_PHY_RX_ON); |
| 490 NS_LOG_DEBUG (this << " Packet dropped due to wrong rece
ived preamble"); |
| 491 } |
| 492 |
| 493 else if(packetType == IEEE_802_15_4_PPDU_PHR) |
| 494 { |
| 495 uint32_t payloadLengthSet = ceil(m_randomdatalength->GetV
alue()); |
| 496 NS_LOG_DEBUG (this << " Radom value for datalength is "<<
payloadLengthSet); |
| 497 Ptr<Packet> packetCorrect = m_currentRxPacket.first->pack
etBurst->GetPackets().front(); |
| 498 uint32_t payloadLengthCorrect = packetCorrect->GetSize(); |
| 499 |
| 500 NS_LOG_DEBUG (this << " Correct Packet Size: " << payload
LengthCorrect << " with duration: " << m_currentRxPacket.first->duration); |
| 501 m_currentRxPacket.first -> duration = (m_currentRxPacket.
first->duration-GetPpduHeaderTxTime ())* payloadLengthSet/payloadLengthCorrect; |
| 502 NS_LOG_DEBUG (this << " Reseted Packet Size: " << payload
LengthSet << " with duration: " << m_currentRxPacket.first->duration); |
| 503 |
| 504 if (payloadLengthSet > payloadLengthCorrect) |
| 505 { |
| 506 NS_LOG_DEBUG (this << " Packet receiving energy waste
d due to wrong received datalength"); |
| 507 } |
| 508 else if (payloadLengthSet < payloadLengthCorrect) |
| 509 { |
| 510 m_currentRxPacket.first->packetBurst->GetPackets().fr
ont() = Create<Packet> (payloadLengthSet); |
| 511 NS_LOG_DEBUG (this << " Packet is cutted and will be
discarded at MAC due to wrong received datalength"); |
| 512 } |
| 513 else |
| 514 { |
| 515 NS_LOG_DEBUG (this << " Packet is received without ef
fect of wrong received datalength"); |
| 516 } |
| 517 |
| 518 spectrumRxParams->duration = m_currentRxPacket.first->dur
ation; |
| 519 m_endRx.Cancel (); |
| 520 spectrumRxParams = DynamicCast<LrWpanSpectrumSignalParame
ters>(m_currentRxPacket.first); |
| 521 Simulator::Schedule (spectrumRxParams->duration, &LrWpanP
hy::EndRx, this, spectrumRxParams); |
| 522 |
| 523 } |
| 524 } |
| 525 } |
| 526 else |
391 { | 527 { |
392 // The packet was destroyed, drop the packet after reception. | 528 NS_LOG_WARN ("Missing ErrorModel"); |
393 m_currentRxPacket.second = true; | |
394 } | 529 } |
395 } | 530 } |
396 else | 531 else |
397 { | 532 NS_LOG_DEBUG (this << " No Effective Receiving Packet"); |
398 NS_LOG_WARN ("Missing ErrorModel"); | |
399 } | |
400 } | 533 } |
401 m_rxLastUpdate = Simulator::Now (); | 534 m_rxLastUpdate = Simulator::Now (); |
402 } | 535 } |
403 | 536 |
404 void | 537 void |
405 LrWpanPhy::EndRx (Ptr<LrWpanSpectrumSignalParameters> params) | 538 LrWpanPhy::EndRx (Ptr<LrWpanSpectrumSignalParameters> spectrumRxParams) |
406 { | 539 { |
407 NS_LOG_FUNCTION (this); | 540 NS_LOG_FUNCTION (this); |
408 NS_ASSERT (params != 0); | 541 NS_ASSERT (spectrumRxParams != 0); |
| 542 |
| 543 Time now = Simulator::Now (); |
| 544 |
409 | 545 |
410 if (!m_edRequest.IsExpired ()) | 546 if (!m_edRequest.IsExpired ()) |
411 { | 547 { |
412 // Update the average receive power during ED. | 548 // Update the average receive power during ED. |
413 Time now = Simulator::Now (); | 549 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_sign
al->GetSignalPsd (),m_phyPIBAttributes.phyCurrentChannel) |
414 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_sign
al->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.m
easurementLength.GetTimeStep (); | 550 * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementL
ength.GetTimeStep (); |
415 m_edPower.lastUpdate = now; | 551 m_edPower.lastUpdate = now; |
416 } | 552 } |
417 | 553 |
418 CheckInterference (); | 554 Time diffTime = now - m_currentPacketRxStart; |
| 555 NS_LOG_DEBUG (this << " Current time difference from transmission start is: "
<< Seconds(diffTime)); |
| 556 NS_ASSERT (diffTime >= 0); |
| 557 |
| 558 if (diffTime >= 0 && diffTime < GetSHRTxTime ()) |
| 559 { |
| 560 CheckInterference (IEEE_802_15_4_PPDU_SHR, spectrumRxParams); |
| 561 } |
| 562 else if (diffTime >= GetSHRTxTime () && diffTime < GetPpduHeaderTxTime()) |
| 563 { |
| 564 CheckInterference (IEEE_802_15_4_PPDU_PHR, spectrumRxParams); |
| 565 } |
| 566 else |
| 567 { |
| 568 CheckInterference (IEEE_802_15_4_PPDU_PAYLOAD, spectrumRxParams); |
| 569 } |
419 | 570 |
420 // Update the interference. | 571 // Update the interference. |
421 m_signal->RemoveSignal (params->psd); | 572 m_signal->RemoveSignal (spectrumRxParams->psd); |
| 573 |
| 574 Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalP
arameters> (spectrumRxParams); |
| 575 |
| 576 //Not lr-wpan signal |
| 577 if (params == 0) |
| 578 { |
| 579 return; |
| 580 } |
422 | 581 |
423 // If this is the end of the currently received packet, check if reception was
successfull. | 582 // If this is the end of the currently received packet, check if reception was
successfull. |
424 Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first; | 583 Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first; |
425 if (currentRxParams == params) | 584 if (currentRxParams == params) |
426 { | 585 { |
427 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().fr
ont (); | 586 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().fr
ont (); |
428 NS_ASSERT (currentPacket != 0); | 587 NS_ASSERT (currentPacket != 0); |
429 | 588 |
430 // If there is no error model attached to the PHY, we always report the ma
ximum LQI value. | 589 // If there is no error model attached to the PHY, we always report the ma
ximum LQI value. |
431 LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ()); | 590 LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // Section 6.2.2.7.3 | 795 // Section 6.2.2.7.3 |
637 void | 796 void |
638 LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state) | 797 LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state) |
639 { | 798 { |
640 NS_LOG_FUNCTION (this << state); | 799 NS_LOG_FUNCTION (this << state); |
641 | 800 |
642 // Check valid states (Table 14) | 801 // Check valid states (Table 14) |
643 NS_ABORT_IF ( (state != IEEE_802_15_4_PHY_RX_ON) | 802 NS_ABORT_IF ( (state != IEEE_802_15_4_PHY_RX_ON) |
644 && (state != IEEE_802_15_4_PHY_TRX_OFF) | 803 && (state != IEEE_802_15_4_PHY_TRX_OFF) |
645 && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF) | 804 && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF) |
646 && (state != IEEE_802_15_4_PHY_TX_ON) ); | 805 && (state != IEEE_802_15_4_PHY_TX_ON) |
| 806 && (state != IEEE_802_15_4_PHY_TRX_START) |
| 807 && (state != IEEE_802_15_4_PHY_TRX_SWITCHING)); |
647 | 808 |
648 NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << stat
e); | 809 NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << stat
e); |
649 // this method always overrides previous state setting attempts | 810 // this method always overrides previous state setting attempts |
650 if (!m_setTRXState.IsExpired ()) | 811 if (!m_setTRXState.IsExpired ()) |
651 { | 812 { |
652 if (m_trxStatePending == state) | 813 if (m_trxStatePending == state) |
653 { | 814 { |
654 // Simply wait for the ongoing state switch. | 815 // Simply wait for the ongoing state switch. |
655 return; | 816 return; |
656 } | 817 } |
657 else | 818 else |
658 { | 819 { |
659 NS_LOG_DEBUG ("Cancel m_setTRXState"); | 820 NS_LOG_DEBUG ("Cancel m_setTRXState"); |
660 // Keep the transceiver state as the old state before the switching at
tempt. | 821 // Keep the transceiver state as the old state before the switching at
tempt. |
661 m_setTRXState.Cancel (); | 822 m_setTRXState.Cancel (); |
662 } | 823 } |
663 } | 824 } |
| 825 |
| 826 if (m_trxState == IEEE_802_15_4_PHY_FORCE_TRX_OFF) |
| 827 { |
| 828 NS_LOG_DEBUG ("Transceiver is already forced off, can not do anything!"); |
| 829 return; |
| 830 } |
| 831 |
664 if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE) | 832 if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE) |
665 { | 833 { |
666 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; | 834 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; |
667 } | 835 } |
668 | 836 |
669 if (state == m_trxState) | 837 if (state == m_trxState) |
670 { | 838 { |
671 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 839 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
672 { | 840 { |
673 m_plmeSetTRXStateConfirmCallback (state); | 841 m_plmeSetTRXStateConfirmCallback (state); |
674 } | 842 } |
675 return; | 843 return; |
676 } | 844 } |
677 | 845 |
678 if ( ((state == IEEE_802_15_4_PHY_RX_ON) | 846 if ( ((state == IEEE_802_15_4_PHY_RX_ON) |
679 || (state == IEEE_802_15_4_PHY_TRX_OFF)) | 847 || (state == IEEE_802_15_4_PHY_TRX_OFF) |
| 848 || (state == IEEE_802_15_4_PHY_TRX_START) |
| 849 || (state == IEEE_802_15_4_PHY_TRX_SWITCHING)) |
680 && (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) ) | 850 && (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) ) |
681 { | 851 { |
682 NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state); | 852 NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state); |
683 m_trxStatePending = state; | 853 m_trxStatePending = state; |
684 return; // Send PlmeSetTRXStateConfirm later | 854 return; // Send PlmeSetTRXStateConfirm later |
685 } | 855 } |
686 | 856 |
687 // specification talks about being in RX_ON and having received | 857 // specification talks about being in RX_ON and having received |
688 // a valid SFD. Here, we are not modelling at that level of | 858 // a valid SFD. Here, we are not modelling at that level of |
689 // granularity, so we just test for BUSY_RX state (any part of | 859 // granularity, so we just test for BUSY_RX state (any part of |
690 // a packet being actively received) | 860 // a packet being actively received) |
691 if (state == IEEE_802_15_4_PHY_TRX_OFF) | 861 if (state == IEEE_802_15_4_PHY_TRX_OFF) |
692 { | 862 { |
693 CancelEd (state); | 863 CancelEd (state); |
694 | 864 |
695 if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX) | 865 if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX) && (m_currentRxPacket.first)
) |
696 && (m_currentRxPacket.first) && (!m_currentRxPacket.second)) | |
697 { | 866 { |
698 NS_LOG_DEBUG ("Receiver has valid SFD; defer state change"); | 867 NS_LOG_DEBUG ("Receiver has valid SFD; defer state change"); |
699 m_trxStatePending = state; | 868 m_trxStatePending = state; |
700 return; // Send PlmeSetTRXStateConfirm later | 869 return; // Send PlmeSetTRXStateConfirm later |
701 } | 870 } |
702 else if (m_trxState == IEEE_802_15_4_PHY_RX_ON || m_trxState == IEEE_802_1
5_4_PHY_TX_ON) | 871 else if (m_trxState == IEEE_802_15_4_PHY_RX_ON || m_trxState == IEEE_802_1
5_4_PHY_TX_ON |
| 872 || m_trxState == IEEE_802_15_4_PHY_TRX_SWITCHING || m_trxState ==
IEEE_802_15_4_PHY_TRX_START) |
703 { | 873 { |
704 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); | 874 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); |
705 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 875 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
706 { | 876 { |
707 m_plmeSetTRXStateConfirmCallback (state); | 877 m_plmeSetTRXStateConfirmCallback (state); |
708 } | 878 } |
709 return; | 879 return; |
710 } | 880 } |
711 } | 881 } |
712 | 882 |
| 883 if (state == IEEE_802_15_4_PHY_TRX_SWITCHING) |
| 884 { |
| 885 |
| 886 ChangeTrxState (IEEE_802_15_4_PHY_TRX_SWITCHING); |
| 887 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
| 888 { |
| 889 m_plmeSetTRXStateConfirmCallback (state); |
| 890 } |
| 891 return; |
| 892 } |
| 893 |
| 894 if (state == IEEE_802_15_4_PHY_TRX_START) |
| 895 { |
| 896 |
| 897 ChangeTrxState (IEEE_802_15_4_PHY_TRX_START); |
| 898 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
| 899 { |
| 900 m_plmeSetTRXStateConfirmCallback (state); |
| 901 } |
| 902 return; |
| 903 } |
| 904 |
713 if (state == IEEE_802_15_4_PHY_TX_ON) | 905 if (state == IEEE_802_15_4_PHY_TX_ON) |
714 { | 906 { |
715 CancelEd (state); | 907 CancelEd (state); |
716 | 908 |
717 NS_LOG_DEBUG ("turn on PHY_TX_ON"); | 909 NS_LOG_DEBUG ("turn on PHY_TX_ON"); |
718 if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX) || (m_trxState == IEEE_802_1
5_4_PHY_RX_ON)) | 910 if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX) || (m_trxState == IEEE_802_1
5_4_PHY_RX_ON)) |
719 { | 911 { |
720 if (m_currentRxPacket.first) | 912 if (m_currentRxPacket.first) |
721 { | 913 { |
722 //terminate reception if needed | 914 //terminate reception if needed |
723 //incomplete reception -- force packet discard | 915 //incomplete reception -- force packet discard |
724 NS_LOG_DEBUG ("force TX_ON, terminate reception"); | 916 NS_LOG_DEBUG ("force TX_ON, terminate reception"); |
725 m_currentRxPacket.second = true; | 917 m_currentRxPacket.second = true; |
726 } | 918 } |
727 | 919 |
728 // If CCA is in progress, cancel CCA and return BUSY. | 920 // If CCA is in progress, cancel CCA and return BUSY. |
729 if (!m_ccaRequest.IsExpired ()) | 921 if (!m_ccaRequest.IsExpired ()) |
730 { | 922 { |
731 m_ccaRequest.Cancel (); | 923 m_ccaRequest.Cancel (); |
732 if (!m_plmeCcaConfirmCallback.IsNull ()) | 924 if (!m_plmeCcaConfirmCallback.IsNull ()) |
733 { | 925 { |
734 m_plmeCcaConfirmCallback (IEEE_802_15_4_PHY_BUSY); | 926 m_plmeCcaConfirmCallback (IEEE_802_15_4_PHY_BUSY); |
735 } | 927 } |
736 } | 928 } |
737 | 929 |
| 930 ChangeTrxState (IEEE_802_15_4_PHY_TRX_SWITCHING); |
| 931 |
738 m_trxStatePending = IEEE_802_15_4_PHY_TX_ON; | 932 m_trxStatePending = IEEE_802_15_4_PHY_TX_ON; |
739 | 933 |
740 // Delay for turnaround time | 934 // Delay for turnaround time |
741 // TODO: Does it also take aTurnaroundTime to switch the transceiver s
tate, | 935 // TODO: Does it also take aTurnaroundTime to switch the transceiver s
tate, |
742 // even when the receiver is not busy? (6.9.2) | 936 // even when the receiver is not busy? (6.9.2) |
743 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRat
e (false)); | 937 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRat
e (false)); |
744 m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXSta
te, this); | 938 m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXSta
te, this); |
745 return; | 939 return; |
746 } | 940 } |
747 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX || m_trxState == IEEE_802
_15_4_PHY_TX_ON) | 941 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX || m_trxState == IEEE_802
_15_4_PHY_TX_ON) |
748 { | 942 { |
749 // We do NOT change the transceiver state here. We only report that | 943 // We do NOT change the transceiver state here. We only report that |
750 // the transceiver is already in TX_ON state. | 944 // the transceiver is already in TX_ON state. |
751 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 945 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
752 { | 946 { |
753 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON); | 947 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON); |
754 } | 948 } |
755 return; | 949 return; |
756 } | 950 } |
757 else if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF) | 951 else if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF || m_trxState == IEEE_802
_15_4_PHY_TRX_SWITCHING |
| 952 || m_trxState == IEEE_802_15_4_PHY_TRX_START) |
758 { | 953 { |
759 ChangeTrxState (IEEE_802_15_4_PHY_TX_ON); | 954 ChangeTrxState (IEEE_802_15_4_PHY_TX_ON); |
760 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 955 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
761 { | 956 { |
762 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON); | 957 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON); |
763 } | 958 } |
764 return; | 959 return; |
765 } | 960 } |
766 } | 961 } |
767 | 962 |
768 if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF) | 963 if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF) |
769 { | 964 { |
770 if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF) | 965 NS_LOG_DEBUG ("force TRX_OFF, SUCCESS"); |
771 { | 966 if (m_currentRxPacket.first) |
772 NS_LOG_DEBUG ("force TRX_OFF, was already off"); | 967 { //terminate reception if needed |
| 968 //incomplete reception -- force packet discard |
| 969 NS_LOG_DEBUG ("force TRX_OFF, terminate reception"); |
| 970 m_currentRxPacket.second = true; |
773 } | 971 } |
774 else | 972 else |
775 { | 973 { |
776 NS_LOG_DEBUG ("force TRX_OFF, SUCCESS"); | 974 NS_LOG_DEBUG ("force TRX_OFF, SUCCESS"); |
777 if (m_currentRxPacket.first) | 975 if (m_currentRxPacket.first) |
778 { //terminate reception if needed | 976 { //terminate reception if needed |
779 //incomplete reception -- force packet discard | 977 //incomplete reception -- force packet discard |
780 NS_LOG_DEBUG ("force TRX_OFF, terminate reception"); | 978 NS_LOG_DEBUG ("force TRX_OFF, terminate reception"); |
781 m_currentRxPacket.second = true; | 979 m_currentRxPacket.second = true; |
782 } | 980 } |
783 if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) | 981 if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) |
784 { | 982 { |
785 NS_LOG_DEBUG ("force TRX_OFF, terminate transmission"); | 983 NS_LOG_DEBUG ("force TRX_OFF, terminate transmission"); |
786 m_currentTxPacket.second = true; | 984 m_currentTxPacket.second = true; |
787 } | 985 } |
788 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); | 986 ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF); |
789 // Clear any other state | 987 // Clear any other state |
790 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; | 988 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; |
791 } | 989 } |
792 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 990 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
793 { | 991 { |
794 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS); | 992 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS); |
795 } | 993 } |
796 return; | 994 return; |
797 } | 995 } |
798 | 996 |
799 if (state == IEEE_802_15_4_PHY_RX_ON) | 997 if (state == IEEE_802_15_4_PHY_RX_ON) |
800 { | 998 { |
801 if (m_trxState == IEEE_802_15_4_PHY_TX_ON || m_trxState == IEEE_802_15_4_P
HY_TRX_OFF) | 999 if (m_trxState == IEEE_802_15_4_PHY_TX_ON) |
802 { | 1000 { |
803 // Turnaround delay | 1001 ChangeTrxState (IEEE_802_15_4_PHY_TRX_SWITCHING); |
804 // TODO: Does it really take aTurnaroundTime to switch the transceiver
state, | |
805 // even when the transmitter is not busy? (6.9.1) | |
806 m_trxStatePending = IEEE_802_15_4_PHY_RX_ON; | 1002 m_trxStatePending = IEEE_802_15_4_PHY_RX_ON; |
807 | 1003 |
| 1004 // Turnaround delay |
| 1005 // DONE: Does it really take aTurnaroundTime to switch the transceiver
state, |
| 1006 // even when the transmitter is not busy? (6.9.1) |
| 1007 // No |
808 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRat
e (false)); | 1008 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRat
e (false)); |
809 m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXSta
te, this); | 1009 m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXSta
te, this); |
810 return; | 1010 return; |
811 } | 1011 } |
| 1012 else if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF || m_trxState == IEEE_802
_15_4_PHY_TRX_SWITCHING |
| 1013 || m_trxState == IEEE_802_15_4_PHY_TRX_START) |
| 1014 { |
| 1015 ChangeTrxState (IEEE_802_15_4_PHY_RX_ON); |
| 1016 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
| 1017 { |
| 1018 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_RX_ON); |
| 1019 } |
| 1020 return; |
| 1021 } |
812 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) | 1022 else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX) |
813 { | 1023 { |
814 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) | 1024 if (!m_plmeSetTRXStateConfirmCallback.IsNull ()) |
815 { | 1025 { |
816 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_RX_ON); | 1026 m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_RX_ON); |
817 } | 1027 } |
818 return; | 1028 return; |
819 } | 1029 } |
820 } | 1030 } |
821 | 1031 |
(...skipping 27 matching lines...) Expand all Loading... |
849 LrWpanPhyEnumeration status = IEEE_802_15_4_PHY_SUCCESS; | 1059 LrWpanPhyEnumeration status = IEEE_802_15_4_PHY_SUCCESS; |
850 | 1060 |
851 switch (id) | 1061 switch (id) |
852 { | 1062 { |
853 case phyCurrentChannel: | 1063 case phyCurrentChannel: |
854 { | 1064 { |
855 if (!ChannelSupported (attribute->phyCurrentChannel)) | 1065 if (!ChannelSupported (attribute->phyCurrentChannel)) |
856 { | 1066 { |
857 status = IEEE_802_15_4_PHY_INVALID_PARAMETER; | 1067 status = IEEE_802_15_4_PHY_INVALID_PARAMETER; |
858 } | 1068 } |
| 1069 |
| 1070 m_phyPIBAttributes.phyLinkFadingBias = attribute->phyLinkFadingBias; |
859 if (m_phyPIBAttributes.phyCurrentChannel != attribute->phyCurrentChannel
) | 1071 if (m_phyPIBAttributes.phyCurrentChannel != attribute->phyCurrentChannel
) |
860 { | 1072 { |
861 // Cancel a pending tranceiver state change. | 1073 // Cancel a pending tranceiver state change. |
862 // Switch off the transceiver. | 1074 // Switch off the transceiver. |
863 // TODO: Is switching off the transceiver the right choice? | 1075 // TODO: Is switching off the transceiver the right choice? |
864 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; | 1076 m_trxState = IEEE_802_15_4_PHY_TRX_OFF; |
865 if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE) | 1077 if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE) |
866 { | 1078 { |
867 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; | 1079 m_trxStatePending = IEEE_802_15_4_PHY_IDLE; |
868 m_setTRXState.Cancel (); | 1080 m_setTRXState.Cancel (); |
(...skipping 12 matching lines...) Expand all Loading... |
881 { | 1093 { |
882 m_currentTxPacket.second = true; | 1094 m_currentTxPacket.second = true; |
883 m_pdDataRequest.Cancel (); | 1095 m_pdDataRequest.Cancel (); |
884 m_currentTxPacket.first = 0; | 1096 m_currentTxPacket.first = 0; |
885 if (!m_pdDataConfirmCallback.IsNull ()) | 1097 if (!m_pdDataConfirmCallback.IsNull ()) |
886 { | 1098 { |
887 m_pdDataConfirmCallback (IEEE_802_15_4_PHY_TRX_OFF); | 1099 m_pdDataConfirmCallback (IEEE_802_15_4_PHY_TRX_OFF); |
888 } | 1100 } |
889 } | 1101 } |
890 m_phyPIBAttributes.phyCurrentChannel = attribute->phyCurrentChannel; | 1102 m_phyPIBAttributes.phyCurrentChannel = attribute->phyCurrentChannel; |
| 1103 |
| 1104 LrWpanSpectrumValueHelper psdHelper; |
| 1105 |
| 1106 SetTxPowerSpectralDensity(psdHelper.CreateTxPowerSpectralDensity (m_
phyPIBAttributes.phyTransmitPower, |
| 1107 m_phyPIBAttributes
.phyCurrentChannel)); |
| 1108 SetNoisePowerSpectralDensity(psdHelper.CreateNoisePowerSpectralDensi
ty (m_phyPIBAttributes.phyCurrentChannel)); |
891 } | 1109 } |
892 break; | 1110 break; |
893 } | 1111 } |
894 case phyChannelsSupported: | 1112 case phyChannelsSupported: |
895 { // only the first element is considered in the array | 1113 { // only the first element is considered in the array |
896 if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0) | 1114 if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0) |
897 { //5 MSBs reserved | 1115 { //5 MSBs reserved |
898 status = IEEE_802_15_4_PHY_INVALID_PARAMETER; | 1116 status = IEEE_802_15_4_PHY_INVALID_PARAMETER; |
899 } | 1117 } |
900 else | 1118 else |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 m_plmeEdConfirmCallback (state, 0); | 1240 m_plmeEdConfirmCallback (state, 0); |
1023 } | 1241 } |
1024 } | 1242 } |
1025 } | 1243 } |
1026 | 1244 |
1027 void | 1245 void |
1028 LrWpanPhy::EndEd (void) | 1246 LrWpanPhy::EndEd (void) |
1029 { | 1247 { |
1030 NS_LOG_FUNCTION (this); | 1248 NS_LOG_FUNCTION (this); |
1031 | 1249 |
1032 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->
GetSignalPsd ()) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m
_edPower.measurementLength.GetTimeStep (); | 1250 m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->
GetSignalPsd (),m_phyPIBAttributes.phyCurrentChannel) |
| 1251 * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.me
asurementLength.GetTimeStep (); |
1033 | 1252 |
1034 uint8_t energyLevel; | 1253 uint8_t energyLevel; |
1035 | 1254 |
1036 // Per IEEE802.15.4-2006 sec 6.9.7 | 1255 // Per IEEE802.15.4-2006 sec 6.9.7 |
1037 double ratio = m_edPower.averagePower / m_rxSensitivity; | 1256 double ratio = m_edPower.averagePower / m_rxSensitivity; |
1038 ratio = 10.0 * log10 (ratio); | 1257 ratio = 10.0 * log10 (ratio); |
1039 if (ratio <= 10.0) | 1258 if (ratio <= 10.0) |
1040 { // less than 10 dB | 1259 { // less than 10 dB |
1041 energyLevel = 0; | 1260 energyLevel = 0; |
1042 } | 1261 } |
(...skipping 13 matching lines...) Expand all Loading... |
1056 } | 1275 } |
1057 } | 1276 } |
1058 | 1277 |
1059 void | 1278 void |
1060 LrWpanPhy::EndCca (void) | 1279 LrWpanPhy::EndCca (void) |
1061 { | 1280 { |
1062 NS_LOG_FUNCTION (this); | 1281 NS_LOG_FUNCTION (this); |
1063 LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED; | 1282 LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED; |
1064 | 1283 |
1065 // Update peak power. | 1284 // Update peak power. |
1066 double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPs
d ()); | 1285 double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPs
d (),m_phyPIBAttributes.phyCurrentChannel); |
1067 if (m_ccaPeakPower < power) | 1286 if (m_ccaPeakPower < power) |
1068 { | 1287 { |
1069 m_ccaPeakPower = power; | 1288 m_ccaPeakPower = power; |
1070 } | 1289 } |
1071 | 1290 |
1072 if (PhyIsBusy ()) | 1291 if (PhyIsBusy ()) |
1073 { | 1292 { |
1074 sensedChannelState = IEEE_802_15_4_PHY_BUSY; | 1293 sensedChannelState = IEEE_802_15_4_PHY_BUSY; |
1075 } | 1294 } |
1076 else if (m_phyPIBAttributes.phyCCAMode == 1) | 1295 else if (m_phyPIBAttributes.phyCCAMode == 1) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 | 1464 |
1246 NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION); | 1465 NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION); |
1247 | 1466 |
1248 totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble | 1467 totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble |
1249 + ppduHeaderSymbolNumbers[m_phyOption].shrSfd | 1468 + ppduHeaderSymbolNumbers[m_phyOption].shrSfd |
1250 + ppduHeaderSymbolNumbers[m_phyOption].phr; | 1469 + ppduHeaderSymbolNumbers[m_phyOption].phr; |
1251 | 1470 |
1252 return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData)); | 1471 return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData)); |
1253 } | 1472 } |
1254 | 1473 |
| 1474 Time |
| 1475 LrWpanPhy::GetSHRTxTime (void) |
| 1476 { |
| 1477 //NS_LOG_FUNCTION (this); |
| 1478 |
| 1479 bool isData = false; |
| 1480 return Seconds (GetPhySHRDuration() / GetDataOrSymbolRate (isData)); |
| 1481 } |
1255 // IEEE802.15.4-2006 Table 2 in section 6.1.2 | 1482 // IEEE802.15.4-2006 Table 2 in section 6.1.2 |
1256 void | 1483 void |
1257 LrWpanPhy::SetMyPhyOption (void) | 1484 LrWpanPhy::SetMyPhyOption (void) |
1258 { | 1485 { |
1259 NS_LOG_FUNCTION (this); | 1486 NS_LOG_FUNCTION (this); |
1260 | 1487 |
1261 m_phyOption = IEEE_802_15_4_INVALID_PHY_OPTION; | 1488 m_phyOption = IEEE_802_15_4_INVALID_PHY_OPTION; |
1262 | 1489 |
1263 if (m_phyPIBAttributes.phyCurrentPage == 0) | 1490 if (m_phyPIBAttributes.phyCurrentPage == 0) |
1264 { | 1491 { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 } | 1593 } |
1367 | 1594 |
1368 int64_t | 1595 int64_t |
1369 LrWpanPhy::AssignStreams (int64_t stream) | 1596 LrWpanPhy::AssignStreams (int64_t stream) |
1370 { | 1597 { |
1371 NS_LOG_FUNCTION (this); | 1598 NS_LOG_FUNCTION (this); |
1372 m_random->SetStream (stream); | 1599 m_random->SetStream (stream); |
1373 return 1; | 1600 return 1; |
1374 } | 1601 } |
1375 | 1602 |
| 1603 |
| 1604 void |
| 1605 LrWpanPhy::HandleEnergyDepletion () |
| 1606 { |
| 1607 NS_LOG_LOGIC ("Transceiver is forced to be Off due to Energy Depletion!"); |
| 1608 PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_FORCE_TRX_OFF); |
| 1609 } |
| 1610 |
1376 } // namespace ns3 | 1611 } // namespace ns3 |
OLD | NEW |