//=========================================================================== // $Name: $ // $Id: ArtsHeader.hh,v 1.1.1.1 2000/03/29 22:53:56 kkeys Exp $ //=========================================================================== // CAIDA 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 General Public License, // v. 2 dated June 1991 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 GPL along with arts++. // Copies can also be obtained from: // // http://www.gnu.org/copyleft/gpl.html // // or by writing to: // // University of California, San Diego // // SDSC/CAIDA // 9500 Gilman Dr., MS-0505 // La Jolla, CA 92093 - 0505 USA // // Or contact: // // info@caida.org //=========================================================================== #ifndef _ARTSHEADER_HH_ #define _ARTSHEADER_HH_ extern "C" { #include #include "caida_t.h" } #include #include //--------------------------------------------------------------------------- // 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 //--------------------------------------------------------------------------- // 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 0x0003000 //--------------------------------------------------------------------------- // 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); } //------------------------------------------------------------------------- // 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); } //------------------------------------------------------------------------- // ostream& write(ostream& os) const //......................................................................... // Writes the ARTS header to an ostream in ARTS format. //------------------------------------------------------------------------- ostream& write(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; //------------------------------------------------------------------------- // istream& ArtsHeader::read(istream& is); //......................................................................... // Reads the ARTS header from an istream. //------------------------------------------------------------------------- istream& ArtsHeader::read(istream& is); //------------------------------------------------------------------------- // int ArtsHeader::read(int fd) //......................................................................... // Reads the ARTS header from a file descriptor. //------------------------------------------------------------------------- int ArtsHeader::read(int fd); // UNTESTED //------------------------------------------------------------------------- // ArtsHeader & operator = (const ArtsHeader & artsHeader) //......................................................................... // Overloaded '=' operator to copy an ArtsHeader. //------------------------------------------------------------------------- ArtsHeader & operator = (const ArtsHeader & artsHeader); //------------------------------------------------------------------------- // friend ostream& operator << (ostream& os, const ArtsHeader & artsHeader) //......................................................................... // Overloaded '<<' operator for dumping human-readable form of header // data to an ostream. //------------------------------------------------------------------------- friend ostream& operator << (ostream& os, const ArtsHeader & artsHeader); private: uint16_t _magic; uint32_t _identifier; uint8_t _version; uint32_t _flags; uint16_t _numAttributes; uint32_t _attrLength; uint32_t _dataLength; }; #endif /* _ARTSHEADER_HH_ */