A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
pyviz.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INESC Porto
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 * C++ helper functions for use by the python visualizer (for things
18 * Python is too slow at).
19 *
20 * Author: Gustavo Carneiro <gjc@inescporto.pt>
21 */
22#ifndef NS3_PYVIZ_H
23#define NS3_PYVIZ_H
24
25#include "ns3/channel.h"
26#include "ns3/event-id.h"
27#include "ns3/ipv4-header.h"
28#include "ns3/ipv4-l3-protocol.h"
29#include "ns3/mac48-address.h"
30#include "ns3/node.h"
31#include "ns3/nstime.h"
32#include "ns3/packet.h"
33
34#include <map>
35#include <set>
36
37namespace ns3
38{
39
40/**
41 * \ingroup visualizer
42 *
43 * \brief helper class to be used by the visualizer
44 * \internal
45 *
46 * This class is not meant to be used by simulations. It is only
47 * meant to be used by the visualizer tool (PyViz). The only reason
48 * it is public is because Python bindings for it are needed,
49 * otherwise it should be considered private.
50 **/
51class PyViz
52{
53 public:
54 PyViz();
55 ~PyViz();
56
57 /**
58 * Register drop trace path function
59 * \param tracePath the path to trace
60 */
61 void RegisterDropTracePath(const std::string& tracePath);
62
63 /**
64 * Register CSMA like device function
65 * \param deviceTypeName the device type name
66 */
67 void RegisterCsmaLikeDevice(const std::string& deviceTypeName);
68 /**
69 * Register WIFI like device function
70 * \param deviceTypeName the device type name
71 */
72 void RegisterWifiLikeDevice(const std::string& deviceTypeName);
73 /**
74 * Register point to point like device function
75 * \param deviceTypeName the device type name
76 */
77 void RegisterPointToPointLikeDevice(const std::string& deviceTypeName);
78
79 /**
80 * Run simulation until a given (simulated, absolute) time is reached
81 * \param time the run time
82 */
83 void SimulatorRunUntil(Time time);
84
85 /**
86 * Pause function
87 * \param message the pause message
88 */
89 static void Pause(const std::string& message);
90 /**
91 * Get pause message function
92 * \returns the pause message
93 */
94 std::vector<std::string> GetPauseMessages() const;
95
96 /// TransmissionSample structure
98 {
99 Ptr<Node> transmitter; ///< transmitter
100 Ptr<Node> receiver; ///< NULL if broadcast
101 Ptr<Channel> channel; ///< channel
102 uint32_t bytes; ///< bytes
103 };
104
105 typedef std::vector<TransmissionSample>
106 TransmissionSampleList; ///< TransmissionSampleList typedef
107 /**
108 * Get transmission samples
109 * \returns the transmission sample list
110 */
112
113 /// PacketDropSample structure
115 {
116 Ptr<Node> transmitter; ///< transmitter
117 uint32_t bytes; ///< bytes
118 };
119
120 typedef std::vector<PacketDropSample> PacketDropSampleList; ///< PacketDropSampleList typedef
121 /**
122 * Get packet drop samples
123 * \returns the packet drop sample list
124 */
126
127 /// PacketSample structure
129 {
130 Time time; ///< time
131 Ptr<Packet> packet; ///< packet
133 };
134
135 /// TxPacketSample structure
137 {
139 };
140
141 /// RxPacketSample structure
143 {
145 };
146
147 /// LastPacketsSample structure
149 {
150 std::vector<RxPacketSample> lastReceivedPackets; ///< last received packets
151 std::vector<TxPacketSample> lastTransmittedPackets; ///< last transmitted packets
152 std::vector<PacketSample> lastDroppedPackets; ///< last dropped packets
153 };
154
155 /**
156 * Get last packets function
157 * \param nodeId the node ID
158 * \returns the last packets
159 */
161
162 /**
163 * Set nodes of interest function
164 * \param nodes the collection of nodes
165 */
166 void SetNodesOfInterest(std::set<uint32_t> nodes);
167
168 /// NetDeviceStatistics structure
170 {
171 /// constructor
173 : transmittedBytes(0),
174 receivedBytes(0),
177 {
178 }
179
180 uint64_t transmittedBytes; ///< transmitted bytes
181 uint64_t receivedBytes; ///< received bytes
182 uint32_t transmittedPackets; ///< transmitted packets
183 uint32_t receivedPackets; ///< received packets
184 };
185
186 /// NodeStatistics structure
188 {
189 uint32_t nodeId; ///< node ID
190 std::vector<NetDeviceStatistics> statistics; ///< statistics
191 };
192
193 /**
194 * Get node statistics
195 * \returns the node statistics
196 */
197 std::vector<NodeStatistics> GetNodesStatistics() const;
198
199 /// PacketCaptureMode enumeration
201 {
202 PACKET_CAPTURE_DISABLED = 1, // packet capture is disabled
203 PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is
204 // present
205 PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are
206 // present
207 };
208
209 /// PacketCaptureOptions structure
211 {
212 std::set<TypeId> headers; ///< headers
213 uint32_t numLastPackets; ///< num last packets
215 };
216
217 /**
218 * Set packet capture options function
219 * \param nodeId the node ID
220 * \param options the capture options
221 */
223
224 // Yes, I know, this is just a utility function, not really related to the class in any way.
225 /**
226 * Utility function - clips a line to a bounding box.
227 * \param [in] boundsX1 Bounding box, minimum X coord
228 * \param [in] boundsY1 Bounding box, minimum Y coord
229 * \param [in] boundsX2 Bounding box, maximum X coord
230 * \param [in] boundsY2 Bounding box, maximum Y coord
231 * \param [in,out] lineX1 Line, minimum X coord (any on input, clipped to the bounding box
232 * on output)
233 * \param [in,out] lineY1 Line, minimum Y coord (any on input, clipped to the bounding box
234 * on output)
235 * \param [in,out] lineX2 Line, maximum X coord (any on input, clipped to the bounding box
236 * on output)
237 * \param [in,out] lineY2 Line, maximum Y coord (any on input, clipped to the bounding box
238 * on output)
239 */
240 // -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout);
241 // @lineY2(direction=inout) -#-
242 static void LineClipping(double boundsX1,
243 double boundsY1,
244 double boundsX2,
245 double boundsY2,
246 double& lineX1,
247 double& lineY1,
248 double& lineX2,
249 double& lineY2);
250 // Don't break the above line or pybindgen will not be able to pick up the above annotation :(
251
252 private:
253 /**
254 * Get packet capture options function
255 * \param nodeId the node ID
256 * \param outOptions the packet capture options
257 * \returns true if successful
258 */
259 bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions** outOptions) const;
260 /**
261 * Filter packet function
262 * \param packet the packet
263 * \param options the capture options
264 * \returns true if successful
265 */
266 static bool FilterPacket(Ptr<const Packet> packet, const PacketCaptureOptions& options);
267
268 typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey; ///< TxRecordKey typedef
269
270 /// TxRecordValue structure
272 {
273 Time time; ///< time
274 Ptr<Node> srcNode; ///< source node
275 bool isBroadcast; ///< is broadcast?
276 };
277
278 /// TransmissionSampleKey structure
280 {
281 /**
282 * Less than operator
283 *
284 * \param other object to compare
285 * \return true if less than
286 */
287 bool operator<(const TransmissionSampleKey& other) const;
288 /**
289 * Equality operator
290 *
291 * \param other object to compare
292 * \return true if equal
293 */
294 bool operator==(const TransmissionSampleKey& other) const;
295 Ptr<Node> transmitter; ///< transmitter
296 Ptr<Node> receiver; ///< NULL if broadcast
297 Ptr<Channel> channel; ///< channel
298 };
299
300 /// TransmissionSampleValue structure
302 {
303 uint32_t bytes; ///< bytes
304 };
305
306 // Data
307 std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions; ///< packet capture options
308 std::vector<std::string> m_pauseMessages; ///< pause message
309 std::map<TxRecordKey, TxRecordValue> m_txRecords; ///< transmit records
310 std::map<TransmissionSampleKey, TransmissionSampleValue>
311 m_transmissionSamples; ///< transmission samples
312 std::map<Ptr<Node>, uint32_t> m_packetDrops; ///< packet drops
313 std::set<uint32_t>
314 m_nodesOfInterest; ///< list of node IDs whose transmissions will be monitored
315 std::map<uint32_t, Time> m_packetsOfInterest; ///< list of packet UIDs that will be monitored
316 std::map<uint32_t, LastPacketsSample> m_lastPackets; ///< last packets
317 std::map<uint32_t, std::vector<NetDeviceStatistics>> m_nodesStatistics; ///< node statistics
318
319 // Trace callbacks
320 /**
321 * Network transmit common trace callback function
322 * \param context the context
323 * \param packet the packet
324 * \param destination the destination MAC address
325 */
326 void TraceNetDevTxCommon(const std::string& context,
327 Ptr<const Packet> packet,
328 const Mac48Address& destination);
329 /**
330 * Network receive common trace callback function
331 * \param context the context
332 * \param packet the packet
333 * \param source the source MAC address
334 */
335 void TraceNetDevRxCommon(const std::string& context,
336 Ptr<const Packet> packet,
337 const Mac48Address& source);
338
339 /**
340 * Wi-Fi transmit trace callback function
341 * \param context the context
342 * \param packet the packet
343 */
344 void TraceNetDevTxWifi(std::string context, Ptr<const Packet> packet);
345 /**
346 * Wi-Fi receive trace callback function
347 * \param context the context
348 * \param packet the packet
349 */
350 void TraceNetDevRxWifi(std::string context, Ptr<const Packet> packet);
351
352 /**
353 * Queue drop trace callback function
354 * \param context the context
355 * \param packet the packet
356 */
357 void TraceDevQueueDrop(std::string context, Ptr<const Packet> packet);
358 /**
359 * Ipv4 drop trace callback function
360 * \param context the context
361 * \param hdr the header
362 * \param packet the packet
363 * \param reason the drop reason
364 * \param dummy_ipv4 the dummy Ipv4
365 * \param interface the interface
366 */
367 void TraceIpv4Drop(std::string context,
368 const ns3::Ipv4Header& hdr,
369 Ptr<const Packet> packet,
371 Ptr<Ipv4> dummy_ipv4,
372 uint32_t interface);
373
374 /**
375 * CSMA transmit trace callback function
376 * \param context the context
377 * \param packet the packet
378 */
379 void TraceNetDevTxCsma(std::string context, Ptr<const Packet> packet);
380 /**
381 * CSMA receive trace callback function
382 * \param context the context
383 * \param packet the packet
384 */
385 void TraceNetDevRxCsma(std::string context, Ptr<const Packet> packet);
386 /**
387 * CSMA promiscuous receive function
388 * \param context the context
389 * \param packet the packet
390 */
391 void TraceNetDevPromiscRxCsma(std::string context, Ptr<const Packet> packet);
392
393 /**
394 * Point to point transmit trace callback function
395 * \param context the context
396 * \param packet the packet
397 */
398 void TraceNetDevTxPointToPoint(std::string context, Ptr<const Packet> packet);
399 /**
400 * Point to point receive trace callback function
401 * \param context the context
402 * \param packet the packet
403 */
404 void TraceNetDevRxPointToPoint(std::string context, Ptr<const Packet> packet);
405
406 /**
407 * WiMax transmit trace callback function
408 * \param context the context
409 * \param packet the packet
410 * \param destination the destination MAC address
411 */
412 void TraceNetDevTxWimax(std::string context,
413 Ptr<const Packet> packet,
414 const Mac48Address& destination);
415 /**
416 * WiMax transmit trace callback function
417 * \param context the context
418 * \param packet the packet
419 * \param source the source MAC address
420 */
421 void TraceNetDevRxWimax(std::string context,
422 Ptr<const Packet> packet,
423 const Mac48Address& source);
424
425 /**
426 * LTE transmit trace callback function
427 * \param context the context
428 * \param packet the packet
429 * \param destination the destination MAC address
430 */
431 void TraceNetDevTxLte(std::string context,
432 Ptr<const Packet> packet,
433 const Mac48Address& destination);
434 /**
435 * LTE receive trace callback function
436 * \param context the context
437 * \param packet the packet
438 * \param source the MAC address of the source
439 */
440 void TraceNetDevRxLte(std::string context,
441 Ptr<const Packet> packet,
442 const Mac48Address& source);
443
444 /**
445 * Find net device statistics function
446 * \param node the node
447 * \param interface the interface number
448 * \returns the device statistics
449 */
450 inline NetDeviceStatistics& FindNetDeviceStatistics(int node, int interface);
451
452 /**
453 * Do pause function
454 * \param message the pause message
455 */
456 void DoPause(const std::string& message);
457
458 bool m_stop; ///< stop?
459 Time m_runUntil; ///< run until time
460
461 /// Stop simulation callback function
463};
464
465} // namespace ns3
466
467#endif /* NS3_PYVIZ_H */
Packet header for IPv4.
Definition: ipv4-header.h:34
DropReason
Reason why a packet has been dropped.
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
helper class to be used by the visualizer
Definition: pyviz.h:52
void RegisterCsmaLikeDevice(const std::string &deviceTypeName)
Register CSMA like device function.
Definition: pyviz.cc:184
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
CSMA receive trace callback function.
Definition: pyviz.cc:793
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
Set packet capture options function.
Definition: pyviz.cc:230
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point receive trace callback function.
Definition: pyviz.cc:801
void RegisterDropTracePath(const std::string &tracePath)
Register drop trace path function.
Definition: pyviz.cc:240
void RegisterWifiLikeDevice(const std::string &deviceTypeName)
Register WIFI like device function.
Definition: pyviz.cc:202
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
packet capture options
Definition: pyviz.h:307
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &destination)
LTE transmit trace callback function.
Definition: pyviz.cc:839
std::map< uint32_t, LastPacketsSample > m_lastPackets
last packets
Definition: pyviz.h:316
void SimulatorRunUntil(Time time)
Run simulation until a given (simulated, absolute) time is reached.
Definition: pyviz.cc:290
bool m_stop
stop?
Definition: pyviz.h:458
PacketDropSampleList GetPacketDropSamples() const
Get packet drop samples.
Definition: pyviz.cc:877
void SetNodesOfInterest(std::set< uint32_t > nodes)
Set nodes of interest function.
Definition: pyviz.cc:895
~PyViz()
Definition: pyviz.cc:245
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
node statistics
Definition: pyviz.h:317
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
CSMA transmit trace callback function.
Definition: pyviz.cc:624
void TraceNetDevTxCommon(const std::string &context, Ptr< const Packet > packet, const Mac48Address &destination)
Network transmit common trace callback function.
Definition: pyviz.cc:521
void DoPause(const std::string &message)
Do pause function.
Definition: pyviz.cc:254
std::vector< NodeStatistics > GetNodesStatistics() const
Get node statistics.
Definition: pyviz.cc:901
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, const Mac48Address &source)
WiMax transmit trace callback function.
Definition: pyviz.cc:832
std::set< uint32_t > m_nodesOfInterest
list of node IDs whose transmissions will be monitored
Definition: pyviz.h:314
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
CSMA promiscuous receive function.
Definition: pyviz.cc:807
static void Pause(const std::string &message)
Pause function.
Definition: pyviz.cc:263
std::vector< std::string > m_pauseMessages
pause message
Definition: pyviz.h:308
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, const Mac48Address &source)
LTE receive trace callback function.
Definition: pyviz.cc:848
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, const Mac48Address &destination)
WiMax transmit trace callback function.
Definition: pyviz.cc:823
void TraceIpv4Drop(std::string context, const ns3::Ipv4Header &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
Ipv4 drop trace callback function.
Definition: pyviz.cc:506
void TraceNetDevRxCommon(const std::string &context, Ptr< const Packet > packet, const Mac48Address &source)
Network receive common trace callback function.
Definition: pyviz.cc:640
TransmissionSampleList GetTransmissionSamples() const
Get transmission samples.
Definition: pyviz.cc:857
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
Utility function - clips a line to a bounding box.
Definition: pyviz.cc:1602
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
transmission samples
Definition: pyviz.h:311
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point transmit trace callback function.
Definition: pyviz.cc:632
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi receive trace callback function.
Definition: pyviz.cc:757
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
Find net device statistics function.
Definition: pyviz.cc:384
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
Queue drop trace callback function.
Definition: pyviz.cc:459
std::map< TxRecordKey, TxRecordValue > m_txRecords
transmit records
Definition: pyviz.h:309
std::vector< std::string > GetPauseMessages() const
Get pause message function.
Definition: pyviz.cc:270
std::vector< PacketDropSample > PacketDropSampleList
PacketDropSampleList typedef.
Definition: pyviz.h:120
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Filter packet function.
Definition: pyviz.cc:417
void CallbackStopSimulation()
Stop simulation callback function.
Definition: pyviz.cc:279
void RegisterPointToPointLikeDevice(const std::string &deviceTypeName)
Register point to point like device function.
Definition: pyviz.cc:216
std::map< Ptr< Node >, uint32_t > m_packetDrops
packet drops
Definition: pyviz.h:312
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Get last packets function.
Definition: pyviz.cc:913
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
Wi-Fi transmit trace callback function.
Definition: pyviz.cc:589
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Get packet capture options function.
Definition: pyviz.cc:402
Time m_runUntil
run until time
Definition: pyviz.h:459
std::map< uint32_t, Time > m_packetsOfInterest
list of packet UIDs that will be monitored
Definition: pyviz.h:315
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
TxRecordKey typedef.
Definition: pyviz.h:268
std::vector< TransmissionSample > TransmissionSampleList
TransmissionSampleList typedef.
Definition: pyviz.h:106
PacketCaptureMode
PacketCaptureMode enumeration.
Definition: pyviz.h:201
@ PACKET_CAPTURE_FILTER_HEADERS_OR
Definition: pyviz.h:203
@ PACKET_CAPTURE_DISABLED
Definition: pyviz.h:202
@ PACKET_CAPTURE_FILTER_HEADERS_AND
Definition: pyviz.h:205
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LastPacketsSample structure.
Definition: pyviz.h:149
std::vector< PacketSample > lastDroppedPackets
last dropped packets
Definition: pyviz.h:152
std::vector< TxPacketSample > lastTransmittedPackets
last transmitted packets
Definition: pyviz.h:151
std::vector< RxPacketSample > lastReceivedPackets
last received packets
Definition: pyviz.h:150
NetDeviceStatistics structure.
Definition: pyviz.h:170
uint64_t receivedBytes
received bytes
Definition: pyviz.h:181
uint64_t transmittedBytes
transmitted bytes
Definition: pyviz.h:180
uint32_t receivedPackets
received packets
Definition: pyviz.h:183
NetDeviceStatistics()
constructor
Definition: pyviz.h:172
uint32_t transmittedPackets
transmitted packets
Definition: pyviz.h:182
NodeStatistics structure.
Definition: pyviz.h:188
std::vector< NetDeviceStatistics > statistics
statistics
Definition: pyviz.h:190
uint32_t nodeId
node ID
Definition: pyviz.h:189
PacketCaptureOptions structure.
Definition: pyviz.h:211
PacketCaptureMode mode
mode
Definition: pyviz.h:214
uint32_t numLastPackets
num last packets
Definition: pyviz.h:213
std::set< TypeId > headers
headers
Definition: pyviz.h:212
PacketDropSample structure.
Definition: pyviz.h:115
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:116
uint32_t bytes
bytes
Definition: pyviz.h:117
PacketSample structure.
Definition: pyviz.h:129
Ptr< Packet > packet
packet
Definition: pyviz.h:131
Ptr< NetDevice > device
device
Definition: pyviz.h:132
RxPacketSample structure.
Definition: pyviz.h:143
Mac48Address from
from
Definition: pyviz.h:144
TransmissionSample structure.
Definition: pyviz.h:98
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:99
Ptr< Channel > channel
channel
Definition: pyviz.h:101
Ptr< Node > receiver
NULL if broadcast.
Definition: pyviz.h:100
TransmissionSampleKey structure.
Definition: pyviz.h:280
Ptr< Channel > channel
channel
Definition: pyviz.h:297
bool operator==(const TransmissionSampleKey &other) const
Equality operator.
Definition: pyviz.cc:376
bool operator<(const TransmissionSampleKey &other) const
Less than operator.
Definition: pyviz.cc:354
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:295
Ptr< Node > receiver
NULL if broadcast.
Definition: pyviz.h:296
TransmissionSampleValue structure.
Definition: pyviz.h:302
TxPacketSample structure.
Definition: pyviz.h:137
Mac48Address to
to
Definition: pyviz.h:138
TxRecordValue structure.
Definition: pyviz.h:272
Ptr< Node > srcNode
source node
Definition: pyviz.h:274
bool isBroadcast
is broadcast?
Definition: pyviz.h:275