A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
forwarder-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
11#include "forwarder-helper.h"
12
13#include "ns3/double.h"
14#include "ns3/forwarder.h"
15#include "ns3/log.h"
16#include "ns3/lora-net-device.h"
17#include "ns3/random-variable-stream.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("ForwarderHelper");
28
33
37
38void
39ForwarderHelper::SetAttribute(std::string name, const AttributeValue& value)
40{
41 m_factory.Set(name, value);
42}
43
49
52{
54 for (auto i = c.Begin(); i != c.End(); ++i)
55 {
56 apps.Add(InstallPriv(*i));
57 }
58
59 return apps;
60}
61
64{
65 NS_LOG_FUNCTION(this << node);
66 NS_ASSERT_MSG(node->GetNDevices() == 2,
67 "NDevices != 2, the node must have a LoraNetDevice and a PointToPointNetDevice");
68
70
71 app->SetNode(node);
72 node->AddApplication(app);
73
74 // Link the Forwarder to the NetDevices
75 for (uint32_t i = 0; i < node->GetNDevices(); i++)
76 {
77 Ptr<NetDevice> currNetDev = node->GetDevice(i);
78 if (auto loraNetDev = DynamicCast<LoraNetDevice>(currNetDev); loraNetDev)
79 {
80 app->SetLoraNetDevice(loraNetDev);
81 loraNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromLora, app));
82 }
83 else if (auto p2pNetDev = DynamicCast<PointToPointNetDevice>(currNetDev); p2pNetDev)
84 {
85 app->SetPointToPointNetDevice(p2pNetDev);
86 p2pNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromPointToPoint, app));
87 }
88 else
89 {
90 NS_LOG_ERROR("Potential error: NetDevice is neither Lora nor PointToPoint");
91 }
92 }
93
94 return app;
95}
96} // namespace lorawan
97} // namespace ns3
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Hold a value for an Attribute.
Definition attribute.h:59
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
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.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
ObjectFactory m_factory
The object factory.
ApplicationContainer Install(NodeContainer c) const
Install a Forwarder application on each node of the input container configured with all the attribute...
ForwarderHelper()
Default constructor.
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install a Forwarder application on the input Node configured with all the attributes set with SetAttr...
This application forwards packets between NetDevices: LoraNetDevice -> PointToPointNetDevice and vice...
Definition forwarder.h:31
bool ReceiveFromPointToPoint(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the PointToPointNetDevice.
Definition forwarder.cc:74
bool ReceiveFromLora(Ptr< NetDevice > loraNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the LoraNetDevice.
Definition forwarder.cc:59
#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_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#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 ",...
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
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580