Index: src/pgbr/model/monitor/source-destination-pairs-traffic-monitor/model/source-destination-pairs-traffic-monitor.h |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/pgbr/model/monitor/source-destination-pairs-traffic-monitor/model/source-destination-pairs-traffic-monitor.h |
@@ -0,0 +1,461 @@ |
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
+/* |
+ * Copyright (c) Waterford Institute of Technology, 2013, Julien Mineraud, BioFINT. |
+ * |
+ * This program is free software; you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 2 as |
+ * published by the Free Software Foundation; |
+ * |
+ * This program is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with this program; if not, write to the Free Software |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
+ * |
+ * Author: Julien Mineraud <julien.mineraud@gmail.com> |
+ * |
+ * Acknowledgements: |
+ * This work has received support from Science Foundation Ireland via the |
+ * "A Biologically inspired framework supporting network management for |
+ * the Future Internet" starting investigator award (grant no. 09/SIRG/I1643). |
+ */ |
+ |
+#include "ns3/object.h" |
+#include "ns3/nstime.h" |
+#include "ns3/ipv4-header.h" |
+#include "ns3/packet.h" |
+#include "ns3/ipv4-l3-protocol.h" |
+#include "ns3/event-id.h" |
+#include "ns3/simulator.h" |
+#include <deque> |
+ |
+#ifndef SOURCE_DESTINATION_PAIRS_TRAFFIC_MONITOR_H_ |
+#define SOURCE_DESTINATION_PAIRS_TRAFFIC_MONITOR_H_ |
+ |
+/*! |
+ * \namespace ns3::pgbr |
+ * Namespace regrouping all objects and functions to run PGBR. |
+ */ |
+namespace ns3 { |
+namespace pgbr { |
+ |
+/*! |
+ * \class SourceDestinationPairsTrafficMonitorPacketTag |
+ * This class is used to tag the packets for collecting results |
+ * The class is a modified version of ns3::Ipv4FlowProbeTag |
+ */ |
+class SourceDestinationPairsTrafficMonitorPacketTag : public Tag |
+{ |
+public: |
+ /*! |
+ * \brief Static function that is required for each ns3::Object. |
+ * |
+ * \fn static TypeId GetTypeId (void) |
+ * \sa ns3::Object::GetTypeId () |
+ * \return the TypeId corresponding to the monitor |
+ */ |
+ static TypeId GetTypeId (void); |
+ |
+ /*! |
+ * \brief Return the current instance type id |
+ * |
+ * \fn virtual TypeId GetInstanceTypeId (void) const |
+ * \sa ns3::Object::GetTypeId () |
+ * \return the TypeId corresponding to the packet tag |
+ */ |
+ virtual TypeId GetInstanceTypeId (void) const; |
+ |
+ /*! |
+ * \brief Return the serialised size of the tag |
+ * |
+ * \fn virtual uint32_t GetSerializedSize (void) const |
+ * \sa ns3::Tag::GetSerializedSize () |
+ * \return the serialised size of the tag |
+ */ |
+ virtual uint32_t GetSerializedSize (void) const; |
+ |
+ /*! |
+ * \brief Serialised the tag to a buffer |
+ * |
+ * \fn virtual void Serialize (TagBuffer buf) const |
+ * \param[in,out] buf the buffer |
+ */ |
+ virtual void Serialize (TagBuffer buf) const; |
+ |
+ /*! |
+ * \brief Deserialised the tag from a buffer |
+ * |
+ * \fn virtual void Deserialize (TagBuffer buf) const |
+ * \param[in,out] buf the buffer |
+ */ |
+ virtual void Deserialize (TagBuffer buf); |
+ |
+ /*! |
+ * \brief Print the tag to an output stream |
+ * |
+ * \fn virtual void Print (std::ostream &os) const |
+ * \param[in,out] os the output stream |
+ */ |
+ virtual void Print (std::ostream &os) const; |
+ |
+ /*! |
+ * The default constructor |
+ */ |
+ SourceDestinationPairsTrafficMonitorPacketTag (); |
+ |
+ /*! |
+ * Another constructor |
+ * \param[in] packetId the packet id |
+ * \param[in] packetSize the packet size |
+ */ |
+ SourceDestinationPairsTrafficMonitorPacketTag (uint64_t packetId, uint32_t packetSize); |
+ |
+ /*! |
+ * \brief Set the packet id |
+ * |
+ * \fn void SetPacketId (uint64_t packetId) |
+ * \param[in] packetId the packet id |
+ */ |
+ void SetPacketId (uint64_t packetId); |
+ |
+ /*! |
+ * \brief Set the packet size |
+ * |
+ * \fn void SetPacketSize (uint32_t packetSize) |
+ * \param[in] packetSize the packet size |
+ */ |
+ void SetPacketSize (uint32_t packetSize); |
+ |
+ /*! |
+ * \brief Get the packet id |
+ * |
+ * \fn uint64_t GetPacketId (void) const |
+ * \return the packet id |
+ */ |
+ uint64_t GetPacketId (void) const; |
+ |
+ /*! |
+ * \brief Get the packet size |
+ * |
+ * \fn uint32_t GetPacketSize (void) const |
+ * \return the packet size |
+ */ |
+ uint32_t GetPacketSize (void) const; |
+ |
+private: |
+ uint64_t m_packetId; /*!< The packet id */ |
+ uint32_t m_packetSize; /*!< The packet size */ |
+}; |
+ |
+/*! |
+ * \class PacketClassifier |
+ * This is just collecting intermediate results. |
+ * We just care about delay, txPackets, txBytes, rxPackets, rxBytes, lostPackets, lostBytes. |
+ * per interval of time defined by the collecting results. |
+ * I have to make sure that the lostPackets counter increments the intermediate zone where the packet was issued. |
+ * So packet loss ratio would be relevant. |
+ * Later on, I would like to have the possibility to collect between source and destination pairs |
+ * The class is a modified version of ns3::FlowClassifier |
+ */ |
+class PacketClassifier |
+{ |
+ |
+public: |
+ |
+ /*! |
+ * \enum Type |
+ * \brief Packet types |
+ * |
+ * Type is an enumeration of predefined constant for describing the type of messages that would be handled by the classifier. |
+ */ |
+ enum Type { |
+ UNTRACKED, /*!< Untracked packet */ |
+ TRACKED_DATA, /*!< Data packet */ |
+ TRACKED_ROUTING /*!< Routing packet */ |
+ }; |
+ |
+ /*! |
+ * The virtual destructor |
+ */ |
+ virtual ~PacketClassifier (); |
+ |
+ /*! |
+ * Abstract function that returns the packet class using the ipv4 header and the packet |
+ * |
+ * \fn virtual Type GetPacketClass (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload) = 0 |
+ * \param[in] ipHeader the ipv4 header |
+ * \param[in] ipPayload the packet |
+ * \return the class of the packet |
+ */ |
+ virtual Type GetPacketClass (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload) = 0; |
+}; |
+ |
+/*! |
+ * \class DefaultPacketClassifier |
+ * \brief Default implementation of a packet classifier |
+ */ |
+class DefaultPacketClassifier : public PacketClassifier |
+{ |
+public: |
+ |
+ /*! |
+ * Function that returns the packet class using the ipv4 header and the packet (by default uses the source or destination ports) |
+ * |
+ * \fn virtual Type GetPacketClass (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload) |
+ * \param[in] ipHeader the ipv4 header |
+ * \param[in] ipPayload the packet |
+ * \return the class of the packet |
+ */ |
+ virtual Type GetPacketClass (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload); |
+}; |
+ |
+/*! |
+ * \class SourceDestinationPairsTrafficMonitor |
+ * |
+ * This is just collecting intermediate results. |
+ * We just care about delay, txPackets, txBytes, rxPackets, rxBytes, lostPackets, lostBytes. |
+ * per interval of time defined by the collecting results. |
+ * The monitor can watch separate source/destination pairs |
+ * TODO I have to make sure that the lostPackets counter increments the intermediate zone where the packet was issued. So packet loss ratio would be relevant. |
+ */ |
+class SourceDestinationPairsTrafficMonitor : public Object |
+{ |
+public: |
+ |
+ /*! |
+ * \brief Static function that is required for each ns3::Object. |
+ * |
+ * \fn static TypeId GetTypeId (void) |
+ * \sa ns3::Object::GetTypeId () |
+ * \return the TypeId corresponding to the monitor |
+ */ |
+ static TypeId GetTypeId (); |
+ |
+ /*! |
+ * \brief Return the current instance type id |
+ * |
+ * \fn virtual TypeId GetInstanceTypeId (void) const |
+ * \sa ns3::Object::GetTypeId () |
+ * \return the TypeId corresponding to the monitor |
+ */ |
+ TypeId GetInstanceTypeId () const; |
+ |
+ /*! |
+ * The constructor |
+ */ |
+ SourceDestinationPairsTrafficMonitor (); |
+ |
+ /*! |
+ * The constructor |
+ */ |
+ virtual ~SourceDestinationPairsTrafficMonitor (); |
+ |
+ |
+ /*! |
+ * Start monitoring at a specific time |
+ * |
+ * \fn void Start (const Time &time) |
+ * \param[in] time the time |
+ */ |
+ void Start (const Time &time); |
+ |
+ /*! |
+ * Stop monitoring at a specific time |
+ * |
+ * \fn void Stop (const Time &time) |
+ * \param[in] time the time |
+ */ |
+ void Stop (const Time &time); |
+ |
+ /*! |
+ * Start monitoring |
+ * |
+ * \fn void StartRightNow () |
+ */ |
+ void StartRightNow (); |
+ |
+ /*! |
+ * Stop monitoring |
+ * |
+ * \fn void StopRightNow () |
+ */ |
+ void StopRightNow (); |
+ |
+ |
+ /*! |
+ * Monitor traffic between specific source and destination |
+ * |
+ * \fn void AddSdpToWatch (Ptr<const Node> src, Ptr<const Node> dst) |
+ * \param[in] src the source node |
+ * \param[in] dst the destination node |
+ */ |
+ void AddSdpToWatch (Ptr<const Node> src, Ptr<const Node> dst); |
+ |
+ /*! |
+ * Serialize the results to the output stream. The choice was made to collect the results in an ASCII format, with fields separated with tabs. |
+ * |
+ * \fn void SerializeToStream (Ptr<OutputStreamWrapper> stream, bool sdp) |
+ * \param[in,out] stream the output stream |
+ * \param[in] sdp true separate the traffic depending on different source/destination pairs |
+ */ |
+ void SerializeToStream (Ptr<OutputStreamWrapper> stream, bool serializeSdp); |
+ |
+ |
+protected: |
+ |
+ /*! |
+ * \brief once the object monitor is constructed, it will start the periodical check for lost packets |
+ * \fn virtual void NotifyConstructionCompleted |
+ */ |
+ virtual void NotifyConstructionCompleted (); |
+ |
+private: |
+ |
+ /*! |
+ * \brief Connect to the ns3::Ipv4L3Protocol traces to monitor packet transmissions, receptions and drops |
+ * \fn void ConnectToTraces () |
+ */ |
+ void ConnectToTraces (); |
+ |
+ /*! |
+ * This function is called for the first transmitted packets |
+ * \fn void ReportFirstTx (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface) |
+ * \param[in] ipHeader the ns3::Ipv4Header of the first packet transmitted |
+ * \param[in] ipPayload the ns3::Packet |
+ * \param[in] interface the interface on which the packet has been transmitted |
+ */ |
+ void ReportFirstTx (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface); |
+ |
+ /*! |
+ * This function is called for the last transmitted packets |
+ * \fn void ReportLastRx (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface) |
+ * \param[in] ipHeader the ns3::Ipv4Header of the last packet transmitted |
+ * \param[in] ipPayload the ns3::Packet |
+ * \param[in] interface the interface on which the packet has been transmitted |
+ */ |
+ void ReportLastRx (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface); |
+ |
+ /*! |
+ * This function is called when a packet is dropped by the ns3::Ipv4L3Protocol |
+ * \fn void ReportIpv4L3ProtocolDrop (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> ipv4, uint32_t ifIndex) |
+ * \param[in] ipHeader the ns3::Ipv4Header of the last packet dropped |
+ * \param[in] ipPayload the ns3::Packet |
+ * \param[in] reason THe reason of the drop |
+ * \param[in] ipv4 The ipv4 |
+ * \param[in] ifIndex The interface on which the packet has been dropped |
+ */ |
+ void ReportIpv4L3ProtocolDrop (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, |
+ Ipv4L3Protocol::DropReason reason, Ptr<Ipv4> ipv4, uint32_t ifIndex); |
+ |
+ /*! |
+ * This function is called when a packet is dropped |
+ * \fn void ReportDrop (Ptr<const Packet> ipPayload) |
+ * \param[in] ipPayload the ns3::Packet |
+ */ |
+ void ReportDrop (Ptr<const Packet> ipPayload); |
+ |
+ /*! |
+ * This function returns a valid packet id |
+ * \fn uint64_t GetNextPacketId () |
+ * \return a valid packet id |
+ */ |
+ uint64_t GetNextPacketId (); |
+ |
+ /*! |
+ * Check right now for packets that appear to be lost, considering |
+ * packets as lost if not seen in the network for a time larger |
+ * than maxDelay |
+ * \fn void CheckForLostPackets (Time maxDelay) |
+ * \param[in] maxDelay the maximum delay for a packet to reach the destination. After this delay is passed, the packet will be considered lost |
+ */ |
+ void CheckForLostPackets (Time maxDelay); |
+ |
+ /*! |
+ * This function periodically calls CheckForLostPackets |
+ * \fn void PeriodicCheckForLostPackets () |
+ */ |
+ void PeriodicCheckForLostPackets (); |
+ |
+ /*! |
+ * \struct TrackedPacket |
+ * \brief Structure to keep information about tracked packets |
+ */ |
+ struct TrackedPacket |
+ { |
+ Time firstSeenTime; /*!< absolute time when the packet was first seen by a probe */ |
+ Time lastSeenTime; /*!< absolute time when the packet was last seen by a probe */ |
+ PacketClassifier::Type packetType; /*!< The type of classification */ |
+ uint32_t src; /*!< The source of the packet */ |
+ uint32_t dst; /*!< The destination of the packet */ |
+ bool isLookedSdp; /*!< If the packet is a data packet, then the flag is used if we do care about the source and the destination of the packet */ |
+ }; |
+ |
+ /*! |
+ * \struct IntermediateStats |
+ * \brief Structure to keep intermediate statistics about the monitored packets |
+ */ |
+ struct IntermediateStats |
+ { |
+ Time startCollectionTime; /*!< The starting time of the monitored period */ |
+ Time stopCollectionTime; /*!< The stoping time of the monitored period */ |
+ |
+ uint64_t txDataBytes; /*!< The number of bytes for data packets that have been transmitted so far */ |
+ uint64_t rxDataBytes; /*!< The number of bytes for data packets that have been received so far */ |
+ uint32_t txDataPackets; /*!< The number of data packets that have been transmitted so far */ |
+ uint32_t rxDataPackets; /*!< The number of data packets that have been received so far */ |
+ uint32_t lostDataPackets; /*!< The number data packets that have been dropped/lost so far */ |
+ Time delayDataSum; /*!< The sum of the delay for all data packets that have been received so far */ |
+ |
+ uint64_t txRoutingBytes; /*!< The number of bytes for routing packets that have been transmitted so far */ |
+ uint64_t rxRoutingBytes; /*!< The number of bytes for routing packets that have been received so far */ |
+ uint32_t txRoutingPackets; /*!< The number of data routing that have been transmitted so far */ |
+ uint32_t rxRoutingPackets; /*!< The number of data routing that have been received so far */ |
+ uint32_t lostRoutingPackets; /*!< The number data routing that have been dropped/lost so far */ |
+ Time delayRoutingSum; /*!< The sum of the delay for all routing packets that have been received so far */ |
+ |
+ /*! |
+ * Basic constructor for the IntermediateStats structure |
+ */ |
+ IntermediateStats () : |
+ startCollectionTime (Simulator::Now ()), stopCollectionTime (Simulator::Now ()), |
+ txDataBytes (0), rxDataBytes (0), txDataPackets (0), rxDataPackets (0), lostDataPackets (0), delayDataSum (Seconds (0)), |
+ txRoutingBytes (0), rxRoutingBytes (0), txRoutingPackets (0), rxRoutingPackets (0), lostRoutingPackets (0), delayRoutingSum (Seconds (0)) {} |
+ }; |
+ |
+ std::deque<IntermediateStats> m_intermediateStats; /*!< List of all intermediate statistics */ |
+ IntermediateStats m_currentStats; /*!< The current stats */ |
+ bool m_enabled; /*!< Flag on if the monitor is monitoring */ |
+ |
+ typedef std::map<uint64_t, TrackedPacket> TrackedPacketMap; /*!< Definition of the structure to keep track of packets */ |
+ TrackedPacketMap m_trackedPackets; /*!< Structure to keep track of packets */ |
+ |
+ uint64_t m_packetIdCounter; /*!< counter for packets */ |
+ PacketClassifier *m_packetClassifier; /*!< Pointer to the packet classifier */ |
+ Time m_maxDelay; /*!< The maximum delay packets can reach their destination before being considered lost/dropped */ |
+ Time m_checkPacketLostInterval; /*!< The interval to check for lost packets */ |
+ bool m_lookAtSdp; /*!< Flag is on if we are interesting in the source or destination of packets */ |
+ |
+ typedef std::pair<uint32_t, uint32_t> sdp_t; /*!< Definition of a source and destination pair */ |
+ std::vector<sdp_t> m_sdps; /*!< List of source and destination pairs of packets we are interesting in monitoring */ |
+ std::map<Ipv4Address, uint32_t> m_destAddressMap; /*!< Mapping of ns3::Ipv4Address to nodes id */ |
+ std::map<sdp_t, IntermediateStats> m_sdpCurrentStats; /*!< The current intermediate stats for the source and destination pairs we are interested in monitoring */ |
+ std::map<sdp_t, std::deque<IntermediateStats> > m_sdpIntermediateStats; /*!< The lists of intermediate stats for the source and destination pairs we are interested in monitoring */ |
+ |
+ EventId m_startEvent; /*!< The start event for the monitoring process */ |
+ EventId m_stopEvent; /*!< The stop event for the monitoring process */ |
+ Time m_interval; /*!< The interval of time used to periodically collect statistics */ |
+ |
+ /*! |
+ * This function periodically collects intermediate statistics about packets |
+ * \fn void CollectIntermediateStats () |
+ */ |
+ void CollectIntermediateStats (void); |
+ |
+}; |
+ |
+}} //namespace pgbr, ns3 |
+ |
+#endif /* SOURCE_DESTINATION_PAIRS_TRAFFIC_MONITOR_H_ */ |