BGPmon-core-2

 view release on metacpan or  search on metacpan

t/04-bgpmon-translator-xfb2bgpdump.t  view on Meta::CPAN

use warnings;
use strict;
use Test::More;
use Data::Dumper;
BEGIN {use_ok( 'BGPmon::Translator::XFB2BGPdump' );}
use BGPmon::Translator::XFB2BGPdump qw(translate_message get_error_code get_error_message);

our $bgp_msg_0_description = "Incomplete message.";
our $bgp_msg_0 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">213.248....

our $bgp_msg_1_description = "Valid XML, type STATUS insead of UPDATE";
our $bgp_msg_1 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><MONITOR><ADDRESS afi="1">128.223...

our $bgp_msg_2_description = "Invalid XML, no timestamp"; 
our $bgp_msg_2 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">213.248....

our $bgp_msg_3_description = "No peer AS.";
our $bgp_msg_3 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><DEST><ADDRESS afi="1">128.223.51...

our $bgp_msg_4_description = "No peer IP.";
our $bgp_msg_4 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ASN4>666</ASN4></SOURCE>...

our $bgp_msg_5_description = "Valid XML: 1 new prefix";
our @bgp_msg_5_bgpdump = ("BGP4MP|1380326253|A|205.166.205.202|6360|64.187.64.0/23|6360 4323 1239 209 16608");
our $bgp_msg_5 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">205.166....

our $bgp_msg_6_description = "Valid XML: Multiple withdrawn prefixes";
our @bgp_msg_6_bgpdump = ('BGP4MP|1380580207|W|194.71.0.1|48285|185.22.137.0/24',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|69.38.178.0/24',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|108.61.128.0/18',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|109.161.64.0/20',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|143.70.237.0/24',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|186.232.14.0/23',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|192.58.232.0/24',
		          'BGP4MP|1380580207|W|194.71.0.1|48285|205.107.212.0/24');
our $bgp_msg_6 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">194.71.0...

our $bgp_msg_7_description = "AFI of 1 withdrawn prefix set to IPV6";
our @bgp_msg_7_bgpdump = ();
our $bgp_msg_7 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">194.71.0...

our $bgp_msg_9_description = "AFI of 1 announced prefix set to IPV6";#TODO
our @bgp_msg_9_bgpdump = ("BGP4MP|1336075235|A|187.16.217.104|613|84.205.74.0/24|262757 16735 3549 3257 12637 12654");
our $bgp_msg_9 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">164.128....

our $bgp_msg_11_description = "Valid XML: Table dump message";
our @bgp_msg_11_bgpdump = ("TABLE_DUMP2|1380322461|A|213.248.80.244|1299|93.190.10.0/24|1299 3356 20485 9198 43994 47254");
our $bgp_msg_11 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="1">213.248...

our $bgp_msg_12_description = "Valid XML: IPv6 MP_REACH message";
our @bgp_msg_12_bgpdump = ("BGP4MP|1380586060|A|2001:1620:1::203|13030|2a00:7540::/48|13030 6939 31692 31692 41938 8359 8359 41938 31692 57401");
our $bgp_msg_12 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="2">2001:16...

our $bgp_msg_13_description = "Valid XML: IPv6 MP_UNREACH message";
our @bgp_msg_13_bgpdump = ('BGP4MP|1380586081|W|2001:470:0:1a::1|6939|2408:8056:4f00::/40',
                           'BGP4MP|1380586081|W|2001:470:0:1a::1|6939|2408:8ffe::/32',
                           'BGP4MP|1380586081|W|2001:470:0:1a::1|6939|100::/1');
our $bgp_msg_13 = '<BGP_MONITOR_MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns="urn:ietf:params:xml:ns:bgp_monitor" xmlns:bgp="urn:ietf:params:xml:ns:xfb" xmlns:ne="urn:ietf:params:xml:ns:network_elements"><SOURCE><ADDRESS afi="2">2001:47...

# Test for complete xml message.
my $out = translate_message();
ok (!defined($out), "Testing for complete XML correct output return.");
my $error_code = get_error_code('translate_message');
ok ($error_code == 701, "Testing for complete XML error code");


# Test for invalid xml message
$out = translate_message($bgp_msg_0);
ok (!defined($out), "Testing for complete invalid XML output return.");
$error_code = get_error_code('translate_message');
ok ($error_code == 703, "Testing for invalid XML");

# Test for message with type not UPDATE
$out = translate_message($bgp_msg_1);
ok (!defined($out), "Testing for non update message output return.");
$error_code = get_error_code('translate_message');
ok ($error_code == 705, "Testing recognizing non update message");

# Test for message with invalid timestamp.
$out = translate_message($bgp_msg_2);
ok (!defined($out), "Testing for invalid timestamp output return.");
$error_code = get_error_code('translate_message');
ok ($error_code == 706, "Testing invalid timestamp");

# Test for message with no peer AS.
$out = translate_message($bgp_msg_3);
ok (!defined($out), "Testing for invalid AS_PATH output return.");
$error_code = get_error_code('translate_message');
ok ($error_code == 707, "Testing missing peer ASN");

# Test for message with no peer IP.
$out = translate_message($bgp_msg_4);
ok (!defined($out), "Testing for invalid peer information output return.");
$error_code = get_error_code('translate_message');
ok ($error_code == 708, "Testing missing peer IP");

# Test for IPv4 announced.
$out = translate_message($bgp_msg_5);
ok (defined($out), "Testing for IPv4 NLRI Announcement output return.");
ok(scalar(@$out) == scalar(@bgp_msg_5_bgpdump),
	"Testing IPv4 announcements");
ok(@{$out}[0] eq $bgp_msg_5_bgpdump[0], 
	"IPv4 announcement output");

# Test for IPv4 withdrawn
$out = undef;
$out = translate_message($bgp_msg_6);
ok (defined($out), "Testing for IPv4 Withdraw output return.");
$error_code = get_error_code('translate_message');
my $error_msg = get_error_message('translate_message');
my @bgpdump_lines = @{$out};
ok(scalar(@bgpdump_lines) == scalar(@bgp_msg_6_bgpdump),



( run in 1.891 second using v1.01-cache-2.11-cpan-364913b4093 )