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
12#include "lora-net-device.h"
13
14#include "ns3/double.h"
15#include "ns3/log.h"
16#include "ns3/pointer.h"
17#include "ns3/string.h"
18
19namespace ns3
20{
21namespace lorawan
22{
23
24NS_LOG_COMPONENT_DEFINE("OneShotSender");
25
26NS_OBJECT_ENSURE_REGISTERED(OneShotSender);
27
28TypeId
30{
31 static TypeId tid = TypeId("ns3::OneShotSender")
33 .AddConstructor<OneShotSender>()
34 .SetGroupName("lorawan");
35 return tid;
36}
37
42
44 : m_sendTime(sendTime)
45{
47}
48
53
54void
56{
57 NS_LOG_FUNCTION(this << sendTime);
58
59 m_sendTime = sendTime;
60}
61
62void
64{
65 NS_LOG_FUNCTION(this);
66
67 // Create and send a new packet
68 Ptr<Packet> packet = Create<Packet>(10);
69 m_mac->Send(packet);
70}
71
72void
74{
75 NS_LOG_FUNCTION(this);
76
77 // Make sure we have a MAC layer
78 if (!m_mac)
79 {
80 // Assumes there's only one device
82
83 m_mac = loraNetDevice->GetMac();
85 }
86
87 // Schedule the next SendPacket event
90}
91
92void
98} // namespace lorawan
99} // namespace ns3
The base class for all ns3 applications.
Definition application.h:51
Ptr< Node > m_node
The node that this application is installed on.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition node.cc:138
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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:274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:191
#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:436
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:580