|
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 |
|
40 /** |
|
41 * \brief helper class to be used by the visualizer |
|
42 * \internal |
|
43 * |
|
44 * This class is not meant to be used by simulations. It is only |
|
45 * meant to be used by the visualizer tool (PyViz). The only reason |
|
46 * it is public is because Python bindings for it are needed, |
|
47 * otherwise it should be considered private. |
|
48 **/ |
|
49 class PyViz |
|
50 { |
|
51 public: |
|
52 PyViz (); |
|
53 ~PyViz (); |
|
54 |
|
55 void RegisterDropTracePath (std::string const &tracePath); |
|
56 |
|
57 void RegisterCsmaLikeDevice (std::string const &deviceTypeName); |
|
58 void RegisterWifiLikeDevice (std::string const &deviceTypeName); |
|
59 void RegisterPointToPointLikeDevice (std::string const &deviceTypeName); |
|
60 |
|
61 // Run simulation until a given (simulated, absolute) time is reached |
|
62 void SimulatorRunUntil (Time time); |
|
63 |
|
64 static void Pause (std::string const &message); |
|
65 std::vector<std::string> GetPauseMessages () const; |
|
66 |
|
67 struct TransmissionSample |
|
68 { |
|
69 Ptr<Node> transmitter; |
|
70 Ptr<Node> receiver; // NULL if broadcast |
|
71 Ptr<Channel> channel; |
|
72 uint32_t bytes; |
|
73 }; |
|
74 typedef std::vector<TransmissionSample> TransmissionSampleList; |
|
75 TransmissionSampleList GetTransmissionSamples () const; |
|
76 |
|
77 struct PacketDropSample |
|
78 { |
|
79 Ptr<Node> transmitter; |
|
80 uint32_t bytes; |
|
81 }; |
|
82 typedef std::vector<PacketDropSample> PacketDropSampleList; |
|
83 PacketDropSampleList GetPacketDropSamples () const; |
|
84 |
|
85 |
|
86 struct PacketSample |
|
87 { |
|
88 Time time; |
|
89 Ptr<Packet> packet; |
|
90 Ptr<NetDevice> device; |
|
91 }; |
|
92 struct TxPacketSample : PacketSample |
|
93 { |
|
94 Mac48Address to; |
|
95 }; |
|
96 struct RxPacketSample : PacketSample |
|
97 { |
|
98 Mac48Address from; |
|
99 }; |
|
100 |
|
101 struct LastPacketsSample |
|
102 { |
|
103 std::vector<RxPacketSample> lastReceivedPackets; |
|
104 std::vector<TxPacketSample> lastTransmittedPackets; |
|
105 std::vector<PacketSample> lastDroppedPackets; |
|
106 }; |
|
107 LastPacketsSample GetLastPackets (uint32_t nodeId) const; |
|
108 |
|
109 |
|
110 void SetNodesOfInterest (std::set<uint32_t> nodes); |
|
111 |
|
112 struct NetDeviceStatistics |
|
113 { |
|
114 NetDeviceStatistics () : transmittedBytes (0), receivedBytes (0), |
|
115 transmittedPackets (0), receivedPackets (0) {} |
|
116 uint64_t transmittedBytes; |
|
117 uint64_t receivedBytes; |
|
118 uint32_t transmittedPackets; |
|
119 uint32_t receivedPackets; |
|
120 }; |
|
121 |
|
122 struct NodeStatistics |
|
123 { |
|
124 uint32_t nodeId; |
|
125 std::vector<NetDeviceStatistics> statistics; |
|
126 }; |
|
127 |
|
128 std::vector<NodeStatistics> GetNodesStatistics () const; |
|
129 |
|
130 enum PacketCaptureMode { |
|
131 PACKET_CAPTURE_DISABLED=1, // packet capture is disabled |
|
132 PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present |
|
133 PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present |
|
134 }; |
|
135 |
|
136 struct PacketCaptureOptions |
|
137 { |
|
138 std::set<TypeId> headers; |
|
139 uint32_t numLastPackets; |
|
140 PacketCaptureMode mode; |
|
141 }; |
|
142 |
|
143 void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options); |
|
144 |
|
145 |
|
146 // Yes, I know, this is just a utility function, not really related to the class in any way. |
|
147 |
|
148 // -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#- |
|
149 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 :( |
|
150 |
|
151 |
|
152 private: |
|
153 |
|
154 bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const; |
|
155 static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options); |
|
156 |
|
157 |
|
158 typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey; |
|
159 |
|
160 struct TxRecordValue |
|
161 { |
|
162 Time time; |
|
163 Ptr<Node> srcNode; |
|
164 bool isBroadcast; |
|
165 }; |
|
166 |
|
167 struct TransmissionSampleKey |
|
168 { |
|
169 bool operator < (TransmissionSampleKey const &other) const; |
|
170 bool operator == (TransmissionSampleKey const &other) const; |
|
171 Ptr<Node> transmitter; |
|
172 Ptr<Node> receiver; // NULL if broadcast |
|
173 Ptr<Channel> channel; |
|
174 }; |
|
175 |
|
176 struct TransmissionSampleValue |
|
177 { |
|
178 uint32_t bytes; |
|
179 }; |
|
180 |
|
181 // data |
|
182 std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions; |
|
183 std::vector<std::string> m_pauseMessages; |
|
184 std::map<TxRecordKey, TxRecordValue> m_txRecords; |
|
185 std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples; |
|
186 std::map<Ptr<Node>, uint32_t> m_packetDrops; |
|
187 std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored |
|
188 std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored |
|
189 std::map<uint32_t, LastPacketsSample> m_lastPackets; |
|
190 std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics; |
|
191 |
|
192 // Trace callbacks |
|
193 void TraceNetDevTxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &destination); |
|
194 void TraceNetDevRxCommon (std::string const &context, Ptr<const Packet> packet, Mac48Address const &source); |
|
195 |
|
196 void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet); |
|
197 void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet); |
|
198 |
|
199 void TraceDevQueueDrop (std::string context, Ptr<const Packet> packet); |
|
200 void TraceIpv4Drop (std::string context, ns3::Ipv4Header const &hdr, Ptr<const Packet> packet, |
|
201 ns3::Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> dummy_ipv4, uint32_t interface); |
|
202 |
|
203 void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet); |
|
204 void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet); |
|
205 void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet); |
|
206 |
|
207 void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet); |
|
208 void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet); |
|
209 |
|
210 void TraceNetDevTxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &destination); |
|
211 void TraceNetDevRxWimax (std::string context, Ptr<const Packet> packet, Mac48Address const &source); |
|
212 |
|
213 inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface); |
|
214 |
|
215 void DoPause (std::string const &message); |
|
216 |
|
217 bool m_stop; |
|
218 EventId m_stopCallbackEvent; |
|
219 void CallbackStopSimulation (); |
|
220 }; |
|
221 |
|
222 |
|
223 } |
|
224 |
|
225 #endif /* NS3_PYVIZ_H */ |