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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20/*
21 * This script simulates a simple network in which one end device sends one
22 * packet to the gateway.
23 */
24
25#include "ns3/command-line.h"
26#include "ns3/constant-position-mobility-model.h"
27#include "ns3/end-device-lora-phy.h"
28#include "ns3/end-device-lorawan-mac.h"
29#include "ns3/gateway-lora-phy.h"
30#include "ns3/gateway-lorawan-mac.h"
31#include "ns3/log.h"
32#include "ns3/lora-helper.h"
33#include "ns3/lorawan-mac-helper.h"
34#include "ns3/mobility-helper.h"
35#include "ns3/node-container.h"
36#include "ns3/one-shot-sender-helper.h"
37#include "ns3/position-allocator.h"
38#include "ns3/simulator.h"
39
40#include <algorithm>
41#include <ctime>
42
43using namespace ns3;
44using namespace lorawan;
45
46NS_LOG_COMPONENT_DEFINE("ParallelReceptionExample");
47
48int
49main(int argc, char* argv[])
50{
51 // Set up logging
52 LogComponentEnable("ParallelReceptionExample", LOG_LEVEL_ALL);
53 // LogComponentEnable ("LoraChannel", LOG_LEVEL_INFO);
54 // LogComponentEnable ("LoraPhy", LOG_LEVEL_ALL);
55 // LogComponentEnable ("EndDeviceLoraPhy", LOG_LEVEL_ALL);
56 LogComponentEnable("GatewayLoraPhy", LOG_LEVEL_ALL);
57 LogComponentEnable("SimpleGatewayLoraPhy", LOG_LEVEL_ALL);
58 // LogComponentEnable ("LoraInterferenceHelper", LOG_LEVEL_ALL);
59 // LogComponentEnable ("LorawanMac", LOG_LEVEL_ALL);
60 // LogComponentEnable ("EndDeviceLorawanMac", LOG_LEVEL_ALL);
61 // LogComponentEnable ("ClassAEndDeviceLorawanMac", LOG_LEVEL_ALL);
62 LogComponentEnable("GatewayLorawanMac", LOG_LEVEL_ALL);
63 // LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL);
64 // LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL);
65 // LogComponentEnable ("LoraHelper", LOG_LEVEL_ALL);
66 // LogComponentEnable ("LoraPhyHelper", LOG_LEVEL_ALL);
67 // LogComponentEnable ("LorawanMacHelper", LOG_LEVEL_ALL);
68 // LogComponentEnable ("OneShotSenderHelper", LOG_LEVEL_ALL);
69 // LogComponentEnable ("OneShotSender", LOG_LEVEL_ALL);
70 // LogComponentEnable ("LorawanMacHeader", LOG_LEVEL_ALL);
71 // LogComponentEnable ("LoraFrameHeader", LOG_LEVEL_ALL);
75
76 /************************
77 * Create the channel *
78 ************************/
79
80 NS_LOG_INFO("Creating the channel...");
81
82 // Create the lora channel object
83 Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel>();
84 loss->SetPathLossExponent(3.76);
85 loss->SetReference(1, 7.7);
86
87 Ptr<PropagationDelayModel> delay = CreateObject<ConstantSpeedPropagationDelayModel>();
88
89 Ptr<LoraChannel> channel = CreateObject<LoraChannel>(loss, delay);
90
91 /************************
92 * Create the helpers *
93 ************************/
94
95 NS_LOG_INFO("Setting up helpers...");
96
98 Ptr<ListPositionAllocator> allocator = CreateObject<ListPositionAllocator>();
99 allocator->Add(Vector(0, 0, 0));
100 mobility.SetPositionAllocator(allocator);
101 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
102
103 // Create the LoraPhyHelper
104 LoraPhyHelper phyHelper = LoraPhyHelper();
105 phyHelper.SetChannel(channel);
106
107 // Create the LorawanMacHelper
109
110 // Create the LoraHelper
111 LoraHelper helper = LoraHelper();
112
113 /************************
114 * Create End Devices *
115 ************************/
116
117 NS_LOG_INFO("Creating the end device...");
118
119 // Create a set of nodes
120 NodeContainer endDevices;
121 endDevices.Create(6);
122
123 // Assign a mobility model to the nodes
124 mobility.Install(endDevices);
125
126 // Create the LoraNetDevices of the end devices
130 helper.Install(phyHelper, macHelper, endDevices);
131
132 /*********************
133 * Create Gateways *
134 *********************/
135
136 NS_LOG_INFO("Creating the gateway...");
137 NodeContainer gateways;
138 gateways.Create(1);
139
140 mobility.Install(gateways);
141
142 // Create a netdevice for each gateway
145 helper.Install(phyHelper, macHelper, gateways);
146
147 /*********************************************
148 * Install applications on the end devices *
149 *********************************************/
150
151 OneShotSenderHelper oneShotSenderHelper;
152
153 oneShotSenderHelper.SetSendTime(Seconds(1));
154 oneShotSenderHelper.Install(endDevices);
155
156 /******************
157 * Set Data Rates *
158 ******************/
159 for (uint32_t i = 0; i < endDevices.GetN(); i++)
160 {
161 endDevices.Get(i)
162 ->GetDevice(0)
163 ->GetObject<LoraNetDevice>()
164 ->GetMac()
166 ->SetDataRate(5 - i);
167 }
168
169 /****************
170 * Simulation *
171 ****************/
172
174
176
178
179 return 0;
180}
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:149
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:522
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Class representing the MAC layer of a LoRaWAN device.
Helps to create LoraNetDevice objects.
Definition: lora-helper.h:48
virtual NetDeviceContainer Install(const LoraPhyHelper &phyHelper, const LorawanMacHelper &macHelper, NodeContainer c) const
Install LoraNetDevices on a list of nodes.
Definition: lora-helper.cc:44
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.
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:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1295
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:302
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition: log.h:119
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
Definition: log.h:120
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:320
ns channel
Definition: third.py:88
ns mobility
Definition: third.py:103