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/sub-band.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 // 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
121void
123{
124 NS_LOG_FUNCTION(this << maxReceptionPaths);
125 m_maxReceptionPaths = maxReceptionPaths;
126}
127
128void
130{
131 m_txPriority = txPriority;
132}
133} // namespace lorawan
134} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
a unique identifier for an interface.
Definition type-id.h:49
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:65
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:580