A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
logical-lora-channel-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
10
11#include "ns3/log.h"
12#include "ns3/simulator.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
19NS_LOG_COMPONENT_DEFINE("LogicalLoraChannelHelper");
20
26
33
34std::vector<Ptr<LogicalLoraChannel>>
40
43{
44 NS_LOG_FUNCTION(this << frequencyHz);
45 for (const auto& sb : m_subBandList)
46 {
47 if (sb->Contains(frequencyHz))
48 {
49 return sb;
50 }
51 }
52 NS_LOG_ERROR("[ERROR] Requested frequency " << frequencyHz << " Hz outside known sub-bands.");
53 return nullptr; // If no SubBand is found, return nullptr
54}
55
56void
58
59{
60 NS_LOG_FUNCTION(this << unsigned(chIndex) << channel);
61 NS_ASSERT_MSG(m_channelVec.size() > chIndex, "ChIndex > channel storage bounds");
62 m_channelVec.at(chIndex) = channel;
63}
64
65void
67{
68 NS_LOG_FUNCTION(this << subBand);
69 m_subBandList.emplace_back(subBand);
70}
71
72Time
74{
75 NS_LOG_FUNCTION(this << channel);
76 return GetWaitTime(channel->GetFrequency());
77}
78
79Time
81{
82 NS_LOG_FUNCTION(this << frequencyHz);
83 auto subBand = GetSubBandFromFrequency(frequencyHz);
84 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
85 Time waitTime = subBand->GetNextTransmissionTime() - Now();
86 waitTime = Max(waitTime, Time(0)); // Handle negative values
87 NS_LOG_DEBUG("waitTime=" << waitTime.As(Time::S));
88 return waitTime;
89}
90
91void
93{
94 NS_LOG_FUNCTION(this << channel);
95 AddEvent(duration, channel->GetFrequency());
96}
97
98void
100{
101 NS_LOG_FUNCTION(this << duration << frequencyHz);
102 NS_LOG_DEBUG("frequency=" << frequencyHz << " Hz, timeOnAir=" << duration.As(Time::S));
103 auto subBand = GetSubBandFromFrequency(frequencyHz);
104 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
105 Time nextTxTime = Now() + duration / subBand->GetDutyCycle();
106 subBand->SetNextTransmissionTime(nextTxTime);
107 NS_LOG_DEBUG("now=" << Now().As(Time::S) << ", nextTxTime=" << nextTxTime.As(Time::S));
108}
109
110double
112{
113 NS_LOG_FUNCTION(this << channel);
114 return GetTxPowerForChannel(channel->GetFrequency());
115}
116
117double
119{
120 NS_LOG_FUNCTION(this << frequencyHz);
121 auto subBand = GetSubBandFromFrequency(frequencyHz);
122 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
123 return subBand->GetMaxTxPowerDbm();
124}
125
126bool
128{
129 return (bool)(GetSubBandFromFrequency(frequencyHz));
130}
131
132} // namespace lorawan
133} // namespace ns3
#define Max(a, b)
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
@ S
second
Definition nstime.h:106
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:422
Time GetWaitTime(Ptr< const LogicalLoraChannel > channel) const
Get the time it is necessary to wait for before transmitting on a given channel.
void SetChannel(uint8_t chIndex, Ptr< LogicalLoraChannel > channel)
Set a new channel at a fixed index.
double GetTxPowerForChannel(Ptr< const LogicalLoraChannel > channel) const
Returns the maximum transmission power [dBm] that is allowed on a channel.
bool IsFrequencyValid(uint32_t frequencyHz) const
Check if a frequency is valid, that is, if it belongs to any of the sub-bands registered in this clas...
void AddEvent(Time duration, Ptr< const LogicalLoraChannel > channel)
Register the transmission of a packet.
std::vector< Ptr< LogicalLoraChannel > > m_channelVec
A vector of the LogicalLoraChannels that are currently registered within this helper.
LogicalLoraChannelHelper(uint8_t size)
Construct a LogicalLoraChannelHelper of a certain size.
std::vector< Ptr< SubBand > > m_subBandList
A vector of the SubBands that are currently registered within this helper.
std::vector< Ptr< LogicalLoraChannel > > GetRawChannelArray() const
Get the frequency channel storage array of this device.
Ptr< SubBand > GetSubBandFromFrequency(uint32_t frequencyHz) const
Get the SubBand a frequency belongs to, also used to test validity of a frequency.
void AddSubBand(Ptr< SubBand > subBand)
Add a new SubBand.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:76
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:253
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:288
Every class exported by the ns3 library is enclosed in the ns3 namespace.