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/forwarder.h"
14#include "ns3/lora-net-device.h"
15
16namespace ns3
17{
18namespace lorawan
19{
20
21NS_LOG_COMPONENT_DEFINE("ForwarderHelper");
22
24{
25 m_factory.SetTypeId("ns3::Forwarder");
26}
27
31
32void
33ForwarderHelper::SetAttribute(std::string name, const AttributeValue& value)
34{
35 m_factory.Set(name, value);
36}
37
43
46{
48 for (auto i = c.Begin(); i != c.End(); ++i)
49 {
50 apps.Add(InstallPriv(*i));
51 }
52
53 return apps;
54}
55
58{
59 NS_LOG_FUNCTION(this << node);
60 NS_ASSERT_MSG(node->GetNDevices() == 2,
61 "NDevices != 2, the node must have a LoraNetDevice and a PointToPointNetDevice");
62
63 Ptr<Forwarder> app = m_factory.Create<Forwarder>();
64
65 app->SetNode(node);
66 node->AddApplication(app);
67
68 // Link the Forwarder to the NetDevices
69 for (uint32_t i = 0; i < node->GetNDevices(); i++)
70 {
71 Ptr<NetDevice> currNetDev = node->GetDevice(i);
72 if (auto loraNetDev = DynamicCast<LoraNetDevice>(currNetDev); loraNetDev)
73 {
74 app->SetLoraNetDevice(loraNetDev);
75 loraNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromLora, app));
76 }
77 else if (auto p2pNetDev = DynamicCast<PointToPointNetDevice>(currNetDev); p2pNetDev)
78 {
79 app->SetPointToPointNetDevice(p2pNetDev);
80 p2pNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromPointToPoint, app));
81 }
82 else
83 {
84 NS_LOG_ERROR("Potential error: NetDevice is neither Lora nor PointToPoint");
85 }
86 }
87
88 return app;
89}
90
91} // namespace lorawan
92} // 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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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:29
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
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_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:246
#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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:605