BGPmon-core-2

 view release on metacpan or  search on metacpan

lib/BGPmon/Translator/XFB2PerlHash/Simple.pm  view on Meta::CPAN

=head2 get_xml_message_type

Returns the type of message we're seeing - if it's from a live stream or if
it's from a RIB dump from a BGPmon source.

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/COLLECTION/content') 
      if $function_name eq 'get_xml_message_type';

=head2 get_origin

Returns the stringified origin of the BGP message.  Defined values are given in
the XFB specification.

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:ORIGIN/content')
      if $function_name eq 'get_origin';

=head2 get_next_hop

Returns a scalar IPv4 address in dotted-decimal notation as given in the next 
hop attribute.

=cut
    #Get the string representation of the content of the NEXT_HOP element
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:NEXT_HOP/content')
      if $function_name eq 'get_next_hop';

=head2 get_xml_string

Returns the raw XML string passed into init

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content('/raw') 
      if $function_name eq 'get_xml_string';
    
=head2 get_status

Returns the status message in the XML if it exists

=cut
    #Return the status message
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/STATUS/TYPE/content') 
      if $function_name eq 'get_status';

################################ ARRAY ELEMENTS ###############################

=head2 get_mp_next_hop

Returns an array of hashes with the next hop(s) from the MP_REACH attribute.

Ex:     my @ret = get_mp_next_hop();
        print my $addr-{'ADDRESS'}-{'content'} foreach $addr (@ret);

=cut
    if($function_name eq 'get_mp_next_hop'){
      my @prefs = ();
      my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content
        ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:MP_REACH_NLRI/bgp:MP_NEXT_HOP/');
      if(ref($hashRes) eq "ARRAY"){
        @prefs = (@prefs, @$hashRes);
      }
      elsif(ref($hashRes) eq "HASH"){
        push(@prefs, $hashRes);
      }
      return @prefs; 
    }

=head2 get_nlri

Returns an array of hashes.  Each of these hashes are structured like so:

{
    'SAFI' = {
                'value' = '1',
                'content' = 'UNICAST'
              },
    'AFI' = {
                'value' = '1',
                'content' = 'IPV4'
             },
    'ADDRESS' = {
                'content' = '192.168.0.0/16'
                 }

}
=cut
    if ($function_name eq 'get_nlri'){
      my @nlri_prefs = (); 
      my $hashRes =  BGPmon::Translator::XFB2PerlHash::get_content
        ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:NLRI/');
      if(ref($hashRes) eq "ARRAY"){
        @nlri_prefs = (@nlri_prefs, @$hashRes);
      }
      elsif(ref($hashRes) eq "HASH"){
        push(@nlri_prefs, $hashRes);
      }
      return @nlri_prefs;
    }

=head2 get_withdrawn

Returns an array of hashes which contain an AFI,SAFI,and withdrawn IPv4 prefix.
These hashes are structured just like the ones described in the documentation
for get_nlri().

=cut
    if ($function_name eq 'get_withdrawn') {
      my @with_prefs = ();
      my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content
        ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:WITHDRAW/');

       if(ref($hashRes) eq "ARRAY"){
         @with_prefs = (@with_prefs, @$hashRes);
       }
       elsif(ref($hashRes) eq "HASH"){
         push(@with_prefs, $hashRes);
       }
       return @with_prefs;
    }

################################### HASHREF ELEMENTS ##########################
=head2 get_as_path

Returns an array of hashes that contains the AS path attribute of the message.
Each hash represents a single AS Segment, which can be either an AS_SEQUENCE
or AS_SET.  Each AS_SEG has an AS subarray that contains the ASNs for that 
segment.

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:AS_PATH/')  
      if $function_name eq 'get_as_path';

=head2 get_as4_path

Returns an array of hashes that contains the AS4_PATH attribute of the message.
Each hash represents a single AS Segment, which can be either an AS_SEQUENCE
or AS_SET.  Each AS_SEG has an AS subarray that contains the ASNs for that 
segment.

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:AS4_PATH/')
      if $function_name eq 'get_as4_path';

=head2 get_mp_nlri

Returns an array of hashes which contain an AFI,SAFI,and announced prefix. 
These hashes are structured just like the ones described in the documentation
for get_nlri().

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:MP_REACH_/NLRI/') 
      if $function_name eq 'get_mp_nlri';

=head2 get_mp_withdrawn

Returns an array of hashes which contain an AFI,SAFI,and withdrawn prefix.
These hashes are structured just like the ones described in the documentation
for get_nlri().

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:MP_UNREACH_NLRI/') 
      if $function_name eq 'get_mp_withdrawn';

=head2 get_peering

Returns a hash reference that contains information about the BGP peering
session that the message was received from.  To see its contents, check the 
XFB specification or use Data::Dumper.

=cut
    return BGPmon::Translator::XFB2PerlHash::get_content
      ('/BGP_MONITOR_MESSAGE/SOURCE/') if $function_name eq 'get_peering';

################################ ERROR HANDLING ###############################



( run in 1.628 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )