//=========================================================================== // @(#) $Name: arts++-1-1-a12 $ // @(#) $Id: ArtsIpPathData.hh,v 1.7 2004/05/26 20:02:19 youngh 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 _ARTSIPPATHDATA_HH_ #define _ARTSIPPATHDATA_HH_ extern "C" { #include #include "caida_t.h" } #include #include "ArtsIpPathEntry.hh" //---------------------------------------------------------------------------- // class ArtsIpPathData //---------------------------------------------------------------------------- //! This class encapsulates the data for a forward IP path. It includes //! the IP address of hops and the RTT from the source to the final //! destination. //---------------------------------------------------------------------------- class ArtsIpPathData { public: // Constants used in _haltReason static const uint8_t k_noHalt = 0x00; static const uint8_t k_icmpUnreachable = 0x01; static const uint8_t k_accessDenied = k_icmpUnreachable; static const uint8_t k_loopDetected = 0x02; static const uint8_t k_gapLimitExceeded = 0x03; static const uint8_t k_ttlLimit = k_gapLimitExceeded; //------------------------------------------------------------------------ // ArtsIpPathData(ipv4addr_t src, ipv4addr_t dst) //........................................................................ //! constructor //------------------------------------------------------------------------ ArtsIpPathData(ipv4addr_t src, ipv4addr_t dst); //------------------------------------------------------------------------- // ArtsIpPathData(const ArtsIpPathData & artsIpPathData) //......................................................................... //! copy constructor //------------------------------------------------------------------------- ArtsIpPathData(const ArtsIpPathData & artsIpPathData); //------------------------------------------------------------------------ // ArtsIpPathData() //........................................................................ //! default constructor //------------------------------------------------------------------------ ArtsIpPathData(); //------------------------------------------------------------------------ // ~ArtsIpPathData() //........................................................................ //! destructor //------------------------------------------------------------------------ ~ArtsIpPathData(); //------------------------------------------------------------------------- // Writes IP path data to an ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os, uint8_t version = 0, uint8_t flags = 0); //------------------------------------------------------------------------- // Writes IP path data 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); //------------------------------------------------------------------------- // Reads IP path data from an istream. //------------------------------------------------------------------------- std::istream& read(std::istream& is, uint8_t version = 0, uint8_t flags = 0); //------------------------------------------------------------------------- // UNTESTED //------------------------------------------------------------------------- int read(int fd, uint8_t version = 0, uint8_t flags = 0); // UNTESTED //------------------------------------------------------------------------- // inline ipv4addr_t Src() const //......................................................................... //! Returns the source address of the IP path. //------------------------------------------------------------------------- inline ipv4addr_t Src() const { return(this->_src); } //------------------------------------------------------------------------- // inline ipv4addr_t Src(ipv4addr_t src) //......................................................................... //! Sets and returns the source address of the IP path. //------------------------------------------------------------------------- inline ipv4addr_t Src(ipv4addr_t src) { this->_src = src; return(this->_src); } //------------------------------------------------------------------------- // inline ipv4addr_t Dst() const //......................................................................... //! Returns the path destination IP address. //------------------------------------------------------------------------- inline ipv4addr_t Dst() const { return(this->_dst); } //------------------------------------------------------------------------- // inline ipv4addr_t Dst(ipv4addr_t dst) //......................................................................... //! Sets and returns the path destination IP address. //------------------------------------------------------------------------- inline ipv4addr_t Dst(ipv4addr_t dst) { this->_dst = dst; return(this->_dst); } //------------------------------------------------------------------------- // inline uint32_t ListId() const //......................................................................... //! Returns the ID of the destination list to which this trace belongs. //------------------------------------------------------------------------- inline uint32_t ListId() const { return(this->_listId); } //------------------------------------------------------------------------- // inline uint32_t ListId(uint32_t id) //......................................................................... //! Sets and returns the destination list ID. //------------------------------------------------------------------------- inline uint32_t ListId(uint32_t id) { this->_listId = id; return(this->_listId); } //------------------------------------------------------------------------- // inline uint32_t CycleId() const //......................................................................... //! Returns the ID (timestamp) of the cycle on which this trace was taken. //------------------------------------------------------------------------- inline uint32_t CycleId() const { return(this->_cycleId); } //------------------------------------------------------------------------- // inline uint32_t CycleId(uint32_t id) //......................................................................... //! Sets and returns the cycle ID (timestamp). //------------------------------------------------------------------------- inline uint32_t CycleId(uint32_t id) { this->_cycleId = id; return(this->_cycleId); } //------------------------------------------------------------------------- // Returns the round-trip time from the source to the destination and back. //------------------------------------------------------------------------- inline const struct timeval Rtt() const { struct timeval rtt; rtt.tv_sec = _rtt / 1000000; rtt.tv_usec = _rtt % 1000000; return rtt; } //------------------------------------------------------------------------- // Sets and returns the round-trip time from the source to the // destination and back. //------------------------------------------------------------------------- inline const struct timeval Rtt(const struct timeval & rtt) { _rtt = rtt.tv_sec * 1000000 + rtt.tv_usec; return rtt; } //------------------------------------------------------------------------- // inline uint8_t HopDistance() const //......................................................................... //! Returns the hop distance from the source to the destination. //------------------------------------------------------------------------- inline uint8_t HopDistance() const { return(this->_hopDistance); } //------------------------------------------------------------------------- // inline uint8_t HopDistance(uint8_t hopDistance) //......................................................................... //! Sets and returns the hop distance from the source to the destination. //------------------------------------------------------------------------- inline uint8_t HopDistance(uint8_t hopDistance) { this->_hopDistance = hopDistance; return(this->_hopDistance); } //------------------------------------------------------------------------- // inline uint8_t DestinationReplied() const //......................................................................... //! Returns 1 if destination is reached, else returns 0. //------------------------------------------------------------------------- inline uint8_t DestinationReplied() const { return _destinationReplied; } //------------------------------------------------------------------------- // inline uint8_t DestinationReplied(uint8_t destinationReplied) //......................................................................... //! Sets and returns destination reply indicator. //------------------------------------------------------------------------- inline uint8_t DestinationReplied(uint8_t destinationReplied) { return _destinationReplied = destinationReplied; } //-------------------------------------------------------------------------- // inline uint8_t HaltReason() const //.......................................................................... //! Returns the reason that incremental probing was halted. //-------------------------------------------------------------------------- inline uint8_t HaltReason() const { return _haltReason; } //-------------------------------------------------------------------------- // inline uint8_t HaltReason(uint8_t haltReason) //.......................................................................... //! Sets and returns the reason for the incomplete path. //-------------------------------------------------------------------------- inline uint8_t HaltReason(uint8_t haltReason) { return _haltReason = haltReason; } inline uint8_t HaltReasonData() const { return _haltReasonData; } inline uint8_t HaltReasonData(uint8_t haltReasonData) { return _haltReasonData = haltReasonData; } //-------------------------------------------------------------------------- // uint8_t LoopLength() const //.......................................................................... // If HaltReason() is k_loopDetected, returns the length of the routing // loop that caused the path to be truncated. Else returns 0. //-------------------------------------------------------------------------- uint8_t LoopLength() const; //-------------------------------------------------------------------------- // uint8_t LoopLength(uint8_t loopLength) //.......................................................................... // Sets and returns the length of the routing loop (number of hops) for // a halted path probe. Automatically calls HaltReason(k_loopDetected). //-------------------------------------------------------------------------- uint8_t LoopLength(uint8_t loopLength); //-------------------------------------------------------------------------- // uint8_t GapLimit() const //.......................................................................... // If HaltReason() is k_gapLimitExceeded, returns the gap limit that was // reached before the probes were halted. Else returns 0. //-------------------------------------------------------------------------- uint8_t GapLimit() const; //-------------------------------------------------------------------------- // uint8_t GapLimit(uint8_t gapLimit) //.......................................................................... // Sets and returns the probe gap limit for a halted path probe. // Automatically calls HaltReason(k_gapLimitExceeded). //-------------------------------------------------------------------------- uint8_t GapLimit(uint8_t gapLimit); uint8_t IcmpCode() const; uint8_t IcmpCode(uint8_t icmpCode); //------------------------------------------------------------------------- // inline uint8_t NumHops() const //......................................................................... //! Returns the number of hops stored in the path vector. //------------------------------------------------------------------------- inline uint8_t NumHops() const { return(this->_numHops); } //------------------------------------------------------------------------- // inline uint8_t NumHops(uint8_t numHops) //......................................................................... //! Sets and returns the number of hops stored in the path vector. //------------------------------------------------------------------------- inline uint8_t NumHops(uint8_t numHops) { this->_numHops = numHops; return(this->_numHops); } inline uint8_t ReplyTtl() const { return _replyTtl; } inline uint8_t ReplyTtl(uint8_t replyTtl) { return _replyTtl = replyTtl; } //------------------------------------------------------------------------- // inline std::vector & Path() const //......................................................................... //! Returns a reference to the path vector. //------------------------------------------------------------------------- inline std::vector & Path() const { return(this->_path); } //------------------------------------------------------------------------- // bool Distinguishable(const std::vector & ipPath) const //......................................................................... //! Returns true if this->_path is distinguishable from ipPath //! (i.e. for one or more hop numbers, the IP addresses don't match). //! Else returns false. //------------------------------------------------------------------------- bool Distinguishable(const std::vector & ipPath) const; //------------------------------------------------------------------------- // bool Distinguishable(const ArtsIpPathData & ipPathData) const //......................................................................... //! Compares the hop vectors (using //! this->Distinguishable(ipPathData.Path()), the source IP addresses, //! the destination IP address, and the hop distance (if both paths //! are complete) of this and ipPathData. If the paths are //! distinguishable by any of these values, we return true, else we //! return false. //------------------------------------------------------------------------- bool Distinguishable(const ArtsIpPathData & ipPathData) const; //------------------------------------------------------------------------- // void MergeWithPath(const std::vector & ipPath, // std::vector & mergedPath) const //......................................................................... //! Merges this->_path with ipPath, putting the resulting path in //! mergedPath. //! //! In most cases, this should *ONLY* be called if //! this->Distinguishable(ipPath) returns false; the intended use of //! this function is to take paths with missing hops for the same //! src:dst and use them to fill in missing hops and place the //! resulting 'merged' path in mergedPath. Results are undefined //! if used in any other manner. //------------------------------------------------------------------------- void MergeWithPath(const std::vector & ipPath, std::vector & mergedPath) const; //------------------------------------------------------------------------- // std::vector * HopAddresses() const; //......................................................................... // UNTESTED // // Returns a dynamically allocated vector of the IP addresses in // the path. The caller is responsible for freeing the returned // object. //------------------------------------------------------------------------- std::vector * HopAddresses() const; //------------------------------------------------------------------------- // bool CommonHopAddresses(const std::vector & ipPath, // std::vector & commonHopAddresses) const //......................................................................... // UNTESTED // // Places common IP addresses from this->_path and ipPath into // commonHopAddresses. Returns true if this->_path and ipPath had // some matching IP addresses, else returns false. //------------------------------------------------------------------------- bool CommonHopAddresses(const std::vector & ipPath, std::vector & commonHopAddresses) const; bool CommonHopAddresses(const std::vector & hopAddresses, std::vector & commonHopAddresses) const; //------------------------------------------------------------------------- // bool CommonHops(const std::vector & ipPath, // std::vector & commonHops) const //......................................................................... // NOT IMPLEMENTED //------------------------------------------------------------------------- // bool CommonHops(const std::vector & ipPath, // std::vector & commonHops) const; //AL: //-------------------------------------------------------------------------- // void AddHop(ipv4addr_t ipAddr, uint8_t hopNum, // const struct timeval & rtt, uint8_t numTries) //.......................................................................... //! Appends a hop to the path. Assigns an IP address of ipAddr and //! a hop number of hopNum to the new hop, *and* the number of tries (numTries) //! for this hop, with round-trip time of rtt. //! Note we *always* tack the new hop on the end of the path, and do //! *not* use hopNum to determine the location. //-------------------------------------------------------------------------- void AddHop(ipv4addr_t ipAddr, uint8_t hopNum, const struct timeval & rtt, uint8_t numTries=-1); //------------------------------------------------------------------------- // Returns the number of bytes required to store object contents on disk. //------------------------------------------------------------------------- uint32_t Length(uint8_t version = 0, uint8_t flags = 0) const; //------------------------------------------------------------------------- // ArtsIpPathData & operator = (const ArtsIpPathData & artsIpPathData) //......................................................................... //! Overloaded '=' operator for assigning the value of one //! ArtsIpPathData object to another. //------------------------------------------------------------------------- ArtsIpPathData & operator = (const ArtsIpPathData & artsIpPathData); //------------------------------------------------------------------------- // friend std::ostream& operator << (std::ostream& os, // const ArtsIpPathData & artsIpPathData) //......................................................................... //! Overloaded ostream '<<' operator to print contents of object. //------------------------------------------------------------------------- friend std::ostream& operator << (std::ostream& os, const ArtsIpPathData & artsIpPathData); void Clear(); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG // XXX Backwards compatibility functions inline uint8_t IsComplete() const { return DestinationReplied(); } inline uint8_t IsComplete(uint8_t isComplete) { return DestinationReplied(isComplete); } inline uint8_t IncompleteReason() const { return HaltReason(); } inline uint8_t IncompleteReason(uint8_t incompleteReason) { return HaltReason(incompleteReason); } inline uint8_t TtlLimit() const { return GapLimit(); } inline uint8_t TtlLimit(uint8_t ttlLimit) { return GapLimit(ttlLimit); } private: ipv4addr_t _src; ipv4addr_t _dst; uint32_t _listId; // artsVersion >= 3 uint32_t _cycleId; // artsVersion >= 3; timestamp uint32_t _rtt; uint8_t _hopDistance; uint8_t _destinationReplied; uint8_t _replyTtl; uint8_t _numHops; uint8_t _haltReason; uint8_t _haltReasonData; mutable std::vector _path; static uint32_t _numObjects; }; #endif /* _ARTSIPPATHDATA_HH_ */