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