diff --git a/src/mesh/helper/mesh-helper.cc b/src/mesh/helper/mesh-helper.cc index 26db7a0ec..a1ffc3d47 100644 --- a/src/mesh/helper/mesh-helper.cc +++ b/src/mesh/helper/mesh-helper.cc @@ -182,14 +182,19 @@ MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr node, uin // this is a const method, but we need to force the correct QoS setting ObjectFactory macObjectFactory = m_mac; macObjectFactory.Set ("QosSupported", BooleanValue (true)); // a mesh station is a QoS station + Ptr phy = phyHelper.Create (node, device); + node->AddDevice (device); + phy->ConfigureStandard (m_standard); + device->SetPhy (phy); Ptr mac = macObjectFactory.Create (); NS_ASSERT (mac != 0); mac->SetSsid (Ssid ()); mac->SetDevice (device); Ptr manager = m_stationManager.Create (); NS_ASSERT (manager != 0); - Ptr phy = phyHelper.Create (node, device); + device->SetRemoteStationManager (manager); mac->SetAddress (Mac48Address::Allocate ()); + device->SetMac (mac); mac->ConfigureStandard (m_standard); Ptr fem = mac->GetFrameExchangeManager (); if (fem != nullptr) @@ -202,11 +207,6 @@ MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr node, uin ackManager->SetWifiMac (mac); fem->SetAckManager (ackManager); } - phy->ConfigureStandard (m_standard); - device->SetMac (mac); - device->SetPhy (phy); - device->SetRemoteStationManager (manager); - node->AddDevice (device); mac->SwitchFrequencyChannel (channelId); return device; diff --git a/src/wave/model/ocb-wifi-mac.cc b/src/wave/model/ocb-wifi-mac.cc index 379a90aa0..0b60903fc 100644 --- a/src/wave/model/ocb-wifi-mac.cc +++ b/src/wave/model/ocb-wifi-mac.cc @@ -380,6 +380,20 @@ OcbWifiMac::ConfigureEdca (uint32_t cwmin, uint32_t cwmax, uint32_t aifsn, enum } } +void +OcbWifiMac::SetWifiPhy (Ptr phy) +{ + NS_LOG_FUNCTION (this << phy); + WifiMac::SetWifiPhy (phy); + NS_ABORT_MSG_IF (!phy->GetOperatingChannel ().IsSet (), + "PHY operating channel must have been set"); + m_channelAccessManager->SetupPhyListener (phy); + if (m_feManager != nullptr) + { + m_feManager->SetWifiPhy (phy); + } +} + void OcbWifiMac::ConfigureStandard (enum WifiStandard standard) { @@ -413,6 +427,10 @@ OcbWifiMac::ConfigureStandard (enum WifiStandard standard) m_feManager->SetMacRxMiddle (m_rxMiddle); m_feManager->SetAddress (GetAddress ()); m_channelAccessManager->SetupFrameExchangeManager (m_feManager); + if (auto phy = GetWifiPhy (); phy != nullptr) + { + m_feManager->SetWifiPhy (phy); + } } diff --git a/src/wave/model/ocb-wifi-mac.h b/src/wave/model/ocb-wifi-mac.h index ea3ff0fcd..16047befb 100644 --- a/src/wave/model/ocb-wifi-mac.h +++ b/src/wave/model/ocb-wifi-mac.h @@ -177,6 +177,7 @@ public: // Inherited from base class virtual void ConfigureStandard (enum WifiStandard standard); + virtual void SetWifiPhy (Ptr phy); protected: virtual void DoDispose (void); private: diff --git a/src/wifi/helper/wifi-helper.cc b/src/wifi/helper/wifi-helper.cc index d817044c5..a4e4400cc 100644 --- a/src/wifi/helper/wifi-helper.cc +++ b/src/wifi/helper/wifi-helper.cc @@ -722,6 +722,7 @@ WifiHelper::Install (const WifiPhyHelper &phyHelper, { Ptr node = *i; Ptr device = CreateObject (); + node->AddDevice (device); device->SetStandard (m_standard); if (m_standard == WIFI_STANDARD_UNSPECIFIED) { @@ -754,13 +755,11 @@ WifiHelper::Install (const WifiPhyHelper &phyHelper, device->SetEhtConfiguration (ehtConfiguration); } Ptr manager = m_stationManager.Create (); + device->SetRemoteStationManager (manager); Ptr phy = phyHelper.Create (node, device); device->SetPhy (phy); phy->ConfigureStandard (m_standard); Ptr mac = macHelper.Create (device, m_standard); - device->SetMac (mac); - device->SetRemoteStationManager (manager); - node->AddDevice (device); if ((m_standard >= WIFI_STANDARD_80211ax) && (m_obssPdAlgorithm.IsTypeIdSet ())) { Ptr obssPdAlgorithm = m_obssPdAlgorithm.Create (); diff --git a/src/wifi/helper/wifi-mac-helper.cc b/src/wifi/helper/wifi-mac-helper.cc index b7546f525..b7c403ed7 100644 --- a/src/wifi/helper/wifi-mac-helper.cc +++ b/src/wifi/helper/wifi-mac-helper.cc @@ -56,6 +56,7 @@ WifiMacHelper::Create (Ptr device, WifiStandard standard) const Ptr mac = macObjectFactory.Create (); mac->SetDevice (device); mac->SetAddress (Mac48Address::Allocate ()); + device->SetMac (mac); mac->ConfigureStandard (standard); Ptr fem = mac->GetFrameExchangeManager (); diff --git a/src/wifi/model/wifi-mac.cc b/src/wifi/model/wifi-mac.cc index acc12b50b..3f06adf13 100644 --- a/src/wifi/model/wifi-mac.cc +++ b/src/wifi/model/wifi-mac.cc @@ -655,10 +655,14 @@ void WifiMac::ConfigureStandard (WifiStandard standard) { NS_LOG_FUNCTION (this << standard); - NS_ABORT_IF (standard >= WIFI_STANDARD_80211n && !m_qosSupported); + NS_ABORT_MSG_IF (m_phy == nullptr || !m_phy->GetOperatingChannel ().IsSet (), + "PHY must have been set and an operating channel must have been set"); + ConfigurePhyDependentParameters (); + m_channelAccessManager->SetupPhyListener (m_phy); SetupFrameExchangeManager (standard); + m_feManager->SetWifiPhy (m_phy); } void @@ -768,12 +772,6 @@ WifiMac::SetWifiPhy (const Ptr phy) { NS_LOG_FUNCTION (this << phy); m_phy = phy; - NS_ABORT_MSG_IF (!m_phy->GetOperatingChannel ().IsSet (), - "PHY operating channel must have been set"); - ConfigurePhyDependentParameters (); - m_channelAccessManager->SetupPhyListener (phy); - NS_ASSERT (m_feManager != 0); - m_feManager->SetWifiPhy (phy); } Ptr diff --git a/src/wifi/test/power-rate-adaptation-test.cc b/src/wifi/test/power-rate-adaptation-test.cc index 59347bee3..709c3ff67 100644 --- a/src/wifi/test/power-rate-adaptation-test.cc +++ b/src/wifi/test/power-rate-adaptation-test.cc @@ -69,28 +69,18 @@ PowerRateAdaptationTest::PowerRateAdaptationTest () Ptr PowerRateAdaptationTest::ConfigureNode () { + /* + * Create and configure node. + */ + Ptr dev = CreateObject (); + Ptr node = CreateObject (); + node->AddDevice (dev); + /* * Create channel model. Is is necessary to configure correctly the phy layer. */ Ptr channel = CreateObject (); - /* - * Create mac layer. We use Adhoc because association is not needed to get supported rates. - */ - Ptr dev = CreateObject (); - Ptr mac = CreateObject (); - mac->SetDevice (dev); - mac->ConfigureStandard (WIFI_STANDARD_80211a); - Ptr fem = mac->GetFrameExchangeManager (); - - Ptr protectionManager = CreateObject (); - protectionManager->SetWifiMac (mac); - fem->SetProtectionManager (protectionManager); - - Ptr ackManager = CreateObject (); - ackManager->SetWifiMac (mac); - fem->SetAckManager (ackManager); - /* * Create mobility model. Is needed by the phy layer for transmission. */ @@ -102,6 +92,7 @@ PowerRateAdaptationTest::ConfigureNode () Ptr phy = CreateObject (); Ptr interferenceHelper = CreateObject (); phy->SetInterferenceHelper (interferenceHelper); + dev->SetPhy (phy); phy->SetChannel (channel); phy->SetDevice (dev); phy->SetMobility (mobility); @@ -118,16 +109,25 @@ PowerRateAdaptationTest::ConfigureNode () * Create manager. */ Ptr manager = m_manager.Create (); + dev->SetRemoteStationManager (manager); /* - * Create and configure node. Add mac and phy layer and the manager. + * Create mac layer. We use Adhoc because association is not needed to get supported rates. */ - Ptr node = CreateObject (); + Ptr mac = CreateObject (); + mac->SetDevice (dev); mac->SetAddress (Mac48Address::Allocate ()); dev->SetMac (mac); - dev->SetPhy (phy); - dev->SetRemoteStationManager (manager); - node->AddDevice (dev); + mac->ConfigureStandard (WIFI_STANDARD_80211a); + Ptr fem = mac->GetFrameExchangeManager (); + + Ptr protectionManager = CreateObject (); + protectionManager->SetWifiMac (mac); + fem->SetProtectionManager (protectionManager); + + Ptr ackManager = CreateObject (); + ackManager->SetWifiMac (mac); + fem->SetAckManager (ackManager); return node; } diff --git a/src/wifi/test/wifi-aggregation-test.cc b/src/wifi/test/wifi-aggregation-test.cc index 3d507c88d..e924a89c3 100644 --- a/src/wifi/test/wifi-aggregation-test.cc +++ b/src/wifi/test/wifi-aggregation-test.cc @@ -126,6 +126,7 @@ AmpduAggregationTest::DoRun (void) m_mac->SetDevice (m_device); m_mac->SetWifiRemoteStationManager (m_manager); m_mac->SetAddress (Mac48Address ("00:00:00:00:00:01")); + m_mac->SetWifiPhy (m_phy); m_mac->ConfigureStandard (WIFI_STANDARD_80211n); Ptr fem = m_mac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -134,7 +135,6 @@ AmpduAggregationTest::DoRun (void) Ptr ackManager = CreateObject (); ackManager->SetWifiMac (m_mac); fem->SetAckManager (ackManager); - m_mac->SetWifiPhy (m_phy); m_device->SetMac (m_mac); m_mac->SetState (StaWifiMac::ASSOCIATED); @@ -377,6 +377,7 @@ TwoLevelAggregationTest::DoRun (void) m_mac->SetDevice (m_device); m_mac->SetWifiRemoteStationManager (m_manager); m_mac->SetAddress (Mac48Address ("00:00:00:00:00:01")); + m_mac->SetWifiPhy (m_phy); m_mac->ConfigureStandard (WIFI_STANDARD_80211n); Ptr fem = m_mac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -385,7 +386,6 @@ TwoLevelAggregationTest::DoRun (void) Ptr ackManager = CreateObject (); ackManager->SetWifiMac (m_mac); fem->SetAckManager (ackManager); - m_mac->SetWifiPhy (m_phy); m_device->SetMac (m_mac); m_mac->SetState (StaWifiMac::ASSOCIATED); @@ -613,6 +613,7 @@ HeAggregationTest::DoRunSubTest (uint16_t bufferSize) m_mac->SetDevice (m_device); m_mac->SetWifiRemoteStationManager (m_manager); m_mac->SetAddress (Mac48Address ("00:00:00:00:00:01")); + m_mac->SetWifiPhy (m_phy); m_mac->ConfigureStandard (WIFI_STANDARD_80211ax); Ptr fem = m_mac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -621,7 +622,6 @@ HeAggregationTest::DoRunSubTest (uint16_t bufferSize) Ptr ackManager = CreateObject (); ackManager->SetWifiMac (m_mac); fem->SetAckManager (ackManager); - m_mac->SetWifiPhy (m_phy); m_device->SetMac (m_mac); m_mac->SetState (StaWifiMac::ASSOCIATED); diff --git a/src/wifi/test/wifi-test.cc b/src/wifi/test/wifi-test.cc index 2687cf8de..c9b32b0c8 100644 --- a/src/wifi/test/wifi-test.cc +++ b/src/wifi/test/wifi-test.cc @@ -140,10 +140,25 @@ WifiTest::CreateOne (Vector pos, Ptr channel) { Ptr node = CreateObject (); Ptr dev = CreateObject (); + node->AddDevice (dev); + + auto mobility = CreateObject (); + auto phy = CreateObject (); + Ptr interferenceHelper = CreateObject (); + phy->SetInterferenceHelper (interferenceHelper); + auto error = CreateObject (); + phy->SetErrorRateModel (error); + phy->SetChannel (channel); + phy->SetDevice (dev); + phy->ConfigureStandard (WIFI_STANDARD_80211a); + dev->SetPhy (phy); + auto manager = m_manager.Create (); + dev->SetRemoteStationManager (manager); Ptr mac = m_mac.Create (); mac->SetDevice (dev); mac->SetAddress (Mac48Address::Allocate ()); + dev->SetMac (mac); mac->ConfigureStandard (WIFI_STANDARD_80211a); Ptr fem = mac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -153,23 +168,8 @@ WifiTest::CreateOne (Vector pos, Ptr channel) ackManager->SetWifiMac (mac); fem->SetAckManager (ackManager); - Ptr mobility = CreateObject (); - Ptr phy = CreateObject (); - Ptr interferenceHelper = CreateObject (); - phy->SetInterferenceHelper (interferenceHelper); - Ptr error = CreateObject (); - phy->SetErrorRateModel (error); - phy->SetChannel (channel); - phy->SetDevice (dev); - phy->ConfigureStandard (WIFI_STANDARD_80211a); - Ptr manager = m_manager.Create (); - mobility->SetPosition (pos); node->AggregateObject (mobility); - dev->SetMac (mac); - dev->SetPhy (phy); - dev->SetRemoteStationManager (manager); - node->AddDevice (dev); Simulator::Schedule (Seconds (1.0), &WifiTest::SendOnePacket, this, dev); } @@ -318,10 +318,26 @@ InterferenceHelperSequenceTest::CreateOne (Vector pos, Ptr chan { Ptr node = CreateObject (); Ptr dev = CreateObject (); + node->AddDevice (dev); + + auto mobility = CreateObject (); + auto phy = CreateObject (); + Ptr interferenceHelper = CreateObject (); + phy->SetInterferenceHelper (interferenceHelper); + auto error = CreateObject (); + phy->SetErrorRateModel (error); + phy->SetChannel (channel); + phy->SetDevice (dev); + phy->SetMobility (mobility); + phy->ConfigureStandard (WIFI_STANDARD_80211a); + dev->SetPhy (phy); + auto manager = m_manager.Create (); + dev->SetRemoteStationManager (manager); Ptr mac = m_mac.Create (); mac->SetDevice (dev); mac->SetAddress (Mac48Address::Allocate ()); + dev->SetMac (mac); mac->ConfigureStandard (WIFI_STANDARD_80211a); Ptr fem = mac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -331,24 +347,8 @@ InterferenceHelperSequenceTest::CreateOne (Vector pos, Ptr chan ackManager->SetWifiMac (mac); fem->SetAckManager (ackManager); - Ptr mobility = CreateObject (); - Ptr phy = CreateObject (); - Ptr interferenceHelper = CreateObject (); - phy->SetInterferenceHelper (interferenceHelper); - Ptr error = CreateObject (); - phy->SetErrorRateModel (error); - phy->SetChannel (channel); - phy->SetDevice (dev); - phy->SetMobility (mobility); - phy->ConfigureStandard (WIFI_STANDARD_80211a); - Ptr manager = m_manager.Create (); - mobility->SetPosition (pos); node->AggregateObject (mobility); - dev->SetMac (mac); - dev->SetPhy (phy); - dev->SetRemoteStationManager (manager); - node->AddDevice (dev); return node; } @@ -523,23 +523,6 @@ DcfImmediateAccessBroadcastTestCase::DoRun (void) Ptr txNode = CreateObject (); Ptr txDev = CreateObject (); - Ptr txMac = m_mac.Create (); - txMac->SetDevice (txDev); - txMac->ConfigureStandard (WIFI_STANDARD_80211a); - Ptr fem = txMac->GetFrameExchangeManager (); - Ptr protectionManager = CreateObject (); - protectionManager->SetWifiMac (txMac); - fem->SetProtectionManager (protectionManager); - Ptr ackManager = CreateObject (); - ackManager->SetWifiMac (txMac); - fem->SetAckManager (ackManager); - - - //Fix the stream assignment to the Dcf Txop objects (backoffs) - //The below stream assignment will result in the Txop object - //using a backoff value of zero for this test when the - //Txop::EndTxNoAck() calls to StartBackoffNow() - AssignWifiRandomStreams (txMac, 23); Ptr txMobility = CreateObject (); Ptr txPhy = CreateObject (); @@ -556,12 +539,29 @@ DcfImmediateAccessBroadcastTestCase::DoRun (void) txMobility->SetPosition (Vector (0.0, 0.0, 0.0)); txNode->AggregateObject (txMobility); - txMac->SetAddress (Mac48Address::Allocate ()); - txDev->SetMac (txMac); txDev->SetPhy (txPhy); txDev->SetRemoteStationManager (m_manager.Create ()); txNode->AddDevice (txDev); + auto txMac = m_mac.Create (); + txMac->SetDevice (txDev); + txMac->SetAddress (Mac48Address::Allocate ()); + txDev->SetMac (txMac); + txMac->ConfigureStandard (WIFI_STANDARD_80211a); + auto fem = txMac->GetFrameExchangeManager (); + auto protectionManager = CreateObject (); + protectionManager->SetWifiMac (txMac); + fem->SetProtectionManager (protectionManager); + auto ackManager = CreateObject (); + ackManager->SetWifiMac (txMac); + fem->SetAckManager (ackManager); + + //Fix the stream assignment to the Dcf Txop objects (backoffs) + //The below stream assignment will result in the Txop object + //using a backoff value of zero for this test when the + //Txop::EndTxNoAck() calls to StartBackoffNow() + AssignWifiRandomStreams (txMac, 23); + m_firstTransmissionTime = Seconds (0.0); m_secondTransmissionTime = Seconds (0.0); m_numSentPackets = 0; @@ -1731,9 +1731,30 @@ Bug2831TestCase::DoRun (void) Ptr apNode = CreateObject (); Ptr apDev = CreateObject (); + apNode->AddDevice (apDev); apDev->SetStandard (WIFI_STANDARD_80211ax); Ptr apHtConfiguration = CreateObject (); apDev->SetHtConfiguration (apHtConfiguration); + ObjectFactory manager; + manager.SetTypeId ("ns3::ConstantRateWifiManager"); + apDev->SetRemoteStationManager (manager.Create ()); + + auto apMobility = CreateObject (); + apMobility->SetPosition (Vector (0.0, 0.0, 0.0)); + apNode->AggregateObject (apMobility); + + auto error = CreateObject (); + m_apPhy = CreateObject (); + apDev->SetPhy (m_apPhy); + Ptr apInterferenceHelper = CreateObject (); + m_apPhy->SetInterferenceHelper (apInterferenceHelper); + m_apPhy->SetErrorRateModel (error); + m_apPhy->SetChannel (channel); + m_apPhy->SetMobility (apMobility); + m_apPhy->SetDevice (apDev); + m_apPhy->ConfigureStandard (WIFI_STANDARD_80211ax); + m_apPhy->SetOperatingChannel (WifiPhy::ChannelTuple {36, 20, (int)(WIFI_PHY_BAND_5GHZ), 0}); + ObjectFactory mac; mac.SetTypeId ("ns3::ApWifiMac"); mac.Set ("EnableBeaconJitter", BooleanValue (false)); @@ -1741,6 +1762,7 @@ Bug2831TestCase::DoRun (void) Ptr apMac = mac.Create (); apMac->SetDevice (apDev); apMac->SetAddress (Mac48Address::Allocate ()); + apDev->SetMac (apMac); apMac->ConfigureStandard (WIFI_STANDARD_80211ax); Ptr fem = apMac->GetFrameExchangeManager (); Ptr protectionManager = CreateObject (); @@ -1752,11 +1774,30 @@ Bug2831TestCase::DoRun (void) Ptr staNode = CreateObject (); Ptr staDev = CreateObject (); + staNode->AddDevice (staDev); staDev->SetStandard (WIFI_STANDARD_80211ax); Ptr staHtConfiguration = CreateObject (); staDev->SetHtConfiguration (staHtConfiguration); + staDev->SetRemoteStationManager (manager.Create ()); + + Ptr staMobility = CreateObject (); + staMobility->SetPosition (Vector (1.0, 0.0, 0.0)); + staNode->AggregateObject (staMobility); + + m_staPhy = CreateObject (); + staDev->SetPhy (m_staPhy); + Ptr staInterferenceHelper = CreateObject (); + m_staPhy->SetInterferenceHelper (staInterferenceHelper); + m_staPhy->SetErrorRateModel (error); + m_staPhy->SetChannel (channel); + m_staPhy->SetMobility (staMobility); + m_staPhy->SetDevice (apDev); + m_staPhy->ConfigureStandard (WIFI_STANDARD_80211ax); + m_staPhy->SetOperatingChannel (WifiPhy::ChannelTuple {36, 20, (int)(WIFI_PHY_BAND_5GHZ), 0}); + mac.SetTypeId ("ns3::StaWifiMac"); - Ptr staMac = mac.Create (); + auto staMac = mac.Create (); + staDev->SetMac (staMac); staMac->SetDevice (staDev); staMac->SetAddress (Mac48Address::Allocate ()); staMac->ConfigureStandard (WIFI_STANDARD_80211ax); @@ -1768,48 +1809,6 @@ Bug2831TestCase::DoRun (void) ackManager->SetWifiMac (staMac); fem->SetAckManager (ackManager); - Ptr apMobility = CreateObject (); - apMobility->SetPosition (Vector (0.0, 0.0, 0.0)); - apNode->AggregateObject (apMobility); - - m_apPhy = CreateObject (); - Ptr apInterferenceHelper = CreateObject (); - m_apPhy->SetInterferenceHelper (apInterferenceHelper); - Ptr apErrorModel = CreateObject (); - m_apPhy->SetErrorRateModel (apErrorModel); - m_apPhy->SetChannel (channel); - m_apPhy->SetMobility (apMobility); - m_apPhy->SetDevice (apDev); - apDev->SetPhy (m_apPhy); - m_apPhy->ConfigureStandard (WIFI_STANDARD_80211ax); - m_apPhy->SetOperatingChannel (WifiPhy::ChannelTuple {36, 20, (int)(WIFI_PHY_BAND_5GHZ), 0}); - - Ptr staMobility = CreateObject (); - staMobility->SetPosition (Vector (1.0, 0.0, 0.0)); - staNode->AggregateObject (staMobility); - - m_staPhy = CreateObject (); - Ptr staInterferenceHelper = CreateObject (); - m_staPhy->SetInterferenceHelper (staInterferenceHelper); - Ptr staErrorModel = CreateObject (); - m_staPhy->SetErrorRateModel (staErrorModel); - m_staPhy->SetChannel (channel); - m_staPhy->SetMobility (staMobility); - m_staPhy->SetDevice (apDev); - staDev->SetPhy (m_staPhy); - m_staPhy->ConfigureStandard (WIFI_STANDARD_80211ax); - m_staPhy->SetOperatingChannel (WifiPhy::ChannelTuple {36, 20, (int)(WIFI_PHY_BAND_5GHZ), 0}); - - apDev->SetMac (apMac); - ObjectFactory manager; - manager.SetTypeId ("ns3::ConstantRateWifiManager"); - apDev->SetRemoteStationManager (manager.Create ()); - apNode->AddDevice (apDev); - - staDev->SetMac (staMac); - staDev->SetRemoteStationManager (manager.Create ()); - staNode->AddDevice (staDev); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyRxBegin", MakeCallback (&Bug2831TestCase::RxCallback, this)); Simulator::Schedule (Seconds (1.0), &Bug2831TestCase::ChangeSupportedChannelWidth, this);