A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
network-server-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 *
19 * Modified by: Alessandro Aimi <alessandro.aimi@unibo.it>
20 */
21
23
24#include "ns3/adr-component.h"
25#include "ns3/double.h"
26#include "ns3/log.h"
27#include "ns3/network-controller-components.h"
28#include "ns3/point-to-point-channel.h"
29#include "ns3/simulator.h"
30#include "ns3/string.h"
31#include "ns3/trace-source-accessor.h"
32
33namespace ns3
34{
35namespace lorawan
36{
37
38NS_LOG_COMPONENT_DEFINE("NetworkServerHelper");
39
41 : m_adrEnabled(false)
42{
43 m_factory.SetTypeId("ns3::NetworkServer");
44 SetAdr("ns3::AdrComponent");
45}
46
48{
49}
50
51void
53{
54 m_factory.Set(name, value);
55}
56
57void
59{
60 for (const auto& [serverP2PNetDev, gwNode] : registration)
61 {
62 NS_ASSERT_MSG(serverP2PNetDev->GetNode()->GetId() != gwNode->GetId(),
63 "wrong P2P NetDevice detected, please provide the one on the network "
64 "server's side instead");
65 m_gatewayRegistrationList.emplace_back(serverP2PNetDev, gwNode);
66 }
67}
68
69void
71{
72 m_endDevices = endDevices;
73}
74
77{
79}
80
83{
84 NS_LOG_FUNCTION(this << node);
85 NS_ASSERT_MSG(node->GetNDevices() > 0, "No gateways connected to provided node");
86
88
89 app->SetNode(node);
90 node->AddApplication(app);
91
92 // Connect the net devices receive callback to the app and register the respective gateway
93 for (const auto& [currentNetDevice, gwNode] : m_gatewayRegistrationList)
94 {
95 currentNetDevice->SetReceiveCallback(MakeCallback(&NetworkServer::Receive, app));
96 app->AddGateway(gwNode, currentNetDevice);
97 }
98
99 // Add the end devices
100 app->AddNodes(m_endDevices);
101
102 // Add components to the NetworkServer
104
105 return app;
106}
107
108void
110{
111 NS_LOG_FUNCTION(this << enableAdr);
112
113 m_adrEnabled = enableAdr;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << type);
120
123}
124
125void
127{
128 NS_LOG_FUNCTION(this << netServer);
129
130 // Add Confirmed Messages support
131 Ptr<ConfirmedMessagesComponent> ackSupport = CreateObject<ConfirmedMessagesComponent>();
132 netServer->AddComponent(ackSupport);
133
134 // Add LinkCheck support
135 Ptr<LinkCheckComponent> linkCheckSupport = CreateObject<LinkCheckComponent>();
136 netServer->AddComponent(linkCheckSupport);
137
138 // Add Adaptive Data Rate (ADR) support
139 if (m_adrEnabled)
140 {
141 netServer->AddComponent(m_adrSupportFactory.Create<NetworkControllerComponent>());
142 }
143}
144} // namespace lorawan
145} // namespace ns3
holds a vector of ns3::Application pointers.
Hold a value for an Attribute.
Definition: attribute.h:70
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Generic class describing a component of the NetworkController.
void EnableAdr(bool enableAdr)
Enable (true) or disable (false) the Adaptive Data Rate (ADR) component in the Network Server created...
ObjectFactory m_adrSupportFactory
Factory to create the Adaptive Data Rate (ADR) component.
void SetGatewaysP2P(const P2PGwRegistration_t &registration)
Register gateways connected with point-to-point to this network server.
void InstallComponents(Ptr< NetworkServer > netServer)
Install the NetworkServerComponent objects onto the NetworkServer application.
void SetEndDevices(NodeContainer endDevices)
Set which end devices will be managed by this network server.
Ptr< Application > InstallPriv(Ptr< Node > node)
Do the actual NetworkServer application installation on the Node.
std::list< std::pair< Ptr< NetDevice >, Ptr< Node > > > m_gatewayRegistrationList
List of gateway to register to this network server.
ObjectFactory m_factory
Factory to create the Network server application.
void SetAdr(std::string type)
Set the Adaptive Data Rate (ADR) implementation to use in the network server created by this helper.
NodeContainer m_endDevices
Set of end devices to connect to this network server.
ApplicationContainer Install(Ptr< Node > node)
Create one lorawan network server application on the Node.
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
bool m_adrEnabled
Whether to enable the Adaptive Data Rate (ADR) algorithm on the NetworkServer application.
The NetworkServer is an application standing on top of a node equipped with links that connect it wit...
bool Receive(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from a gateway.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
std::list< std::pair< Ptr< PointToPointNetDevice >, Ptr< Node > > > P2PGwRegistration_t
Store network server app registration details for gateway nodes having a P2P link with the network se...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:700