BGPmon-core-1
view release on metacpan or search on metacpan
bin/bgpmon_filter view on Meta::CPAN
################################PROGRAM START SUBROUTINES#############################
sub logFilterSize{
my $numPrefs = BGPmon::Filter::get_num_ASes();
log_info("Total ASes parsed: $numPrefs");
$numPrefs = BGPmon::Filter::get_num_ip_addrs();
log_info("Total addresses parsed: $numPrefs");
$numPrefs = BGPmon::Filter::get_num_IPv4_prefs();
log_info("total IPv4 prefixes after condensing: $numPrefs");
$numPrefs = BGPmon::Filter::get_num_IPv6_prefs();
log_info("total IPv6 prefixes after condensing: $numPrefs");
$numPrefs= BGPmon::Filter::get_total_num_filters();
log_info("Total number of active filters:$numPrefs");
}
sub parseAndCheck{
my @params = (
{
Name => BGPmon::Configure::CONFIG_FILE_PARAMETER_NAME,
lib/BGPmon/Filter.pm view on Meta::CPAN
use threads;
use threads::shared;
BEGIN{
require Exporter;
our $VERSION = '1.092';
our $AUTOLOAD;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(init parse_xml_msg parse_config_file
parse_database_config toString filterReset get_error_msg get_error_code
matches printFilters get_num_IPv4_prefs get_num_IPv6_prefs
get_num_ASes get_num_ip_addrs get_tot_num_filters);
}
my $progName = $0;
# Variables to hold error codes and messages
my %error_code;
my %error_msg;
lib/BGPmon/Filter.pm view on Meta::CPAN
$error_msg{$fname} = UNKNOWN_CONFIG_MSG;
return 1;
}
}
#closing the file
close($file);
condense_prefs(); #aggregates where possible
optimize_prefs(); #puts them in the multilayer hash for faster lookups
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
return 0;
}
sub parse_database_config{
my $listName = shift;
my $fname = 'parse_database_config';
lock($lock);
#getting a list of prefixes
my @prefs = BGPmon::CPM::PList::Manager::export2CSV('',$listName);
my $size = scalar(@prefs);
if($size == 0){
#TODO create an error message that has the list size at zero
}
#resetting the module
filterReset();
#creating new prefixes
foreach(@prefs){
my $newPref = $_->prefix();
my $moreSpec = $_->watch_more_specifics();
if(is_IPv6($newPref)){
my $temp = new BGPmon::Filter::Prefix(6, $newPref, $moreSpec);
push(@v6prefixes, $temp);
}
else{
my $temp = new BGPmon::Filter::Prefix(4, $newPref, $moreSpec);
push(@v4prefixes, $temp);
}
}
#optimizing
condense_prefs(); #aggregates where possible
optimize_prefs(); #puts them in the multilayer hash for faster lookups
$error_code{$fname} = NO_ERROR_CODE;
$error_msg{$fname} = NO_ERROR_MSG;
return 0;
}
#puts the prefixes for IPv4 into a multi-layer hash lookup
sub optimize_prefs{
foreach(@v4prefixes){
my $temp = $_;
addV4prefixToHash($temp->prefix(), $temp);
}
#TODO put in error codes
return 0;
}
=head2 get_num_IPv4_prefs
Will count the number of IPv4 prefixes it has parsed from the configuration
file and return the integer
Input: None
Output : Integer
=cut
sub get_num_IPv4_prefs{
my $toReturn = scalar(@v4prefixes);
return $toReturn;
}
=head2 get_num_IPv6_prefs
Will count the number of IPv6 prefixes it has parsed from the configuration
file and return the integer
Input: None
Output : Integer
=cut
sub get_num_IPv6_prefs{
my $toReturn = scalar(@v6prefixes);
return $toReturn;
}
=head2 get_num_ASes
Will count the number of ASes it has parsed from the configuration
file and return the integer
lib/BGPmon/Filter.pm view on Meta::CPAN
lock($lock);
my $toReturn = 0;
$toReturn += scalar(@v4prefixes);
$toReturn += scalar(@v6prefixes);
$toReturn += scalar(%asNumbers);
$toReturn += scalar(@addresses);
return $toReturn;
}
#condense__prefs
#
#Will try to aggregate IPv4 and IPv6 prefixes where possible. This is used to reduce
#overhead that the filter script may experience later. Please note that the
#parse_config_file must be ran beforehand.
#
#Input: None
#
#Output: 0 if there is no error
# 1 if an error occured
#
#
sub condense_prefs{
##Starting with IPv4
#Will continuously agg. addresses where it can until none are left
my $found = TRUE;
while($found){
$found = FALSE;
for( my $i = 0; $i < scalar(@v4prefixes); $i++){
my $currPref = $v4prefixes[$i];
for(my $k = $i+1; $k < scalar(@v4prefixes); $k++){
my $thisPref = $v4prefixes[$k];
t/00-bgpmon-filter.t view on Meta::CPAN
#Testing XML Message Parsing
BGPmon::Filter::init();
BGPmon::Filter::parse_config_file($location."bgpmon-filter-config.txt");
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
#--testing that the code checks for a message
BGPmon::Filter::parse_xml_msg();
$errCode = BGPmon::Filter::get_error_code('parse_xml_msg');
is($errCode, BGPmon::Filter::NO_MSG_GIVEN, "No XML Message Given");
#--testing for correct <WITHDRAWN> filtering
my $xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" seq_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z" precision_ti...
my $res = BGPmon::Filter::matches($xml4msg);
is($res, TRUE, "XML IPv4 WITHDRAWN tag");
t/00-bgpmon-filter.t view on Meta::CPAN
#--testing for as number in as path - last as number
$xml4msg = '<BGP_MESSAGE length="00002457" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="2128112124" seq_num="2021378733"/><TIME timestamp="1343692801" datetime="2012-07-31T00:00:01Z" precision_time...
my $res5 = BGPmon::Filter::matches($xml4msg);
is($res5, TRUE, "XML AS Last in AS_PATH");
#--testing more specific prefix matching works correctly
BGPmon::Filter::filterReset();
BGPmon::Filter::parse_config_file($location.'bgpmon-filter-config-ms.txt');
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
$xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" seq_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z" precision_time=...
my $resa = BGPmon::Filter::matches($xml4msg);
is($resa, TRUE, "More Specific Prefix Matching");
#--testing less specific prefix matching works correctly
BGPmon::Filter::filterReset();
BGPmon::Filter::parse_config_file($location.'bgpmon-filter-config-ls.txt');
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
$xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" seq_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z" precision_time=...
my $resb = BGPmon::Filter::matches($xml4msg);
is($resb, TRUE, "Less Specific Prefix Matching");
#--tsting that IPv4 address matching works correctly
#Note - this depends on the $xml4msg from the Less Specific Prefix Matching test.
BGPmon::Filter::filterReset();
BGPmon::Filter::parse_config_file($location.'bgpmon-filter-config-ip.txt');
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
my $rescc = BGPmon::Filter::matches($xml4msg);
is($rescc, TRUE, "IPv4 Address Matching");
#--tsting that IPv4 address matching works correctly
#Note - this depends on the $xml4msg from the Less Specific Prefix Matching test.
BGPmon::Filter::filterReset();
BGPmon::Filter::parse_config_file($location.'bgpmon-filter-config-ip.txt');
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
$xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" seq_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z" precision_time=...
$rescc = BGPmon::Filter::matches($xml4msg);
is($rescc, FALSE, "IPv4 Address Matching");
BGPmon::Filter::filterReset();
BGPmon::Filter::parse_config_file($location.'bgpmon-filter-config-all-ms.txt');
BGPmon::Filter::condense_prefs();
BGPmon::Filter::optimize_prefs();
$xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" seq_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z" precision_time=...
my $num = BGPmon::Filter::get_total_num_filters();
is($num, 1, "Number of Filters");
$rescc = BGPmon::Filter::matches($xml4msg);
is($rescc, TRUE, "Filter All");
( run in 2.127 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )