Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MAC command tests and improve MAC layer implementation #183

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2b7e8db
Comment out logging in tests
non-det-alle Nov 8, 2024
fd2721c
Refactor DB to Db for consistency
non-det-alle Nov 8, 2024
d541034
Refactor m_controlDataRate/DataRateAdaptation to ADR bit as in LoRaWA…
non-det-alle Nov 9, 2024
56062ee
Add Margin unit of measure & getters for Margin and GwCnt
non-det-alle Nov 11, 2024
913c6a0
Fit LinkAdrReq MAC command to specifications and remove regional depe…
non-det-alle Nov 9, 2024
ae19631
Refactor MaxNumbTx to NbTrans as in LoRaWAN specifications + correct …
non-det-alle Nov 11, 2024
10a9d30
Tx power should be converted to dBm ERP, not EIRP
non-det-alle Nov 11, 2024
4820c07
Avoid Object initialization for MAC commands (CreateObject -> Create)
non-det-alle Nov 11, 2024
8b35719
Rewrite OnLinkAdrReq from reputable source
non-det-alle Nov 11, 2024
fa9c56d
Tx power dBm values to double + more robust GetTxPowerIndex impl
non-det-alle Nov 11, 2024
0b1c56a
LoRaWAN Headers: store MAC commands to vector instead of list, clean-…
non-det-alle Nov 12, 2024
4c8bf62
Add getters to LinkAdrAns MAC command
non-det-alle Nov 12, 2024
f682b99
LinkCheckAns and LinkAdrReq tests
non-det-alle Nov 12, 2024
20c554a
DutyCycleReq: align terminology with specs, move logic from header to…
non-det-alle Nov 12, 2024
941bbc3
NS_TEST_ASSERT_MSG_EQ where needed
non-det-alle Nov 12, 2024
c23c76b
Fix MAC command frequency encoding endianness
non-det-alle Nov 12, 2024
71b9403
RxParamSetupReq: add RxParamSetupAns getters, clean-up, fix frequency…
non-det-alle Nov 12, 2024
fb62480
DevStatusReq: implementation and tests
non-det-alle Nov 12, 2024
2ef7c23
(hopefully) annotate all frequency variables with MHz/Hz
non-det-alle Nov 13, 2024
f5bdabc
Isolate unit test scope, add LinkAdrAns/RxParamSetupAns creation prin…
non-det-alle Nov 13, 2024
ed4389f
Refactor Create to Install in LoraPhyHelper and LorawanMacHelper to a…
non-det-alle Nov 13, 2024
76e9f6f
Evaluate null Ptr in return statements as indicated by the Ptr class …
non-det-alle Nov 14, 2024
4e5ea77
Rework the SubBand class
non-det-alle Nov 16, 2024
2f15be8
Rework the LogicalLoraChannel class
non-det-alle Nov 17, 2024
62b3942
LinkCheckAns: Fill margin field with meaningful values
non-det-alle Nov 18, 2024
0f49026
Rework LogicalLoraChannelHelper class
non-det-alle Nov 18, 2024
3cd45a2
Rework MacCommand classes
non-det-alle Nov 17, 2024
3118f99
Refactor waitingTime to waitTime (English proofing)
non-det-alle Nov 17, 2024
8519d4a
Rework EndDeviceLorawanMac class
non-det-alle Nov 18, 2024
d60bb4c
More LinkAdrReq test cases + use actual device matrix to test RX1Offs…
non-det-alle Nov 17, 2024
b65e958
Implement OnNewChannelReq and add MAC command test cases
non-det-alle Nov 17, 2024
7690863
Time-related code improvements
non-det-alle Nov 18, 2024
7377e2b
Fix new doxygen warnings
non-det-alle Nov 18, 2024
ee04065
Address clang-tidy-18 warnings
non-det-alle Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/adr-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ main(int argc, char* argv[])
double mobileNodeProbability = 0;
double sideLengthMeters = 10000;
int gatewayDistanceMeters = 5000;
double maxRandomLossDB = 10;
double maxRandomLossDb = 10;
double minSpeedMetersPerSecond = 2;
double maxSpeedMetersPerSecond = 16;
std::string adrType = "ns3::AdrComponent";
Expand All @@ -98,7 +98,7 @@ main(int argc, char* argv[])
sideLengthMeters);
cmd.AddValue("maxRandomLoss",
"Maximum amount (dB) of the random loss component",
maxRandomLossDB);
maxRandomLossDb);
cmd.AddValue("gatewayDistance", "Distance (m) between gateways", gatewayDistanceMeters);
cmd.AddValue("initializeSF", "Whether to initialize the SFs", initializeSF);
cmd.AddValue("MinSpeed", "Minimum speed (m/s) for mobile devices", minSpeedMetersPerSecond);
Expand Down Expand Up @@ -132,7 +132,7 @@ main(int argc, char* argv[])

// Set the end devices to allow data rate control (i.e. adaptive data rate) from the network
// server
Config::SetDefault("ns3::EndDeviceLorawanMac::DRControl", BooleanValue(true));
Config::SetDefault("ns3::EndDeviceLorawanMac::ADR", BooleanValue(true));

// Create a simple wireless channel
///////////////////////////////////
Expand All @@ -143,7 +143,7 @@ main(int argc, char* argv[])

Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable>();
x->SetAttribute("Min", DoubleValue(0.0));
x->SetAttribute("Max", DoubleValue(maxRandomLossDB));
x->SetAttribute("Max", DoubleValue(maxRandomLossDb));

Ptr<RandomPropagationLossModel> randomLoss = CreateObject<RandomPropagationLossModel>();
randomLoss->SetAttribute("Variable", PointerValue(x));
Expand Down
2 changes: 1 addition & 1 deletion examples/aloha-throughput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ main(int argc, char* argv[])
appHelper.SetPacketSize(packetSize);
ApplicationContainer appContainer = appHelper.Install(endDevices);

appContainer.Start(Seconds(0));
appContainer.Start(Time(0));
appContainer.Stop(appStopTime);

std::ofstream outputFile;
Expand Down
4 changes: 2 additions & 2 deletions examples/complete-network-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ main(int argc, char* argv[])
DoubleValue(10));
ApplicationContainer appContainer = appHelper.Install(endDevices);

appContainer.Start(Seconds(0));
appContainer.Start(Time(0));
appContainer.Stop(appStopTime);

/**************************
Expand Down Expand Up @@ -353,7 +353,7 @@ main(int argc, char* argv[])
NS_LOG_INFO("Computing performance metrics...");

LoraPacketTracker& tracker = helper.GetPacketTracker();
std::cout << tracker.CountMacPacketsGlobally(Seconds(0), appStopTime + Hours(1)) << std::endl;
std::cout << tracker.CountMacPacketsGlobally(Time(0), appStopTime + Hours(1)) << std::endl;

return 0;
}
6 changes: 3 additions & 3 deletions examples/frame-counter-update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ main(int argc, char* argv[])

Time appStopTime = Seconds(simulationTimeSeconds);
OneShotSenderHelper appHelper = OneShotSenderHelper();
appHelper.SetSendTime(Seconds(0));
appHelper.SetSendTime(Time(0));
ApplicationContainer appContainer = appHelper.Install(endDevices);
appHelper.SetSendTime(Seconds(100));
appContainer.Add(appHelper.Install(endDevices));
appHelper.SetSendTime(Seconds(200));
appContainer.Add(appHelper.Install(endDevices));

appContainer.Start(Seconds(0));
appContainer.Start(Time(0));
appContainer.Stop(appStopTime);

Simulator::Schedule(Seconds(110), &ChangeEndDevicePosition, endDevices.Get(0), true);
Expand Down Expand Up @@ -298,7 +298,7 @@ main(int argc, char* argv[])

LoraPacketTracker& tracker = helper.GetPacketTracker();
NS_LOG_INFO("Printing total sent MAC-layer packets and successful MAC-layer packets");
std::cout << tracker.CountMacPacketsGlobally(Seconds(0), appStopTime + Hours(1)) << std::endl;
std::cout << tracker.CountMacPacketsGlobally(Time(0), appStopTime + Hours(1)) << std::endl;

return 0;
}
39 changes: 19 additions & 20 deletions helper/lora-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
NS_LOG_COMPONENT_DEFINE("LoraHelper");

LoraHelper::LoraHelper()
: m_lastPhyPerformanceUpdate(Seconds(0)),
m_lastGlobalPerformanceUpdate(Seconds(0))
: m_lastPhyPerformanceUpdate(Time(0)),
m_lastGlobalPerformanceUpdate(Time(0))
{
}

Expand All @@ -47,7 +47,7 @@
Ptr<LoraNetDevice> device = CreateObject<LoraNetDevice>();

// Create the PHY
Ptr<LoraPhy> phy = phyHelper.Create(node, device);
Ptr<LoraPhy> phy = phyHelper.Install(node, device);
NS_ASSERT(phy);
device->SetPhy(phy);
NS_LOG_DEBUG("Done creating the PHY");
Expand Down Expand Up @@ -85,7 +85,7 @@
}

// Create the MAC
Ptr<LorawanMac> mac = macHelper.Create(node, device);
Ptr<LorawanMac> mac = macHelper.Install(node, device);
NS_ASSERT(mac);
mac->SetPhy(phy);
NS_LOG_DEBUG("Done creating the MAC");
Expand Down Expand Up @@ -151,7 +151,7 @@
LoraHelper::EnableSimulationTimePrinting(Time interval)
{
m_oldtime = std::time(nullptr);
Simulator::Schedule(Seconds(0), &LoraHelper::DoPrintSimulationTime, this, interval);
Simulator::Schedule(Time(0), &LoraHelper::DoPrintSimulationTime, this, interval);

Check warning on line 154 in helper/lora-helper.cc

View check run for this annotation

Codecov / codecov/patch

helper/lora-helper.cc#L154

Added line #L154 was not covered by tests
}

void
Expand Down Expand Up @@ -181,7 +181,7 @@
{
const char* c = filename.c_str();
std::ofstream outputFile;
if (Simulator::Now() == Seconds(0))
if (Now().IsZero())
{
// Delete contents of the file as it is opened
outputFile.open(c, std::ofstream::out | std::ofstream::trunc);
Expand All @@ -192,7 +192,7 @@
outputFile.open(c, std::ofstream::out | std::ofstream::app);
}

Time currentTime = Simulator::Now();
Time currentTime = Now();
for (auto j = endDevices.Begin(); j != endDevices.End(); ++j)
{
Ptr<Node> object = *j;
Expand All @@ -204,9 +204,9 @@
Ptr<ClassAEndDeviceLorawanMac> mac =
DynamicCast<ClassAEndDeviceLorawanMac>(loraNetDevice->GetMac());
int dr = int(mac->GetDataRate());
double txPower = mac->GetTransmissionPower();
double txPower = mac->GetTransmissionPowerDbm();
Vector pos = position->GetPosition();
outputFile << currentTime.GetSeconds() << " " << object->GetId() << " " << pos.x << " "
outputFile << currentTime.As(Time::S) << " " << object->GetId() << " " << pos.x << " "
<< pos.y << " " << dr << " " << unsigned(txPower) << std::endl;
}
// for (NodeContainer::Iterator j = gateways.Begin (); j != gateways.End (); ++j)
Expand Down Expand Up @@ -245,7 +245,7 @@

const char* c = filename.c_str();
std::ofstream outputFile;
if (Simulator::Now() == Seconds(0))
if (Now().IsZero())
{
// Delete contents of the file as it is opened
outputFile.open(c, std::ofstream::out | std::ofstream::trunc);
Expand All @@ -259,14 +259,14 @@
for (auto it = gateways.Begin(); it != gateways.End(); ++it)
{
int systemId = (*it)->GetId();
outputFile << Simulator::Now().GetSeconds() << " " << std::to_string(systemId) << " "
outputFile << Now().As(Time::S) << " " << std::to_string(systemId) << " "
<< m_packetTracker->PrintPhyPacketsPerGw(m_lastPhyPerformanceUpdate,
Simulator::Now(),
Now(),
systemId)
<< std::endl;
}

m_lastPhyPerformanceUpdate = Simulator::Now();
m_lastPhyPerformanceUpdate = Now();

outputFile.close();
}
Expand All @@ -292,7 +292,7 @@

const char* c = filename.c_str();
std::ofstream outputFile;
if (Simulator::Now() == Seconds(0))
if (Now().IsZero())
{
// Delete contents of the file as it is opened
outputFile.open(c, std::ofstream::out | std::ofstream::trunc);
Expand All @@ -303,21 +303,20 @@
outputFile.open(c, std::ofstream::out | std::ofstream::app);
}

outputFile << Simulator::Now().GetSeconds() << " "
<< m_packetTracker->CountMacPacketsGlobally(m_lastGlobalPerformanceUpdate,
Simulator::Now())
outputFile << Now().As(Time::S) << " "
<< m_packetTracker->CountMacPacketsGlobally(m_lastGlobalPerformanceUpdate, Now())
<< std::endl;

m_lastGlobalPerformanceUpdate = Simulator::Now();
m_lastGlobalPerformanceUpdate = Now();

outputFile.close();
}

void
LoraHelper::DoPrintSimulationTime(Time interval)
{
// NS_LOG_INFO ("Time: " << Simulator::Now().GetHours());
std::cout << "Simulated time: " << Simulator::Now().GetHours() << " hours" << std::endl;
// NS_LOG_INFO ("Time: " << Now().As(Time::H));
std::cout << "Simulated time: " << Now().As(Time::H) << std::endl;

Check warning on line 319 in helper/lora-helper.cc

View check run for this annotation

Codecov / codecov/patch

helper/lora-helper.cc#L319

Added line #L319 was not covered by tests
std::cout << "Real time from last call: " << std::time(nullptr) - m_oldtime << " seconds"
<< std::endl;
m_oldtime = std::time(nullptr);
Expand Down
10 changes: 5 additions & 5 deletions helper/lora-packet-tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LoraPacketTracker::MacTransmissionCallback(Ptr<const Packet> packet)

MacPacketStatus status;
status.packet = packet;
status.sendTime = Simulator::Now();
status.sendTime = Now();
status.senderId = Simulator::GetContext();
status.receivedTime = Time::Max();

Expand All @@ -60,11 +60,11 @@ LoraPacketTracker::RequiredTransmissionsCallback(uint8_t reqTx,
{
NS_LOG_INFO("Finished retransmission attempts for a packet");
NS_LOG_DEBUG("Packet: " << packet << "ReqTx " << unsigned(reqTx) << ", succ: " << success
<< ", firstAttempt: " << firstAttempt.GetSeconds());
<< ", firstAttempt: " << firstAttempt.As(Time::S));

RetransmissionStatus entry;
entry.firstAttempt = firstAttempt;
entry.finishTime = Simulator::Now();
entry.finishTime = Now();
entry.reTxAttempts = reqTx;
entry.successful = success;

Expand All @@ -84,7 +84,7 @@ LoraPacketTracker::MacGwReceptionCallback(Ptr<const Packet> packet)
if (it != m_macPacketTracker.end())
{
(*it).second.receptionTimes.insert(
std::pair<int, Time>(Simulator::GetContext(), Simulator::Now()));
std::pair<int, Time>(Simulator::GetContext(), Now()));
}
else
{
Expand All @@ -106,7 +106,7 @@ LoraPacketTracker::TransmissionCallback(Ptr<const Packet> packet, uint32_t edId)
// Create a packetStatus
PacketStatus status;
status.packet = packet;
status.sendTime = Simulator::Now();
status.sendTime = Now();
status.senderId = edId;

m_packetTracker.insert(std::pair<Ptr<const Packet>, PacketStatus>(packet, status));
Expand Down
2 changes: 1 addition & 1 deletion helper/lora-phy-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ LoraPhyHelper::Set(std::string name, const AttributeValue& v)
}

Ptr<LoraPhy>
LoraPhyHelper::Create(Ptr<Node> node, Ptr<NetDevice> device) const
LoraPhyHelper::Install(Ptr<Node> node, Ptr<NetDevice> device) const
{
NS_LOG_FUNCTION(this << node->GetId() << device);

Expand Down
2 changes: 1 addition & 1 deletion helper/lora-phy-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LoraPhyHelper
* \param device The device within which this PHY will be created.
* \return A newly-created PHY object.
*/
Ptr<LoraPhy> Create(Ptr<Node> node, Ptr<NetDevice> device) const;
Ptr<LoraPhy> Install(Ptr<Node> node, Ptr<NetDevice> device) const;

/**
* Set the maximum number of gateway receive paths.
Expand Down
Loading