5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator-ngmn-ftp-multi.cc
1// Copyright (c) 2022 CTTC
2// Copyright (c) 2023 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3//
4// SPDX-License-Identifier: GPL-2.0-only
5
6#include "traffic-generator-ngmn-ftp-multi.h"
7
8#include "ns3/address.h"
9#include "ns3/double.h"
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/nstime.h"
13#include "ns3/packet.h"
14#include "ns3/simulator.h"
15#include "ns3/socket-factory.h"
16#include "ns3/socket.h"
17#include "ns3/tcp-socket-factory.h"
18#include "ns3/trace-source-accessor.h"
19#include "ns3/udp-socket-factory.h"
20#include "ns3/uinteger.h"
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("TrafficGeneratorNgmnFtpMulti");
26NS_OBJECT_ENSURE_REGISTERED(TrafficGeneratorNgmnFtpMulti);
27
28TypeId
30{
31 static TypeId tid =
32 TypeId("ns3::TrafficGeneratorNgmnFtpMulti")
33 .SetParent<TrafficGenerator>()
34 .SetGroupName("Applications")
35 .AddConstructor<TrafficGeneratorNgmnFtpMulti>()
36 .AddAttribute("MaxFileSize",
37 "Max file size in number of bytes",
38 UintegerValue(5e6),
39 MakeUintegerAccessor(&TrafficGeneratorNgmnFtpMulti::m_maxFileSize),
40 MakeUintegerChecker<uint32_t>(1))
41 .AddAttribute("PacketSize",
42 "The number of bytes to write per socket send",
43 UintegerValue(512),
45 MakeUintegerChecker<uint32_t>(1))
46 .AddAttribute("ReadingTimeMean",
47 "The mean reading time in seconds",
48 DoubleValue(180),
49 MakeDoubleAccessor(&TrafficGeneratorNgmnFtpMulti::m_readingTimeMean),
50 MakeDoubleChecker<double>())
51 .AddAttribute("FileSizeMu",
52 "Mu parameter of lognormal distribution "
53 "for the file size generation",
54 DoubleValue(14.45),
55 MakeDoubleAccessor(&TrafficGeneratorNgmnFtpMulti::m_fileSizeMu),
56 MakeDoubleChecker<double>())
57 .AddAttribute("FileSizeSigma",
58 "Sigma parameter of lognormal distribution "
59 "for the file size generation",
60 DoubleValue(0.35),
61 MakeDoubleAccessor(&TrafficGeneratorNgmnFtpMulti::m_fileSizeSigma),
62 MakeDoubleChecker<double>())
63 .AddAttribute("Remote",
64 "The address of the destination",
65 AddressValue(),
66 MakeAddressAccessor(&TrafficGenerator::SetRemote),
67 MakeAddressChecker())
68 .AddAttribute("Protocol",
69 "The type of protocol to use.",
70 TypeIdValue(TcpSocketFactory::GetTypeId()),
71 MakeTypeIdAccessor(&TrafficGenerator::SetProtocol),
72 MakeTypeIdChecker())
73 .AddTraceSource("Tx",
74 "A new packet is created and is sent",
75 MakeTraceSourceAccessor(&TrafficGenerator::m_txTrace),
76 "ns3::TrafficGenerator::TxTracedCallback");
77 return tid;
78}
79
80TrafficGeneratorNgmnFtpMulti::TrafficGeneratorNgmnFtpMulti()
82{
83 NS_LOG_FUNCTION(this);
84}
85
86TrafficGeneratorNgmnFtpMulti::~TrafficGeneratorNgmnFtpMulti()
87{
88 NS_LOG_FUNCTION(this);
89}
90
91void
92TrafficGeneratorNgmnFtpMulti::StartApplication()
93{
94 NS_LOG_FUNCTION(this);
96}
97
98void
99TrafficGeneratorNgmnFtpMulti::PacketBurstSent()
100{
101 NS_LOG_FUNCTION(this);
102 Time readingTime = GetNextReadingTime();
103 NS_LOG_DEBUG("Next file transfer:" << readingTime);
104 Simulator::Schedule(readingTime, &TrafficGenerator::SendPacketBurst, this);
105}
106
107void
109{
110 m_packetSize = sendSize;
111}
112
113Time
114TrafficGeneratorNgmnFtpMulti::GetNextReadingTime()
115{
116 NS_LOG_FUNCTION(this);
117 return Seconds(m_readingTime->GetValue());
118}
119
120void
121TrafficGeneratorNgmnFtpMulti::GenerateNextPacketBurstSize()
122{
123 NS_LOG_FUNCTION(this);
124 uint32_t fileSize = 0;
125 while (true)
126 {
127 fileSize = m_fileSize->GetValue();
128 if (fileSize <= m_maxFileSize)
129 {
130 break;
131 }
132 else
133 {
134 NS_LOG_DEBUG("Generated file size value is higher than the maximum "
135 "allowed value. Max value: "
136 << m_maxFileSize << ", generated value:" << fileSize);
137 }
138 }
139
140 NS_LOG_DEBUG("New file size:" << fileSize);
141 SetPacketBurstSizeInBytes(fileSize);
142}
143
144uint32_t
145TrafficGeneratorNgmnFtpMulti::GetNextPacketSize() const
146{
147 NS_LOG_FUNCTION(this);
148 return m_packetSize;
149}
150
151void
152TrafficGeneratorNgmnFtpMulti::DoDispose()
153{
154 NS_LOG_FUNCTION(this);
155 m_readingTime = nullptr;
156 m_fileSize = nullptr;
157 // chain up
158 TrafficGenerator::DoDispose();
159}
160
161void
162TrafficGeneratorNgmnFtpMulti::DoInitialize()
163{
164 NS_LOG_FUNCTION(this);
165 // configure random number generators parameters
166 m_readingTime = CreateObject<ExponentialRandomVariable>();
167 m_readingTime->SetAttribute("Mean", DoubleValue(m_readingTimeMean));
168 m_fileSize = CreateObject<LogNormalRandomVariable>();
169 m_fileSize->SetAttribute("Mu", DoubleValue(m_fileSizeMu));
170 m_fileSize->SetAttribute("Sigma", DoubleValue(m_fileSizeSigma)); // chain up
171 TrafficGenerator::DoInitialize();
172}
173
174int64_t
176{
177 m_readingTime->SetStream(stream);
178 m_fileSize->SetStream(stream + 1);
179 return 2;
180}
181
182} // Namespace ns3
void SetRemote(Address remote)
Sets the remote address.
bool SendPacketBurst()
Send another packet burst, which can be e.g., a file, or a video frame.
void SetProtocol(TypeId protocol)
Sets the protocol.
void SetPacketSize(uint32_t packetSize)
Sets the packet size.