1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2011 Bucknell University 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 * Authors: L. Felipe Perrone (perrone@bucknell.edu) 19 * Tiago G. Rodrigues (tgr002@bucknell.edu) 20 * 21 * Modified by: Mitch Watrous (watrous@u.washington.edu) 22 */ 23 24 #ifndef PACKET_PROBE_H 25 #define PACKET_PROBE_H 26 27 #include "ns3/object.h" 28 #include "ns3/callback.h" 29 #include "ns3/boolean.h" 30 #include "ns3/nstime.h" 31 #include "ns3/packet.h" 32 #include "ns3/traced-value.h" 33 #include "ns3/simulator.h" 34 #include "ns3/probe.h" 35 36 namespace ns3 { 37 38 /** 39 * This class is designed to probe an underlying ns3 TraceSource 40 * exporting a packet. This probe exports a trace source "Output" 41 * with argument of type Ptr<const Packet>. This probe exports 42 * another trace source "OutputBytes" with arguments of type uint32_t, 43 * which is the number of bytes in the packet. The trace sources emit 44 * values when either the probed trace source emits a new value, or 45 * when SetValue () is called. 46 */ 47 class PacketProbe : public Probe 48 { 49 public: 50 /** 51 * \brief Get the type ID. 52 * \return the object TypeId 53 */ 54 static TypeId GetTypeId (); 55 PacketProbe (); 56 virtual ~PacketProbe (); 57 58 /** 59 * \brief Set a probe value 60 * 61 * \param packet set the traced packet equal to this 62 */ 63 void SetValue (Ptr<const Packet> packet); 64 65 /** 66 * \brief Set a probe value by its name in the Config system 67 * 68 * \param path config path to access the probe 69 * \param packet set the traced packet equal to this 70 */ 71 static void SetValueByPath (std::string path, Ptr<const Packet> packet); 72 73 /** 74 * \brief connect to a trace source attribute provided by a given object 75 * 76 * \param traceSource the name of the attribute TraceSource to connect to 77 * \param obj ns3::Object to connect to 78 * \return true if the trace source was successfully connected 79 */ 80 virtual bool ConnectByObject (std::string traceSource, Ptr<Object> obj); 81 82 /** 83 * \brief connect to a trace source provided by a config path 84 * 85 * \param path Config path to bind to 86 * 87 * Note, if an invalid path is provided, the probe will not be connected 88 * to anything. 89 */ 90 virtual void ConnectByPath (std::string path); 91 92 private: 93 /** 94 * \brief Method to connect to an underlying ns3::TraceSource with 95 * arguments of type Ptr<const Packet> 96 * 97 * \param packet the traced packet 98 */ 99 void TraceSink (Ptr<const Packet> packet); 100 101 /// Traced callback: packet received 102 TracedCallback<Ptr<const Packet> > m_output; 103 /// Traced callback: size of previous packet receive, size of actual packet received 104 TracedCallback<uint32_t, uint32_t> m_outputBytes; 105 106 /// The traced packet. 107 Ptr<const Packet> m_packet; 108 109 /// The size of the traced packet. 110 uint32_t m_packetSizeOld; 111 }; 112 113 114 } // namespace ns3 115 116 #endif // PACKET_PROBE_H 117