A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
utilities.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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 * Authors: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#include "utilities.h"
21
22namespace ns3
23{
24namespace lorawan
25{
26
27Ptr<LoraChannel>
29{
30 // Create the lora channel object
31 Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel>();
32 loss->SetPathLossExponent(3.76);
33 loss->SetReference(1, 7.7);
34
35 Ptr<PropagationDelayModel> delay = CreateObject<ConstantSpeedPropagationDelayModel>();
36
37 return CreateObject<LoraChannel>(loss, delay);
38}
39
42{
43 // Create the LoraPhyHelper
44 LoraPhyHelper phyHelper = LoraPhyHelper();
45 phyHelper.SetChannel(channel);
46
47 // Create the LorawanMacHelper
49
50 // Create the LoraHelper
51 LoraHelper helper = LoraHelper();
52
53 // Create a set of nodes
54 NodeContainer endDevices;
55 endDevices.Create(nDevices);
56
57 // Assign a mobility model to the node
58 mobility.Install(endDevices);
59
60 // Create the LoraNetDevices of the end devices
63 helper.Install(phyHelper, macHelper, endDevices);
64
65 return endDevices;
66}
67
70{
71 // Create the LoraPhyHelper
72 LoraPhyHelper phyHelper = LoraPhyHelper();
73 phyHelper.SetChannel(channel);
74
75 // Create the LorawanMacHelper
77
78 // Create the LoraHelper
79 LoraHelper helper = LoraHelper();
80
81 // Create the gateways
82 NodeContainer gateways;
83 gateways.Create(nGateways);
84
85 mobility.Install(gateways);
86
87 // Create a netdevice for each gateway
90 helper.Install(phyHelper, macHelper, gateways);
91
92 return gateways;
93}
94
97{
98 // Create the network server node
99 Ptr<Node> nsNode = CreateObject<Node>();
100
101 // PointToPoint links between gateways and server
103 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
104 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
105 // Store network server app registration details for later
106 P2PGwRegistration_t gwRegistration;
107 for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
108 {
109 auto container = p2p.Install(nsNode, *gw);
110 auto serverP2PNetDev = DynamicCast<PointToPointNetDevice>(container.Get(0));
111 gwRegistration.emplace_back(serverP2PNetDev, *gw);
112 }
113
114 // Install server application
115 NetworkServerHelper networkServerHelper;
116 networkServerHelper.SetGatewaysP2P(gwRegistration);
117 networkServerHelper.SetEndDevices(endDevices);
118 networkServerHelper.Install(nsNode);
119
120 // Install a forwarder on the gateways
121 ForwarderHelper forwarderHelper;
122 forwarderHelper.Install(gateways);
123
124 return nsNode;
125}
126
127NetworkComponents
129{
130 // This function sets up a network with some devices and some gateways, and
131 // returns the created nodes through a NetworkComponents struct.
132
134
135 MobilityHelper mobility;
136 mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
137 "rho",
138 DoubleValue(1000),
139 "X",
140 DoubleValue(0.0),
141 "Y",
142 DoubleValue(0.0));
143 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
144
145 NodeContainer endDevices = CreateEndDevices(nDevices, mobility, channel);
146
147 NodeContainer gateways = CreateGateways(nGateways, mobility, channel);
148
149 LorawanMacHelper::SetSpreadingFactorsUp(endDevices, gateways, channel);
150
151 Ptr<Node> nsNode = CreateNetworkServer(endDevices, gateways);
152
153 return {channel, endDevices, gateways, nsNode};
154}
155
156} // namespace lorawan
157} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Helper class used to assign positions and mobility models to nodes.
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.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Hold variables of type string.
Definition: string.h:56
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.
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
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.
static std::vector< int > SetSpreadingFactorsUp(NodeContainer endDevices, NodeContainer gateways, Ptr< LoraChannel > channel)
Initialize the end devices' data rate parameter.
This class can install a NetworkServer application on a node.
void SetGatewaysP2P(const P2PGwRegistration_t &registration)
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.
int nDevices
Number of end device nodes to create.
int nGateways
Number of gateway nodes to create.
Ptr< Node > CreateNetworkServer(NodeContainer endDevices, NodeContainer gateways)
Definition: utilities.cc:96
Ptr< LoraChannel > CreateChannel()
Definition: utilities.cc:28
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...
NodeContainer CreateGateways(int nGateways, MobilityHelper mobility, Ptr< LoraChannel > channel)
Definition: utilities.cc:69
NetworkComponents InitializeNetwork(int nDevices, int nGateways)
Definition: utilities.cc:128
NodeContainer CreateEndDevices(int nDevices, MobilityHelper mobility, Ptr< LoraChannel > channel)
Definition: utilities.cc:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.