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/simulator.h>
30 #include <ns3/string.h>
31 #include <ns3/trace-source-accessor.h>
32 
33 NS_LOG_COMPONENT_DEFINE("LoraForwarderHelper");
34 
35 namespace ns3
36 {
37 
38 NS_OBJECT_ENSURE_REGISTERED(LoraForwarderHelper);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId("ns3::LoraForwarderHelper")
44  .SetParent<Object>()
45  .AddConstructor<LoraForwarderHelper>();
46  return tid;
47 }
48 
50 {
51  m_factory.SetTypeId("ns3::LoraForwarder");
52 }
53 
55 {
56 }
57 
58 void
59 LoraForwarderHelper::SetAttribute(std::string name, const AttributeValue& value)
60 {
61  m_factory.Set(name, value);
62 }
63 
64 ApplicationContainer
65 LoraForwarderHelper::Install(Ptr<Node> node) const
66 {
67  return ApplicationContainer(InstallPriv(node));
68 }
69 
70 ApplicationContainer
71 LoraForwarderHelper::Install(NodeContainer c) const
72 {
73  ApplicationContainer apps;
74  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i)
75  {
76  apps.Add(InstallPriv(*i));
77  }
78 
79  return apps;
80 }
81 
82 Ptr<Application>
83 LoraForwarderHelper::InstallPriv(Ptr<Node> node) const
84 {
85  NS_LOG_FUNCTION(this << node);
86 
87  Ptr<LoraForwarder> app = m_factory.Create<LoraForwarder>();
88 
89  app->SetNode(node);
90  node->AddApplication(app);
91 
92  // Link the LoraForwarder to the SatLorawanNetDevices
93  for (uint32_t i = 0; i < node->GetNDevices(); i++)
94  {
95  Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
96  if (currentNetDevice->GetObject<SatLorawanNetDevice>() != nullptr)
97  {
98  Ptr<SatLorawanNetDevice> loraNetDevice =
99  currentNetDevice->GetObject<SatLorawanNetDevice>();
100  uint8_t beamId = loraNetDevice->GetLorawanMac()->GetBeamId();
101  app->SetLoraNetDevice(beamId, loraNetDevice);
102  loraNetDevice->SetReceiveNetworkServerCallback(
103  MakeCallback(&LoraForwarder::ReceiveFromLora, app));
104  }
105  else if (currentNetDevice->GetObject<PointToPointNetDevice>() != nullptr)
106  {
107  Ptr<PointToPointNetDevice> pointToPointNetDevice =
108  currentNetDevice->GetObject<PointToPointNetDevice>();
109  app->SetPointToPointNetDevice(pointToPointNetDevice);
110  pointToPointNetDevice->SetReceiveCallback(
111  MakeCallback(&LoraForwarder::ReceiveFromPointToPoint, app));
112  }
113  }
114 
115  return app;
116 }
117 } // namespace ns3
void SetAttribute(std::string name, const AttributeValue &value)
ApplicationContainer Install(NodeContainer c) const
static TypeId GetTypeId(void)
Get the type ID.
Ptr< Application > InstallPriv(Ptr< Node > node) const
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.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.