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/log.h"
13#include "ns3/periodic-sender.h"
14#include "ns3/random-variable-stream.h"
15#include "ns3/simulator.h"
16#include "ns3/string.h"
17#include "ns3/trace-source-accessor.h"
18
19namespace ns3
20{
21namespace lorawan
22{
23
24NS_LOG_COMPONENT_DEFINE("PeriodicSenderHelper");
25
27{
28 m_factory.SetTypeId("ns3::PeriodicSender");
29
30 // m_factory.Set ("PacketSizeRandomVariable", StringValue
31 // ("ns3::ParetoRandomVariable[Bound=10|Shape=2.5]"));
32
34 m_initialDelay->SetAttribute("Min", DoubleValue(0));
35
37 m_intervalProb->SetAttribute("Min", DoubleValue(0));
38 m_intervalProb->SetAttribute("Max", DoubleValue(1));
39
40 m_pktSize = 10;
41 m_pktSizeRV = nullptr;
42}
43
47
48void
50{
51 m_factory.Set(name, value);
52}
53
59
62{
64 for (auto i = c.Begin(); i != c.End(); ++i)
65 {
66 apps.Add(InstallPriv(*i));
67 }
68
69 return apps;
70}
71
74{
75 NS_LOG_FUNCTION(this << node);
76
78
79 Time interval;
80 if (m_period == Seconds(0))
81 {
82 double intervalProb = m_intervalProb->GetValue();
83 NS_LOG_DEBUG("IntervalProb = " << intervalProb);
84
85 // Based on TR 45.820
86 if (intervalProb < 0.4)
87 {
88 interval = Days(1);
89 }
90 else if (0.4 <= intervalProb && intervalProb < 0.8)
91 {
92 interval = Hours(2);
93 }
94 else if (0.8 <= intervalProb && intervalProb < 0.95)
95 {
96 interval = Hours(1);
97 }
98 else
99 {
100 interval = Minutes(30);
101 }
102 }
103 else
104 {
105 interval = m_period;
106 }
107
108 app->SetInterval(interval);
109 NS_LOG_DEBUG("Created an application with interval = " << interval.GetHours() << " hours");
110
111 app->SetInitialDelay(Seconds(m_initialDelay->GetValue(0, interval.GetSeconds())));
112 app->SetPacketSize(m_pktSize);
113 if (m_pktSizeRV)
114 {
115 app->SetPacketSizeRandomVariable(m_pktSizeRV);
116 }
117
118 app->SetNode(node);
119 node->AddApplication(app);
120
121 return app;
122}
123
124void
126{
127 m_period = period;
128}
129
130void
135
136void
138{
139 m_pktSize = size;
140}
141
142} // namespace lorawan
143} // 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.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
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: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(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:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1272
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1284
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1296
Every class exported by the ns3 library is enclosed in the ns3 namespace.