5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator.h
1// Copyright (c) 2010 Georgia Institute of Technology
2// Copyright (c) 2022 CTTC
3// Copyright (c) 2023 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#ifndef TRAFFIC_GENERATOR_H
8#define TRAFFIC_GENERATOR_H
9
10#include "ns3/address.h"
11#include "ns3/application.h"
12#include "ns3/event-id.h"
13#include "ns3/ptr.h"
14#include "ns3/traced-callback.h"
15
16namespace ns3
17{
18
19class Address;
20class Socket;
21
38class TrafficGenerator : public Application
39{
40 public:
45 static TypeId GetTypeId();
46
48
49 ~TrafficGenerator() override;
50
57 uint64_t GetTotalBytes() const;
58
65 uint64_t GetTotalPackets() const;
66
73 bool SendPacketBurst();
74
79 Ptr<Socket> GetSocket() const;
80
84 void SetPacketSize(uint32_t packetSize);
88 void SetRemote(Address remote);
92 void SetProtocol(TypeId protocol);
93
95 typedef TracedCallback<Ptr<const Packet>> TxTracedCallback;
96 TxTracedCallback m_txTrace;
97
106 int64_t AssignStreams(int64_t stream) override;
107
108 protected:
109 void DoDispose() override;
110 void DoInitialize() override;
111 /*
112 * @brief Used by child classes to configure the burst size in the number
113 * of bytes when GenerateNextPucketBurstSize is called
114 */
115 void SetPacketBurstSizeInBytes(uint32_t burstSize);
116 /*
117 * @brief Used by child classes to configure the burst size in the number
118 * of packets when GenerateNextPucketBurstSize is called
119 */
120 void SetPacketBurstSizeInPackets(uint32_t burstSize);
121 /*
122 * @brief Returns the latest generated packet burst size in the number
123 * of bytes
124 */
125 uint32_t GetPacketBurstSizeInBytes() const;
126 /*
127 * @brief Returns the latest generated packet burst size in the number
128 * of bytes
129 */
130 uint32_t GetPacketBurstSizeInPackets() const;
131 /*
132 * @brief Called at the time specified by the Stop.
133 * Notice that we want to allow that child classes can call stop of this class,
134 * which is why we change its default access level from private to protected.
135 */
136 void StopApplication() override; // Called at time specified by Stop
137 /*
138 * @return Traffic generator ID
139 */
140 uint16_t GetTgId() const;
141
142 /*
143 * @brief Returns peer address
144 * @return the peer address
145 */
146 Address GetPeer() const;
147
148 private:
149 // inherited from Application base class.
150 void StartApplication() override; // Called at time specified by Start
156 void SendNextPacket();
161 void ConnectionSucceeded(Ptr<Socket> socket);
166 void ConnectionFailed(Ptr<Socket> socket);
171 void CloseSucceeded(Ptr<Socket> socket);
176 void CloseFailed(Ptr<Socket> socket);
180 void SendNextPacketIfConnected(Ptr<Socket>, uint32_t);
185 virtual void PacketBurstSent();
189 virtual void GenerateNextPacketBurstSize();
194 virtual uint32_t GetNextPacketSize() const = 0;
200 virtual Time GetNextPacketTime() const;
201
202 Ptr<Socket> m_socket;
203 Address m_peer;
204 bool m_connected{false};
205 uint32_t m_currentBurstTotBytes{0};
206 TypeId m_tid;
207 uint32_t m_currentBurstTotPackets{0};
208 uint64_t m_totBytes{0};
209 uint64_t m_totPackets{0};
210 bool m_stopped{false};
211 uint32_t m_packetBurstSizeInBytes{0};
212 uint32_t m_packetBurstSizeInPackets{0};
213 EventId m_eventIdSendNextPacket;
215 bool m_waitForNextPacketBurst{
216 false};
218
219 static uint16_t m_tgIdCounter;
220 uint16_t m_tgId{0};
221 uint16_t m_packetId{
222 0};
223};
224
225} // namespace ns3
226
227#endif /* TRAFFIC_GENERATOR_H */
uint64_t GetTotalPackets() const
Get the total number of packets that have been sent during this object's lifetime.
void SetRemote(Address remote)
Sets the remote address.
static TypeId GetTypeId()
Get the type ID.
bool SendPacketBurst()
Send another packet burst, which can be e.g., a file, or a video frame.
int64_t AssignStreams(int64_t stream) override
TracedCallback< Ptr< const Packet > > TxTracedCallback
Traced Callback: sent packets.
void SetPacketSize(uint32_t packetSize)
Sets the packet size.
void SetProtocol(TypeId protocol)
Sets the protocol.
uint64_t GetTotalBytes() const
Get the total number of bytes that have been sent during this object's lifetime.
Ptr< Socket > GetSocket() const
Get the socket this application is attached to.