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 #include <stdint.h>
28 
29 NS_LOG_COMPONENT_DEFINE("LoraGatewayStatus");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(LoraGatewayStatus);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId("ns3::LoraGatewayStatus").AddConstructor<LoraGatewayStatus>();
40  return tid;
41 }
42 
44 {
45  NS_LOG_FUNCTION(this);
46 }
47 
49 {
50  NS_LOG_FUNCTION(this);
51 }
52 
54  Ptr<NetDevice> netDevice,
55  Ptr<LorawanMacGateway> gwMac)
56  : m_address(address),
57  m_netDevice(netDevice),
58  m_gatewayMac(gwMac),
59  m_nextTransmissionTime(Seconds(0))
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
64 Address
66 {
67  NS_LOG_FUNCTION(this);
68 
69  return m_address;
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION(this);
76 
77  m_address = address;
78 }
79 
80 Ptr<NetDevice>
82 {
83  return m_netDevice;
84 }
85 
86 void
87 LoraGatewayStatus::SetNetDevice(Ptr<NetDevice> netDevice)
88 {
89  m_netDevice = netDevice;
90 }
91 
92 Ptr<LorawanMacGateway>
94 {
95  return m_gatewayMac;
96 }
97 
98 bool
100 {
101  NS_LOG_FUNCTION(this << frequency);
102 
103  // We can't send multiple packets at once, see SX1301 V2.01 page 29
104 
105  // Check that the gateway was not already "booked"
106  if (m_nextTransmissionTime > Simulator::Now() - MilliSeconds(1))
107  {
108  NS_LOG_INFO("This gateway is already booked for a transmission");
109  return false;
110  }
111 
112  // Check that the gateway is not already in TX mode
113  if (m_gatewayMac->IsTransmitting())
114  {
115  NS_LOG_INFO("This gateway is currently transmitting");
116  return false;
117  }
118 
119  // Check that the gateway is not constrained by the duty cycle
120  Time waitingTime = m_gatewayMac->GetWaitingTime(frequency);
121  if (waitingTime > Seconds(0))
122  {
123  NS_LOG_INFO("Gateway cannot be used because of duty cycle");
124  NS_LOG_INFO("Waiting time at current GW: " << waitingTime.GetSeconds() << " seconds");
125 
126  return false;
127  }
128 
129  return true;
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION(this << nextTransmissionTime);
136 
137  m_nextTransmissionTime = nextTransmissionTime;
138 }
139 } // 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 // TODO useless ??? Remove !
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.