25#include "ns3/command-line.h"
26#include "ns3/config.h"
27#include "ns3/core-module.h"
28#include "ns3/forwarder-helper.h"
29#include "ns3/gateway-lora-phy.h"
30#include "ns3/hex-grid-position-allocator.h"
32#include "ns3/lora-channel.h"
33#include "ns3/lora-device-address-generator.h"
34#include "ns3/lora-helper.h"
35#include "ns3/lora-phy-helper.h"
36#include "ns3/lorawan-mac-helper.h"
37#include "ns3/mobility-helper.h"
38#include "ns3/network-module.h"
39#include "ns3/network-server-helper.h"
40#include "ns3/periodic-sender-helper.h"
41#include "ns3/periodic-sender.h"
42#include "ns3/point-to-point-module.h"
43#include "ns3/random-variable-stream.h"
44#include "ns3/rectangle.h"
45#include "ns3/string.h"
48using namespace lorawan;
61 NS_LOG_DEBUG(
"DR" <<
unsigned(oldDr) <<
" -> DR" <<
unsigned(newDr));
73 NS_LOG_DEBUG(oldTxPower <<
" dBm -> " << newTxPower <<
" dBm");
77main(
int argc,
char* argv[])
80 bool adrEnabled =
true;
81 bool initializeSF =
false;
83 int nPeriodsOf20Minutes = 20;
84 double mobileNodeProbability = 0;
85 double sideLengthMeters = 10000;
86 int gatewayDistanceMeters = 5000;
87 double maxRandomLossDB = 10;
88 double minSpeedMetersPerSecond = 2;
89 double maxSpeedMetersPerSecond = 16;
90 std::string adrType =
"ns3::AdrComponent";
93 cmd.AddValue(
"verbose",
"Whether to print output or not",
verbose);
94 cmd.AddValue(
"MultipleGwCombiningMethod",
"ns3::AdrComponent::MultipleGwCombiningMethod");
95 cmd.AddValue(
"MultiplePacketsCombiningMethod",
96 "ns3::AdrComponent::MultiplePacketsCombiningMethod");
97 cmd.AddValue(
"HistoryRange",
"ns3::AdrComponent::HistoryRange");
98 cmd.AddValue(
"MType",
"ns3::EndDeviceLorawanMac::MType");
99 cmd.AddValue(
"EDDRAdaptation",
"ns3::EndDeviceLorawanMac::EnableEDDataRateAdaptation");
100 cmd.AddValue(
"ChangeTransmissionPower",
"ns3::AdrComponent::ChangeTransmissionPower");
101 cmd.AddValue(
"AdrEnabled",
"Whether to enable Adaptive Data Rate (ADR)", adrEnabled);
102 cmd.AddValue(
"nDevices",
"Number of devices to simulate",
nDevices);
103 cmd.AddValue(
"PeriodsToSimulate",
"Number of periods (20m) to simulate", nPeriodsOf20Minutes);
104 cmd.AddValue(
"MobileNodeProbability",
105 "Probability of a node being a mobile node",
106 mobileNodeProbability);
107 cmd.AddValue(
"sideLength",
108 "Length (m) of the side of the rectangle nodes will be placed in",
110 cmd.AddValue(
"maxRandomLoss",
111 "Maximum amount (dB) of the random loss component",
113 cmd.AddValue(
"gatewayDistance",
"Distance (m) between gateways", gatewayDistanceMeters);
114 cmd.AddValue(
"initializeSF",
"Whether to initialize the SFs", initializeSF);
115 cmd.AddValue(
"MinSpeed",
"Minimum speed (m/s) for mobile devices", minSpeedMetersPerSecond);
116 cmd.AddValue(
"MaxSpeed",
"Maximum speed (m/s) for mobile devices", maxSpeedMetersPerSecond);
117 cmd.AddValue(
"MaxTransmissions",
"ns3::EndDeviceLorawanMac::MaxTransmissions");
118 cmd.Parse(argc, argv);
120 int gatewayRings = 2 + (std::sqrt(2) * sideLengthMeters) / (gatewayDistanceMeters);
121 int nGateways = 3 * gatewayRings * gatewayRings - 3 * gatewayRings + 1;
152 loss->SetPathLossExponent(3.76);
153 loss->SetReference(1, 7.7);
162 loss->SetNext(randomLoss);
176 PointerValue(CreateObjectWithAttributes<UniformRandomVariable>(
182 PointerValue(CreateObjectWithAttributes<UniformRandomVariable>(
198 CreateObject<HexGridPositionAllocator>(gatewayDistanceMeters / 2);
224 helper.
Install(phyHelper, macHelper, gateways);
234 int fixedPositionNodes =
double(
nDevices) * (1 - mobileNodeProbability);
235 for (
int i = 0; i < fixedPositionNodes; ++i)
241 "ns3::RandomWalk2dMobilityModel",
244 Rectangle(-sideLengthMeters, sideLengthMeters, -sideLengthMeters, sideLengthMeters)),
248 PointerValue(CreateObjectWithAttributes<UniformRandomVariable>(
253 for (
int i = fixedPositionNodes; i < (int)endDevices.
GetN(); ++i)
262 CreateObject<LoraDeviceAddressGenerator>(nwkId, nwkAddr);
269 helper.
Install(phyHelper, macHelper, endDevices);
287 Ptr<Node> networkServer = CreateObject<Node>();
295 for (
auto gw = gateways.
Begin(); gw != gateways.
End(); ++gw)
298 auto serverP2PNetDev = DynamicCast<PointToPointNetDevice>(
container.Get(0));
299 gwRegistration.emplace_back(serverP2PNetDev, *gw);
304 networkServerHelper.
EnableAdr(adrEnabled);
305 networkServerHelper.
SetAdr(adrType);
308 networkServerHelper.
Install(networkServer);
312 forwarderHelper.
Install(gateways);
316 "/NodeList/*/DeviceList/0/$ns3::LoraNetDevice/Mac/$ns3::EndDeviceLorawanMac/TxPower",
319 "/NodeList/*/DeviceList/0/$ns3::LoraNetDevice/Mac/$ns3::EndDeviceLorawanMac/DataRate",
334 Time simulationTime =
Seconds(1200 * nPeriodsOf20Minutes);
340 Seconds(1200 * (nPeriodsOf20Minutes - 1)))
holds a vector of ns3::Application pointers.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Build a set of PointToPointNetDevice objects.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
This class can be used to install Forwarder applications on a set of gateways.
ApplicationContainer Install(NodeContainer c) const
Install a Forwarder application on each node of the input container configured with all the attribute...
Helps to create LoraNetDevice objects.
void EnablePeriodicDeviceStatusPrinting(NodeContainer endDevices, NodeContainer gateways, std::string filename, Time interval)
Periodically prints the status of devices in the network to a file.
void EnablePeriodicPhyPerformancePrinting(NodeContainer gateways, std::string filename, Time interval)
Periodically prints PHY-level performance at every gateway in the container.
void EnablePacketTracking()
Enable tracking of packets via trace sources.
LoraPacketTracker & GetPacketTracker()
Get a reference to the Packet Tracker object.
virtual NetDeviceContainer Install(const LoraPhyHelper &phyHelper, const LorawanMacHelper &macHelper, NodeContainer c) const
Install LoraNetDevices on a list of nodes.
void EnablePeriodicGlobalPerformancePrinting(std::string filename, Time interval)
Periodically print global performance as the total number of send and received packets.
Tracks and stores packets sent in the simulation and provides aggregation functionality.
std::string CountMacPacketsGlobally(Time startTime, Time stopTime)
In a time interval, count packets to evaluate the global performance at MAC level of the whole networ...
Helper to install LoraPhy instances on multiple Nodes.
void SetDeviceType(enum DeviceType dt)
Set the kind of PHY this helper will create.
void SetChannel(Ptr< LoraChannel > channel)
Set the LoraChannel to connect the PHYs to.
Helper class for configuring and installing the LorawanMac class on devices and gateways.
void SetDeviceType(enum DeviceType dt)
Set the kind of MAC this helper will create.
void SetAddressGenerator(Ptr< LoraDeviceAddressGenerator > addrGen)
Set the address generator to use for creation of these nodes.
static std::vector< int > SetSpreadingFactorsUp(NodeContainer endDevices, NodeContainer gateways, Ptr< LoraChannel > channel)
Initialize the end devices' data rate parameter.
void SetRegion(enum Regions region)
Set the region in which the device is to operate.
This class can install a NetworkServer application on a node.
void EnableAdr(bool enableAdr)
Enable (true) or disable (false) the Adaptive Data Rate (ADR) component in the Network Server created...
void SetGatewaysP2P(const P2PGwRegistration_t ®istration)
Register gateways connected with point-to-point to this network server.
void SetEndDevices(NodeContainer endDevices)
Set which end devices will be managed by this network server.
void SetAdr(std::string type)
Set the Adaptive Data Rate (ADR) implementation to use in the network server created by this helper.
ApplicationContainer Install(Ptr< Node > node)
Create one lorawan network server application on the Node.
This class can be used to install PeriodicSender applications on a wide range of nodes.
void SetPeriod(Time period)
Set the period to be used by the applications created by this helper.
ApplicationContainer Install(NodeContainer c) const
Install a PeriodicSender application on each node of the input container configured with all the attr...
int nDevices
Number of end device nodes to create.
int nGateways
Number of gateway nodes to create.
int appPeriodSeconds
Duration (s) of the inter-transmission time of end devices.
void SetDefault(std::string name, const AttributeValue &value)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
std::list< std::pair< Ptr< PointToPointNetDevice >, Ptr< Node > > > P2PGwRegistration_t
Store network server app registration details for gateway nodes having a P2P link with the network se...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
void OnDataRateChange(uint8_t oldDr, uint8_t newDr)
Record a change in the data rate setting on an end device.
void OnTxPowerChange(double oldTxPower, double newTxPower)
Record a change in the transmission power setting on an end device.