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 = TypeId("ns3::GatewayStatus")
25 .AddConstructor<GatewayStatus>()
26 .SetGroupName("lorawan");
27 return tid;
28}
29
34
39
41 Ptr<NetDevice> netDevice,
43 : m_address(address),
44 m_netDevice(netDevice),
45 m_gatewayMac(gwMac),
47{
48 NS_LOG_FUNCTION(this);
49}
50
53{
54 NS_LOG_FUNCTION(this);
55
56 return m_address;
57}
58
59void
61{
62 NS_LOG_FUNCTION(this);
63
64 m_address = address;
65}
66
72
73void
75{
76 m_netDevice = netDevice;
77}
78
84
85bool
87{
88 // We can't send multiple packets at once, see SX1301 V2.01 page 29
89
90 // Check that the gateway was not already "booked"
92 {
93 NS_LOG_INFO("This gateway is already booked for a transmission");
94 return false;
95 }
96
97 // Check that the gateway is not already in TX mode
98 if (m_gatewayMac->IsTransmitting())
99 {
100 NS_LOG_INFO("This gateway is currently transmitting");
101 return false;
102 }
103
104 // Check that the gateway is not constrained by the duty cycle
105 Time waitTime = m_gatewayMac->GetWaitTime(frequencyHz);
106 if (waitTime.IsStrictlyPositive())
107 {
108 NS_LOG_INFO("Gateway cannot be used because of duty cycle");
109 NS_LOG_INFO("Wait time at current gateway: " << waitTime.As(Time::S));
110
111 return false;
112 }
113
114 return true;
115}
116
117void
119{
120 m_nextTransmissionTime = nextTransmissionTime;
121}
122} // namespace lorawan
123} // namespace ns3
a polymophic address class
Definition address.h:90
Object()
Constructor.
Definition object.cc:96
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
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:403
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 SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:1357
Every class exported by the ns3 library is enclosed in the ns3 namespace.