From 82ea58a95c03ab158edfd81860ad614d1bf70ec6 Mon Sep 17 00:00:00 2001 From: Alessandro Aimi Date: Mon, 21 Oct 2024 11:35:05 +0200 Subject: [PATCH] Prefer explicit DynamicCast in place of GetObject for downcasting (#176) --- examples/aloha-throughput.cc | 14 ++++----- examples/complete-network-example.cc | 2 +- examples/frame-counter-update.cc | 4 +-- examples/network-server-example.cc | 4 +-- examples/parallel-reception-example.cc | 7 ++--- helper/lora-helper.cc | 4 +-- helper/lora-phy-helper.cc | 4 +-- helper/lora-radio-energy-model-helper.cc | 6 ++-- helper/lorawan-mac-helper.cc | 36 ++++++++++++------------ model/class-a-end-device-lorawan-mac.cc | 26 ++++++++--------- model/end-device-lorawan-mac.cc | 12 ++++---- model/gateway-lorawan-mac.cc | 2 +- model/lora-channel.cc | 2 +- model/lora-frame-header.h | 4 +-- model/network-server.cc | 8 +++--- model/network-status.cc | 2 +- model/one-shot-sender.cc | 2 +- model/periodic-sender.cc | 2 +- test/lorawan-test-suite.cc | 13 ++++----- test/network-server-test-suite.cc | 26 ++++++----------- test/utilities.h | 2 +- 21 files changed, 84 insertions(+), 98 deletions(-) diff --git a/examples/aloha-throughput.cc b/examples/aloha-throughput.cc index 4f823fdd68..4bf7a5957f 100644 --- a/examples/aloha-throughput.cc +++ b/examples/aloha-throughput.cc @@ -222,7 +222,7 @@ main(int argc, char* argv[]) for (auto j = endDevices.Begin(); j != endDevices.End(); ++j) { Ptr node = *j; - Ptr loraNetDevice = node->GetDevice(0)->GetObject(); + Ptr loraNetDevice = DynamicCast(node->GetDevice(0)); Ptr phy = loraNetDevice->GetPhy(); } @@ -325,17 +325,17 @@ main(int argc, char* argv[]) // Install trace sources for (auto node = gateways.Begin(); node != gateways.End(); node++) { - (*node)->GetDevice(0)->GetObject()->GetPhy()->TraceConnectWithoutContext( - "ReceivedPacket", - MakeCallback(OnPacketReceptionCallback)); + DynamicCast((*node)->GetDevice(0)) + ->GetPhy() + ->TraceConnectWithoutContext("ReceivedPacket", MakeCallback(OnPacketReceptionCallback)); } // Install trace sources for (auto node = endDevices.Begin(); node != endDevices.End(); node++) { - (*node)->GetDevice(0)->GetObject()->GetPhy()->TraceConnectWithoutContext( - "StartSending", - MakeCallback(OnTransmissionCallback)); + DynamicCast((*node)->GetDevice(0)) + ->GetPhy() + ->TraceConnectWithoutContext("StartSending", MakeCallback(OnTransmissionCallback)); } LorawanMacHelper::SetSpreadingFactorsUp(endDevices, gateways, channel); diff --git a/examples/complete-network-example.cc b/examples/complete-network-example.cc index ff6487809d..be2a2686db 100644 --- a/examples/complete-network-example.cc +++ b/examples/complete-network-example.cc @@ -205,7 +205,7 @@ main(int argc, char* argv[]) for (auto j = endDevices.Begin(); j != endDevices.End(); ++j) { Ptr node = *j; - Ptr loraNetDevice = node->GetDevice(0)->GetObject(); + Ptr loraNetDevice = DynamicCast(node->GetDevice(0)); Ptr phy = loraNetDevice->GetPhy(); } diff --git a/examples/frame-counter-update.cc b/examples/frame-counter-update.cc index 68187ab6a2..013c80acd1 100644 --- a/examples/frame-counter-update.cc +++ b/examples/frame-counter-update.cc @@ -211,9 +211,9 @@ main(int argc, char* argv[]) for (auto j = endDevices.Begin(); j != endDevices.End(); ++j) { Ptr node = *j; - Ptr loraNetDevice = node->GetDevice(0)->GetObject(); + Ptr loraNetDevice = DynamicCast(node->GetDevice(0)); Ptr phy = loraNetDevice->GetPhy(); - Ptr mac = loraNetDevice->GetMac()->GetObject(); + Ptr mac = DynamicCast(loraNetDevice->GetMac()); phy->TraceConnectWithoutContext("StartSending", MakeCallback(&OnPhySentPacket)); mac->TraceConnectWithoutContext("RequiredTransmissions", MakeCallback(&OnMacPacketOutcome)); } diff --git a/examples/network-server-example.cc b/examples/network-server-example.cc index c63563e8ea..5e03615cfd 100644 --- a/examples/network-server-example.cc +++ b/examples/network-server-example.cc @@ -133,8 +133,8 @@ main(int argc, char* argv[]) helper.Install(phyHelper, macHelper, endDevices); // Set message type (Default is unconfirmed) - Ptr edMac1 = endDevices.Get(1)->GetDevice(0)->GetObject()->GetMac(); - Ptr edLorawanMac1 = edMac1->GetObject(); + Ptr edMac1 = DynamicCast(endDevices.Get(1)->GetDevice(0))->GetMac(); + Ptr edLorawanMac1 = DynamicCast(edMac1); edLorawanMac1->SetMType(LorawanMacHeader::CONFIRMED_DATA_UP); // Install applications in end devices diff --git a/examples/parallel-reception-example.cc b/examples/parallel-reception-example.cc index 92a3c66f9f..0c2a29dffe 100644 --- a/examples/parallel-reception-example.cc +++ b/examples/parallel-reception-example.cc @@ -147,11 +147,8 @@ main(int argc, char* argv[]) ******************/ for (uint32_t i = 0; i < endDevices.GetN(); i++) { - endDevices.Get(i) - ->GetDevice(0) - ->GetObject() - ->GetMac() - ->GetObject() + DynamicCast( + DynamicCast(endDevices.Get(i)->GetDevice(0))->GetMac()) ->SetDataRate(5 - i); } diff --git a/helper/lora-helper.cc b/helper/lora-helper.cc index 5ed66ed88b..ba691ed76b 100644 --- a/helper/lora-helper.cc +++ b/helper/lora-helper.cc @@ -199,10 +199,10 @@ LoraHelper::DoPrintDeviceStatus(NodeContainer endDevices, Ptr position = object->GetObject(); NS_ASSERT(position); Ptr netDevice = object->GetDevice(0); - Ptr loraNetDevice = netDevice->GetObject(); + Ptr loraNetDevice = DynamicCast(netDevice); NS_ASSERT(loraNetDevice); Ptr mac = - loraNetDevice->GetMac()->GetObject(); + DynamicCast(loraNetDevice->GetMac()); int dr = int(mac->GetDataRate()); double txPower = mac->GetTransmissionPower(); Vector pos = position->GetPosition(); diff --git a/helper/lora-phy-helper.cc b/helper/lora-phy-helper.cc index 19e6f12b8f..51ff87bd3d 100644 --- a/helper/lora-phy-helper.cc +++ b/helper/lora-phy-helper.cc @@ -90,7 +90,7 @@ LoraPhyHelper::Create(Ptr node, Ptr device) const for (auto& f : frequencies) { - phy->GetObject()->AddFrequency(f); + DynamicCast(phy)->AddFrequency(f); } int receptionPaths = 0; @@ -98,7 +98,7 @@ LoraPhyHelper::Create(Ptr node, Ptr device) const // int maxReceptionPaths = 8; while (receptionPaths < m_maxReceptionPaths) { - phy->GetObject()->AddReceptionPath(); + DynamicCast(phy)->AddReceptionPath(); receptionPaths++; } } diff --git a/helper/lora-radio-energy-model-helper.cc b/helper/lora-radio-energy-model-helper.cc index f6e670ccb2..82a6d3ec88 100644 --- a/helper/lora-radio-energy-model-helper.cc +++ b/helper/lora-radio-energy-model-helper.cc @@ -80,15 +80,15 @@ LoraRadioEnergyModelHelper::DoInstall(Ptr device, Ptr s NS_FATAL_ERROR("NetDevice type is not LoraNetDevice!"); } Ptr node = device->GetNode(); - Ptr model = m_radioEnergy.Create()->GetObject(); + Ptr model = m_radioEnergy.Create(); NS_ASSERT(model); // set energy source pointer model->SetEnergySource(source); // set energy depletion callback // if none is specified, make a callback to EndDeviceLoraPhy::SetSleepMode - Ptr loraDevice = device->GetObject(); - Ptr loraPhy = loraDevice->GetPhy()->GetObject(); + Ptr loraDevice = DynamicCast(device); + Ptr loraPhy = DynamicCast(loraDevice->GetPhy()); // add model to device model list in energy source source->AppendDeviceEnergyModel(model); // create and register energy model phy listener diff --git a/helper/lorawan-mac-helper.cc b/helper/lorawan-mac-helper.cc index 1fc853a16e..4e18b7dedb 100644 --- a/helper/lorawan-mac-helper.cc +++ b/helper/lorawan-mac-helper.cc @@ -71,14 +71,14 @@ LorawanMacHelper::Create(Ptr node, Ptr device) const // If we are operating on an end device, add an address to it if (m_deviceType == ED_A && m_addrGen) { - mac->GetObject()->SetDeviceAddress(m_addrGen->NextAddress()); + DynamicCast(mac)->SetDeviceAddress(m_addrGen->NextAddress()); } // Add a basic list of channels based on the region where the device is // operating if (m_deviceType == ED_A) { - Ptr edMac = mac->GetObject(); + Ptr edMac = DynamicCast(mac); switch (m_region) { case LorawanMacHelper::EU: { @@ -101,7 +101,7 @@ LorawanMacHelper::Create(Ptr node, Ptr device) const } else { - Ptr gwMac = mac->GetObject(); + Ptr gwMac = DynamicCast(mac); switch (m_region) { case LorawanMacHelper::EU: { @@ -171,7 +171,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr gwMac) const // ReceivePath configuration // /////////////////////////////// Ptr gwPhy = - gwMac->GetDevice()->GetObject()->GetPhy()->GetObject(); + DynamicCast(DynamicCast(gwMac->GetDevice())->GetPhy()); ApplyCommonAlohaConfigurations(gwMac); @@ -184,7 +184,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr gwMac) const int maxReceptionPaths = 1; while (receptionPaths < maxReceptionPaths) { - gwPhy->GetObject()->AddReceptionPath(); + DynamicCast(gwPhy)->AddReceptionPath(); receptionPaths++; } gwPhy->AddFrequency(868.1); @@ -268,7 +268,7 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr gwMac) const // ReceivePath configuration // /////////////////////////////// Ptr gwPhy = - gwMac->GetDevice()->GetObject()->GetPhy()->GetObject(); + DynamicCast(DynamicCast(gwMac->GetDevice())->GetPhy()); ApplyCommonEuConfigurations(gwMac); @@ -291,7 +291,7 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr gwMac) const int maxReceptionPaths = 8; while (receptionPaths < maxReceptionPaths) { - gwPhy->GetObject()->AddReceptionPath(); + DynamicCast(gwPhy)->AddReceptionPath(); receptionPaths++; } } @@ -382,7 +382,7 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr gwMac) // ReceivePath configuration // /////////////////////////////// Ptr gwPhy = - gwMac->GetDevice()->GetObject()->GetPhy()->GetObject(); + DynamicCast(DynamicCast(gwMac->GetDevice())->GetPhy()); ApplyCommonEuConfigurations(gwMac); @@ -403,7 +403,7 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr gwMac) int maxReceptionPaths = 8; while (receptionPaths < maxReceptionPaths) { - gwPhy->GetObject()->AddReceptionPath(); + gwPhy->AddReceptionPath(); receptionPaths++; } } @@ -456,10 +456,10 @@ LorawanMacHelper::SetSpreadingFactorsUp(NodeContainer endDevices, Ptr position = object->GetObject(); NS_ASSERT(position); Ptr netDevice = object->GetDevice(0); - Ptr loraNetDevice = netDevice->GetObject(); + Ptr loraNetDevice = DynamicCast(netDevice); NS_ASSERT(loraNetDevice); Ptr mac = - loraNetDevice->GetMac()->GetObject(); + DynamicCast(loraNetDevice->GetMac()); NS_ASSERT(mac); // Try computing the distance from each gateway and find the best one @@ -479,7 +479,7 @@ LorawanMacHelper::SetSpreadingFactorsUp(NodeContainer endDevices, if (currentRxPower > highestRxPower) { bestGateway = curr; - bestGatewayPosition = curr->GetObject(); + bestGatewayPosition = currPosition; highestRxPower = currentRxPower; } } @@ -488,7 +488,7 @@ LorawanMacHelper::SetSpreadingFactorsUp(NodeContainer endDevices, double rxPower = highestRxPower; // Get the end device sensitivity - Ptr edPhy = loraNetDevice->GetPhy()->GetObject(); + Ptr edPhy = DynamicCast(loraNetDevice->GetPhy()); const double* edSensitivity = EndDeviceLoraPhy::sensitivity; if (rxPower > *edSensitivity) @@ -533,9 +533,9 @@ LorawanMacHelper::SetSpreadingFactorsUp(NodeContainer endDevices, // Get the Gw sensitivity Ptr gatewayNetDevice = bestGateway->GetDevice (0); - Ptr gatewayLoraNetDevice = gatewayNetDevice->GetObject (); - Ptr gatewayPhy = gatewayLoraNetDevice->GetPhy ()->GetObject - (); const double *gwSensitivity = gatewayPhy->sensitivity; + Ptr gatewayLoraNetDevice = DynamicCast(gatewayNetDevice); + Ptr gatewayPhy = DynamicCast + (gatewayLoraNetDevice->GetPhy ()); const double *gwSensitivity = gatewayPhy->sensitivity; if(rxPower > *gwSensitivity) { @@ -615,10 +615,10 @@ LorawanMacHelper::SetSpreadingFactorsGivenDistribution(NodeContainer endDevices, Ptr position = object->GetObject(); NS_ASSERT(position); Ptr netDevice = object->GetDevice(0); - Ptr loraNetDevice = netDevice->GetObject(); + Ptr loraNetDevice = DynamicCast(netDevice); NS_ASSERT(loraNetDevice); Ptr mac = - loraNetDevice->GetMac()->GetObject(); + DynamicCast(loraNetDevice->GetMac()); NS_ASSERT(mac); double prob = uniformRV->GetValue(0, 1); diff --git a/model/class-a-end-device-lorawan-mac.cc b/model/class-a-end-device-lorawan-mac.cc index 41f9cfed2c..f59832151b 100644 --- a/model/class-a-end-device-lorawan-mac.cc +++ b/model/class-a-end-device-lorawan-mac.cc @@ -114,7 +114,7 @@ ClassAEndDeviceLorawanMac::SendToPhy(Ptr packetToSend) ////////////////////////////// // Switch the PHY to the channel so that it will listen here for downlink - m_phy->GetObject()->SetFrequency(txChannel->GetFrequency()); + DynamicCast(m_phy)->SetFrequency(txChannel->GetFrequency()); // Instruct the PHY on the right Spreading Factor to listen for during the window // create a SetReplyDataRate function? @@ -123,7 +123,7 @@ ClassAEndDeviceLorawanMac::SendToPhy(Ptr packetToSend) << ", m_rx1DrOffset: " << unsigned(m_rx1DrOffset) << ", replyDataRate: " << unsigned(replyDataRate) << "."); - m_phy->GetObject()->SetSpreadingFactor(GetSfFromDataRate(replyDataRate)); + DynamicCast(m_phy)->SetSpreadingFactor(GetSfFromDataRate(replyDataRate)); } ////////////////////////// @@ -228,7 +228,7 @@ ClassAEndDeviceLorawanMac::Receive(Ptr packet) } } - m_phy->GetObject()->SwitchToSleep(); + DynamicCast(m_phy)->SwitchToSleep(); } void @@ -237,7 +237,7 @@ ClassAEndDeviceLorawanMac::FailedReception(Ptr packet) NS_LOG_FUNCTION(this << packet); // Switch to sleep after a failed reception - m_phy->GetObject()->SwitchToSleep(); + DynamicCast(m_phy)->SwitchToSleep(); if (m_secondReceiveWindow.IsExpired() && m_retxParams.waitingAck) { @@ -282,7 +282,7 @@ ClassAEndDeviceLorawanMac::TxFinished(Ptr packet) // this); // Switch the PHY to sleep - m_phy->GetObject()->SwitchToSleep(); + DynamicCast(m_phy)->SwitchToSleep(); } void @@ -291,7 +291,7 @@ ClassAEndDeviceLorawanMac::OpenFirstReceiveWindow() NS_LOG_FUNCTION_NOARGS(); // Set Phy in Standby mode - m_phy->GetObject()->SwitchToStandby(); + DynamicCast(m_phy)->SwitchToStandby(); // Calculate the duration of a single symbol for the first receive window data rate double tSym = pow(2, GetSfFromDataRate(GetFirstReceiveWindowDataRate())) / @@ -310,7 +310,7 @@ ClassAEndDeviceLorawanMac::CloseFirstReceiveWindow() { NS_LOG_FUNCTION_NOARGS(); - Ptr phy = m_phy->GetObject(); + Ptr phy = DynamicCast(m_phy); // Check the Phy layer's state: // - RX -> We are receiving a preamble. @@ -341,7 +341,7 @@ ClassAEndDeviceLorawanMac::OpenSecondReceiveWindow() // Check for receiver status: if it's locked on a packet, don't open this // window at all. - if (m_phy->GetObject()->GetState() == EndDeviceLoraPhy::RX) + if (DynamicCast(m_phy)->GetState() == EndDeviceLoraPhy::RX) { NS_LOG_INFO("Won't open second receive window since we are in RX mode."); @@ -349,14 +349,14 @@ ClassAEndDeviceLorawanMac::OpenSecondReceiveWindow() } // Set Phy in Standby mode - m_phy->GetObject()->SwitchToStandby(); + DynamicCast(m_phy)->SwitchToStandby(); // Switch to appropriate channel and data rate NS_LOG_INFO("Using parameters: " << m_secondReceiveWindowFrequency << "Hz, DR" << unsigned(m_secondReceiveWindowDataRate)); - m_phy->GetObject()->SetFrequency(m_secondReceiveWindowFrequency); - m_phy->GetObject()->SetSpreadingFactor( + DynamicCast(m_phy)->SetFrequency(m_secondReceiveWindowFrequency); + DynamicCast(m_phy)->SetSpreadingFactor( GetSfFromDataRate(m_secondReceiveWindowDataRate)); // Calculate the duration of a single symbol for the second receive window data rate @@ -376,7 +376,7 @@ ClassAEndDeviceLorawanMac::CloseSecondReceiveWindow() { NS_LOG_FUNCTION_NOARGS(); - Ptr phy = m_phy->GetObject(); + Ptr phy = DynamicCast(m_phy); // NS_ASSERT (phy->m_state != EndDeviceLoraPhy::TX && // phy->m_state != EndDeviceLoraPhy::SLEEP); @@ -410,7 +410,7 @@ ClassAEndDeviceLorawanMac::CloseSecondReceiveWindow() } else if (m_retxParams.retxLeft == 0 && - m_phy->GetObject()->GetState() != EndDeviceLoraPhy::RX) + DynamicCast(m_phy)->GetState() != EndDeviceLoraPhy::RX) { uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft); m_requiredTxCallback(txs, false, m_retxParams.firstAttempt, m_retxParams.packet); diff --git a/model/end-device-lorawan-mac.cc b/model/end-device-lorawan-mac.cc index d2d436651a..b5eb1cd8d0 100644 --- a/model/end-device-lorawan-mac.cc +++ b/model/end-device-lorawan-mac.cc @@ -366,7 +366,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a LinkCheckAns command."); // Cast the command - Ptr linkCheckAns = (*it)->GetObject(); + Ptr linkCheckAns = DynamicCast(*it); // Call the appropriate function to take action OnLinkCheckAns(linkCheckAns->GetMargin(), linkCheckAns->GetGwCnt()); @@ -377,7 +377,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a LinkAdrReq command."); // Cast the command - Ptr linkAdrReq = (*it)->GetObject(); + Ptr linkAdrReq = DynamicCast(*it); // Call the appropriate function to take action OnLinkAdrReq(linkAdrReq->GetDataRate(), @@ -391,7 +391,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a DutyCycleReq command."); // Cast the command - Ptr dutyCycleReq = (*it)->GetObject(); + Ptr dutyCycleReq = DynamicCast(*it); // Call the appropriate function to take action OnDutyCycleReq(dutyCycleReq->GetMaximumAllowedDutyCycle()); @@ -402,7 +402,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a RxParamSetupReq command."); // Cast the command - Ptr rxParamSetupReq = (*it)->GetObject(); + Ptr rxParamSetupReq = DynamicCast(*it); // Call the appropriate function to take action OnRxParamSetupReq(rxParamSetupReq); @@ -413,7 +413,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a DevStatusReq command."); // Cast the command - Ptr devStatusReq = (*it)->GetObject(); + Ptr devStatusReq = DynamicCast(*it); // Call the appropriate function to take action OnDevStatusReq(); @@ -424,7 +424,7 @@ EndDeviceLorawanMac::ParseCommands(LoraFrameHeader frameHeader) NS_LOG_DEBUG("Detected a NewChannelReq command."); // Cast the command - Ptr newChannelReq = (*it)->GetObject(); + Ptr newChannelReq = DynamicCast(*it); // Call the appropriate function to take action OnNewChannelReq(newChannelReq->GetChannelIndex(), diff --git a/model/gateway-lorawan-mac.cc b/model/gateway-lorawan-mac.cc index 6ada4b0ce9..9754c5afca 100644 --- a/model/gateway-lorawan-mac.cc +++ b/model/gateway-lorawan-mac.cc @@ -114,7 +114,7 @@ GatewayLorawanMac::Receive(Ptr packet) if (macHdr.IsUplink()) { - m_device->GetObject()->Receive(packetCopy); + DynamicCast(m_device)->Receive(packetCopy); NS_LOG_DEBUG("Received packet: " << packet); diff --git a/model/lora-channel.cc b/model/lora-channel.cc index fbb9757919..debb11819b 100644 --- a/model/lora-channel.cc +++ b/model/lora-channel.cc @@ -95,7 +95,7 @@ LoraChannel::GetNDevices() const Ptr LoraChannel::GetDevice(std::size_t i) const { - return m_phyList[i]->GetDevice()->GetObject(); + return DynamicCast(m_phyList[i]->GetDevice()); } void diff --git a/model/lora-frame-header.h b/model/lora-frame-header.h index db05d2eb09..8d32f1de1c 100644 --- a/model/lora-frame-header.h +++ b/model/lora-frame-header.h @@ -339,9 +339,9 @@ LoraFrameHeader::GetMacCommand() std::list>::const_iterator it; for (it = m_macCommands.begin(); it != m_macCommands.end(); ++it) { - if ((*it)->GetObject()) + if (DynamicCast(*it)) { - return (*it)->GetObject(); + return DynamicCast(*it); } } diff --git a/model/network-server.cc b/model/network-server.cc index 141df2d092..984dfa7a64 100644 --- a/model/network-server.cc +++ b/model/network-server.cc @@ -80,7 +80,7 @@ NetworkServer::AddGateway(Ptr gateway, Ptr netDevice) Ptr p2pNetDevice; for (uint32_t i = 0; i < gateway->GetNDevices(); i++) { - p2pNetDevice = gateway->GetDevice(i)->GetObject(); + p2pNetDevice = DynamicCast(gateway->GetDevice(i)); if (p2pNetDevice) { // We found a p2pNetDevice on the gateway @@ -90,7 +90,7 @@ NetworkServer::AddGateway(Ptr gateway, Ptr netDevice) // Get the gateway's LoRa MAC layer (assumes gateway's MAC is configured as first device) Ptr gwMac = - gateway->GetDevice(0)->GetObject()->GetMac()->GetObject(); + DynamicCast(DynamicCast(gateway->GetDevice(0))->GetMac()); NS_ASSERT(gwMac); // Get the Address @@ -124,7 +124,7 @@ NetworkServer::AddNode(Ptr node) Ptr loraNetDevice; for (uint32_t i = 0; i < node->GetNDevices(); i++) { - loraNetDevice = node->GetDevice(i)->GetObject(); + loraNetDevice = DynamicCast(node->GetDevice(i)); if (loraNetDevice) { // We found a LoraNetDevice on the node @@ -134,7 +134,7 @@ NetworkServer::AddNode(Ptr node) // Get the MAC Ptr edLorawanMac = - loraNetDevice->GetMac()->GetObject(); + DynamicCast(loraNetDevice->GetMac()); // Update the NetworkStatus about the existence of this node m_status->AddNode(edLorawanMac); diff --git a/model/network-status.cc b/model/network-status.cc index c931dea136..74d0fc4236 100644 --- a/model/network-status.cc +++ b/model/network-status.cc @@ -59,7 +59,7 @@ NetworkStatus::AddNode(Ptr edMac) { // The device doesn't exist. Create new EndDeviceStatus Ptr edStatus = - CreateObject(edAddress, edMac->GetObject()); + CreateObject(edAddress, DynamicCast(edMac)); // Add it to the map m_endDeviceStatuses.insert( diff --git a/model/one-shot-sender.cc b/model/one-shot-sender.cc index af7d0000dc..c9f5609ad7 100644 --- a/model/one-shot-sender.cc +++ b/model/one-shot-sender.cc @@ -78,7 +78,7 @@ OneShotSender::StartApplication() if (!m_mac) { // Assumes there's only one device - Ptr loraNetDevice = m_node->GetDevice(0)->GetObject(); + Ptr loraNetDevice = DynamicCast(m_node->GetDevice(0)); m_mac = loraNetDevice->GetMac(); NS_ASSERT(m_mac); diff --git a/model/periodic-sender.cc b/model/periodic-sender.cc index 113c7e4576..e5b296fa70 100644 --- a/model/periodic-sender.cc +++ b/model/periodic-sender.cc @@ -126,7 +126,7 @@ PeriodicSender::StartApplication() if (!m_mac) { // Assumes there's only one device - Ptr loraNetDevice = m_node->GetDevice(0)->GetObject(); + Ptr loraNetDevice = DynamicCast(m_node->GetDevice(0)); m_mac = loraNetDevice->GetMac(); NS_ASSERT(m_mac); diff --git a/test/lorawan-test-suite.cc b/test/lorawan-test-suite.cc index 8fb2306d8a..c3e3d1d7e5 100644 --- a/test/lorawan-test-suite.cc +++ b/test/lorawan-test-suite.cc @@ -346,7 +346,7 @@ HeaderTest::DoRun() // Deserialization frameHdr.Deserialize(serialized); - Ptr command = (*(frameHdr.GetCommands().begin()))->GetObject(); + Ptr command = DynamicCast(*frameHdr.GetCommands().begin()); uint8_t margin = command->GetMargin(); uint8_t gwCnt = command->GetGwCnt(); @@ -388,8 +388,7 @@ HeaderTest::DoRun() frameHdr1.SetAsDownlink(); pkt->RemoveHeader(frameHdr1); - Ptr linkCheckAns = - (*(frameHdr1.GetCommands().begin()))->GetObject(); + Ptr linkCheckAns = DynamicCast(*frameHdr1.GetCommands().begin()); NS_TEST_EXPECT_MSG_EQ((pkt->GetSize()), 10, @@ -1404,8 +1403,8 @@ PhyConnectivityTest::DoRun() txParams.sf = 7; edPhy2->SetSpreadingFactor(7); - edPhy2->GetMobility()->GetObject()->SetPosition( - Vector(2990, 0, 0)); + DynamicCast(edPhy2->GetMobility()) + ->SetPosition(Vector(2990, 0, 0)); Simulator::Schedule(Seconds(2), &SimpleEndDeviceLoraPhy::Send, @@ -1429,8 +1428,8 @@ PhyConnectivityTest::DoRun() // Try again using a packet with higher spreading factor txParams.sf = 8; edPhy2->SetSpreadingFactor(8); - edPhy2->GetMobility()->GetObject()->SetPosition( - Vector(2990, 0, 0)); + DynamicCast(edPhy2->GetMobility()) + ->SetPosition(Vector(2990, 0, 0)); Simulator::Schedule(Seconds(2), &SimpleEndDeviceLoraPhy::Send, diff --git a/test/network-server-test-suite.cc b/test/network-server-test-suite.cc index 436c2ad0ac..46f19ddf45 100644 --- a/test/network-server-test-suite.cc +++ b/test/network-server-test-suite.cc @@ -183,10 +183,8 @@ DownlinkPacketTest::SendPacket(Ptr endDevice, bool requestAck) { if (requestAck) { - endDevice->GetDevice(0) - ->GetObject() - ->GetMac() - ->GetObject() + DynamicCast( + DynamicCast(endDevice->GetDevice(0))->GetMac()) ->SetMType(LorawanMacHeader::CONFIRMED_DATA_UP); } endDevice->GetDevice(0)->Send(Create(20), Address(), 0); @@ -208,11 +206,8 @@ DownlinkPacketTest::DoRun() Ptr nsNode = components.nsNode; // Connect the end device's trace source for received packets - endDevices.Get(0) - ->GetDevice(0) - ->GetObject() - ->GetMac() - ->GetObject() + DynamicCast( + DynamicCast(endDevices.Get(0)->GetDevice(0))->GetMac()) ->TraceConnectWithoutContext( "RequiredTransmissions", MakeCallback(&DownlinkPacketTest::ReceivedPacketAtEndDevice, this)); @@ -288,10 +283,8 @@ LinkCheckTest::LastKnownGatewayCount(int newValue, int oldValue) void LinkCheckTest::SendPacket(Ptr endDevice, bool requestAck) { - Ptr macLayer = endDevice->GetDevice(0) - ->GetObject() - ->GetMac() - ->GetObject(); + Ptr macLayer = DynamicCast( + DynamicCast(endDevice->GetDevice(0))->GetMac()); if (requestAck) { @@ -319,11 +312,8 @@ LinkCheckTest::DoRun() Ptr nsNode = components.nsNode; // Connect the end device's trace source for last known gateway count - endDevices.Get(0) - ->GetDevice(0) - ->GetObject() - ->GetMac() - ->GetObject() + DynamicCast( + DynamicCast(endDevices.Get(0)->GetDevice(0))->GetMac()) ->TraceConnectWithoutContext("LastKnownGatewayCount", MakeCallback(&LinkCheckTest::LastKnownGatewayCount, this)); diff --git a/test/utilities.h b/test/utilities.h index 2296652424..a496136e15 100644 --- a/test/utilities.h +++ b/test/utilities.h @@ -45,7 +45,7 @@ template Ptr GetMacLayerFromNode(Ptr n) { - return n->GetDevice(0)->GetObject()->GetMac()->GetObject(); + return DynamicCast(DynamicCast(n->GetDevice(0))->GetMac()); } NetworkComponents InitializeNetwork(int nDevices, int nGateways);