|
gjc@3519
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
gjc@3519
|
2 |
/*
|
|
gjc@3519
|
3 |
* Copyright (c) 2008 INESC Porto
|
|
gjc@3519
|
4 |
*
|
|
gjc@3519
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
gjc@3519
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
gjc@3519
|
7 |
* published by the Free Software Foundation;
|
|
gjc@3519
|
8 |
*
|
|
gjc@3519
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
gjc@3519
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
gjc@3519
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
gjc@3519
|
12 |
* GNU General Public License for more details.
|
|
gjc@3519
|
13 |
*
|
|
gjc@3519
|
14 |
* You should have received a copy of the GNU General Public License
|
|
gjc@3519
|
15 |
* along with this program; if not, write to the Free Software
|
|
gjc@3519
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
gjc@3519
|
17 |
*
|
|
gjc@3519
|
18 |
* C++ helper functions for use by the python visualizer (for things
|
|
gjc@3519
|
19 |
* Python is too slow at).
|
|
gjc@3519
|
20 |
*
|
|
gjc@3519
|
21 |
* Author: Gustavo Carneiro <gjc@inescporto.pt>
|
|
gjc@3519
|
22 |
*/
|
|
gjc@3519
|
23 |
#ifndef NS3_PYVIZ_H
|
|
gjc@3519
|
24 |
#define NS3_PYVIZ_H
|
|
gjc@3519
|
25 |
|
|
gjc@3519
|
26 |
#include "ns3/nstime.h"
|
|
gjc@3780
|
27 |
#include "ns3/event-id.h"
|
|
gjc@3595
|
28 |
#include "ns3/node.h"
|
|
gjc@3595
|
29 |
#include "ns3/channel.h"
|
|
gjc@3595
|
30 |
#include "ns3/packet.h"
|
|
gjc@3595
|
31 |
#include "ns3/mac48-address.h"
|
|
gjc@3595
|
32 |
#include <map>
|
|
gjc@3710
|
33 |
#include <set>
|
|
gjc@3519
|
34 |
|
|
gjc@3530
|
35 |
namespace ns3 {
|
|
gjc@3530
|
36 |
|
|
gjc@3530
|
37 |
class PyViz
|
|
gjc@3519
|
38 |
{
|
|
gjc@3530
|
39 |
public:
|
|
gjc@3530
|
40 |
PyViz ();
|
|
gjc@3530
|
41 |
~PyViz ();
|
|
gjc@3780
|
42 |
|
|
gjc@3820
|
43 |
void RegisterDropTracePath (std::string const &tracePath);
|
|
gjc@3820
|
44 |
|
|
gjc@3887
|
45 |
void RegisterCsmaLikeDevice (std::string const &deviceTypeName);
|
|
gjc@3887
|
46 |
void RegisterWifiLikeDevice (std::string const &deviceTypeName);
|
|
gjc@3887
|
47 |
void RegisterPointToPointLikeDevice (std::string const &deviceTypeName);
|
|
gjc@3887
|
48 |
|
|
gjc@3530
|
49 |
// Run simulation until a given (simulated, absolute) time is reached
|
|
gjc@3530
|
50 |
void SimulatorRunUntil (Time time);
|
|
gjc@3595
|
51 |
|
|
gjc@3780
|
52 |
static void Pause (std::string const &message);
|
|
gjc@3780
|
53 |
std::vector<std::string> GetPauseMessages () const;
|
|
gjc@3780
|
54 |
|
|
gjc@3595
|
55 |
struct TransmissionSample
|
|
gjc@3595
|
56 |
{
|
|
gjc@3595
|
57 |
Ptr<Node> transmitter;
|
|
gjc@3595
|
58 |
Ptr<Node> receiver; // NULL if broadcast
|
|
gjc@3595
|
59 |
Ptr<Channel> channel;
|
|
gjc@3595
|
60 |
uint32_t bytes;
|
|
gjc@3595
|
61 |
};
|
|
gjc@3758
|
62 |
typedef std::vector<TransmissionSample> TransmissionSampleList;
|
|
gjc@3758
|
63 |
TransmissionSampleList GetTransmissionSamples () const;
|
|
gjc@3595
|
64 |
|
|
gjc@3758
|
65 |
struct PacketDropSample
|
|
gjc@3758
|
66 |
{
|
|
gjc@3758
|
67 |
Ptr<Node> transmitter;
|
|
gjc@3758
|
68 |
uint32_t bytes;
|
|
gjc@3758
|
69 |
};
|
|
gjc@3758
|
70 |
typedef std::vector<PacketDropSample> PacketDropSampleList;
|
|
gjc@3758
|
71 |
PacketDropSampleList GetPacketDropSamples () const;
|
|
gjc@3595
|
72 |
|
|
gjc@3595
|
73 |
|
|
gjc@3760
|
74 |
struct PacketSample
|
|
gjc@3760
|
75 |
{
|
|
gjc@3760
|
76 |
Time time;
|
|
gjc@3760
|
77 |
Ptr<Packet> packet;
|
|
gjc@3760
|
78 |
Ptr<NetDevice> device;
|
|
gjc@3760
|
79 |
};
|
|
gjc@3887
|
80 |
struct TxPacketSample : PacketSample
|
|
gjc@3887
|
81 |
{
|
|
gjc@3887
|
82 |
Mac48Address to;
|
|
gjc@3887
|
83 |
};
|
|
gjc@3887
|
84 |
struct RxPacketSample : PacketSample
|
|
gjc@3887
|
85 |
{
|
|
gjc@3887
|
86 |
Mac48Address from;
|
|
gjc@3887
|
87 |
};
|
|
gjc@3760
|
88 |
|
|
gjc@3760
|
89 |
struct LastPacketsSample
|
|
gjc@3760
|
90 |
{
|
|
gjc@3887
|
91 |
std::vector<RxPacketSample> lastReceivedPackets;
|
|
gjc@3887
|
92 |
std::vector<TxPacketSample> lastTransmittedPackets;
|
|
gjc@3760
|
93 |
std::vector<PacketSample> lastDroppedPackets;
|
|
gjc@3760
|
94 |
};
|
|
gjc@3766
|
95 |
LastPacketsSample GetLastPackets (uint32_t nodeId) const;
|
|
gjc@3760
|
96 |
|
|
gjc@3760
|
97 |
|
|
gjc@3710
|
98 |
void SetNodesOfInterest (std::set<uint32_t> nodes);
|
|
gjc@3710
|
99 |
|
|
gjc@3739
|
100 |
struct NetDeviceStatistics
|
|
gjc@3739
|
101 |
{
|
|
gjc@3739
|
102 |
NetDeviceStatistics () : transmittedBytes (0), receivedBytes (0),
|
|
gjc@3739
|
103 |
transmittedPackets (0), receivedPackets (0) {}
|
|
gjc@3739
|
104 |
uint64_t transmittedBytes;
|
|
gjc@3739
|
105 |
uint64_t receivedBytes;
|
|
gjc@3739
|
106 |
uint32_t transmittedPackets;
|
|
gjc@3739
|
107 |
uint32_t receivedPackets;
|
|
gjc@3739
|
108 |
};
|
|
gjc@3739
|
109 |
|
|
gjc@3739
|
110 |
struct NodeStatistics
|
|
gjc@3739
|
111 |
{
|
|
gjc@3739
|
112 |
uint32_t nodeId;
|
|
gjc@3739
|
113 |
std::vector<NetDeviceStatistics> statistics;
|
|
gjc@3739
|
114 |
};
|
|
gjc@3739
|
115 |
|
|
gjc@3739
|
116 |
std::vector<NodeStatistics> GetNodesStatistics () const;
|
|
gjc@3739
|
117 |
|
|
gjc@3885
|
118 |
enum PacketCaptureMode {
|
|
gjc@3885
|
119 |
PACKET_CAPTURE_DISABLED=1, // packet capture is disabled
|
|
gjc@3885
|
120 |
PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present
|
|
gjc@3885
|
121 |
PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present
|
|
gjc@3885
|
122 |
};
|
|
gjc@3885
|
123 |
|
|
gjc@3885
|
124 |
struct PacketCaptureOptions
|
|
gjc@3885
|
125 |
{
|
|
gjc@3885
|
126 |
std::set<TypeId> headers;
|
|
gjc@3885
|
127 |
uint32_t numLastPackets;
|
|
gjc@3885
|
128 |
PacketCaptureMode mode;
|
|
gjc@3885
|
129 |
};
|
|
gjc@3885
|
130 |
|
|
gjc@3885
|
131 |
void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options);
|
|
gjc@3848
|
132 |
|
|
gjc@3902
|
133 |
|
|
gjc@3902
|
134 |
// Yes, I know, this is just a utility function, not really related to the class in any way.
|
|
gjc@3902
|
135 |
|
|
gjc@3902
|
136 |
// -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#-
|
|
gjc@3902
|
137 |
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 :(
|
|
gjc@3902
|
138 |
|
|
gjc@3902
|
139 |
|
|
gjc@3595
|
140 |
private:
|
|
gjc@3885
|
141 |
|
|
gjc@3885
|
142 |
bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
|
|
gjc@3885
|
143 |
static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
|
|
gjc@3739
|
144 |
|
|
gjc@3739
|
145 |
|
|
gjc@3714
|
146 |
typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
|
|
gjc@3714
|
147 |
|
|
gjc@3714
|
148 |
struct TxRecordValue
|
|
gjc@3595
|
149 |
{
|
|
gjc@3714
|
150 |
Time time;
|
|
gjc@3595
|
151 |
Ptr<Node> srcNode;
|
|
gjc@3702
|
152 |
bool isBroadcast;
|
|
gjc@3595
|
153 |
};
|
|
gjc@3714
|
154 |
|
|
gjc@3595
|
155 |
struct TransmissionSampleKey
|
|
gjc@3595
|
156 |
{
|
|
gjc@3595
|
157 |
bool operator < (TransmissionSampleKey const &other) const;
|
|
gjc@3742
|
158 |
bool operator == (TransmissionSampleKey const &other) const;
|
|
gjc@3595
|
159 |
Ptr<Node> transmitter;
|
|
gjc@3595
|
160 |
Ptr<Node> receiver; // NULL if broadcast
|
|
gjc@3595
|
161 |
Ptr<Channel> channel;
|
|
gjc@3595
|
162 |
};
|
|
gjc@3595
|
163 |
|
|
gjc@3595
|
164 |
struct TransmissionSampleValue
|
|
gjc@3595
|
165 |
{
|
|
gjc@3595
|
166 |
uint32_t bytes;
|
|
gjc@3595
|
167 |
};
|
|
gjc@3595
|
168 |
|
|
gjc@3887
|
169 |
// data
|
|
gjc@3887
|
170 |
std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
|
|
gjc@3887
|
171 |
std::vector<std::string> m_pauseMessages;
|
|
gjc@3887
|
172 |
std::map<TxRecordKey, TxRecordValue> m_txRecords;
|
|
gjc@3595
|
173 |
std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
|
|
gjc@3758
|
174 |
std::map<Ptr<Node>, uint32_t> m_packetDrops;
|
|
gjc@3710
|
175 |
std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored
|
|
gjc@3714
|
176 |
std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored
|
|
gjc@3766
|
177 |
std::map<uint32_t, LastPacketsSample> m_lastPackets;
|
|
gjc@3739
|
178 |
std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
|
|
gjc@3739
|
179 |
|
|
gjc@3887
|
180 |
// Trace callbacks
|
|
gjc@3887
|
181 |
void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
|
|
gjc@3887
|
182 |
void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
|
|
gjc@3595
|
183 |
|
|
gjc@3759
|
184 |
void TraceDrop (std::string context, Ptr<const Packet> packet);
|
|
gjc@3758
|
185 |
|
|
gjc@3702
|
186 |
void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
|
|
gjc@3702
|
187 |
void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
|
|
gjc@3702
|
188 |
void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet, NetDevice::PacketType packetType);
|
|
gjc@3702
|
189 |
|
|
gjc@3887
|
190 |
void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
|
|
gjc@3887
|
191 |
void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
|
|
gjc@3887
|
192 |
|
|
gjc@3739
|
193 |
inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
|
|
gjc@3739
|
194 |
|
|
gjc@3780
|
195 |
void DoPause (std::string const &message);
|
|
gjc@3739
|
196 |
|
|
gjc@3780
|
197 |
bool m_stop;
|
|
gjc@3780
|
198 |
EventId m_stopCallbackEvent;
|
|
gjc@3780
|
199 |
void CallbackStopSimulation ();
|
|
gjc@3530
|
200 |
};
|
|
gjc@3519
|
201 |
|
|
gjc@3530
|
202 |
|
|
gjc@3519
|
203 |
}
|
|
gjc@3519
|
204 |
|
|
gjc@3519
|
205 |
#endif /* NS3_PYVIZ_H */
|