A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
parallel-reception-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9/*
10 * This script simulates a simple network in which one end device sends one
11 * packet to the gateway.
12 */
13
14#include "ns3/command-line.h"
15#include "ns3/constant-position-mobility-model.h"
16#include "ns3/end-device-lora-phy.h"
17#include "ns3/end-device-lorawan-mac.h"
18#include "ns3/gateway-lora-phy.h"
19#include "ns3/gateway-lorawan-mac.h"
20#include "ns3/log.h"
21#include "ns3/lora-helper.h"
22#include "ns3/lorawan-mac-helper.h"
23#include "ns3/mobility-helper.h"
24#include "ns3/node-container.h"
25#include "ns3/one-shot-sender-helper.h"
26#include "ns3/position-allocator.h"
27#include "ns3/simulator.h"
28
29#include <algorithm>
30#include <ctime>
31
32using namespace ns3;
33using namespace lorawan;
34
35NS_LOG_COMPONENT_DEFINE("ParallelReceptionExample");
36
37int
38main(int argc, char* argv[])
39{
40 // Set up logging
41 LogComponentEnable("ParallelReceptionExample", LOG_LEVEL_ALL);
42 // LogComponentEnable ("LoraChannel", LOG_LEVEL_INFO);
43 // LogComponentEnable ("LoraPhy", LOG_LEVEL_ALL);
44 // LogComponentEnable ("EndDeviceLoraPhy", LOG_LEVEL_ALL);
45 LogComponentEnable("GatewayLoraPhy", LOG_LEVEL_ALL);
46 LogComponentEnable("SimpleGatewayLoraPhy", LOG_LEVEL_ALL);
47 // LogComponentEnable ("LoraInterferenceHelper", LOG_LEVEL_ALL);
48 // LogComponentEnable ("LorawanMac", LOG_LEVEL_ALL);
49 // LogComponentEnable ("EndDeviceLorawanMac", LOG_LEVEL_ALL);
50 // LogComponentEnable ("ClassAEndDeviceLorawanMac", LOG_LEVEL_ALL);
51 LogComponentEnable("GatewayLorawanMac", LOG_LEVEL_ALL);
52 // LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL);
53 // LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL);
54 // LogComponentEnable ("LoraHelper", LOG_LEVEL_ALL);
55 // LogComponentEnable ("LoraPhyHelper", LOG_LEVEL_ALL);
56 // LogComponentEnable ("LorawanMacHelper", LOG_LEVEL_ALL);
57 // LogComponentEnable ("OneShotSenderHelper", LOG_LEVEL_ALL);
58 // LogComponentEnable ("OneShotSender", LOG_LEVEL_ALL);
59 // LogComponentEnable ("LorawanMacHeader", LOG_LEVEL_ALL);
60 // LogComponentEnable ("LoraFrameHeader", LOG_LEVEL_ALL);
64
65 /************************
66 * Create the channel *
67 ************************/
68
69 NS_LOG_INFO("Creating the channel...");
70
71 // Create the lora channel object
73 loss->SetPathLossExponent(3.76);
74 loss->SetReference(1, 7.7);
75
77
79
80 /************************
81 * Create the helpers *
82 ************************/
83
84 NS_LOG_INFO("Setting up helpers...");
85
88 allocator->Add(Vector(0, 0, 0));
89 mobility.SetPositionAllocator(allocator);
90 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
91
92 // Create the LoraPhyHelper
93 LoraPhyHelper phyHelper = LoraPhyHelper();
94 phyHelper.SetChannel(channel);
95
96 // Create the LorawanMacHelper
98
99 // Create the LoraHelper
100 LoraHelper helper = LoraHelper();
101
102 /************************
103 * Create End Devices *
104 ************************/
105
106 NS_LOG_INFO("Creating the end device...");
107
108 // Create a set of nodes
109 NodeContainer endDevices;
110 endDevices.Create(6);
111
112 // Assign a mobility model to the nodes
113 mobility.Install(endDevices);
114
115 // Create the LoraNetDevices of the end devices
119 helper.Install(phyHelper, macHelper, endDevices);
120
121 /*********************
122 * Create Gateways *
123 *********************/
124
125 NS_LOG_INFO("Creating the gateway...");
126 NodeContainer gateways;
127 gateways.Create(1);
128
129 mobility.Install(gateways);
130
131 // Create a netdevice for each gateway
134 helper.Install(phyHelper, macHelper, gateways);
135
136 /*********************************************
137 * Install applications on the end devices *
138 *********************************************/
139
140 OneShotSenderHelper oneShotSenderHelper;
141
142 oneShotSenderHelper.SetSendTime(Seconds(1));
143 oneShotSenderHelper.Install(endDevices);
144
145 /******************
146 * Set Data Rates *
147 ******************/
148 for (uint32_t i = 0; i < endDevices.GetN(); i++)
149 {
151 DynamicCast<LoraNetDevice>(endDevices.Get(i)->GetDevice(0))->GetMac())
152 ->SetDataRate(5 - i);
153 }
154
155 /****************
156 * Simulation *
157 ****************/
158
160
162
164
165 return 0;
166}
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
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.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition node.cc:138
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Helps to create LoraNetDevice objects.
Definition lora-helper.h:37
virtual NetDeviceContainer Install(const LoraPhyHelper &phyHelper, const LorawanMacHelper &macHelper, NodeContainer c) const
Install LoraNetDevices on a list of nodes.
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 SetRegion(enum Regions region)
Set the region in which the device is to operate.
This class can be used to install OneShotSender applications on multiple nodes at once.
void SetSendTime(Time sendTime)
Set the send time of the applications.
ApplicationContainer Install(NodeContainer c) const
Install a OneShotSender application on each node of the input container configured with all the attri...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1284
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.
Definition log.cc:291
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition log.h:107
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition log.h:108
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
Definition log.h:109
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition log.cc:309
channel
Definition third.py:77
mobility
Definition third.py:92