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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "gateway-status.h"
10
11#include "ns3/log.h"
12
13namespace ns3
14{
15namespace lorawan
16{
17
18NS_LOG_COMPONENT_DEFINE("GatewayStatus");
19
20TypeId
22{
23 static TypeId tid =
24 TypeId("ns3::GatewayStatus").AddConstructor<GatewayStatus>().SetGroupName("lorawan");
25 return tid;
26}
27
32
37
39 Ptr<NetDevice> netDevice,
41 : m_address(address),
42 m_netDevice(netDevice),
43 m_gatewayMac(gwMac),
44 m_nextTransmissionTime(Time(0))
45{
46 NS_LOG_FUNCTION(this);
47}
48
51{
52 NS_LOG_FUNCTION(this);
53
54 return m_address;
55}
56
57void
59{
60 NS_LOG_FUNCTION(this);
61
62 m_address = address;
63}
64
70
71void
73{
74 m_netDevice = netDevice;
75}
76
82
83bool
85{
86 // We can't send multiple packets at once, see SX1301 V2.01 page 29
87
88 // Check that the gateway was not already "booked"
90 {
91 NS_LOG_INFO("This gateway is already booked for a transmission");
92 return false;
93 }
94
95 // Check that the gateway is not already in TX mode
96 if (m_gatewayMac->IsTransmitting())
97 {
98 NS_LOG_INFO("This gateway is currently transmitting");
99 return false;
100 }
101
102 // Check that the gateway is not constrained by the duty cycle
103 Time waitTime = m_gatewayMac->GetWaitTime(frequencyHz);
104 if (waitTime.IsStrictlyPositive())
105 {
106 NS_LOG_INFO("Gateway cannot be used because of duty cycle");
107 NS_LOG_INFO("Wait time at current gateway: " << waitTime.As(Time::S));
108
109 return false;
110 }
111
112 return true;
113}
114
115void
117{
118 m_nextTransmissionTime = nextTransmissionTime;
119}
120} // namespace lorawan
121} // namespace ns3
a polymophic address class
Definition address.h:90
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
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:340
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:49
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition type-id.h:694
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.
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.
bool IsAvailableForTransmission(uint32_t frequencyHz)
Set a pointer to this gateway's MAC instance.
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:191
#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:264
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.