5G-LENA nr-v4.0
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator-3gpp-audio-data.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-3gpp-audio-data.h"
7
8#include "ns3/double.h"
9#include "ns3/log.h"
10#include "ns3/nstime.h"
11#include "ns3/tcp-socket-factory.h"
12#include "ns3/trace-source-accessor.h"
13#include "ns3/uinteger.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("TrafficGenerator3gppAudioData");
19NS_OBJECT_ENSURE_REGISTERED(TrafficGenerator3gppAudioData);
20
21TypeId
23{
24 static TypeId tid =
25 TypeId("ns3::TrafficGenerator3gppAudioData")
26 .SetParent<TrafficGenerator>()
27 .SetGroupName("Applications")
28 .AddConstructor<TrafficGenerator3gppAudioData>()
29 .AddAttribute(
30 "DataRate",
31 "The desired data rate in Mbps. Typical values are 0.756 Mbps and 1.12 Mbps.",
32 DoubleValue(0.756),
33 MakeDoubleAccessor(&TrafficGenerator3gppAudioData::SetDataRate),
34 MakeDoubleChecker<double>())
35 .AddAttribute("Periodicity",
36 "The periodicity in milliseconds.",
37 UintegerValue(4),
38 MakeUintegerAccessor(&TrafficGenerator3gppAudioData::m_periodicity),
39 MakeUintegerChecker<uint32_t>())
40 .AddAttribute("Remote",
41 "The address of the destination",
42 AddressValue(),
43 MakeAddressAccessor(&TrafficGenerator::SetRemote),
44 MakeAddressChecker())
45 .AddAttribute("Protocol",
46 "The type of protocol to use.",
47 TypeIdValue(TcpSocketFactory::GetTypeId()),
48 MakeTypeIdAccessor(&TrafficGenerator::SetProtocol),
49 MakeTypeIdChecker())
50 .AddTraceSource("Tx",
51 "A new packet is created and is sent",
52 MakeTraceSourceAccessor(&TrafficGenerator::m_txTrace),
53 "ns3::TrafficGenerator::TxTracedCallback");
54 return tid;
55}
56
57TrafficGenerator3gppAudioData::TrafficGenerator3gppAudioData()
59{
60 NS_LOG_FUNCTION(this);
61}
62
63TrafficGenerator3gppAudioData::~TrafficGenerator3gppAudioData()
64{
65 NS_LOG_FUNCTION(this);
66}
67
68void
69TrafficGenerator3gppAudioData::DoInitialize()
70{
71 m_packetSize = (m_dataRate * 1e6 * m_periodicity * 1e-3) / 8;
72 NS_ASSERT(m_packetSize);
73 TrafficGenerator::DoInitialize();
74}
75
76void
77TrafficGenerator3gppAudioData::StartApplication()
78{
79 NS_LOG_FUNCTION(this);
81}
82
83void
84TrafficGenerator3gppAudioData::SetDataRate(double dataRate)
85{
86 NS_LOG_FUNCTION(this);
87 m_dataRate = dataRate;
88}
89
90void
91TrafficGenerator3gppAudioData::PacketBurstSent()
92{
93 NS_LOG_FUNCTION(this);
94 // in 3GPP description of the Option 2 (video + audio/data) there is no notion of frames or
95 // packet bursts, just packets
96 NS_ABORT_MSG("This function should not be called for the video + audio/data traffic");
97}
98
99void
100TrafficGenerator3gppAudioData::GenerateNextPacketBurstSize()
101{
102 NS_LOG_FUNCTION(this);
103 SetPacketBurstSizeInPackets(1);
104}
105
106uint32_t
107TrafficGenerator3gppAudioData::GetNextPacketSize() const
108{
109 NS_LOG_FUNCTION(this);
110 return m_packetSize;
111}
112
113Time
114TrafficGenerator3gppAudioData::GetNextPacketTime() const
115{
116 NS_LOG_FUNCTION(this);
117 NS_ASSERT(m_periodicity);
118 NS_LOG_DEBUG("Next packet time in Milliseconds: " << m_periodicity);
119 return MilliSeconds(m_periodicity);
120}
121
122int64_t
124{
125 return 0;
126}
127
128} // 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.