lora-forwarder.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.h"
24 
25 #include "lora-beam-tag.h"
26 
27 #include <ns3/log.h>
28 
29 NS_LOG_COMPONENT_DEFINE("LoraForwarder");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(LoraForwarder);
35 
36 TypeId
38 {
39  static TypeId tid =
40  TypeId("ns3::LoraForwarder").SetParent<Application>().AddConstructor<LoraForwarder>();
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION_NOARGS();
47 }
48 
50 {
51  NS_LOG_FUNCTION_NOARGS();
52 }
53 
54 void
55 LoraForwarder::SetPointToPointNetDevice(Ptr<PointToPointNetDevice> pointToPointNetDevice)
56 {
57  NS_LOG_FUNCTION(this << pointToPointNetDevice);
58 
59  m_pointToPointNetDevice = pointToPointNetDevice;
60 }
61 
62 void
63 LoraForwarder::SetLoraNetDevice(uint8_t beamId, Ptr<SatLorawanNetDevice> loraNetDevice)
64 {
65  NS_LOG_FUNCTION(this << loraNetDevice);
66 
67  m_satLorawanNetDevices[beamId] = loraNetDevice;
68 }
69 
70 bool
71 LoraForwarder::ReceiveFromLora(Ptr<SatLorawanNetDevice> loraNetDevice,
72  Ptr<const Packet> packet,
73  uint16_t protocol,
74  const Address& sender)
75 {
76  NS_LOG_FUNCTION(this << packet << protocol << sender);
77 
78  Ptr<Packet> packetCopy = packet->Copy();
79 
80  LoraBeamTag beamTag = LoraBeamTag(loraNetDevice->GetLorawanMac()->GetBeamId());
81  packetCopy->AddPacketTag(beamTag);
82 
83  m_pointToPointNetDevice->Send(packetCopy, m_pointToPointNetDevice->GetBroadcast(), protocol);
84 
85  return true;
86 }
87 
88 bool
89 LoraForwarder::ReceiveFromPointToPoint(Ptr<NetDevice> pointToPointNetDevice,
90  Ptr<const Packet> packet,
91  uint16_t protocol,
92  const Address& sender)
93 {
94  NS_LOG_FUNCTION(this << packet << protocol << sender);
95 
96  Ptr<Packet> packetCopy = packet->Copy();
97 
98  LoraBeamTag tag;
99  packetCopy->RemovePacketTag(tag);
100  uint8_t beamId = tag.GetBeamId();
101 
102  // TODO not sure address is correct...
103  m_satLorawanNetDevices[beamId]->Send(packetCopy, sender, protocol);
104 
105  return true;
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION(this);
112 
113  // TODO Make sure we are connected to both needed devices
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION_NOARGS();
120 
121  // TODO Get rid of callbacks
122 }
123 
124 } // namespace ns3
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Definition: lora-beam-tag.h:34
uint8_t GetBeamId() const
Read which beam ID this packet was transmitted with.
Ptr< PointToPointNetDevice > m_pointToPointNetDevice
Pointer to the P2PNetDevice we use to.
bool ReceiveFromLora(Ptr< SatLorawanNetDevice > loraNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the LoraNetDevice.
std::map< uint8_t, Ptr< SatLorawanNetDevice > > m_satLorawanNetDevices
Map between beam ID and pointer to the node's SatLorawanNetDevice.
static TypeId GetTypeId(void)
void StartApplication(void)
Start the application.
void StopApplication(void)
Stop the application.
void SetLoraNetDevice(uint8_t beamId, Ptr< SatLorawanNetDevice > loraNetDevice)
Sets the device to use to communicate with the EDs.
bool ReceiveFromPointToPoint(Ptr< NetDevice > pointToPointNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the PointToPointNetDevice.
void SetPointToPointNetDevice(Ptr< PointToPointNetDevice > pointToPointNetDevice)
Sets the P2P device to use to communicate with the NS.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.