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 Packet;
26
27/**
28 * @ingroup udpclientserver
29 *
30 * @brief A trace based streamer
31 *
32 * Sends UDP packets based on a trace file of a MPEG4 stream.
33 * Trace files can be downloaded from:
34 * https://web.archive.org/web/20210113211420/http://trace.eas.asu.edu/mpeg4/index.html
35 * (the 2 first lines of the file should be removed) A valid trace file is a file with 4 columns:
36 * \li -1- the first one represents the frame index
37 * \li -2- the second one indicates the type of the frame: I, P or B
38 * \li -3- the third one indicates the time on which the frame was generated by the encoder
39 * (integer, milliseconds) \li -4- the fourth one indicates the frame size in byte
40 *
41 * Additional trace files can be generated from MPEG4 files using the tool
42 * available in https://pypi.org/project/trace-extractor/
43 *
44 * If no valid MPEG4 trace file is provided to the application the trace from
45 * g_defaultEntries array will be loaded.
46 *
47 * Also note that:
48 * \li -1- consecutive 'B' frames are sent together,
49 * \li -2- any trace file is (by default) read again once finished (loop).
50 *
51 * The latter behavior can be changed through the "TraceLoop" attribute.
52 */
54{
55 public:
56 /**
57 * @brief Get the type ID.
58 * @return the object TypeId
59 */
60 static TypeId GetTypeId();
61
63 ~UdpTraceClient() override;
64
65 static constexpr uint16_t DEFAULT_PORT{100}; //!< default port
66
67 /**
68 * @brief set the remote address and port
69 * @param ip remote IP address
70 * @param port remote port
71 */
72 NS_DEPRECATED_3_44("Use SetRemote without port parameter instead")
73 void SetRemote(const Address& ip, uint16_t port);
74 void SetRemote(const Address& addr) override;
75
76 /**
77 * @brief Set the trace file to be used by the application
78 * @param filename a path to an MPEG4 trace file formatted as follows:
79 * Frame No Frametype Time[ms] Length [byte]
80 * Frame No Frametype Time[ms] Length [byte]
81 * ...
82 */
83 void SetTraceFile(const std::string& filename);
84
85 /**
86 * @brief Return the maximum packet size
87 * @return the maximum packet size
88 */
89 uint16_t GetMaxPacketSize() const;
90
91 /**
92 * @brief Set the maximum packet size
93 * @param maxPacketSize The maximum packet size
94 */
95 void SetMaxPacketSize(uint16_t maxPacketSize);
96
97 /**
98 * @brief Set the trace loop flag
99 * @param traceLoop true if the trace should be re-used
100 */
101 void SetTraceLoop(bool traceLoop);
102
103 private:
104 void DoStartApplication() override;
105 void CancelEvents() override;
106
107 /**
108 * @brief Set the remote port (temporary function until deprecated attributes are removed)
109 * @param port remote port
110 */
111 void SetPort(uint16_t port);
112
113 /**
114 * @brief Get the remote port (temporary function until deprecated attributes are removed)
115 * @return the remote port
116 */
117 uint16_t GetPort() const;
118
119 /**
120 * @brief Get the remote address (temporary function until deprecated attributes are removed)
121 * @return the remote address
122 */
123 Address GetRemote() const;
124
125 /**
126 * @brief Load current trace file
127 */
128 void LoadTrace();
129
130 /**
131 * @brief Load the default trace
132 */
133 void LoadDefaultTrace();
134
135 /**
136 * @brief Send a packet
137 */
138 void Send();
139
140 /**
141 * @brief Send a packet of a given size
142 * @param size the packet size
143 */
144 void SendPacket(uint32_t size);
145
146 /**
147 * @brief Entry to send.
148 *
149 * Each entry represents an MPEG frame
150 */
152 {
153 uint32_t timeToSend; //!< Time to send the frame
154 uint32_t packetSize; //!< Size of the frame
155 char frameType; //!< Frame type (I, P or B)
156 };
157
158 uint32_t m_sent{0}; //!< Counter for sent packets
159 std::optional<uint16_t> m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44
160 EventId m_sendEvent; //!< Event to send the next packet
161
162 std::vector<TraceEntry> m_entries; //!< Entries in the trace to send
163 uint32_t m_currentEntry{0}; //!< Current entry index
164 static TraceEntry g_defaultEntries[]; //!< Default trace to send
165 uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
166 bool m_traceLoop; //!< Loop through the trace file
167 std::string m_traceFile; //!< The location of the trace file
168};
169
170} // namespace ns3
171
172#endif /* UDP_TRACE_CLIENT_H */
a polymophic address class
Definition address.h:111
An identifier for simulation events.
Definition event-id.h:44
network packets
Definition packet.h:228
SourceApplication(bool allowPacketSocket=true)
Constructor.
a unique identifier for an interface.
Definition type-id.h:49
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.
Address GetRemote() const
Get the remote address (temporary function until deprecated attributes are removed).
static TypeId GetTypeId()
Get the type ID.
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.
uint16_t GetMaxPacketSize() const
Return the maximum packet size.
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).
static constexpr uint16_t DEFAULT_PORT
default port
void SetRemote(const Address &ip, uint16_t port)
set the remote address and port
void CancelEvents() override
Cancel all pending events.
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).
void LoadDefaultTrace()
Load the default trace.
void DoStartApplication() override
Application specific startup code for child subclasses.
uint16_t port
Definition dsdv-manet.cc:33
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
#define NS_DEPRECATED_3_44(msg)
Tag for things deprecated in version ns-3.44.
Definition deprecated.h:112
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
#define private
static void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
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).