A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Davide Magrin <magrinda@dei.unipd.it>
7
*/
8
9
#include "
lora-phy-helper.h
"
10
11
#include "ns3/log.h"
12
#include "ns3/sub-band.h"
13
14
namespace
ns3
15
{
16
namespace
lorawan
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"LoraPhyHelper"
);
20
21
LoraPhyHelper::LoraPhyHelper
()
22
:
m_maxReceptionPaths
(8),
23
m_txPriority
(true)
24
{
25
NS_LOG_FUNCTION
(
this
);
26
}
27
28
void
29
LoraPhyHelper::SetChannel
(
Ptr<LoraChannel>
channel)
30
{
31
m_channel
= channel;
32
}
33
34
void
35
LoraPhyHelper::SetDeviceType
(
enum
DeviceType
dt)
36
{
37
NS_LOG_FUNCTION
(
this
<< dt);
38
switch
(dt)
39
{
40
case
GW
:
41
m_phy
.SetTypeId(
"ns3::SimpleGatewayLoraPhy"
);
42
break
;
43
case
ED
:
44
m_phy
.SetTypeId(
"ns3::SimpleEndDeviceLoraPhy"
);
45
break
;
46
}
47
}
48
49
TypeId
50
LoraPhyHelper::GetDeviceType
()
const
51
{
52
NS_LOG_FUNCTION
(
this
);
53
return
m_phy
.GetTypeId();
54
}
55
56
void
57
LoraPhyHelper::Set
(std::string name,
const
AttributeValue
& v)
58
{
59
m_phy
.Set(name, v);
60
}
61
62
Ptr<LoraPhy>
63
LoraPhyHelper::Install
(
Ptr<Node>
node,
Ptr<NetDevice>
device)
const
64
{
65
NS_LOG_FUNCTION
(
this
<< node->GetId() << device);
66
67
// Create the PHY and set its channel
68
Ptr<LoraPhy>
phy =
m_phy
.Create<
LoraPhy
>();
69
phy->SetChannel(
m_channel
);
70
71
// Configuration is different based on the kind of device we have to create
72
std::string typeId =
m_phy
.GetTypeId().GetName();
73
if
(typeId ==
"ns3::SimpleGatewayLoraPhy"
)
74
{
75
// Inform the channel of the presence of this PHY
76
m_channel
->Add(phy);
77
78
// For now, assume that the PHY will listen to the default EU channels
79
// with this ReceivePath configuration:
80
// 3 ReceivePaths on 868.1 MHz
81
// 3 ReceivePaths on 868.3 MHz
82
// 2 ReceivePaths on 868.5 MHz
83
84
// We expect that MacHelper instances will overwrite this setting if the
85
// device will operate in a different region
86
std::vector<uint32_t> frequenciesHz;
87
frequenciesHz.push_back(868100000);
88
frequenciesHz.push_back(868300000);
89
frequenciesHz.push_back(868500000);
90
91
for
(
auto
& f : frequenciesHz)
92
{
93
DynamicCast<SimpleGatewayLoraPhy>
(phy)->AddFrequency(f);
94
}
95
96
int
receptionPaths = 0;
97
// Set maxReceptionPaths as a parameter
98
// int maxReceptionPaths = 8;
99
while
(receptionPaths <
m_maxReceptionPaths
)
100
{
101
DynamicCast<SimpleGatewayLoraPhy>
(phy)->AddReceptionPath();
102
receptionPaths++;
103
}
104
}
105
else
if
(typeId ==
"ns3::SimpleEndDeviceLoraPhy"
)
106
{
107
// The line below can be commented to speed up uplink-only simulations.
108
// This implies that the LoraChannel instance will only know about
109
// Gateways, and it will not lose time delivering packets and interference
110
// information to devices which will never listen.
111
112
m_channel
->Add(phy);
113
}
114
115
// Link the PHY to its net device
116
phy->SetDevice(device);
117
118
return
phy;
119
}
120
121
void
122
LoraPhyHelper::SetMaxReceptionPaths
(
int
maxReceptionPaths)
123
{
124
NS_LOG_FUNCTION
(
this
<< maxReceptionPaths);
125
m_maxReceptionPaths
= maxReceptionPaths;
126
}
127
128
void
129
LoraPhyHelper::SetGatewayTransmissionPriority
(
bool
txPriority)
130
{
131
m_txPriority
= txPriority;
132
}
133
}
// namespace lorawan
134
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
ns3::lorawan::LoraPhyHelper::SetDeviceType
void SetDeviceType(enum DeviceType dt)
Set the kind of PHY this helper will create.
Definition
lora-phy-helper.cc:35
ns3::lorawan::LoraPhyHelper::DeviceType
DeviceType
Enum for the type of device: End Device (ED) or Gateway (GW).
Definition
lora-phy-helper.h:38
ns3::lorawan::LoraPhyHelper::GW
@ GW
Definition
lora-phy-helper.h:39
ns3::lorawan::LoraPhyHelper::ED
@ ED
Definition
lora-phy-helper.h:40
ns3::lorawan::LoraPhyHelper::m_channel
Ptr< LoraChannel > m_channel
The channel instance the PHYs will be connected to.
Definition
lora-phy-helper.h:103
ns3::lorawan::LoraPhyHelper::GetDeviceType
TypeId GetDeviceType() const
Get the TypeId of the object to be created with LoraPhyHelper.
Definition
lora-phy-helper.cc:50
ns3::lorawan::LoraPhyHelper::Install
Ptr< LoraPhy > Install(Ptr< Node > node, Ptr< NetDevice > device) const
Create a LoraPhy and connect it to a device on a node.
Definition
lora-phy-helper.cc:63
ns3::lorawan::LoraPhyHelper::SetMaxReceptionPaths
void SetMaxReceptionPaths(int maxReceptionPaths)
Set the maximum number of gateway receive paths.
Definition
lora-phy-helper.cc:122
ns3::lorawan::LoraPhyHelper::Set
void Set(std::string name, const AttributeValue &v)
Set an attribute of the underlying PHY object.
Definition
lora-phy-helper.cc:57
ns3::lorawan::LoraPhyHelper::LoraPhyHelper
LoraPhyHelper()
Default constructor.
Definition
lora-phy-helper.cc:21
ns3::lorawan::LoraPhyHelper::m_txPriority
bool m_txPriority
Whether to give priority to downlink transmission over reception at the gateways.
Definition
lora-phy-helper.h:105
ns3::lorawan::LoraPhyHelper::SetGatewayTransmissionPriority
void SetGatewayTransmissionPriority(bool txPriority)
Set if giving priority to downlink transmission over reception at the gateways.
Definition
lora-phy-helper.cc:129
ns3::lorawan::LoraPhyHelper::SetChannel
void SetChannel(Ptr< LoraChannel > channel)
Set the LoraChannel to connect the PHYs to.
Definition
lora-phy-helper.cc:29
ns3::lorawan::LoraPhyHelper::m_maxReceptionPaths
int m_maxReceptionPaths
The maximum number of receive paths at the gateway.
Definition
lora-phy-helper.h:104
ns3::lorawan::LoraPhyHelper::m_phy
ObjectFactory m_phy
The PHY layer factory object.
Definition
lora-phy-helper.h:102
ns3::lorawan::LoraPhy
Base class for PHY layers implementing the LoRa modulation scheme.
Definition
lora-phy.h:65
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
lora-phy-helper.h
ns3::lorawan
Definition
forwarder-helper.cc:25
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:580
src
lorawan
helper
lora-phy-helper.cc
Generated on Wed Jun 11 2025 13:15:31 for ns-3 by
1.13.2