A Discrete-Event Network Simulator
API
pyviz.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INESC Porto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * C++ helper functions for use by the python visualizer (for things
19  * Python is too slow at).
20  *
21  * Author: Gustavo Carneiro <gjc@inescporto.pt>
22  */
23 #ifndef NS3_PYVIZ_H
24 #define NS3_PYVIZ_H
25 
26 #include "ns3/nstime.h"
27 #include "ns3/event-id.h"
28 #include "ns3/node.h"
29 #include "ns3/channel.h"
30 #include "ns3/packet.h"
31 #include "ns3/mac48-address.h"
32 #include "ns3/ipv4-header.h"
33 #include "ns3/ipv4-l3-protocol.h"
34 
35 #include <map>
36 #include <set>
37 
38 namespace ns3 {
39 
51 class PyViz
52 {
53 public:
54  PyViz ();
55  ~PyViz ();
56 
61  void RegisterDropTracePath (std::string const &tracePath);
62 
67  void RegisterCsmaLikeDevice (std::string const &deviceTypeName);
72  void RegisterWifiLikeDevice (std::string const &deviceTypeName);
77  void RegisterPointToPointLikeDevice (std::string const &deviceTypeName);
78 
83  void SimulatorRunUntil (Time time);
84 
89  static void Pause (std::string const &message);
94  std::vector<std::string> GetPauseMessages () const;
95 
98  {
102  uint32_t bytes;
103  };
104  typedef std::vector<TransmissionSample> TransmissionSampleList;
110 
113  {
115  uint32_t bytes;
116  };
117  typedef std::vector<PacketDropSample> PacketDropSampleList;
123 
124 
127  {
131  };
134  {
136  };
139  {
141  };
142 
145  {
146  std::vector<RxPacketSample> lastReceivedPackets;
147  std::vector<TxPacketSample> lastTransmittedPackets;
148  std::vector<PacketSample> lastDroppedPackets;
149  };
155  LastPacketsSample GetLastPackets (uint32_t nodeId) const;
156 
157 
162  void SetNodesOfInterest (std::set<uint32_t> nodes);
163 
166  {
170  uint64_t transmittedBytes;
171  uint64_t receivedBytes;
173  uint32_t receivedPackets;
174  };
175 
178  {
179  uint32_t nodeId;
180  std::vector<NetDeviceStatistics> statistics;
181  };
182 
187  std::vector<NodeStatistics> GetNodesStatistics () const;
188 
191  PACKET_CAPTURE_DISABLED=1, // packet capture is disabled
192  PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present
193  PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present
194  };
195 
198  {
199  std::set<TypeId> headers;
200  uint32_t numLastPackets;
202  };
203 
209  void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options);
210 
211 
212  // Yes, I know, this is just a utility function, not really related to the class in any way.
224  // -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#-
225  static void LineClipping (double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2);
226  // Don't break the above line or pybindgen will not be able to pick up the above annotation :(
227 
228 private:
229 
236  bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
243  static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
244 
245 
246  typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
247 
250  {
253  bool isBroadcast;
254  };
255 
258  {
265  bool operator < (TransmissionSampleKey const &other) const;
272  bool operator == (TransmissionSampleKey const &other) const;
276  };
277 
280  {
281  uint32_t bytes;
282  };
283 
284  // data
285  std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
286  std::vector<std::string> m_pauseMessages;
287  std::map<TxRecordKey, TxRecordValue> m_txRecords;
288  std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
289  std::map<Ptr<Node>, uint32_t> m_packetDrops;
290  std::set<uint32_t> m_nodesOfInterest;
291  std::map<uint32_t, Time> m_packetsOfInterest;
292  std::map<uint32_t, LastPacketsSample> m_lastPackets;
293  std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
294 
295  // Trace callbacks
302  void TraceNetDevTxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &destination);
309  void TraceNetDevRxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &source);
310 
316  void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet);
322  void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet);
323 
329  void TraceDevQueueDrop (std::string context, Ptr<const Packet> packet);
339  void TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet,
340  ns3::Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> dummy_ipv4, uint32_t interface);
341 
347  void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
353  void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
359  void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet);
360 
366  void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
372  void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
373 
380  void TraceNetDevTxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
387  void TraceNetDevRxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
388 
395  void TraceNetDevTxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
402  void TraceNetDevRxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
403 
410  inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
411 
416  void DoPause (std::string const &message);
417 
418  bool m_stop;
421  void CallbackStopSimulation ();
422 };
423 
424 
425 }
426 
427 #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:44
helper class to be used by the visualizer
Definition: pyviz.h:52
void RegisterDropTracePath(std::string const &tracePath)
Register drop trace path function.
Definition: pyviz.cc:240
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
CSMA receive trace callback function.
Definition: pyviz.cc:802
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
Set packet capture options function.
Definition: pyviz.cc:230
void RegisterCsmaLikeDevice(std::string const &deviceTypeName)
Register CSMA like device function.
Definition: pyviz.cc:184
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point receive trace callback function.
Definition: pyviz.cc:810
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
packet capture options
Definition: pyviz.h:285
static void Pause(std::string const &message)
Pause function.
Definition: pyviz.cc:261
std::map< uint32_t, LastPacketsSample > m_lastPackets
last packets
Definition: pyviz.h:292
void SimulatorRunUntil(Time time)
Run simulation until a given (simulated, absolute) time is reached.
Definition: pyviz.cc:288
bool m_stop
stop?
Definition: pyviz.h:418
void TraceIpv4Drop(std::string context, ns3::Ipv4Header const &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
ipv4 drop trace callback function
Definition: pyviz.cc:516
PacketDropSampleList GetPacketDropSamples() const
Get packet drop samples.
Definition: pyviz.cc:885
void TraceNetDevTxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &destination)
network transmit common trace callback function
Definition: pyviz.cc:528
void SetNodesOfInterest(std::set< uint32_t > nodes)
Set nodes of interest function.
Definition: pyviz.cc:906
~PyViz()
Definition: pyviz.cc:245
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
node statsitics
Definition: pyviz.h:293
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
CSMA transmit trace callback function.
Definition: pyviz.cc:630
void DoPause(std::string const &message)
Do pause function.
Definition: pyviz.cc:253
std::vector< NodeStatistics > GetNodesStatistics() const
Get node statistics.
Definition: pyviz.cc:912
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
LTE receive trace callback function.
Definition: pyviz.cc:853
std::set< uint32_t > m_nodesOfInterest
list of node IDs whose transmissions will be monitored
Definition: pyviz.h:290
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
CSMA promiscious receive function.
Definition: pyviz.cc:816
void RegisterWifiLikeDevice(std::string const &deviceTypeName)
Register WIFI like device function.
Definition: pyviz.cc:202
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
WIMax transmit trace callback function.
Definition: pyviz.cc:832
std::vector< std::string > m_pauseMessages
pause message
Definition: pyviz.h:286
void TraceNetDevRxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &source)
network receive common trace callback function
Definition: pyviz.cc:649
TransmissionSampleList GetTransmissionSamples() const
Get transmission samples.
Definition: pyviz.cc:862
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:1475
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
WIMax transmit trace callback function.
Definition: pyviz.cc:839
void RegisterPointToPointLikeDevice(std::string const &deviceTypeName)
Register point to point like device function.
Definition: pyviz.cc:216
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
transmission samples
Definition: pyviz.h:288
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Point to point transmit trace calllback function.
Definition: pyviz.cc:638
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
WIFI receive trace callback function.
Definition: pyviz.cc:763
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
Findnet device statistics function.
Definition: pyviz.cc:388
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
queue drop trace callback function
Definition: pyviz.cc:470
std::map< TxRecordKey, TxRecordValue > m_txRecords
transmit records
Definition: pyviz.h:287
std::vector< std::string > GetPauseMessages() const
Get pause message function.
Definition: pyviz.cc:268
std::vector< PacketDropSample > PacketDropSampleList
PacketDropSampleList typedef.
Definition: pyviz.h:117
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Filter packet function.
Definition: pyviz.cc:419
void CallbackStopSimulation()
stop simulation callback function
Definition: pyviz.cc:277
std::map< Ptr< Node >, uint32_t > m_packetDrops
packt drops
Definition: pyviz.h:289
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Get last packets function.
Definition: pyviz.cc:926
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
WIFI transmit trace callback function.
Definition: pyviz.cc:594
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Get packet capture options function.
Definition: pyviz.cc:405
Time m_runUntil
run until time
Definition: pyviz.h:419
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
LTE transmit trace callback function.
Definition: pyviz.cc:846
std::map< uint32_t, Time > m_packetsOfInterest
list of packet UIDs that will be monitored
Definition: pyviz.h:291
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
TxRecordKey typedef.
Definition: pyviz.h:246
std::vector< TransmissionSample > TransmissionSampleList
TransmissionSampleList typedef.
Definition: pyviz.h:104
PacketCaptureMode
PacketCaptureMode enumeration.
Definition: pyviz.h:190
@ PACKET_CAPTURE_FILTER_HEADERS_OR
Definition: pyviz.h:192
@ PACKET_CAPTURE_DISABLED
Definition: pyviz.h:191
@ PACKET_CAPTURE_FILTER_HEADERS_AND
Definition: pyviz.h:193
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LastPacketsSample structure.
Definition: pyviz.h:145
std::vector< PacketSample > lastDroppedPackets
last dropped packets
Definition: pyviz.h:148
std::vector< TxPacketSample > lastTransmittedPackets
last transmitted packets
Definition: pyviz.h:147
std::vector< RxPacketSample > lastReceivedPackets
last received packets
Definition: pyviz.h:146
NetDeviceStatistics structure.
Definition: pyviz.h:166
uint64_t receivedBytes
received bytes
Definition: pyviz.h:171
uint64_t transmittedBytes
transmitted bytes
Definition: pyviz.h:170
uint32_t receivedPackets
received packets
Definition: pyviz.h:173
NetDeviceStatistics()
constructor
Definition: pyviz.h:168
uint32_t transmittedPackets
transmitted packets
Definition: pyviz.h:172
NodeStatistics structure.
Definition: pyviz.h:178
std::vector< NetDeviceStatistics > statistics
statistics
Definition: pyviz.h:180
uint32_t nodeId
node ID
Definition: pyviz.h:179
PacketCaptureOptions structure.
Definition: pyviz.h:198
PacketCaptureMode mode
mode
Definition: pyviz.h:201
uint32_t numLastPackets
num last packets
Definition: pyviz.h:200
std::set< TypeId > headers
headers
Definition: pyviz.h:199
PacketDropSample structure.
Definition: pyviz.h:113
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:114
uint32_t bytes
bytes
Definition: pyviz.h:115
PacketSample structure.
Definition: pyviz.h:127
Ptr< Packet > packet
packet
Definition: pyviz.h:129
Ptr< NetDevice > device
device
Definition: pyviz.h:130
RxPacketSample structure.
Definition: pyviz.h:139
Mac48Address from
from
Definition: pyviz.h:140
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:258
Ptr< Channel > channel
channel
Definition: pyviz.h:275
Ptr< Node > transmitter
transmitter
Definition: pyviz.h:273
bool operator==(TransmissionSampleKey const &other) const
equality operator
Definition: pyviz.cc:378
bool operator<(TransmissionSampleKey const &other) const
less than operator
Definition: pyviz.cc:350
Ptr< Node > receiver
NULL if broadcast.
Definition: pyviz.h:274
TransmissionSampleValue structure.
Definition: pyviz.h:280
TxPacketSample structure.
Definition: pyviz.h:134
Mac48Address to
to
Definition: pyviz.h:135
TxRecordValue structure.
Definition: pyviz.h:250
Ptr< Node > srcNode
source node
Definition: pyviz.h:252
bool isBroadcast
is broadcast?
Definition: pyviz.h:253