A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
one-shot-sender.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
20#include "one-shot-sender.h"
21
23#include "lora-net-device.h"
24
25#include "ns3/double.h"
26#include "ns3/log.h"
27#include "ns3/pointer.h"
28#include "ns3/string.h"
29
30namespace ns3
31{
32namespace lorawan
33{
34
35NS_LOG_COMPONENT_DEFINE("OneShotSender");
36
37NS_OBJECT_ENSURE_REGISTERED(OneShotSender);
38
39TypeId
41{
42 static TypeId tid = TypeId("ns3::OneShotSender")
44 .AddConstructor<OneShotSender>()
45 .SetGroupName("lorawan");
46 return tid;
47}
48
50{
52}
53
55 : m_sendTime(sendTime)
56{
58}
59
61{
63}
64
65void
67{
68 NS_LOG_FUNCTION(this << sendTime);
69
70 m_sendTime = sendTime;
71}
72
73void
75{
76 NS_LOG_FUNCTION(this);
77
78 // Create and send a new packet
79 Ptr<Packet> packet = Create<Packet>(10);
80 m_mac->Send(packet);
81}
82
83void
85{
86 NS_LOG_FUNCTION(this);
87
88 // Make sure we have a MAC layer
89 if (!m_mac)
90 {
91 // Assumes there's only one device
92 Ptr<LoraNetDevice> loraNetDevice = m_node->GetDevice(0)->GetObject<LoraNetDevice>();
93
94 m_mac = loraNetDevice->GetMac();
96 }
97
98 // Schedule the next SendPacket event
101}
102
103void
105{
108}
109} // namespace lorawan
110} // namespace ns3
The base class for all ns3 applications.
Definition: application.h:62
Ptr< Node > m_node
The node that this application is installed on.
Definition: application.h:158
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:149
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:285
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold together all LoRa related objects.
EventId m_sendEvent
The sending event.
void SendPacket()
Send a packet using the LoraNetDevice's Send method.
Ptr< LorawanMac > m_mac
The MAC layer of this node.
~OneShotSender() override
Destructor.
void StartApplication() override
Start the application by scheduling the first SendPacket event.
OneShotSender()
Default constructor.
static TypeId GetTypeId()
Register this type.
void SetSendTime(Time sendTime)
Set the time at which this app will send a packet.
void StopApplication() override
Stop the application.
Time m_sendTime
The time at which to send the packet.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.