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#include "lorawan-mac.h"
13
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18namespace lorawan
19{
20
21NS_LOG_COMPONENT_DEFINE("PeriodicSender");
22
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::PeriodicSender")
30 .AddConstructor<PeriodicSender>()
31 .SetGroupName("lorawan")
32 .AddAttribute("Interval",
33 "The interval between packet sends of this app",
34 TimeValue(Time(0)),
38 // .AddAttribute ("PacketSizeRandomVariable", "The random variable that determines the shape of
39 // the packet size, in bytes",
40 // StringValue ("ns3::UniformRandomVariable[Min=0,Max=10]"),
41 // MakePointerAccessor (&PeriodicSender::m_pktSizeRV),
42 // MakePointerChecker <RandomVariableStream>());
43 return tid;
44}
45
55
60
61void
63{
64 NS_LOG_FUNCTION(this << interval);
65 m_interval = interval;
66}
67
68Time
70{
71 NS_LOG_FUNCTION(this);
72 return m_interval;
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << delay);
79 m_initialDelay = delay;
80}
81
82void
87
88void
90{
91 m_basePktSize = size;
92}
93
94void
96{
97 NS_LOG_FUNCTION(this);
98
99 // Create and send a new packet
100 Ptr<Packet> packet;
101 if (m_pktSizeRV)
102 {
103 int randomsize = m_pktSizeRV->GetInteger();
104 packet = Create<Packet>(m_basePktSize + randomsize);
105 }
106 else
107 {
109 }
110 m_mac->Send(packet);
111
112 // Schedule the next SendPacket event
114
115 NS_LOG_DEBUG("Sent a packet of size " << packet->GetSize());
116}
117
118void
120{
121 NS_LOG_FUNCTION(this);
122
123 // Make sure we have a MAC layer
124 if (!m_mac)
125 {
126 // Assumes there's only one device
127 Ptr<LoraNetDevice> loraNetDevice = DynamicCast<LoraNetDevice>(m_node->GetDevice(0));
128
129 m_mac = loraNetDevice->GetMac();
131 }
132
133 // Schedule the next SendPacket event
135 NS_LOG_DEBUG("Starting up application with a first event with a " << m_initialDelay.As(Time::S)
136 << " delay");
138 NS_LOG_DEBUG("Event Id: " << m_sendEvent.GetUid());
139}
140
141void
147
148} // namespace lorawan
149} // 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
@ S
second
Definition nstime.h:106
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Implements a sender application generating packets following a periodic point process.
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:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1376
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:605
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1396