A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
periodic-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 "periodic-sender.h"
10
11#include "lora-net-device.h"
12
13#include "ns3/double.h"
14#include "ns3/log.h"
15#include "ns3/pointer.h"
16#include "ns3/string.h"
17
18namespace ns3
19{
20namespace lorawan
21{
22
23NS_LOG_COMPONENT_DEFINE("PeriodicSender");
24
25NS_OBJECT_ENSURE_REGISTERED(PeriodicSender);
26
27TypeId
29{
30 static TypeId tid = TypeId("ns3::PeriodicSender")
32 .AddConstructor<PeriodicSender>()
33 .SetGroupName("lorawan")
34 .AddAttribute("Interval",
35 "The interval between packet sends of this app",
40 // .AddAttribute ("PacketSizeRandomVariable", "The random variable that determines the shape of
41 // the packet size, in bytes",
42 // StringValue ("ns3::UniformRandomVariable[Min=0,Max=10]"),
43 // MakePointerAccessor (&PeriodicSender::m_pktSizeRV),
44 // MakePointerChecker <RandomVariableStream>());
45 return tid;
46}
47
49 : m_interval(Seconds(10)),
50 m_initialDelay(Seconds(1)),
51 m_basePktSize(10),
52 m_pktSizeRV(nullptr)
53
54{
56}
57
62
63void
65{
66 NS_LOG_FUNCTION(this << interval);
67 m_interval = interval;
68}
69
70Time
72{
73 NS_LOG_FUNCTION(this);
74 return m_interval;
75}
76
77void
79{
80 NS_LOG_FUNCTION(this << delay);
81 m_initialDelay = delay;
82}
83
84void
89
90void
92{
93 m_basePktSize = size;
94}
95
96void
98{
99 NS_LOG_FUNCTION(this);
100
101 // Create and send a new packet
102 Ptr<Packet> packet;
103 if (m_pktSizeRV)
104 {
105 int randomsize = m_pktSizeRV->GetInteger();
106 packet = Create<Packet>(m_basePktSize + randomsize);
107 }
108 else
109 {
111 }
112 m_mac->Send(packet);
113
114 // Schedule the next SendPacket event
116
117 NS_LOG_DEBUG("Sent a packet of size " << packet->GetSize());
118}
119
120void
122{
123 NS_LOG_FUNCTION(this);
124
125 // Make sure we have a MAC layer
126 if (!m_mac)
127 {
128 // Assumes there's only one device
130
131 m_mac = loraNetDevice->GetMac();
133 }
134
135 // Schedule the next SendPacket event
137 NS_LOG_DEBUG("Starting up application with a first event with a " << m_initialDelay.GetSeconds()
138 << " seconds delay");
140 NS_LOG_DEBUG("Event Id: " << m_sendEvent.GetUid());
141}
142
143void
149
150} // namespace lorawan
151} // 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.
uint32_t GetUid() const
Definition event-id.cc:99
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.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
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
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Ptr< RandomVariableStream > m_pktSizeRV
The random variable that adds bytes to the packet size.
Time m_interval
The interval between to consecutive send events.
~PeriodicSender() override
Destructor.
Time GetInterval() const
Get the sending interval.
Ptr< LorawanMac > m_mac
The MAC layer of this node.
void SetInterval(Time interval)
Set the sending interval.
void SetPacketSize(uint8_t size)
Set packet size.
void StartApplication() override
Start the application by scheduling the first SendPacket event.
void SetInitialDelay(Time delay)
Set the initial delay of this application.
void SetPacketSizeRandomVariable(Ptr< RandomVariableStream > rv)
Set to add randomness to the base packet size.
Time m_initialDelay
The initial delay of this application.
static TypeId GetTypeId()
Register this type.
void SendPacket()
Send a packet using the LoraNetDevice's Send method.
EventId m_sendEvent
The sending event scheduled as next.
PeriodicSender()
Default constructor.
void StopApplication() override
Stop the application.
uint8_t m_basePktSize
The packet size.
#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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416