Fix misuse of Create<>() function

If Create<>() is used to create an object of an Object subclass,
attributes are not initialized.
This commit is contained in:
Stefano Avallone
2025-06-11 20:23:36 +02:00
parent f315c12d8d
commit 8adca5d42d
17 changed files with 35 additions and 34 deletions

View File

@@ -104,7 +104,7 @@ BuildingsChannelConditionModelTestCase::DoRun()
Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel>(); Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel>();
Ptr<Building> building = Create<Building>(); auto building = CreateObject<Building>();
building->SetNRoomsX(1); building->SetNRoomsX(1);
building->SetNRoomsY(1); building->SetNRoomsY(1);
building->SetNFloors(1); building->SetNFloors(1);

View File

@@ -174,7 +174,7 @@ BuildingsPenetrationLossesTestCase::DoRun()
// create the factory for the propagation loss model // create the factory for the propagation loss model
ObjectFactory propModelFactory; ObjectFactory propModelFactory;
Ptr<Building> building = Create<Building>(); auto building = CreateObject<Building>();
building->SetExtWallsType(Building::ExtWallsType_t::ConcreteWithWindows); building->SetExtWallsType(Building::ExtWallsType_t::ConcreteWithWindows);
building->SetNRoomsX(1); building->SetNRoomsX(1);
building->SetNRoomsY(1); building->SetNRoomsY(1);

View File

@@ -136,7 +136,7 @@ ThreeGppV2vBuildingsChCondModelTestCase::DoRun()
Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>(); Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
nodes.Get(1)->AggregateObject(b); nodes.Get(1)->AggregateObject(b);
Ptr<Building> building = Create<Building>(); auto building = CreateObject<Building>();
building->SetNRoomsX(1); building->SetNRoomsX(1);
building->SetNRoomsY(1); building->SetNRoomsY(1);
building->SetNFloors(1); building->SetNFloors(1);

View File

@@ -1880,7 +1880,7 @@ PointerAttributeTestCase::DoRun()
// Now, lets create an Object of type Derived and set the local Ptr to point // Now, lets create an Object of type Derived and set the local Ptr to point
// to that object. We can then set the PointerValue Attribute to that Ptr. // to that object. We can then set the PointerValue Attribute to that Ptr.
// //
derived = Create<Derived>(); derived = CreateObject<Derived>();
bool ok = p->SetAttributeFailSafe("Pointer", PointerValue(derived)); bool ok = p->SetAttributeFailSafe("Pointer", PointerValue(derived));
NS_TEST_ASSERT_MSG_EQ(ok, NS_TEST_ASSERT_MSG_EQ(ok,
true, true,

View File

@@ -85,15 +85,16 @@ FlowMonitorHelper::Install(Ptr<Node> node)
Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol>(); Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol>();
if (ipv4) if (ipv4)
{ {
Ptr<Ipv4FlowProbe> probe = auto probe =
Create<Ipv4FlowProbe>(monitor, DynamicCast<Ipv4FlowClassifier>(classifier), node); CreateObject<Ipv4FlowProbe>(monitor, DynamicCast<Ipv4FlowClassifier>(classifier), node);
} }
Ptr<FlowClassifier> classifier6 = GetClassifier6(); Ptr<FlowClassifier> classifier6 = GetClassifier6();
Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol>(); Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol>();
if (ipv6) if (ipv6)
{ {
Ptr<Ipv6FlowProbe> probe6 = auto probe6 = CreateObject<Ipv6FlowProbe>(monitor,
Create<Ipv6FlowProbe>(monitor, DynamicCast<Ipv6FlowClassifier>(classifier6), node); DynamicCast<Ipv6FlowClassifier>(classifier6),
node);
} }
return m_flowMonitor; return m_flowMonitor;
} }

View File

@@ -70,7 +70,7 @@ main(int argc, char* argv[])
std::vector<Vector> enbPosition; std::vector<Vector> enbPosition;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>(); Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
Ptr<Building> building; Ptr<Building> building;
building = Create<Building>(); building = CreateObject<Building>();
building->SetBoundaries( building->SetBoundaries(
Box(0.0, nRooms * roomLength, 0.0, nRooms * roomLength, 0.0, roomHeight)); Box(0.0, nRooms * roomLength, 0.0, nRooms * roomLength, 0.0, roomHeight));
building->SetBuildingType(Building::Residential); building->SetBuildingType(Building::Residential);

View File

@@ -48,7 +48,7 @@ RemoteChannelBundleManager::Add(uint32_t systemId)
NS_ASSERT(!g_initialized); NS_ASSERT(!g_initialized);
NS_ASSERT(g_remoteChannelBundles.find(systemId) == g_remoteChannelBundles.end()); NS_ASSERT(g_remoteChannelBundles.find(systemId) == g_remoteChannelBundles.end());
Ptr<RemoteChannelBundle> remoteChannelBundle = Create<RemoteChannelBundle>(systemId); auto remoteChannelBundle = CreateObject<RemoteChannelBundle>(systemId);
g_remoteChannelBundles[systemId] = remoteChannelBundle; g_remoteChannelBundles[systemId] = remoteChannelBundle;

View File

@@ -56,7 +56,7 @@ Ptr<PacketBurst>
PacketBurst::Copy() const PacketBurst::Copy() const
{ {
NS_LOG_FUNCTION(this); NS_LOG_FUNCTION(this);
Ptr<PacketBurst> burst = Create<PacketBurst>(); Ptr<PacketBurst> burst = CreateObject<PacketBurst>();
for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter) for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
{ {

View File

@@ -237,7 +237,7 @@ main(int argc, char* argv[])
{ {
// Create a special Ipv4StaticRouting instance for RoutingTableAssociation // Create a special Ipv4StaticRouting instance for RoutingTableAssociation
// Even the Ipv4StaticRouting instance added to list may be used // Even the Ipv4StaticRouting instance added to list may be used
Ptr<Ipv4StaticRouting> hnaEntries = Create<Ipv4StaticRouting>(); Ptr<Ipv4StaticRouting> hnaEntries = CreateObject<Ipv4StaticRouting>();
// Add the required routes into the Ipv4StaticRouting Protocol instance // Add the required routes into the Ipv4StaticRouting Protocol instance
// and have the node generate HNA messages for all these routes // and have the node generate HNA messages for all these routes

View File

@@ -252,7 +252,7 @@ RoutingProtocol::RoutingProtocol()
{ {
m_uniformRandomVariable = CreateObject<UniformRandomVariable>(); m_uniformRandomVariable = CreateObject<UniformRandomVariable>();
m_hnaRoutingTable = Create<Ipv4StaticRouting>(); m_hnaRoutingTable = CreateObject<Ipv4StaticRouting>();
} }
RoutingProtocol::~RoutingProtocol() RoutingProtocol::~RoutingProtocol()

View File

@@ -2231,7 +2231,7 @@ OfdmaAckSequenceTest::DoRun()
{ {
// create a listening VHT station // create a listening VHT station
wifi.SetStandard(WIFI_STANDARD_80211ac); wifi.SetStandard(WIFI_STANDARD_80211ac);
wifi.Install(phy, mac, Create<Node>()); wifi.Install(phy, mac, CreateObject<Node>());
} }
wifi.SetStandard(m_scenario == WifiOfdmaScenario::HE ? WIFI_STANDARD_80211ax wifi.SetStandard(m_scenario == WifiOfdmaScenario::HE ? WIFI_STANDARD_80211ax

View File

@@ -622,7 +622,7 @@ BaseStationNetDevice::DoSend(Ptr<Packet> packet,
const Mac48Address& dest, const Mac48Address& dest,
uint16_t protocolNumber) uint16_t protocolNumber)
{ {
Ptr<PacketBurst> burst = Create<PacketBurst>(); Ptr<PacketBurst> burst = CreateObject<PacketBurst>();
ServiceFlow* serviceFlow = nullptr; ServiceFlow* serviceFlow = nullptr;
NS_LOG_INFO("BS (" << source << "):"); NS_LOG_INFO("BS (" << source << "):");

View File

@@ -164,7 +164,7 @@ BSSchedulerRtps::CreateUgsBurst(ServiceFlow* serviceFlow,
Time timeStamp; Time timeStamp;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
// serviceFlow->CleanUpQueue (); // serviceFlow->CleanUpQueue ();
@@ -211,7 +211,7 @@ BSSchedulerRtps::BSSchedulerBroadcastConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
while (GetBs()->GetBroadcastConnection()->HasPackets() && availableSymbols > 0) while (GetBs()->GetBroadcastConnection()->HasPackets() && availableSymbols > 0)
{ {
@@ -258,7 +258,7 @@ BSSchedulerRtps::BSSchedulerInitialRangingConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
while (GetBs()->GetInitialRangingConnection()->HasPackets() && availableSymbols > 0) while (GetBs()->GetInitialRangingConnection()->HasPackets() && availableSymbols > 0)
{ {
@@ -306,7 +306,7 @@ BSSchedulerRtps::BSSchedulerBasicConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
std::vector<Ptr<WimaxConnection>> connections; std::vector<Ptr<WimaxConnection>> connections;
@@ -353,7 +353,7 @@ BSSchedulerRtps::BSSchedulerBasicConnection(uint32_t& availableSymbols)
if (burst->GetNPackets() != 0) if (burst->GetNPackets() != 0)
{ {
AddDownlinkBurst(connection, diuc, modulationType, burst); AddDownlinkBurst(connection, diuc, modulationType, burst);
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
} }
} }
} }
@@ -367,7 +367,7 @@ BSSchedulerRtps::BSSchedulerPrimaryConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
std::vector<Ptr<WimaxConnection>> connections; std::vector<Ptr<WimaxConnection>> connections;
@@ -427,7 +427,7 @@ BSSchedulerRtps::BSSchedulerUGSConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
Time currentTime = Simulator::Now(); Time currentTime = Simulator::Now();
@@ -471,7 +471,7 @@ BSSchedulerRtps::BSSchedulerUGSConnection(uint32_t& availableSymbols)
AddDownlinkBurst(connection, diuc, modulationType, burst); AddDownlinkBurst(connection, diuc, modulationType, burst);
currentTime = Simulator::Now(); currentTime = Simulator::Now();
serviceFlowRecord->SetDlTimeStamp(currentTime); serviceFlowRecord->SetDlTimeStamp(currentTime);
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
} }
} }
} }
@@ -484,7 +484,7 @@ BSSchedulerRtps::BSSchedulerRTPSConnection(uint32_t& availableSymbols)
Ptr<WimaxConnection> connection; Ptr<WimaxConnection> connection;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
Time currentTime = Simulator::Now(); Time currentTime = Simulator::Now();
@@ -569,7 +569,7 @@ BSSchedulerRtps::BSSchedulerRTPSConnection(uint32_t& availableSymbols)
{ {
packet = rtPSConnection[i]->GetQueue()->Peek(hdr); packet = rtPSConnection[i]->GetQueue()->Peek(hdr);
uint32_t symbolsForPacketTransmission = 0; uint32_t symbolsForPacketTransmission = 0;
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
NS_LOG_INFO("\t\tCID = " << rtPSConnection[i]->GetCid() NS_LOG_INFO("\t\tCID = " << rtPSConnection[i]->GetCid()
<< " assignedSymbols = " << symbolsRequired[i]); << " assignedSymbols = " << symbolsRequired[i]);
@@ -627,7 +627,7 @@ BSSchedulerRtps::BSSchedulerNRTPSConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
std::vector<ServiceFlow*> serviceFlows; std::vector<ServiceFlow*> serviceFlows;
@@ -670,7 +670,7 @@ BSSchedulerRtps::BSSchedulerNRTPSConnection(uint32_t& availableSymbols)
if (burst->GetNPackets() != 0) if (burst->GetNPackets() != 0)
{ {
AddDownlinkBurst(connection, diuc, modulationType, burst); AddDownlinkBurst(connection, diuc, modulationType, burst);
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
} }
} }
} }
@@ -684,7 +684,7 @@ BSSchedulerRtps::BSSchedulerBEConnection(uint32_t& availableSymbols)
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
std::vector<ServiceFlow*> serviceFlows; std::vector<ServiceFlow*> serviceFlows;
@@ -726,7 +726,7 @@ BSSchedulerRtps::BSSchedulerBEConnection(uint32_t& availableSymbols)
if (burst->GetNPackets() != 0) if (burst->GetNPackets() != 0)
{ {
AddDownlinkBurst(connection, diuc, modulationType, burst); AddDownlinkBurst(connection, diuc, modulationType, burst);
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
} }
} }
} }

View File

@@ -175,7 +175,7 @@ BSSchedulerSimple::Schedule()
} }
else else
{ {
burst = Create<PacketBurst>(); burst = CreateObject<PacketBurst>();
while (connection->HasPackets()) while (connection->HasPackets())
{ {
uint32_t FirstPacketSize = connection->GetQueue()->GetFirstPacketRequiredByte( uint32_t FirstPacketSize = connection->GetQueue()->GetFirstPacketRequiredByte(
@@ -353,7 +353,7 @@ BSSchedulerSimple::CreateUgsBurst(ServiceFlow* serviceFlow,
Time timeStamp; Time timeStamp;
GenericMacHeader hdr; GenericMacHeader hdr;
Ptr<Packet> packet; Ptr<Packet> packet;
Ptr<PacketBurst> burst = Create<PacketBurst>(); auto burst = CreateObject<PacketBurst>();
uint32_t nrSymbolsRequired = 0; uint32_t nrSymbolsRequired = 0;
// serviceFlow->CleanUpQueue (); // serviceFlow->CleanUpQueue ();

View File

@@ -543,7 +543,7 @@ SimpleOfdmWimaxPhy::ConvertBitsToBurst(Bvec buffer)
j++; j++;
} }
uint16_t pos = 0; uint16_t pos = 0;
Ptr<PacketBurst> RecvBurst = Create<PacketBurst>(); Ptr<PacketBurst> RecvBurst = CreateObject<PacketBurst>();
while (pos < bufferSize) while (pos < bufferSize)
{ {
uint16_t packetSize = 0; uint16_t packetSize = 0;

View File

@@ -202,7 +202,7 @@ SSLinkManager::SendRangingRequest(uint8_t uiuc, uint16_t allocationSize)
} }
Ptr<Packet> packet = Create<Packet>(); Ptr<Packet> packet = Create<Packet>();
Ptr<PacketBurst> burst = Create<PacketBurst>(); Ptr<PacketBurst> burst = CreateObject<PacketBurst>();
packet->AddHeader(m_rngreq); packet->AddHeader(m_rngreq);
packet->AddHeader(ManagementMessageType(ManagementMessageType::MESSAGE_TYPE_RNG_REQ)); packet->AddHeader(ManagementMessageType(ManagementMessageType::MESSAGE_TYPE_RNG_REQ));

View File

@@ -70,7 +70,7 @@ SSScheduler::Schedule(uint16_t availableSymbols,
Ptr<WimaxConnection>& connection) Ptr<WimaxConnection>& connection)
{ {
Time timeStamp; Time timeStamp;
Ptr<PacketBurst> burst = Create<PacketBurst>(); Ptr<PacketBurst> burst = CreateObject<PacketBurst>();
uint16_t nrSymbolsRequired = 0; uint16_t nrSymbolsRequired = 0;
if (!connection) if (!connection)