BGPmon-core-2
view release on metacpan or search on metacpan
lib/BGPmon/Translator/XFB2PerlHash/Simple.pm view on Meta::CPAN
=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'
lib/BGPmon/Translator/XFB2PerlHash/Simple.pm view on Meta::CPAN
'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.
lib/BGPmon/Translator/XFB2PerlHash/Simpler.pm view on Meta::CPAN
Output: Array of IPv4/6 prefixes that were seen to have been withdrawn.
=cut
sub extract_withdraw{
my $fname = 'extract_withdarw';
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
#Getting Withdraws
my @with_prefs = ();
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:WITHDRAW/');
if(ref($hashRes) eq "ARRAY"){
foreach my $res (@$hashRes){
push(@with_prefs, $res->{'content'});
}
}
elsif(ref($hashRes) eq "HASH"){
push(@with_prefs, $hashRes->{'content'});
}
#Uniqueing
@with_prefs = uniq(@with_prefs);
return @with_prefs;
}
=head2 extract_nlri
Will extract all the prefixes in NLRI areas from the parsed XML mesage.
Input: None
Output: Array of IPv4 prefixes that were seen in NLRIs.
lib/BGPmon/Translator/XFB2PerlHash/Simpler.pm view on Meta::CPAN
sub extract_nlri{
my $fname = 'extract_nlri';
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
#Getting NLRI's
my @nlris = ();
#Getting NLRI announcements
my @nlri_prefs = ();
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:NLRI/');
if(ref($hashRes) eq "ARRAY"){
foreach my $res (@$hashRes){
push(@nlris, $res->{'content'});
}
}
elsif(ref($hashRes) eq "HASH"){
push(@nlris, $hashRes->{'content'});
lib/BGPmon/Translator/XFB2PerlHash/Simpler.pm view on Meta::CPAN
Output: Array of IPv4/6 prefixes that were seen in MP_REACH_NLRI's
=cut
sub extract_mpreach_nlri{
my $fname = 'extract_mpreach_nlri';
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
#Getting mp_reach_nlris
my @mpnlri_prefs = ();
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:MP_REACH_NLRI/bgp:MP_NLRI/');
if(ref($hashRes) eq "ARRAY"){
foreach my $res (@$hashRes){
push(@mpnlri_prefs, $res->{'content'});
}
}
elsif(ref($hashRes) eq "HASH"){
push(@mpnlri_prefs, $hashRes->{'content'});
}
#Uniqueing
@mpnlri_prefs = uniq(@mpnlri_prefs);
return @mpnlri_prefs;
}
=head2 extract_mpunreach_nlri
Will extract all the IPv4/6 prefixes withdrawn in MP_UNREACH_NLRI's from
the parsed XML mesage.
Input: None
Output: Array of IPv4/6 prefixes that were seen in MP_UNREACH_NLRI's
( run in 0.764 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )