Hello everyone,

I am in the following situation. What I want to realize is a small bgp session and update the routing. After that is established, I want to test the routing via a small script.

It would be nice if someone could give me a small hint where I possible have a mistake in my code or where to look next, as I have nomore ideas. Thanks in advance for your help.

Following I put my code:

#!/usr/local/bin/perl # Modules # ======= # Standard use strict; use warnings; # For BGP use Net::ACL; use Net::ACL::Rule qw( :action :rc ); use Net::BGP::NLRI qw( :origin ); use Net::BGP::Peer; use Net::BGP::Policy; use Net::BGP::Process; use Net::BGP::RIB; use Net::BGP::RIBEntry; use Net::BGP::Router; use Net::BGP::Update; # Constructor for BGP-Router-Object my $router = new Net::BGP::Router( Name => 'FirstOwnBGPRouter', Policy => new Net::BGP::Policy(), ); sub open_callback { print "OpenCallback\n"; my $peer = $_[0]; return 0; } sub keepalive_callback { print "KeepaliveCallback\n"; return 0; } sub update_callback { my $peer = $_[0]; my $update = $_[1]; print "Update_Callback_Function\n"; # # # Get Peer-Data # my $version = $peer->version(); # my $this_id = $peer->this_id(); # my $this_as = $peer->this_as(); # my $peer_id = $peer->peer_id(); # my $peer_as = $peer->peer_as(); # # # # Print Peer-Data # print "BGP-Peer-Data\n============\n"; # print "Version: $version\n"; # print "IP: $this_id\n"; # print "AS: $this_as\n"; # print "Remote_IP: $peer_id\n"; # print "Remote_AS: $peer_as\n\n"; return 1; } sub notification_callback { print "NotificationCallback\n"; return 1; } sub error_callback { print "ErrorCallback\n"; return 1; } # Constructor for BGP-Peer-Object my $peer = new Net::BGP::Peer( Start => 1, ThisID => '10.46.16.209', ThisAS => 8560, PeerID => '10.46.16.129', PeerAS => 8560, PeerPort => 179, ConnectRetryTime => 300, HoldTime => 60, KeepAliveTime => 20, Listen => 1, Passive => 0, OpenCallback => \&open_callback, KeepaliveCallback => \&keepalive_callback, UpdateCallback => \&update_callback, NotificationCallback => \&notification_callback, ErrorCallback => \&error_callback ); # Start the peer print "Start BGP-Peer\n\n"; $peer->start(); # Get Peer-Data my $version = $peer->version(); my $this_id = $peer->this_id(); my $this_as = $peer->this_as(); my $peer_id = $peer->peer_id(); my $peer_as = $peer->peer_as(); # Print Peer-Data print "BGP-Peer-Data\n============\n"; print "Version: $version\n"; print "IP: $this_id\n"; print "AS: $this_as\n"; print "Remote_IP: $peer_id\n"; print "Remote_AS: $peer_as\n\n"; # Create new BGP-Process my $process = new Net::BGP::Process( ListenAddr => '10.46.16.209', Port => '179' ); # Constructor for ACL-Rule-Object my $acl_rule = new Net::ACL::Rule( Action => ACL_PERMIT, Seq => 10 ); # Constructor for ACL-Object my $acl = new Net::ACL( Name => 'MyACL', Type => 'prefix-list', Rule => $acl_rule ); # Constructor for BGP-Policy-Object my $policy = new Net::BGP::Policy(); # Accessor Methods (Net::BGP::Policy object) $policy->set($peer, 'in', $acl); $policy->delete($peer,'out'); # Constructor for BGP-RIBEntry-Object my $entry = new Net::BGP::RIBEntry( Prefix => '212.227.114.9/32' ); # Accessor Methods (Net::BGP::RIBEntry object) $entry->add_peer($peer, 'in'); # Constructor for BGP-NLRI-Object print "Create new NLRI-Object\n"; my $nlri = Net::BGP::NLRI->new( Aggregator => [ 8560, '10.46.16.209' ], AsPath => Net::BGP::ASPath->new( "8560" ), AtomicAggregate => 1, LocalPref => 100, MED => 200, NextHop => '10.46.16.209', Origin => INCOMPLETE, ); # my $nlri_ref = [ qw( 10.46.16.128/25 10.46.81.0/24 212.227.114.0/24 ) +]; my $withdrawn_ref = [ qw( ) ]; # Print some information of the nlri-object my $string = $nlri->asstring; print "NLRI-Information: $string\n\n"; # Constructor for BGP-Update-Object my $update = Net::BGP::Update->new($nlri,$nlri_ref,$withdrawn_ref); # Update peer object #TODO: Test of updating peer correctly print "Update peer object\n"; $peer->update($update); my $listen = $peer->is_listener(); my $passive = $peer->is_passive(); my $estab = $peer->is_established(); print "Is_listener: $listen\n Is_passive: $passive\n Is_established: $estab\n"; # Constructor for BGP-RIB-Object my $rib = new Net::BGP::RIB(); # Accessor Methods (Net::BGP::RIB object) $rib->add_peer($peer,'in',$policy); $rib->handle_update($peer,$update,$policy); # Print string describing the RIB #my $string = $entry->asstring(); #print "String describing the RIB: $string\n"; # Accessor Methods (Net::BGP::Router object) $router->add_peer($peer,'in', $acl); # $router->remove_peer($peer,'both'); $router->set_policy($policy); #$router->set_policy($peer,'in',$acl); # Add peer to the process print "Add BGP-Peer to BGP-Process\n"; $process->add_peer($peer); # Take over program control flow print "BGP-Process takes over program control flow\n\n"; $process->event_loop();

In reply to gridlocked situation with net::bgp and update the peer routing information by MelX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.