Loading...
Searching...
No Matches
lora-network-server.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2018 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 * Authors: Davide Magrin <magrinda@dei.unipd.it>
19 * Martina Capuzzo <capuzzom@dei.unipd.it>
20 *
21 * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
22 */
23
24#include "lora-network-server.h"
25
26#include "lora-device-address.h"
27#include "lora-frame-header.h"
28#include "lora-network-status.h"
29#include "lorawan-mac-command.h"
31#include "lorawan-mac-header.h"
33#include "satellite-topology.h"
34
35#include "ns3/log.h"
36#include "ns3/singleton.h"
37
38namespace ns3
39{
40
41NS_LOG_COMPONENT_DEFINE("LoraNetworkServer");
42
43NS_OBJECT_ENSURE_REGISTERED(LoraNetworkServer);
44
45TypeId
47{
48 static TypeId tid =
49 TypeId("ns3::LoraNetworkServer")
50 .SetParent<Application>()
51 .AddConstructor<LoraNetworkServer>()
52 .AddTraceSource(
53 "ReceivedPacket",
54 "Trace source that is fired when a packet arrives at the Network Server",
55 MakeTraceSourceAccessor(&LoraNetworkServer::m_receivedPacket),
56 "ns3::Packet::TracedCallback");
57 return tid;
58}
59
61 : m_status(CreateObject<LoraNetworkStatus>()),
64{
65 NS_LOG_FUNCTION_NOARGS();
66}
67
69{
70 NS_LOG_FUNCTION_NOARGS();
71}
72
73void
75{
76 NS_LOG_FUNCTION_NOARGS();
77}
78
79void
81{
82 NS_LOG_FUNCTION_NOARGS();
83}
84
85void
86LoraNetworkServer::AddGateway(Ptr<Node> gateway, Ptr<NetDevice> netDevice)
87{
88 NS_LOG_FUNCTION(this << gateway);
89
90 // Get the PointToPointNetDevice
91 Ptr<PointToPointNetDevice> p2pNetDevice;
92 for (uint32_t i = 0; i < gateway->GetNDevices(); i++)
93 {
94 p2pNetDevice = gateway->GetDevice(i)->GetObject<PointToPointNetDevice>();
95 if (p2pNetDevice != nullptr)
96 {
97 // We found a p2pNetDevice on the gateway
98 break;
99 }
100 }
101
102 // Get the Address
103 Address gatewayAddress = p2pNetDevice->GetAddress();
104
105 // Get the gateway's LoRa MAC layer (assumes gateway's MAC is configured as first device)
106 switch (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode())
107 {
109 Ptr<SatLorawanNetDevice> satLoraNetDevice =
110 DynamicCast<SatLorawanNetDevice>(gateway->GetDevice(1));
111 Ptr<LorawanMacGateway> gwMac = DynamicCast<LorawanMacGateway>(satLoraNetDevice->GetMac());
112 // Create new gatewayStatus
113 Ptr<LoraGatewayStatus> gwStatus =
114 CreateObject<LoraGatewayStatus>(gatewayAddress, netDevice, gwMac);
115 m_status->AddGateway(gateway, gatewayAddress, gwStatus);
116 break;
117 }
119 // Create new gatewayStatus
120 Ptr<LoraGatewayStatus> gwStatus =
121 CreateObject<LoraGatewayStatus>(gatewayAddress, netDevice, nullptr);
122 m_status->AddGateway(gateway, gatewayAddress, gwStatus);
123 break;
124 }
125 default:
126 NS_FATAL_ERROR("Incorrect regeneration mode for LORA");
127 }
128}
129
130void
131LoraNetworkServer::AddNodes(NodeContainer nodes)
132{
133 NS_LOG_FUNCTION_NOARGS();
134
135 // For each node in the container, call the function to add that single node
136 NodeContainer::Iterator it;
137 for (it = nodes.Begin(); it != nodes.End(); it++)
138 {
139 AddNode(*it);
140 }
141}
142
143void
145{
146 NS_LOG_FUNCTION(this << node);
147
148 // Get the SatLorawanNetDevice
149 Ptr<SatLorawanNetDevice> loraNetDevice;
150 for (uint32_t i = 0; i < node->GetNDevices(); i++)
151 {
152 loraNetDevice = DynamicCast<SatLorawanNetDevice>(node->GetDevice(i));
153 if (loraNetDevice != nullptr)
154 {
155 // We found a SatLorawanNetDevice on the node
156 break;
157 }
158 }
159
160 // Get the MAC
161 Ptr<LorawanMacEndDeviceClassA> edLorawanMac =
162 DynamicCast<LorawanMacEndDeviceClassA>(loraNetDevice->GetMac());
163
164 // Update the NetworkStatus about the existence of this node
165 m_status->AddNode(edLorawanMac);
166}
167
168bool
169LoraNetworkServer::Receive(Ptr<NetDevice> device,
170 Ptr<const Packet> packet,
171 uint16_t protocol,
172 const Address& address)
173{
174 NS_LOG_FUNCTION(this << packet << protocol << address);
175
176 // Fire the trace source
177 m_receivedPacket(packet);
178
179 // Inform the scheduler of the newly arrived packet
180 m_scheduler->OnReceivedPacket(packet);
181
182 // Inform the status of the newly arrived packet
183 m_status->OnReceivedPacket(packet, address);
184
185 // Inform the controller of the newly arrived packet
186 m_controller->OnNewPacket(packet);
187
188 return true;
189}
190
191void
192LoraNetworkServer::AddComponent(Ptr<LoraNetworkControllerComponent> component)
193{
194 NS_LOG_FUNCTION(this << component);
195
196 m_controller->Install(component);
197}
198
199Ptr<LoraNetworkStatus>
204
205} // namespace ns3
This class collects a series of components that deal with various aspects of managing the network,...
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.
TracedCallback< Ptr< const Packet > > m_receivedPacket
static TypeId GetTypeId(void)
void StartApplication(void)
Start the NS application.
void AddGateway(Ptr< Node > gateway, Ptr< NetDevice > netDevice)
Add this gateway to the list of gateways connected to this NS.
Ptr< LoraNetworkStatus > m_status
void AddNodes(NodeContainer nodes)
Inform the LoraNetworkServer that these nodes are connected to the network.
Ptr< LoraNetworkScheduler > m_scheduler
void AddNode(Ptr< Node > node)
Inform the LoraNetworkServer that this node is connected to the network.
void StopApplication(void)
Stop the NS application.
void AddComponent(Ptr< LoraNetworkControllerComponent > component)
A NetworkControllerComponent to this LoraNetworkServer instance.
Ptr< LoraNetworkController > m_controller
Ptr< LoraNetworkStatus > GetNetworkStatus(void)
This class represents the knowledge about the state of the network that is available at the Network S...
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.