//=========================================================================== // @(#) $Name: arts++-1-1-a12 $ // @(#) $Id: ArtsAttribute.hh,v 1.2 2004/04/21 23:51:25 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 _ARTSATTRIBUTE_HH_ #define _ARTSATTRIBUTE_HH_ extern "C" { #include #include #include "artslocal.h" #include "caida_t.h" } #include #ifdef HAVE_IOSTREAM #include #else #include #endif //--------------------------------------------------------------------------- // Object Attribute Identifiers //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // pad attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_PAD(); #define artsC_ATTR_PAD 0 //--------------------------------------------------------------------------- // ASCII comment string attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_COMMENT(); #define artsC_ATTR_COMMENT 1 //--------------------------------------------------------------------------- // Creation time attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_CREATION(); #define artsC_ATTR_CREATION 2 //--------------------------------------------------------------------------- // Time range attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_PERIOD(); #define artsC_ATTR_PERIOD 3 //--------------------------------------------------------------------------- // Host attribute (an IP address) //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_HOST(); #define artsC_ATTR_HOST 4 //--------------------------------------------------------------------------- // Interface name attribute (ifDescr) //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_IFDESCR(); #define artsC_ATTR_IFDESCR 5 //--------------------------------------------------------------------------- // interface index attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_IFINDEX(); #define artsC_ATTR_IFINDEX 6 //--------------------------------------------------------------------------- // interface IP address attribute //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_IFIPADDR(); #define artsC_ATTR_IFIPADDR 7 //--------------------------------------------------------------------------- // pair of IP addresses //--------------------------------------------------------------------------- const uint32_t artsC_ATTR_HOSTPAIR(); #define artsC_ATTR_HOSTPAIR 8 //--------------------------------------------------------------------------- // Object Attribute Formats //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Unsigned 8-bit value //--------------------------------------------------------------------------- const uint8_t artsC_UBIT8(); #define artsC_UBIT8 2 //--------------------------------------------------------------------------- // Unsigned 16-bit value //--------------------------------------------------------------------------- const uint8_t artsC_UBIT16(); #define artsC_UBIT16 3 //--------------------------------------------------------------------------- // Unsigned 32-bit value //--------------------------------------------------------------------------- const uint8_t artsC_UBIT32(); #define artsC_UBIT32 4 //--------------------------------------------------------------------------- // Unsigned 64-bit value //--------------------------------------------------------------------------- const uint8_t artsC_UBIT64(); #define artsC_UBIT64 5 //--------------------------------------------------------------------------- // Signed 8-bit value //--------------------------------------------------------------------------- const uint8_t artsC_BIT8(); #define artsC_BIT8 6 //--------------------------------------------------------------------------- // Signed 16-bit value //--------------------------------------------------------------------------- const uint8_t artsC_BIT16(); #define artsC_BIT16 7 //--------------------------------------------------------------------------- // Signed 32-bit value //--------------------------------------------------------------------------- const uint8_t artsC_BIT32(); #define artsC_BIT32 8 //--------------------------------------------------------------------------- // Signed 64-bit value //--------------------------------------------------------------------------- const uint8_t artsC_BIT64(); #define artsC_BIT64 9 //--------------------------------------------------------------------------- // Null-terminated 8-bit string //--------------------------------------------------------------------------- const uint8_t artsC_STRING8(); #define artsC_STRING8 10 //--------------------------------------------------------------------------- // 8-bit character array //--------------------------------------------------------------------------- const uint8_t artsC_CHAR8(); #define artsC_CHAR8 11 //--------------------------------------------------------------------------- // IP Address //--------------------------------------------------------------------------- const uint8_t artsC_IPV4_ADDRESS(); #define artsC_IPV4_ADDRESS 12 //--------------------------------------------------------------------------- // Unix GMT date value //--------------------------------------------------------------------------- const uint8_t artsC_UNIX_DATE(); #define artsC_UNIX_DATE 13 //--------------------------------------------------------------------------- // Pair of unix GMT date values //--------------------------------------------------------------------------- const uint8_t artsC_UNIX_DATE_RANGE(); #define artsC_UNIX_DATE_RANGE 14 //--------------------------------------------------------------------------- // 32-bit floating point (XDR) //--------------------------------------------------------------------------- const uint8_t artsC_FLOAT32(); #define artsC_FLOAT32 15 //--------------------------------------------------------------------------- // 64-bit float (XDR double) //--------------------------------------------------------------------------- const uint8_t artsC_DOUBLE64(); #define artsC_DOUBLE64 16 //--------------------------------------------------------------------------- // pair of IPv4 addresses //--------------------------------------------------------------------------- const uint8_t artsC_IPV4_ADDRESS_PAIR(); #define artsC_IPV4_ADDRESS_PAIR 17 //--------------------------------------------------------------------------- // class ArtsAttribute //--------------------------------------------------------------------------- //! Class to encapsulate an ARTS attribute. //--------------------------------------------------------------------------- class ArtsAttribute { public: //------------------------------------------------------------------------- // ArtsAttribute() //......................................................................... //! constructor //------------------------------------------------------------------------- ArtsAttribute(); ArtsAttribute(const ArtsAttribute & attribute); //------------------------------------------------------------------------- // ~ArtsAttribute() //......................................................................... //! destructor //------------------------------------------------------------------------- ~ArtsAttribute(); //------------------------------------------------------------------------- // ArtsAttribute & operator = (const ArtsAttribute & artsAttribute) //......................................................................... //! Overloaded '=' operator for deep-copying an ArtsAttribute. //------------------------------------------------------------------------- ArtsAttribute & operator = (const ArtsAttribute & artsAttribute); //------------------------------------------------------------------------- // uint32_t Identifier() const //......................................................................... //! Returns the attribute identifier. //------------------------------------------------------------------------- uint32_t Identifier() const; //------------------------------------------------------------------------- // uint32_t Identifier(uint32_t identifier) //......................................................................... //! Sets and returns the attribute identifier. //------------------------------------------------------------------------- uint32_t Identifier(uint32_t identifier); //------------------------------------------------------------------------- // uint8_t Format() const //......................................................................... //! Returns the attribute format. //------------------------------------------------------------------------- uint8_t Format() const; //------------------------------------------------------------------------- // uint8_t Format(uint8_t format) //......................................................................... //! Sets and returns the attribute format. //------------------------------------------------------------------------- uint8_t Format(uint8_t format); //------------------------------------------------------------------------- // uint32_t Length() const //......................................................................... //! Returns the attribute length. //------------------------------------------------------------------------- uint32_t Length() const; //------------------------------------------------------------------------- // uint32_t Length(uint32_t length) //......................................................................... //! Sets and returns the attribute length. //------------------------------------------------------------------------- uint32_t Length(uint32_t length); //------------------------------------------------------------------------- // const std::string Comment() const //......................................................................... //! Returns the attribute comment if the attribute really is a comment //! attribute, otherwise asserts. //------------------------------------------------------------------------- const std::string Comment() const; //------------------------------------------------------------------------- // uint32_t Creation() const //......................................................................... //! Returns the attribute creation timestamp if the attribute identifier //! is artsC_ATTR_CREATION (i.e. the attirbute really is a creation //! attribute), else asserts. //------------------------------------------------------------------------- uint32_t Creation() const; //------------------------------------------------------------------------- // uint32_t Creation(uint32_t creation) //......................................................................... //! Sets and returns the attribute creation timestamp if the attribute //! identifier is artsC_ATTR_CREATION (i.e. the attirbute really is a //! creation attribute), else asserts. //------------------------------------------------------------------------- uint32_t Creation(uint32_t creation); //------------------------------------------------------------------------- // const uint32_t *Period() const //......................................................................... //! Returns the attribute period if the attribute is really a period //! attribute, else asserts. //------------------------------------------------------------------------- const uint32_t *Period() const; //------------------------------------------------------------------------- // uint32_t *Period(uint32_t startTime, uint32_t endTime) //......................................................................... //! Sets and returns the attribute period if the attribute is really a //! period attribute, else asserts. //------------------------------------------------------------------------- uint32_t *Period(uint32_t startTime, uint32_t endTime); //------------------------------------------------------------------------- // ipv4addr_t Host() const //......................................................................... //! Returns the attribute IP address if the attribute is really a host //! attribute, else asserts. //------------------------------------------------------------------------- ipv4addr_t Host() const; //------------------------------------------------------------------------- // ipv4addr_t Host(ipv4addr_t host) //......................................................................... //! Sets and returns the attribute IP address if the attribute is really a //! host attribute, else asserts. //------------------------------------------------------------------------- ipv4addr_t Host(ipv4addr_t host); //-------------------------------------------------------------------------- // const ipv4addr_t * HostPair() const //.......................................................................... //! Returns the host pair attribute value if attribute is really a host //! pair attribute, else asserts. //-------------------------------------------------------------------------- const ipv4addr_t * HostPair() const; //-------------------------------------------------------------------------- // const ipv4addr_t * HostPair(ipv4addr_t host1, ipv4addr_t host2) //.......................................................................... //! Sets and returns the attribute host pair value id the attribute is //! really a host pair attribute, else asserts. //-------------------------------------------------------------------------- const ipv4addr_t * HostPair(ipv4addr_t host1, ipv4addr_t host2); //------------------------------------------------------------------------- // const std::string IfDescr() const //......................................................................... //! Returns the attribute interface name if the attribute is really an //! ifDescr attribute, else asserts. //------------------------------------------------------------------------- const std::string IfDescr() const; //------------------------------------------------------------------------- // std::string IfDescr(const std::string & ifDescr) //......................................................................... //! Sets and returns the attribute interface name if the attribute is //! really an ifDescr attribute, else asserts. //------------------------------------------------------------------------- std::string IfDescr(const std::string & ifDescr); //------------------------------------------------------------------------- // uint16_t IfIndex() const //......................................................................... //! Returns the interface index if the attribute is really an //! interface index attribute, else asserts. //------------------------------------------------------------------------- uint16_t IfIndex() const; //------------------------------------------------------------------------- // uint16_t IfIndex(uint16_t ifIndex) //......................................................................... //! Sets and returns the ifIndex if the attribute is really an //! interface index attribute, else asserts. //------------------------------------------------------------------------- uint16_t IfIndex(uint16_t ifIndex); //-------------------------------------------------------------------------- // ipv4addr_t IfIpAddr() const //.......................................................................... //! Returns the interface IP address if the attribute is really an //! interface IP address attribute, else asserts. //-------------------------------------------------------------------------- ipv4addr_t IfIpAddr() const; //-------------------------------------------------------------------------- // ipv4addr_t IfIpAddr(ipv4addr_t ipAddr) //.......................................................................... //! Sets and returns the interface IP address if the attribute is //! really an interface IP address attribute, else asserts. //-------------------------------------------------------------------------- ipv4addr_t IfIpAddr(ipv4addr_t ipAddr); //------------------------------------------------------------------------- // void *Arbitrary() const //......................................................................... //! Returns the value of an arbitrary-format ARTS attribute. Arbitrary //! attributes can be used when a pre-defined attribute type does not //! exist for the type of data stored in the attribute. For example, //! an application-specific attribute. The pointer returned here is //! just a pointer to a block of memory of length ArtsAttribute::Length(). //! It is the responsibility of the caller to convert to an approriate //! representation. //------------------------------------------------------------------------- void *Arbitrary() const; //------------------------------------------------------------------------- // void *Arbitrary(void *arbitrary) //......................................................................... //! Sets and returns the value of an arbitrary-format ARTS attribute. //! Note that the pointer passed in should be a pointer to a block of //! memory of length ArtsAttribute::Length(). Internally the ARTS library //! will treat the data as opaque. //------------------------------------------------------------------------- void *Arbitrary(void *arbitrary); //------------------------------------------------------------------------- // std::ostream& write(std::ostream& os) const //......................................................................... //! Writes the attribute to an ostream and returns the ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os) const; //------------------------------------------------------------------------- // int write(int fd) const //......................................................................... //! Writes the attribute to a file descriptor. Returns the number of //! bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd) const; //------------------------------------------------------------------------- // std::istream& read(std::istream& is) //......................................................................... //! Reads an attribute from an istream and returns the istream. //------------------------------------------------------------------------- std::istream& read(std::istream& is); //------------------------------------------------------------------------- // int read(int fd) //......................................................................... //! Reads an attribute from a file descriptor and returns the number of //! bytes read. UNTESTED //------------------------------------------------------------------------- int read(int fd); // UNTESTED //------------------------------------------------------------------------- // uint32_t Bytes() const //......................................................................... //! Returns the number of bytes required to store the attribute on disk. //------------------------------------------------------------------------- uint32_t Bytes() const { return(sizeof(this->_identifier) + sizeof(this->_length) + this->_length); } //------------------------------------------------------------------------- // friend std::ostream & operator << (std::ostream &os, // ArtsAttribute & artsAttribute) //......................................................................... //! Overloaded '<<' operator to dump attribute to an ostream in a //! himan-readable form. //------------------------------------------------------------------------- friend std::ostream & operator << (std::ostream &os, ArtsAttribute & artsAttribute); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint32_t _identifier; uint8_t _format; uint32_t _length; union { uint8_t pad; std::string *comment; uint32_t creation; uint32_t period[2]; ipv4addr_t host; ipv4addr_t hostPair[2]; uint16_t ifIndex; ipv4addr_t ifIpAddr; std::string *ifDescr; void *arbitrary; } _value; // Attribute value static uint32_t _numObjects; }; #endif // _ARTSATTRIBUTE_HH_