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 * 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
22#include "forwarder-helper.h"
23
24#include "ns3/double.h"
25#include "ns3/forwarder.h"
26#include "ns3/log.h"
27#include "ns3/lora-net-device.h"
28#include "ns3/random-variable-stream.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("ForwarderHelper");
39
41{
42 m_factory.SetTypeId("ns3::Forwarder");
43}
44
46{
47}
48
49void
50ForwarderHelper::SetAttribute(std::string name, const AttributeValue& value)
51{
52 m_factory.Set(name, value);
53}
54
57{
59}
60
63{
65 for (auto i = c.Begin(); i != c.End(); ++i)
66 {
67 apps.Add(InstallPriv(*i));
68 }
69
70 return apps;
71}
72
75{
76 NS_LOG_FUNCTION(this << node);
77 NS_ASSERT_MSG(node->GetNDevices() == 2,
78 "NDevices != 2, the node must have a LoraNetDevice and a PointToPointNetDevice");
79
81
82 app->SetNode(node);
83 node->AddApplication(app);
84
85 // Link the Forwarder to the NetDevices
86 for (uint32_t i = 0; i < node->GetNDevices(); i++)
87 {
88 Ptr<NetDevice> currNetDev = node->GetDevice(i);
89 if (auto loraNetDev = DynamicCast<LoraNetDevice>(currNetDev); loraNetDev)
90 {
91 app->SetLoraNetDevice(loraNetDev);
92 loraNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromLora, app));
93 }
94 else if (auto p2pNetDev = DynamicCast<PointToPointNetDevice>(currNetDev); p2pNetDev)
95 {
96 app->SetPointToPointNetDevice(p2pNetDev);
97 p2pNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromPointToPoint, app));
98 }
99 else
100 {
101 NS_LOG_ERROR("Potential error: NetDevice is neither Lora nor PointToPoint");
102 }
103 }
104
105 return app;
106}
107} // namespace lorawan
108} // 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:70
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.
Definition: ptr.h:77
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:42
bool ReceiveFromPointToPoint(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the PointToPointNetDevice.
Definition: forwarder.cc:85
bool ReceiveFromLora(Ptr< NetDevice > loraNetDevice, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from the LoraNetDevice.
Definition: forwarder.cc:70
#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_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#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 ",...
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