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/double.h"
15#include "ns3/log.h"
16#include "ns3/network-controller-components.h"
17#include "ns3/point-to-point-channel.h"
18#include "ns3/simulator.h"
19#include "ns3/string.h"
20#include "ns3/trace-source-accessor.h"
21
22namespace ns3
23{
24namespace lorawan
25{
26
27NS_LOG_COMPONENT_DEFINE("NetworkServerHelper");
28
30 : m_adrEnabled(false)
31{
32 m_factory.SetTypeId("ns3::NetworkServer");
33 SetAdr("ns3::AdrComponent");
34}
35
39
40void
42{
43 m_factory.Set(name, value);
44}
45
46void
48{
49 for (const auto& [serverP2PNetDev, gwNode] : registration)
50 {
51 NS_ASSERT_MSG(serverP2PNetDev->GetNode()->GetId() != gwNode->GetId(),
52 "wrong P2P NetDevice detected, please provide the one on the network "
53 "server's side instead");
54 m_gatewayRegistrationList.emplace_back(serverP2PNetDev, gwNode);
55 }
56}
57
58void
63
69
72{
73 NS_LOG_FUNCTION(this << node);
74 NS_ASSERT_MSG(node->GetNDevices() > 0, "No gateways connected to provided node");
75
77
78 app->SetNode(node);
79 node->AddApplication(app);
80
81 // Connect the net devices receive callback to the app and register the respective gateway
82 for (const auto& [currentNetDevice, gwNode] : m_gatewayRegistrationList)
83 {
84 currentNetDevice->SetReceiveCallback(MakeCallback(&NetworkServer::Receive, app));
85 app->AddGateway(gwNode, currentNetDevice);
86 }
87
88 // Add the end devices
89 app->AddNodes(m_endDevices);
90
91 // Add components to the NetworkServer
93
94 return app;
95}
96
97void
99{
100 NS_LOG_FUNCTION(this << enableAdr);
101
102 m_adrEnabled = enableAdr;
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << type);
109
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << netServer);
118
119 // Add Confirmed Messages support
121 netServer->AddComponent(ackSupport);
122
123 // Add LinkCheck support
125 netServer->AddComponent(linkCheckSupport);
126
127 // Add Adaptive Data Rate (ADR) support
128 if (m_adrEnabled)
129 {
130 netServer->AddComponent(m_adrSupportFactory.Create<NetworkControllerComponent>());
131 }
132}
133} // namespace lorawan
134} // 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.
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.
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:619
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:684