1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 INESC Porto
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;
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.
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
18 * C++ helper functions for use by the python visualizer (for things
19 * Python is too slow at).
21 * Author: Gustavo Carneiro <gjc@inescporto.pt>
26 #include "ns3/nstime.h"
27 #include "ns3/event-id.h"
29 #include "ns3/channel.h"
30 #include "ns3/packet.h"
31 #include "ns3/mac48-address.h"
43 void RegisterDropTracePath (std::string const &tracePath);
45 void RegisterCsmaLikeDevice (std::string const &deviceTypeName);
46 void RegisterWifiLikeDevice (std::string const &deviceTypeName);
47 void RegisterPointToPointLikeDevice (std::string const &deviceTypeName);
49 // Run simulation until a given (simulated, absolute) time is reached
50 void SimulatorRunUntil (Time time);
52 static void Pause (std::string const &message);
53 std::vector<std::string> GetPauseMessages () const;
55 struct TransmissionSample
57 Ptr<Node> transmitter;
58 Ptr<Node> receiver; // NULL if broadcast
62 typedef std::vector<TransmissionSample> TransmissionSampleList;
63 TransmissionSampleList GetTransmissionSamples () const;
65 struct PacketDropSample
67 Ptr<Node> transmitter;
70 typedef std::vector<PacketDropSample> PacketDropSampleList;
71 PacketDropSampleList GetPacketDropSamples () const;
78 Ptr<NetDevice> device;
80 struct TxPacketSample : PacketSample
84 struct RxPacketSample : PacketSample
89 struct LastPacketsSample
91 std::vector<RxPacketSample> lastReceivedPackets;
92 std::vector<TxPacketSample> lastTransmittedPackets;
93 std::vector<PacketSample> lastDroppedPackets;
95 LastPacketsSample GetLastPackets (uint32_t nodeId) const;
98 void SetNodesOfInterest (std::set<uint32_t> nodes);
100 struct NetDeviceStatistics
102 NetDeviceStatistics () : transmittedBytes (0), receivedBytes (0),
103 transmittedPackets (0), receivedPackets (0) {}
104 uint64_t transmittedBytes;
105 uint64_t receivedBytes;
106 uint32_t transmittedPackets;
107 uint32_t receivedPackets;
110 struct NodeStatistics
113 std::vector<NetDeviceStatistics> statistics;
116 std::vector<NodeStatistics> GetNodesStatistics () const;
118 enum PacketCaptureMode {
119 PACKET_CAPTURE_DISABLED=1, // packet capture is disabled
120 PACKET_CAPTURE_FILTER_HEADERS_OR, // packet capture if any of the indicated headers is present
121 PACKET_CAPTURE_FILTER_HEADERS_AND, // packet capture if all of the indicated headers are present
124 struct PacketCaptureOptions
126 std::set<TypeId> headers;
127 uint32_t numLastPackets;
128 PacketCaptureMode mode;
131 void SetPacketCaptureOptions (uint32_t nodeId, PacketCaptureOptions options);
134 // Yes, I know, this is just a utility function, not really related to the class in any way.
136 // -#- @lineX1(direction=inout); @lineY1(direction=inout); @lineX2(direction=inout); @lineY2(direction=inout) -#-
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 :(
142 bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
143 static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
146 typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
155 struct TransmissionSampleKey
157 bool operator < (TransmissionSampleKey const &other) const;
158 bool operator == (TransmissionSampleKey const &other) const;
159 Ptr<Node> transmitter;
160 Ptr<Node> receiver; // NULL if broadcast
161 Ptr<Channel> channel;
164 struct TransmissionSampleValue
170 std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
171 std::vector<std::string> m_pauseMessages;
172 std::map<TxRecordKey, TxRecordValue> m_txRecords;
173 std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
174 std::map<Ptr<Node>, uint32_t> m_packetDrops;
175 std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored
176 std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored
177 std::map<uint32_t, LastPacketsSample> m_lastPackets;
178 std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
181 void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
182 void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
184 void TraceDrop (std::string context, Ptr<const Packet> packet);
186 void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
187 void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
188 void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet, NetDevice::PacketType packetType);
190 void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
191 void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
193 inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
195 void DoPause (std::string const &message);
198 EventId m_stopCallbackEvent;
199 void CallbackStopSimulation ();
205 #endif /* NS3_PYVIZ_H */