A Discrete-Event Network Simulator
API
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 
37 namespace ns3
38 {
39 
51 class PyViz
52 {
53  public:
54  PyViz();
55  ~PyViz();
56 
61  void RegisterDropTracePath(const std::string& tracePath);
62 
67  void RegisterCsmaLikeDevice(const std::string& deviceTypeName);
72  void RegisterWifiLikeDevice(const std::string& deviceTypeName);
77  void RegisterPointToPointLikeDevice(const std::string& deviceTypeName);
78 
83  void SimulatorRunUntil(Time time);
84 
89  static void Pause(const std::string& message);
94  std::vector<std::string> GetPauseMessages() const;
95 
98  {
102  uint32_t bytes;
103  };
104 
105  typedef std::vector<TransmissionSample>
112 
115  {
117  uint32_t bytes;
118  };
119 
120  typedef std::vector<PacketDropSample> PacketDropSampleList;
126 
129  {
133  };
134 
137  {
139  };
140 
143  {
145  };
146 
149  {
150  std::vector<RxPacketSample> lastReceivedPackets;
151  std::vector<TxPacketSample> lastTransmittedPackets;
152  std::vector<PacketSample> lastDroppedPackets;
153  };
154 
160  LastPacketsSample GetLastPackets(uint32_t nodeId) const;
161 
166  void SetNodesOfInterest(std::set<uint32_t> nodes);
167 
170  {
173  : transmittedBytes(0),
174  receivedBytes(0),
176  receivedPackets(0)
177  {
178  }
179 
180  uint64_t transmittedBytes;
181  uint64_t receivedBytes;
183  uint32_t receivedPackets;
184  };
185 
188  {
189  uint32_t nodeId;
190  std::vector<NetDeviceStatistics> statistics;
191  };
192 
197  std::vector<NodeStatistics> GetNodesStatistics() const;
198 
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 
211  {
212  std::set<TypeId> headers;
213  uint32_t numLastPackets;
215  };
216 
222  void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options);
223 
224  // Yes, I know, this is just a utility function, not really related to the class in any way.
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:
259  bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions** outOptions) const;
266  static bool FilterPacket(Ptr<const Packet> packet, const PacketCaptureOptions& options);
267 
268  typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
269 
272  {
275  bool isBroadcast;
276  };
277 
280  {
287  bool operator<(const TransmissionSampleKey& other) const;
294  bool operator==(const TransmissionSampleKey& other) const;
298  };
299 
302  {
303  uint32_t bytes;
304  };
305 
306  // Data
307  std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
308  std::vector<std::string> m_pauseMessages;
309  std::map<TxRecordKey, TxRecordValue> m_txRecords;
310  std::map<TransmissionSampleKey, TransmissionSampleValue>
312  std::map<Ptr<Node>, uint32_t> m_packetDrops;
313  std::set<uint32_t>
315  std::map<uint32_t, Time> m_packetsOfInterest;
316  std::map<uint32_t, LastPacketsSample> m_lastPackets;
317  std::map<uint32_t, std::vector<NetDeviceStatistics>> m_nodesStatistics;
318 
319  // Trace callbacks
326  void TraceNetDevTxCommon(const std::string& context,
327  Ptr<const Packet> packet,
328  const Mac48Address& destination);
335  void TraceNetDevRxCommon(const std::string& context,
336  Ptr<const Packet> packet,
337  const Mac48Address& source);
338 
344  void TraceNetDevTxWifi(std::string context, Ptr<const Packet> packet);
350  void TraceNetDevRxWifi(std::string context, Ptr<const Packet> packet);
351 
357  void TraceDevQueueDrop(std::string context, Ptr<const Packet> packet);
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 
379  void TraceNetDevTxCsma(std::string context, Ptr<const Packet> packet);
385  void TraceNetDevRxCsma(std::string context, Ptr<const Packet> packet);
391  void TraceNetDevPromiscRxCsma(std::string context, Ptr<const Packet> packet);
392 
398  void TraceNetDevTxPointToPoint(std::string context, Ptr<const Packet> packet);
404  void TraceNetDevRxPointToPoint(std::string context, Ptr<const Packet> packet);
405 
412  void TraceNetDevTxWimax(std::string context,
413  Ptr<const Packet> packet,
414  const Mac48Address& destination);
421  void TraceNetDevRxWimax(std::string context,
422  Ptr<const Packet> packet,
423  const Mac48Address& source);
424 
431  void TraceNetDevTxLte(std::string context,
432  Ptr<const Packet> packet,
433  const Mac48Address& destination);
440  void TraceNetDevRxLte(std::string context,
441  Ptr<const Packet> packet,
442  const Mac48Address& source);
443 
450  inline NetDeviceStatistics& FindNetDeviceStatistics(int node, int interface);
451 
456  void DoPause(const std::string& message);
457 
458  bool m_stop;
460 
462  void CallbackStopSimulation();
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
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