A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gateway-status.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#include "gateway-status.h"
21
22#include "ns3/log.h"
23
24namespace ns3
25{
26namespace lorawan
27{
28
29NS_LOG_COMPONENT_DEFINE("GatewayStatus");
30
31TypeId
33{
34 static TypeId tid =
35 TypeId("ns3::GatewayStatus").AddConstructor<GatewayStatus>().SetGroupName("lorawan");
36 return tid;
37}
38
40{
41 NS_LOG_FUNCTION(this);
42}
43
45{
46 NS_LOG_FUNCTION(this);
47}
48
50 Ptr<NetDevice> netDevice,
52 : m_address(address),
53 m_netDevice(netDevice),
54 m_gatewayMac(gwMac),
55 m_nextTransmissionTime(Seconds(0))
56{
57 NS_LOG_FUNCTION(this);
58}
59
62{
63 NS_LOG_FUNCTION(this);
64
65 return m_address;
66}
67
68void
70{
71 NS_LOG_FUNCTION(this);
72
73 m_address = address;
74}
75
78{
79 return m_netDevice;
80}
81
82void
84{
85 m_netDevice = netDevice;
86}
87
90{
91 return m_gatewayMac;
92}
93
94bool
96{
97 // We can't send multiple packets at once, see SX1301 V2.01 page 29
98
99 // Check that the gateway was not already "booked"
101 {
102 NS_LOG_INFO("This gateway is already booked for a transmission");
103 return false;
104 }
105
106 // Check that the gateway is not already in TX mode
107 if (m_gatewayMac->IsTransmitting())
108 {
109 NS_LOG_INFO("This gateway is currently transmitting");
110 return false;
111 }
112
113 // Check that the gateway is not constrained by the duty cycle
114 Time waitingTime = m_gatewayMac->GetWaitingTime(frequency);
115 if (waitingTime > Seconds(0))
116 {
117 NS_LOG_INFO("Gateway cannot be used because of duty cycle");
118 NS_LOG_INFO("Waiting time at current gateway: " << waitingTime.GetSeconds() << " seconds");
119
120 return false;
121 }
122
123 return true;
124}
125
126void
128{
129 m_nextTransmissionTime = nextTransmissionTime;
130}
131} // namespace lorawan
132} // namespace ns3
a polymophic address class
Definition: address.h:101
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
a unique identifier for an interface.
Definition: type-id.h:59
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:651
This class represents the network server's knowledge about a gateway in the LoRaWAN network it is adm...
void SetAddress(Address address)
Set this gateway's P2P link address.
~GatewayStatus() override
Destructor.
bool IsAvailableForTransmission(double frequency)
‍**
Address GetAddress()
Get this gateway's P2P link address.
Ptr< NetDevice > m_netDevice
The NetDevice through which to reach this gateway from the server.
Time m_nextTransmissionTime
This gateway's next transmission time.
void SetNextTransmissionTime(Time nextTransmissionTime)
Set the time of the next scheduled transmission for the gateway.
Ptr< GatewayLorawanMac > GetGatewayMac()
Get a pointer to this gateway's MAC instance.
Ptr< GatewayLorawanMac > m_gatewayMac
The Mac layer of the gateway.
static TypeId GetTypeId()
Register this type.
Ptr< NetDevice > GetNetDevice()
Get the NetDevice through which it's possible to contact this gateway from the server.
Address m_address
The Address of the P2PNetDevice of this gateway.
GatewayStatus()
Default constructor.
void SetNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice through which it's possible to contact this gateway from the server.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Every class exported by the ns3 library is enclosed in the ns3 namespace.