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 
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/satellite-topology.h"
31 #include "ns3/simulator.h"
32 #include "ns3/string.h"
33 #include "ns3/trace-source-accessor.h"
34 
35 #include <stdint.h>
36 #include <string>
37 
38 NS_LOG_COMPONENT_DEFINE("LoraNetworkServerHelper");
39 
40 namespace ns3
41 {
42 
43 NS_OBJECT_ENSURE_REGISTERED(LoraNetworkServerHelper);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId("ns3::LoraNetworkServerHelper")
49  .SetParent<Object>()
50  .AddConstructor<LoraNetworkServerHelper>();
51  return tid;
52 }
53 
55 {
56  m_factory.SetTypeId("ns3::LoraNetworkServer");
57  p2pHelper.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
58  p2pHelper.SetChannelAttribute("Delay", StringValue("2ms"));
59  SetAdr("ns3::LoraAdrComponent");
60 }
61 
63 {
64 }
65 
66 void
67 LoraNetworkServerHelper::SetAttribute(std::string name, const AttributeValue& value)
68 {
69  m_factory.Set(name, value);
70 }
71 
72 ApplicationContainer
74 {
75  return ApplicationContainer(InstallPriv(node));
76 }
77 
78 ApplicationContainer
80 {
81  ApplicationContainer apps;
82  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i)
83  {
84  apps.Add(InstallPriv(*i));
85  }
86 
87  return apps;
88 }
89 
90 Ptr<Application>
92 {
93  NS_LOG_FUNCTION(this << node);
94 
95  Ptr<LoraNetworkServer> app = m_factory.Create<LoraNetworkServer>();
96 
97  app->SetNode(node);
98  node->AddApplication(app);
99 
100  // Cycle on each gateway
101  NodeContainer gwNodes = Singleton<SatTopology>::Get()->GetGwNodes();
102  for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
103  {
104  // Add the connections with the gateway
105  // Create a PointToPoint link between gateway and NS
106  NetDeviceContainer container = p2pHelper.Install(node, *it);
107 
108  // Add the gateway to the NS list
109  app->AddGateway(*it, container.Get(0));
110 
111  // Link the NetworkServer to its NetDevices
112  for (uint32_t i = 0; i < node->GetNDevices(); i++)
113  {
114  Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
115  currentNetDevice->SetReceiveCallback(MakeCallback(&LoraNetworkServer::Receive, app));
116  }
117  }
118 
119  // Add the end devices
120  app->AddNodes(Singleton<SatTopology>::Get()->GetUtNodes());
121 
122  // Add components to the NetworkServer
123  InstallComponents(app);
124 
125  return app;
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION(this << enableAdr);
132 
133  m_adrEnabled = enableAdr;
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION(this << type);
140 
141  m_adrSupportFactory = ObjectFactory();
142  m_adrSupportFactory.SetTypeId(type);
143 }
144 
145 void
146 LoraNetworkServerHelper::InstallComponents(Ptr<LoraNetworkServer> netServer)
147 {
148  NS_LOG_FUNCTION(this << netServer);
149 
150  // Add Confirmed Messages support
151  Ptr<LoraConfirmedMessagesComponent> ackSupport = CreateObject<LoraConfirmedMessagesComponent>();
152  netServer->AddComponent(ackSupport);
153 
154  // Add LinkCheck support
155  Ptr<LoraLinkCheckComponent> linkCheckSupport = CreateObject<LoraLinkCheckComponent>();
156  netServer->AddComponent(linkCheckSupport);
157 
158  // Add Adr support
159  if (m_adrEnabled)
160  {
161  netServer->AddComponent(m_adrSupportFactory.Create<LoraNetworkControllerComponent>());
162  }
163 }
164 } // namespace ns3
Generic class describing a component of the NetworkController.
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)
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)
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.