MelX has asked for the wisdom of the Perl Monks concerning the following question:

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();
  • Comment on gridlocked situation with net::bgp and update the peer routing information
  • Download Code

Replies are listed 'Best First'.
Re: gridlocked situation with net::bgp and update the peer routing information
by jethro (Monsignor) on Feb 08, 2010 at 14:29 UTC
    What is missing from your description is what exactly goes wrong or does not work?
Re: gridlocked situation with net::bgp and update the peer routing information
by MelX (Novice) on Feb 08, 2010 at 14:30 UTC

    Hello,

    I could establish the tcp connection to my remote peer, during this process I want to update the peer with new information, but no call of the UpdateCallback function happened.

    Any advice would be great!

    Best regards

    Marcus

      I think you get a call to the callback when your peer sends an update, not when you send one.

        Hello,

        though for testing purposes I want to
        initiate one update manually.

        So if I understand you right it is not
        possible to do this, so I need a second
        peer to do this right?

        Best regard
        Marcus
        Hello,

        thanks for your help. So my next try would be to set up another peer to update and check the results.

        I keep this posting uptodate.

        Thanks to all who give me some hints and advise!

        Best regards
        Marcus

        Hello,

        what I've done so far, I setup a remote peer and I could establish a connection to this remote peer, what I do not understand is how could I handle the incoming update messages?

        My first suggestion was, that I could handle the incoming message, checked with tcpdump for incoming connections, via the update_callback subroutine, for testing purposes I put there a print line, however no call fo the callback-sub. What am I missing?

        Thanks for your help in advance.

        Best regards
        Marcus
      Hello,
      following the codesnipet where the problem is located:
      # Constructor for BGP-Update-Object my $update = Net::BGP::Update->new($nlri,$nlri_ref,$withdrawn_ref); # Update peer object print "Update peer object\n"; $peer->update($update);

      Update peer object does not work, no call
      of theUpdateCallback-function

      Best regard
      Marcus