5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator-ngmn-video.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-video.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("TrafficGeneratorNgmnVideo");
26NS_OBJECT_ENSURE_REGISTERED(TrafficGeneratorNgmnVideo);
27
28uint32_t TrafficGeneratorNgmnVideo::m_flowIdCounter = 0;
29
30TypeId
32{
33 static TypeId tid =
34 TypeId("ns3::TrafficGeneratorNgmnVideo")
35 .SetParent<TrafficGenerator>()
36 .SetGroupName("Applications")
37 .AddConstructor<TrafficGeneratorNgmnVideo>()
38 .AddAttribute(
39 "NumberOfPacketsInFrame",
40 "Number of packets in frame",
41 UintegerValue(20),
42 MakeUintegerAccessor(&TrafficGeneratorNgmnVideo::m_numberOfPacketsInFrame),
43 MakeUintegerChecker<uint32_t>(8))
44 .AddAttribute("InterframeIntervalTime",
45 "Interframe interval time ",
46 TimeValue(MilliSeconds(100)),
47 MakeTimeAccessor(&TrafficGeneratorNgmnVideo::m_interframeIntervalTime),
48 MakeTimeChecker())
49 .AddAttribute("PacketSizeScale",
50 "The scale parameter for the Pareto distribution "
51 "for the packet size generation",
52 DoubleValue(40),
53 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetSizeScale),
54 MakeDoubleChecker<double>())
55 .AddAttribute("PacketSizeShape",
56 "The shape parameter for the Pareto distribution "
57 "for the packet size generation",
58 DoubleValue(1.2),
59 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetSizeShape),
60 MakeDoubleChecker<double>())
61 .AddAttribute("PacketSizeBound",
62 "The bound parameter for the Pareto distribution "
63 "for the packet size generation",
64 DoubleValue(250),
65 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetSizeBound),
66 MakeDoubleChecker<double>())
67 .AddAttribute("PacketTimeScale",
68 "The scale parameter for the Pareto distribution "
69 "for the packet time generation",
70 DoubleValue(2.5),
71 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetTimeScale),
72 MakeDoubleChecker<double>())
73 .AddAttribute("PacketTimeShape",
74 "The shape parameter for the Pareto distribution "
75 "for the packet timee generation",
76 DoubleValue(1.2),
77 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetTimeShape),
78 MakeDoubleChecker<double>())
79 .AddAttribute("PacketTimeBound",
80 "The bound parameter for the Pareto distribution "
81 "for the packet time generation",
82 DoubleValue(12.5),
83 MakeDoubleAccessor(&TrafficGeneratorNgmnVideo::m_packetTimeBound),
84 MakeDoubleChecker<double>())
85 .AddAttribute("Remote",
86 "The address of the destination",
87 AddressValue(),
88 MakeAddressAccessor(&TrafficGenerator::SetRemote),
89 MakeAddressChecker())
90 .AddAttribute("Protocol",
91 "The type of protocol to use.",
92 TypeIdValue(TcpSocketFactory::GetTypeId()),
93 MakeTypeIdAccessor(&TrafficGenerator::SetProtocol),
94 MakeTypeIdChecker())
95 .AddTraceSource("Tx",
96 "A new packet is created and is sent",
97 MakeTraceSourceAccessor(&TrafficGenerator::m_txTrace),
98 "ns3::TrafficGenerator::TxTracedCallback");
99 return tid;
100}
101
102TrafficGeneratorNgmnVideo::TrafficGeneratorNgmnVideo()
104{
105 NS_LOG_FUNCTION(this);
106 m_flowId = m_flowIdCounter++;
107}
108
109TrafficGeneratorNgmnVideo::~TrafficGeneratorNgmnVideo()
110{
111 NS_LOG_FUNCTION(this);
112}
113
114void
115TrafficGeneratorNgmnVideo::StartApplication()
116{
117 NS_LOG_FUNCTION(this);
119}
120
121uint32_t
122TrafficGeneratorNgmnVideo::GetNextPacketSize() const
123{
124 NS_LOG_FUNCTION(this);
125 // We implement a bounded pareto (not truncated Pareto), to get the expected mean.
126 // This way, if RV x (generated according to Pareto type I distribution) is lower
127 // than the maximum value, x=max.
128 // Also, in NGMN doc there is a typo in the scale value for video packet size,
129 // which is 40B according to wifi doc IEEE 802.16m-08/004r2.
130 uint32_t packetSize = floor(std::min(m_packetSizeGenerator->GetValue(), m_packetSizeBound));
131 NS_LOG_DEBUG(" Next packet size :" << packetSize);
132 return packetSize;
133}
134
135Time
136TrafficGeneratorNgmnVideo::GetNextPacketTime() const
137{
138 NS_LOG_FUNCTION(this);
139 // We implement a bounded pareto (not truncated Pareto), to get the expected mean.
140 // This way, if RV x (generated according to Pareto type I distribution) is lower than the
141 // maximum value, x=max.
142 Time packetTime =
143 Seconds(std::min(m_packetTimeGenerator->GetValue(), m_packetTimeBound) * 0.001);
144 NS_LOG_DEBUG("Next packet time :" << packetTime.As(Time::MS));
145 return packetTime;
146}
147
148void
149TrafficGeneratorNgmnVideo::PacketBurstSent()
150{
151 NS_LOG_FUNCTION(this);
152 m_packetFrameCounter++;
153 NS_LOG_INFO("Next frame to send: " << m_packetFrameCounter);
154 // inter-frame interval time
155 Simulator::Schedule(m_interframeIntervalTime, &TrafficGenerator::SendPacketBurst, this);
156}
157
158void
159TrafficGeneratorNgmnVideo::GenerateNextPacketBurstSize()
160{
161 NS_LOG_FUNCTION(this);
162 SetPacketBurstSizeInPackets(m_numberOfPacketsInFrame);
163}
164
165void
166TrafficGeneratorNgmnVideo::DoDispose()
167{
168 NS_LOG_FUNCTION(this);
169 m_packetSizeGenerator = nullptr;
170 m_packetTimeGenerator = nullptr;
171 // chain up
172 TrafficGenerator::DoDispose();
173}
174
175void
176TrafficGeneratorNgmnVideo::DoInitialize()
177{
178 NS_LOG_FUNCTION(this);
179 m_packetSizeGenerator = CreateObject<ParetoRandomVariable>();
180 m_packetSizeGenerator->SetAttribute("Scale", DoubleValue(m_packetSizeScale));
181 m_packetSizeGenerator->SetAttribute("Shape", DoubleValue(m_packetSizeShape));
182 m_packetTimeGenerator = CreateObject<ParetoRandomVariable>();
183 m_packetTimeGenerator->SetAttribute("Scale", DoubleValue(m_packetTimeScale));
184 m_packetTimeGenerator->SetAttribute("Shape", DoubleValue(m_packetTimeShape));
185 // chain up
186 TrafficGenerator::DoInitialize();
187}
188
189int64_t
191{
192 m_packetSizeGenerator->SetStream(stream);
193 m_packetTimeGenerator->SetStream(stream + 1);
194
195 return 2;
196}
197
198} // 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.
static TypeId GetTypeId()
Get the type ID.
int64_t AssignStreams(int64_t stream) override