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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "one-shot-sender.h"
10
11#include "lora-net-device.h"
12#include "lorawan-mac.h"
13
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18namespace lorawan
19{
20
21NS_LOG_COMPONENT_DEFINE("OneShotSender");
22
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::OneShotSender")
30 .AddConstructor<OneShotSender>()
31 .SetGroupName("lorawan");
32 return tid;
33}
34
39
45
50
51void
53{
54 NS_LOG_FUNCTION(this << sendTime);
55
56 m_sendTime = sendTime;
57}
58
59void
61{
62 NS_LOG_FUNCTION(this);
63
64 // Create and send a new packet
65 Ptr<Packet> packet = Create<Packet>(10);
66 m_mac->Send(packet);
67}
68
69void
71{
72 NS_LOG_FUNCTION(this);
73
74 // Make sure we have a MAC layer
75 if (!m_mac)
76 {
77 // Assumes there's only one device
78 Ptr<LoraNetDevice> loraNetDevice = DynamicCast<LoraNetDevice>(m_node->GetDevice(0));
79
80 m_mac = loraNetDevice->GetMac();
82 }
83
84 // Schedule the next SendPacket event
87}
88
89void
95
96} // namespace lorawan
97} // namespace ns3
Ptr< Node > m_node
The node that this application is installed on.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
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:268
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Packet sender application to send a single packet.
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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
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