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 "gateway-lorawan-mac.h"
12
13#include "ns3/simulator.h"
14
15namespace ns3
16{
17namespace lorawan
18{
19
20NS_LOG_COMPONENT_DEFINE("GatewayStatus");
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::GatewayStatus")
27 .AddConstructor<GatewayStatus>()
28 .SetGroupName("lorawan");
29 return tid;
30}
31
36
41
43 Ptr<NetDevice> netDevice,
45 : m_address(address),
46 m_netDevice(netDevice),
47 m_gatewayMac(gwMac),
49{
50 NS_LOG_FUNCTION(this);
51}
52
55{
56 NS_LOG_FUNCTION(this);
57
58 return m_address;
59}
60
61void
63{
64 NS_LOG_FUNCTION(this);
65
66 m_address = address;
67}
68
74
75void
77{
78 m_netDevice = netDevice;
79}
80
86
87bool
89{
90 // We can't send multiple packets at once, see SX1301 V2.01 page 29
91
92 // Check that the gateway was not already "booked"
94 {
95 NS_LOG_INFO("This gateway is already booked for a transmission");
96 return false;
97 }
98
99 // Check that the gateway is not already in TX mode
100 if (m_gatewayMac->IsTransmitting())
101 {
102 NS_LOG_INFO("This gateway is currently transmitting");
103 return false;
104 }
105
106 // Check that the gateway is not constrained by the duty cycle
107 Time waitTime = m_gatewayMac->GetWaitTime(frequencyHz);
108 if (waitTime.IsStrictlyPositive())
109 {
110 NS_LOG_INFO("Gateway cannot be used because of duty cycle");
111 NS_LOG_INFO("Wait time at current gateway: " << waitTime.As(Time::S));
112
113 return false;
114 }
115
116 return true;
117}
118
119void
121{
122 m_nextTransmissionTime = nextTransmissionTime;
123}
124
125} // namespace lorawan
126} // namespace ns3
a polymophic address class
Definition address.h:114
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:408
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:341
@ S
second
Definition nstime.h:106
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
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:194
#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:267
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:288
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
Every class exported by the ns3 library is enclosed in the ns3 namespace.