//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: Arts.hh,v 1.2 2004/04/21 23:51:24 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 _ARTS_HH_ #define _ARTS_HH_ #include #include #include "ArtsHeader.hh" #include "ArtsAttributeVector.hh" #include "ArtsIpPathData.hh" #include "ArtsAsMatrixData.hh" #include "ArtsNetMatrixData.hh" #include "ArtsPortTableData.hh" #include "ArtsPortMatrixData.hh" #include "ArtsProtocolTableData.hh" #include "ArtsSelectedPortTableData.hh" #include "ArtsTosTableData.hh" #include "ArtsInterfaceMatrixData.hh" #include "ArtsNextHopTableData.hh" #include "ArtsBgp4RouteTableData.hh" #include "ArtsRttTimeSeriesTableData.hh" //--------------------------------------------------------------------------- // class Arts //--------------------------------------------------------------------------- //! Top-level Arts class. The most frequent instantiation of this class: //! an application needs to deal with an Arts object whose type is not //! known until runtime. For example, reading a file containing ARTS //! objects of arbitrary type or order. // //! In cases where an application knows what type of Arts object it //! needs, it should instantiate the derived class and not this class. //--------------------------------------------------------------------------- class Arts { public: //------------------------------------------------------------------------- // Arts() //......................................................................... //! constructor //------------------------------------------------------------------------- Arts(); //-------------------------------------------------------------------------- // Arts(const Arts & arts) //.......................................................................... //! copy constructor //-------------------------------------------------------------------------- Arts(const Arts & arts); //------------------------------------------------------------------------- // ~Arts() //......................................................................... //! destructor //------------------------------------------------------------------------- ~Arts(); //------------------------------------------------------------------------- // void AddHostAttribute(ipv4addr_t hostAddr) //......................................................................... //! Adds a host attribute with an IP address of hostAddr. //------------------------------------------------------------------------- void AddHostAttribute(ipv4addr_t hostAddr); //-------------------------------------------------------------------------- // void AddHostPairAttribute(ipv4addr_t host1, ipv4addr_t host2) //.......................................................................... //! Adds a host pair attribute. //-------------------------------------------------------------------------- void AddHostPairAttribute(ipv4addr_t host1, ipv4addr_t host2); //------------------------------------------------------------------------- // void AddCreationAttribute(uint32_t creationTime); //......................................................................... //! Adds a creation time attribute. //------------------------------------------------------------------------- void AddCreationAttribute(uint32_t creationTime); //------------------------------------------------------------------------- // void AddPeriodAttribute(uint32_t startTime, uint32_t endTime) //......................................................................... //! Adds a period attribute (startTime to endTime). //------------------------------------------------------------------------- void AddPeriodAttribute(uint32_t startTime, uint32_t endTime); //------------------------------------------------------------------------- // void AddIfIndexAttribute(uint16_t ifIndex) //......................................................................... //! Adds an interface index attribute using ifIndex as value. //------------------------------------------------------------------------- void AddIfIndexAttribute(uint16_t ifIndex); //-------------------------------------------------------------------------- // void AddIfDescrAttribute(const std::string & ifDescr) //.......................................................................... //! Adds an interface description attribute using ifDescr as value. //-------------------------------------------------------------------------- void AddIfDescrAttribute(const std::string & ifDescr); //-------------------------------------------------------------------------- // void AddIfIpAddrAttribute(ipv4addr_t ipAddr) //.......................................................................... //! Adds an interface IP address attribute using ipAddr as value. //-------------------------------------------------------------------------- void AddIfIpAddrAttribute(ipv4addr_t ipAddr); //------------------------------------------------------------------------- // inline ArtsHeader & Header() const //......................................................................... //! Returns a reference to the header data. //------------------------------------------------------------------------- inline ArtsHeader & Header() const { return(this->_header); } //------------------------------------------------------------------------- // inline ArtsAttributeVector & Attributes() const //......................................................................... //! Returns a reference to the vector of attributes. //------------------------------------------------------------------------- inline ArtsAttributeVector & Attributes() const { return(this->_attributes); } //------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindCreationAttribute() const //......................................................................... //! Returns an iterator for the first creation attribute in the object. //! If a creation attribute is not found, returns this->Attributes().end() //------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindCreationAttribute() const; //-------------------------------------------------------------------------- // bool RemoveCreationAttribute() //.......................................................................... //! Removes the creation time attribute (if it exists) from the Arts //! object and returns true. If the Arts object does not contain a //! creation time attribute, returns false. //-------------------------------------------------------------------------- bool RemoveCreationAttribute(); //------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindPeriodAttribute() const //......................................................................... //! Returns an iterator for the first period attribute in the object. //! If a period attribute is not found, returns this->Attributes().end() //------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindPeriodAttribute() const; //-------------------------------------------------------------------------- // bool RemovePeriodAttribute() //.......................................................................... //! Removes the period attribute (if it exists) from the Arts object //! and returns true. If the Arts object does not contain a period //! attribute, returns false. //-------------------------------------------------------------------------- bool RemovePeriodAttribute(); //------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindHostAttribute() const //......................................................................... //! Returns an iterator for the first host attribute in the object. //! If a host attribute is not found, returns this->Attributes().end() //------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindHostAttribute() const; //-------------------------------------------------------------------------- // bool RemoveHostAttribute() //.......................................................................... //! Removes the host attribute (if it exists) from the Arts object //! and returns true. If the Arts object does not contain a host //! attribute, returns false. //-------------------------------------------------------------------------- bool RemoveHostAttribute(); //-------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindHostPairAttribute() const //.......................................................................... //! Returns an iterator for the first host pair attribute in the //! object. If a host pair attribute is not found, returns //! this->Attributes().end() //-------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindHostPairAttribute() const; //-------------------------------------------------------------------------- // bool RemoveHostPairAttribute() //.......................................................................... //! Removes the host pair attribute (if it exists) from the Arts //! object and returns true. If the Arts object does not contain a //! host pair attribute, returns false. //-------------------------------------------------------------------------- bool RemoveHostPairAttribute(); //------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindIfIndexAttribute() const //......................................................................... //! returns an iterator for the first interface index attribute in //! the object. If an interface index attribute is not found, returns //! this->Attributes().end() //------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindIfIndexAttribute() const; //-------------------------------------------------------------------------- // bool RemoveIfIndexAttribute() //.......................................................................... //! Removes the interface index attribute (if it exists) from the Arts //! object and returns true. If the Arts object does not contain an //! interface index attribute, returns false. //-------------------------------------------------------------------------- bool RemoveIfIndexAttribute(); //-------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindIfDescrAttribute() const //.......................................................................... //! returns an iterator for the first interface description attribute //! in the object. If an interface description attribute is not found, //! returns this->Attributes().end() //-------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindIfDescrAttribute() const; //-------------------------------------------------------------------------- // bool RemoveIfDescrAttribute() //.......................................................................... //! Removes the interface description attribute (if it exists) from //! the Arts object and returns true. If the Arts object does not //! contain an interface description attribute, returns false. //-------------------------------------------------------------------------- bool RemoveIfDescrAttribute(); //-------------------------------------------------------------------------- // ArtsAttributeVector::const_iterator FindIfIpAddrAttribute() const //.......................................................................... //! returns an iterator for the first interface IP address attribute //! in the object. If an interface IP address attribute is not found, //! returns this->Attributes().end() //-------------------------------------------------------------------------- ArtsAttributeVector::const_iterator FindIfIpAddrAttribute() const; //-------------------------------------------------------------------------- // bool RemoveIfIpAddrAttribute() //.......................................................................... //! Removes the interface IP address attribute (if it exists) from //! the Arts object and returns true. If the Arts object does not //! contain an interface IP address attribute, returns false. //-------------------------------------------------------------------------- bool RemoveIfIpAddrAttribute(); //------------------------------------------------------------------------- // inline ArtsIpPathData* IpPathData() const //......................................................................... //! Returns a pointer to the IP path data in an object containing //! ArtsIpPathData. If the object is not holding ArtsIpPathData, //! returns NULL. //------------------------------------------------------------------------- inline ArtsIpPathData* IpPathData() const { return(this->_data._ipPath); } //------------------------------------------------------------------------- // inline ArtsAsMatrixData* AsMatrixData() const //......................................................................... //! Returns a pointer to the AS matrix data in an object. Returns NULL //! if there is no AS matrix data in the object. //------------------------------------------------------------------------- inline ArtsAsMatrixData* AsMatrixData() const { return(this->_data._asMatrix); } //------------------------------------------------------------------------- // inline ArtsNetMatrixData* NetMatrixData() const //......................................................................... //! Returns a pointer to the AS matrix data in an object. Returns NULL //! if there is no AS matrix data in the object. //------------------------------------------------------------------------- inline ArtsNetMatrixData* NetMatrixData() const { return(this->_data._netMatrix); } //------------------------------------------------------------------------- // inline ArtsPortTableData* PortTableData() const //......................................................................... //! Returns a pointer to the port table in the object. Returns NULL if //! there is no port table in the object. //------------------------------------------------------------------------- inline ArtsPortTableData* PortTableData() const { return(this->_data._portTable); } //------------------------------------------------------------------------- // inline ArtsSelectedPortTableData* SelectedPortTableData() const //......................................................................... //! Returns a pointer to the selected port table in the object. //! Returns NULL if there is no selected port table in the object. //------------------------------------------------------------------------- inline ArtsSelectedPortTableData* SelectedPortTableData() const { return(this->_data._selectedPortTable); } //------------------------------------------------------------------------- // inline ArtsPortMatrixData* PortMatrixData() const //......................................................................... //! Returns a pointer to the port matrix in the object. Returns NULL //! if there is no port matrix in the object. //------------------------------------------------------------------------- inline ArtsPortMatrixData* PortMatrixData() const { return(this->_data._portMatrix); } //------------------------------------------------------------------------- // inline ArtsProtocolTableData* ProtocolTableData() const //......................................................................... //! Returns a pointer to the protocol table in the object. Returns //! NULL if there is no protocol table in the object. //------------------------------------------------------------------------- inline ArtsProtocolTableData* ProtocolTableData() const { return(this->_data._protocolTable); } //-------------------------------------------------------------------------- // inline ArtsTosTableData * TosTableData() const //.......................................................................... //! Returns a pointer to the TOS table in the object. Returns NULL if //! there is no TOS table in the object. //-------------------------------------------------------------------------- inline ArtsTosTableData * TosTableData() const { return(this->_data._tosTable); } //------------------------------------------------------------------------- // inline ArtsInterfaceMatrixData * InterfaceMatrixData() const //......................................................................... //! Returns a pointer to the interface matrix in the object. Returns //! NULL if there is no interface matrix in the object. //------------------------------------------------------------------------- inline ArtsInterfaceMatrixData * InterfaceMatrixData() const { return(this->_data._interfaceMatrix); } //------------------------------------------------------------------------- // inline ArtsNextHopTableData * NextHopTableData() const //......................................................................... //! Returns a pointer to the IP nexthop table in the object. Returns //! NULL if there is no IP nexthop table in the object. //------------------------------------------------------------------------- inline ArtsNextHopTableData * NextHopTableData() const { return(this->_data._nextHopTable); } //-------------------------------------------------------------------------- // inline ArtsBgp4RouteTableData * Bgp4RouteTableData() const //.......................................................................... //! Returns a pointer to the BGP4 route table in the object. Returns //! NULL if there is no BGP4 route table in the object. //-------------------------------------------------------------------------- inline ArtsBgp4RouteTableData * Bgp4RouteTableData() const { return(this->_data._bgp4RouteTable); } //-------------------------------------------------------------------------- // inline ArtsRttTimeSeriesTableData * RttTimeSeriesTableData() const //.......................................................................... //! Returns a pointer to the RTT time series table in the object. //! Returns NULL if there is no RTT time series table in the object. //-------------------------------------------------------------------------- inline ArtsRttTimeSeriesTableData * RttTimeSeriesTableData() const { return(this->_data._rttTimeSeriesTable); } //-------------------------------------------------------------------------- // std::istream & readData(std::istream & is) //.......................................................................... // //-------------------------------------------------------------------------- std::istream & readData(std::istream & is); //-------------------------------------------------------------------------- // int readData(int fd) //.......................................................................... // //-------------------------------------------------------------------------- int readData(int fd); //------------------------------------------------------------------------- // std::istream& read(std::istream& is) //......................................................................... //! Loads the data from an istream into the Arts object. Returns a //! reference to the istream. //------------------------------------------------------------------------- std::istream & read(std::istream & is); //------------------------------------------------------------------------- // int read(int fd) //......................................................................... //! Loads the data from a file descriptor into the Arts object. //! Returns the number of bytes read on success, -1 on failure. //------------------------------------------------------------------------- int read(int fd); //------------------------------------------------------------------------- // std::ostream& write(std::ostream& os) //......................................................................... //! Writes an Arts object to an ostream. Returns a reference to the //! ostream. //------------------------------------------------------------------------- std::ostream& write(std::ostream& os); //------------------------------------------------------------------------- // int write(int fd) //......................................................................... //! Writes an Arts object to a file descriptor. Returns the number //! of bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd); //------------------------------------------------------------------------- // Arts & operator = (const Arts & arts) //......................................................................... //! Overloaded '=' operator to deep-copy an ARTS object. //------------------------------------------------------------------------- Arts & operator = (const Arts & arts); //------------------------------------------------------------------------- // friend std::ostream & operator << (std::ostream & os, // const Arts & arts) //......................................................................... //! Overloaded ostream '<<' operator to dump the contents of an Arts //! object to an ostream in a human-readable form. Returns the //! ostream. //------------------------------------------------------------------------- friend std::ostream & operator << (std::ostream & os, const Arts & arts); //-------------------------------------------------------------------------- // friend std::istream & operator >> (std::istream & is, // Arts & arts) //.......................................................................... //! This works just like our read(is) member, but lets us use //! istream_iterator to walk through Arts objects in an istream. //-------------------------------------------------------------------------- friend std::istream & operator >> (std::istream & is, Arts & arts); //-------------------------------------------------------------------------- // void DeleteData() //.......................................................................... // Deletes data contained in Arts object. //-------------------------------------------------------------------------- void DeleteData(); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif protected: struct { ArtsIpPathData* _ipPath; ArtsAsMatrixData* _asMatrix; ArtsPortTableData* _portTable; ArtsProtocolTableData* _protocolTable; ArtsNetMatrixData* _netMatrix; ArtsPortMatrixData* _portMatrix; ArtsSelectedPortTableData* _selectedPortTable; ArtsInterfaceMatrixData* _interfaceMatrix; ArtsNextHopTableData* _nextHopTable; ArtsBgp4RouteTableData* _bgp4RouteTable; ArtsRttTimeSeriesTableData* _rttTimeSeriesTable; ArtsTosTableData* _tosTable; } _data; mutable ArtsHeader _header; mutable ArtsAttributeVector _attributes; //-------------------------------------------------------------------------- // void DeleteAttributes() //.......................................................................... // Deletes attributes contained in Arts object. //-------------------------------------------------------------------------- void DeleteAttributes(); static uint32_t _numObjects; }; #endif /* _ARTS_HH_ */