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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18 * <amine.ismail@udcast.com>
19 */
20
21#ifndef UDP_TRACE_CLIENT_H
22#define UDP_TRACE_CLIENT_H
23
24#include "ns3/application.h"
25#include "ns3/event-id.h"
26#include "ns3/ipv4-address.h"
27#include "ns3/ptr.h"
28
29#include <vector>
30
31namespace ns3
32{
33
34class Socket;
35class Packet;
36
37/**
38 * \ingroup udpclientserver
39 *
40 * \brief A trace based streamer
41 *
42 * Sends UDP packets based on a trace file of a MPEG4 stream.
43 * Trace files can be downloaded from:
44 * https://web.archive.org/web/20210113211420/http://trace.eas.asu.edu/mpeg4/index.html
45 * (the 2 first lines of the file should be removed) A valid trace file is a file with 4 columns:
46 * \li -1- the first one represents the frame index
47 * \li -2- the second one indicates the type of the frame: I, P or B
48 * \li -3- the third one indicates the time on which the frame was generated by the encoder
49 * (integer, milliseconds) \li -4- the fourth one indicates the frame size in byte
50 *
51 * Additional trace files can be generated from MPEG4 files using the tool
52 * available in https://pypi.org/project/trace-extractor/
53 *
54 * If no valid MPEG4 trace file is provided to the application the trace from
55 * g_defaultEntries array will be loaded.
56 *
57 * Also note that:
58 * \li -1- consecutive 'B' frames are sent together,
59 * \li -2- any trace file is (by default) read again once finished (loop).
60 *
61 * The latter behavior can be changed through the "TraceLoop" attribute.
62 */
64{
65 public:
66 /**
67 * \brief Get the type ID.
68 * \return the object TypeId
69 */
70 static TypeId GetTypeId();
71
73
74 /**
75 * \brief Creates a traceBasedStreamer application
76 * \param ip the destination ip address to which the stream will be sent
77 * \param port the destination udp port to which the stream will be sent
78 * \param traceFile a path to an MPEG4 trace file formatted as follows:
79 * FrameNo Frametype Time[ms] Length [byte]
80 * FrameNo Frametype Time[ms] Length [byte]
81 * ...
82 *
83 *
84 */
85 UdpTraceClient(Ipv4Address ip, uint16_t port, char* traceFile);
86 ~UdpTraceClient() override;
87
88 /**
89 * \brief set the remote address and port
90 * \param ip remote IP address
91 * \param port remote port
92 */
93 void SetRemote(Address ip, uint16_t port);
94 /**
95 * \brief set the remote address
96 * \param addr remote address
97 */
98 void SetRemote(Address addr);
99
100 /**
101 * \brief Set the trace file to be used by the application
102 * \param filename a path to an MPEG4 trace file formatted as follows:
103 * Frame No Frametype Time[ms] Length [byte]
104 * Frame No Frametype Time[ms] Length [byte]
105 * ...
106 */
107 void SetTraceFile(std::string filename);
108
109 /**
110 * \brief Return the maximum packet size
111 * \return the maximum packet size
112 */
113 uint16_t GetMaxPacketSize();
114
115 /**
116 * \brief Set the maximum packet size
117 * \param maxPacketSize The maximum packet size
118 */
119 void SetMaxPacketSize(uint16_t maxPacketSize);
120
121 /**
122 * \brief Set the trace loop flag
123 * \param traceLoop true if the trace should be re-used
124 */
125 void SetTraceLoop(bool traceLoop);
126
127 private:
128 void StartApplication() override;
129 void StopApplication() override;
130
131 /**
132 * \brief Load a trace file
133 * \param filename the trace file path
134 */
135 void LoadTrace(std::string filename);
136 /**
137 * \brief Load the default trace
138 */
139 void LoadDefaultTrace();
140
141 /**
142 * \brief Send a packet
143 */
144 void Send();
145 /**
146 * \brief Send a packet of a given size
147 * \param size the packet size
148 */
149 void SendPacket(uint32_t size);
150
151 /**
152 * \brief Entry to send.
153 *
154 * Each entry represents an MPEG frame
155 */
157 {
158 uint32_t timeToSend; //!< Time to send the frame
159 uint32_t packetSize; //!< Size of the frame
160 char frameType; //!< Frame type (I, P or B)
161 };
162
163 uint32_t m_sent; //!< Counter for sent packets
165 Address m_peerAddress; //!< Remote peer address
166 uint16_t m_peerPort; //!< Remote peer port
167 uint8_t m_tos; //!< The packets Type of Service
168 EventId m_sendEvent; //!< Event to send the next packet
169
170 std::vector<TraceEntry> m_entries; //!< Entries in the trace to send
171 uint32_t m_currentEntry; //!< Current entry index
172 static TraceEntry g_defaultEntries[]; //!< Default trace to send
173 uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
174 bool m_traceLoop; //!< Loop through the trace file
175};
176
177} // namespace ns3
178
179#endif /* UDP_TRACE_CLIENT_H */
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
A trace based streamer.
EventId m_sendEvent
Event to send the next packet.
void StopApplication() override
Application specific shutdown code.
uint8_t m_tos
The packets Type of Service.
static TypeId GetTypeId()
Get the type ID.
void Send()
Send a packet.
uint16_t m_peerPort
Remote peer port.
void SetTraceLoop(bool traceLoop)
Set the trace loop flag.
uint32_t m_sent
Counter for sent packets.
void SetRemote(Address ip, uint16_t port)
set the remote address and port
Address m_peerAddress
Remote peer address.
std::vector< TraceEntry > m_entries
Entries in the trace to send.
uint32_t m_currentEntry
Current entry index.
void SetTraceFile(std::string filename)
Set the trace file to be used by the application.
void LoadTrace(std::string filename)
Load a trace file.
void SetMaxPacketSize(uint16_t maxPacketSize)
Set the maximum packet size.
void StartApplication() override
Application specific startup code.
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)
static TraceEntry g_defaultEntries[]
Default trace to send.
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:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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)