//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsHeader.hh,v 1.2 2004/04/21 23:51:26 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 _ARTSHEADER_HH_ #define _ARTSHEADER_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 //--------------------------------------------------------------------------- // ARTS file magic number //--------------------------------------------------------------------------- const uint16_t artsC_MAGIC(); #define artsC_MAGIC 0xdfb0 //--------------------------------------------------------------------------- // File Information Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_FILE(); #define artsC_OBJECT_FILE 0x0000001 //--------------------------------------------------------------------------- // Error Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_ERROR(); #define artsC_OBJECT_ERROR 0x0000002 //--------------------------------------------------------------------------- // Net Matrix Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_NET(); #define artsC_OBJECT_NET 0x0000010 //--------------------------------------------------------------------------- // AS Matrix Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_AS_MATRIX(); #define artsC_OBJECT_AS_MATRIX 0x0000011 //--------------------------------------------------------------------------- // Port Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_PORT(); #define artsC_OBJECT_PORT 0x0000020 //--------------------------------------------------------------------------- // Port Matrix Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_PORT_MATRIX(); #define artsC_OBJECT_PORT_MATRIX 0x0000021 //--------------------------------------------------------------------------- // Selected Port Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_SELECTED_PORT(); #define artsC_OBJECT_SELECTED_PORT 0x0000022 //--------------------------------------------------------------------------- // Protocols Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_PROTO(); #define artsC_OBJECT_PROTO 0x0000030 //--------------------------------------------------------------------------- // TOS Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_TOS(); #define artsC_OBJECT_TOS 0x00000031 //--------------------------------------------------------------------------- // Interface Matrix Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_INTERFACE_MATRIX(); #define artsC_OBJECT_INTERFACE_MATRIX 0x00000040 //--------------------------------------------------------------------------- // NextHop Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_NEXT_HOP(); #define artsC_OBJECT_NEXT_HOP 0x00000041 //--------------------------------------------------------------------------- // SNMP Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_SNMP(); #define artsC_OBJECT_SNMP 0x0000100 //--------------------------------------------------------------------------- // SNMP Topology Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_SNMP_TOPO(); #define artsC_OBJECT_SNMP_TOPO 0x0000200 //--------------------------------------------------------------------------- // Usage Reporting Statistical Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_U_R_STAT(); #define artsC_OBJECT_U_R_STAT 0x0000300 //--------------------------------------------------------------------------- // AS Path Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_AS_PATH(); #define artsC_OBJECT_AS_PATH 0x0001000 //--------------------------------------------------------------------------- // rtdata Transaction Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_TRANS(); #define artsC_OBJECT_TRANS 0x0002000 //--------------------------------------------------------------------------- // IP Path Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_IP_PATH(); #define artsC_OBJECT_IP_PATH 0x00003000 //--------------------------------------------------------------------------- // BGP4 Route Table Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_BGP4(); #define artsC_OBJECT_BGP4 0x00004000 //--------------------------------------------------------------------------- // RTT Time Series Object //--------------------------------------------------------------------------- const uint32_t artsC_OBJECT_RTT_TIME_SERIES(); #define artsC_OBJECT_RTT_TIME_SERIES 0x00005000 //--------------------------------------------------------------------------- // class ArtsHeader //--------------------------------------------------------------------------- //! Class to represent header portion of an ARTS data object. All ARTS //! objects contain an ArtsHeader. This class is used to hold //! information generic to ARTS objects: a magic number, an identifier, //! a version number, flags and some length indicators (for both //! attributes and data). //--------------------------------------------------------------------------- class ArtsHeader { public: //------------------------------------------------------------------------- // ArtsHeader() //......................................................................... //! constructor //------------------------------------------------------------------------- ArtsHeader(); //------------------------------------------------------------------------- // ~ArtsHeader() //......................................................................... //! destructor //------------------------------------------------------------------------- ~ArtsHeader(); //------------------------------------------------------------------------- // inline uint16_t Magic() const //......................................................................... //! Returns the magic number in the header. This will return //! artsC_MAGIC if all is well with the object. //------------------------------------------------------------------------- inline uint16_t Magic() const { return(this->_magic); } //------------------------------------------------------------------------- // inline uint16_t Magic(uint16_t magic) //......................................................................... //! Sets and returns the magic number in the header. It should always //! be set to artsC_MAGIC. //------------------------------------------------------------------------- inline uint16_t Magic(uint16_t magic) { this->_magic = magic; return(this->_magic); } //------------------------------------------------------------------------- // inline uint32_t Identifier() const //......................................................................... //! Returns the identifier in the header. The identifier indicates //! what type of ARTS object we have. //------------------------------------------------------------------------- inline uint32_t Identifier() const { return(_identifier); } //------------------------------------------------------------------------- // inline uint32_t Identifier(uint32_t identifier) //......................................................................... //! Sets and returns the identifier in the header. The identifier //! indicates what type of ARTS object we have. //------------------------------------------------------------------------- inline uint32_t Identifier(uint32_t identifier) { this->_identifier = identifier; return(this->_identifier); } //------------------------------------------------------------------------- // const char * IdentifierName() const //......................................................................... //! Returns a string representing the name of the Arts object type //! (a textual description of our Identifier()). If the object type //! is unknown to us, returns a string holding the Identifier() value //! formatted as a hexadecimal ("%#x"). //------------------------------------------------------------------------- const char * IdentifierName() const; //------------------------------------------------------------------------- // inline uint8_t Version() const //......................................................................... //! Returns the object version from the header. ARTS objects of a //! particular type (see Identifier()) may support more than one version, //! typically for different on-disk formats. //------------------------------------------------------------------------- inline uint8_t Version() const { return(this->_version); } //------------------------------------------------------------------------- // inline uint8_t Version(uint8_t version) //......................................................................... //! Sets and returns the object version from the header. ARTS objects of a //! particular type (see Identifier()) may support more than one version, //! typically for different on-disk formats. //------------------------------------------------------------------------- inline uint8_t Version(uint8_t version) { this->_version = version; return(this->_version); } //------------------------------------------------------------------------- // inline uint32_t Flags() const //......................................................................... //! Returns the object flags from the header. Flags are used in a //! manner specific to the type of ARTS object. //------------------------------------------------------------------------- inline uint32_t Flags() const { return(this->_flags); } //------------------------------------------------------------------------- // inline uint32_t Flags(uint32_t flags) //......................................................................... //! Sets and returns the object flags from the header. Flags are used in //! a manner specific to the type of ARTS object. //------------------------------------------------------------------------- inline uint32_t Flags(uint32_t flags) { this->_flags = flags; return(this->_flags); } //------------------------------------------------------------------------- // inline uint16_t NumAttributes() const //......................................................................... //! Returns the number of attributes in the ARTS object. //------------------------------------------------------------------------- inline uint16_t NumAttributes() const { return(this->_numAttributes); } //------------------------------------------------------------------------- // inline uint16_t NumAttributes(uint16_t numAttributes) //......................................................................... //! Sets and returns the number of attributes in the ARTS object. //------------------------------------------------------------------------- inline uint16_t NumAttributes(uint16_t numAttributes) { this->_numAttributes = numAttributes; return(this->_numAttributes); } //------------------------------------------------------------------------- // inline uint32_t AttrLength() const //......................................................................... //! Returns the length of the attributes in the ARTS object (bytes used //! to store attributes on disk). //------------------------------------------------------------------------- inline uint32_t AttrLength() const { return(this->_attrLength); } //------------------------------------------------------------------------- // inline uint32_t AttrLength(uint32_t attrLength) //......................................................................... //! Sets and returns the length of the attributes in the ARTS object //! (bytes used to store attributes on disk). //------------------------------------------------------------------------- inline uint32_t AttrLength(uint32_t attrLength) { this->_attrLength = attrLength; return(this->_attrLength); } //------------------------------------------------------------------------- // inline uint32_t DataLength() const //......................................................................... //! Returns the length of the data in the ARTS object (bytes required to //! store the object data on disk minus the space required for the //! header and attributes). //------------------------------------------------------------------------- inline uint32_t DataLength() const { return(this->_dataLength); } //------------------------------------------------------------------------- // inline uint32_t DataLength(uint32_t dataLength) //......................................................................... //! Sets and returns the length of the data in the ARTS object (bytes //! required to store the object data on disk minus the space required //! for the header and attributes). //------------------------------------------------------------------------- inline uint32_t DataLength(uint32_t dataLength) { this->_dataLength = dataLength; return(this->_dataLength); } //------------------------------------------------------------------------- // std::ostream& write(std::ostream& os) const //......................................................................... //! Writes the ARTS header to an ostream in ARTS format. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os) const; //------------------------------------------------------------------------- // int write(int fd) const //......................................................................... //! Writes the ARTS header to a file descriptor. Returns the number of //! bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd) const; //------------------------------------------------------------------------- // std::istream& ArtsHeader::read(std::istream& is); //......................................................................... //! Reads the ARTS header from an istream. //------------------------------------------------------------------------- std::istream& read(std::istream& is); //------------------------------------------------------------------------- // int ArtsHeader::read(int fd) //......................................................................... //! Reads the ARTS header from a file descriptor. //------------------------------------------------------------------------- int read(int fd); //------------------------------------------------------------------------- // ArtsHeader & operator = (const ArtsHeader & artsHeader) //......................................................................... //! Overloaded '=' operator to copy an ArtsHeader. //------------------------------------------------------------------------- ArtsHeader & operator = (const ArtsHeader & artsHeader); //------------------------------------------------------------------------- // friend std::ostream& operator << (std::ostream& os, const ArtsHeader & artsHeader) //......................................................................... //! Overloaded '<<' operator for dumping human-readable form of header //! data to an ostream. //------------------------------------------------------------------------- friend std::ostream& operator << (std::ostream& os, const ArtsHeader & artsHeader); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint16_t _magic; uint32_t _identifier; uint8_t _version; uint32_t _flags; uint16_t _numAttributes; uint32_t _attrLength; uint32_t _dataLength; static uint32_t _numObjects; }; #endif /* _ARTSHEADER_HH_ */