//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsBgp4AsPathSegment.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 _ARTSBGP4ASPATHSEGMENT_HH_ #define _ARTSBGP4ASPATHSEGMENT_HH_ extern "C" { #include "caida_t.h" } #include //--------------------------------------------------------------------------- // class ArtsBgp4AsPathSegment //--------------------------------------------------------------------------- //! This class abstracts an AS path segement in a BGP AS path attribute. //! An AS path segment may be of type SET or SEQUENCE; a SET segment is //! unordered while a SEQUENCE segment is ordered. See RFC 1771 for //! more details. //--------------------------------------------------------------------------- class ArtsBgp4AsPathSegment { public: //------------------------------------------------------------------------- //! Define some static constants for AS path segment types. //------------------------------------------------------------------------- static const uint8_t k_segmentTypeSet = 1; static const uint8_t k_segmentTypeSequence = 2; //-------------------------------------------------------------------------- // ArtsBgp4AsPathSegment() //.......................................................................... //! constructor //-------------------------------------------------------------------------- ArtsBgp4AsPathSegment(); //-------------------------------------------------------------------------- // ArtsBgp4AsPathSegment(const ArtsBgp4AsPathSegment & asPathSegment) //.......................................................................... //! copy constructor //-------------------------------------------------------------------------- ArtsBgp4AsPathSegment(const ArtsBgp4AsPathSegment & asPathSegment); //-------------------------------------------------------------------------- // ~ArtsBgp4AsPathSegment() //.......................................................................... //! destructor //-------------------------------------------------------------------------- ~ArtsBgp4AsPathSegment(); //------------------------------------------------------------------------- // uint8_t Type() const //......................................................................... //! Returns the type of the segment (1 == SET, 2 == SEQUENCE). //------------------------------------------------------------------------- uint8_t Type() const; //------------------------------------------------------------------------- // uint8_t Type(uint8_t type) //......................................................................... //! Sets and returns the type of the segment (1 == SET, 2 == SEQUENCE). //------------------------------------------------------------------------- uint8_t Type(uint8_t type); //------------------------------------------------------------------------- // std::vector & AS() const //......................................................................... //! Returns a reference to the vector of AS numbers in the segment. //! Note that this member can be called on a const object though we //! don't return a const reference; the vector of AS numbers is //! mutable. //------------------------------------------------------------------------- std::vector & AS() const; //-------------------------------------------------------------------------- // std::istream & read(std::istream & is, uint8_t version = 0) //.......................................................................... //! Reads the ArtsBgp4AsPathSegment from an istream. Returns a reference //! to the istream. //-------------------------------------------------------------------------- std::istream & read(std::istream & is, uint8_t version = 0); //-------------------------------------------------------------------------- // int read(int fd, uint8_t version = 0) //.......................................................................... //! Reads the ArtsBgp4AsPathSegment from a file descriptor. Returns the //! number of bytes read on success, -1 on failure. //-------------------------------------------------------------------------- int read(int fd, uint8_t version = 0); //-------------------------------------------------------------------------- // std::ostream & write(std::ostream & os, uint8_t version = 0) const //.......................................................................... //! Writes the ArtsBgp4AsPathSegment to an ostream. Returns a reference //! to the ostream. //-------------------------------------------------------------------------- std::ostream & write(std::ostream & os, uint8_t version = 0) const; //-------------------------------------------------------------------------- // int write(int fd, uint8_t version = 0) const //.......................................................................... //! Writes the ArtsBgp4AsPathSegment to a file descriptor. Returns the //! number of bytes written on success, -1 on failure. //-------------------------------------------------------------------------- int write(int fd, uint8_t version = 0) const; //-------------------------------------------------------------------------- // uint32_t Length(uint8_t version = 0) const //.......................................................................... //! Returns the number of bytes required to write the //! ArtsBgp4AsPathSegment to disk. //-------------------------------------------------------------------------- uint32_t Length(uint8_t version = 0) const; //-------------------------------------------------------------------------- // void AddAs(uint16_t as) //.......................................................................... //! Appends an AS number to the segment. //-------------------------------------------------------------------------- void AddAs(uint16_t as); //-------------------------------------------------------------------------- // void Unique() //.......................................................................... //! If the segment is a sequence segment (not an AS_SET), removes //! adjacent duplicate AS numbers from the segment. //-------------------------------------------------------------------------- void Unique(); //-------------------------------------------------------------------------- // ArtsBgp4AsPathSegment & // operator = (const ArtsBgp4AsPathSegment & bgp4AsPathSegment) //.......................................................................... //! Overloaded = operator, deep-copies an ArtsBgp4AsPathSegment. //-------------------------------------------------------------------------- ArtsBgp4AsPathSegment & operator = (const ArtsBgp4AsPathSegment & asPathSegment); //-------------------------------------------------------------------------- // friend std::ostream & // operator << (std::ostream& os, // const ArtsBgp4AsPathSegment & bgpAsPathSegment) //.......................................................................... //! Writes the contents of an ArtsBgp4AsPathSegment to an ostream in //! a human-friendly form. //-------------------------------------------------------------------------- friend std::ostream & operator << (std::ostream& os, const ArtsBgp4AsPathSegment & bgpAsPathSegment); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint8_t _type; // the segment type mutable std::vector _AS; // the segment AS numbers static uint32_t _numObjects; }; #endif // _ARTSBGP4ASPATHSEGMENT_HH_