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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "utilities.h"
10
11#include "ns3/forwarder-helper.h"
12#include "ns3/lora-helper.h"
13#include "ns3/mobility-model.h"
14#include "ns3/network-server-helper.h"
15#include "ns3/point-to-point-helper.h"
16#include "ns3/string.h"
17
18namespace ns3
19{
20namespace lorawan
21{
22
23Ptr<LoraChannel>
25{
26 // Create the lora channel object
28 loss->SetPathLossExponent(3.76);
29 loss->SetReference(1, 7.7);
30
32
33 return CreateObject<LoraChannel>(loss, delay);
34}
35
38{
39 // Create the LoraPhyHelper
40 LoraPhyHelper phyHelper = LoraPhyHelper();
41 phyHelper.SetChannel(channel);
42
43 // Create the LorawanMacHelper
45
46 // Create the LoraHelper
47 LoraHelper helper = LoraHelper();
48
49 // Create a set of nodes
50 NodeContainer endDevices;
51 endDevices.Create(nDevices);
52
53 // Assign a mobility model to the node
54 mobility.Install(endDevices);
55
56 // Create the LoraNetDevices of the end devices
59 helper.Install(phyHelper, macHelper, endDevices);
60
61 return endDevices;
62}
63
66{
67 // Create the LoraPhyHelper
68 LoraPhyHelper phyHelper = LoraPhyHelper();
69 phyHelper.SetChannel(channel);
70
71 // Create the LorawanMacHelper
73
74 // Create the LoraHelper
75 LoraHelper helper = LoraHelper();
76
77 // Create the gateways
78 NodeContainer gateways;
79 gateways.Create(nGateways);
80
81 mobility.Install(gateways);
82
83 // Create a netdevice for each gateway
86 helper.Install(phyHelper, macHelper, gateways);
87
88 return gateways;
89}
90
93{
94 // Create the network server node
96
97 // PointToPoint links between gateways and server
99 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
100 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
101 // Store network server app registration details for later
102 P2PGwRegistration_t gwRegistration;
103 for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
104 {
105 auto container = p2p.Install(nsNode, *gw);
106 auto serverP2PNetDev = DynamicCast<PointToPointNetDevice>(container.Get(0));
107 gwRegistration.emplace_back(serverP2PNetDev, *gw);
108 }
109
110 // Install server application
111 NetworkServerHelper networkServerHelper;
112 networkServerHelper.SetGatewaysP2P(gwRegistration);
113 networkServerHelper.SetEndDevices(endDevices);
114 networkServerHelper.Install(nsNode);
115
116 // Install a forwarder on the gateways
117 ForwarderHelper forwarderHelper;
118 forwarderHelper.Install(gateways);
119
120 return nsNode;
121}
122
123NetworkComponents
125{
126 // This function sets up a network with some devices and some gateways, and
127 // returns the created nodes through a NetworkComponents struct.
128
130
131 MobilityHelper mobility;
132 mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
133 "rho",
134 DoubleValue(1000),
135 "X",
136 DoubleValue(0.0),
137 "Y",
138 DoubleValue(0.0));
139 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
140
141 NodeContainer endDevices = CreateEndDevices(nDevices, mobility, channel);
142
143 NodeContainer gateways = CreateGateways(nGateways, mobility, channel);
144
145 LorawanMacHelper::SetSpreadingFactorsUp(endDevices, gateways, channel);
146
147 Ptr<Node> nsNode = CreateNetworkServer(endDevices, gateways);
148
149 return {channel, endDevices, gateways, nsNode};
150}
151
152} // namespace lorawan
153} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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:70
Hold variables of type string.
Definition string.h:45
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:34
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.
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< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< Node > CreateNetworkServer(NodeContainer endDevices, NodeContainer gateways)
Definition utilities.cc:92
Ptr< LoraChannel > CreateChannel()
Definition utilities.cc:24
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:65
NetworkComponents InitializeNetwork(int nDevices, int nGateways)
Definition utilities.cc:124
NodeContainer CreateEndDevices(int nDevices, MobilityHelper mobility, Ptr< LoraChannel > channel)
Definition utilities.cc:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:605