//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsNetMatrixData.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 ARTSNETMATRIXDATA_HH_ #define ARTSNETMATRIXDATA_HH_ extern "C" { #include "caida_t.h" #include "artslocal.h" } #include #ifdef HAVE_IOSTREAM #include #else #include #endif #include "ArtsNetMatrixEntry.hh" //--------------------------------------------------------------------------- // class ArtsNetMatrixData //--------------------------------------------------------------------------- //! This class encapsulates the data portion of an ARTS net matrix object. //! This class is not normally instantiated directly, but instead //! instantiated from the containing object (an Arts or ArtsNetMatrix //! object). //--------------------------------------------------------------------------- class ArtsNetMatrixData { public: //------------------------------------------------------------------------- // ArtsNetMatrixData() //......................................................................... //! constructor //------------------------------------------------------------------------- ArtsNetMatrixData(); //-------------------------------------------------------------------------- // inline ~ArtsNetMatrixData() //.......................................................................... //! destructor //-------------------------------------------------------------------------- ~ArtsNetMatrixData(); //------------------------------------------------------------------------- // inline uint16_t SampleInterval() const //......................................................................... //! Returns the sampling ratio if the net matrix was built using packet //! sampling techniques. Normally this value is 1, meaning we're working //! with complete data sets (for example, from Cisco flow-export). //------------------------------------------------------------------------- inline uint16_t SampleInterval() const { return(this->_sampleInterval); } //------------------------------------------------------------------------- // inline uint16_t SampleInterval(uint16_t sampleInterval) //......................................................................... //! Sets and returns the sampling ratio if the net matrix was built using //! packet sampling techniques. Normally this value is 1, meaning we're //! working with complete data sets (for example, from Cisco flow-export). //------------------------------------------------------------------------- inline uint16_t SampleInterval(uint16_t sampleInterval) { this->_sampleInterval = sampleInterval; return(this->_sampleInterval); } //------------------------------------------------------------------------- // inline uint32_t Count() const //......................................................................... //! Returns the number of net matrix entries (cells) in an //! ArtsNetMatrixData object. //------------------------------------------------------------------------- inline uint32_t Count() const { return(this->_count); } //------------------------------------------------------------------------- // inline uint32_t Count(uint32_t count) //......................................................................... //! Sets and Returns the number of net matrix entries (cells) in an //! ArtsNetMatrixData object. //------------------------------------------------------------------------- inline uint32_t Count(uint32_t count) { this->_count = count; return(this->_count); } //------------------------------------------------------------------------- // inline uint64_t TotalPkts() const //......................................................................... //! Returns the total packets of traffic in the ArtsNetMatrixData object. //! The total is the sum of all traffic from each source to each //! destination. //------------------------------------------------------------------------- inline uint64_t TotalPkts() const { return(this->_totpkts); } //------------------------------------------------------------------------- // inline uint64_t TotalPkts(uint64_t totalPkts) //......................................................................... //! Sets and returns the total packets of traffic in the ArtsNetMatrixData //! object. The total is the sum of all traffic from each source to each //! destination. //------------------------------------------------------------------------- inline uint64_t TotalPkts(uint64_t totalPkts) { this->_totpkts = totalPkts; return(this->_totpkts); } //------------------------------------------------------------------------- // inline uint64_t TotalBytes() const //......................................................................... //! Returns the total bytes of traffic in the ArtsNetMatrixData object. //! The total is the sum of all traffic from each source to each //! destination. //------------------------------------------------------------------------- inline uint64_t TotalBytes() const { return(this->_totbytes); } //------------------------------------------------------------------------- // inline uint64_t TotalBytes(uint64_t totalBytes) //......................................................................... //! Sets and returns the total bytes of traffic in the ArtsNetMatrixData //! object. The total is the sum of all traffic from each source to each //! destination. //------------------------------------------------------------------------- inline uint64_t TotalBytes(uint64_t totalBytes) { this->_totbytes = totalBytes; return(this->_totbytes); } //------------------------------------------------------------------------- // inline uint64_t Orphans() const //......................................................................... // //------------------------------------------------------------------------- inline uint64_t Orphans() const { return(this->_orphans); } //------------------------------------------------------------------------- // inline uint64_t Orphans(uint64_t orphans) //......................................................................... // //------------------------------------------------------------------------- inline uint64_t Orphans(uint64_t orphans) { this->_orphans = orphans; return(this->_orphans); } //------------------------------------------------------------------------- // inline std::vector & NetEntries() const //......................................................................... //! Return a reference to the vector of ArtsNetMatrixEntry objects. Note //! that even though this member may be called from a const object, the //! returned reference is not const; the vector is mutable. //------------------------------------------------------------------------- inline std::vector & NetEntries() const { return(this->_netEntries); } //------------------------------------------------------------------------- // void SortEntriesByBytes() //......................................................................... //! Sorts the net matrix entries by the number of bytes in the net //! entries (the bytes of traffic sent from a source network to a //! destinatino network). //------------------------------------------------------------------------- void SortEntriesByBytes(); //------------------------------------------------------------------------- // void SortEntriesByPkts() //......................................................................... //! Sorts the net matrix entries by the number of packets in the net //! entries (the packets of traffic sent from a source network to a //! destinatino network). //------------------------------------------------------------------------- void SortEntriesByPkts(); //------------------------------------------------------------------------- // uint32_t Length(uint8_t version = 2) const //......................................................................... //! Returns the length required to store the ArtsNetMatrixData object //! on disk. //------------------------------------------------------------------------- uint32_t Length(uint8_t version = 2) const; //------------------------------------------------------------------------- // std::istream& read(std::istream& is, uint8_t version = 2) //......................................................................... //! Reads an ArtsNetMatrixData object 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 ArtsNetMatrixData object from a file descriptor. Returns //! the number of bytes read if successful, -1 on failure. //------------------------------------------------------------------------- int read(int fd, uint8_t version = 2); //------------------------------------------------------------------------- // std::ostream& write(std::ostream& os, uint8_t version = 2) //......................................................................... //! Writes an ArtsNetMatrixData object to an ostream. Returns the //! ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os, uint8_t version = 2); //------------------------------------------------------------------------- // int write(int fd, uint8_t version = 2) //......................................................................... //! Writes an ArtsNetMatrixData object to a file descriptor. Returns //! the number of bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd, uint8_t version = 2); //------------------------------------------------------------------------- // std::ostream& operator << (std::ostream& os, // const ArtsNetMatrixData & artsNetMatrixData) //......................................................................... //! Overloaded '<<' operator. Dumps the contents of an ArtsNetMatrixData //! object to an ostream in a human-readable form. Returns the ostream. //------------------------------------------------------------------------- friend std::ostream& operator << (std::ostream& os, const ArtsNetMatrixData & artsNetMatrixData); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif private: uint16_t _sampleInterval; uint32_t _count; uint64_t _totpkts; uint64_t _totbytes; uint64_t _orphans; mutable std::vector _netEntries; static uint32_t _numObjects; }; #endif /* ARTSNETMATRIXDATA_HH_ */