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
11namespace ns3
12{
13namespace lorawan
14{
15
16Ptr<LoraChannel>
18{
19 // Create the lora channel object
21 loss->SetPathLossExponent(3.76);
22 loss->SetReference(1, 7.7);
23
25
26 return CreateObject<LoraChannel>(loss, delay);
27}
28
31{
32 // Create the LoraPhyHelper
33 LoraPhyHelper phyHelper = LoraPhyHelper();
34 phyHelper.SetChannel(channel);
35
36 // Create the LorawanMacHelper
38
39 // Create the LoraHelper
40 LoraHelper helper = LoraHelper();
41
42 // Create a set of nodes
43 NodeContainer endDevices;
44 endDevices.Create(nDevices);
45
46 // Assign a mobility model to the node
47 mobility.Install(endDevices);
48
49 // Create the LoraNetDevices of the end devices
52 helper.Install(phyHelper, macHelper, endDevices);
53
54 return endDevices;
55}
56
59{
60 // Create the LoraPhyHelper
61 LoraPhyHelper phyHelper = LoraPhyHelper();
62 phyHelper.SetChannel(channel);
63
64 // Create the LorawanMacHelper
66
67 // Create the LoraHelper
68 LoraHelper helper = LoraHelper();
69
70 // Create the gateways
71 NodeContainer gateways;
72 gateways.Create(nGateways);
73
74 mobility.Install(gateways);
75
76 // Create a netdevice for each gateway
79 helper.Install(phyHelper, macHelper, gateways);
80
81 return gateways;
82}
83
86{
87 // Create the network server node
89
90 // PointToPoint links between gateways and server
92 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
93 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
94 // Store network server app registration details for later
95 P2PGwRegistration_t gwRegistration;
96 for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
97 {
98 auto container = p2p.Install(nsNode, *gw);
99 auto serverP2PNetDev = DynamicCast<PointToPointNetDevice>(container.Get(0));
100 gwRegistration.emplace_back(serverP2PNetDev, *gw);
101 }
102
103 // Install server application
104 NetworkServerHelper networkServerHelper;
105 networkServerHelper.SetGatewaysP2P(gwRegistration);
106 networkServerHelper.SetEndDevices(endDevices);
107 networkServerHelper.Install(nsNode);
108
109 // Install a forwarder on the gateways
110 ForwarderHelper forwarderHelper;
111 forwarderHelper.Install(gateways);
112
113 return nsNode;
114}
115
116NetworkComponents
118{
119 // This function sets up a network with some devices and some gateways, and
120 // returns the created nodes through a NetworkComponents struct.
121
123
124 MobilityHelper mobility;
125 mobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
126 "rho",
127 DoubleValue(1000),
128 "X",
129 DoubleValue(0.0),
130 "Y",
131 DoubleValue(0.0));
132 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
133
134 NodeContainer endDevices = CreateEndDevices(nDevices, mobility, channel);
135
136 NodeContainer gateways = CreateGateways(nGateways, mobility, channel);
137
138 LorawanMacHelper::SetSpreadingFactorsUp(endDevices, gateways, channel);
139
140 Ptr<Node> nsNode = CreateNetworkServer(endDevices, gateways);
141
142 return {channel, endDevices, gateways, nsNode};
143}
144
145} // namespace lorawan
146} // 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.
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: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.
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:619
Ptr< Node > CreateNetworkServer(NodeContainer endDevices, NodeContainer gateways)
Definition utilities.cc:85
Ptr< LoraChannel > CreateChannel()
Definition utilities.cc:17
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:58
NetworkComponents InitializeNetwork(int nDevices, int nGateways)
Definition utilities.cc:117
NodeContainer CreateEndDevices(int nDevices, MobilityHelper mobility, Ptr< LoraChannel > channel)
Definition utilities.cc:30
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:580