14#include "ns3/command-line.h"
15#include "ns3/config.h"
16#include "ns3/core-module.h"
17#include "ns3/forwarder-helper.h"
18#include "ns3/gateway-lora-phy.h"
19#include "ns3/hex-grid-position-allocator.h"
21#include "ns3/lora-channel.h"
22#include "ns3/lora-device-address-generator.h"
23#include "ns3/lora-helper.h"
24#include "ns3/lora-phy-helper.h"
25#include "ns3/lorawan-mac-helper.h"
26#include "ns3/mobility-helper.h"
27#include "ns3/network-module.h"
28#include "ns3/network-server-helper.h"
29#include "ns3/periodic-sender-helper.h"
30#include "ns3/periodic-sender.h"
31#include "ns3/point-to-point-module.h"
32#include "ns3/random-variable-stream.h"
33#include "ns3/rectangle.h"
34#include "ns3/string.h"
37using namespace lorawan;
50 NS_LOG_DEBUG(
"DR" <<
unsigned(oldDr) <<
" -> DR" <<
unsigned(newDr));
62 NS_LOG_DEBUG(oldTxPower <<
" dBm -> " << newTxPower <<
" dBm");
66main(
int argc,
char* argv[])
69 bool adrEnabled =
true;
70 bool initializeSF =
false;
72 int nPeriodsOf20Minutes = 20;
73 double mobileNodeProbability = 0;
74 double sideLengthMeters = 10000;
75 int gatewayDistanceMeters = 5000;
76 double maxRandomLossDB = 10;
77 double minSpeedMetersPerSecond = 2;
78 double maxSpeedMetersPerSecond = 16;
79 std::string adrType =
"ns3::AdrComponent";
82 cmd.AddValue(
"verbose",
"Whether to print output or not",
verbose);
83 cmd.AddValue(
"MultipleGwCombiningMethod",
"ns3::AdrComponent::MultipleGwCombiningMethod");
84 cmd.AddValue(
"MultiplePacketsCombiningMethod",
85 "ns3::AdrComponent::MultiplePacketsCombiningMethod");
86 cmd.AddValue(
"HistoryRange",
"ns3::AdrComponent::HistoryRange");
87 cmd.AddValue(
"MType",
"ns3::EndDeviceLorawanMac::MType");
88 cmd.AddValue(
"EDDRAdaptation",
"ns3::EndDeviceLorawanMac::EnableEDDataRateAdaptation");
89 cmd.AddValue(
"ChangeTransmissionPower",
"ns3::AdrComponent::ChangeTransmissionPower");
90 cmd.AddValue(
"AdrEnabled",
"Whether to enable Adaptive Data Rate (ADR)", adrEnabled);
91 cmd.AddValue(
"nDevices",
"Number of devices to simulate",
nDevices);
92 cmd.AddValue(
"PeriodsToSimulate",
"Number of periods (20m) to simulate", nPeriodsOf20Minutes);
93 cmd.AddValue(
"MobileNodeProbability",
94 "Probability of a node being a mobile node",
95 mobileNodeProbability);
96 cmd.AddValue(
"sideLength",
97 "Length (m) of the side of the rectangle nodes will be placed in",
99 cmd.AddValue(
"maxRandomLoss",
100 "Maximum amount (dB) of the random loss component",
102 cmd.AddValue(
"gatewayDistance",
"Distance (m) between gateways", gatewayDistanceMeters);
103 cmd.AddValue(
"initializeSF",
"Whether to initialize the SFs", initializeSF);
104 cmd.AddValue(
"MinSpeed",
"Minimum speed (m/s) for mobile devices", minSpeedMetersPerSecond);
105 cmd.AddValue(
"MaxSpeed",
"Maximum speed (m/s) for mobile devices", maxSpeedMetersPerSecond);
106 cmd.AddValue(
"MaxTransmissions",
"ns3::EndDeviceLorawanMac::MaxTransmissions");
107 cmd.Parse(argc, argv);
109 int gatewayRings = 2 + (std::sqrt(2) * sideLengthMeters) / (gatewayDistanceMeters);
110 int nGateways = 3 * gatewayRings * gatewayRings - 3 * gatewayRings + 1;
141 loss->SetPathLossExponent(3.76);
142 loss->SetReference(1, 7.7);
151 loss->SetNext(randomLoss);
213 helper.
Install(phyHelper, macHelper, gateways);
223 int fixedPositionNodes =
double(
nDevices) * (1 - mobileNodeProbability);
224 for (
int i = 0; i < fixedPositionNodes; ++i)
230 "ns3::RandomWalk2dMobilityModel",
233 Rectangle(-sideLengthMeters, sideLengthMeters, -sideLengthMeters, sideLengthMeters)),
242 for (
int i = fixedPositionNodes; i < (int)endDevices.
GetN(); ++i)
258 helper.
Install(phyHelper, macHelper, endDevices);
284 for (
auto gw = gateways.
Begin(); gw != gateways.
End(); ++gw)
288 gwRegistration.emplace_back(serverP2PNetDev, *gw);
293 networkServerHelper.
EnableAdr(adrEnabled);
294 networkServerHelper.
SetAdr(adrType);
297 networkServerHelper.
Install(networkServer);
301 forwarderHelper.
Install(gateways);
305 "/NodeList/*/DeviceList/0/$ns3::LoraNetDevice/Mac/$ns3::EndDeviceLorawanMac/TxPower",
308 "/NodeList/*/DeviceList/0/$ns3::LoraNetDevice/Mac/$ns3::EndDeviceLorawanMac/DataRate",
323 Time simulationTime =
Seconds(1200 * nPeriodsOf20Minutes);
329 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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
@ 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.