BGPmon-core-2
view release on metacpan or search on metacpan
lib/BGPmon/Translator/XFB2PerlHash/Simpler.pm view on Meta::CPAN
=cut
sub extract_sender_port{
my $fname = 'extract_sender_port';
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/SOURCE/PORT/content');
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
return $hashRes;
}
=head2 extract_sender_asn
Will extract a sender's ASN number from the parsed XML mesage.
Input: None
Output: ASN number if successful; undef if not.
=cut
sub extract_sender_asn{
my $fname = 'extract_sender_asn';
my $hashRes2 = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/SOURCE/ASN2/content');
my $hashRes4 = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/SOURCE/ASN4/content');
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
if(defined($hashRes2) and $hashRes2 ne ""){
return $hashRes2;
}
elsif(defined($hashRes4) and $hashRes4 ne ""){
return $hashRes4;
}
else{
return undef;
}
}
=head2 extract_withdraw
Will extract all the withdrawn prefixes from the parsed XML mesage.
Input: None
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.
=cut
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'});
}
#Uniqueing
@nlris = uniq(@nlris);
return @nlris;
}
=head2 extract_mpreach_nlri
Will extract all the IPv4/6 prefixes announced in MP_REACH_NLRI's from
the parsed XML mesage. This will exclude the MP_REACH NEXT_HOP.
Input: None
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
=cut
sub extract_mpunreach_nlri{
my $fname = 'extract_mpunreach_nlri';
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
#Getting mp_unreach_nlris
my @toReturn = ();
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:MP_UNREACH_NLRI/bgp:MP_NLRI/');
if(ref($hashRes) eq "ARRAY"){
foreach my $res (@$hashRes){
push(@toReturn, $res->{'content'});
}
}
elsif(ref($hashRes) eq "HASH"){
push(@toReturn,$hashRes->{'content'});
}
#Uniquing
@toReturn = uniq(@toReturn);
return @toReturn;
}
=head2 extract_aspath
Will extract all the ASNs found in either AS_PATH/AS_SET or AS_PATH/AS_SEQUENCE
from the parsed XML mesage.
Input: None
Output: Array of ASNs found in the AS_PATH path attribute.
=cut
sub extract_aspath{
my $fname = 'extract_aspath';
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
#Checking for AS numbers in the AS_Path attribute
my @toReturn = ();
my $hashRes = BGPmon::Translator::XFB2PerlHash::get_content(
'/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:AS_PATH/bgp:AS_SEQUENCE/bgp:ASN2/');
if(ref($hashRes) eq "ARRAY"){
foreach my $res (@$hashRes){
( run in 0.525 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )