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 * 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/simple-gateway-lora-phy.h"
12
13namespace ns3
14{
15namespace lorawan
16{
17
18NS_LOG_COMPONENT_DEFINE("LoraPhyHelper");
19
26
27void
32
33void
35{
36 NS_LOG_FUNCTION(this << dt);
37 switch (dt)
38 {
39 case GW:
40 m_phy.SetTypeId("ns3::SimpleGatewayLoraPhy");
41 break;
42 case ED:
43 m_phy.SetTypeId("ns3::SimpleEndDeviceLoraPhy");
44 break;
45 }
46}
47
50{
51 NS_LOG_FUNCTION(this);
52 return m_phy.GetTypeId();
53}
54
55void
56LoraPhyHelper::Set(std::string name, const AttributeValue& v)
57{
58 m_phy.Set(name, v);
59}
60
63{
64 NS_LOG_FUNCTION(this << node->GetId() << device);
65
66 // Create the PHY and set its channel
67 Ptr<LoraPhy> phy = m_phy.Create<LoraPhy>();
68 phy->SetChannel(m_channel);
69
70 // Configuration is different based on the kind of device we have to create
71 std::string typeId = m_phy.GetTypeId().GetName();
72 if (typeId == "ns3::SimpleGatewayLoraPhy")
73 {
74 // Inform the channel of the presence of this PHY
75 m_channel->Add(phy);
76
77 // For now, assume that the PHY will listen to the default EU channels
78 // with this ReceivePath configuration:
79 // 3 ReceivePaths on 868.1 MHz
80 // 3 ReceivePaths on 868.3 MHz
81 // 2 ReceivePaths on 868.5 MHz
82
83 // We expect that MacHelper instances will overwrite this setting if the
84 // device will operate in a different region
85 std::vector<uint32_t> frequenciesHz;
86 frequenciesHz.push_back(868100000);
87 frequenciesHz.push_back(868300000);
88 frequenciesHz.push_back(868500000);
89
90 for (auto& f : frequenciesHz)
91 {
92 DynamicCast<SimpleGatewayLoraPhy>(phy)->AddFrequency(f);
93 }
94
95 int receptionPaths = 0;
96 // Set maxReceptionPaths as a parameter
97 // int maxReceptionPaths = 8;
98 while (receptionPaths < m_maxReceptionPaths)
99 {
100 DynamicCast<SimpleGatewayLoraPhy>(phy)->AddReceptionPath();
101 receptionPaths++;
102 }
103 }
104 else if (typeId == "ns3::SimpleEndDeviceLoraPhy")
105 {
106 // The line below can be commented to speed up uplink-only simulations.
107 // This implies that the LoraChannel instance will only know about
108 // Gateways, and it will not lose time delivering packets and interference
109 // information to devices which will never listen.
110
111 m_channel->Add(phy);
112 }
113
114 // Link the PHY to its net device
115 phy->SetDevice(device);
116
117 return phy;
118}
119
120void
122{
123 NS_LOG_FUNCTION(this << maxReceptionPaths);
124 m_maxReceptionPaths = maxReceptionPaths;
125}
126
127void
129{
130 m_txPriority = txPriority;
131}
132
133} // namespace lorawan
134} // namespace ns3
uint32_t v
Hold a value for an Attribute.
Definition attribute.h:59
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
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 > Install(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:81
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:605