A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-phy-helper.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#include "lora-phy-helper.h"
21
22#include "ns3/log.h"
23#include "ns3/sub-band.h"
24
25namespace ns3
26{
27namespace lorawan
28{
29
30NS_LOG_COMPONENT_DEFINE("LoraPhyHelper");
31
33 : m_maxReceptionPaths(8),
34 m_txPriority(true)
35{
36 NS_LOG_FUNCTION(this);
37}
38
39void
41{
42 m_channel = channel;
43}
44
45void
47{
48 NS_LOG_FUNCTION(this << dt);
49 switch (dt)
50 {
51 case GW:
52 m_phy.SetTypeId("ns3::SimpleGatewayLoraPhy");
53 break;
54 case ED:
55 m_phy.SetTypeId("ns3::SimpleEndDeviceLoraPhy");
56 break;
57 }
58}
59
62{
63 NS_LOG_FUNCTION(this);
64 return m_phy.GetTypeId();
65}
66
67void
68LoraPhyHelper::Set(std::string name, const AttributeValue& v)
69{
70 m_phy.Set(name, v);
71}
72
75{
76 NS_LOG_FUNCTION(this << node->GetId() << device);
77
78 // Create the PHY and set its channel
80 phy->SetChannel(m_channel);
81
82 // Configuration is different based on the kind of device we have to create
83 std::string typeId = m_phy.GetTypeId().GetName();
84 if (typeId == "ns3::SimpleGatewayLoraPhy")
85 {
86 // Inform the channel of the presence of this PHY
87 m_channel->Add(phy);
88
89 // For now, assume that the PHY will listen to the default EU channels
90 // with this ReceivePath configuration:
91 // 3 ReceivePaths on 868.1
92 // 3 ReceivePaths on 868.3
93 // 2 ReceivePaths on 868.5
94
95 // We expect that MacHelper instances will overwrite this setting if the
96 // device will operate in a different region
97 std::vector<double> frequencies;
98 frequencies.push_back(868.1);
99 frequencies.push_back(868.3);
100 frequencies.push_back(868.5);
101
102 for (auto& f : frequencies)
103 {
104 phy->GetObject<SimpleGatewayLoraPhy>()->AddFrequency(f);
105 }
106
107 int receptionPaths = 0;
108 // Set maxReceptionPaths as a parameter
109 // int maxReceptionPaths = 8;
110 while (receptionPaths < m_maxReceptionPaths)
111 {
112 phy->GetObject<SimpleGatewayLoraPhy>()->AddReceptionPath();
113 receptionPaths++;
114 }
115 }
116 else if (typeId == "ns3::SimpleEndDeviceLoraPhy")
117 {
118 // The line below can be commented to speed up uplink-only simulations.
119 // This implies that the LoraChannel instance will only know about
120 // Gateways, and it will not lose time delivering packets and interference
121 // information to devices which will never listen.
122
123 m_channel->Add(phy);
124 }
125
126 // Link the PHY to its net device
127 phy->SetDevice(device);
128
129 return phy;
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << maxReceptionPaths);
136 m_maxReceptionPaths = maxReceptionPaths;
137}
138
139void
141{
142 m_txPriority = txPriority;
143}
144} // namespace lorawan
145} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
TypeId GetTypeId() const
Get the TypeId which will be created by this ObjectFactory.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
std::string GetName() const
Get the name.
Definition: type-id.cc:992
void SetDeviceType(enum DeviceType dt)
Set the kind of PHY this helper will create.
DeviceType
Enum for the type of device: End Device (ED) or Gateway (GW).
Ptr< LoraChannel > m_channel
The channel instance the PHYs will be connected to.
TypeId GetDeviceType() const
Get the TypeId of the object to be created with LoraPhyHelper.
Ptr< LoraPhy > Create(Ptr< Node > node, Ptr< NetDevice > device) const
Create a LoraPhy and connect it to a device on a node.
void SetMaxReceptionPaths(int maxReceptionPaths)
Set the maximum number of gateway receive paths.
void Set(std::string name, const AttributeValue &v)
Set an attribute of the underlying PHY object.
LoraPhyHelper()
Default constructor.
bool m_txPriority
Whether to give priority to downlink transmission over reception at the gateways.
void SetGatewayTransmissionPriority(bool txPriority)
Set if giving priority to downlink transmission over reception at the gateways.
void SetChannel(Ptr< LoraChannel > channel)
Set the LoraChannel to connect the PHYs to.
int m_maxReceptionPaths
The maximum number of receive paths at the gateway.
ObjectFactory m_phy
The PHY layer factory object.
Base class for PHY layers implementing the LoRa modulation scheme.
Definition: lora-phy.h:76
Class modeling a Lora SX1301 chip.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.