//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsIpPathEntry.hh,v 1.3 2004/04/21 23:51:27 kkeys Exp $ //=========================================================================== // Copyright Notice // // By accessing this software, arts++, you are duly informed // of and agree to be bound by the conditions described below in this // notice: // // This software product, arts++, is developed by Daniel W. McRobb, and // copyrighted(C) 1998 by the University of California, San Diego // (UCSD), with all rights reserved. UCSD administers the CAIDA grant, // NCR-9711092, under which part of this code was developed. // // There is no charge for arts++ software. You can redistribute it // and/or modify it under the terms of the GNU Lesser General Public // License, Version 2.1, February 1999, which is incorporated by // reference herein. // // arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use // of it will not infringe on any third party's intellectual // property rights. // // You should have received a copy of the GNU Lesser General Public // License along with arts++. Copies can also be obtained from: // // http://www.gnu.org/copyleft/lesser.html // // or by writing to: // // Free Software Foundation, Inc. // 59 Temple Place, Suite 330 // Boston, MA 02111-1307 // USA // // Or contact: // // info@caida.org //=========================================================================== #ifndef _ARTSIPPATHENTRY_HH_ #define _ARTSIPPATHENTRY_HH_ extern "C" { #include "artslocal.h" #include #include #include #include "caida_t.h" } #ifdef HAVE_IOSTREAM #include #else #include #endif #ifdef HAVE_IOMANIP #include #else #include #endif //---------------------------------------------------------------------------- // class ArtsIpPathEntry //---------------------------------------------------------------------------- //! This class represents a single entry in a forward IP path. It //! contains the IP address of a hop and the hop number of the hop //! (hop distance from the source). //---------------------------------------------------------------------------- class ArtsIpPathEntry { public: // Flags for determining output format. static const uint8_t k_none = 0; static const uint8_t k_rtt = 1; //------------------------------------------------------------------------- // ArtsIpPathEntry(ipv4addr_t ipAddr) //......................................................................... //! constructor accepting an IP address. //------------------------------------------------------------------------- ArtsIpPathEntry(ipv4addr_t ipAddr); //------------------------------------------------------------------------- // ArtsIpPathEntry(ipv4addr_t ipAddr, uint8_t hopNum) //......................................................................... //! constructor accepting an IP address and hop number. //------------------------------------------------------------------------- ArtsIpPathEntry(ipv4addr_t ipAddr, uint8_t hopNum); //------------------------------------------------------------------------- // operator = (const ArtsIpPathEntry& artsIpPathEntry) //......................................................................... //! overloaded '=' operator for deep-copying an ArtsIpPathEntry. //------------------------------------------------------------------------- ArtsIpPathEntry & operator = (const ArtsIpPathEntry& artsIpPathEntry); //------------------------------------------------------------------------- // ArtsIpPathEntry() //......................................................................... //! default constructor //------------------------------------------------------------------------- ArtsIpPathEntry(); //------------------------------------------------------------------------- // ~ArtsIpPathEntry() //......................................................................... //! destructor //------------------------------------------------------------------------- ~ArtsIpPathEntry(); //------------------------------------------------------------------------- // inline void IpAddr(ipv4addr_t ipAddr) //......................................................................... //! Sets and returns the IP address of an IP path entry. //------------------------------------------------------------------------- inline void IpAddr(ipv4addr_t ipAddr) { _ipAddr = ipAddr; return; } //------------------------------------------------------------------------- // inline ipv4addr_t IpAddr() const //......................................................................... //! Returns the IP address of an IP path entry. //------------------------------------------------------------------------- inline ipv4addr_t IpAddr() const { return(_ipAddr); } inline const struct timeval Rtt() const { struct timeval rtt; rtt.tv_sec = _rtt / 1000000; rtt.tv_usec = _rtt % 1000000; return rtt; } inline const struct timeval Rtt(const struct timeval & rtt) { _rtt = rtt.tv_sec * 1000000 + rtt.tv_usec; return rtt; } //-------------------------------------------------------------------------- // inline uint8_t NumTries() const //.......................................................................... // //-------------------------------------------------------------------------- inline uint8_t NumTries() const { return(this->_numTries); } //-------------------------------------------------------------------------- // inline uint8_t NumTries(uint8_t numTries) //.......................................................................... // //-------------------------------------------------------------------------- inline uint8_t NumTries(uint8_t numTries) { this->_numTries = numTries; return(this->_numTries); } //------------------------------------------------------------------------- // Returns the bytes required to store the IP path entry in a file in // ARTS format. //------------------------------------------------------------------------- inline uint32_t Length(uint8_t version = 0, uint8_t flags = 0) const { uint32_t len = sizeof(this->_hopNum) + sizeof(this->_ipAddr); if (version >= 1) { if (version == 1 || flags & k_rtt) { len += sizeof(_rtt); len += sizeof(this->_numTries); } } return(len); } //------------------------------------------------------------------------- // inline bool operator < (const ArtsIpPathEntry& artsIpPathEntry) const //......................................................................... //! Overloaded '<' operator. Compares by hop number, can be used for //! sorting path into ascending hop numbers. //------------------------------------------------------------------------- inline bool operator < (const ArtsIpPathEntry& artsIpPathEntry) const { return(this->_hopNum < artsIpPathEntry.HopNum()); } //------------------------------------------------------------------------- // inline bool operator > (const ArtsIpPathEntry& artsIpPathEntry) const //......................................................................... //! Overloaded '>' operator. Compares by hop number, can be used for //! sorting path into ascending hop numbers. //------------------------------------------------------------------------- inline bool operator > (const ArtsIpPathEntry& artsIpPathEntry) const { return(this->_hopNum > artsIpPathEntry.HopNum()); } //------------------------------------------------------------------------- // inline bool operator == (const ArtsIpPathEntry& artsIpPathEntry) const //......................................................................... //! Overloaded '==' operator. Compares by hop IP address only (does //! not use hop number in comparison). //------------------------------------------------------------------------- inline bool operator == (const ArtsIpPathEntry& artsIpPathEntry) const { return(this->_ipAddr == artsIpPathEntry.IpAddr()); } //------------------------------------------------------------------------- // Reads an IP path entry from an istream. //------------------------------------------------------------------------- std::istream& read(std::istream& is, uint8_t version = 0, uint8_t flags = 0); //------------------------------------------------------------------------- // Reads an IP path entry from a file descriptor. //------------------------------------------------------------------------- int read(int fd, uint8_t version = 0, uint8_t flags = 0); // UNTESTED //------------------------------------------------------------------------- // Writes an IP path entry to an ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os, uint8_t version = 0, uint8_t flags = 0) const; //------------------------------------------------------------------------- // Writes an IP path entry to a file descriptor. Returns the number of // bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd, uint8_t version = 0, uint8_t flags = 0) const; //------------------------------------------------------------------------- // inline uint8_t HopNum() //......................................................................... //! Returns the hop number of the IP path entry. //------------------------------------------------------------------------- inline uint8_t HopNum() const { return(_hopNum); } //------------------------------------------------------------------------- // inline void HopNum(uint8_t hopNum) //......................................................................... //! Sets the hop number of the IP path entry. //------------------------------------------------------------------------- inline void HopNum(uint8_t hopNum) { _hopNum = hopNum; return; } //------------------------------------------------------------------------- // friend std::ostream& operator << (std::ostream& os, // const ArtsIpPathEntry& artsIpPathEntry) //......................................................................... //! overloaded '<<' operator for dumping human-readable version of IP //! path entry to an ostream. //------------------------------------------------------------------------- friend std::ostream& operator << (std::ostream& os, const ArtsIpPathEntry& artsIpPathEntry); //-------------------------------------------------------------------------- // void Clear() //.......................................................................... // //-------------------------------------------------------------------------- void Clear(); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint32_t _rtt; ipv4addr_t _ipAddr; uint8_t _hopNum; uint8_t _numTries; static uint32_t _numObjects; }; //--------------------------------------------------------------------------- // class ArtsIpPathEntryLessByHopNumber //--------------------------------------------------------------------------- //! Just a function class used in STL set operations and the like; returns //! true if hopA's hop number is less than hop B's hop number, else //! returns false. //--------------------------------------------------------------------------- class ArtsIpPathEntryLessByHopNumber { public: bool operator()(const ArtsIpPathEntry & hopA, const ArtsIpPathEntry & hopB) { if (hopA.HopNum() < hopB.HopNum()) return(true); else return(false); } }; #endif /* _ARTSIPPATHENTRY_HH_ */