A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
udp-trace-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
7 * <amine.ismail@udcast.com>
8 */
9
10#ifndef UDP_TRACE_CLIENT_H
11#define UDP_TRACE_CLIENT_H
12
13#include "source-application.h"
14
15#include "ns3/event-id.h"
16#include "ns3/ipv4-address.h"
17#include "ns3/ptr.h"
18
19#include <optional>
20#include <vector>
21
22namespace ns3
23{
24
25class Socket;
26class Packet;
27
28/**
29 * @ingroup udpclientserver
30 *
31 * @brief A trace based streamer
32 *
33 * Sends UDP packets based on a trace file of a MPEG4 stream.
34 * Trace files can be downloaded from:
35 * https://web.archive.org/web/20210113211420/http://trace.eas.asu.edu/mpeg4/index.html
36 * (the 2 first lines of the file should be removed) A valid trace file is a file with 4 columns:
37 * \li -1- the first one represents the frame index
38 * \li -2- the second one indicates the type of the frame: I, P or B
39 * \li -3- the third one indicates the time on which the frame was generated by the encoder
40 * (integer, milliseconds) \li -4- the fourth one indicates the frame size in byte
41 *
42 * Additional trace files can be generated from MPEG4 files using the tool
43 * available in https://pypi.org/project/trace-extractor/
44 *
45 * If no valid MPEG4 trace file is provided to the application the trace from
46 * g_defaultEntries array will be loaded.
47 *
48 * Also note that:
49 * \li -1- consecutive 'B' frames are sent together,
50 * \li -2- any trace file is (by default) read again once finished (loop).
51 *
52 * The latter behavior can be changed through the "TraceLoop" attribute.
53 */
55{
56 public:
57 /**
58 * @brief Get the type ID.
59 * @return the object TypeId
60 */
61 static TypeId GetTypeId();
62
64 ~UdpTraceClient() override;
65
66 static constexpr uint16_t DEFAULT_PORT{100}; //!< default port
67
68 /**
69 * @brief set the remote address and port
70 * @param ip remote IP address
71 * @param port remote port
72 */
73 NS_DEPRECATED_3_44("Use SetRemote without port parameter instead")
74 void SetRemote(const Address& ip, uint16_t port);
75 void SetRemote(const Address& addr) override;
76
77 /**
78 * @brief Set the trace file to be used by the application
79 * @param filename a path to an MPEG4 trace file formatted as follows:
80 * Frame No Frametype Time[ms] Length [byte]
81 * Frame No Frametype Time[ms] Length [byte]
82 * ...
83 */
84 void SetTraceFile(const std::string& filename);
85
86 /**
87 * @brief Return the maximum packet size
88 * @return the maximum packet size
89 */
90 uint16_t GetMaxPacketSize();
91
92 /**
93 * @brief Set the maximum packet size
94 * @param maxPacketSize The maximum packet size
95 */
96 void SetMaxPacketSize(uint16_t maxPacketSize);
97
98 /**
99 * @brief Set the trace loop flag
100 * @param traceLoop true if the trace should be re-used
101 */
102 void SetTraceLoop(bool traceLoop);
103
104 private:
105 void StartApplication() override;
106 void StopApplication() override;
107
108 /**
109 * @brief Set the remote port (temporary function until deprecated attributes are removed)
110 * @param port remote port
111 */
112 void SetPort(uint16_t port);
113
114 /**
115 * @brief Get the remote port (temporary function until deprecated attributes are removed)
116 * @return the remote port
117 */
118 uint16_t GetPort() const;
119
120 /**
121 * @brief Get the remote address (temporary function until deprecated attributes are removed)
122 * @return the remote address
123 */
124 Address GetRemote() const;
125
126 /**
127 * @brief Load current trace file
128 */
129 void LoadTrace();
130
131 /**
132 * @brief Load the default trace
133 */
134 void LoadDefaultTrace();
135
136 /**
137 * @brief Send a packet
138 */
139 void Send();
140
141 /**
142 * @brief Send a packet of a given size
143 * @param size the packet size
144 */
145 void SendPacket(uint32_t size);
146
147 /**
148 * @brief Entry to send.
149 *
150 * Each entry represents an MPEG frame
151 */
153 {
154 uint32_t timeToSend; //!< Time to send the frame
155 uint32_t packetSize; //!< Size of the frame
156 char frameType; //!< Frame type (I, P or B)
157 };
158
159 uint32_t m_sent; //!< Counter for sent packets
161 std::optional<uint16_t> m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44
162 EventId m_sendEvent; //!< Event to send the next packet
163
164 std::vector<TraceEntry> m_entries; //!< Entries in the trace to send
165 uint32_t m_currentEntry; //!< Current entry index
166 static TraceEntry g_defaultEntries[]; //!< Default trace to send
167 uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
168 bool m_traceLoop; //!< Loop through the trace file
169 std::string m_traceFile; //!< The location of the trace file
170};
171
172} // namespace ns3
173
174#endif /* UDP_TRACE_CLIENT_H */
a polymophic address class
Definition address.h:90
An identifier for simulation events.
Definition event-id.h:45
Smart pointer class similar to boost::intrusive_ptr.
Base class for source applications.
a unique identifier for an interface.
Definition type-id.h:48
A trace based streamer.
EventId m_sendEvent
Event to send the next packet.
void SetTraceFile(const std::string &filename)
Set the trace file to be used by the application.
void StopApplication() override
Application specific shutdown code.
Address GetRemote() const
Get the remote address (temporary function until deprecated attributes are removed)
static TypeId GetTypeId()
Get the type ID.
void Send()
Send a packet.
std::optional< uint16_t > m_peerPort
Remote peer port (deprecated) // NS_DEPRECATED_3_44.
void SetTraceLoop(bool traceLoop)
Set the trace loop flag.
uint32_t m_sent
Counter for sent packets.
std::vector< TraceEntry > m_entries
Entries in the trace to send.
uint32_t m_currentEntry
Current entry index.
void SetMaxPacketSize(uint16_t maxPacketSize)
Set the maximum packet size.
void LoadTrace()
Load current trace file.
void SetPort(uint16_t port)
Set the remote port (temporary function until deprecated attributes are removed)
void StartApplication() override
Application specific startup code.
static constexpr uint16_t DEFAULT_PORT
default port
void SetRemote(const Address &ip, uint16_t port)
set the remote address and port
void SendPacket(uint32_t size)
Send a packet of a given size.
bool m_traceLoop
Loop through the trace file.
uint16_t m_maxPacketSize
Maximum packet size to send (including the SeqTsHeader)
std::string m_traceFile
The location of the trace file.
static TraceEntry g_defaultEntries[]
Default trace to send.
uint16_t GetPort() const
Get the remote port (temporary function until deprecated attributes are removed)
uint16_t GetMaxPacketSize()
Return the maximum packet size.
void LoadDefaultTrace()
Load the default trace.
Ptr< Socket > m_socket
Socket.
uint16_t port
Definition dsdv-manet.cc:33
#define NS_DEPRECATED_3_44(msg)
Tag for things deprecated in version ns-3.44.
Definition deprecated.h:91
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
#define private
Entry to send.
uint32_t timeToSend
Time to send the frame.
uint32_t packetSize
Size of the frame.
char frameType
Frame type (I, P or B)