A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
periodic-sender-helper.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
10
11#include "ns3/double.h"
12#include "ns3/periodic-sender.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
19NS_LOG_COMPONENT_DEFINE("PeriodicSenderHelper");
20
22{
23 m_factory.SetTypeId("ns3::PeriodicSender");
24
25 // m_factory.Set ("PacketSizeRandomVariable", StringValue
26 // ("ns3::ParetoRandomVariable[Bound=10|Shape=2.5]"));
27
29 m_initialDelay->SetAttribute("Min", DoubleValue(0));
30
32 m_intervalProb->SetAttribute("Min", DoubleValue(0));
33 m_intervalProb->SetAttribute("Max", DoubleValue(1));
34
35 m_pktSize = 10;
36 m_pktSizeRV = nullptr;
37}
38
42
43void
45{
46 m_factory.Set(name, value);
47}
48
54
57{
59 for (auto i = c.Begin(); i != c.End(); ++i)
60 {
61 apps.Add(InstallPriv(*i));
62 }
63
64 return apps;
65}
66
69{
70 NS_LOG_FUNCTION(this << node);
71
73
74 Time interval;
75 if (m_period.IsZero())
76 {
77 double intervalProb = m_intervalProb->GetValue();
78 NS_LOG_DEBUG("IntervalProb = " << intervalProb);
79
80 // Based on TR 45.820
81 if (intervalProb < 0.4)
82 {
83 interval = Days(1);
84 }
85 else if (0.4 <= intervalProb && intervalProb < 0.8)
86 {
87 interval = Hours(2);
88 }
89 else if (0.8 <= intervalProb && intervalProb < 0.95)
90 {
91 interval = Hours(1);
92 }
93 else
94 {
95 interval = Minutes(30);
96 }
97 }
98 else
99 {
100 interval = m_period;
101 }
102
103 app->SetInterval(interval);
104 NS_LOG_DEBUG("Created an application with interval = " << interval.As(Time::H));
105
106 app->SetInitialDelay(Seconds(m_initialDelay->GetValue(0, interval.GetSeconds())));
107 app->SetPacketSize(m_pktSize);
108 if (m_pktSizeRV)
109 {
110 app->SetPacketSizeRandomVariable(m_pktSizeRV);
111 }
112
113 app->SetNode(node);
114 node->AddApplication(app);
115
116 return app;
117}
118
119void
121{
122 m_period = period;
123}
124
125void
130
131void
133{
134 m_pktSize = size;
135}
136
137} // namespace lorawan
138} // namespace ns3
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Hold a value for an Attribute.
Definition attribute.h:59
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
@ H
hour, 60 minutes
Definition nstime.h:104
Ptr< RandomVariableStream > m_pktSizeRV
Whether or not a random component is added to the packet size.
uint8_t m_pktSize
The base packet size.
void SetPeriod(Time period)
Set the period to be used by the applications created by this helper.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetPacketSize(uint8_t size)
Set the base value for applications packet size in bytes.
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install a PeriodicSender application on the input Node configured with all the attributes set with Se...
Ptr< UniformRandomVariable > m_intervalProb
The random variable used to pick inter-transmission intervals of different applications from a discre...
void SetPacketSizeRandomVariable(Ptr< RandomVariableStream > rv)
Set a random variable to enable a random size to be added to the base packet size for each new transm...
Time m_period
The base period with which the application will be set to send messages.
ObjectFactory m_factory
The factory to create PeriodicSender applications.
Ptr< UniformRandomVariable > m_initialDelay
The random variable used to extract a start off delay for each PeriodicSender application.
ApplicationContainer Install(NodeContainer c) const
Install a PeriodicSender application on each node of the input container configured with all the attr...
Implements a sender application generating packets following a periodic point process.
#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(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1232
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1244
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1256
Every class exported by the ns3 library is enclosed in the ns3 namespace.