//=========================================================================== // @(#) $Name: arts++-1-1-a12 $ // @(#) $Id: ArtsNetMatrixEntry.hh,v 1.2 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 _ArtsNetMatrixEntry_HH_ #define _ArtsNetMatrixEntry_HH_ extern "C" { #include "artslocal.h" #include #include "caida_t.h" } #ifdef HAVE_IOSTREAM #include #else #include #endif #ifdef HAVE_IOMANIP #include #else #include #endif //--------------------------------------------------------------------------- // class ArtsNetMatrixEntry //--------------------------------------------------------------------------- //! Class representing a single net matrix entry. This class holds a //! source net number, a destination net number, and the packets and bytes //! sent from the source net to the destination net. //--------------------------------------------------------------------------- class ArtsNetMatrixEntry { public: //------------------------------------------------------------------------- // ArtsNetMatrixEntry() //......................................................................... //! constructor //------------------------------------------------------------------------- ArtsNetMatrixEntry(); //-------------------------------------------------------------------------- // ArtsNetMatrixEntry(const ArtsNetMatrixEntry & asmEntry) //.......................................................................... //! copy constructor //-------------------------------------------------------------------------- ArtsNetMatrixEntry(const ArtsNetMatrixEntry & asmEntry); //-------------------------------------------------------------------------- // ~ArtsNetMatrixEntry() //.......................................................................... //! destructor //-------------------------------------------------------------------------- ~ArtsNetMatrixEntry(); //------------------------------------------------------------------------- // inline uint16_t Descriptor() const //......................................................................... //! Returns the descriptor field of the object. The descriptor field //! is a bitfield containing indicators of the length of the Src(), Dst(), //! Pkts() and Bytes() fields when stored on disk or sent via a socket. //------------------------------------------------------------------------- inline uint16_t Descriptor() const { return(this->_descriptor); } //------------------------------------------------------------------------- // inline uint16_t Descriptor(uint16_t descriptor) //......................................................................... //! Sets and returns the descriptor field of the object. //------------------------------------------------------------------------- inline uint16_t Descriptor(uint16_t descriptor) { this->_descriptor = descriptor; return(this->_descriptor); } //------------------------------------------------------------------------- // inline ipv4addr_t Src() const //......................................................................... //! Returns the source net number. //------------------------------------------------------------------------- inline ipv4addr_t Src() const { return(this->_src); } //------------------------------------------------------------------------- // uint8_t SrcMaskLen() const //......................................................................... //! Returns the source network mask length. //------------------------------------------------------------------------- uint8_t SrcMaskLen() const; //------------------------------------------------------------------------- // uint8_t SrcMaskLen(uint8_t maskLen) //......................................................................... //! Sets and returns the source network mask length. //------------------------------------------------------------------------- uint8_t SrcMaskLen(uint8_t maskLen); //------------------------------------------------------------------------- // inline ipv4addr_t Src(ipv4addr_t src) //......................................................................... //! Sets and returns the source net number. //------------------------------------------------------------------------- inline ipv4addr_t Src(ipv4addr_t src) { this->_src = src; return(this->_src); } //------------------------------------------------------------------------- // inline ipv4addr_t Dst() const //......................................................................... //! Returns the destination net number. //------------------------------------------------------------------------- inline ipv4addr_t Dst() const { return(this->_dst); } //------------------------------------------------------------------------- // uint8_t DstMaskLen() const //......................................................................... //! Returns the destination network mask length. //------------------------------------------------------------------------- uint8_t DstMaskLen() const; //------------------------------------------------------------------------- // uint8_t DstMaskLen(uint8_t maskLen) //......................................................................... //! Sets and returns the destination network mask length. //------------------------------------------------------------------------- uint8_t DstMaskLen(uint8_t maskLen); //------------------------------------------------------------------------- // inline ipv4addr_t Dst(ipv4addr_t dst) //......................................................................... //! Sets and returns the source net number. //------------------------------------------------------------------------- inline ipv4addr_t Dst(ipv4addr_t dst) { this->_dst = dst; return(this->_dst); } //------------------------------------------------------------------------- // inline uint64_t Pkts() const //......................................................................... //! Returns the number of packets sent from the source net to the //! destination net. //------------------------------------------------------------------------- inline uint64_t Pkts() const { return(this->_pkts); } //------------------------------------------------------------------------- // uint64_t Pkts(uint64_t pkts) //......................................................................... //! Sets and returns the number of packets sent from the source net to the //! destination net. //------------------------------------------------------------------------- uint64_t Pkts(uint64_t pkts); //------------------------------------------------------------------------- // inline uint64_t Bytes() const //......................................................................... //! Returns the number of bytes sent from the source net to the //! destination net. //------------------------------------------------------------------------- inline uint64_t Bytes() const { return(this->_bytes); } //------------------------------------------------------------------------- // uint64_t Bytes(uint64_t bytes) //......................................................................... //! Sets and returns the number of bytes sent from the source net to the //! destination net. //------------------------------------------------------------------------- uint64_t Bytes(uint64_t bytes); //------------------------------------------------------------------------- // uint32_t Length(uint8_t version = 2) const //......................................................................... //! Returns the bytes of space required to store the ArtsNetMatrixEntry //! on disk. //------------------------------------------------------------------------- uint32_t Length(uint8_t version = 2) const; //------------------------------------------------------------------------- // std::istream& read(std::istream& is, uint8_t version = 2) //......................................................................... //! Reads an ArtsNetMatrixEntry from an istream. Returns the istream. //------------------------------------------------------------------------- std::istream& read(std::istream& is, uint8_t version = 2); //------------------------------------------------------------------------- // int read(int fd, uint8_t version = 2) //......................................................................... //! Reads an ArtsNetMatrixEntry from a file descriptor. Returns the //! number of bytes read on success, -1 on failure. //------------------------------------------------------------------------- int read(int fd, uint8_t version = 2); //------------------------------------------------------------------------- // std::ostream& write(std::ostream& os, uint8_t version = 2) const //......................................................................... //! Writes an ArtsNetMatrixEntry to an ostream. Returns the ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os, uint8_t version = 2) const; //------------------------------------------------------------------------- // int write(int fd, uint8_t version = 2) const //......................................................................... //! Writes an ArtsNetMatrixEntry to a file descriptor. Returns the //! number of bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd, uint8_t version = 2) const; //------------------------------------------------------------------------- // std::ostream & operator << (std::ostream& os, // const ArtsNetMatrixEntry & artsNetMatrixEntry) //......................................................................... //! Overloaded '<<' operator to dump the contents of an ArtsNetMatrixEntry //! to an ostream in a human-readable form. Returns the ostream. //------------------------------------------------------------------------- friend std::ostream & operator << (std::ostream& os, const ArtsNetMatrixEntry & artsNetMatrixEntry); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint16_t _descriptor; ipv4addr_t _src; ipv4addr_t _dst; uint64_t _pkts; uint64_t _bytes; static uint32_t _numObjects; }; //--------------------------------------------------------------------------- // class ArtsNetMatrixEntryGreaterBytes //--------------------------------------------------------------------------- //! This class is used as a comparison operator for sorting //! ArtsNetMatrixEntry objects in descending order by bytes of traffic. //--------------------------------------------------------------------------- class ArtsNetMatrixEntryGreaterBytes { public: //--------------------------------------------------------------------------- // bool operator () (const ArtsNetMatrixEntry & netEntry1, // const ArtsNetMatrixEntry & netEntry2) const //........................................................................... // //--------------------------------------------------------------------------- bool operator () (const ArtsNetMatrixEntry & netEntry1, const ArtsNetMatrixEntry & netEntry2) const; }; //--------------------------------------------------------------------------- // class ArtsNetMatrixEntryGreaterPkts //--------------------------------------------------------------------------- //! This class is used as a comparison operator for sorting //! ArtsNetMatrixEntry objects in descending order by packets of traffic. //--------------------------------------------------------------------------- class ArtsNetMatrixEntryGreaterPkts { public: //--------------------------------------------------------------------------- // bool operator () (const ArtsNetMatrixEntry & netEntry1, // const ArtsNetMatrixEntry & netEntry2) const //........................................................................... // //--------------------------------------------------------------------------- bool operator () (const ArtsNetMatrixEntry & netEntry1, const ArtsNetMatrixEntry & netEntry2) const; }; #endif /* _ARTSNETMATRIXENTRY_HH_ */