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/log.h"
12#include "ns3/simple-gateway-lora-phy.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
19NS_LOG_COMPONENT_DEFINE("LoraPhyHelper");
20
27
28void
33
34void
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
51{
52 NS_LOG_FUNCTION(this);
53 return m_phy.GetTypeId();
54}
55
56void
57LoraPhyHelper::Set(std::string name, const AttributeValue& v)
58{
59 m_phy.Set(name, v);
60}
61
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 // We expect that MacHelper instances will overwrite this setting if the
80 // device will operate in a different region
81 std::vector<uint32_t> frequenciesHz;
82 frequenciesHz.push_back(868100000);
83 frequenciesHz.push_back(868300000);
84 frequenciesHz.push_back(868500000);
85
86 for (auto& f : frequenciesHz)
87 {
88 DynamicCast<SimpleGatewayLoraPhy>(phy)->AddFrequency(f);
89 }
90
91 int receptionPaths = 0;
92 // Set maxReceptionPaths as a parameter
93 // int maxReceptionPaths = 8;
94 while (receptionPaths < m_maxReceptionPaths)
95 {
96 DynamicCast<SimpleGatewayLoraPhy>(phy)->AddReceptionPath();
97 receptionPaths++;
98 }
99 }
100 else if (typeId == "ns3::SimpleEndDeviceLoraPhy")
101 {
102 // The line below can be commented to speed up uplink-only simulations.
103 // This implies that the LoraChannel instance will only know about
104 // Gateways, and it will not lose time delivering packets and interference
105 // information to devices which will never listen.
106
107 m_channel->Add(phy);
108 }
109
110 // Link the PHY to its net device
111 phy->SetDevice(device);
112
113 return phy;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << maxReceptionPaths);
120 m_maxReceptionPaths = maxReceptionPaths;
121}
122
123void
125{
126 m_txPriority = txPriority;
127}
128
129} // namespace lorawan
130} // 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:102
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#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:643