lora-forwarder-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 "lora-forwarder-helper.h"
24 
25 #include <ns3/double.h>
26 #include <ns3/log.h>
27 #include <ns3/lora-forwarder.h>
28 #include <ns3/random-variable-stream.h>
29 #include <ns3/satellite-topology.h>
30 #include <ns3/simulator.h>
31 #include <ns3/singleton.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("LoraForwarderHelper");
39 
40 namespace ns3
41 {
42 
43 NS_OBJECT_ENSURE_REGISTERED(LoraForwarderHelper);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId("ns3::LoraForwarderHelper")
49  .SetParent<Object>()
50  .AddConstructor<LoraForwarderHelper>();
51  return tid;
52 }
53 
55 {
56  m_factory.SetTypeId("ns3::LoraForwarder");
57 }
58 
60 {
61 }
62 
63 void
64 LoraForwarderHelper::SetAttribute(std::string name, const AttributeValue& value)
65 {
66  m_factory.Set(name, value);
67 }
68 
69 ApplicationContainer
70 LoraForwarderHelper::Install(Ptr<Node> node) const
71 {
72  switch (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode())
73  {
74  case SatEnums::TRANSPARENT: {
75  return ApplicationContainer(InstallPrivGwLora(node));
76  }
78  return ApplicationContainer(InstallPrivGwDvb(node));
79  }
80  default:
81  NS_FATAL_ERROR("Incorrect regeneration mode for LORA");
82  }
83 }
84 
85 ApplicationContainer
86 LoraForwarderHelper::Install(NodeContainer c) const
87 {
88  ApplicationContainer apps;
89  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i)
90  {
91  apps.Add(Install(*i));
92  }
93 
94  return apps;
95 }
96 
97 Ptr<Application>
99 {
100  NS_LOG_FUNCTION(this << node);
101 
102  Ptr<LoraForwarder> app = m_factory.Create<LoraForwarder>();
103 
104  app->SetNode(node);
105  node->AddApplication(app);
106 
107  // Link the LoraForwarder to the SatLorawanNetDevices
108  for (uint32_t i = 0; i < node->GetNDevices(); i++)
109  {
110  Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
111  if (currentNetDevice->GetObject<SatLorawanNetDevice>() != nullptr)
112  {
113  Ptr<SatLorawanNetDevice> loraNetDevice =
114  currentNetDevice->GetObject<SatLorawanNetDevice>();
115  uint8_t beamId = loraNetDevice->GetMac()->GetBeamId();
116  app->SetLoraNetDevice(beamId, loraNetDevice);
117  loraNetDevice->SetReceiveNetworkServerCallback(
118  MakeCallback(&LoraForwarder::ReceiveFromLora, app));
119  }
120  else if (currentNetDevice->GetObject<PointToPointNetDevice>() != nullptr)
121  {
122  Ptr<PointToPointNetDevice> pointToPointNetDevice =
123  currentNetDevice->GetObject<PointToPointNetDevice>();
124  app->SetPointToPointNetDevice(pointToPointNetDevice);
125  pointToPointNetDevice->SetReceiveCallback(
126  MakeCallback(&LoraForwarder::ReceiveFromPointToPoint, app));
127  }
128  }
129 
130  return app;
131 }
132 
133 Ptr<Application>
135 {
136  NS_LOG_FUNCTION(this << node);
137 
138  Ptr<LoraForwarder> app = m_factory.Create<LoraForwarder>();
139 
140  app->SetNode(node);
141  node->AddApplication(app);
142 
143  // Link the LoraForwarder to the SatLorawanNetDevices
144  for (uint32_t i = 0; i < node->GetNDevices(); i++)
145  {
146  Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
147  if (currentNetDevice->GetObject<SatLorawanNetDevice>() != nullptr)
148  {
149  Ptr<SatLorawanNetDevice> loraNetDevice =
150  currentNetDevice->GetObject<SatLorawanNetDevice>();
151  uint8_t beamId = loraNetDevice->GetMac()->GetBeamId();
152  app->SetLoraNetDevice(beamId, loraNetDevice);
153  loraNetDevice->SetReceiveNetworkServerCallback(
154  MakeCallback(&LoraForwarder::ReceiveFromLora, app));
155  }
156  else if (currentNetDevice->GetObject<PointToPointNetDevice>() != nullptr)
157  {
158  Ptr<PointToPointNetDevice> pointToPointNetDevice =
159  currentNetDevice->GetObject<PointToPointNetDevice>();
160  app->SetPointToPointNetDevice(pointToPointNetDevice);
161  pointToPointNetDevice->SetReceiveCallback(
162  MakeCallback(&LoraForwarder::ReceiveFromPointToPoint, app));
163  }
164  }
165 
166  return app;
167 }
168 
169 } // namespace ns3
Ptr< Application > InstallPrivGwDvb(Ptr< Node > node) const
Install if ground GW is a DVB GW.
void SetAttribute(std::string name, const AttributeValue &value)
Ptr< Application > InstallPrivGwLora(Ptr< Node > node) const
Install if ground GW is a Lora GW.
ApplicationContainer Install(NodeContainer c) const
static TypeId GetTypeId(void)
Get the type ID.
This application forwards packets between NetDevices: SatLorawanNetDevice -> PointToPointNetDevice an...
bool ReceiveFromLora(Ptr< SatLorawanNetDevice > loraNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the LoraNetDevice.
bool ReceiveFromPointToPoint(Ptr< NetDevice > pointToPointNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the PointToPointNetDevice.
SatLorawanNetDevice to be utilized in the UT and GW nodes for IoT configuration.
Ptr< SatMac > GetMac(void) const
Get a Mac pointer.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.