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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 *
8 * Modified by: Alessandro Aimi <alessandro.aimi@unibo.it>
9 */
10
12
13#include "ns3/adr-component.h"
14#include "ns3/network-server.h"
15
16namespace ns3
17{
18namespace lorawan
19{
20
21NS_LOG_COMPONENT_DEFINE("NetworkServerHelper");
22
24 : m_adrEnabled(true)
25{
26 m_factory.SetTypeId("ns3::NetworkServer");
27 SetAdr("ns3::AdrComponent");
28}
29
33
34void
36{
37 m_factory.Set(name, value);
38}
39
40void
42{
43 for (const auto& [serverP2PNetDev, gwNode] : registration)
44 {
45 NS_ASSERT_MSG(serverP2PNetDev->GetNode()->GetId() != gwNode->GetId(),
46 "wrong P2P NetDevice detected, please provide the one on the network "
47 "server's side instead");
48 m_gatewayRegistrationList.emplace_back(serverP2PNetDev, gwNode);
49 }
50}
51
52void
57
63
66{
67 NS_LOG_FUNCTION(this << node);
68 NS_ASSERT_MSG(node->GetNDevices() > 0, "No gateways connected to provided node");
69
71
72 app->SetNode(node);
73 node->AddApplication(app);
74
75 // Connect the net devices receive callback to the app and register the respective gateway
76 for (const auto& [currentNetDevice, gwNode] : m_gatewayRegistrationList)
77 {
78 currentNetDevice->SetReceiveCallback(MakeCallback(&NetworkServer::Receive, app));
79 app->AddGateway(gwNode, currentNetDevice);
80 }
81
82 // Add the end devices
83 app->AddNodes(m_endDevices);
84
85 // Add components to the NetworkServer
87
88 return app;
89}
90
91void
93{
94 NS_LOG_FUNCTION(this << enableAdr);
95
96 m_adrEnabled = enableAdr;
97}
98
99void
101{
102 NS_LOG_FUNCTION(this << type);
103
105 m_adrSupportFactory.SetTypeId(type);
106}
107
108void
110{
111 NS_LOG_FUNCTION(this << netServer);
112
113 // Add Confirmed Messages support
115 netServer->AddComponent(ackSupport);
116
117 // Add LinkCheck support
119 netServer->AddComponent(linkCheckSupport);
120
121 // Add Adaptive Data Rate (ADR) support
122 if (m_adrEnabled)
123 {
124 netServer->AddComponent(m_adrSupportFactory.Create<NetworkControllerComponent>());
125 }
126}
127
128} // namespace lorawan
129} // namespace ns3
holds a vector of ns3::Application pointers.
Hold a value for an Attribute.
Definition attribute.h:59
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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:75
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:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
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.