lora-network-server-helper.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 "ns3/lora-network-server-helper.h"
24 
25 #include "ns3/double.h"
26 #include "ns3/log.h"
27 #include "ns3/lora-adr-component.h"
28 #include "ns3/lora-network-controller-components.h"
29 #include "ns3/satellite-lorawan-net-device.h"
30 #include "ns3/simulator.h"
31 #include "ns3/string.h"
32 #include "ns3/trace-source-accessor.h"
33 
34 NS_LOG_COMPONENT_DEFINE("LoraNetworkServerHelper");
35 
36 namespace ns3
37 {
38 
39 NS_OBJECT_ENSURE_REGISTERED(LoraNetworkServerHelper);
40 
41 TypeId
43 {
44  static TypeId tid = TypeId("ns3::LoraNetworkServerHelper")
45  .SetParent<Object>()
46  .AddConstructor<LoraNetworkServerHelper>();
47  return tid;
48 }
49 
51 {
52  m_factory.SetTypeId("ns3::LoraNetworkServer");
53  p2pHelper.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
54  p2pHelper.SetChannelAttribute("Delay", StringValue("2ms"));
55  SetAdr("ns3::LoraAdrComponent");
56 }
57 
59 {
60 }
61 
62 void
63 LoraNetworkServerHelper::SetAttribute(std::string name, const AttributeValue& value)
64 {
65  m_factory.Set(name, value);
66 }
67 
68 void
69 LoraNetworkServerHelper::SetGateways(NodeContainer gateways)
70 {
71  m_gateways = gateways;
72 }
73 
74 void
75 LoraNetworkServerHelper::SetEndDevices(NodeContainer endDevices)
76 {
77  m_endDevices = endDevices;
78 }
79 
80 ApplicationContainer
82 {
83  return ApplicationContainer(InstallPriv(node));
84 }
85 
86 ApplicationContainer
88 {
89  ApplicationContainer apps;
90  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i)
91  {
92  apps.Add(InstallPriv(*i));
93  }
94 
95  return apps;
96 }
97 
98 Ptr<Application>
100 {
101  NS_LOG_FUNCTION(this << node);
102 
103  Ptr<LoraNetworkServer> app = m_factory.Create<LoraNetworkServer>();
104 
105  app->SetNode(node);
106  node->AddApplication(app);
107 
108  // Cycle on each gateway
109  for (NodeContainer::Iterator it = m_gateways.Begin(); it != m_gateways.End(); it++)
110  {
111  // Add the connections with the gateway
112  // Create a PointToPoint link between gateway and NS
113  NetDeviceContainer container = p2pHelper.Install(node, *it);
114 
115  // Add the gateway to the NS list
116  app->AddGateway(*it, container.Get(0));
117 
118  // Link the NetworkServer to its NetDevices
119  for (uint32_t i = 0; i < node->GetNDevices(); i++)
120  {
121  Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
122  currentNetDevice->SetReceiveCallback(MakeCallback(&LoraNetworkServer::Receive, app));
123  }
124  }
125 
126  // Add the end devices
127  app->AddNodes(m_endDevices);
128 
129  // Add components to the NetworkServer
130  InstallComponents(app);
131 
132  return app;
133 }
134 
135 void
137 {
138  NS_LOG_FUNCTION(this << enableAdr);
139 
140  m_adrEnabled = enableAdr;
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION(this << type);
147 
148  m_adrSupportFactory = ObjectFactory();
149  m_adrSupportFactory.SetTypeId(type);
150 }
151 
152 void
153 LoraNetworkServerHelper::InstallComponents(Ptr<LoraNetworkServer> netServer)
154 {
155  NS_LOG_FUNCTION(this << netServer);
156 
157  // Add Confirmed Messages support
158  Ptr<LoraConfirmedMessagesComponent> ackSupport = CreateObject<LoraConfirmedMessagesComponent>();
159  netServer->AddComponent(ackSupport);
160 
161  // Add LinkCheck support
162  Ptr<LoraLinkCheckComponent> linkCheckSupport = CreateObject<LoraLinkCheckComponent>();
163  netServer->AddComponent(linkCheckSupport);
164 
165  // Add Adr support
166  if (m_adrEnabled)
167  {
168  netServer->AddComponent(m_adrSupportFactory.Create<LoraNetworkControllerComponent>());
169  }
170 }
171 } // namespace ns3
Generic class describing a component of the NetworkController.
void SetGateways(NodeContainer gateways)
Set which gateways will need to be connected to this NS.
PointToPointHelper p2pHelper
Helper to create PointToPoint links.
static TypeId GetTypeId(void)
Get the type ID.
void SetAdr(std::string type)
Set the ADR implementation to use in the Network Server created by this helper.
Ptr< Application > InstallPriv(Ptr< Node > node)
void InstallComponents(Ptr< LoraNetworkServer > netServer)
NodeContainer m_endDevices
Set of endDevices to connect to this NS.
void SetEndDevices(NodeContainer endDevices)
Set which end devices will be managed by this NS.
ApplicationContainer Install(NodeContainer c)
void EnableAdr(bool enableAdr)
Enable (true) or disable (false) the ADR component in the Network Server created by this helper.
void SetAttribute(std::string name, const AttributeValue &value)
NodeContainer m_gateways
Set of gateways to connect to this NS.
The LoraNetworkServer is an application standing on top of a node equipped with links that connect it...
bool Receive(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &address)
Receive a packet from a gateway.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.