diff --git a/Makefile.am b/Makefile.am index 13aab90..f28d681 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=parser dumper examples +SUBDIRS=parser dumper2 ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 8c0bebd..aff2f49 100644 --- a/configure.ac +++ b/configure.ac @@ -81,6 +81,6 @@ dnl AC_FUNC_REALLOC AC_OUTPUT(Makefile bgpparser.pc parser/Makefile - dumper/Makefile + dumper2/Makefile examples/Makefile ) diff --git a/dumper/AttributeTypeAggregatorDumper.cpp b/dumper/AttributeTypeAggregatorDumper.cpp index 08ebd6a..0e9a07d 100644 --- a/dumper/AttributeTypeAggregatorDumper.cpp +++ b/dumper/AttributeTypeAggregatorDumper.cpp @@ -81,6 +81,6 @@ string AttributeTypeAggregatorDumper::genAscii() node << (int)as << " " << FORMAT_IPv4_ADDRESS( attr->getAggregatorBGPSpeakerIPAddress().ipv4 ); return node.str( ); - } +} // vim: sw=4 ts=4 sts=4 expandtab diff --git a/dumper/BGPMessageDumper.cpp b/dumper/BGPMessageDumper.cpp index 9897565..b2b66ca 100644 --- a/dumper/BGPMessageDumper.cpp +++ b/dumper/BGPMessageDumper.cpp @@ -114,11 +114,11 @@ string BGPMessageDumper::genAscii() string src_addr, dst_addr; switch(afi) { - case AFI_IPv4: + case AFI_IPv4: src_addr=FORMAT_IPv4_ADDRESS( local_addr.ipv4 ); dst_addr=FORMAT_IPv4_ADDRESS( peer_addr.ipv4 ); break; - case AFI_IPv6: + case AFI_IPv6: src_addr=FORMAT_IPv6_ADDRESS( local_addr.ipv6 ); dst_addr=FORMAT_IPv6_ADDRESS( peer_addr.ipv6 ); break; diff --git a/dumper/BGPUpdateDumper.cpp b/dumper/BGPUpdateDumper.cpp index f6467ad..3651574 100644 --- a/dumper/BGPUpdateDumper.cpp +++ b/dumper/BGPUpdateDumper.cpp @@ -126,9 +126,6 @@ list BGPUpdateDumper::genAsciiMsg(string peer_addr, string peer_as, bool BGPUpdatePtr bgp_update = dynamic_pointer_cast( bgp_msg ); list bgp_msg_list; -// list NLRI; -// list WITHDRAWN; - /* BGP Update node */ // Attributes string as_path = ""; @@ -157,7 +154,7 @@ list BGPUpdateDumper::genAsciiMsg(string peer_addr, string peer_as, bool case 6: agg = attr_dumper->genAscii(); break; case 7: aggregator = attr_dumper->genAscii(); break; case 8: communities = attr_dumper->genAscii(); break; - + case 14: mp_reach = attr; break; diff --git a/dumper/Makefile.am b/dumper/Makefile.am index 86fddd9..9813fca 100644 --- a/dumper/Makefile.am +++ b/dumper/Makefile.am @@ -21,33 +21,7 @@ bgpparser_SOURCES = \ FakeBGPUpdate.cpp FakeBGPUpdate.h \ FakeBGPAttribute.cpp FakeBGPAttribute.h \ FakeAttributeTypeMPReachNLRI.cpp FakeAttributeTypeMPReachNLRI.h \ -AttributeTypeASPathDumper.cpp \ -AttributeTypeAggregatorDumper.cpp \ -AttributeTypeAtomicAggregateDumper.cpp \ -AttributeTypeClusterListDumper.cpp \ -AttributeTypeCommunitiesDumper.cpp \ -AttributeTypeDumper.cpp \ -AttributeTypeLocalPrefDumper.cpp \ -AttributeTypeMPReachNLRIDumper.cpp \ -AttributeTypeMPUnreachNLRIDumper.cpp \ -AttributeTypeMultiExitDiscDumper.cpp \ -AttributeTypeNextHopDumper.cpp \ -AttributeTypeOriginDumper.cpp \ -AttributeTypeOriginatorIDDumper.cpp \ -BGPAttributeDumper.cpp \ -BGPDumper.cpp \ -BGPKeepAliveDumper.cpp \ -BGPMessageDumper.cpp \ -BGPNotificationDumper.cpp \ -BGPOpenDumper.cpp \ -BGPRouteRefreshDumper.cpp \ -BGPStateChangeDumper.cpp \ -BGPUpdateDumper.cpp \ -Dumper.cpp \ -MRTBgp4MPMessageDumper.cpp \ -MRTBgp4MPStateChangeDumper.cpp \ -MRTTblDumpV1Dumper.cpp \ -MRTTblDumpV2Dumper.cpp \ -mrt2xml.cpp \ -xmlinternal.c +AsciiVisitor.cpp XMLVisitor.cpp \ +xmlinternal.c \ +main.cpp diff --git a/dumper/mrt2xml.cpp b/dumper/mrt2xml.cpp index 4608774..9d45ea5 100644 --- a/dumper/mrt2xml.cpp +++ b/dumper/mrt2xml.cpp @@ -40,18 +40,9 @@ /* MRT classes */ #include "MRTCommonHeader.h" -#include "MRTBgp4MPStateChange.h" -#include "MRTBgp4MPMessage.h" -#include "MRTTblDump.h" -#include "MRTTblDumpV2PeerIndexTbl.h" #include "Exceptions.h" -/* Dumper class */ -#include "Dumper.h" -#include "MRTTblDumpV1Dumper.h" -#include "MRTTblDumpV2Dumper.h" -#include "MRTBgp4MPMessageDumper.h" -#include "MRTBgp4MPStateChangeDumper.h" +#include "AsciiVisitor.h" //#define MAX_MRT_TYPE_NUM 49 //#define MAX_MRT_SUBTYPE_NUM 6 @@ -256,6 +247,8 @@ int main(int argc, char** argv) unsigned int unTotalBytesRead = 0; + AsciiVisitor visitor; + shared_ptr mrt_tblv2_dumper( new MRTTblDumpV2Dumper() ); while( in.peek()!=-1 ) { @@ -263,118 +256,8 @@ int main(int argc, char** argv) { MRTMessagePtr msg = MRTCommonHeader::newMessage( in ); - switch( msg->getType() ) - { - // -------------------------- // - // TABLE_DUMP // - // -------------------------- // - case TABLE_DUMP: - { -// dump_type = 1; - switch(msg->getSubType()) - { - case AFI_IPv4: - case AFI_IPv6: - { - // Prepare BGP4MP Message pointer ./ - MRTTblDumpPtr tblDump = dynamic_pointer_cast( msg ); - - // Dumper for BGP Message ./ - MRTTblDumpV1DumperPtr mrt_tblv1_dumper( new MRTTblDumpV1Dumper() ); - mrt_tblv1_dumper->setTblDumpMsg( tblDump ); - procMsg( mrt_tblv1_dumper, flag_format, flag_newline, flag_bgpdump ); - } - break; - - default: - LOG4CXX_ERROR( _log, "Undefined Subtype (TABLE_DUMP_V1) :" << msg->getSubType() ); - break; - } - } - break; - - // -------------------------- // - // TABLE_DUMP_V2 // - // -------------------------- // - case TABLE_DUMP_V2: - { -// dump_type = 2; - // Dumper for Table Dumper v2 // - switch (msg->getSubType()) - { - case RIB_IPV4_UNICAST: - case RIB_IPV4_MULTICAST: - case RIB_IPV6_UNICAST: - case RIB_IPV6_MULTICAST: - { - MRTTblDumpV2RibHeaderPtr tblDumpHeader = - dynamic_pointer_cast( msg ); - - mrt_tblv2_dumper->setTblDumpMsg( tblDumpHeader ); - procMsg( mrt_tblv2_dumper, flag_format, flag_newline, flag_bgpdump ); - } - break; - - case PEER_INDEX_TABLE: - { - MRTTblDumpV2PeerIndexTblPtr peerIndexTbl - = dynamic_pointer_cast( msg ); - - mrt_tblv2_dumper->setPeerIndexTbl( peerIndexTbl ); - } - break; - - default: - LOG4CXX_ERROR(_log, "Undefined Subtype (TABLE_DUMP_V2) :" << msg->getSubType() ); - break; - } - break; - } - break; - - // -------------------------- // - // BGP4MP // - // -------------------------- // - case BGP4MP: - { -// dump_type = 0; - switch (msg->getSubType()) - { - case BGP4MP_MESSAGE: - case BGP4MP_MESSAGE_AS4: - { - // Prepare BGP4MP Message pointer ./ - MRTBgp4MPMessagePtr bgp4MPmsg = dynamic_pointer_cast( msg ); - - // Dumper for BGP Message ./ - MRTBgp4MPMessageDumperPtr mrt_bgp4mp_msg_dumper = MRTBgp4MPMessageDumper::newDumper( bgp4MPmsg ); - procMsg( mrt_bgp4mp_msg_dumper, flag_format, flag_newline, flag_bgpdump ); - } - break; - - case BGP4MP_STATE_CHANGE: - case BGP4MP_STATE_CHANGE_AS4: - { - // Prepare BGP4MP State Change pointer // - MRTBgp4MPStateChangePtr bgp4MPmsg = dynamic_pointer_cast( msg ); - - // Dumper for BGP State Change // - MRTBgp4MPStateChangeDumperPtr mrt_bgp4mp_sc_dumper = MRTBgp4MPStateChangeDumper::newDumper( bgp4MPmsg ); - procMsg( mrt_bgp4mp_sc_dumper, flag_format, flag_newline, flag_bgpdump ); - } - break; - - default: - LOG4CXX_ERROR( _log,"Undefined Subtype (BGP4MP) :" << msg->getSubType() ); - break; - } - } - break; - - default: - LOG4CXX_ERROR(_log, "Undefined Type:" << msg->getType()); - break; - } + msg->accept( visitor ); + } catch( BGPParserError &e ) { diff --git a/include/xml.h b/dumper/xml.h similarity index 100% rename from include/xml.h rename to dumper/xml.h diff --git a/include/xmldata.h b/dumper/xmldata.h similarity index 100% rename from include/xmldata.h rename to dumper/xmldata.h diff --git a/include/xmlinternal.h b/dumper/xmlinternal.h similarity index 100% rename from include/xmlinternal.h rename to dumper/xmlinternal.h diff --git a/dumper2/ASSegmentVisitor.cpp b/dumper2/ASSegmentVisitor.cpp new file mode 100644 index 0000000..5b0b50b --- /dev/null +++ b/dumper2/ASSegmentVisitor.cpp @@ -0,0 +1,4 @@ + +#include + +#include "ASSegmentVisitor.h" diff --git a/dumper2/ASSegmentVisitor.h b/dumper2/ASSegmentVisitor.h new file mode 100644 index 0000000..b6541d5 --- /dev/null +++ b/dumper2/ASSegmentVisitor.h @@ -0,0 +1,40 @@ + +#ifndef _ASCII_ATTRS_VISITOR_H_ +#define _ASCII_ATTRS_VISITOR_H_ + +#include + +class ASSegmentVisitor : public GJDepthFirst +{ + virtual boost::any& visit( AttributeTypeASPathSegment &n, boost::any ¶m ) + { + string head = ""; + string tail = ""; + string sep = " "; + + switch( n.getPathSegmentType() ) + { + case AttributeTypeASPathSegment::AS_SEQUENCE: head = ""; tail=""; sep=" "; break; + case AttributeTypeASPathSegment::AS_SET: head = "{"; tail="}", sep=","; break; + case AttributeTypeASPathSegment::AS_CONFED_SEQUENCE: head = "("; tail=")"; sep=" "; break; + case AttributeTypeASPathSegment::AS_CONFED_SET: head = "["; tail="]"; sep=","; break; + } + + ostringstream os; + + os << head; + bool isFirst=true; + BOOST_FOREACH( uint32_t asn, as_seg->getPathSegmentValue() ) + { + if( isFirst ) + isFirst=false; + else + os << sep; + + os << asn; + } + os << tail; + } +}; + +#endif diff --git a/dumper2/AsciiBGPVisitor.cpp b/dumper2/AsciiBGPVisitor.cpp new file mode 100644 index 0000000..787d848 --- /dev/null +++ b/dumper2/AsciiBGPVisitor.cpp @@ -0,0 +1,2 @@ + +#include "AsciiBGPVisitor.h" diff --git a/dumper2/AsciiBGPVisitor.h b/dumper2/AsciiBGPVisitor.h new file mode 100644 index 0000000..df82cc0 --- /dev/null +++ b/dumper2/AsciiBGPVisitor.h @@ -0,0 +1,84 @@ + +#include +#include + +#include "AttrsVisitor.h" + +#include "Params.h" + + +class AsciiBGPVisitor : public AttrsVisitor +{ + virtual void visit( BGPOpen &n, boost::any ¶m ) + { + // prevent visiting optional headers + } + + virtual void visit( BGPUpdate &n, boost::any ¶m ) + { + BOOST_FOREACH( const BGPAttributePtr &attr, n.getPathAttributes() ) + { + attr->accept( *this, param ); + } + + param.afi=AFI_IPv4; + + BOOST_FOREACH( const RoutePtr &route, n.getWithdrawnRoutes() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getNlriRoutes() ) + { + route->accept( *this, param ); + } + } + + virtual void visit( AttributeTypeMPReachNLRI &n, boost::any ¶m ) + { + param.afi = n.getAFI( ); + param.next_hop = FORMAT_IP_ADDRESS( n.getNextHopAddress(), n.getAFI() ); + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getNLRI() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getSNPA() ) + { + route->accept( *this, param ); + } + } + virtual void visit( AttributeTypeMPUnreachNLRI &n, boost::any ¶m ) + { + param.afi = n.getAFI( ); + + BOOST_FOREACH( const NLRIUnReachablePtr &route, n.getNLRI() ) + { + route->accept( *this, param ); + } + } + + virtual void visit( Route &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + + virtual void visit( NLRIReachable &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + virtual void visit( NLRIUnReachable &n, boost::any ¶m ) + { + std::cout + << param.mrt_type << "|" << param.timestamp << "|" + << "W" + "|" + param.peer_addr + "|" + param.peer_as + "|" + n.toString( params.afi ) + << std::endl; + } +}; diff --git a/dumper2/AsciiVisitor.cpp b/dumper2/AsciiVisitor.cpp new file mode 100644 index 0000000..4c4e473 --- /dev/null +++ b/dumper2/AsciiVisitor.cpp @@ -0,0 +1,4 @@ + +#include + +#include diff --git a/dumper2/AsciiVisitor.h b/dumper2/AsciiVisitor.h new file mode 100644 index 0000000..eb2760b --- /dev/null +++ b/dumper2/AsciiVisitor.h @@ -0,0 +1,92 @@ + +#include + +#include "AsciiBGPVisitor.h" + +#include + +class AsciiVisitor : public DepthFirstVisitor +{ + AsciiBGPVisitor _bgpVisitor; + +public: + virtual void visit( MRTBgp4MPMessage &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS() +// n.getLocalAS() +// n.getInterfaceIndex() +// n.getAddressFamily(); +// n.getPeerIP() +// n.getLocalIP() + + n.getPayload()->accept( _bgpVisitor, Info( + "BGP4MP", + n.getTimestamp(), + "A", + FORMAT_IP_ADDRESS( n.getPeerIP(), n.getAddressFamily() ), + n.getPeerAS() + ) ); + } + + virtual void visit( MRTBgp4MPStateChange &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS( ) +// n.getLocalAS( ) +// n.getInterfaceIndex( ) +// n.getAddressFamily( ) +// n.getPeerIP( ) +// n.getLocalIP( ) +// n.getOldState( ) +// n.getNewState( ) + } + + virtual void visit( MRTTblDump &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getViewNumber( ) +// n.getSequenceNumber( ) +// n.getPrefix( ) +// n.getPrefixLength( ) +// n.getStatus( ) +// n.getOriginatedTime( ) +// n.getPeerIP( ) +// n.getPeerAS( ) +// n.getAttributeLength( ) + } + + virtual void visit( MRTTblDumpV2RibHeader &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getSequenceNumber( ) +// n.getPrefixLength( ) +// n.getPrefix( ) +// n.getEntryCount( ) +// n.getAFI( ) +// n.getSAFI( ) + +// n.getPeerIndexTbl() + + BOOST_FOREACH( const TblDumpV2RibEntryPtr &entry, n.getRibEntries() ) + { + entry->accept( *this ); + } + } +}; diff --git a/dumper2/AttrsVisitor.cpp b/dumper2/AttrsVisitor.cpp new file mode 100644 index 0000000..591ba25 --- /dev/null +++ b/dumper2/AttrsVisitor.cpp @@ -0,0 +1,4 @@ + +#include + +#include "AttrsVisitor.h" diff --git a/dumper2/AttrsVisitor.h b/dumper2/AttrsVisitor.h new file mode 100644 index 0000000..1360afe --- /dev/null +++ b/dumper2/AttrsVisitor.h @@ -0,0 +1,141 @@ + +#include +#include + +#include "ASSegmentVisitor.h" + +#include "Params.h" + +class AttrsVisitor : public GJVoidDepthFirst +{ + ASSegmentVisitor _asSegmentVisitor; + + ////////////////////////////////////////////////////////////////////////////// + //////////////////////////////// ORIGIN ////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeOrigin &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + + switch( n.getOrigin( ) ) + { + case IGP: + param.origin="IGP"; + break; + case EGP: + param.origin="EGP"; + break; + default: + param.origin="INCOMPLETE"; + break; + } + } + + ////////////////////////////////////////////////////////////////////////////// + //////////////////////////////// AS PATH ///////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual boost::any& visit( AttributeTypeASPath &n, boost::any ¶m ) + { + ostringstream os; + + bool isFirst=true; + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, /**/n.getPathSegmentsComplete()/**/ ) + { + if( isFirst ) + isFirst=false; + else + os << " "; + + os << segment->accept( _asSegmentVisitor, os ); + } + + param.as_path=os.str( ); + } + + virtual boost::any& visit( AttributeTypeAS4Path &n, boost::any ¶m ) + { + ostringstream os; + + bool isFirst=true; + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, /**/n.getPathSegments()/**/ ) + { + if( isFirst ) + isFirst=false; + else + os << " "; + + os << segment->accept( _asSegmentVisitor, os ); + } + + param.as_path=os.str( ); + } + + ////////////////////////////////////////////////////////////////////////////// + //////////////////////////////// NEXT HOP //////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeNextHop &n, boost::any ¶m ) + { + param.nexthop=FORMAT_IP_ADDRESS( n.getNextHopIPAddress(), n.getNextHopAFI() ); + } + + ////////////////////////////////////////////////////////////////////////////// + ////////////////////////////// MultiExitDisc ///////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeMultiExitDisc &n, boost::any ¶m ) + { + param.med=n.getMultiExitDiscValue( ); + } + + ////////////////////////////////////////////////////////////////////////////// + ////////////////////////////// LOCAL PREF //////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeLocalPref &n, boost::any ¶m ) + { + param.lpref=n.getLocalPrefValue( ); + } + + ////////////////////////////////////////////////////////////////////////////// + /////////////////////////// ATOMIC AGGREGATE //////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeAtomicAggregate &n, boost::any ¶m ) + { + param.agg="AG"; + } + + ////////////////////////////////////////////////////////////////////////////// + ////////////////////////////// AGGREGATOR //////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual boost::any& visit( AttributeTypeAggregator &n, boost::any ¶m ) + { + ostringstream os; + os << (int)n.getAggregatorLastASComplete( ) << " " + << FORMAT_IPv4_ADDRESS( n.getAggregatorBGPSpeakerIPAddress().ipv4 ); + + param.aggregator=os.str( ); + } + + ////////////////////////////////////////////////////////////////////////////// + ////////////////////////////// COMMUNITIES /////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + virtual void visit( AttributeTypeCommunities &n, boost::any ¶m ) + { + ostringstream node; + string sep = ""; + + BOOST_FOREACH( const CommunityValue &value, n.getCommunityValue() ) + { + if( value.ASnum == 0xFFFF && value.info == 0xFF01 ) + { + node << sep << "no-export"; + } + else + { + node << sep << (int)value.ASnum << ":" << (int)value.info; + } + sep = " "; + } + return node.str(); + } +}; diff --git a/dumper2/Makefile.am b/dumper2/Makefile.am new file mode 100644 index 0000000..542a2ad --- /dev/null +++ b/dumper2/Makefile.am @@ -0,0 +1,21 @@ +AM_CPPFLAGS=-I$(top_srcdir)/include \ + $(log4cxx_CFLAGS) \ + $(BOOST_CPPFLAGS) + +bgpparser_LDADD = ../parser/libbgpparser.la + +AM_LDFLAGS = \ + $(log4cxx_LIBS) \ + $(BOOST_LDFLAGS) \ + $(BOOST_SYSTEM_LIB) \ + $(BOOST_FILESYSTEM_LIB) \ + $(BOOST_PROGRAM_OPTIONS_LIB) \ + $(BOOST_REGEX_LIB) \ + $(BOOST_IOSTREAMS_LIB) + +bin_PROGRAMS = bgpparser + +bgpparser_SOURCES = \ +AsciiVisitor.cpp AsciiBGPVisitor.cpp AsciiAttrsVisitor.cpp \ +main.cpp + diff --git a/dumper2/Params.h b/dumper2/Params.h new file mode 100644 index 0000000..ab7e416 --- /dev/null +++ b/dumper2/Params.h @@ -0,0 +1,33 @@ + +#ifndef _PARAMS_H_ +#define _PARAMS_H_ + +struct Info +{ + std::string mrt_type; + uint32_t timestamp; + std::string dump_type; /* B|A|W */ + std::string peer_addr; + uint32_t peer_as; + + std::string as_path ; + std::string origin ; + std::string next_hop ; + uint32_t med ; + uint32_t lpref ; + std::string agg ; + std::string aggregator ; + std::string communities; + + uint8_t afi; + + Info( const std::string &_mrt_type, uint32_t _timestamp, + const std::string &_dump_type, + const std::string &_peer_addr, uint32_t _peer_as ) + : mrt_type(_mrt_type), timestamp(_timestamp), dump_type(_dump_type), + peer_addr(_peer_addr), peer_as(_peer_as), + med(0), lpref(0), agg("NAG") + { } +}; + +#endif diff --git a/dumper2/XMLVisitor.cpp b/dumper2/XMLVisitor.cpp new file mode 100644 index 0000000..ca8bcc8 --- /dev/null +++ b/dumper2/XMLVisitor.cpp @@ -0,0 +1,5 @@ + +#include + +#include + diff --git a/dumper2/XMLVisitor.h b/dumper2/XMLVisitor.h new file mode 100644 index 0000000..5c39b72 --- /dev/null +++ b/dumper2/XMLVisitor.h @@ -0,0 +1,17 @@ + +#ifndef _XMLVISITOR_H_ +#define _XMLVISITOR_H_ + +#include + +//class XMLVisitor : public Visitor +//{ +//// std::string visit( const BGPMessage &msg ); +//// +//// std::string visit( const BGPUpdate &msg ); +//// +//// std::string visit( const ) +// +//}; + +#endif diff --git a/dumper2/bgpparser b/dumper2/bgpparser new file mode 100755 index 0000000..bb6f67e --- /dev/null +++ b/dumper2/bgpparser @@ -0,0 +1,207 @@ +#! /bin/sh + +# bgpparser - temporary wrapper script for .libs/bgpparser +# Generated by libtool (GNU libtool) 2.2.10 +# +# The bgpparser program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.2.10' + notinst_deplibs=' ../parser/libbgpparser.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + file="$0" + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + ECHO="printf %s\\n" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ which is used only on +# windows platforms, and (c) all begin with the string --lt- +# (application programs are unlikely to have options which match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's ../libtool value, followed by no. +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=$0 + shift + for lt_opt + do + case "$lt_opt" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=`$ECHO "X$lt_script_arg0" | /opt/local/bin/gsed -e 's/^X//' -e 's%/[^/]*$%%'` + test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. + lt_dump_F=`$ECHO "X$lt_script_arg0" | /opt/local/bin/gsed -e 's/^X//' -e 's%^.*/%%'` + cat "$lt_dump_D/$lt_dump_F" + exit 0 + ;; + --lt-*) + $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n "$lt_option_debug"; then + echo "bgpparser:bgpparser:${LINENO}: libtool wrapper (GNU libtool) 2.2.10" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + $ECHO "bgpparser:bgpparser:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" + lt_dump_args_N=`expr $lt_dump_args_N + 1` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ + + if test -n "$lt_option_debug"; then + $ECHO "bgpparser:bgpparser:${LINENO}: newargv[0]: $progdir/$program" 1>&2 + func_lt_dump_args ${1+"$@"} 1>&2 + fi + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from $@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + for lt_wr_arg + do + case $lt_wr_arg in + --lt-*) ;; + *) set x "$@" "$lt_wr_arg"; shift;; + esac + shift + done + func_exec_program_core ${1+"$@"} +} + + # Parse options + func_parse_lt_options "$0" ${1+"$@"} + + # Find the directory that this script lives in. + thisdir=`$ECHO "$file" | /opt/local/bin/gsed 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /opt/local/bin/gsed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "$file" | /opt/local/bin/gsed 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "$file" | /opt/local/bin/gsed 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /opt/local/bin/gsed -n 's/.*-> //p'` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /opt/local/bin/gsed 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='bgpparser' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to DYLD_LIBRARY_PATH + DYLD_LIBRARY_PATH="/Users/cawka/Devel/bgpparser/parser/.libs:$DYLD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated DYLD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + DYLD_LIBRARY_PATH=`$ECHO "$DYLD_LIBRARY_PATH" | /opt/local/bin/gsed 's/::*$//'` + + export DYLD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + func_exec_program ${1+"$@"} + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + $ECHO "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/dumper2/main.cpp b/dumper2/main.cpp new file mode 100644 index 0000000..42c47a8 --- /dev/null +++ b/dumper2/main.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2008,2009, University of California, Los Angeles All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NLnetLabs nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include "AsciiVisitor.h" + +#ifdef LOG4CXX +#include +#include +#include +#include +#include +#include +#include +#include +using namespace log4cxx; +using namespace log4cxx::helpers; +#endif + +#include + +#include +namespace fs = boost::filesystem; + +#include +#include +#include +#include +namespace po = boost::program_options; + +#include +#include +#include +#include +#include +#include +#include + +#include +namespace io = boost::iostreams; + +using namespace std; +using namespace boost; + +#ifdef LOG4CXX +static LoggerPtr _log=Logger::getLogger( "bgpparser" ); +#endif + +int main(int argc, char** argv) +{ + uint32_t unFlags = 0; + po::variables_map CONFIG; + + po::options_description opts( "General options" ); + opts.add_options() + ( "help", "Print this help message" ) +#ifdef LOG4CXX + ( "log", po::value(), "log4cxx configuration file" ) +#endif + ( "file", po::value(), + "MRT file or - to input from stdin" ) + ( "format", po::value(), + "Compression format: txt, z, gz, or bz2 (will be overridden by the actual extension of the file)" ) + ; + + po::positional_options_description p; + p.add("file", -1); + + try + { + po::store( po::command_line_parser(argc, argv). + options(opts). + positional(p).run(), + CONFIG ); + } + catch( const po::error &error ) + { + cerr << "ERROR: " << error.what() << endl + << endl + << opts << endl; + + exit( 2 ); + } + + if( CONFIG.count("help")>0 ) + { + cout << opts << endl; + exit( 0 ); + } + +#ifdef LOG4CXX + // configure Logger + if( CONFIG.count("log")>0 ) + PropertyConfigurator::configureAndWatch( CONFIG["log"].as() ); + else if( fs::exists("log4cxx.properties") ) + PropertyConfigurator::configureAndWatch( "log4cxx.properties" ); + else + { +// PatternLayoutPtr layout ( new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n") ); +// ConsoleAppenderPtr appender ( new ConsoleAppender( layout ) ); + +// BasicConfigurator::configure( appender ); + Logger::getRootLogger()->setLevel( log4cxx::Level::getOff() ); + } +#endif + + if( CONFIG.count("file")==0 ) + { + cerr << "ERROR: Input file should be specified" << endl + << endl + << opts << endl; + exit( 1 ); + } + + //////////////////////////////////////////////////////////////////////////// + string format=CONFIG.count("format")>0 ? CONFIG["format"].as( ) : ""; + //////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////// + string filename=CONFIG["file"].as(); + smatch m; + if( regex_match(filename, m, regex("^.*\\.(gz|bz2)$")) ) format=m[1]; + //////////////////////////////////////////////////////////////////////////// + + io::filtering_stream in; + + if( format=="gz" ) + { + LOG4CXX_DEBUG( _log, "Input file has GZIP format" ); + in.push( io::gzip_decompressor() ); + } + else if( format=="bz2" ) + { + LOG4CXX_DEBUG( _log, "Input file has BZIP2 format" ); + in.push( io::bzip2_decompressor() ); + } + + ifstream input_file( filename.c_str(), ios_base::in | ios_base::binary ); + if( !input_file.is_open() ) + { + cerr << "ERROR: " << "cannot open file [" << filename << "] for reading" << endl + << endl; + exit( 3 ); + } + + if( filename=="-" ) + in.push( cin ); + else + in.push( input_file ); + + AsciiVisitor ascii; + + int i=1; + int mrt_id=0; + try + { + while( in.peek()!=-1 ) + { + mrt_id++; + + MRTMessagePtr msg=MRTCommonHeader::newMessage( in ); + msg->accept( ascii ) ; + } + } + catch( EOFException e ) + { + LOG4CXX_DEBUG( _log, "EOF" ); + ; //do nothing + } +// catch( io::gzip_error e ) +// catch( io::bzip2_error e ) + catch( std::istream::failure e ) + { + cerr << "ERROR: " << e.what() << endl; + exit( 10 ); + } + catch( BGPParserError &e ) + { +// cerr << "ERROR in MRT #"< -#include -#else -#include -#endif /* WIN32 */ - -#include "MRTStructure.h" - -class MRTBgp4MPEntry : - public MRTCommonHeader -{ -public: - MRTBgp4MPEntry( MRTCommonHeader &header, std::istream &input ); - virtual ~MRTBgp4MPEntry(void); - -protected: - uint16_t viewNumber; - uint16_t status; - uint32_t timeLastChange; - uint16_t addressFamily; - uint8_t safi; - uint8_t prefixLength; - -private: - static log4cxx::LoggerPtr Logger; -}; - -#endif /* _MRTBGP4MPENTRY_H_ */ diff --git a/include/MRTBgp4MPSnapshot.h b/include/MRTBgp4MPSnapshot.h deleted file mode 100644 index 8d3d5a1..0000000 --- a/include/MRTBgp4MPSnapshot.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2008,2009, University of California, Los Angeles All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NLnetLabs nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MRTBGP4MPSNAPSHOT_H_ -#define _MRTBGP4MPSNAPSHOT_H_ - -#include "MRTCommonHeader.h" -#include "MRTStructure.h" - -class MRTBgp4MPSnapshot : - public MRTCommonHeader -{ -public: - MRTBgp4MPSnapshot(MRTCommonHeader &header, std::istream &input); - ~MRTBgp4MPSnapshot(void); - - uint16_t getViewNumber(void) const { return viewNumber; } - const std::string& getFileName(void) const { return fileName; } - -protected: - uint16_t viewNumber; - std::string fileName; - -private: - static log4cxx::LoggerPtr Logger; -}; - -#endif /* _MRTBGP4MPSNAPSHOT_H_ */ diff --git a/include/bgpparser.h b/include/bgpparser.h index 3d83fde..9924256 100644 --- a/include/bgpparser.h +++ b/include/bgpparser.h @@ -33,9 +33,23 @@ #include #endif +#include +#include + #include #include #include +#include +#include + +#include "visitors/Visitor.h" +#include "visitors/GJVoidVisitor.h" +#include "visitors/GJNoArguVisitor.h" +#include "visitors/GJVisitor.h" + +#include "parsers/Node.h" + +#include "Exceptions.h" #ifdef LOG4CXX #include @@ -50,7 +64,6 @@ namespace log4cxx } } -#include #define LOG4CXX_INFO(logger,msg) { } #define LOG4CXX_FATAL(logger,msg) { } #define LOG4CXX_WARN(logger,msg) { } @@ -70,10 +83,27 @@ namespace log4cxx #include #endif /* WIN32 */ - #define BITMASK_8 0x000000FF #define BITMASK_16 0x0000FFFF +/* IP addresses... consider moving to common code */ +typedef union _IPAddress { + in_addr ipv4; + in6_addr ipv6; +} IPAddress; + +/* Address Families... consider moving to common code */ +enum { + AFI_IPv4 = 1, + AFI_IPv6 = 2 +}; + + +/* MULTICAST/UNICAST */ +enum { + SAFI_UNICAST = 1, + SAFI_MULTICAST = 2 +}; #ifdef DEBUG # define _PRINT_HEX_VALL(l,x,name) { if( l>=DBG_LEVEL ) { printf(" %s value: 0x%02x%02x%02x%02x\n", name, \ @@ -138,4 +168,19 @@ inline std::string FORMAT_IPv6_ADDRESS( in6_addr addr ) return boost::asio::ip::address_v6( ipv6 ).to_string( ); } +inline std::string FORMAT_IP_ADDRESS( IPAddress addr, int afi ) +{ + std::string addr_str; + switch( afi ) + { + case AFI_IPv4: + addr_str=FORMAT_IPv4_ADDRESS( addr.ipv4 ); + break; + case AFI_IPv6: + addr_str=FORMAT_IPv6_ADDRESS( addr.ipv6 ); + break; + } + return addr_str; +} + #endif diff --git a/include/AttributeTypeDumper.h b/include/dumpers/AttributeTypeDumper.h similarity index 100% rename from include/AttributeTypeDumper.h rename to include/dumpers/AttributeTypeDumper.h diff --git a/include/BGPAttributeDumper.h b/include/dumpers/BGPAttributeDumper.h similarity index 100% rename from include/BGPAttributeDumper.h rename to include/dumpers/BGPAttributeDumper.h diff --git a/include/BGPDumper.h b/include/dumpers/BGPDumper.h similarity index 100% rename from include/BGPDumper.h rename to include/dumpers/BGPDumper.h diff --git a/include/BGPMessageDumper.h b/include/dumpers/BGPMessageDumper.h similarity index 100% rename from include/BGPMessageDumper.h rename to include/dumpers/BGPMessageDumper.h diff --git a/include/BGPStateChangeDumper.h b/include/dumpers/BGPStateChangeDumper.h similarity index 100% rename from include/BGPStateChangeDumper.h rename to include/dumpers/BGPStateChangeDumper.h diff --git a/include/Dumper.h b/include/dumpers/Dumper.h similarity index 100% rename from include/Dumper.h rename to include/dumpers/Dumper.h diff --git a/include/FakeAttributeTypeMPReachNLRI.h b/include/dumpers/FakeAttributeTypeMPReachNLRI.h similarity index 100% rename from include/FakeAttributeTypeMPReachNLRI.h rename to include/dumpers/FakeAttributeTypeMPReachNLRI.h diff --git a/include/FakeBGPAttribute.h b/include/dumpers/FakeBGPAttribute.h similarity index 100% rename from include/FakeBGPAttribute.h rename to include/dumpers/FakeBGPAttribute.h diff --git a/include/FakeBGPUpdate.h b/include/dumpers/FakeBGPUpdate.h similarity index 100% rename from include/FakeBGPUpdate.h rename to include/dumpers/FakeBGPUpdate.h diff --git a/include/MRTBgp4MPMessageDumper.h b/include/dumpers/MRTBgp4MPMessageDumper.h similarity index 100% rename from include/MRTBgp4MPMessageDumper.h rename to include/dumpers/MRTBgp4MPMessageDumper.h diff --git a/include/MRTBgp4MPStateChangeDumper.h b/include/dumpers/MRTBgp4MPStateChangeDumper.h similarity index 100% rename from include/MRTBgp4MPStateChangeDumper.h rename to include/dumpers/MRTBgp4MPStateChangeDumper.h diff --git a/include/MRTTblDumpV1Dumper.h b/include/dumpers/MRTTblDumpV1Dumper.h similarity index 100% rename from include/MRTTblDumpV1Dumper.h rename to include/dumpers/MRTTblDumpV1Dumper.h diff --git a/include/MRTTblDumpV2Dumper.h b/include/dumpers/MRTTblDumpV2Dumper.h similarity index 100% rename from include/MRTTblDumpV2Dumper.h rename to include/dumpers/MRTTblDumpV2Dumper.h diff --git a/include/AttributeType.h b/include/parsers/AttributeType.h similarity index 87% rename from include/AttributeType.h rename to include/parsers/AttributeType.h index 7c190ff..114a0cb 100644 --- a/include/AttributeType.h +++ b/include/parsers/AttributeType.h @@ -37,7 +37,7 @@ class AttributeType; typedef boost::shared_ptr AttributeTypePtr; -class AttributeType +class AttributeType : public Node { public: virtual ~AttributeType( ); @@ -46,16 +46,20 @@ class AttributeType static AttributeTypePtr newAttribute(uint8_t type, uint16_t len, std::istream &input, bool isAS4); static std::string getTypeStr(uint8_t attrType); - uint16_t getLength() { return length; } + uint16_t getLength() const { return length; } const boost::shared_ptr &getData() const { return data; } -// uint8_t hasError() { return error; } -// void setValue(uint8_t* value) { this->value = value; }; - bool getAS4() { return isAS4; } + bool getAS4() const { return isAS4; } void setAS4(bool isAS4) { this->isAS4 = isAS4; }; + virtual void printMe() { /*cout << "AttributeType Default";*/ }; virtual void printMeCompact() { /*cout << "AttributeType Default";*/ }; // virtual AttributeType* clone() { /*cout << "Cloning AttributeType" << endl;*/ return new AttributeType(length, value, isAS4); } + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + enum AttributeTypeCode { ORIGIN = 1, diff --git a/include/AttributeTypeAS4Aggregator.h b/include/parsers/AttributeTypeAS4Aggregator.h similarity index 88% rename from include/AttributeTypeAS4Aggregator.h rename to include/parsers/AttributeTypeAS4Aggregator.h index 6768bec..964d749 100644 --- a/include/AttributeTypeAS4Aggregator.h +++ b/include/parsers/AttributeTypeAS4Aggregator.h @@ -45,10 +45,15 @@ class AttributeTypeAS4Aggregator : void setAggregatorLastAS(uint32_t aggregatorLastAS) { this->aggregatorLastAS = aggregatorLastAS; }; IPAddress getAggregatorBGPSpeakerIPAddress(void) const { return bgpSpeakerIPAddress; }; void setAggregatorBGPSpeakerIPAddress(IPAddress *bgpSpeakerIPAddress) { memcpy(&(this->bgpSpeakerIPAddress.ipv4), bgpSpeakerIPAddress, sizeof(bgpSpeakerIPAddress->ipv4)); }; - //void setAggregatorBGPSpeakerIPAddress(IPAddress *); + virtual void printMe(); virtual void printMeCompact(); - + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint32_t aggregatorLastAS; IPAddress bgpSpeakerIPAddress; diff --git a/include/AttributeTypeAS4Path.h b/include/parsers/AttributeTypeAS4Path.h similarity index 82% rename from include/AttributeTypeAS4Path.h rename to include/parsers/AttributeTypeAS4Path.h index dc8d8bb..d4c02f8 100644 --- a/include/AttributeTypeAS4Path.h +++ b/include/parsers/AttributeTypeAS4Path.h @@ -42,6 +42,11 @@ class AttributeTypeAS4PathSegment : public AttributeTypeASPathSegment AttributeTypeAS4PathSegment( std::istream &input ) : AttributeTypeASPathSegment(input,true) { } virtual void printMeCompact( ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; @@ -68,10 +73,14 @@ class AttributeTypeAS4Path : virtual void printMe(); virtual void printMeCompact(); -// virtual AttributeType* clone(); uint32_t getCountOfASNs( ) const; + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: std::list pathSegments; diff --git a/include/AttributeTypeASPath.h b/include/parsers/AttributeTypeASPath.h similarity index 85% rename from include/AttributeTypeASPath.h rename to include/parsers/AttributeTypeASPath.h index e0d6b79..1e4727f 100644 --- a/include/AttributeTypeASPath.h +++ b/include/parsers/AttributeTypeASPath.h @@ -39,7 +39,7 @@ class AttributeTypeAS4Path; const int AS_TRANS=23456; -class AttributeTypeASPathSegment +class AttributeTypeASPathSegment : public Node { public: AttributeTypeASPathSegment( std::istream &input, bool is4byte ); @@ -68,6 +68,11 @@ class AttributeTypeASPathSegment virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint8_t pathSegmentType; uint8_t pathSegmentLength; // Number of path segments (not octets!) @@ -95,7 +100,12 @@ class AttributeTypeASPath : virtual void printMeCompact(); uint32_t getCountOfASNs( ) const; - + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: std::list pathSegments; std::list pathSegmentsComplete; diff --git a/include/AttributeTypeAggregator.h b/include/parsers/AttributeTypeAggregator.h similarity index 89% rename from include/AttributeTypeAggregator.h rename to include/parsers/AttributeTypeAggregator.h index 91cbd85..916b790 100644 --- a/include/AttributeTypeAggregator.h +++ b/include/parsers/AttributeTypeAggregator.h @@ -50,11 +50,15 @@ class AttributeTypeAggregator : void setAggregatorLastASComplete() { this->aggregatorLastASComplete = this->aggregatorLastAS; }; IPAddress getAggregatorBGPSpeakerIPAddress(void) const { return bgpSpeakerIPAddress; }; -// void setAggregatorBGPSpeakerIPAddress(IPAddress *bgpSpeakerIPAddress) { memcpy(&(this->bgpSpeakerIPAddress.ipv4), bgpSpeakerIPAddress, sizeof(bgpSpeakerIPAddress->ipv4)); }; - //void setAggregatorBGPSpeakerIPAddress(IPAddress *); + virtual void printMe(); virtual void printMeCompact(); - + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint32_t aggregatorLastAS; uint32_t aggregatorLastASComplete; diff --git a/include/AttributeTypeAtomicAggregate.h b/include/parsers/AttributeTypeAtomicAggregate.h similarity index 86% rename from include/AttributeTypeAtomicAggregate.h rename to include/parsers/AttributeTypeAtomicAggregate.h index 9113274..5160165 100644 --- a/include/AttributeTypeAtomicAggregate.h +++ b/include/parsers/AttributeTypeAtomicAggregate.h @@ -43,6 +43,11 @@ class AttributeTypeAtomicAggregate : virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/AttributeTypeClusterList.h b/include/parsers/AttributeTypeClusterList.h similarity index 87% rename from include/AttributeTypeClusterList.h rename to include/parsers/AttributeTypeClusterList.h index d76b219..76f5501 100644 --- a/include/AttributeTypeClusterList.h +++ b/include/parsers/AttributeTypeClusterList.h @@ -45,6 +45,11 @@ class AttributeTypeClusterList : public AttributeType virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: std::list cluster_list; diff --git a/include/AttributeTypeCommunities.h b/include/parsers/AttributeTypeCommunities.h similarity index 85% rename from include/AttributeTypeCommunities.h rename to include/parsers/AttributeTypeCommunities.h index 68ba621..4bd4323 100644 --- a/include/AttributeTypeCommunities.h +++ b/include/parsers/AttributeTypeCommunities.h @@ -53,12 +53,17 @@ class AttributeTypeCommunities : AttributeTypeCommunities(AttributeType &header, std::istream &input); virtual ~AttributeTypeCommunities(void); - const std::list& getCommunityValue(void) const { return communityValues; }; + const std::list& getCommunityValues(void) const { return communityValues; }; // void setCommunityValue(CommunityValue communityVal) { this->communityValues->push_back(communityVal); }; void printMe(); void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: std::list communityValues; diff --git a/include/AttributeTypeExtCommunities.h b/include/parsers/AttributeTypeExtCommunities.h similarity index 84% rename from include/AttributeTypeExtCommunities.h rename to include/parsers/AttributeTypeExtCommunities.h index dbcf0e0..f9f8ca3 100644 --- a/include/AttributeTypeExtCommunities.h +++ b/include/parsers/AttributeTypeExtCommunities.h @@ -50,12 +50,17 @@ class AttributeTypeExtCommunities : AttributeTypeExtCommunities( AttributeType &header, std::istream &input ); virtual ~AttributeTypeExtCommunities( ); - const std::list& getExtCommunityValue(void) const { return extCommunityValues; }; + const std::list& getExtCommunityValues(void) const { return extCommunityValues; }; // void setExtCommunityValue(ExtCommunityValue ExtCommunityVal) { this->extCommunityValues->push_back(ExtCommunityVal); }; void printMe(); void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: std::list extCommunityValues; diff --git a/include/AttributeTypeLocalPref.h b/include/parsers/AttributeTypeLocalPref.h similarity index 87% rename from include/AttributeTypeLocalPref.h rename to include/parsers/AttributeTypeLocalPref.h index ca92ae2..407a403 100644 --- a/include/AttributeTypeLocalPref.h +++ b/include/parsers/AttributeTypeLocalPref.h @@ -42,9 +42,15 @@ class AttributeTypeLocalPref : uint32_t getLocalPrefValue(void) const { return localPref; }; void setLocalPrefValue(uint32_t val) { localPref = val; }; + void printMe(); void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint32_t localPref; diff --git a/include/AttributeTypeMPReachNLRI.h b/include/parsers/AttributeTypeMPReachNLRI.h similarity index 91% rename from include/AttributeTypeMPReachNLRI.h rename to include/parsers/AttributeTypeMPReachNLRI.h index 0384b5b..8578c93 100644 --- a/include/AttributeTypeMPReachNLRI.h +++ b/include/parsers/AttributeTypeMPReachNLRI.h @@ -65,8 +65,10 @@ class AttributeTypeMPReachNLRI : virtual void printMe(); virtual void printMeCompact(); -// void setCorrupt(bool c) { corrupt = c; }; -// bool getCorrupt(void) { return corrupt; }; + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } protected: /* @todo Right now nextHopAddress and nextHopAddress are set to be invalid !!! */ diff --git a/include/AttributeTypeMPUnreachNLRI.h b/include/parsers/AttributeTypeMPUnreachNLRI.h similarity index 89% rename from include/AttributeTypeMPUnreachNLRI.h rename to include/parsers/AttributeTypeMPUnreachNLRI.h index 872c9c6..1fe263e 100644 --- a/include/AttributeTypeMPUnreachNLRI.h +++ b/include/parsers/AttributeTypeMPUnreachNLRI.h @@ -56,6 +56,11 @@ class AttributeTypeMPUnreachNLRI : bool getCorrupt(void) { return corrupt; }; void setCorrupt(bool c) { corrupt = c; }; + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint16_t afi; uint8_t safi; diff --git a/include/AttributeTypeMultiExitDisc.h b/include/parsers/AttributeTypeMultiExitDisc.h similarity index 87% rename from include/AttributeTypeMultiExitDisc.h rename to include/parsers/AttributeTypeMultiExitDisc.h index cd67a3f..c48ac17 100644 --- a/include/AttributeTypeMultiExitDisc.h +++ b/include/parsers/AttributeTypeMultiExitDisc.h @@ -46,6 +46,11 @@ class AttributeTypeMultiExitDisc : void printMe(); void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint32_t discriminator; diff --git a/include/AttributeTypeNextHop.h b/include/parsers/AttributeTypeNextHop.h similarity index 87% rename from include/AttributeTypeNextHop.h rename to include/parsers/AttributeTypeNextHop.h index 823d3d3..da99f52 100644 --- a/include/AttributeTypeNextHop.h +++ b/include/parsers/AttributeTypeNextHop.h @@ -48,6 +48,11 @@ class AttributeTypeNextHop : virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: IPAddress nextHop; uint16_t afi; diff --git a/include/AttributeTypeOrigin.h b/include/parsers/AttributeTypeOrigin.h similarity index 87% rename from include/AttributeTypeOrigin.h rename to include/parsers/AttributeTypeOrigin.h index ac4759e..1c0aa2a 100644 --- a/include/AttributeTypeOrigin.h +++ b/include/parsers/AttributeTypeOrigin.h @@ -50,7 +50,12 @@ class AttributeTypeOrigin : public AttributeType virtual void printMe(); virtual void printMeCompact(); // virtual AttributeType* clone() { return new AttributeTypeOrigin(length, origin, value); } - + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: Origin origin; diff --git a/include/AttributeTypeOriginatorID.h b/include/parsers/AttributeTypeOriginatorID.h similarity index 87% rename from include/AttributeTypeOriginatorID.h rename to include/parsers/AttributeTypeOriginatorID.h index 2a2bec8..662aae3 100644 --- a/include/AttributeTypeOriginatorID.h +++ b/include/parsers/AttributeTypeOriginatorID.h @@ -43,6 +43,11 @@ class AttributeTypeOriginatorID : public AttributeType virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint32_t originator_id; diff --git a/include/BGPAttribute.h b/include/parsers/BGPAttribute.h similarity index 78% rename from include/BGPAttribute.h rename to include/parsers/BGPAttribute.h index ac06030..c2559eb 100644 --- a/include/BGPAttribute.h +++ b/include/parsers/BGPAttribute.h @@ -35,7 +35,7 @@ #include "BGPStructure.h" #include "AttributeType.h" -class BGPAttribute +class BGPAttribute : public Node { public: BGPAttribute( std::istream &input, bool isAS4 ); @@ -54,27 +54,30 @@ class BGPAttribute void setAttributeLength(uint16_t attribLength) { isExtendedLength() ? attributeLength.twoOctet = attribLength : attributeLength.oneOctet = BITMASK_8 & attribLength; }; - AttributeTypePtr getAttributeValue(void) const { return value; }; - AttributeTypePtr getAttributeValueMutable(void) { return value; }; -// // The instance takes ownership of value. -// void setAttributeValue(AttributeType *value) { this->value = value; }; + AttributeTypePtr getAttributeValue( ) const { return value; }; + AttributeTypePtr getAttributeValueMutable( ) { return value; }; int totalSize() { return sizeof(attributeFlags) + sizeof(attributeTypeCode) + (isExtendedLength() ? 2 : 1) + getAttributeLength(); } - bool isOptional(void) const { return ((attributeFlags & 0x80) == 0) ? false : true; }; - bool isWellKnown(void) const { return !isOptional(); }; - bool isTransitive(void) const { return ((attributeFlags & 0x40) == 0) ? false : true; }; - bool isNonTransitive(void) const { return !isTransitive(); }; - bool isPartial(void) const { return ((attributeFlags & 0x20) == 0) ? false : true; }; - bool isComplete(void) const { return !isPartial(); }; - bool isExtendedLength(void) const { return ((attributeFlags & 0x10) == 0) ? false : true; }; + bool isOptional( ) const { return ((attributeFlags & 0x80) == 0) ? false : true; }; + bool isWellKnown( ) const { return !isOptional(); }; + bool isTransitive( ) const { return ((attributeFlags & 0x40) == 0) ? false : true; }; + bool isNonTransitive( ) const { return !isTransitive(); }; + bool isPartial( ) const { return ((attributeFlags & 0x20) == 0) ? false : true; }; + bool isComplete( ) const { return !isPartial(); }; + bool isExtendedLength( ) const { return ((attributeFlags & 0x10) == 0) ? false : true; }; virtual void printMe() { value->printMe(); }; virtual void printMeCompact() { value->printMeCompact(); }; + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: BGPAttribute( uint8_t flags, uint8_t code, uint16_t len, const AttributeTypePtr &_value ) : attributeFlags(flags), attributeTypeCode(code), value(_value) { attributeLength.twoOctet=len; } diff --git a/include/BGPCommonHeader.h b/include/parsers/BGPCommonHeader.h similarity index 93% rename from include/BGPCommonHeader.h rename to include/parsers/BGPCommonHeader.h index e6eb9fe..9950851 100644 --- a/include/BGPCommonHeader.h +++ b/include/parsers/BGPCommonHeader.h @@ -176,7 +176,7 @@ class BGPCommonHeader; typedef BGPCommonHeader BGPMessage; typedef boost::shared_ptr BGPMessagePtr; -class BGPCommonHeader /* AKA BGPMessage */ +class BGPCommonHeader /* AKA BGPMessage */ : public Node { public: enum BGP_MESSAGE_TYPE @@ -197,9 +197,9 @@ class BGPCommonHeader /* AKA BGPMessage */ virtual std::string TypeStr() { return "UNKNOWN"; }; // // Getters and Setters - uint8_t* getMarker() { return marker; } - uint16_t getLength() { return length; } - uint8_t getType() { return type; } + const uint8_t* getMarker() const { return marker; } + uint16_t getLength() const { return length; } + uint8_t getType() const { return type; } const boost::shared_ptr &getData() const { return data; } // uint8_t hasError() { return error; } @@ -209,6 +209,11 @@ class BGPCommonHeader /* AKA BGPMessage */ // Factory method for creating a BGP message instance. static BGPMessagePtr newMessage( std::istream &input, bool isAS4 ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: BGPCommonHeader( uint8_t type ); diff --git a/include/BGPKeepAlive.h b/include/parsers/BGPKeepAlive.h similarity index 86% rename from include/BGPKeepAlive.h rename to include/parsers/BGPKeepAlive.h index f44bf98..a94a15d 100644 --- a/include/BGPKeepAlive.h +++ b/include/parsers/BGPKeepAlive.h @@ -45,6 +45,11 @@ class BGPKeepAlive: public BGPCommonHeader virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: private: diff --git a/include/BGPNotification.h b/include/parsers/BGPNotification.h similarity index 81% rename from include/BGPNotification.h rename to include/parsers/BGPNotification.h index de606a4..5c9e6be 100644 --- a/include/BGPNotification.h +++ b/include/parsers/BGPNotification.h @@ -41,15 +41,18 @@ class BGPNotification : virtual BGP_MESSAGE_TYPE Type() { return NOTIFICATION; } virtual std::string TypeStr() { return "NOTIFICATION"; }; - uint32_t getErrorCode(void) const { return errorCode; }; - void setErrorCode(uint32_t errorCode) { this->errorCode = errorCode; }; - uint32_t getSubErrorCode(void) const { return subErrorCode; }; - void setSubErrorCode(uint32_t subErrorCode) { this->subErrorCode = subErrorCode; }; + uint32_t getErrorCode( ) const { return errorCode; }; + uint32_t getSubErrorCode( ) const { return subErrorCode; }; + const boost::shared_ptr getData( ) const { return data; }; - // TODO: add data getter/setter functions - const boost::shared_ptr getData(void) const { return data; }; virtual void printMe(); virtual void printMeCompact(); + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint8_t errorCode; uint8_t subErrorCode; diff --git a/include/BGPOpen.h b/include/parsers/BGPOpen.h similarity index 73% rename from include/BGPOpen.h rename to include/parsers/BGPOpen.h index 5734c4f..4a97b64 100644 --- a/include/BGPOpen.h +++ b/include/parsers/BGPOpen.h @@ -31,6 +31,8 @@ #define __BGPOpen_H__ #include "BGPCommonHeader.h" +#include "OptionalParameter.h" +#include class BGPOpen : public BGPCommonHeader { @@ -41,11 +43,23 @@ class BGPOpen : public BGPCommonHeader virtual BGP_MESSAGE_TYPE Type() { return OPEN; } virtual std::string TypeStr() { return "OPEN"; }; - bool isAS4Supported( ) const { return isAS4; } + uint8_t getVersion( ) const { return version; } + uint16_t getMyAS( ) const { return myAS; } + uint16_t getHoldTime( ) const { return holdTime; } + uint32_t getBgpId( ) const { return bgpId; } + uint8_t getOptParmLen( ) const { return optParmLen; } + bool isAS4Supported( ) const { return isAS4; } + + const std::list& getOptParams( ) const { return optParams; } virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint8_t version; uint16_t myAS; @@ -53,6 +67,7 @@ class BGPOpen : public BGPCommonHeader uint32_t bgpId; uint8_t optParmLen; + std::list optParams; bool isAS4; private: diff --git a/include/BGPRouteRefresh.h b/include/parsers/BGPRouteRefresh.h similarity index 82% rename from include/BGPRouteRefresh.h rename to include/parsers/BGPRouteRefresh.h index 8731cc0..8a4c207 100644 --- a/include/BGPRouteRefresh.h +++ b/include/parsers/BGPRouteRefresh.h @@ -34,8 +34,6 @@ class BGPRouteRefresh : public BGPCommonHeader { - - public: BGPRouteRefresh( BGPCommonHeader &header, std::istream &input ); virtual ~BGPRouteRefresh(); @@ -43,9 +41,18 @@ class BGPRouteRefresh : public BGPCommonHeader virtual BGP_MESSAGE_TYPE Type() { return ROUTE_REFRESH; } virtual std::string TypeStr() { return "ROUTE_REFRESH"; }; + uint16_t getAfi( ) const { return afi; } + uint8_t getRes( ) const { return res; } + uint8_t getSafi( ) const { return safi; } + virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint16_t afi; uint8_t res; diff --git a/include/BGPStructure.h b/include/parsers/BGPStructure.h similarity index 76% rename from include/BGPStructure.h rename to include/parsers/BGPStructure.h index 19f6f5b..6d204fa 100644 --- a/include/BGPStructure.h +++ b/include/parsers/BGPStructure.h @@ -37,7 +37,7 @@ #include -class Route +class Route : public Node { public: Route( uint8_t aLength, std::istream &input ); @@ -54,6 +54,11 @@ class Route void printMe(uint16_t afi=AFI_IPv4); void printMeCompact(uint16_t afi=AFI_IPv4); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: Route( ) {} @@ -82,6 +87,11 @@ class NLRIReachable : public Route NLRIReachable(uint8_t aLength, IPAddress aPrefix) : Route(aLength, aPrefix) {} ~NLRIReachable() {} + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } }; typedef boost::shared_ptr NLRIReachablePtr; @@ -94,6 +104,11 @@ class NLRIUnReachable : public Route NLRIUnReachable(uint8_t aLength, IPAddress aPrefix): Route(aLength, aPrefix) {} ~NLRIUnReachable() {} + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } }; typedef boost::shared_ptr NLRIUnReachablePtr; diff --git a/include/BGPUpdate.h b/include/parsers/BGPUpdate.h similarity index 86% rename from include/BGPUpdate.h rename to include/parsers/BGPUpdate.h index 36fe762..88a336b 100644 --- a/include/BGPUpdate.h +++ b/include/parsers/BGPUpdate.h @@ -45,8 +45,8 @@ class BGPUpdate: public BGPCommonHeader virtual std::string TypeStr() { return "UPDATE"; }; inline uint16_t getWithdrawnRoutesLength() { return withdrawnRoutesLength; } - inline uint16_t getPathAttributesLength() { return pathAttributesLength; } - inline uint16_t getNlriLength() { return nlriLength; } + inline uint16_t getPathAttributesLength() { return pathAttributesLength; } + inline uint16_t getNlriLength() { return nlriLength; } const std::list& getPathAttributes() { return pathAttributes; } const std::list& getWithdrawnRoutes() { return withdrawnRoutes; } @@ -55,6 +55,11 @@ class BGPUpdate: public BGPCommonHeader virtual void printMe(); virtual void printMeCompact(); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: BGPUpdate( ); diff --git a/include/MRTBgp4MPMessage.h b/include/parsers/MRTBgp4MPMessage.h similarity index 70% rename from include/MRTBgp4MPMessage.h rename to include/parsers/MRTBgp4MPMessage.h index 59f18fe..730468f 100644 --- a/include/MRTBgp4MPMessage.h +++ b/include/parsers/MRTBgp4MPMessage.h @@ -49,15 +49,20 @@ class MRTBgp4MPMessage : MRTBgp4MPMessage( MRTCommonHeader &header, std::istream &is ); virtual ~MRTBgp4MPMessage(void); - uint32_t getPeerAS(void) const; - uint32_t getLocalAS(void) const; - uint16_t getInterfaceIndex(void) const; - uint16_t getAddressFamily(void) const; - IPAddress getPeerIP(void) const; - IPAddress getLocalIP(void) const; + inline uint32_t getPeerAS(void) const; + inline uint32_t getLocalAS(void) const; + inline uint16_t getInterfaceIndex(void) const; + inline uint16_t getAddressFamily(void) const; + inline IPAddress getPeerIP(void) const; + inline IPAddress getLocalIP(void) const; BGPMessagePtr getPayload( ) const { return payload; }; + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: MRTBgp4MPMessage( MRTCommonHeader &header ) : MRTCommonHeader( header ) { ; } void processIPs( std::istream &input ); @@ -81,4 +86,30 @@ class MRTBgp4MPMessage : typedef boost::shared_ptr MRTBgp4MPMessagePtr; +/////////////////////////////////////////////////////////////////////////// + +uint32_t MRTBgp4MPMessage::getPeerAS(void) const { + return peerAS; +} + +uint32_t MRTBgp4MPMessage::getLocalAS(void) const { + return localAS; +} + +uint16_t MRTBgp4MPMessage::getInterfaceIndex(void) const { + return interfaceIndex; +} + +uint16_t MRTBgp4MPMessage::getAddressFamily(void) const { + return addressFamily; +} + +IPAddress MRTBgp4MPMessage::getPeerIP(void) const { + return peerIP; +} + +IPAddress MRTBgp4MPMessage::getLocalIP(void) const { + return localIP; +} + #endif /* _MRTBGP4MPMESSAGE_H_ */ diff --git a/include/MRTBgp4MPMessageAS4.h b/include/parsers/MRTBgp4MPMessageAS4.h similarity index 84% rename from include/MRTBgp4MPMessageAS4.h rename to include/parsers/MRTBgp4MPMessageAS4.h index f7d8723..70fac45 100644 --- a/include/MRTBgp4MPMessageAS4.h +++ b/include/parsers/MRTBgp4MPMessageAS4.h @@ -36,6 +36,11 @@ class MRTBgp4MPMessageAS4 : public MRTBgp4MPMessage public: MRTBgp4MPMessageAS4( MRTCommonHeader &header, std::istream &is ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/MRTBgp4MPStateChange.h b/include/parsers/MRTBgp4MPStateChange.h similarity index 80% rename from include/MRTBgp4MPStateChange.h rename to include/parsers/MRTBgp4MPStateChange.h index 3b8e836..c1f92c1 100644 --- a/include/MRTBgp4MPStateChange.h +++ b/include/parsers/MRTBgp4MPStateChange.h @@ -48,17 +48,23 @@ class MRTBgp4MPStateChange : MRTBgp4MPStateChange( MRTCommonHeader &header, std::istream &input ); virtual ~MRTBgp4MPStateChange(void); - uint32_t getPeerAS(void) const; - uint32_t getLocalAS(void) const; - uint16_t getInterfaceIndex(void) const; - uint16_t getAddressFamily(void) const; - IPAddress getPeerIP(void) const; - IPAddress getLocalIP(void) const; - uint16_t getOldState(void) const; - uint16_t getNewState(void) const; + inline uint32_t getPeerAS( ) const; + inline uint32_t getLocalAS( ) const; + inline uint16_t getInterfaceIndex( ) const; + inline uint16_t getAddressFamily( ) const; + inline IPAddress getPeerIP( ) const; + inline IPAddress getLocalIP( ) const; + inline uint16_t getOldState( ) const; + inline uint16_t getNewState( ) const; + virtual void printMe(void); virtual void printMeCompact(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: MRTBgp4MPStateChange( MRTCommonHeader &header) : MRTCommonHeader( header ) { ; } void processIPs( std::istream &input ); diff --git a/include/MRTBgp4MPStateChangeAS4.h b/include/parsers/MRTBgp4MPStateChangeAS4.h similarity index 85% rename from include/MRTBgp4MPStateChangeAS4.h rename to include/parsers/MRTBgp4MPStateChangeAS4.h index e79e784..b0469cc 100644 --- a/include/MRTBgp4MPStateChangeAS4.h +++ b/include/parsers/MRTBgp4MPStateChangeAS4.h @@ -36,6 +36,11 @@ class MRTBgp4MPStateChangeAS4 : public MRTBgp4MPStateChange public: MRTBgp4MPStateChangeAS4( MRTCommonHeader &header, std::istream &input ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/MRTCommonHeader.h b/include/parsers/MRTCommonHeader.h similarity index 77% rename from include/MRTCommonHeader.h rename to include/parsers/MRTCommonHeader.h index 0211ca5..d4dd3c7 100644 --- a/include/MRTCommonHeader.h +++ b/include/parsers/MRTCommonHeader.h @@ -37,15 +37,15 @@ typedef class MRTCommonHeader MRTMessage; typedef class boost::shared_ptr MRTMessagePtr; /* Common header defined by all MRT packets */ -class MRTCommonHeader +class MRTCommonHeader : public Node { public: virtual ~MRTCommonHeader(void); - time_t getTimestamp(void) const; - uint16_t getType(void) const; - uint16_t getSubType(void) const; - uint32_t getLength(void) const; + inline time_t getTimestamp( ) const; + inline uint16_t getType( ) const; + inline uint16_t getSubType( ) const; + inline uint32_t getLength( ) const; const MRTCommonHeaderPacket &getHeader( ) const { return pkt; } const boost::shared_ptr &getData( ) const { return data; } @@ -53,6 +53,11 @@ class MRTCommonHeader /* static interface... uint8_t pointer will be updated to new location in file after call */ static MRTMessagePtr newMessage( std::istream &input ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: MRTCommonHeader( std::istream &input ); @@ -72,4 +77,20 @@ class MRTCommonHeader static log4cxx::LoggerPtr Logger; }; +time_t MRTCommonHeader::getTimestamp(void) const { + return timestamp; +} + +uint16_t MRTCommonHeader::getType(void) const { + return type; +} + +uint16_t MRTCommonHeader::getSubType(void) const { + return subtype; +} + +uint32_t MRTCommonHeader::getLength(void) const { + return length; +} + #endif /* _MRTCOMMONHEADER_H_ */ diff --git a/include/MRTStructure.h b/include/parsers/MRTStructure.h similarity index 96% rename from include/MRTStructure.h rename to include/parsers/MRTStructure.h index e296736..3877d79 100644 --- a/include/MRTStructure.h +++ b/include/parsers/MRTStructure.h @@ -29,20 +29,6 @@ #ifndef _MRTSTRUCTURE_H_ #define _MRTSTRUCTURE_H_ -/* Address Families... consider moving to common code */ -enum { - AFI_IPv4 = 1, - AFI_IPv6 = 2 -}; - - -/* MULTICAST/UNICAST */ -enum { - SAFI_UNICAST = 1, - SAFI_MULTICAST = 2 -}; - - /* MRT types */ enum { /* NULL = 0, */ @@ -200,13 +186,6 @@ enum { MALFORMED_AS_PATH = 11 }; -/* IP addresses... consider moving to common code */ -typedef union _IPAddress { - in_addr ipv4; - in6_addr ipv6; -} IPAddress; - - /* Network Layer Reachability Information... moved to BGPStructure.h */ /* typedef struct _NLRI { diff --git a/include/MRTTblDump.h b/include/parsers/MRTTblDump.h similarity index 65% rename from include/MRTTblDump.h rename to include/parsers/MRTTblDump.h index bca18f7..8b4d4cd 100644 --- a/include/MRTTblDump.h +++ b/include/parsers/MRTTblDump.h @@ -53,20 +53,26 @@ class MRTTblDump : MRTTblDump( MRTCommonHeader &header, std::istream &input ); virtual ~MRTTblDump(void); - uint16_t getViewNumber(void) const; - uint16_t getSequenceNumber(void) const; - IPAddress getPrefix(void) const; - uint8_t getPrefixLength(void) const; - uint8_t getStatus(void) const; - time_t getOriginatedTime(void) const; - IPAddress getPeerIP(void) const; - uint16_t getPeerAS(void) const; - uint16_t getAttributeLength(void) const; + inline uint16_t getViewNumber( ) const; + inline uint16_t getSequenceNumber( ) const; + inline IPAddress getPrefix( ) const; + inline uint8_t getPrefixLength( ) const; + inline uint8_t getStatus( ) const; + inline time_t getOriginatedTime( ) const; + inline IPAddress getPeerIP( ) const; + inline uint16_t getPeerAS( ) const; + inline uint16_t getAttributeLength( ) const; virtual void printMe() { std::cout << "MRTTblDump"; }; virtual void printMeCompact(); const std::list &getAttributes(void) const { return attributes; }; + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint16_t viewNumber; uint16_t sequenceNumber; @@ -86,5 +92,41 @@ class MRTTblDump : typedef boost::shared_ptr MRTTblDumpPtr; +uint16_t MRTTblDump::getViewNumber(void) const { + return viewNumber; +} + +uint16_t MRTTblDump::getSequenceNumber(void) const { + return sequenceNumber; +} + +IPAddress MRTTblDump::getPrefix(void) const { + return prefix; +} + +uint8_t MRTTblDump::getPrefixLength(void) const { + return prefixLength; +} + +uint8_t MRTTblDump::getStatus(void) const { + return status; +} + +time_t MRTTblDump::getOriginatedTime(void) const { + return originatedTime; +} + +IPAddress MRTTblDump::getPeerIP(void) const { + return peerIP; +} + +uint16_t MRTTblDump::getPeerAS(void) const { + return peerAS; +} + +uint16_t MRTTblDump::getAttributeLength(void) const { + return attributeLength; +} + #endif /* _MRTTBLDUMP_H_ */ diff --git a/include/MRTTblDumpV2PeerIndexTbl.h b/include/parsers/MRTTblDumpV2PeerIndexTbl.h similarity index 70% rename from include/MRTTblDumpV2PeerIndexTbl.h rename to include/parsers/MRTTblDumpV2PeerIndexTbl.h index 743aa22..3c951b4 100644 --- a/include/MRTTblDumpV2PeerIndexTbl.h +++ b/include/parsers/MRTTblDumpV2PeerIndexTbl.h @@ -54,12 +54,19 @@ class MRTTblDumpV2PeerIndexTbl : MRTTblDumpV2PeerIndexTbl( MRTCommonHeader &header, std::istream &input ); virtual ~MRTTblDumpV2PeerIndexTbl(void); - uint32_t getCollectorBGPId(void) const; - uint16_t getViewNameLength(void) const; - const std::string &ggetViewName(void) const { return viewName; } - uint16_t getPeerCount(void) const; + inline uint32_t getCollectorBGPId( ) const; + inline uint16_t getViewNameLength( ) const; + inline uint16_t getPeerCount( ) const; + + const std::string &getViewName( ) const { return viewName; } + const std::vector &getPeerEntries(void) { return peerEntries; } - const MRTTblDumpV2PeerIndexTblPeerEntryPtr getPeer( uint16_t peerIndex ); + inline const MRTTblDumpV2PeerIndexTblPeerEntryPtr getPeer( uint16_t peerIndex ); + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } protected: uint32_t collectorBGPId; @@ -74,5 +81,25 @@ class MRTTblDumpV2PeerIndexTbl : typedef boost::shared_ptr MRTTblDumpV2PeerIndexTblPtr; +const MRTTblDumpV2PeerIndexTblPeerEntryPtr MRTTblDumpV2PeerIndexTbl::getPeer( uint16_t peerIndex ) +{ + if( peerIndex>peerEntries.size() ) throw BGPTextError( "Corrupted PeerIndexTbl" ); + return peerEntries[peerIndex]; +} + + +uint32_t MRTTblDumpV2PeerIndexTbl::getCollectorBGPId(void) const { + return collectorBGPId; +} + +uint16_t MRTTblDumpV2PeerIndexTbl::getViewNameLength(void) const { + return viewNameLength; +} + +uint16_t MRTTblDumpV2PeerIndexTbl::getPeerCount(void) const { + return peerCount; +} + + #endif /* _MRTTBLDUMPV2PEERINDEXTBL_H_ */ diff --git a/include/MRTTblDumpV2RibGeneric.h b/include/parsers/MRTTblDumpV2RibGeneric.h similarity index 86% rename from include/MRTTblDumpV2RibGeneric.h rename to include/parsers/MRTTblDumpV2RibGeneric.h index fb01144..572a869 100644 --- a/include/MRTTblDumpV2RibGeneric.h +++ b/include/parsers/MRTTblDumpV2RibGeneric.h @@ -49,6 +49,11 @@ class MRTTblDumpV2RibGeneric : MRTTblDumpV2RibGeneric(MRTCommonHeader &header, std::istream &input); virtual ~MRTTblDumpV2RibGeneric(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/MRTTblDumpV2RibHeader.h b/include/parsers/MRTTblDumpV2RibHeader.h similarity index 74% rename from include/MRTTblDumpV2RibHeader.h rename to include/parsers/MRTTblDumpV2RibHeader.h index 13caa42..32cf440 100644 --- a/include/MRTTblDumpV2RibHeader.h +++ b/include/parsers/MRTTblDumpV2RibHeader.h @@ -50,12 +50,12 @@ class MRTTblDumpV2RibHeader : public: virtual ~MRTTblDumpV2RibHeader(void); - uint32_t getSequenceNumber(void) const; - uint8_t getPrefixLength(void) const; - IPAddress getPrefix(void) const; - uint16_t getEntryCount(void) const; - uint16_t getAFI(void) const; - uint16_t getSAFI(void) const; + inline uint32_t getSequenceNumber( ) const; + inline uint8_t getPrefixLength( ) const; + inline IPAddress getPrefix( ) const; + inline uint16_t getEntryCount( ) const; + inline uint16_t getAFI( ) const; + inline uint16_t getSAFI( ) const; const std::list &getRibEntries(void) const { return ribs; }; @@ -69,6 +69,11 @@ class MRTTblDumpV2RibHeader : virtual void printMeCompact(); virtual void printMeCompact( const MRTTblDumpV2PeerIndexTblPtr& ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: MRTTblDumpV2RibHeader( MRTCommonHeader &header, std::istream &input ); void init( std::istream &input ); @@ -89,4 +94,29 @@ class MRTTblDumpV2RibHeader : typedef boost::shared_ptr MRTTblDumpV2RibHeaderPtr; +uint32_t MRTTblDumpV2RibHeader::getSequenceNumber(void) const { + return sequenceNumber; +} + +uint8_t MRTTblDumpV2RibHeader::getPrefixLength(void) const { + return prefixLength; +} + +IPAddress MRTTblDumpV2RibHeader::getPrefix(void) const { + return prefix; +} + +uint16_t MRTTblDumpV2RibHeader::getEntryCount(void) const { + return entryCount; +} + +uint16_t MRTTblDumpV2RibHeader::getAFI(void) const { + return afi; +} + +uint16_t MRTTblDumpV2RibHeader::getSAFI(void) const { + return safi; +} + + #endif /* _MRTTBLDUMPV2RIBHEADER_H_ */ diff --git a/include/MRTTblDumpV2RibIPv4Multicast.h b/include/parsers/MRTTblDumpV2RibIPv4Multicast.h similarity index 86% rename from include/MRTTblDumpV2RibIPv4Multicast.h rename to include/parsers/MRTTblDumpV2RibIPv4Multicast.h index 17f4035..6af6e68 100644 --- a/include/MRTTblDumpV2RibIPv4Multicast.h +++ b/include/parsers/MRTTblDumpV2RibIPv4Multicast.h @@ -50,6 +50,11 @@ class MRTTblDumpV2RibIPv4Multicast : MRTTblDumpV2RibIPv4Multicast(MRTCommonHeader &header, std::istream &input); virtual ~MRTTblDumpV2RibIPv4Multicast(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: }; diff --git a/include/MRTTblDumpV2RibIPv4Unicast.h b/include/parsers/MRTTblDumpV2RibIPv4Unicast.h similarity index 87% rename from include/MRTTblDumpV2RibIPv4Unicast.h rename to include/parsers/MRTTblDumpV2RibIPv4Unicast.h index f9c21a6..eaeee7a 100644 --- a/include/MRTTblDumpV2RibIPv4Unicast.h +++ b/include/parsers/MRTTblDumpV2RibIPv4Unicast.h @@ -50,6 +50,11 @@ class MRTTblDumpV2RibIPv4Unicast : MRTTblDumpV2RibIPv4Unicast(MRTCommonHeader &header, std::istream &input); virtual ~MRTTblDumpV2RibIPv4Unicast(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/MRTTblDumpV2RibIPv6Multicast.h b/include/parsers/MRTTblDumpV2RibIPv6Multicast.h similarity index 87% rename from include/MRTTblDumpV2RibIPv6Multicast.h rename to include/parsers/MRTTblDumpV2RibIPv6Multicast.h index 73aab4b..7f693f7 100644 --- a/include/MRTTblDumpV2RibIPv6Multicast.h +++ b/include/parsers/MRTTblDumpV2RibIPv6Multicast.h @@ -50,6 +50,11 @@ class MRTTblDumpV2RibIPv6Multicast : MRTTblDumpV2RibIPv6Multicast(MRTCommonHeader &header, std::istream &input); virtual ~MRTTblDumpV2RibIPv6Multicast(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/MRTTblDumpV2RibIPv6Unicast.h b/include/parsers/MRTTblDumpV2RibIPv6Unicast.h similarity index 86% rename from include/MRTTblDumpV2RibIPv6Unicast.h rename to include/parsers/MRTTblDumpV2RibIPv6Unicast.h index 1b3c289..33ffa47 100644 --- a/include/MRTTblDumpV2RibIPv6Unicast.h +++ b/include/parsers/MRTTblDumpV2RibIPv6Unicast.h @@ -50,6 +50,11 @@ class MRTTblDumpV2RibIPv6Unicast : MRTTblDumpV2RibIPv6Unicast(MRTCommonHeader &header, std::istream &input); virtual ~MRTTblDumpV2RibIPv6Unicast(void); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: static log4cxx::LoggerPtr Logger; }; diff --git a/include/parsers/Node.h b/include/parsers/Node.h new file mode 100644 index 0000000..1acc0b1 --- /dev/null +++ b/include/parsers/Node.h @@ -0,0 +1,13 @@ + +#ifndef _NODE_H_ +#define _NODE_H_ + +class Node +{ + virtual void accept( Visitor &v ) =0; + virtual void accept( GJVoidVisitor &v, boost::any param ) =0; + virtual boost::any accept( GJNoArguVisitor &v ) =0; + virtual boost::any accept( GJVisitor &v, boost::any param ) =0; +}; + +#endif diff --git a/include/OptionalParameter.h b/include/parsers/OptionalParameter.h similarity index 62% rename from include/OptionalParameter.h rename to include/parsers/OptionalParameter.h index 0eadf89..ca49449 100644 --- a/include/OptionalParameter.h +++ b/include/parsers/OptionalParameter.h @@ -5,7 +5,7 @@ class OptionalParameter; typedef boost::shared_ptr OptionalParameterPtr; -class OptionalParameter +class OptionalParameter : public Node { public: enum @@ -21,6 +21,11 @@ class OptionalParameter static OptionalParameterPtr newOptionalParameter( std::istream &is ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: OptionalParameter( std::istream &input ); diff --git a/include/OptionalParameterCapabilities.h b/include/parsers/OptionalParameterCapabilities.h similarity index 53% rename from include/OptionalParameterCapabilities.h rename to include/parsers/OptionalParameterCapabilities.h index 135b4b3..bcd0b61 100644 --- a/include/OptionalParameterCapabilities.h +++ b/include/parsers/OptionalParameterCapabilities.h @@ -19,6 +19,15 @@ class OptionalParameterCapabilities : public OptionalParameter CAPABILITY_AS4=65 //[RFC4893] }; + uint8_t getCapCode( ) const { return capCode; } + uint8_t getCapLength( ) const { return capLength; } + const boost::shared_ptr& getCapValue( ) const { return capValue; } + + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + private: uint8_t capCode; uint8_t capLength; diff --git a/include/TblDumpV2RibEntry.h b/include/parsers/TblDumpV2RibEntry.h similarity index 81% rename from include/TblDumpV2RibEntry.h rename to include/parsers/TblDumpV2RibEntry.h index 779a68d..873fd6a 100644 --- a/include/TblDumpV2RibEntry.h +++ b/include/parsers/TblDumpV2RibEntry.h @@ -34,21 +34,15 @@ #include -class TblDumpV2RibEntry +class TblDumpV2RibEntry : public Node { public: TblDumpV2RibEntry( std::istream &input ); virtual ~TblDumpV2RibEntry(void); - uint16_t getPeerIndex(void) const { return peerIndex; }; - void setPeerIndex(uint16_t peerIndex) { this->peerIndex = peerIndex; }; - time_t getOriginatedTime(void) const { return originatedTime; }; - void setOriginatedTime(time_t originatedTime) { this->originatedTime = originatedTime; }; - - /* consider removing attribute length getter/setters */ - uint16_t getAttributeLength(void) const { return attributeLength; }; - void setAttributeLength(uint16_t attributeLength) { this->attributeLength = attributeLength; }; - + uint16_t getPeerIndex( ) const { return peerIndex; }; + time_t getOriginatedTime( ) const { return originatedTime; }; + uint16_t getAttributeLength( ) const { return attributeLength; }; const std::list &getAttributes(void) const { return attributes; }; virtual void printMe(); @@ -56,6 +50,11 @@ class TblDumpV2RibEntry virtual void printMeCompact(); virtual void printMeCompact( const MRTTblDumpV2PeerIndexTblPtr &peerIndexTbl ); + virtual void accept( Visitor &v ) { v.visit( *this ); } + virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); } + virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); } + virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); } + protected: uint16_t peerIndex; // This is an index into the PEER_INDEX_TABLE MRT record uint32_t originatedTime; diff --git a/include/visitors/DepthFirstVisitor.h b/include/visitors/DepthFirstVisitor.h new file mode 100644 index 0000000..6151bc2 --- /dev/null +++ b/include/visitors/DepthFirstVisitor.h @@ -0,0 +1,485 @@ + +#ifndef _DEPTHFIRSTVISITOR_H_ +#define _DEPTHFIRSTVISITOR_H_ + +#include "Visitor.h" + +#include "parsers/MRTCommonHeader.h" + +#include "parsers/MRTBgp4MPStateChange.h" +#include "parsers/MRTBgp4MPStateChangeAS4.h" +#include "parsers/MRTBgp4MPMessage.h" +#include "parsers/MRTBgp4MPMessageAS4.h" + +#include "parsers/MRTTblDump.h" +#include "parsers/MRTTblDumpV2PeerIndexTbl.h" +#include "parsers/MRTTblDumpV2RibHeader.h" +#include "parsers/MRTTblDumpV2RibIPv4Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv4Multicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Multicast.h" +#include "parsers/MRTTblDumpV2RibGeneric.h" + +#include "parsers/BGPCommonHeader.h" + +#include "parsers/BGPOpen.h" +#include "parsers/BGPUpdate.h" +#include "parsers/BGPKeepAlive.h" +#include "parsers/BGPNotification.h" +#include "parsers/BGPRouteRefresh.h" + +#include "parsers/AttributeType.h" + +#include "parsers/AttributeTypeAggregator.h" +#include "parsers/AttributeTypeAS4Aggregator.h" +#include "parsers/AttributeTypeASPath.h" +#include "parsers/AttributeTypeAS4Path.h" +#include "parsers/AttributeTypeAtomicAggregate.h" +#include "parsers/AttributeTypeCommunities.h" +#include "parsers/AttributeTypeOriginatorID.h" +#include "parsers/AttributeTypeClusterList.h" +#include "parsers/AttributeTypeExtCommunities.h" +#include "parsers/AttributeTypeLocalPref.h" +#include "parsers/AttributeTypeMultiExitDisc.h" +#include "parsers/AttributeTypeNextHop.h" +#include "parsers/AttributeTypeOrigin.h" +#include "parsers/AttributeTypeMPReachNLRI.h" +#include "parsers/AttributeTypeMPUnreachNLRI.h" + +class DepthFirstVisitor : public Visitor +{ + virtual void visit( MRTCommonHeader &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + } + + virtual void visit( MRTBgp4MPMessage &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS() +// n.getLocalAS() +// n.getInterfaceIndex() +// n.getAddressFamily(); +// n.getPeerIP() +// n.getLocalIP() + + n.getPayload()->accept( *this ); + } + + virtual void visit( MRTBgp4MPMessageAS4 &n ) + { + static_cast( n ).accept( *this ); + } + + virtual void visit( MRTBgp4MPStateChange &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS( ) +// n.getLocalAS( ) +// n.getInterfaceIndex( ) +// n.getAddressFamily( ) +// n.getPeerIP( ) +// n.getLocalIP( ) +// n.getOldState( ) +// n.getNewState( ) + } + + virtual void visit( MRTBgp4MPStateChangeAS4 &n ) + { + static_cast( n ).accept( *this ); + } + + virtual void visit( MRTTblDump &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getViewNumber( ) +// n.getSequenceNumber( ) +// n.getPrefix( ) +// n.getPrefixLength( ) +// n.getStatus( ) +// n.getOriginatedTime( ) +// n.getPeerIP( ) +// n.getPeerAS( ) +// n.getAttributeLength( ) + } + + virtual void visit( MRTTblDumpV2PeerIndexTbl &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getCollectorBGPId( ) +// n.getViewNameLength( ) +// n.getPeerCount( ) +// n.getPeerEntries( ) + } + + virtual void visit( MRTTblDumpV2RibHeader &n ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getSequenceNumber( ) +// n.getPrefixLength( ) +// n.getPrefix( ) +// n.getEntryCount( ) +// n.getAFI( ) +// n.getSAFI( ) + +// n.getPeerIndexTbl() + + BOOST_FOREACH( const TblDumpV2RibEntryPtr &entry, n.getRibEntries() ) + { + entry->accept( *this ); + } + } + + virtual void visit( MRTTblDumpV2RibGeneric &n ) + { + static_cast( n ).accept( *this ); + } + virtual void visit( MRTTblDumpV2RibIPv4Multicast &n ) + { + static_cast( n ).accept( *this ); + } + virtual void visit( MRTTblDumpV2RibIPv4Unicast &n ) + { + static_cast( n ).accept( *this ); + } + virtual void visit( MRTTblDumpV2RibIPv6Multicast &n ) + { + static_cast( n ).accept( *this ); + } + virtual void visit( MRTTblDumpV2RibIPv6Unicast &n ) + { + static_cast( n ).accept( *this ); + } + + virtual void visit( TblDumpV2RibEntry &n ) + { +// n.getPeerIndex( ) +// n.getOriginatedTime( ) +// n.getAttributeLength( ) + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getAttributes() ) + { + attr->accept( *this ); + } + } + + virtual void visit( BGPCommonHeader &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + } + + virtual void visit( BGPKeepAlive &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + } + + virtual void visit( BGPNotification &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getErrorCode( ) +// n.getSubErrorCode( ) +// n.getData( ) + } + + virtual void visit( BGPOpen &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getVersion( ) +// n.getMyAS( ) +// n.getHoldTime( ) +// n.getBgpId( ) +// n.getOptParmLen( ) +// n.isAS4Supported( ) + + BOOST_FOREACH( const OptionalParameterPtr ¶m, n.getOptParams( ) ) + { + param->accept( *this ); + } + } + virtual void visit( BGPRouteRefresh &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getAfi( ) +// n.getRes( ) +// n.getSafi( ) + } + virtual void visit( BGPUpdate &n ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getWithdrawnRoutesLength() +// n.getPathAttributesLength() +// n.getNlriLength() + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getPathAttributes() ) + { + attr->accept( *this ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getWithdrawnRoutes() ) + { + route->accept( *this ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getNlriRoutes() ) + { + route->accept( *this ); + } + } + + virtual void visit( BGPAttribute &n ) + { +// n.getAttributeFlags( ) +// n.getAttributeTypeCode( ) +// n.getAttributeLength( ) +// + other helpers available, see BGPAttribute + + n.getAttributeValue()->accept( *this ); + } + + virtual void visit( AttributeType &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + } + virtual void visit( AttributeTypeAS4Aggregator &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + } + virtual void visit( AttributeTypeASPath &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// + n.getPathSegmentsComplete() is also available + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this ); + } + } + virtual void visit( AttributeTypeASPathSegment &n ) + { +// n.getPathSegmentType( ) +// n.getPathSegmentLength( ) +// n.getPathSegmentValue( ) + } + virtual void visit( AttributeTypeAS4Path &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this ); + } + } + virtual void visit( AttributeTypeAS4PathSegment &n ) + { +// n.getPathSegmentType( ) +// n.getPathSegmentLength( ) +// n.getPathSegmentValue( ) + } + virtual void visit( AttributeTypeAggregator &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorLastASComplete( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + } + virtual void visit( AttributeTypeAtomicAggregate &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + } + virtual void visit( AttributeTypeClusterList &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getClusterList( ) + } + virtual void visit( AttributeTypeCommunities &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getCommunityValues( ) + } + virtual void visit( AttributeTypeExtCommunities &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getExtCommunityValues( ) + } + virtual void visit( AttributeTypeLocalPref &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getLocalPrefValue( ) + } + virtual void visit( AttributeTypeMPReachNLRI &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) +// n.getNextHopAddressLength( ) +// n.getNextHopAddress( ) +// n.getNextHopAddressLocal( ) + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getNLRI() ) + { + route->accept( *this ); + } + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getSNPA() ) + { + route->accept( *this ); + } + } + virtual void visit( AttributeTypeMPUnreachNLRI &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) + + BOOST_FOREACH( const NLRIUnReachablePtr &route, n.getNLRI() ) + { + route->accept( *this ); + } + } + virtual void visit( AttributeTypeMultiExitDisc &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getMultiExitDiscValue( ) + } + virtual void visit( AttributeTypeNextHop &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getNextHopIPAddress( ) +// n.getNextHopAFI( ) + } + virtual void visit( AttributeTypeOrigin &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + } + virtual void visit( AttributeTypeOriginatorID &n ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + } + + virtual void visit( OptionalParameter &n ) + { +// n.getType( ) +// n.getLength( ) + } + virtual void visit( OptionalParameterCapabilities &n ) + { +// n.getType( ) +// n.getLength( ) + +// n.getCapCode( ) +// n.getCapLength( ) +// n.getCapValue( ) + } + + virtual void visit( Route &n ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + + virtual void visit( NLRIReachable &n ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + virtual void visit( NLRIUnReachable &n ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } +}; + +#endif diff --git a/include/visitors/ForwardDeclarations.h b/include/visitors/ForwardDeclarations.h new file mode 100644 index 0000000..3d6d1a6 --- /dev/null +++ b/include/visitors/ForwardDeclarations.h @@ -0,0 +1,50 @@ + +#ifndef _FORWARDDECLARATIONS_H_ +#define _FORWARDDECLARATIONS_H_ + +class MRTCommonHeader; +class MRTBgp4MPMessage; +class MRTBgp4MPMessageAS4; +class MRTBgp4MPStateChange; +class MRTBgp4MPStateChangeAS4; +class AttributeType; +class AttributeTypeAS4Aggregator; +class AttributeTypeAS4Path; +class AttributeTypeAS4PathSegment; +class AttributeTypeASPath; +class AttributeTypeASPathSegment; +class AttributeTypeAggregator; +class AttributeTypeAtomicAggregate; +class AttributeTypeClusterList; +class AttributeTypeCommunities; +class AttributeTypeExtCommunities; +class AttributeTypeLocalPref; +class AttributeTypeMPReachNLRI; +class AttributeTypeMPUnreachNLRI; +class AttributeTypeMultiExitDisc; +class AttributeTypeNextHop; +class AttributeTypeOrigin; +class AttributeTypeOriginatorID; +class BGPAttribute; +class BGPCommonHeader; +class BGPKeepAlive; +class BGPNotification; +class BGPOpen; +class BGPRouteRefresh; +class BGPUpdate; +class MRTTblDump; +class MRTTblDumpV2PeerIndexTbl; +class MRTTblDumpV2RibGeneric; +class MRTTblDumpV2RibHeader; +class MRTTblDumpV2RibIPv4Multicast; +class MRTTblDumpV2RibIPv4Unicast; +class MRTTblDumpV2RibIPv6Multicast; +class MRTTblDumpV2RibIPv6Unicast; +class OptionalParameter; +class OptionalParameterCapabilities; +class TblDumpV2RibEntry; +class Route; +class NLRIReachable; +class NLRIUnReachable; + +#endif diff --git a/include/visitors/GJDepthFirst.h b/include/visitors/GJDepthFirst.h new file mode 100644 index 0000000..f443a53 --- /dev/null +++ b/include/visitors/GJDepthFirst.h @@ -0,0 +1,522 @@ + +#ifndef _GJDEPTHFIRST_H_ +#define _GKDEPTHFIRST_H_ + +#include "GJVisitor.h" + +#include "parsers/MRTCommonHeader.h" + +#include "parsers/MRTBgp4MPStateChange.h" +#include "parsers/MRTBgp4MPStateChangeAS4.h" +#include "parsers/MRTBgp4MPMessage.h" +#include "parsers/MRTBgp4MPMessageAS4.h" + +#include "parsers/MRTTblDump.h" +#include "parsers/MRTTblDumpV2PeerIndexTbl.h" +#include "parsers/MRTTblDumpV2RibHeader.h" +#include "parsers/MRTTblDumpV2RibIPv4Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv4Multicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Multicast.h" +#include "parsers/MRTTblDumpV2RibGeneric.h" + +#include "parsers/BGPCommonHeader.h" + +#include "parsers/BGPOpen.h" +#include "parsers/BGPUpdate.h" +#include "parsers/BGPKeepAlive.h" +#include "parsers/BGPNotification.h" +#include "parsers/BGPRouteRefresh.h" + +#include "parsers/AttributeType.h" + +#include "parsers/AttributeTypeAggregator.h" +#include "parsers/AttributeTypeAS4Aggregator.h" +#include "parsers/AttributeTypeASPath.h" +#include "parsers/AttributeTypeAS4Path.h" +#include "parsers/AttributeTypeAtomicAggregate.h" +#include "parsers/AttributeTypeCommunities.h" +#include "parsers/AttributeTypeOriginatorID.h" +#include "parsers/AttributeTypeClusterList.h" +#include "parsers/AttributeTypeExtCommunities.h" +#include "parsers/AttributeTypeLocalPref.h" +#include "parsers/AttributeTypeMultiExitDisc.h" +#include "parsers/AttributeTypeNextHop.h" +#include "parsers/AttributeTypeOrigin.h" +#include "parsers/AttributeTypeMPReachNLRI.h" +#include "parsers/AttributeTypeMPUnreachNLRI.h" + +class GJDepthFirst : public GJVisitor +{ + virtual boost::any& visit( MRTCommonHeader &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + return boost::any(); + } + + virtual boost::any& visit( MRTBgp4MPMessage &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS() +// n.getLocalAS() +// n.getInterfaceIndex() +// n.getAddressFamily(); +// n.getPeerIP() +// n.getLocalIP() + + return n.getPayload()->accept( *this, param ); + } + + virtual boost::any& visit( MRTBgp4MPMessageAS4 &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + + virtual boost::any& visit( MRTBgp4MPStateChange &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS( ) +// n.getLocalAS( ) +// n.getInterfaceIndex( ) +// n.getAddressFamily( ) +// n.getPeerIP( ) +// n.getLocalIP( ) +// n.getOldState( ) +// n.getNewState( ) + return boost::any(); + } + + virtual boost::any& visit( MRTBgp4MPStateChangeAS4 &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + + virtual boost::any& visit( MRTTblDump &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getViewNumber( ) +// n.getSequenceNumber( ) +// n.getPrefix( ) +// n.getPrefixLength( ) +// n.getStatus( ) +// n.getOriginatedTime( ) +// n.getPeerIP( ) +// n.getPeerAS( ) +// n.getAttributeLength( ) + return boost::any(); + } + + virtual boost::any& visit( MRTTblDumpV2PeerIndexTbl &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getCollectorBGPId( ) +// n.getViewNameLength( ) +// n.getPeerCount( ) +// n.getPeerEntries( ) + return boost::any(); + } + + virtual boost::any& visit( MRTTblDumpV2RibHeader &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getSequenceNumber( ) +// n.getPrefixLength( ) +// n.getPrefix( ) +// n.getEntryCount( ) +// n.getAFI( ) +// n.getSAFI( ) + +// n.getPeerIndexTbl() + + BOOST_FOREACH( const TblDumpV2RibEntryPtr &entry, n.getRibEntries() ) + { + entry->accept( *this, param ); + } + return boost::any(); + } + + virtual boost::any& visit( MRTTblDumpV2RibGeneric &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + virtual boost::any& visit( MRTTblDumpV2RibIPv4Multicast &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + virtual boost::any& visit( MRTTblDumpV2RibIPv4Unicast &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + virtual boost::any& visit( MRTTblDumpV2RibIPv6Multicast &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + virtual boost::any& visit( MRTTblDumpV2RibIPv6Unicast &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + + virtual boost::any& visit( TblDumpV2RibEntry &n, boost::any ¶m ) + { +// n.getPeerIndex( ) +// n.getOriginatedTime( ) +// n.getAttributeLength( ) + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getAttributes() ) + { + attr->accept( *this, param ); + } + + return boost::any(); + } + + virtual boost::any& visit( BGPCommonHeader &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + return boost::any(); + } + + virtual boost::any& visit( BGPKeepAlive &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + return boost::any(); + } + + virtual boost::any& visit( BGPNotification &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getErrorCode( ) +// n.getSubErrorCode( ) +// n.getData( ) + return boost::any(); + } + + virtual boost::any& visit( BGPOpen &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getVersion( ) +// n.getMyAS( ) +// n.getHoldTime( ) +// n.getBgpId( ) +// n.getOptParmLen( ) +// n.isAS4Supported( ) + + BOOST_FOREACH( const OptionalParameterPtr ¶m, n.getOptParams( ) ) + { + param->accept( *this, param ); + } + return boost::any(); + } + virtual boost::any& visit( BGPRouteRefresh &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getAfi( ) +// n.getRes( ) +// n.getSafi( ) + return boost::any(); + } + virtual boost::any& visit( BGPUpdate &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getWithdrawnRoutesLength() +// n.getPathAttributesLength() +// n.getNlriLength() + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getPathAttributes() ) + { + attr->accept( *this, param ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getWithdrawnRoutes() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getNlriRoutes() ) + { + route->accept( *this, param ); + } + return boost::any(); + } + + virtual boost::any& visit( BGPAttribute &n, boost::any ¶m ) + { +// n.getAttributeFlags( ) +// n.getAttributeTypeCode( ) +// n.getAttributeLength( ) +// + other helpers available, see BGPAttribute + + n.getAttributeValue()->accept( *this, param ); + return boost::any(); + } + + virtual boost::any& visit( AttributeType &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeAS4Aggregator &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeASPath &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// + n.getPathSegmentsComplete() is also available + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this, param ); + } + return boost::any(); + } + + virtual boost::any& visit( AttributeTypeASPathSegment &n, boost::any ¶m ) + { +// n.getPathSegmentType( ) +// n.getPathSegmentLength( ) +// n.getPathSegmentValue( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeAS4PathSegment &n, boost::any ¶m ) + { + return static_cast( n ).accept( *this, param ); + } + + virtual boost::any& visit( AttributeTypeAS4Path &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this, param ); + } + return boost::any(); + } + + virtual boost::any& visit( AttributeTypeAggregator &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorLastASComplete( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeAtomicAggregate &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeClusterList &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getClusterList( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeCommunities &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getCommunityValues( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeExtCommunities &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getExtCommunityValues( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeLocalPref &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getLocalPrefValue( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeMPReachNLRI &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) +// n.getNextHopAddressLength( ) +// n.getNextHopAddress( ) +// n.getNextHopAddressLocal( ) + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getNLRI() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getSNPA() ) + { + route->accept( *this, param ); + } + return boost::any(); + } + virtual boost::any& visit( AttributeTypeMPUnreachNLRI &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) + + BOOST_FOREACH( const NLRIUnReachablePtr &route, n.getNLRI() ) + { + route->accept( *this, param ); + } + return boost::any(); + } + virtual boost::any& visit( AttributeTypeMultiExitDisc &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getMultiExitDiscValue( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeNextHop &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getNextHopIPAddress( ) +// n.getNextHopAFI( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeOrigin &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + return boost::any(); + } + virtual boost::any& visit( AttributeTypeOriginatorID &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + return boost::any(); + } + + virtual boost::any& visit( OptionalParameter &n, boost::any ¶m ) + { +// n.getType( ) +// n.getLength( ) + return boost::any(); + } + virtual boost::any& visit( OptionalParameterCapabilities &n, boost::any ¶m ) + { +// n.getType( ) +// n.getLength( ) + +// n.getCapCode( ) +// n.getCapLength( ) +// n.getCapValue( ) + return boost::any(); + } + + virtual boost::any& visit( Route &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + return boost::any(); + } + + virtual boost::any& visit( NLRIReachable &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + return boost::any(); + } + virtual boost::any& visit( NLRIUnReachable &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + return boost::any(); + } +}; + +#endif diff --git a/include/visitors/GJNoArguVisitor.h b/include/visitors/GJNoArguVisitor.h new file mode 100644 index 0000000..6536cbe --- /dev/null +++ b/include/visitors/GJNoArguVisitor.h @@ -0,0 +1,59 @@ + +#ifndef _GJNOARGUVISITOR_H_ +#define _GJNOARGUVISITOR_H_ + +#include "ForwardDeclarations.h" + +class GJNoArguVisitor +{ +public: + virtual boost::any visit( MRTCommonHeader& )=0; + + virtual boost::any visit( MRTBgp4MPMessage& )=0; + virtual boost::any visit( MRTBgp4MPMessageAS4& )=0; + virtual boost::any visit( MRTBgp4MPStateChange& )=0; + virtual boost::any visit( MRTBgp4MPStateChangeAS4& )=0; + + virtual boost::any visit( AttributeType& )=0; + virtual boost::any visit( AttributeTypeAS4Aggregator& )=0; + virtual boost::any visit( AttributeTypeAS4Path& )=0; + virtual boost::any visit( AttributeTypeAS4PathSegment& )=0; + virtual boost::any visit( AttributeTypeASPath& )=0; + virtual boost::any visit( AttributeTypeASPathSegment& )=0; + virtual boost::any visit( AttributeTypeAggregator& )=0; + virtual boost::any visit( AttributeTypeAtomicAggregate& )=0; + virtual boost::any visit( AttributeTypeClusterList& )=0; + virtual boost::any visit( AttributeTypeCommunities& )=0; + virtual boost::any visit( AttributeTypeExtCommunities& )=0; + virtual boost::any visit( AttributeTypeLocalPref& )=0; + virtual boost::any visit( AttributeTypeMPReachNLRI& )=0; + virtual boost::any visit( AttributeTypeMPUnreachNLRI& )=0; + virtual boost::any visit( AttributeTypeMultiExitDisc& )=0; + virtual boost::any visit( AttributeTypeNextHop& )=0; + virtual boost::any visit( AttributeTypeOrigin& )=0; + virtual boost::any visit( AttributeTypeOriginatorID& )=0; + + virtual boost::any visit( BGPCommonHeader& )=0; + virtual boost::any visit( BGPKeepAlive& )=0; + virtual boost::any visit( BGPNotification& )=0; + virtual boost::any visit( BGPOpen& )=0; + virtual boost::any visit( BGPRouteRefresh& )=0; + virtual boost::any visit( BGPUpdate& )=0; + virtual boost::any visit( BGPAttribute& )=0; + + virtual boost::any visit( MRTTblDump& )=0; + virtual boost::any visit( MRTTblDumpV2PeerIndexTbl& )=0; + virtual boost::any visit( MRTTblDumpV2RibGeneric& )=0; + virtual boost::any visit( MRTTblDumpV2RibHeader& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv4Multicast& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv4Unicast& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv6Multicast& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv6Unicast& )=0; + virtual boost::any visit( OptionalParameter& )=0; + virtual boost::any visit( OptionalParameterCapabilities& )=0; + virtual boost::any visit( TblDumpV2RibEntry& )=0; + + virtual boost::any visit( Route& )=0; +}; + +#endif diff --git a/include/visitors/GJVisitor.h b/include/visitors/GJVisitor.h new file mode 100644 index 0000000..47cb426 --- /dev/null +++ b/include/visitors/GJVisitor.h @@ -0,0 +1,59 @@ + +#ifndef _GJVISITOR_H_ +#define _GJVISITOR_H_ + +#include "ForwardDeclarations.h" + +class GJVisitor +{ +public: + virtual boost::any visit( MRTCommonHeader& , boost::any& )=0; + + virtual boost::any visit( MRTBgp4MPMessage& , boost::any& )=0; + virtual boost::any visit( MRTBgp4MPMessageAS4& , boost::any& )=0; + virtual boost::any visit( MRTBgp4MPStateChange& , boost::any& )=0; + virtual boost::any visit( MRTBgp4MPStateChangeAS4& , boost::any& )=0; + + virtual boost::any visit( AttributeType& , boost::any& )=0; + virtual boost::any visit( AttributeTypeAS4Aggregator& , boost::any& )=0; + virtual boost::any visit( AttributeTypeAS4Path& , boost::any& )=0; + virtual boost::any visit( AttributeTypeAS4PathSegment& , boost::any& )=0; + virtual boost::any visit( AttributeTypeASPath& , boost::any& )=0; + virtual boost::any visit( AttributeTypeASPathSegment& , boost::any& )=0; + virtual boost::any visit( AttributeTypeAggregator& , boost::any& )=0; + virtual boost::any visit( AttributeTypeAtomicAggregate& , boost::any& )=0; + virtual boost::any visit( AttributeTypeClusterList& , boost::any& )=0; + virtual boost::any visit( AttributeTypeCommunities& , boost::any& )=0; + virtual boost::any visit( AttributeTypeExtCommunities& , boost::any& )=0; + virtual boost::any visit( AttributeTypeLocalPref& , boost::any& )=0; + virtual boost::any visit( AttributeTypeMPReachNLRI& , boost::any& )=0; + virtual boost::any visit( AttributeTypeMPUnreachNLRI& , boost::any& )=0; + virtual boost::any visit( AttributeTypeMultiExitDisc& , boost::any& )=0; + virtual boost::any visit( AttributeTypeNextHop& , boost::any& )=0; + virtual boost::any visit( AttributeTypeOrigin& , boost::any& )=0; + virtual boost::any visit( AttributeTypeOriginatorID& , boost::any& )=0; + + virtual boost::any visit( BGPCommonHeader& , boost::any& )=0; + virtual boost::any visit( BGPKeepAlive& , boost::any& )=0; + virtual boost::any visit( BGPNotification& , boost::any& )=0; + virtual boost::any visit( BGPOpen& , boost::any& )=0; + virtual boost::any visit( BGPRouteRefresh& , boost::any& )=0; + virtual boost::any visit( BGPUpdate& , boost::any& )=0; + virtual boost::any visit( BGPAttribute& , boost::any& )=0; + + virtual boost::any visit( MRTTblDump& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2PeerIndexTbl& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibGeneric& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibHeader& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv4Multicast& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv4Unicast& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv6Multicast& , boost::any& )=0; + virtual boost::any visit( MRTTblDumpV2RibIPv6Unicast& , boost::any& )=0; + virtual boost::any visit( OptionalParameter& , boost::any& )=0; + virtual boost::any visit( OptionalParameterCapabilities& , boost::any& )=0; + virtual boost::any visit( TblDumpV2RibEntry& , boost::any& )=0; + + virtual boost::any visit( Route& , boost::any& )=0; +}; + +#endif diff --git a/include/visitors/GJVoidDepthFirst.h b/include/visitors/GJVoidDepthFirst.h new file mode 100644 index 0000000..a7201aa --- /dev/null +++ b/include/visitors/GJVoidDepthFirst.h @@ -0,0 +1,485 @@ + +#ifndef _GJVOIDDEPTHFIRST_H_ +#define _GKVOIDDEPTHFIRST_H_ + +#include "GJVoidVisitor.h" + +#include "parsers/MRTCommonHeader.h" + +#include "parsers/MRTBgp4MPStateChange.h" +#include "parsers/MRTBgp4MPStateChangeAS4.h" +#include "parsers/MRTBgp4MPMessage.h" +#include "parsers/MRTBgp4MPMessageAS4.h" + +#include "parsers/MRTTblDump.h" +#include "parsers/MRTTblDumpV2PeerIndexTbl.h" +#include "parsers/MRTTblDumpV2RibHeader.h" +#include "parsers/MRTTblDumpV2RibIPv4Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv4Multicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Unicast.h" +#include "parsers/MRTTblDumpV2RibIPv6Multicast.h" +#include "parsers/MRTTblDumpV2RibGeneric.h" + +#include "parsers/BGPCommonHeader.h" + +#include "parsers/BGPOpen.h" +#include "parsers/BGPUpdate.h" +#include "parsers/BGPKeepAlive.h" +#include "parsers/BGPNotification.h" +#include "parsers/BGPRouteRefresh.h" + +#include "parsers/AttributeType.h" + +#include "parsers/AttributeTypeAggregator.h" +#include "parsers/AttributeTypeAS4Aggregator.h" +#include "parsers/AttributeTypeASPath.h" +#include "parsers/AttributeTypeAS4Path.h" +#include "parsers/AttributeTypeAtomicAggregate.h" +#include "parsers/AttributeTypeCommunities.h" +#include "parsers/AttributeTypeOriginatorID.h" +#include "parsers/AttributeTypeClusterList.h" +#include "parsers/AttributeTypeExtCommunities.h" +#include "parsers/AttributeTypeLocalPref.h" +#include "parsers/AttributeTypeMultiExitDisc.h" +#include "parsers/AttributeTypeNextHop.h" +#include "parsers/AttributeTypeOrigin.h" +#include "parsers/AttributeTypeMPReachNLRI.h" +#include "parsers/AttributeTypeMPUnreachNLRI.h" + +class GJVoidDepthFirst : public GJVoidVisitor +{ + virtual void visit( MRTCommonHeader &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + } + + virtual void visit( MRTBgp4MPMessage &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS() +// n.getLocalAS() +// n.getInterfaceIndex() +// n.getAddressFamily(); +// n.getPeerIP() +// n.getLocalIP() + + n.getPayload()->accept( *this, param ); + } + + virtual void visit( MRTBgp4MPMessageAS4 &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + + virtual void visit( MRTBgp4MPStateChange &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getPeerAS( ) +// n.getLocalAS( ) +// n.getInterfaceIndex( ) +// n.getAddressFamily( ) +// n.getPeerIP( ) +// n.getLocalIP( ) +// n.getOldState( ) +// n.getNewState( ) + } + + virtual void visit( MRTBgp4MPStateChangeAS4 &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + + virtual void visit( MRTTblDump &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getViewNumber( ) +// n.getSequenceNumber( ) +// n.getPrefix( ) +// n.getPrefixLength( ) +// n.getStatus( ) +// n.getOriginatedTime( ) +// n.getPeerIP( ) +// n.getPeerAS( ) +// n.getAttributeLength( ) + } + + virtual void visit( MRTTblDumpV2PeerIndexTbl &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getCollectorBGPId( ) +// n.getViewNameLength( ) +// n.getPeerCount( ) +// n.getPeerEntries( ) + } + + virtual void visit( MRTTblDumpV2RibHeader &n, boost::any ¶m ) + { +// n.getTimestamp( ) +// n.getType( ) +// n.getSubType( ) +// n.getLength( ) + +// n.getSequenceNumber( ) +// n.getPrefixLength( ) +// n.getPrefix( ) +// n.getEntryCount( ) +// n.getAFI( ) +// n.getSAFI( ) + +// n.getPeerIndexTbl() + + BOOST_FOREACH( const TblDumpV2RibEntryPtr &entry, n.getRibEntries() ) + { + entry->accept( *this, param ); + } + } + + virtual void visit( MRTTblDumpV2RibGeneric &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + virtual void visit( MRTTblDumpV2RibIPv4Multicast &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + virtual void visit( MRTTblDumpV2RibIPv4Unicast &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + virtual void visit( MRTTblDumpV2RibIPv6Multicast &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + virtual void visit( MRTTblDumpV2RibIPv6Unicast &n, boost::any ¶m ) + { + static_cast( n ).accept( *this, param ); + } + + virtual void visit( TblDumpV2RibEntry &n, boost::any ¶m ) + { +// n.getPeerIndex( ) +// n.getOriginatedTime( ) +// n.getAttributeLength( ) + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getAttributes() ) + { + attr->accept( *this, param ); + } + } + + virtual void visit( BGPCommonHeader &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + } + + virtual void visit( BGPKeepAlive &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + } + + virtual void visit( BGPNotification &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getErrorCode( ) +// n.getSubErrorCode( ) +// n.getData( ) + } + + virtual void visit( BGPOpen &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getVersion( ) +// n.getMyAS( ) +// n.getHoldTime( ) +// n.getBgpId( ) +// n.getOptParmLen( ) +// n.isAS4Supported( ) + + BOOST_FOREACH( const OptionalParameterPtr ¶m, n.getOptParams( ) ) + { + param->accept( *this, param ); + } + } + virtual void visit( BGPRouteRefresh &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getAfi( ) +// n.getRes( ) +// n.getSafi( ) + } + virtual void visit( BGPUpdate &n, boost::any ¶m ) + { +// n.getMarker() +// n.getLength() +// n.getType() + +// n.getWithdrawnRoutesLength() +// n.getPathAttributesLength() +// n.getNlriLength() + + BOOST_FOREACH( const BGPAttributePtr &attr, n.getPathAttributes() ) + { + attr->accept( *this, param ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getWithdrawnRoutes() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const RoutePtr &route, n.getNlriRoutes() ) + { + route->accept( *this, param ); + } + } + + virtual void visit( BGPAttribute &n, boost::any ¶m ) + { +// n.getAttributeFlags( ) +// n.getAttributeTypeCode( ) +// n.getAttributeLength( ) +// + other helpers available, see BGPAttribute + + n.getAttributeValue()->accept( *this, param ); + } + + virtual void visit( AttributeType &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + } + virtual void visit( AttributeTypeAS4Aggregator &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + } + virtual void visit( AttributeTypeASPath &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// + n.getPathSegmentsComplete() is also available + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this, param ); + } + } + virtual void visit( AttributeTypeASPathSegment &n, boost::any ¶m ) + { +// n.getPathSegmentType( ) +// n.getPathSegmentLength( ) +// n.getPathSegmentValue( ) + } + virtual void visit( AttributeTypeAS4Path &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + + BOOST_FOREACH( const AttributeTypeASPathSegmentPtr &segment, n.getPathSegments() ) + { + segment->accept( *this, param ); + } + } + virtual void visit( AttributeTypeAS4PathSegment &n, boost::any ¶m ) + { +// n.getPathSegmentType( ) +// n.getPathSegmentLength( ) +// n.getPathSegmentValue( ) + } + virtual void visit( AttributeTypeAggregator &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAggregatorLastAS( ) +// n.getAggregatorLastASComplete( ) +// n.getAggregatorBGPSpeakerIPAddress( ) + } + virtual void visit( AttributeTypeAtomicAggregate &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + } + virtual void visit( AttributeTypeClusterList &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getClusterList( ) + } + virtual void visit( AttributeTypeCommunities &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getCommunityValues( ) + } + virtual void visit( AttributeTypeExtCommunities &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getExtCommunityValues( ) + } + virtual void visit( AttributeTypeLocalPref &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getLocalPrefValue( ) + } + virtual void visit( AttributeTypeMPReachNLRI &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) +// n.getNextHopAddressLength( ) +// n.getNextHopAddress( ) +// n.getNextHopAddressLocal( ) + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getNLRI() ) + { + route->accept( *this, param ); + } + + BOOST_FOREACH( const NLRIReachablePtr& route, n.getSNPA() ) + { + route->accept( *this, param ); + } + } + virtual void visit( AttributeTypeMPUnreachNLRI &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getAFI( ) +// n.getSAFI( ) + + BOOST_FOREACH( const NLRIUnReachablePtr &route, n.getNLRI() ) + { + route->accept( *this, param ); + } + } + virtual void visit( AttributeTypeMultiExitDisc &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getMultiExitDiscValue( ) + } + virtual void visit( AttributeTypeNextHop &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getNextHopIPAddress( ) +// n.getNextHopAFI( ) + } + virtual void visit( AttributeTypeOrigin &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + } + virtual void visit( AttributeTypeOriginatorID &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getData( ) +// n.getAS4( ) + +// n.getOrigin( ) + } + + virtual void visit( OptionalParameter &n, boost::any ¶m ) + { +// n.getType( ) +// n.getLength( ) + } + virtual void visit( OptionalParameterCapabilities &n, boost::any ¶m ) + { +// n.getType( ) +// n.getLength( ) + +// n.getCapCode( ) +// n.getCapLength( ) +// n.getCapValue( ) + } + + virtual void visit( Route &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + + virtual void visit( NLRIReachable &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } + virtual void visit( NLRIUnReachable &n, boost::any ¶m ) + { +// n.getLength( ) +// n.getPrefix( ) +// n.getNumOctets( ) +// + helper methods available, see Route + } +}; + +#endif diff --git a/include/visitors/GJVoidVisitor.h b/include/visitors/GJVoidVisitor.h new file mode 100644 index 0000000..b0af355 --- /dev/null +++ b/include/visitors/GJVoidVisitor.h @@ -0,0 +1,59 @@ + +#ifndef _GJVOIDVISITOR_H_ +#define _GJVOIDVISITOR_H_ + +#include "ForwardDeclarations.h" + +class GJVoidVisitor +{ +public: + virtual void visit( MRTCommonHeader& , boost::any& )=0; + + virtual void visit( MRTBgp4MPMessage& , boost::any& )=0; + virtual void visit( MRTBgp4MPMessageAS4& , boost::any& )=0; + virtual void visit( MRTBgp4MPStateChange& , boost::any& )=0; + virtual void visit( MRTBgp4MPStateChangeAS4& , boost::any& )=0; + + virtual void visit( AttributeType& , boost::any& )=0; + virtual void visit( AttributeTypeAS4Aggregator& , boost::any& )=0; + virtual void visit( AttributeTypeAS4Path& , boost::any& )=0; + virtual void visit( AttributeTypeAS4PathSegment& , boost::any& )=0; + virtual void visit( AttributeTypeASPath& , boost::any& )=0; + virtual void visit( AttributeTypeASPathSegment& , boost::any& )=0; + virtual void visit( AttributeTypeAggregator& , boost::any& )=0; + virtual void visit( AttributeTypeAtomicAggregate& , boost::any& )=0; + virtual void visit( AttributeTypeClusterList& , boost::any& )=0; + virtual void visit( AttributeTypeCommunities& , boost::any& )=0; + virtual void visit( AttributeTypeExtCommunities& , boost::any& )=0; + virtual void visit( AttributeTypeLocalPref& , boost::any& )=0; + virtual void visit( AttributeTypeMPReachNLRI& , boost::any& )=0; + virtual void visit( AttributeTypeMPUnreachNLRI& , boost::any& )=0; + virtual void visit( AttributeTypeMultiExitDisc& , boost::any& )=0; + virtual void visit( AttributeTypeNextHop& , boost::any& )=0; + virtual void visit( AttributeTypeOrigin& , boost::any& )=0; + virtual void visit( AttributeTypeOriginatorID& , boost::any& )=0; + + virtual void visit( BGPCommonHeader& , boost::any& )=0; + virtual void visit( BGPKeepAlive& , boost::any& )=0; + virtual void visit( BGPNotification& , boost::any& )=0; + virtual void visit( BGPOpen& , boost::any& )=0; + virtual void visit( BGPRouteRefresh& , boost::any& )=0; + virtual void visit( BGPUpdate& , boost::any& )=0; + virtual void visit( BGPAttribute& , boost::any& )=0; + + virtual void visit( MRTTblDump& , boost::any& )=0; + virtual void visit( MRTTblDumpV2PeerIndexTbl& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibGeneric& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibHeader& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibIPv4Multicast& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibIPv4Unicast& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibIPv6Multicast& , boost::any& )=0; + virtual void visit( MRTTblDumpV2RibIPv6Unicast& , boost::any& )=0; + virtual void visit( OptionalParameter& , boost::any& )=0; + virtual void visit( OptionalParameterCapabilities& , boost::any& )=0; + virtual void visit( TblDumpV2RibEntry& , boost::any& )=0; + + virtual void visit( Route& , boost::any& )=0; +}; + +#endif diff --git a/include/visitors/Visitor.h b/include/visitors/Visitor.h new file mode 100644 index 0000000..134bdbd --- /dev/null +++ b/include/visitors/Visitor.h @@ -0,0 +1,61 @@ + +#ifndef _VISITOR_H_ +#define _VISITOR_H_ + +#include "ForwardDeclarations.h" + +class Visitor +{ +public: + virtual void visit( MRTCommonHeader& )=0; + + virtual void visit( MRTBgp4MPMessage& )=0; + virtual void visit( MRTBgp4MPMessageAS4& )=0; + virtual void visit( MRTBgp4MPStateChange& )=0; + virtual void visit( MRTBgp4MPStateChangeAS4& )=0; + + virtual void visit( AttributeType& )=0; + virtual void visit( AttributeTypeAS4Aggregator& )=0; + virtual void visit( AttributeTypeAS4Path& )=0; + virtual void visit( AttributeTypeAS4PathSegment& )=0; + virtual void visit( AttributeTypeASPath& )=0; + virtual void visit( AttributeTypeASPathSegment& )=0; + virtual void visit( AttributeTypeAggregator& )=0; + virtual void visit( AttributeTypeAtomicAggregate& )=0; + virtual void visit( AttributeTypeClusterList& )=0; + virtual void visit( AttributeTypeCommunities& )=0; + virtual void visit( AttributeTypeExtCommunities& )=0; + virtual void visit( AttributeTypeLocalPref& )=0; + virtual void visit( AttributeTypeMPReachNLRI& )=0; + virtual void visit( AttributeTypeMPUnreachNLRI& )=0; + virtual void visit( AttributeTypeMultiExitDisc& )=0; + virtual void visit( AttributeTypeNextHop& )=0; + virtual void visit( AttributeTypeOrigin& )=0; + virtual void visit( AttributeTypeOriginatorID& )=0; + + virtual void visit( BGPCommonHeader& )=0; + virtual void visit( BGPKeepAlive& )=0; + virtual void visit( BGPNotification& )=0; + virtual void visit( BGPOpen& )=0; + virtual void visit( BGPRouteRefresh& )=0; + virtual void visit( BGPUpdate& )=0; + virtual void visit( BGPAttribute& )=0; + + virtual void visit( MRTTblDump& )=0; + virtual void visit( MRTTblDumpV2PeerIndexTbl& )=0; + virtual void visit( MRTTblDumpV2RibGeneric& )=0; + virtual void visit( MRTTblDumpV2RibHeader& )=0; + virtual void visit( MRTTblDumpV2RibIPv4Multicast& )=0; + virtual void visit( MRTTblDumpV2RibIPv4Unicast& )=0; + virtual void visit( MRTTblDumpV2RibIPv6Multicast& )=0; + virtual void visit( MRTTblDumpV2RibIPv6Unicast& )=0; + virtual void visit( OptionalParameter& )=0; + virtual void visit( OptionalParameterCapabilities& )=0; + virtual void visit( TblDumpV2RibEntry& )=0; + + virtual void visit( Route& )=0; + virtual void visit( NLRIReachable& )=0; + virtual void visit( NLRIUnReachable& )=0; +}; + +#endif diff --git a/parser/BGPOpen.cpp b/parser/BGPOpen.cpp index 811ca79..c2be8aa 100644 --- a/parser/BGPOpen.cpp +++ b/parser/BGPOpen.cpp @@ -84,6 +84,7 @@ BGPOpen::BGPOpen( BGPCommonHeader &header, std::istream &input ) } } + optParams.push_back( param ); left-=param->getLength( ); } } diff --git a/parser/MRTBgp4MPEntry.cpp b/parser/MRTBgp4MPEntry.cpp deleted file mode 100644 index 7f46238..0000000 --- a/parser/MRTBgp4MPEntry.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008,2009, University of California, Los Angeles All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NLnetLabs nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -// Modified: Jonathan Park (jpark@cs.ucla.edu) -#include - -#include "MRTBgp4MPEntry.h" -#include "Exceptions.h" - -using namespace std; - -#include -#include -namespace io = boost::iostreams; - -log4cxx::LoggerPtr MRTBgp4MPEntry::Logger=log4cxx::Logger::getLogger( "bgpparser.MRTBgp4MPEntry" ); - -MRTBgp4MPEntry::MRTBgp4MPEntry( MRTCommonHeader &header, istream &input ) : MRTCommonHeader(header) -{ - LOG4CXX_TRACE( Logger, "" ); - - bool error=false; - - MRTBgp4MPEntryPacket pkt; - error|= sizeof(MRTBgp4MPEntryPacket)!= - io::read( input, reinterpret_cast(&pkt), sizeof(MRTBgp4MPEntryPacket) ); - - viewNumber = ntohs(pkt.viewNumber); - status = ntohs(pkt.status); - timeLastChange = ntohl(pkt.timeLastChange); - addressFamily = ntohs(pkt.addressFamily); - safi = pkt.safi; - - throw BGPTextError( "MRTBgp4MP is not supported yet" ); - /* how to extract out next hop address based on next hop length? */ - - /* move pointer p to beginning of prefix length field assuming next hop len field is in bytes */ - io::detail::skip( input, pkt.nextHopLength, boost::mpl::false_() ); - - /* set prefix length and increment pointer p to beginning of variable length address prefix field */ - io::read( input, reinterpret_cast(&prefixLength), sizeof(uint8_t) ); - - /* TODO: this message format has been _deprecated_ and is no longer supported */ - - /* TODO: increment the pointer to the new location in the file stream */ -} - -MRTBgp4MPEntry::~MRTBgp4MPEntry(void) { - /* nothing */ -} diff --git a/parser/MRTBgp4MPMessage.cpp b/parser/MRTBgp4MPMessage.cpp index 0ffe119..4acb4f1 100644 --- a/parser/MRTBgp4MPMessage.cpp +++ b/parser/MRTBgp4MPMessage.cpp @@ -97,26 +97,3 @@ MRTBgp4MPMessage::~MRTBgp4MPMessage(void) { } -uint32_t MRTBgp4MPMessage::getPeerAS(void) const { - return peerAS; -} - -uint32_t MRTBgp4MPMessage::getLocalAS(void) const { - return localAS; -} - -uint16_t MRTBgp4MPMessage::getInterfaceIndex(void) const { - return interfaceIndex; -} - -uint16_t MRTBgp4MPMessage::getAddressFamily(void) const { - return addressFamily; -} - -IPAddress MRTBgp4MPMessage::getPeerIP(void) const { - return peerIP; -} - -IPAddress MRTBgp4MPMessage::getLocalIP(void) const { - return localIP; -} diff --git a/parser/MRTBgp4MPSnapshot.cpp b/parser/MRTBgp4MPSnapshot.cpp deleted file mode 100644 index ca07368..0000000 --- a/parser/MRTBgp4MPSnapshot.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2008,2009, University of California, Los Angeles All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NLnetLabs nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -// Modified: Jonathan Park (jpark@cs.ucla.edu) -#include - -#include "MRTBgp4MPSnapshot.h" -#include "Exceptions.h" - -using namespace std; - -#include -namespace io = boost::iostreams; - -log4cxx::LoggerPtr MRTBgp4MPSnapshot::Logger = log4cxx::Logger::getLogger( "bgpparser.MRTBgp4MPSnapshot" ); - -MRTBgp4MPSnapshot::MRTBgp4MPSnapshot( MRTCommonHeader &header, std::istream &input ) -: MRTCommonHeader( header ) -{ - LOG4CXX_TRACE( Logger, "" ); - - /* copy out the view number and convert to host order */ - bool error= sizeof(uint16_t)!= - io::read( input, reinterpret_cast(&viewNumber), sizeof(uint16_t) ); - viewNumber = ntohs(viewNumber); - - if( error ) - { - LOG4CXX_ERROR( Logger, "Parsing error" ); - throw BGPError( ); - } - - input >> fileName; -} - -MRTBgp4MPSnapshot::~MRTBgp4MPSnapshot(void) { - /* nothing */ -} - diff --git a/parser/MRTCommonHeader.cpp b/parser/MRTCommonHeader.cpp index e0651f5..3ad116b 100644 --- a/parser/MRTCommonHeader.cpp +++ b/parser/MRTCommonHeader.cpp @@ -35,8 +35,6 @@ #include "MRTBgp4MPStateChangeAS4.h" #include "MRTBgp4MPMessage.h" #include "MRTBgp4MPMessageAS4.h" -#include "MRTBgp4MPEntry.h" -#include "MRTBgp4MPSnapshot.h" #include "MRTTblDump.h" #include "MRTTblDumpV2PeerIndexTbl.h" @@ -90,22 +88,6 @@ MRTCommonHeader::~MRTCommonHeader(void) { /* nothing */ } -time_t MRTCommonHeader::getTimestamp(void) const { - return timestamp; -} - -uint16_t MRTCommonHeader::getType(void) const { - return type; -} - -uint16_t MRTCommonHeader::getSubType(void) const { - return subtype; -} - -uint32_t MRTCommonHeader::getLength(void) const { - return length; -} - /* * Factory method for creating MRTMessages */ @@ -158,16 +140,16 @@ MRTMessagePtr MRTCommonHeader::newMessage( istream &input ) { break; case BGP4MP_ENTRY: - //PRINT_DBG(" Case BGP4MP_ENTRY"); - //msg = new MRTBgp4MPEntry(ptr); /* not supported yet */ - //break; + /* deprecated */ + msg=header; + break; case BGP4MP_SNAPSHOT: - //PRINT_DBG(" Case BGP4MP_SNAPSHOT"); - //msg = new MRTBgp4MPSnapshot(ptr); /* not supported yet */ - //break; + /* deprecated */ + msg=header; + break; default: LOG4CXX_ERROR( Logger, "unrecognized subtype ["<< (int)header->getSubType() <<"] for bgp4mp." ); - + msg=header; break; } } diff --git a/parser/MRTTblDump.cpp b/parser/MRTTblDump.cpp index e309a17..9d080e3 100644 --- a/parser/MRTTblDump.cpp +++ b/parser/MRTTblDump.cpp @@ -129,42 +129,6 @@ MRTTblDump::~MRTTblDump(void) { } -uint16_t MRTTblDump::getViewNumber(void) const { - return viewNumber; -} - -uint16_t MRTTblDump::getSequenceNumber(void) const { - return sequenceNumber; -} - -IPAddress MRTTblDump::getPrefix(void) const { - return prefix; -} - -uint8_t MRTTblDump::getPrefixLength(void) const { - return prefixLength; -} - -uint8_t MRTTblDump::getStatus(void) const { - return status; -} - -time_t MRTTblDump::getOriginatedTime(void) const { - return originatedTime; -} - -IPAddress MRTTblDump::getPeerIP(void) const { - return peerIP; -} - -uint16_t MRTTblDump::getPeerAS(void) const { - return peerAS; -} - -uint16_t MRTTblDump::getAttributeLength(void) const { - return attributeLength; -} - void MRTTblDump::printMeCompact() { cout << viewNumber << "|" << sequenceNumber << "|"; if (getSubType() == AFI_IPv4) { diff --git a/parser/MRTTblDumpV2PeerIndexTbl.cpp b/parser/MRTTblDumpV2PeerIndexTbl.cpp index 407b308..8dfdbf0 100644 --- a/parser/MRTTblDumpV2PeerIndexTbl.cpp +++ b/parser/MRTTblDumpV2PeerIndexTbl.cpp @@ -149,22 +149,3 @@ MRTTblDumpV2PeerIndexTbl::MRTTblDumpV2PeerIndexTbl( MRTCommonHeader &header, std MRTTblDumpV2PeerIndexTbl::~MRTTblDumpV2PeerIndexTbl(void) { } -const MRTTblDumpV2PeerIndexTblPeerEntryPtr MRTTblDumpV2PeerIndexTbl::getPeer( uint16_t peerIndex ) -{ - if( peerIndex>peerEntries.size() ) throw BGPTextError( "Corrupted PeerIndexTbl" ); - return peerEntries[peerIndex]; -} - - -uint32_t MRTTblDumpV2PeerIndexTbl::getCollectorBGPId(void) const { - return collectorBGPId; -} - -uint16_t MRTTblDumpV2PeerIndexTbl::getViewNameLength(void) const { - return viewNameLength; -} - -uint16_t MRTTblDumpV2PeerIndexTbl::getPeerCount(void) const { - return peerCount; -} - diff --git a/parser/MRTTblDumpV2RibHeader.cpp b/parser/MRTTblDumpV2RibHeader.cpp index 3b748e3..21dae21 100644 --- a/parser/MRTTblDumpV2RibHeader.cpp +++ b/parser/MRTTblDumpV2RibHeader.cpp @@ -97,30 +97,6 @@ void MRTTblDumpV2RibHeader::init( istream &input ) MRTTblDumpV2RibHeader::~MRTTblDumpV2RibHeader(void) { } -uint32_t MRTTblDumpV2RibHeader::getSequenceNumber(void) const { - return sequenceNumber; -} - -uint8_t MRTTblDumpV2RibHeader::getPrefixLength(void) const { - return prefixLength; -} - -IPAddress MRTTblDumpV2RibHeader::getPrefix(void) const { - return prefix; -} - -uint16_t MRTTblDumpV2RibHeader::getEntryCount(void) const { - return entryCount; -} - -uint16_t MRTTblDumpV2RibHeader::getAFI(void) const { - return afi; -} - -uint16_t MRTTblDumpV2RibHeader::getSAFI(void) const { - return safi; -} - /* static */void MRTTblDumpV2RibHeader::processAttributes( list &attributes, istream &input, int len, bool isAS4 ) { diff --git a/parser/Makefile.am b/parser/Makefile.am index 9a31dbb..dc24310 100644 --- a/parser/Makefile.am +++ b/parser/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(top_srcdir)/include $(log4cxx_CFLAGS) $(BOOST_CPPFLAGS) +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/parsers $(log4cxx_CFLAGS) $(BOOST_CPPFLAGS) lib_LTLIBRARIES=libbgpparser.la @@ -31,10 +31,8 @@ BGPNotification.cpp \ BGPOpen.cpp \ BGPRouteRefresh.cpp \ BGPUpdate.cpp \ -MRTBgp4MPEntry.cpp \ MRTBgp4MPMessage.cpp \ MRTBgp4MPMessageAS4.cpp \ -MRTBgp4MPSnapshot.cpp \ MRTBgp4MPStateChange.cpp \ MRTBgp4MPStateChangeAS4.cpp \ MRTCommonHeader.cpp \ @@ -51,57 +49,45 @@ TblDumpV2RibEntry.cpp libbgpparser_la_HEADERS = \ ../include/bgpparser.h \ ../include/Exceptions.h \ -../include/AttributeType.h \ -../include/AttributeTypeAS4Aggregator.h \ -../include/AttributeTypeAS4Path.h \ -../include/AttributeTypeASPath.h \ -../include/AttributeTypeAggregator.h \ -../include/AttributeTypeAtomicAggregate.h \ -../include/AttributeTypeClusterList.h \ -../include/AttributeTypeCommunities.h \ -../include/AttributeTypeDumper.h \ -../include/AttributeTypeExtCommunities.h \ -../include/AttributeTypeLocalPref.h \ -../include/AttributeTypeMPReachNLRI.h \ -../include/AttributeTypeMPUnreachNLRI.h \ -../include/AttributeTypeMultiExitDisc.h \ -../include/AttributeTypeNextHop.h \ -../include/AttributeTypeOrigin.h \ -../include/AttributeTypeOriginatorID.h \ -../include/OptionalParameter.h \ -../include/OptionalParameterCapabilities.h \ -../include/BGPAttribute.h \ -../include/BGPAttributeDumper.h \ -../include/BGPCommonHeader.h \ -../include/BGPDumper.h \ -../include/BGPKeepAlive.h \ -../include/BGPMessageDumper.h \ -../include/BGPNotification.h \ -../include/BGPOpen.h \ -../include/BGPRouteRefresh.h \ -../include/BGPStateChangeDumper.h \ -../include/BGPStructure.h \ -../include/BGPUpdate.h \ -../include/Dumper.h \ -../include/MRTBgp4MPEntry.h \ -../include/MRTBgp4MPMessage.h \ -../include/MRTBgp4MPMessageAS4.h \ -../include/MRTBgp4MPMessageDumper.h \ -../include/MRTBgp4MPSnapshot.h \ -../include/MRTBgp4MPStateChange.h \ -../include/MRTBgp4MPStateChangeAS4.h \ -../include/MRTBgp4MPStateChangeDumper.h \ -../include/MRTCommonHeader.h \ -../include/MRTStructure.h \ -../include/MRTTblDump.h \ -../include/MRTTblDumpV1Dumper.h \ -../include/MRTTblDumpV2Dumper.h \ -../include/MRTTblDumpV2PeerIndexTbl.h \ -../include/MRTTblDumpV2RibGeneric.h \ -../include/MRTTblDumpV2RibHeader.h \ -../include/MRTTblDumpV2RibIPv4Multicast.h \ -../include/MRTTblDumpV2RibIPv4Unicast.h \ -../include/MRTTblDumpV2RibIPv6Multicast.h \ -../include/MRTTblDumpV2RibIPv6Unicast.h \ -../include/TblDumpV2RibEntry.h +../include/parsers/AttributeType.h \ +../include/parsers/AttributeTypeAS4Aggregator.h \ +../include/parsers/AttributeTypeAS4Path.h \ +../include/parsers/AttributeTypeASPath.h \ +../include/parsers/AttributeTypeAggregator.h \ +../include/parsers/AttributeTypeAtomicAggregate.h \ +../include/parsers/AttributeTypeClusterList.h \ +../include/parsers/AttributeTypeCommunities.h \ +../include/parsers/AttributeTypeExtCommunities.h \ +../include/parsers/AttributeTypeLocalPref.h \ +../include/parsers/AttributeTypeMPReachNLRI.h \ +../include/parsers/AttributeTypeMPUnreachNLRI.h \ +../include/parsers/AttributeTypeMultiExitDisc.h \ +../include/parsers/AttributeTypeNextHop.h \ +../include/parsers/AttributeTypeOrigin.h \ +../include/parsers/AttributeTypeOriginatorID.h \ +../include/parsers/OptionalParameter.h \ +../include/parsers/OptionalParameterCapabilities.h \ +../include/parsers/BGPAttribute.h \ +../include/parsers/BGPCommonHeader.h \ +../include/parsers/BGPKeepAlive.h \ +../include/parsers/BGPNotification.h \ +../include/parsers/BGPOpen.h \ +../include/parsers/BGPRouteRefresh.h \ +../include/parsers/BGPStructure.h \ +../include/parsers/BGPUpdate.h \ +../include/parsers/MRTBgp4MPMessage.h \ +../include/parsers/MRTBgp4MPMessageAS4.h \ +../include/parsers/MRTBgp4MPStateChange.h \ +../include/parsers/MRTBgp4MPStateChangeAS4.h \ +../include/parsers/MRTCommonHeader.h \ +../include/parsers/MRTStructure.h \ +../include/parsers/MRTTblDump.h \ +../include/parsers/MRTTblDumpV2PeerIndexTbl.h \ +../include/parsers/MRTTblDumpV2RibGeneric.h \ +../include/parsers/MRTTblDumpV2RibHeader.h \ +../include/parsers/MRTTblDumpV2RibIPv4Multicast.h \ +../include/parsers/MRTTblDumpV2RibIPv4Unicast.h \ +../include/parsers/MRTTblDumpV2RibIPv6Multicast.h \ +../include/parsers/MRTTblDumpV2RibIPv6Unicast.h \ +../include/parsers/TblDumpV2RibEntry.h