Several changes: 1. code cleanup; 2. converged captured packets into a single format (not nice to have wifi with only payload but csma with payload and ethernet header); 3. allow registering new netdevice types for PyViz to handle.
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);
135 bool GetPacketCaptureOptions (uint32_t nodeId, const PacketCaptureOptions **outOptions) const;
136 static bool FilterPacket (Ptr<const Packet> packet, const PacketCaptureOptions &options);
139 typedef std::pair<Ptr<Channel>, uint32_t> TxRecordKey;
148 struct TransmissionSampleKey
150 bool operator < (TransmissionSampleKey const &other) const;
151 bool operator == (TransmissionSampleKey const &other) const;
152 Ptr<Node> transmitter;
153 Ptr<Node> receiver; // NULL if broadcast
154 Ptr<Channel> channel;
157 struct TransmissionSampleValue
163 std::map<uint32_t, PacketCaptureOptions> m_packetCaptureOptions;
164 std::vector<std::string> m_pauseMessages;
165 std::map<TxRecordKey, TxRecordValue> m_txRecords;
166 std::map<TransmissionSampleKey, TransmissionSampleValue> m_transmissionSamples;
167 std::map<Ptr<Node>, uint32_t> m_packetDrops;
168 std::set<uint32_t> m_nodesOfInterest; // list of node IDs whose transmissions will be monitored
169 std::map<uint32_t, Time> m_packetsOfInterest; // list of packet UIDs that will be monitored
170 std::map<uint32_t, LastPacketsSample> m_lastPackets;
171 std::map<uint32_t, std::vector<NetDeviceStatistics> > m_nodesStatistics;
174 void TraceNetDevTxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
175 void TraceNetDevRxWifi (std::string context, Ptr<const Packet> packet, Mac48Address address);
177 void TraceDrop (std::string context, Ptr<const Packet> packet);
179 void TraceNetDevTxCsma (std::string context, Ptr<const Packet> packet);
180 void TraceNetDevRxCsma (std::string context, Ptr<const Packet> packet);
181 void TraceNetDevPromiscRxCsma (std::string context, Ptr<const Packet> packet, NetDevice::PacketType packetType);
183 void TraceNetDevTxPointToPoint (std::string context, Ptr<const Packet> packet);
184 void TraceNetDevRxPointToPoint (std::string context, Ptr<const Packet> packet);
186 inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface);
188 void DoPause (std::string const &message);
191 EventId m_stopCallbackEvent;
192 void CallbackStopSimulation ();
198 #endif /* NS3_PYVIZ_H */