//=========================================================================== // $Name: arts++-1-1-a12 $ // $Id: ArtsBgp4Attribute.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 _ARTSBGP4ATTRIBUTE_HH_ #define _ARTSBGP4ATTRIBUTE_HH_ extern "C" { #include "caida_t.h" } #include #include "ArtsBgp4AsPathAttribute.hh" #include "ArtsBgp4AggregatorAttribute.hh" #include "ArtsBgp4DPAttribute.hh" //--------------------------------------------------------------------------- // origin (IGP, EGP, incomplete) attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_Origin(); #define Bgp4_Attribute_Origin 1 //--------------------------------------------------------------------------- // AS path attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_AsPath(); #define Bgp4_Attribute_AsPath 2 //--------------------------------------------------------------------------- // next hop attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_NextHop(); #define Bgp4_Attribute_NextHop 3 //--------------------------------------------------------------------------- // M.E.D. attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_MultiExitDisc(); #define Bgp4_Attribute_MultiExitDisc 4 //--------------------------------------------------------------------------- // local preference attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_LocalPref(); #define Bgp4_Attribute_LocalPref 5 //--------------------------------------------------------------------------- // atomic aggregate attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_AtomicAggregate(); #define Bgp4_Attribute_AtomicAggregate 6 //--------------------------------------------------------------------------- // aggregator attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_Aggregator(); #define Bgp4_Attribute_Aggregator 7 //--------------------------------------------------------------------------- // community attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_Community(); #define Bgp4_Attribute_Community 8 //--------------------------------------------------------------------------- // DPA attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_DPA(); #define Bgp4_Attribute_DPA 11 //--------------------------------------------------------------------------- // Multiprotocol Reachable attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_MPReachNLRI(); #define Bgp4_Attribute_MPReachNLRI 14 //--------------------------------------------------------------------------- // Multiprotocol Unreachable attribute //--------------------------------------------------------------------------- const uint16_t Bgp4_Attribute_MPUnreachNLRI(); #define Bgp4_Attribute_MPUnreachNLRI 15 //--------------------------------------------------------------------------- // class ArtsBgp4Attribute //--------------------------------------------------------------------------- //! This class abstracts a BGP4 attribute. This is a container class //! for a discriminate union that lets us store any type of BGP4 attribute //! from the set of supported BGP attributes (all the required attributes //! plus community, DPA, Aggregator and MED). Note that this class does //! *not* abstract any 0-length attributes like Atomic Aggregate. //--------------------------------------------------------------------------- class ArtsBgp4Attribute { public: static const uint8_t k_originTypeIGP = 0; static const uint8_t k_originTypeEGP = 1; static const uint8_t k_originTypeIncomplete = 2; //------------------------------------------------------------------------- // ArtsBgp4Attribute() //......................................................................... //! constructor //------------------------------------------------------------------------- ArtsBgp4Attribute(); //-------------------------------------------------------------------------- // ArtsBgp4Attribute(const ArtsBgp4Attribute & bgp4Attr) //.......................................................................... //! copy constructor //-------------------------------------------------------------------------- ArtsBgp4Attribute(const ArtsBgp4Attribute & bgp4Attr); //------------------------------------------------------------------------- // ~ArtsBgp4Attribute() //......................................................................... //! destructor //------------------------------------------------------------------------- ~ArtsBgp4Attribute(); //------------------------------------------------------------------------- // uint8_t Flags() const //......................................................................... //! Returns the flags in the attribute. //------------------------------------------------------------------------- uint8_t Flags() const; //------------------------------------------------------------------------- // uint8_t Flags(uint8_t flags) //......................................................................... //! Sets and returns the flags in the attribute. //------------------------------------------------------------------------- uint8_t Flags(uint8_t flags); //------------------------------------------------------------------------- // uint8_t Type() const //......................................................................... //! Returns the type of the attribute (Bgp4_Attribute_NextHop, //! Bgp4_Attribute_Community, ...). //------------------------------------------------------------------------- uint8_t Type() const; //------------------------------------------------------------------------- // uint8_t Type(uint8_t attrType) //......................................................................... //! Sets and returns the type of the attribute (Bgp4_Attribute_NextHop, //! Bgp4_Attribute_Community, ...). //------------------------------------------------------------------------- uint8_t Type(uint8_t attrType); //------------------------------------------------------------------------- // uint16_t Length(uint8_t version = 0) const //......................................................................... //! Returns the attribute length. Note this is an attribute-type //! dependent value. //------------------------------------------------------------------------- uint16_t Length(uint8_t version = 0) const; //------------------------------------------------------------------------- // uint8_t Origin() const //......................................................................... //! If Type() is Bgp4_Attribute_Origin, returns the ORIGIN attribute //! (IGP, EGP or INCOMPLETE). Else asserts. //------------------------------------------------------------------------- uint8_t Origin() const; //------------------------------------------------------------------------- // uint8_t Origin(uint8_t origin) //......................................................................... //! If Type() is Bgp4_Attribute_Origin, sets and returns the contained //! ORIGIN attribute. Else asserts. //------------------------------------------------------------------------- uint8_t Origin(uint8_t origin); //------------------------------------------------------------------------- // const ArtsBgp4AsPathAttribute * AsPath() const //......................................................................... //! If Type() is Bgp4_Attribute_AsPath, returns a pointer to the //! contained AS PATH attribute. Else asserts. //------------------------------------------------------------------------- const ArtsBgp4AsPathAttribute * AsPath() const; //------------------------------------------------------------------------- // const ArtsBgp4AsPathAttribute * // AsPath(const ArtsBgp4AsPathAttribute & asPath) //......................................................................... //! Sets the contained AS path attribute and returns a pointer to it. //! Automatically sets Type() to Bgp4_Attribute_AsPath. //------------------------------------------------------------------------- const ArtsBgp4AsPathAttribute * AsPath(const ArtsBgp4AsPathAttribute & asPath); //------------------------------------------------------------------------- // const ipv4addr_t & NextHop() const //......................................................................... //! If Type() is Bgp4_Attribute_NextHop, returns the contained nexthop //! attribute. Else asserts. //------------------------------------------------------------------------- const ipv4addr_t & NextHop() const; //------------------------------------------------------------------------- // const ipv4addr_t & NextHop(const ipv4addr_t & nextHop) //......................................................................... //! Sets and returns the contained nexthop attribute. Automatically //! sets Type() to Bgp4_Attribute_NextHop. //------------------------------------------------------------------------- const ipv4addr_t & NextHop(const ipv4addr_t & nextHop); //------------------------------------------------------------------------- // uint32_t MED() const //......................................................................... //! If Type() is Bgp4_Attribute_MultiExitDisc, returns the contained //! MED attribute. Else asserts. //------------------------------------------------------------------------- uint32_t MED() const; //------------------------------------------------------------------------- // uint32_t MED(uint32_t med) //......................................................................... //! Sets and returns the contained MED attribute. Automatically sets //! Type() to Bgp4_Attribute_MultiExitDisc. //------------------------------------------------------------------------- uint32_t MED(uint32_t med); //------------------------------------------------------------------------- // uint32_t LocalPref() const //......................................................................... //! If Type() is Bgp4_Attribute_LocalPref, returns the contained //! localpref attribute. Else aserts. //------------------------------------------------------------------------- uint32_t LocalPref() const; //------------------------------------------------------------------------- // uint32_t LocalPref(uint32_t localPref) //......................................................................... //! Sets and returns the contained localpref attribute. Automatically //! sets Type() to Bgp4_Attribute_LocalPref. //------------------------------------------------------------------------- uint32_t LocalPref(uint32_t localPref); //------------------------------------------------------------------------- // const ArtsBgp4AggregatorAttribute * Aggregator() const //......................................................................... //! If Type() is Bgp4_Attribute_Aggregator, returns a pointer to the //! contained aggregator attribute. Else asserts. //------------------------------------------------------------------------- const ArtsBgp4AggregatorAttribute * Aggregator() const; //------------------------------------------------------------------------- // const ArtsBgp4AggregatorAttribute * // Aggregator(const ArtsBgp4AggregatorAttribute & aggregator) //......................................................................... //! Sets the contained aggregator attribute and returns a pointer to //! it. Automatically sets Type() to Bgp4_Attribute_Aggregator. //------------------------------------------------------------------------- const ArtsBgp4AggregatorAttribute * Aggregator(const ArtsBgp4AggregatorAttribute & aggregator); //------------------------------------------------------------------------- // const std::vector * Community() const //......................................................................... //! If Type() is Bgp4_Attribute_Community, returns the contained //! community attribute. Else asserts. //------------------------------------------------------------------------- const std::vector * Community() const; //------------------------------------------------------------------------- // const std::vector * Community(const std::vector & community) //......................................................................... //! Sets the contained community attribute and returns a pointer to //! it. Automatically sets Type() to Bgp4_Attribute_Community. //------------------------------------------------------------------------- const std::vector * Community(const std::vector & community); //------------------------------------------------------------------------- // const ArtsBgp4DPAttribute * DP() const //......................................................................... //! If Type() is Bgp4_Attribute_DPA, returns a pointer to the //! contained destination preference attribute. Else asserts. //------------------------------------------------------------------------- const ArtsBgp4DPAttribute * DP() const; //------------------------------------------------------------------------- // const ArtsBgp4DPAttribute * DP(const ArtsBgp4DPAttribute & dp) //......................................................................... //! Sets the contained destination preference attribute and returns //! a pointer to it. Automatically sets Type() to Bgp4_Attribute_DPA. //------------------------------------------------------------------------- const ArtsBgp4DPAttribute * DP(const ArtsBgp4DPAttribute & dp); //-------------------------------------------------------------------------- // void DeleteValue() //.......................................................................... //! Deletes internally allocated objects. This has to be smart since //! we have pointers in a discriminate union. //-------------------------------------------------------------------------- void DeleteValue(); //-------------------------------------------------------------------------- // std::istream & read(std::istream & is, uint8_t version = 0) //.......................................................................... //! Reads the contents of an ArtsBgp4Attribute from an istream. //! Returns the istream. //-------------------------------------------------------------------------- std::istream & read(std::istream & is, uint8_t version = 0); //-------------------------------------------------------------------------- // int read(int fd, uint8_t version = 0) //.......................................................................... //! Reads the contents of an ArtsBgp4Attribute 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 contents of an ArtsBgp4Attribute to an ostream. Returns //! the ostream. //-------------------------------------------------------------------------- std::ostream & write(std::ostream & os, uint8_t version = 0) const; //-------------------------------------------------------------------------- // int write(int fd, uint8_t version = 0) const //.......................................................................... //! Writes the contents of an ArtsBgp4Attribute to a file descriptor. //! Returns the number of bytes written on succes,s -1 on failure. //-------------------------------------------------------------------------- int write(int fd, uint8_t version = 0) const; //-------------------------------------------------------------------------- // ArtsBgp4Attribute & operator = (const ArtsBgp4Attribute & bgp4Attr) //.......................................................................... //! Deep copies an ArtsBgp4Attribute. //-------------------------------------------------------------------------- ArtsBgp4Attribute & operator = (const ArtsBgp4Attribute & bgp4Attr); //-------------------------------------------------------------------------- // friend std::ostream & // operator << (std::ostream& os, // const ArtsBgp4Attribute & bgp4Attribute) //.......................................................................... //! Writes an ArtsBgp4Attribute to an ostream in a human-friendly form. //-------------------------------------------------------------------------- friend std::ostream & operator << (std::ostream& os, const ArtsBgp4Attribute & bgp4Attribute); #ifndef NDEBUG //------------------------------------------------------------------------ // static uint32_t NumObjects() //........................................................................ // //------------------------------------------------------------------------ static uint32_t NumObjects() { return(_numObjects); } #endif // NDEBUG private: uint8_t _flags; uint8_t _type; union { ArtsBgp4AsPathAttribute *_asPath; ArtsBgp4AggregatorAttribute *_aggregator; std::vector *_community; ArtsBgp4DPAttribute *_dp; ipv4addr_t _nextHop; uint32_t _MED; uint32_t _localPref; uint8_t _origin; } _value; static uint32_t _numObjects; }; #endif // _ARTSBGP4ATTRIBUTE_HH_