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/simulator.h"
12
13namespace ns3
14{
15namespace lorawan
16{
17
18NS_LOG_COMPONENT_DEFINE("LogicalLoraChannelHelper");
19
21 : m_channelVec(size)
22{
23 NS_LOG_FUNCTION(this);
24}
25
32
33std::vector<Ptr<LogicalLoraChannel>>
39
42{
43 NS_LOG_FUNCTION(this << frequencyHz);
44 for (const auto& sb : m_subBandList)
45 {
46 if (sb->Contains(frequencyHz))
47 {
48 return sb;
49 }
50 }
51 NS_LOG_ERROR("[ERROR] Requested frequency " << frequencyHz << " Hz outside known sub-bands.");
52 return nullptr; // If no SubBand is found, return nullptr
53}
54
55void
57
58{
59 NS_LOG_FUNCTION(this << unsigned(chIndex) << channel);
60 NS_ASSERT_MSG(m_channelVec.size() > chIndex, "ChIndex > channel storage bounds");
61 m_channelVec.at(chIndex) = channel;
62}
63
64void
66{
67 NS_LOG_FUNCTION(this << subBand);
68 m_subBandList.emplace_back(subBand);
69}
70
71Time
73{
74 NS_LOG_FUNCTION(this << channel);
75 return GetWaitTime(channel->GetFrequency());
76}
77
78Time
80{
81 NS_LOG_FUNCTION(this << frequencyHz);
82 auto subBand = GetSubBandFromFrequency(frequencyHz);
83 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
84 Time waitTime = subBand->GetNextTransmissionTime() - Now();
85 waitTime = Max(waitTime, Time(0)); // Handle negative values
86 NS_LOG_DEBUG("waitTime=" << waitTime.As(Time::S));
87 return waitTime;
88}
89
90void
92{
93 NS_LOG_FUNCTION(this << channel);
94 AddEvent(duration, channel->GetFrequency());
95}
96
97void
99{
100 NS_LOG_FUNCTION(this << duration << frequencyHz);
101 NS_LOG_DEBUG("frequency=" << frequencyHz << " Hz, timeOnAir=" << duration.As(Time::S));
102 auto subBand = GetSubBandFromFrequency(frequencyHz);
103 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
104 Time nextTxTime = Now() + duration / subBand->GetDutyCycle();
105 subBand->SetNextTransmissionTime(nextTxTime);
106 NS_LOG_DEBUG("now=" << Now().As(Time::S) << ", nextTxTime=" << nextTxTime.As(Time::S));
107}
108
109double
111{
112 NS_LOG_FUNCTION(this << channel);
113 return GetTxPowerForChannel(channel->GetFrequency());
114}
115
116double
118{
119 NS_LOG_FUNCTION(this << frequencyHz);
120 auto subBand = GetSubBandFromFrequency(frequencyHz);
121 NS_ASSERT_MSG(subBand, "Input frequency is out-of-band");
122 return subBand->GetMaxTxPowerDbm();
123}
124
125bool
127{
128 return (bool)(GetSubBandFromFrequency(frequencyHz));
129}
130
131} // namespace lorawan
132} // namespace ns3
#define Max(a, b)
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ S
second
Definition nstime.h:105
void SetChannel(uint8_t chIndex, Ptr< LogicalLoraChannel > channel)
Set a new channel at a fixed index.
double GetTxPowerForChannel(Ptr< 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...
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 AddEvent(Time duration, Ptr< LogicalLoraChannel > channel)
Register the transmission of a packet.
void AddSubBand(Ptr< SubBand > subBand)
Add a new SubBand.
Time GetWaitTime(Ptr< LogicalLoraChannel > channel) const
Get the time it is necessary to wait for before transmitting on a given channel.
#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:75
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.