20#include "ns3/building-allocator.h"
21#include "ns3/building-penetration-loss.h"
22#include "ns3/buildings-helper.h"
23#include "ns3/callback.h"
24#include "ns3/command-line.h"
25#include "ns3/constant-position-mobility-model.h"
26#include "ns3/correlated-shadowing-propagation-loss-model.h"
27#include "ns3/double.h"
28#include "ns3/end-device-lora-phy.h"
29#include "ns3/end-device-lorawan-mac.h"
30#include "ns3/forwarder-helper.h"
31#include "ns3/gateway-lora-phy.h"
32#include "ns3/gateway-lorawan-mac.h"
34#include "ns3/lora-device-address.h"
35#include "ns3/lora-frame-header.h"
36#include "ns3/lora-helper.h"
37#include "ns3/lora-net-device.h"
38#include "ns3/lora-phy.h"
39#include "ns3/lorawan-mac-header.h"
40#include "ns3/mobility-helper.h"
41#include "ns3/network-server-helper.h"
42#include "ns3/node-container.h"
43#include "ns3/periodic-sender-helper.h"
44#include "ns3/pointer.h"
45#include "ns3/position-allocator.h"
46#include "ns3/random-variable-stream.h"
47#include "ns3/simulator.h"
53using namespace lorawan;
83 packet->PeekPacketTag(tag);
98 packet->PeekPacketTag(tag);
103main(
int argc,
char* argv[])
105 std::string interferenceMatrix =
"aloha";
108 cmd.AddValue(
"nDevices",
"Number of end devices to include in the simulation",
nDevices);
110 cmd.AddValue(
"interferenceMatrix",
111 "Interference matrix to use [aloha, goursaud]",
114 cmd.Parse(argc, argv);
124 if (interferenceMatrix ==
"aloha")
128 else if (interferenceMatrix ==
"goursaud")
139 mobility.SetPositionAllocator(
"ns3::UniformDiscPositionAllocator",
146 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
154 loss->SetPathLossExponent(3.76);
155 loss->SetReference(1, 7.7);
161 CreateObject<CorrelatedShadowingPropagationLossModel>();
164 loss->SetNext(shadowing);
169 shadowing->SetNext(buildingLoss);
210 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
213 Vector position =
mobility->GetPosition();
222 CreateObject<LoraDeviceAddressGenerator>(nwkId, nwkAddr);
228 helper.
Install(phyHelper, macHelper, endDevices);
233 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
250 allocator->Add(Vector(0.0, 0.0, 15.0));
251 mobility.SetPositionAllocator(allocator);
257 helper.
Install(phyHelper, macHelper, gateways);
273 appContainer.
Stop(appStopTime);
275 std::ofstream outputFile;
277 outputFile.open(
"durations.txt", std::ofstream::out | std::ofstream::trunc);
278 for (uint8_t sf = 7; sf <= 12; sf++)
297 pkt->AddHeader(frameHdr);
302 pkt->AddHeader(macHdr);
313 Ptr<Node> networkServer = CreateObject<Node>();
321 for (
auto gw = gateways.
Begin(); gw != gateways.
End(); ++gw)
324 auto serverP2PNetDev = DynamicCast<PointToPointNetDevice>(
container.Get(0));
325 gwRegistration.emplace_back(serverP2PNetDev, *gw);
331 nsHelper.
Install(networkServer);
337 for (
auto node = gateways.
Begin(); node != gateways.
End(); node++)
345 for (
auto node = endDevices.
Begin(); node != endDevices.
End(); node++)
370 for (
int i = 0; i < 6; i++)
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
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.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the 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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Build a set of PointToPointNetDevice objects.
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.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
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...
This class represents the device address of a LoraWAN end device.
Helps to create LoraNetDevice objects.
void EnablePacketTracking()
Enable tracking of packets via trace sources.
virtual NetDeviceContainer Install(const LoraPhyHelper &phyHelper, const LorawanMacHelper &macHelper, NodeContainer c) const
Install LoraNetDevices on a list of nodes.
static CollisionMatrix collisionMatrix
Collision matrix type set by the constructor.
Hold together all LoRa related objects.
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.
static Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
static Time GetTSym(LoraTxParameters txParams)
Compute the symbol time from spreading factor and bandwidth.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
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 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.
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.
void SetPacketSize(uint8_t size)
Set the base value for applications packet size in bytes.
ApplicationContainer Install(NodeContainer c) const
Install a PeriodicSender application on each node of the input container configured with all the attr...
int appPeriodSeconds
Duration (s) of the inter-transmission time of end devices.
#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.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time Hours(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t 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.
auto packetsReceived
Record received pkts by Data Rate (DR) [index 0 -> DR5, index 5 -> DR0].
void OnPacketReceptionCallback(Ptr< const Packet > packet, uint32_t receiverNodeId)
Record the correct reception of a packet by a gateway.
double simulationTimeSeconds
Scenario duration (s) in simulated time.
auto packetsSent
Record received pkts by Data Rate (DR) [index 0 -> DR5, index 5 -> DR0].
int nDevices
Number of end device nodes to create.
bool realisticChannelModel
Whether to use a more realistic channel model with buildings and correlated shadowing.
int nGateways
Number of gateway nodes to create.
double radiusMeters
Radius (m) of the deployment.
void OnTransmissionCallback(Ptr< const Packet > packet, uint32_t senderNodeId)
Record the beginning of a transmission by an end device.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
uint8_t codingRate
Code rate (obtained as 4/(codingRate+4))
uint32_t nPreamble
Number of preamble symbols.
bool headerDisabled
Whether to use implicit header mode.
double bandwidthHz
Bandwidth in Hz.
bool lowDataRateOptimizationEnabled
Whether low data rate optimization is enabled.
bool crcEnabled
Whether Cyclic Redundancy Check (CRC) is enabled.
uint8_t sf
Spreading Factor.
static const uint32_t packetSize
Packet size generated at the AP.