lora-gateway-status.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 University of Padova
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Davide Magrin <magrinda@dei.unipd.it>
19  *
20  * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21  */
22 
23 #include "lora-gateway-status.h"
24 
25 #include <ns3/log.h>
26 
27 NS_LOG_COMPONENT_DEFINE("LoraGatewayStatus");
28 
29 namespace ns3
30 {
31 
32 NS_OBJECT_ENSURE_REGISTERED(LoraGatewayStatus);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId("ns3::LoraGatewayStatus").AddConstructor<LoraGatewayStatus>();
38  return tid;
39 }
40 
42 {
43  NS_LOG_FUNCTION(this);
44 }
45 
47 {
48  NS_LOG_FUNCTION(this);
49 }
50 
52  Ptr<NetDevice> netDevice,
53  Ptr<LorawanMacGateway> gwMac)
54  : m_address(address),
55  m_netDevice(netDevice),
56  m_gatewayMac(gwMac),
57  m_nextTransmissionTime(Seconds(0))
58 {
59  NS_LOG_FUNCTION(this);
60 }
61 
62 Address
64 {
65  NS_LOG_FUNCTION(this);
66 
67  return m_address;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION(this);
74 
75  m_address = address;
76 }
77 
78 Ptr<NetDevice>
80 {
81  return m_netDevice;
82 }
83 
84 void
85 LoraGatewayStatus::SetNetDevice(Ptr<NetDevice> netDevice)
86 {
87  m_netDevice = netDevice;
88 }
89 
90 Ptr<LorawanMacGateway>
92 {
93  return m_gatewayMac;
94 }
95 
96 bool
98 {
99  NS_LOG_FUNCTION(this << frequency);
100 
101  // We can't send multiple packets at once, see SX1301 V2.01 page 29
102 
103  // Check that the gateway was not already "booked"
104  if (m_nextTransmissionTime > Simulator::Now() - MilliSeconds(1))
105  {
106  NS_LOG_INFO("This gateway is already booked for a transmission");
107  return false;
108  }
109 
110  // Check that the gateway is not already in TX mode
111  if (m_gatewayMac->IsTransmitting())
112  {
113  NS_LOG_INFO("This gateway is currently transmitting");
114  return false;
115  }
116 
117  // Check that the gateway is not constrained by the duty cycle
118  Time waitingTime = m_gatewayMac->GetWaitingTime(frequency);
119  if (waitingTime > Seconds(0))
120  {
121  NS_LOG_INFO("Gateway cannot be used because of duty cycle");
122  NS_LOG_INFO("Waiting time at current GW: " << waitingTime.GetSeconds() << " seconds");
123 
124  return false;
125  }
126 
127  return true;
128 }
129 
130 void
132 {
133  NS_LOG_FUNCTION(this << nextTransmissionTime);
134 
135  m_nextTransmissionTime = nextTransmissionTime;
136 }
137 } // namespace ns3
void SetNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice through which it's possible to contact this gateway from the server.
static TypeId GetTypeId(void)
Time m_nextTransmissionTime
This gateway's next transmission time.
Address GetAddress()
Get this gateway's P2P link address.
Ptr< NetDevice > GetNetDevice()
Get the NetDevice through which it's possible to contact this gateway from the server.
Ptr< LorawanMacGateway > GetGatewayMac(void)
Get a pointer to this gateway's MAC instance.
void SetNextTransmissionTime(Time nextTransmissionTime)
void SetAddress(Address address)
Set this gateway's P2P link address.
Ptr< NetDevice > m_netDevice
The NetDevice through which to reach this gateway from the server.
Ptr< LorawanMacGateway > m_gatewayMac
The Mac layer of the gateway.
bool IsAvailableForTransmission(double frequency)
Set a pointer to this gateway's MAC instance.
Address m_address
The Address of the P2PNetDevice of this gateway.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.