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 "ns3/application.h"
14#include "ns3/event-id.h"
15#include "ns3/ipv4-address.h"
16#include "ns3/ptr.h"
17
18#include <vector>
19
20namespace ns3
21{
22
23class Socket;
24class Packet;
25
26/**
27 * \ingroup udpclientserver
28 *
29 * \brief A trace based streamer
30 *
31 * Sends UDP packets based on a trace file of a MPEG4 stream.
32 * Trace files can be downloaded from:
33 * https://web.archive.org/web/20210113211420/http://trace.eas.asu.edu/mpeg4/index.html
34 * (the 2 first lines of the file should be removed) A valid trace file is a file with 4 columns:
35 * \li -1- the first one represents the frame index
36 * \li -2- the second one indicates the type of the frame: I, P or B
37 * \li -3- the third one indicates the time on which the frame was generated by the encoder
38 * (integer, milliseconds) \li -4- the fourth one indicates the frame size in byte
39 *
40 * Additional trace files can be generated from MPEG4 files using the tool
41 * available in https://pypi.org/project/trace-extractor/
42 *
43 * If no valid MPEG4 trace file is provided to the application the trace from
44 * g_defaultEntries array will be loaded.
45 *
46 * Also note that:
47 * \li -1- consecutive 'B' frames are sent together,
48 * \li -2- any trace file is (by default) read again once finished (loop).
49 *
50 * The latter behavior can be changed through the "TraceLoop" attribute.
51 */
53{
54 public:
55 /**
56 * \brief Get the type ID.
57 * \return the object TypeId
58 */
59 static TypeId GetTypeId();
60
62
63 /**
64 * \brief Creates a traceBasedStreamer application
65 * \param ip the destination ip address to which the stream will be sent
66 * \param port the destination udp port to which the stream will be sent
67 * \param traceFile a path to an MPEG4 trace file formatted as follows:
68 * FrameNo Frametype Time[ms] Length [byte]
69 * FrameNo Frametype Time[ms] Length [byte]
70 * ...
71 *
72 *
73 */
74 UdpTraceClient(Ipv4Address ip, uint16_t port, char* traceFile);
75 ~UdpTraceClient() override;
76
77 /**
78 * \brief set the remote address and port
79 * \param ip remote IP address
80 * \param port remote port
81 */
82 void SetRemote(Address ip, uint16_t port);
83 /**
84 * \brief set the remote address
85 * \param addr remote address
86 */
87 void SetRemote(Address addr);
88
89 /**
90 * \brief Set the trace file to be used by the application
91 * \param filename a path to an MPEG4 trace file formatted as follows:
92 * Frame No Frametype Time[ms] Length [byte]
93 * Frame No Frametype Time[ms] Length [byte]
94 * ...
95 */
96 void SetTraceFile(std::string filename);
97
98 /**
99 * \brief Return the maximum packet size
100 * \return the maximum packet size
101 */
102 uint16_t GetMaxPacketSize();
103
104 /**
105 * \brief Set the maximum packet size
106 * \param maxPacketSize The maximum packet size
107 */
108 void SetMaxPacketSize(uint16_t maxPacketSize);
109
110 /**
111 * \brief Set the trace loop flag
112 * \param traceLoop true if the trace should be re-used
113 */
114 void SetTraceLoop(bool traceLoop);
115
116 private:
117 void StartApplication() override;
118 void StopApplication() override;
119
120 /**
121 * \brief Load a trace file
122 * \param filename the trace file path
123 */
124 void LoadTrace(std::string filename);
125 /**
126 * \brief Load the default trace
127 */
128 void LoadDefaultTrace();
129
130 /**
131 * \brief Send a packet
132 */
133 void Send();
134 /**
135 * \brief Send a packet of a given size
136 * \param size the packet size
137 */
138 void SendPacket(uint32_t size);
139
140 /**
141 * \brief Entry to send.
142 *
143 * Each entry represents an MPEG frame
144 */
146 {
147 uint32_t timeToSend; //!< Time to send the frame
148 uint32_t packetSize; //!< Size of the frame
149 char frameType; //!< Frame type (I, P or B)
150 };
151
152 uint32_t m_sent; //!< Counter for sent packets
154 Address m_peerAddress; //!< Remote peer address
155 uint16_t m_peerPort; //!< Remote peer port
156 uint8_t m_tos; //!< The packets Type of Service
157 EventId m_sendEvent; //!< Event to send the next packet
158
159 std::vector<TraceEntry> m_entries; //!< Entries in the trace to send
160 uint32_t m_currentEntry; //!< Current entry index
161 static TraceEntry g_defaultEntries[]; //!< Default trace to send
162 uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
163 bool m_traceLoop; //!< Loop through the trace file
164};
165
166} // namespace ns3
167
168#endif /* UDP_TRACE_CLIENT_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
An identifier for simulation events.
Definition event-id.h:45
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
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 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:33
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)