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 
57  void RegisterDropTracePath (std::string const &tracePath);
58 
59  void RegisterCsmaLikeDevice (std::string const &deviceTypeName);
60  void RegisterWifiLikeDevice (std::string const &deviceTypeName);
61  void RegisterPointToPointLikeDevice (std::string const &deviceTypeName);
62 
63  // Run simulation until a given (simulated, absolute) time is reached
64  void SimulatorRunUntil (Time time);
65 
66  static void Pause (std::string const &message);
67  std::vector<std::string> GetPauseMessages () const;
68 
70  {
72  Ptr<Node> receiver; // NULL if broadcast
74  uint32_t bytes;
75  };
76  typedef std::vector<TransmissionSample> TransmissionSampleList;
77  TransmissionSampleList GetTransmissionSamples () const;
78 
80  {
82  uint32_t bytes;
83  };
84  typedef std::vector<PacketDropSample> PacketDropSampleList;
85  PacketDropSampleList GetPacketDropSamples () const;
86 
87 
88  struct PacketSample
89  {
93  };
95  {
97  };
99  {
101  };
102 
104  {
105  std::vector<RxPacketSample> lastReceivedPackets;
106  std::vector<TxPacketSample> lastTransmittedPackets;
107  std::vector<PacketSample> lastDroppedPackets;
108  };
109  LastPacketsSample GetLastPackets (uint32_t nodeId) const;
110 
111 
112  void SetNodesOfInterest (std::set<uint32_t> nodes);
113 
115  {
119  uint64_t receivedBytes;
121  uint32_t receivedPackets;
122  };
123 
125  {
126  uint32_t nodeId;
127  std::vector<NetDeviceStatistics> statistics;
128  };
129 
130  std::vector<NodeStatistics> GetNodesStatistics () const;
131 
133  PACKET_CAPTURE_DISABLED=1, // packet capture is disabled
134  PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present
135  PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present
136  };
137 
139  {
140  std::set<TypeId> headers;
141  uint32_t numLastPackets;
143  };
144 
145  void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options);
146 
147 
148  // Yes, I know, this is just a utility function, not really related to the class in any way.
149 
150  // -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#-
151  static void LineClipping (double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2); // don't break this line or pybindgen will not be able to pick up the above annotation :(
152 
153 
154 private:
155 
156  bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
157  static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
158 
159 
160  typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
161 
163  {
167  };
168 
170  {
171  bool operator < (TransmissionSampleKey const &other) const;
172  bool operator == (TransmissionSampleKey const &other) const;
174  Ptr<Node> receiver; // NULL if broadcast
176  };
177 
179  {
180  uint32_t bytes;
181  };
182 
183  // data
184  std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
185  std::vector<std::string> m_pauseMessages;
186  std::map<TxRecordKey, TxRecordValue> m_txRecords;
187  std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
188  std::map<Ptr<Node>, uint32_t> m_packetDrops;
189  std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored
190  std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored
191  std::map<uint32_t, LastPacketsSample> m_lastPackets;
192  std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
193 
194  // Trace callbacks
195  void TraceNetDevTxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &destination);
196  void TraceNetDevRxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &source);
197 
198  void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet);
199  void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet);
200 
201  void TraceDevQueueDrop (std::string context, Ptr<const Packet> packet);
202  void TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet,
203  ns3::Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> dummy_ipv4, uint32_t interface);
204 
205  void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
206  void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
207  void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet);
208 
209  void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
210  void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
211 
212  void TraceNetDevTxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
213  void TraceNetDevRxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
214 
215  void TraceNetDevTxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &destination);
216  void TraceNetDevRxLte (std::string context, Ptr<const Packet> packet, Mac48Address const &source);
217 
218  inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
219 
220  void DoPause (std::string const &message);
221 
222  bool m_stop;
224  void CallbackStopSimulation ();
225 };
226 
227 
228 }
229 
230 #endif /* NS3_PYVIZ_H */
std::vector< TransmissionSample > TransmissionSampleList
Definition: pyviz.h:76
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
std::vector< std::string > m_pauseMessages
Definition: pyviz.h:185
void TraceNetDevTxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &destination)
Definition: pyviz.cc:518
std::pair< Ptr< Channel >, uint32_t > TxRecordKey
Definition: pyviz.h:160
std::map< uint32_t, std::vector< NetDeviceStatistics > > m_nodesStatistics
Definition: pyviz.h:192
helper class to be used by the visualizer
Definition: pyviz.h:51
void TraceIpv4Drop(std::string context, ns3::Ipv4Header const &hdr, Ptr< const Packet > packet, ns3::Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > dummy_ipv4, uint32_t interface)
Definition: pyviz.cc:506
bool operator<(TransmissionSampleKey const &other) const
Definition: pyviz.cc:340
std::map< uint32_t, Time > m_packetsOfInterest
Definition: pyviz.h:190
std::map< TransmissionSampleKey, TransmissionSampleValue > m_transmissionSamples
Definition: pyviz.h:187
void TraceNetDevRxCommon(std::string const &context, Ptr< const Packet > packet, Mac48Address const &source)
Definition: pyviz.cc:639
std::map< Ptr< Node >, uint32_t > m_packetDrops
Definition: pyviz.h:188
std::map< uint32_t, LastPacketsSample > m_lastPackets
Definition: pyviz.h:191
void CallbackStopSimulation()
Definition: pyviz.cc:267
Mac48Address from
Definition: pyviz.h:100
std::vector< NetDeviceStatistics > statistics
Definition: pyviz.h:127
static bool FilterPacket(Ptr< const Packet > packet, const PacketCaptureOptions &options)
Definition: pyviz.cc:409
tuple nodes
Definition: first.py:25
void TraceNetDevTxWifi(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:584
void RegisterDropTracePath(std::string const &tracePath)
Definition: pyviz.cc:230
Packet header for IPv4.
Definition: ipv4-header.h:33
Ptr< Node > srcNode
Definition: pyviz.h:165
NetDeviceStatistics & FindNetDeviceStatistics(int node, int interface)
Definition: pyviz.cc:378
std::vector< TxPacketSample > lastTransmittedPackets
Definition: pyviz.h:106
Ptr< Packet > packet
Definition: pyviz.h:91
void RegisterPointToPointLikeDevice(std::string const &deviceTypeName)
Definition: pyviz.cc:206
Ptr< Channel > channel
Definition: pyviz.h:73
void TraceNetDevRxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
Definition: pyviz.cc:843
std::set< TypeId > headers
Definition: pyviz.h:140
void TraceNetDevPromiscRxCsma(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:806
Ptr< NetDevice > device
Definition: pyviz.h:92
void SimulatorRunUntil(Time time)
Definition: pyviz.cc:278
PacketDropSampleList GetPacketDropSamples() const
Definition: pyviz.cc:875
bool GetPacketCaptureOptions(uint32_t nodeId, const PacketCaptureOptions **outOptions) const
Definition: pyviz.cc:395
void SetNodesOfInterest(std::set< uint32_t > nodes)
Definition: pyviz.cc:896
Ptr< Node > transmitter
Definition: pyviz.h:81
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< uint32_t, PacketCaptureOptions > m_packetCaptureOptions
Definition: pyviz.h:184
an EUI-48 address
Definition: mac48-address.h:43
std::vector< RxPacketSample > lastReceivedPackets
Definition: pyviz.h:105
void TraceNetDevTxPointToPoint(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:628
void TraceNetDevRxWifi(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:753
void TraceDevQueueDrop(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:460
void RegisterCsmaLikeDevice(std::string const &deviceTypeName)
Definition: pyviz.cc:174
bool operator==(TransmissionSampleKey const &other) const
Definition: pyviz.cc:368
void TraceNetDevTxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
Definition: pyviz.cc:822
PacketCaptureMode
Definition: pyviz.h:132
std::set< uint32_t > m_nodesOfInterest
Definition: pyviz.h:189
bool m_stop
Definition: pyviz.h:222
~PyViz()
Definition: pyviz.cc:235
Time m_runUntil
Definition: pyviz.h:223
std::vector< NodeStatistics > GetNodesStatistics() const
Definition: pyviz.cc:902
static void LineClipping(double boundsX1, double boundsY1, double boundsX2, double boundsY2, double &lineX1, double &lineY1, double &lineX2, double &lineY2)
Definition: pyviz.cc:1417
TransmissionSampleList GetTransmissionSamples() const
Definition: pyviz.cc:852
void RegisterWifiLikeDevice(std::string const &deviceTypeName)
Definition: pyviz.cc:192
PacketCaptureMode mode
Definition: pyviz.h:142
std::vector< PacketDropSample > PacketDropSampleList
Definition: pyviz.h:84
DropReason
Reason why a packet has been dropped.
Mac48Address to
Definition: pyviz.h:96
void DoPause(std::string const &message)
Definition: pyviz.cc:243
void SetPacketCaptureOptions(uint32_t nodeId, PacketCaptureOptions options)
Definition: pyviz.cc:220
static void Pause(std::string const &message)
Definition: pyviz.cc:251
std::map< TxRecordKey, TxRecordValue > m_txRecords
Definition: pyviz.h:186
std::vector< PacketSample > lastDroppedPackets
Definition: pyviz.h:107
void TraceNetDevTxLte(std::string context, Ptr< const Packet > packet, Mac48Address const &destination)
Definition: pyviz.cc:836
void TraceNetDevTxCsma(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:620
void TraceNetDevRxPointToPoint(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:800
std::vector< std::string > GetPauseMessages() const
Definition: pyviz.cc:258
void TraceNetDevRxCsma(std::string context, Ptr< const Packet > packet)
Definition: pyviz.cc:792
void TraceNetDevRxWimax(std::string context, Ptr< const Packet > packet, Mac48Address const &source)
Definition: pyviz.cc:829
LastPacketsSample GetLastPackets(uint32_t nodeId) const
Definition: pyviz.cc:916