| 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) 2005,2006 INRIA | 3 * Copyright (c) 2005,2006 INRIA |
| 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 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 Ptr<WifiChannel> | 305 Ptr<WifiChannel> |
| 306 YansWifiPhy::GetChannel (void) const | 306 YansWifiPhy::GetChannel (void) const |
| 307 { | 307 { |
| 308 return m_channel; | 308 return m_channel; |
| 309 } | 309 } |
| 310 void | 310 void |
| 311 YansWifiPhy::SetChannel (Ptr<YansWifiChannel> channel) | 311 YansWifiPhy::SetChannel (Ptr<YansWifiChannel> channel) |
| 312 { | 312 { |
| 313 m_channel = channel; | 313 m_channel = channel; |
| 314 m_channel->Add (this); | 314 m_channel->Add (this); |
| 315 m_channelId = 1; // always start on channel starting frequency (channel 1 ) | 315 m_channelNumber = 1; // always start on channel starting frequency (chann el 1) |
| 316 } | 316 } |
| 317 | 317 |
| 318 void | 318 void |
| 319 YansWifiPhy::SetChannelNumber (uint16_t nch) | 319 YansWifiPhy::SetChannelNumber (uint16_t nch) |
| 320 { | 320 { |
| 321 // TODO implement channel switching state machine here | 321 NS_ASSERT(!IsStateSwitching()); |
| 322 DoSetChannelNumber (nch); | 322 switch (m_state->GetState ()) { |
| 323 case YansWifiPhy::SYNC: | |
| 324 NS_LOG_DEBUG ("drop packet because of channel switching while reception"); | |
| 325 m_endSyncEvent.Cancel(); | |
| 326 goto switchChannel; | |
| 327 break; | |
| 328 case YansWifiPhy::TX: | |
| 329 NS_LOG_DEBUG ("channel switching postponed until end of current transmissi on"); | |
| 330 Simulator::Schedule (GetDelayUntilIdle(), &YansWifiPhy::SetChannelNumber, this, nch); | |
| 331 break; | |
| 332 case YansWifiPhy::CCA_BUSY: | |
| 333 case YansWifiPhy::IDLE: | |
| 334 goto switchChannel; | |
| 335 break; | |
| 336 default: | |
| 337 NS_ASSERT (false); | |
| 338 break; | |
| 339 } | |
| 340 | |
| 341 return; | |
| 342 | |
| 343 switchChannel: | |
| 344 | |
| 345 NS_LOG_DEBUG("switching channel " << m_channelNumber << " -> " << nch); | |
| 346 m_state->SwitchToChannelSwitching(m_channelSwitchDelay); | |
| 347 m_interference.EraseEvents(); | |
| 348 /* | |
| 349 * Needed here to be able to correctly sensed the medium for the first | |
| 350 * time after the switching. The actual switching is not performed until | |
| 351 * after m_channelSwitchDelay. Packets received during the switching | |
| 352 * state are added to the event list and are employed later to figure | |
| 353 * out the state of the medium after the switching. | |
| 354 */ | |
| 355 m_channelNumber = nch; | |
|
Mathieu Lacage
2009/08/19 08:19:12
I am curious: do you ever use m_channelNumber anyw
Ramon Bauza
2009/09/08 11:36:08
On 2009/08/19 08:19:12, Mathieu Lacage wrote:
> I
| |
| 323 } | 356 } |
| 324 | 357 |
| 358 /* | |
| 359 * This function wouldn't be really needed because channel switching delay is | |
|
Mathieu Lacage
2009/08/19 08:19:12
so, why is it needed ?
Ramon Bauza
2009/09/08 11:36:08
On 2009/08/19 08:19:12, Mathieu Lacage wrote:
> so
| |
| 360 * modelled in WifiPhyStateHelper. | |
| 361 */ | |
| 325 void | 362 void |
| 326 YansWifiPhy::DoSetChannelNumber (uint16_t nch) | 363 YansWifiPhy::DoSetChannelNumber (uint16_t nch) |
| 327 { | 364 { |
| 328 NS_LOG_DEBUG("switching channel " << m_channelId << " -> " << nch); | 365 NS_LOG_DEBUG("switching channel " << m_channelNumber << " -> " << nch); |
| 329 m_channelId = nch; | 366 m_channelNumber = nch; |
| 330 } | 367 } |
| 331 | 368 |
| 332 uint16_t | 369 uint16_t |
| 333 YansWifiPhy::GetChannelNumber() const | 370 YansWifiPhy::GetChannelNumber() const |
| 334 { | 371 { |
| 335 return m_channelId; | 372 return m_channelNumber; |
| 336 } | 373 } |
| 337 | 374 |
| 338 double | 375 double |
| 339 YansWifiPhy::GetChannelFrequencyMhz() const | 376 YansWifiPhy::GetChannelFrequencyMhz() const |
| 340 { | 377 { |
| 341 return m_channelStartingFrequency + 5 * (GetChannelNumber() - 1); | 378 return m_channelStartingFrequency + 5 * (GetChannelNumber() - 1); |
| 342 } | 379 } |
| 343 | 380 |
| 344 void | 381 void |
| 345 YansWifiPhy::SetReceiveOkCallback (SyncOkCallback callback) | 382 YansWifiPhy::SetReceiveOkCallback (SyncOkCallback callback) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 364 Time endRx = Simulator::Now () + rxDuration; | 401 Time endRx = Simulator::Now () + rxDuration; |
| 365 | 402 |
| 366 Ptr<InterferenceHelper::Event> event; | 403 Ptr<InterferenceHelper::Event> event; |
| 367 event = m_interference.Add (packet->GetSize (), | 404 event = m_interference.Add (packet->GetSize (), |
| 368 txMode, | 405 txMode, |
| 369 preamble, | 406 preamble, |
| 370 rxDuration, | 407 rxDuration, |
| 371 rxPowerW); | 408 rxPowerW); |
| 372 | 409 |
| 373 switch (m_state->GetState ()) { | 410 switch (m_state->GetState ()) { |
| 411 case YansWifiPhy::SWITCHING: | |
| 412 NS_LOG_DEBUG ("drop packet because of channel switching (power="<< | |
|
Mathieu Lacage
2009/08/19 08:19:12
is this debug message really relevant ? I don't se
Ramon Bauza
2009/09/08 11:36:08
On 2009/08/19 08:19:12, Mathieu Lacage wrote:
> is
| |
| 413 rxPowerW<<"W)"); | |
| 414 NotifyRxDrop (packet); | |
| 415 /* | |
| 416 * Packets received on the upcoming channel are added to the event list | |
| 417 * during the switching state. This way the medium can be correctly sensed | |
| 418 * when the device listens to the channel for the first time after the | |
| 419 * switching e.g. after channel switching, the channel may be sensed as | |
| 420 * busy due to other devices' tramissions started before the end of | |
| 421 * the switching. | |
| 422 */ | |
| 423 if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) | |
| 424 { | |
| 425 // that packet will be noise _after_ the completion of the | |
| 426 // channel switching. | |
| 427 goto maybeCcaBusy; | |
| 428 } | |
| 429 break; | |
| 374 case YansWifiPhy::SYNC: | 430 case YansWifiPhy::SYNC: |
| 375 NS_LOG_DEBUG ("drop packet because already in Sync (power="<< | 431 NS_LOG_DEBUG ("drop packet because already in Sync (power="<< |
| 376 rxPowerW<<"W)"); | 432 rxPowerW<<"W)"); |
| 377 NotifyRxDrop (packet); | 433 NotifyRxDrop (packet); |
| 378 if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) | 434 if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) |
| 379 { | 435 { |
| 380 // that packet will be noise _after_ the reception of the | 436 // that packet will be noise _after_ the reception of the |
| 381 // currently-received packet. | 437 // currently-received packet. |
| 382 goto maybeCcaBusy; | 438 goto maybeCcaBusy; |
| 383 } | 439 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 void | 490 void |
| 435 YansWifiPhy::SendPacket (Ptr<const Packet> packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower) | 491 YansWifiPhy::SendPacket (Ptr<const Packet> packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower) |
| 436 { | 492 { |
| 437 NS_LOG_FUNCTION (this << packet << txMode << preamble << (uint32_t)txPower); | 493 NS_LOG_FUNCTION (this << packet << txMode << preamble << (uint32_t)txPower); |
| 438 /* Transmission can happen if: | 494 /* Transmission can happen if: |
| 439 * - we are syncing on a packet. It is the responsability of the | 495 * - we are syncing on a packet. It is the responsability of the |
| 440 * MAC layer to avoid doing this but the PHY does nothing to | 496 * MAC layer to avoid doing this but the PHY does nothing to |
| 441 * prevent it. | 497 * prevent it. |
| 442 * - we are idle | 498 * - we are idle |
| 443 */ | 499 */ |
| 444 NS_ASSERT (!m_state->IsStateTx ()); | 500 NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ()); |
| 445 | 501 |
| 446 Time txDuration = CalculateTxDuration (packet->GetSize (), txMode, preamble); | 502 Time txDuration = CalculateTxDuration (packet->GetSize (), txMode, preamble); |
| 447 if (m_state->IsStateSync ()) | 503 if (m_state->IsStateSync ()) |
| 448 { | 504 { |
| 449 m_endSyncEvent.Cancel (); | 505 m_endSyncEvent.Cancel (); |
| 450 } | 506 } |
| 451 NotifyTxBegin (packet); | 507 NotifyTxBegin (packet); |
| 452 uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000; | 508 uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000; |
| 453 bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble); | 509 bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble); |
| 454 NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz(), dataRate500K bpsUnits, isShortPreamble); | 510 NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz(), dataRate500K bpsUnits, isShortPreamble); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 bool | 622 bool |
| 567 YansWifiPhy::IsStateSync (void) | 623 YansWifiPhy::IsStateSync (void) |
| 568 { | 624 { |
| 569 return m_state->IsStateSync (); | 625 return m_state->IsStateSync (); |
| 570 } | 626 } |
| 571 bool | 627 bool |
| 572 YansWifiPhy::IsStateTx (void) | 628 YansWifiPhy::IsStateTx (void) |
| 573 { | 629 { |
| 574 return m_state->IsStateTx (); | 630 return m_state->IsStateTx (); |
| 575 } | 631 } |
| 632 bool | |
| 633 YansWifiPhy::IsStateSwitching (void) | |
| 634 { | |
| 635 return m_state->IsStateSwitching (); | |
| 636 } | |
| 576 | 637 |
| 577 Time | 638 Time |
| 578 YansWifiPhy::GetStateDuration (void) | 639 YansWifiPhy::GetStateDuration (void) |
| 579 { | 640 { |
| 580 return m_state->GetStateDuration (); | 641 return m_state->GetStateDuration (); |
| 581 } | 642 } |
| 582 Time | 643 Time |
| 583 YansWifiPhy::GetDelayUntilIdle (void) | 644 YansWifiPhy::GetDelayUntilIdle (void) |
| 584 { | 645 { |
| 585 return m_state->GetDelayUntilIdle (); | 646 return m_state->GetDelayUntilIdle (); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode () , event->GetPreambleType ()); | 722 m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode () , event->GetPreambleType ()); |
| 662 } | 723 } |
| 663 else | 724 else |
| 664 { | 725 { |
| 665 /* failure. */ | 726 /* failure. */ |
| 666 NotifyRxDrop (packet); | 727 NotifyRxDrop (packet); |
| 667 m_state->SwitchFromSyncEndError (packet, snrPer.snr); | 728 m_state->SwitchFromSyncEndError (packet, snrPer.snr); |
| 668 } | 729 } |
| 669 } | 730 } |
| 670 } // namespace ns3 | 731 } // namespace ns3 |
| OLD | NEW |