| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Net::BGP::Peer; | 
| 4 | 4 |  |  | 4 |  | 72387 | use bytes; | 
|  | 4 |  |  |  |  | 48 |  | 
|  | 4 |  |  |  |  | 25 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 125 | use strict; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 140 |  | 
| 7 | 4 |  |  |  |  | 958 | use vars qw( | 
| 8 |  |  |  |  |  |  | $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @BGP @GENERIC | 
| 9 |  |  |  |  |  |  | @BGP_EVENT_MESSAGE_MAP @BGP_EVENTS @BGP_FSM @BGP_STATES | 
| 10 | 4 |  |  | 4 |  | 21 | ); | 
|  | 4 |  |  |  |  | 8 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | ## Inheritance and Versioning ## | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | @ISA     = qw( Exporter ); | 
| 15 |  |  |  |  |  |  | $VERSION = '0.18'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | ## General Definitions ## | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 17 |  |  | 17 | 0 | 46 | sub TRUE  { 1 } | 
| 20 | 17 |  |  | 17 | 0 | 102 | sub FALSE { 0 } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | ## BGP Network Constants ## | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 8 |  |  | 8 | 0 | 102 | sub BGP_PORT      { 179 } | 
| 25 | 5 |  |  | 5 | 0 | 13 | sub BGP_VERSION_4 {   4 } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ## Export Tag Definitions ## | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | @BGP         = qw( BGP_PORT BGP_VERSION_4 ); | 
| 30 |  |  |  |  |  |  | @GENERIC     = qw( TRUE FALSE dump_hex ); | 
| 31 |  |  |  |  |  |  | @EXPORT      = (); | 
| 32 |  |  |  |  |  |  | @EXPORT_OK   = ( @BGP, @GENERIC ); | 
| 33 |  |  |  |  |  |  | %EXPORT_TAGS = ( | 
| 34 |  |  |  |  |  |  | bgp      => [ @BGP ], | 
| 35 |  |  |  |  |  |  | generic  => [ @GENERIC ], | 
| 36 |  |  |  |  |  |  | ALL      => [ @EXPORT, @EXPORT_OK ] | 
| 37 |  |  |  |  |  |  | ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | ## Module Imports ## | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 4 |  |  | 4 |  | 32 | use Scalar::Util qw( weaken ); | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 239 |  | 
| 42 | 4 |  |  | 4 |  | 24 | use Exporter; | 
|  | 4 |  |  |  |  | 31 |  | 
|  | 4 |  |  |  |  | 166 |  | 
| 43 | 4 |  |  | 4 |  | 527 | use IO::Socket; | 
|  | 4 |  |  |  |  | 21916 |  | 
|  | 4 |  |  |  |  | 23 |  | 
| 44 | 4 |  |  | 4 |  | 2042 | use Carp; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 236 |  | 
| 45 | 4 |  |  | 4 |  | 22 | use Carp qw(cluck); | 
|  | 4 |  |  |  |  | 15 |  | 
|  | 4 |  |  |  |  | 194 |  | 
| 46 | 4 |  |  | 4 |  | 974 | use Net::BGP::Notification qw( :errors ); | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 849 |  | 
| 47 | 4 |  |  | 4 |  | 1033 | use Net::BGP::Refresh; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 178 |  | 
| 48 | 4 |  |  | 4 |  | 1082 | use Net::BGP::Update; | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 212 |  | 
| 49 | 4 |  |  | 4 |  | 2573 | use Net::BGP::Transport; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 11067 |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | ## Global private variables ## | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | my %knownpeers; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | ## Generic Subroutines ## | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | # This subroutine was snicked from David Town's excellent Net::SNMP | 
| 58 |  |  |  |  |  |  | # module and renamed as dump_hex(). Removed class dependence and made | 
| 59 |  |  |  |  |  |  | # into standalone subroutine. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub dump_hex | 
| 62 |  |  |  |  |  |  | { | 
| 63 | 0 |  |  | 0 | 0 | 0 | my $data = shift(); | 
| 64 | 0 |  |  |  |  | 0 | my ($length, $offset, $line, $hex) = (0, 0, '', ''); | 
| 65 | 0 |  |  |  |  | 0 | my $string; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  |  |  | 0 | $string = ''; | 
| 68 | 0 |  |  |  |  | 0 | $length = length($data); | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 |  |  |  |  | 0 | while ($length > 0) { | 
| 71 | 0 | 0 |  |  |  | 0 | if ($length >= 16) { | 
| 72 | 0 |  |  |  |  | 0 | $line = substr($data, $offset, 16); | 
| 73 |  |  |  |  |  |  | } else { | 
| 74 | 0 |  |  |  |  | 0 | $line = substr($data, $offset, $length); | 
| 75 |  |  |  |  |  |  | } | 
| 76 | 0 |  |  |  |  | 0 | $hex  = unpack('H*', $line); | 
| 77 | 0 |  |  |  |  | 0 | $hex .= ' ' x (32 - length($hex)); | 
| 78 | 0 |  |  |  |  | 0 | $hex  = sprintf("%s %s %s %s  " x 4, unpack('a2' x 16, $hex)); | 
| 79 | 0 |  |  |  |  | 0 | $line =~ s/[\x00-\x1f\x7f-\xff]/./g; | 
| 80 | 0 |  |  |  |  | 0 | $string .= sprintf("[%03d]  %s %s\n", $offset, uc($hex), $line); | 
| 81 | 0 |  |  |  |  | 0 | $offset += 16; | 
| 82 | 0 |  |  |  |  | 0 | $length -= 16; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 0 |  |  |  |  | 0 | return ( $string ); | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | ## Public Class Methods ## | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub new | 
| 91 |  |  |  |  |  |  | { | 
| 92 | 5 |  |  | 5 | 0 | 2050 | my $class = shift(); | 
| 93 | 5 |  |  |  |  | 9 | my ($arg, $value); | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 5 |  |  |  |  | 19 | my $this = { | 
| 96 |  |  |  |  |  |  | _bgp_version           => BGP_VERSION_4, | 
| 97 |  |  |  |  |  |  | _local_id              => undef, | 
| 98 |  |  |  |  |  |  | _peer_id               => undef, | 
| 99 |  |  |  |  |  |  | _peer_port             => BGP_PORT, | 
| 100 |  |  |  |  |  |  | _local_as              => 0, | 
| 101 |  |  |  |  |  |  | _peer_as               => 0, | 
| 102 |  |  |  |  |  |  | _user_timers           => {}, | 
| 103 |  |  |  |  |  |  | _transport             => undef, | 
| 104 |  |  |  |  |  |  | _listen                => TRUE, | 
| 105 |  |  |  |  |  |  | _passive               => FALSE, | 
| 106 |  |  |  |  |  |  | _announce_refresh      => FALSE, | 
| 107 |  |  |  |  |  |  | _support_capabilities  => TRUE, | 
| 108 |  |  |  |  |  |  | _support_mbgp          => TRUE, | 
| 109 |  |  |  |  |  |  | _support_as4           => FALSE, | 
| 110 |  |  |  |  |  |  | _opaque_data           => undef, | 
| 111 |  |  |  |  |  |  | _open_callback         => undef, | 
| 112 |  |  |  |  |  |  | _established_callback  => undef, | 
| 113 |  |  |  |  |  |  | _keepalive_callback    => undef, | 
| 114 |  |  |  |  |  |  | _update_callback       => undef, | 
| 115 |  |  |  |  |  |  | _refresh_callback      => undef, | 
| 116 |  |  |  |  |  |  | _reset_callback        => undef, | 
| 117 |  |  |  |  |  |  | _notification_callback => undef, | 
| 118 |  |  |  |  |  |  | _error_callback        => undef | 
| 119 |  |  |  |  |  |  | }; | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 5 |  |  |  |  | 14 | bless($this, $class); | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 5 |  |  |  |  | 11 | my %transarg = (); | 
| 124 | 5 |  |  |  |  | 33 | while ( defined($arg = shift()) ) { | 
| 125 | 54 |  |  |  |  | 67 | $value = shift(); | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 54 | 100 | 66 |  |  | 449 | if (( $arg =~ /^start$/i ) | 
|  |  | 100 | 100 |  |  |  |  | 
|  |  | 100 | 66 |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | || ( $arg =~ /^connectretrytime$/i ) | 
| 129 |  |  |  |  |  |  | || ( $arg =~ /^keepalivetime$/i ) | 
| 130 |  |  |  |  |  |  | || ( $arg =~ /^holdtime$/i )) { | 
| 131 | 9 |  |  |  |  | 33 | $transarg{$arg} = $value; | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  | elsif ( $arg =~ /^thisid$/i ) { | 
| 134 | 5 |  |  |  |  | 22 | $this->{_local_id} = $value; | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  | elsif ( $arg =~ /^thisas$/i ) { | 
| 137 | 5 |  |  |  |  | 15 | $this->{_local_as} = $value; | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  | elsif ( $arg =~ /^peerid$/i ) { | 
| 140 | 5 |  |  |  |  | 16 | $this->{_peer_id} = $value; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  | elsif ( $arg =~ /^peeras$/i ) { | 
| 143 | 5 |  |  |  |  | 15 | $this->{_peer_as} = $value; | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  | elsif ( $arg =~ /^peerport$/i ) { | 
| 146 | 4 |  |  |  |  | 10 | $this->{_peer_port} = $value; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  | elsif ( $arg =~ /^listen$/i ) { | 
| 149 | 5 |  |  |  |  | 24 | $this->{_listen} = $value; | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  | elsif ( $arg =~ /^passive$/i ) { | 
| 152 | 5 |  |  |  |  | 15 | $this->{_passive} = $value; | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  | elsif ( $arg =~ /^refreshcallback$/i ) { | 
| 155 | 0 |  |  |  |  | 0 | $this->{_refresh_callback} = $value; | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  | elsif ( $arg =~ /^opaquedata$/i ) { | 
| 158 | 0 |  |  |  |  | 0 | $this->{_opaque_data} = $value; | 
| 159 |  |  |  |  |  |  | } | 
| 160 |  |  |  |  |  |  | elsif ( $arg =~ /^refresh$/i ) { | 
| 161 | 0 |  |  |  |  | 0 | warnings::warnif( | 
| 162 |  |  |  |  |  |  | 'deprecated', | 
| 163 |  |  |  |  |  |  | 'Refresh in is deprecated, use AnnounceRefresh instead' | 
| 164 |  |  |  |  |  |  | ); | 
| 165 | 0 |  |  |  |  | 0 | $this->{_announce_refresh} = $value; | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  | elsif ( $arg =~ /^announcerefresh$/i ) { | 
| 168 | 4 |  |  |  |  | 11 | $this->{_announce_refresh} = $value; | 
| 169 |  |  |  |  |  |  | } | 
| 170 |  |  |  |  |  |  | elsif ( $arg =~ /^supportcapabilities$/i ) { | 
| 171 | 0 |  |  |  |  | 0 | $this->{_support_capabilities} = $value; | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | elsif ( $arg =~ /^supportmbgp$/i ) { | 
| 174 | 4 |  |  |  |  | 12 | $this->{_support_mbgp} = $value; | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  | elsif ( $arg =~ /^supportas4$/i ) { | 
| 177 | 3 |  |  |  |  | 10 | $this->{_support_as4} = $value; | 
| 178 |  |  |  |  |  |  | } | 
| 179 |  |  |  |  |  |  | elsif ( $arg =~ /^opencallback$/i ) { | 
| 180 | 0 |  |  |  |  | 0 | $this->{_open_callback} = $value; | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  | elsif ( $arg =~ /^establishedcallback$/i ) { | 
| 183 | 0 |  |  |  |  | 0 | $this->{_established_callback} = $value; | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  | elsif ( $arg =~ /^keepalivecallback$/i ) { | 
| 186 | 0 |  |  |  |  | 0 | $this->{_keepalive_callback} = $value; | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  | elsif ( $arg =~ /^updatecallback$/i ) { | 
| 189 | 0 |  |  |  |  | 0 | $this->{_update_callback} = $value; | 
| 190 |  |  |  |  |  |  | } | 
| 191 |  |  |  |  |  |  | elsif ( $arg =~ /^resetcallback$/i ) { | 
| 192 | 0 |  |  |  |  | 0 | $this->{_reset_callback} = $value; | 
| 193 |  |  |  |  |  |  | } | 
| 194 |  |  |  |  |  |  | elsif ( $arg =~ /^notificationcallback$/i ) { | 
| 195 | 0 |  |  |  |  | 0 | $this->{_notification_callback} = $value; | 
| 196 |  |  |  |  |  |  | } | 
| 197 |  |  |  |  |  |  | elsif ( $arg =~ /^errorcallback$/i ) { | 
| 198 | 0 |  |  |  |  | 0 | $this->{_error_callback} = $value; | 
| 199 |  |  |  |  |  |  | } | 
| 200 |  |  |  |  |  |  | else { | 
| 201 | 0 |  |  |  |  | 0 | croak "unrecognized argument $arg\n"; | 
| 202 |  |  |  |  |  |  | } | 
| 203 |  |  |  |  |  |  | } | 
| 204 |  |  |  |  |  |  |  | 
| 205 | 5 |  |  |  |  | 10 | $transarg{parent} = $this; | 
| 206 | 5 |  |  |  |  | 36 | $this->{_transport} = Net::BGP::Transport->new(%transarg); | 
| 207 |  |  |  |  |  |  |  | 
| 208 | 5 |  |  |  |  | 29 | weaken($knownpeers{$this} = $this); | 
| 209 | 5 |  |  |  |  | 17 | return ( $this ); | 
| 210 |  |  |  |  |  |  | } | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | sub renew | 
| 213 |  |  |  |  |  |  | { | 
| 214 | 0 |  |  | 0 | 0 | 0 | my $proto = shift; | 
| 215 | 0 |  | 0 |  |  | 0 | my $class = ref $proto || $proto; | 
| 216 | 0 |  |  |  |  | 0 | my $name = shift; | 
| 217 | 0 |  |  |  |  | 0 | return $knownpeers{$name}; | 
| 218 |  |  |  |  |  |  | } | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | ## Public Object Methods - Proxies for backward compatibility ## | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | sub start | 
| 223 |  |  |  |  |  |  | { | 
| 224 | 0 |  |  | 0 | 0 | 0 | foreach my $trans (shift->transports) | 
| 225 |  |  |  |  |  |  | { | 
| 226 | 0 |  |  |  |  | 0 | $trans->start(); | 
| 227 |  |  |  |  |  |  | }; | 
| 228 |  |  |  |  |  |  | } | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | sub stop | 
| 231 |  |  |  |  |  |  | { | 
| 232 | 6 |  |  | 6 | 0 | 71 | foreach my $trans (shift->transports) | 
| 233 |  |  |  |  |  |  | { | 
| 234 | 6 |  |  |  |  | 21 | $trans->stop(); | 
| 235 |  |  |  |  |  |  | }; | 
| 236 |  |  |  |  |  |  | } | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | sub version | 
| 239 |  |  |  |  |  |  | { | 
| 240 | 0 |  |  | 0 | 0 | 0 | return shift->transport->version; | 
| 241 |  |  |  |  |  |  | } | 
| 242 |  |  |  |  |  |  |  | 
| 243 |  |  |  |  |  |  | sub update | 
| 244 |  |  |  |  |  |  | { | 
| 245 | 4 |  |  | 4 | 0 | 50 | return shift->transport->update(@_); | 
| 246 |  |  |  |  |  |  | } | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | sub refresh | 
| 249 |  |  |  |  |  |  | { | 
| 250 | 2 |  |  | 2 | 0 | 18 | return shift->transport->refresh(@_); | 
| 251 |  |  |  |  |  |  | } | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | ## Public Object Methods ## | 
| 254 |  |  |  |  |  |  |  | 
| 255 |  |  |  |  |  |  | sub transport | 
| 256 |  |  |  |  |  |  | { | 
| 257 | 413 |  |  | 413 | 0 | 727 | my $this = shift(); | 
| 258 | 413 | 50 |  |  |  | 739 | $this->{_transport} = shift if @_; | 
| 259 | 413 |  |  |  |  | 1001 | return $this->{_transport}; | 
| 260 |  |  |  |  |  |  | } | 
| 261 |  |  |  |  |  |  |  | 
| 262 |  |  |  |  |  |  | sub transports | 
| 263 |  |  |  |  |  |  | { | 
| 264 | 162 |  |  | 162 | 0 | 258 | my $this = shift(); | 
| 265 | 162 | 50 |  |  |  | 275 | return ($this->transport) unless defined $this->transport->sibling; | 
| 266 | 0 |  |  |  |  | 0 | return ($this->transport,$this->transport->sibling); | 
| 267 |  |  |  |  |  |  | } | 
| 268 |  |  |  |  |  |  |  | 
| 269 |  |  |  |  |  |  | sub this_id | 
| 270 |  |  |  |  |  |  | { | 
| 271 | 14 |  |  | 14 | 0 | 22 | my $this = shift(); | 
| 272 | 14 |  |  |  |  | 81 | return ( $this->{_local_id} ); | 
| 273 |  |  |  |  |  |  | } | 
| 274 |  |  |  |  |  |  |  | 
| 275 |  |  |  |  |  |  | sub this_as | 
| 276 |  |  |  |  |  |  | { | 
| 277 | 12 |  |  | 12 | 0 | 18 | my $this = shift(); | 
| 278 | 12 |  |  |  |  | 35 | return ( $this->{_local_as} ); | 
| 279 |  |  |  |  |  |  | } | 
| 280 |  |  |  |  |  |  |  | 
| 281 |  |  |  |  |  |  | sub this_can_refresh | 
| 282 |  |  |  |  |  |  | { | 
| 283 | 8 |  |  | 8 | 0 | 13 | my $this = shift(); | 
| 284 | 8 |  |  |  |  | 35 | return ( $this->{_announce_refresh} ); | 
| 285 |  |  |  |  |  |  | } | 
| 286 |  |  |  |  |  |  |  | 
| 287 |  |  |  |  |  |  | sub this_can_as4 | 
| 288 |  |  |  |  |  |  | { | 
| 289 | 8 |  |  | 8 | 0 | 13 | my $this = shift(); | 
| 290 | 8 |  |  |  |  | 22 | return ( $this->{_support_as4} ); | 
| 291 |  |  |  |  |  |  | } | 
| 292 |  |  |  |  |  |  |  | 
| 293 |  |  |  |  |  |  | sub support_capabilities | 
| 294 |  |  |  |  |  |  | { | 
| 295 | 6 |  |  | 6 | 0 | 8 | my $this = shift(); | 
| 296 | 6 |  |  |  |  | 15 | return ( $this->{_support_capabilities} ); | 
| 297 |  |  |  |  |  |  | } | 
| 298 |  |  |  |  |  |  |  | 
| 299 |  |  |  |  |  |  | sub support_mbgp | 
| 300 |  |  |  |  |  |  | { | 
| 301 | 6 |  |  | 6 | 0 | 15 | my $this = shift(); | 
| 302 | 6 |  |  |  |  | 15 | return ( $this->{_support_mbgp} ); | 
| 303 |  |  |  |  |  |  | } | 
| 304 |  |  |  |  |  |  |  | 
| 305 |  |  |  |  |  |  | sub peer_id | 
| 306 |  |  |  |  |  |  | { | 
| 307 | 8 |  |  | 8 | 0 | 15 | my $this = shift(); | 
| 308 | 8 |  |  |  |  | 26 | return ( $this->{_peer_id} ); | 
| 309 |  |  |  |  |  |  | } | 
| 310 |  |  |  |  |  |  |  | 
| 311 |  |  |  |  |  |  | sub peer_as | 
| 312 |  |  |  |  |  |  | { | 
| 313 | 11 |  |  | 11 | 0 | 16 | my $this = shift(); | 
| 314 | 11 |  |  |  |  | 55 | return ( $this->{_peer_as} ); | 
| 315 |  |  |  |  |  |  | } | 
| 316 |  |  |  |  |  |  |  | 
| 317 |  |  |  |  |  |  | sub peer_port | 
| 318 |  |  |  |  |  |  | { | 
| 319 | 2 |  |  | 2 | 0 | 5 | my $this = shift(); | 
| 320 | 2 |  |  |  |  | 5 | return ( $this->{_peer_port} ); | 
| 321 |  |  |  |  |  |  | } | 
| 322 |  |  |  |  |  |  |  | 
| 323 |  |  |  |  |  |  | sub peer_can_as4 | 
| 324 |  |  |  |  |  |  | { | 
| 325 | 1 |  |  | 1 | 0 | 5 | my $this = shift(); | 
| 326 | 1 |  |  |  |  | 2 | return $this->transport->can_as4; | 
| 327 |  |  |  |  |  |  | } | 
| 328 |  |  |  |  |  |  |  | 
| 329 |  |  |  |  |  |  | sub peer_can_mbgp | 
| 330 |  |  |  |  |  |  | { | 
| 331 | 2 |  |  | 2 | 0 | 23 | my $this = shift(); | 
| 332 | 2 |  |  |  |  | 7 | return $this->transport->can_mbgp; | 
| 333 |  |  |  |  |  |  | } | 
| 334 |  |  |  |  |  |  |  | 
| 335 |  |  |  |  |  |  | sub peer_can_refresh | 
| 336 |  |  |  |  |  |  | { | 
| 337 | 0 |  |  | 0 | 0 | 0 | my $this = shift(); | 
| 338 | 0 |  |  |  |  | 0 | return $this->transport->can_refresh; | 
| 339 |  |  |  |  |  |  | } | 
| 340 |  |  |  |  |  |  |  | 
| 341 |  |  |  |  |  |  | sub is_listener | 
| 342 |  |  |  |  |  |  | { | 
| 343 | 9 |  |  | 9 | 0 | 14 | my $this = shift(); | 
| 344 | 9 |  |  |  |  | 60 | return ( $this->{_listen} ); | 
| 345 |  |  |  |  |  |  | } | 
| 346 |  |  |  |  |  |  |  | 
| 347 |  |  |  |  |  |  | sub is_passive | 
| 348 |  |  |  |  |  |  | { | 
| 349 | 10 |  |  | 10 | 0 | 25 | my $this = shift(); | 
| 350 | 10 |  |  |  |  | 30 | return ( $this->{_passive} ); | 
| 351 |  |  |  |  |  |  | } | 
| 352 |  |  |  |  |  |  |  | 
| 353 |  |  |  |  |  |  | sub is_established | 
| 354 |  |  |  |  |  |  | { | 
| 355 | 0 |  |  | 0 | 0 | 0 | my $this = shift(); | 
| 356 | 0 |  |  |  |  | 0 | return ( $this->transport->is_established ); | 
| 357 |  |  |  |  |  |  | } | 
| 358 |  |  |  |  |  |  |  | 
| 359 |  |  |  |  |  |  | sub opaque_data | 
| 360 |  |  |  |  |  |  | { | 
| 361 | 0 |  |  | 0 | 0 | 0 | my ($this, $opaque_data) = @_; | 
| 362 | 0 |  |  |  |  | 0 | my $old_value = $this->{_opaque_data}; | 
| 363 | 0 | 0 |  |  |  | 0 | $this->{_opaque_data} = $opaque_data if defined($opaque_data); | 
| 364 | 0 |  |  |  |  | 0 | return ( $old_value ); | 
| 365 |  |  |  |  |  |  | } | 
| 366 |  |  |  |  |  |  |  | 
| 367 |  |  |  |  |  |  | sub set_open_callback | 
| 368 |  |  |  |  |  |  | { | 
| 369 | 2 |  |  | 2 | 0 | 10 | my ($this, $callback) = @_; | 
| 370 | 2 |  |  |  |  | 4 | $this->{_open_callback} = $callback; | 
| 371 |  |  |  |  |  |  | } | 
| 372 |  |  |  |  |  |  |  | 
| 373 |  |  |  |  |  |  | sub set_established_callback | 
| 374 |  |  |  |  |  |  | { | 
| 375 | 2 |  |  | 2 | 0 | 9 | my ($this, $callback) = @_; | 
| 376 | 2 |  |  |  |  | 5 | $this->{_established_callback} = $callback; | 
| 377 |  |  |  |  |  |  | } | 
| 378 |  |  |  |  |  |  |  | 
| 379 |  |  |  |  |  |  | sub set_keepalive_callback | 
| 380 |  |  |  |  |  |  | { | 
| 381 | 4 |  |  | 4 | 0 | 26 | my ($this, $callback) = @_; | 
| 382 | 4 |  |  |  |  | 11 | $this->{_keepalive_callback} = $callback; | 
| 383 |  |  |  |  |  |  | } | 
| 384 |  |  |  |  |  |  |  | 
| 385 |  |  |  |  |  |  | sub set_update_callback | 
| 386 |  |  |  |  |  |  | { | 
| 387 | 2 |  |  | 2 | 0 | 10 | my ($this, $callback) = @_; | 
| 388 | 2 |  |  |  |  | 4 | $this->{_update_callback} = $callback; | 
| 389 |  |  |  |  |  |  | } | 
| 390 |  |  |  |  |  |  |  | 
| 391 |  |  |  |  |  |  | sub set_refresh_callback | 
| 392 |  |  |  |  |  |  | { | 
| 393 | 2 |  |  | 2 | 0 | 8 | my ($this, $callback) = @_; | 
| 394 | 2 |  |  |  |  | 16 | $this->{_refresh_callback} = $callback; | 
| 395 |  |  |  |  |  |  | } | 
| 396 |  |  |  |  |  |  |  | 
| 397 |  |  |  |  |  |  | sub set_reset_callback | 
| 398 |  |  |  |  |  |  | { | 
| 399 | 4 |  |  | 4 | 0 | 18 | my ($this, $callback) = @_; | 
| 400 | 4 |  |  |  |  | 8 | $this->{_reset_callback} = $callback; | 
| 401 |  |  |  |  |  |  | } | 
| 402 |  |  |  |  |  |  |  | 
| 403 |  |  |  |  |  |  | sub set_notification_callback | 
| 404 |  |  |  |  |  |  | { | 
| 405 | 4 |  |  | 4 | 0 | 16 | my ($this, $callback) = @_; | 
| 406 | 4 |  |  |  |  | 8 | $this->{_notification_callback} = $callback; | 
| 407 |  |  |  |  |  |  | } | 
| 408 |  |  |  |  |  |  |  | 
| 409 |  |  |  |  |  |  | sub set_error_callback | 
| 410 |  |  |  |  |  |  | { | 
| 411 | 6 |  |  | 6 | 0 | 31 | my ($this, $callback) = @_; | 
| 412 | 6 |  |  |  |  | 14 | $this->{_error_callback} = $callback; | 
| 413 |  |  |  |  |  |  | } | 
| 414 |  |  |  |  |  |  |  | 
| 415 |  |  |  |  |  |  | sub add_timer | 
| 416 |  |  |  |  |  |  | { | 
| 417 | 2 |  |  | 2 | 0 | 14 | my ($this, $callback, $timeout) = @_; | 
| 418 | 2 |  |  |  |  | 3 | my $timer; | 
| 419 |  |  |  |  |  |  |  | 
| 420 | 2 |  |  |  |  | 7 | $timer = { | 
| 421 |  |  |  |  |  |  | _timer    => $timeout, | 
| 422 |  |  |  |  |  |  | _timeout  => $timeout, | 
| 423 |  |  |  |  |  |  | _callback => $callback, | 
| 424 |  |  |  |  |  |  | }; | 
| 425 |  |  |  |  |  |  |  | 
| 426 | 2 |  |  |  |  | 7 | $this->{_user_timers}->{$timer} = $timer; | 
| 427 |  |  |  |  |  |  | } | 
| 428 |  |  |  |  |  |  |  | 
| 429 |  |  |  |  |  |  | sub remove_timer | 
| 430 |  |  |  |  |  |  | { | 
| 431 | 2 |  |  | 2 | 0 | 46 | my ($this, $callback) = @_; | 
| 432 | 2 |  |  |  |  | 8 | my ($key, $timer); | 
| 433 |  |  |  |  |  |  |  | 
| 434 | 2 |  |  |  |  | 6 | foreach $key ( keys(%{$this->{_user_timers}}) ) { | 
|  | 2 |  |  |  |  | 7 |  | 
| 435 | 2 |  |  |  |  | 7 | $timer = $this->{_user_timers}->{$key}; | 
| 436 | 2 | 50 |  |  |  | 13 | if ( $timer->{_callback} == $callback ) { | 
| 437 | 2 |  |  |  |  | 11 | delete $this->{_user_timers}->{$key}; | 
| 438 |  |  |  |  |  |  | } | 
| 439 |  |  |  |  |  |  | } | 
| 440 |  |  |  |  |  |  | } | 
| 441 |  |  |  |  |  |  |  | 
| 442 |  |  |  |  |  |  | sub asstring | 
| 443 |  |  |  |  |  |  | { | 
| 444 | 0 |  |  | 0 | 0 | 0 | my $this = shift; | 
| 445 |  |  |  |  |  |  |  | 
| 446 | 0 | 0 |  |  |  | 0 | my @l = map { defined $_ ? $_ : 'n/a'; } ( | 
|  | 0 |  |  |  |  | 0 |  | 
| 447 |  |  |  |  |  |  | $this->this_id, $this->this_as, | 
| 448 |  |  |  |  |  |  | $this->peer_id, $this->peer_as); | 
| 449 |  |  |  |  |  |  |  | 
| 450 | 0 |  |  |  |  | 0 | return $l[0] . ':' . $l[1] . '<=>' . $l[2] . ':' . $l[3]; | 
| 451 |  |  |  |  |  |  | } | 
| 452 |  |  |  |  |  |  |  | 
| 453 |  |  |  |  |  |  | ## Overridable Methods ## | 
| 454 |  |  |  |  |  |  |  | 
| 455 |  |  |  |  |  |  | sub open_callback | 
| 456 |  |  |  |  |  |  | { | 
| 457 | 4 |  |  | 4 | 0 | 9 | my $this = shift(); | 
| 458 |  |  |  |  |  |  |  | 
| 459 | 4 | 100 |  |  |  | 11 | if ( defined($this->{_open_callback}) ) { | 
| 460 | 2 |  |  |  |  | 5 | &{ $this->{_open_callback} }($this); | 
|  | 2 |  |  |  |  | 20 |  | 
| 461 |  |  |  |  |  |  | } | 
| 462 |  |  |  |  |  |  | } | 
| 463 |  |  |  |  |  |  |  | 
| 464 |  |  |  |  |  |  | sub established_callback | 
| 465 |  |  |  |  |  |  | { | 
| 466 | 4 |  |  | 4 | 0 | 7 | my $this = shift(); | 
| 467 |  |  |  |  |  |  |  | 
| 468 | 4 | 100 |  |  |  | 14 | if ( defined($this->{_established_callback}) ) { | 
| 469 | 2 |  |  |  |  | 4 | &{ $this->{_established_callback} }($this); | 
|  | 2 |  |  |  |  | 8 |  | 
| 470 |  |  |  |  |  |  | } | 
| 471 |  |  |  |  |  |  | } | 
| 472 |  |  |  |  |  |  |  | 
| 473 |  |  |  |  |  |  | sub keepalive_callback | 
| 474 |  |  |  |  |  |  | { | 
| 475 | 8 |  |  | 8 | 0 | 15 | my $this = shift(); | 
| 476 |  |  |  |  |  |  |  | 
| 477 | 8 | 100 |  |  |  | 34 | if ( defined($this->{_keepalive_callback}) ) { | 
| 478 | 4 |  |  |  |  | 9 | &{ $this->{_keepalive_callback} }($this); | 
|  | 4 |  |  |  |  | 32 |  | 
| 479 |  |  |  |  |  |  | } | 
| 480 |  |  |  |  |  |  | } | 
| 481 |  |  |  |  |  |  |  | 
| 482 |  |  |  |  |  |  | sub update_callback | 
| 483 |  |  |  |  |  |  | { | 
| 484 | 4 |  |  | 4 | 0 | 192 | my ($this, $update) = @_; | 
| 485 |  |  |  |  |  |  |  | 
| 486 | 4 | 50 |  |  |  | 19 | if ( defined($this->{_update_callback}) ) { | 
| 487 | 4 |  |  |  |  | 8 | &{ $this->{_update_callback} }($this, $update); | 
|  | 4 |  |  |  |  | 21 |  | 
| 488 |  |  |  |  |  |  | } | 
| 489 |  |  |  |  |  |  | } | 
| 490 |  |  |  |  |  |  |  | 
| 491 |  |  |  |  |  |  | sub refresh_callback | 
| 492 |  |  |  |  |  |  | { | 
| 493 | 6 |  |  | 6 | 0 | 15 | my ($this,$refresh) = @_; | 
| 494 |  |  |  |  |  |  |  | 
| 495 | 6 | 100 |  |  |  | 19 | if ( defined($this->{_refresh_callback}) ) { | 
| 496 | 4 |  |  |  |  | 9 | &{ $this->{_refresh_callback} }($this,$refresh); | 
|  | 4 |  |  |  |  | 17 |  | 
| 497 |  |  |  |  |  |  | } | 
| 498 |  |  |  |  |  |  | } | 
| 499 |  |  |  |  |  |  |  | 
| 500 |  |  |  |  |  |  | sub reset_callback | 
| 501 |  |  |  |  |  |  | { | 
| 502 | 8 |  |  | 8 | 0 | 16 | my ($this,$refresh) = @_; | 
| 503 |  |  |  |  |  |  |  | 
| 504 | 8 | 50 |  |  |  | 150 | if ( defined($this->{_reset_callback}) ) { | 
| 505 | 8 |  |  |  |  | 34 | &{ $this->{_reset_callback} }($this); | 
|  | 8 |  |  |  |  | 28 |  | 
| 506 |  |  |  |  |  |  | } | 
| 507 |  |  |  |  |  |  | } | 
| 508 |  |  |  |  |  |  |  | 
| 509 |  |  |  |  |  |  | sub notification_callback | 
| 510 |  |  |  |  |  |  | { | 
| 511 | 2 |  |  | 2 | 0 | 7 | my ($this, $error) = @_; | 
| 512 |  |  |  |  |  |  |  | 
| 513 | 2 | 50 |  |  |  | 10 | if ( defined($this->{_notification_callback}) ) { | 
| 514 | 2 |  |  |  |  | 15 | &{ $this->{_notification_callback} }($this, $error); | 
|  | 2 |  |  |  |  | 12 |  | 
| 515 |  |  |  |  |  |  | } | 
| 516 |  |  |  |  |  |  | } | 
| 517 |  |  |  |  |  |  |  | 
| 518 |  |  |  |  |  |  | sub error_callback | 
| 519 |  |  |  |  |  |  | { | 
| 520 | 6 |  |  | 6 | 0 | 15 | my ($this, $error) = @_; | 
| 521 |  |  |  |  |  |  |  | 
| 522 | 6 | 100 |  |  |  | 27 | if ( defined($this->{_error_callback}) ) { | 
| 523 | 4 |  |  |  |  | 18 | &{ $this->{_error_callback} }($this, $error); | 
|  | 4 |  |  |  |  | 16 |  | 
| 524 |  |  |  |  |  |  | } | 
| 525 |  |  |  |  |  |  | } | 
| 526 |  |  |  |  |  |  |  | 
| 527 |  |  |  |  |  |  | ## Private Object Methods ## | 
| 528 |  |  |  |  |  |  |  | 
| 529 |  |  |  |  |  |  | sub _update_timers | 
| 530 |  |  |  |  |  |  | { | 
| 531 | 76 |  |  | 76 |  | 138 | my ($this, $delta) = @_; | 
| 532 |  |  |  |  |  |  |  | 
| 533 |  |  |  |  |  |  | # Proxy for transport timers | 
| 534 | 76 |  |  |  |  | 140 | my $min_time = $this->transport->_update_timers($delta); | 
| 535 |  |  |  |  |  |  |  | 
| 536 |  |  |  |  |  |  | # Update user defined timers | 
| 537 | 76 |  |  |  |  | 118 | foreach my $key ( keys(%{$this->{_user_timers}}) ) { | 
|  | 76 |  |  |  |  | 575 |  | 
| 538 | 20 |  |  |  |  | 34 | my $timer = $this->{_user_timers}->{$key}; | 
| 539 | 20 | 50 |  |  |  | 50 | if ( defined($timer->{_timer}) ) { | 
| 540 | 20 |  |  |  |  | 41 | $timer->{_timer} -= $delta; | 
| 541 |  |  |  |  |  |  |  | 
| 542 | 20 | 100 |  |  |  | 42 | if ( $timer->{_timer} <= 0 ) { | 
| 543 | 4 |  |  |  |  | 12 | $timer->{_timer} = $timer->{_timeout}; | 
| 544 | 4 |  |  |  |  | 8 | &{ $timer->{_callback} }($this); | 
|  | 4 |  |  |  |  | 42 |  | 
| 545 |  |  |  |  |  |  | } | 
| 546 |  |  |  |  |  |  |  | 
| 547 | 20 | 50 |  |  |  | 74 | my $min = ($timer->{_timer} < 0) ? 0 : $timer->{_timer}; | 
| 548 | 20 | 50 |  |  |  | 44 | if ( $min < $min_time ) { | 
| 549 | 20 |  |  |  |  | 40 | $min_time = $min; | 
| 550 |  |  |  |  |  |  | } | 
| 551 |  |  |  |  |  |  | } | 
| 552 |  |  |  |  |  |  | } | 
| 553 |  |  |  |  |  |  |  | 
| 554 | 76 |  |  |  |  | 179 | return ( $min_time ); | 
| 555 |  |  |  |  |  |  | } | 
| 556 |  |  |  |  |  |  |  | 
| 557 |  |  |  |  |  |  | ## POD ## | 
| 558 |  |  |  |  |  |  |  | 
| 559 |  |  |  |  |  |  | =pod | 
| 560 |  |  |  |  |  |  |  | 
| 561 |  |  |  |  |  |  | =head1 NAME | 
| 562 |  |  |  |  |  |  |  | 
| 563 |  |  |  |  |  |  | C - Class encapsulating BGP-4 peering session state and functionality | 
| 564 |  |  |  |  |  |  |  | 
| 565 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 566 |  |  |  |  |  |  |  | 
| 567 |  |  |  |  |  |  | use Net::BGP::Peer; | 
| 568 |  |  |  |  |  |  |  | 
| 569 |  |  |  |  |  |  | $peer = Net::BGP::Peer->new( | 
| 570 |  |  |  |  |  |  | Start                => 1, | 
| 571 |  |  |  |  |  |  | ThisID               => '10.0.0.1', | 
| 572 |  |  |  |  |  |  | ThisAS               => 64512, | 
| 573 |  |  |  |  |  |  | PeerID               => '10.0.0.2', | 
| 574 |  |  |  |  |  |  | PeerAS               => 64513, | 
| 575 |  |  |  |  |  |  | PeerPort             => 1179, | 
| 576 |  |  |  |  |  |  | ConnectRetryTime     => 300, | 
| 577 |  |  |  |  |  |  | HoldTime             => 60, | 
| 578 |  |  |  |  |  |  | KeepAliveTime        => 20, | 
| 579 |  |  |  |  |  |  | Listen               => 0, | 
| 580 |  |  |  |  |  |  | Passive              => 0, | 
| 581 |  |  |  |  |  |  | AnnounceRefresh      => 1, | 
| 582 |  |  |  |  |  |  | SupportCapabilities  => 1, | 
| 583 |  |  |  |  |  |  | SupportMBGP          => 1, | 
| 584 |  |  |  |  |  |  | SupportAS4           => 1, | 
| 585 |  |  |  |  |  |  | OpaqueData           => $my_ref, | 
| 586 |  |  |  |  |  |  | OpenCallback         => \&my_open_callback, | 
| 587 |  |  |  |  |  |  | KeepaliveCallback    => \&my_keepalive_callback, | 
| 588 |  |  |  |  |  |  | UpdateCallback       => \&my_update_callback, | 
| 589 |  |  |  |  |  |  | NotificationCallback => \&my_notification_callback, | 
| 590 |  |  |  |  |  |  | ErrorCallback        => \&my_error_callback | 
| 591 |  |  |  |  |  |  | ); | 
| 592 |  |  |  |  |  |  |  | 
| 593 |  |  |  |  |  |  | $peer = renew Net::BGP::Peer("$peer"); | 
| 594 |  |  |  |  |  |  |  | 
| 595 |  |  |  |  |  |  | $peer->start(); | 
| 596 |  |  |  |  |  |  | $peer->stop(); | 
| 597 |  |  |  |  |  |  |  | 
| 598 |  |  |  |  |  |  | $peer->update($update); | 
| 599 |  |  |  |  |  |  | $peer->refresh($refresh); | 
| 600 |  |  |  |  |  |  |  | 
| 601 |  |  |  |  |  |  | $version = $peer->version(); | 
| 602 |  |  |  |  |  |  |  | 
| 603 |  |  |  |  |  |  | $this_id = $peer->this_id(); | 
| 604 |  |  |  |  |  |  | $this_as = $peer->this_as(); | 
| 605 |  |  |  |  |  |  | $peer_id = $peer->peer_id(); | 
| 606 |  |  |  |  |  |  | $peer_as = $peer->peer_as(); | 
| 607 |  |  |  |  |  |  | $my_ref  = $peer->opaque_data(); | 
| 608 |  |  |  |  |  |  | $my_ref  = $peer->opaque_data($new_ref); | 
| 609 |  |  |  |  |  |  |  | 
| 610 |  |  |  |  |  |  | $i_will  = $peer->support_capabilities(); | 
| 611 |  |  |  |  |  |  |  | 
| 612 |  |  |  |  |  |  | $i_mbgp  = $peer->support_mbgp(); | 
| 613 |  |  |  |  |  |  |  | 
| 614 |  |  |  |  |  |  | $i_can   = $peer->this_can_refresh(); | 
| 615 |  |  |  |  |  |  | $peer_can= $peer->peer_can_refresh(); | 
| 616 |  |  |  |  |  |  |  | 
| 617 |  |  |  |  |  |  | $peer_as4= $peer->peer_can_as4(); | 
| 618 |  |  |  |  |  |  |  | 
| 619 |  |  |  |  |  |  | $listen  = $peer->is_listener(); | 
| 620 |  |  |  |  |  |  | $passive = $peer->is_passive(); | 
| 621 |  |  |  |  |  |  | $estab   = $peer->is_established(); | 
| 622 |  |  |  |  |  |  |  | 
| 623 |  |  |  |  |  |  | $trans   = $peer->transport($trans); | 
| 624 |  |  |  |  |  |  | @trans   = $peer->transports; | 
| 625 |  |  |  |  |  |  |  | 
| 626 |  |  |  |  |  |  | $string  = $peer->asstring(); | 
| 627 |  |  |  |  |  |  |  | 
| 628 |  |  |  |  |  |  | $peer->set_open_callback(\&my_open_callback); | 
| 629 |  |  |  |  |  |  | $peer->set_established_callback(\&my_established_callback); | 
| 630 |  |  |  |  |  |  | $peer->set_keepalive_callback(\&my_keepalive_callback); | 
| 631 |  |  |  |  |  |  | $peer->set_update_callback(\&my_update_callback); | 
| 632 |  |  |  |  |  |  | $peer->set_notification_callback(\&my_notification_callback); | 
| 633 |  |  |  |  |  |  | $peer->set_error_callback(\&my_error_callback); | 
| 634 |  |  |  |  |  |  |  | 
| 635 |  |  |  |  |  |  | $peer->add_timer(\&my_minute_timer, 60); | 
| 636 |  |  |  |  |  |  | $peer->remove_timer(\&my_minute_timer); | 
| 637 |  |  |  |  |  |  |  | 
| 638 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 639 |  |  |  |  |  |  |  | 
| 640 |  |  |  |  |  |  | This module encapsulates the state and functionality associated with a BGP | 
| 641 |  |  |  |  |  |  | peering session. Each instance of a C object corresponds | 
| 642 |  |  |  |  |  |  | to a peering session with a distinct peer and presents a programming | 
| 643 |  |  |  |  |  |  | interface to manipulate the peering session state and exchange of routing | 
| 644 |  |  |  |  |  |  | information. Through the methods provided by the C module, | 
| 645 |  |  |  |  |  |  | a program can start or stop peering sessions, send BGP routing UPDATE | 
| 646 |  |  |  |  |  |  | messages, and register callback functions which are invoked whenever the | 
| 647 |  |  |  |  |  |  | peer receives BGP messages from its peer. | 
| 648 |  |  |  |  |  |  |  | 
| 649 |  |  |  |  |  |  | =head1 CONSTRUCTOR | 
| 650 |  |  |  |  |  |  |  | 
| 651 |  |  |  |  |  |  | I - create a new C object | 
| 652 |  |  |  |  |  |  |  | 
| 653 |  |  |  |  |  |  | This is the constructor for C objects. It returns a | 
| 654 |  |  |  |  |  |  | reference to the newly created object. The following named parameters may | 
| 655 |  |  |  |  |  |  | be passed to the constructor. Once the object is created, only the | 
| 656 |  |  |  |  |  |  | callback function references can later be changed. | 
| 657 |  |  |  |  |  |  |  | 
| 658 |  |  |  |  |  |  | =head2 Start | 
| 659 |  |  |  |  |  |  |  | 
| 660 |  |  |  |  |  |  | Setting this parameter to a true value causes the peer to initiate a | 
| 661 |  |  |  |  |  |  | session with its peer immediately after it is registered with the | 
| 662 |  |  |  |  |  |  | L object's I method. If omitted or | 
| 663 |  |  |  |  |  |  | set to a false value, the peer will remain in the Idle state until | 
| 664 |  |  |  |  |  |  | the I method is called explicitly by the program. When in | 
| 665 |  |  |  |  |  |  | the Idle state the peer will refuse connections and will not initiate | 
| 666 |  |  |  |  |  |  | connection attempts. | 
| 667 |  |  |  |  |  |  |  | 
| 668 |  |  |  |  |  |  | =head2 ThisID | 
| 669 |  |  |  |  |  |  |  | 
| 670 |  |  |  |  |  |  | This parameter sets the BGP ID (IP address) of the C | 
| 671 |  |  |  |  |  |  | object. It takes a string in IP dotted decimal notation. | 
| 672 |  |  |  |  |  |  |  | 
| 673 |  |  |  |  |  |  | =head2 ThisAS | 
| 674 |  |  |  |  |  |  |  | 
| 675 |  |  |  |  |  |  | This parameter sets the BGP Autonomous System number of the C | 
| 676 |  |  |  |  |  |  | object. It takes an integer value in the range of a 16-bit unsigned integer. | 
| 677 |  |  |  |  |  |  |  | 
| 678 |  |  |  |  |  |  | =head2 PeerID | 
| 679 |  |  |  |  |  |  |  | 
| 680 |  |  |  |  |  |  | This parameter sets the BGP ID (IP address) of the object's peer. It takes | 
| 681 |  |  |  |  |  |  | a string in IP dotted decimal notation. | 
| 682 |  |  |  |  |  |  |  | 
| 683 |  |  |  |  |  |  | =head2 PeerAS | 
| 684 |  |  |  |  |  |  |  | 
| 685 |  |  |  |  |  |  | This parameter sets the BGP Autonomous System number of the object's peer. | 
| 686 |  |  |  |  |  |  | It takes an integer value in the range of a 16-bit unsigned integer. | 
| 687 |  |  |  |  |  |  |  | 
| 688 |  |  |  |  |  |  | =head2 PeerPort | 
| 689 |  |  |  |  |  |  |  | 
| 690 |  |  |  |  |  |  | This parameter sets the TCP port number on the peer to which to connect. It | 
| 691 |  |  |  |  |  |  | must be in the range of a valid TCP port number. | 
| 692 |  |  |  |  |  |  |  | 
| 693 |  |  |  |  |  |  | =head2 ConnectRetryTime | 
| 694 |  |  |  |  |  |  |  | 
| 695 |  |  |  |  |  |  | This parameter sets the BGP ConnectRetry timer duration, the value of which | 
| 696 |  |  |  |  |  |  | is given in seconds. | 
| 697 |  |  |  |  |  |  |  | 
| 698 |  |  |  |  |  |  | =head2 HoldTime | 
| 699 |  |  |  |  |  |  |  | 
| 700 |  |  |  |  |  |  | This parameter sets the BGP Hold Time duration, the value of which | 
| 701 |  |  |  |  |  |  | is given in seconds. | 
| 702 |  |  |  |  |  |  |  | 
| 703 |  |  |  |  |  |  | =head2 KeepAliveTime | 
| 704 |  |  |  |  |  |  |  | 
| 705 |  |  |  |  |  |  | This parameter sets the BGP KeepAlive timer duration, the value of which | 
| 706 |  |  |  |  |  |  | is given in seconds. | 
| 707 |  |  |  |  |  |  |  | 
| 708 |  |  |  |  |  |  | =head2 Listen | 
| 709 |  |  |  |  |  |  |  | 
| 710 |  |  |  |  |  |  | This parameter specifies whether the C will listen for | 
| 711 |  |  |  |  |  |  | and accept connections from its peer. If set to a false value, the peer | 
| 712 |  |  |  |  |  |  | will only initiate connections and will not accept connection attempts | 
| 713 |  |  |  |  |  |  | from the peer (unless the B parameter is set to a true value). | 
| 714 |  |  |  |  |  |  | Note that this behavior is not specified by RFC 1771 and should be | 
| 715 |  |  |  |  |  |  | considered non-standard. However, it is useful under certain circumstances | 
| 716 |  |  |  |  |  |  | and should not present problems as long as one side of the connection is | 
| 717 |  |  |  |  |  |  | configured to listen. | 
| 718 |  |  |  |  |  |  |  | 
| 719 |  |  |  |  |  |  | =head2 Passive | 
| 720 |  |  |  |  |  |  |  | 
| 721 |  |  |  |  |  |  | This parameter specifies whether the C will attempt to | 
| 722 |  |  |  |  |  |  | initiate connections to its peer. If set to a true value, the peer will | 
| 723 |  |  |  |  |  |  | only listen for connections and will not initate connections to its peer | 
| 724 |  |  |  |  |  |  | (unless the B parameter is set to false value). Note that this | 
| 725 |  |  |  |  |  |  | behavior is not specified by RFC 1771 and should be considered non-standard. | 
| 726 |  |  |  |  |  |  | However, it is useful under certain circumstances and should not present | 
| 727 |  |  |  |  |  |  | problems as long as one side of the connection is configured to initiate | 
| 728 |  |  |  |  |  |  | connections. | 
| 729 |  |  |  |  |  |  |  | 
| 730 |  |  |  |  |  |  | =head2 AnnounceRefresh | 
| 731 |  |  |  |  |  |  |  | 
| 732 |  |  |  |  |  |  | This parameter specifies whether the C will announce support | 
| 733 |  |  |  |  |  |  | for route refresh ('soft re-configure' as specified by RFC 2918). No support | 
| 734 |  |  |  |  |  |  | for route refresh is implemented - only the B function. This | 
| 735 |  |  |  |  |  |  | has no effect if SupportCapabilities is FALSE. | 
| 736 |  |  |  |  |  |  |  | 
| 737 |  |  |  |  |  |  | =head2 SupportCapabilities | 
| 738 |  |  |  |  |  |  |  | 
| 739 |  |  |  |  |  |  | This parameter specifies whether the C will attempt to | 
| 740 |  |  |  |  |  |  | negotiate capabilities. You can set this to FALSE if talking to an old BGP | 
| 741 |  |  |  |  |  |  | speaker that doesn't support it (you'll get a notification message for an | 
| 742 |  |  |  |  |  |  | unsupported capability if this is the case). This defaults to TRUE. | 
| 743 |  |  |  |  |  |  |  | 
| 744 |  |  |  |  |  |  | =head2 SupportMBGP | 
| 745 |  |  |  |  |  |  |  | 
| 746 |  |  |  |  |  |  | This parameter specifies whether the C will attempt to | 
| 747 |  |  |  |  |  |  | negotiate MBGP. Quagga (and probably others) need this if you want to send | 
| 748 |  |  |  |  |  |  | the REFRESH capability. Today this just indicates support for IPv4 unicast. | 
| 749 |  |  |  |  |  |  | This defaults to TRUE. This has no effect if SupportCapabilities is FALSE. | 
| 750 |  |  |  |  |  |  |  | 
| 751 |  |  |  |  |  |  | =head2 SupportAS4 | 
| 752 |  |  |  |  |  |  |  | 
| 753 |  |  |  |  |  |  | This parameter specifies whether outgoing connections from the C | 
| 754 |  |  |  |  |  |  | will attempt to negotiate AS4 (32 bit ASNs). For received connections, this | 
| 755 |  |  |  |  |  |  | parameter has no effect - it only determines whether or not AS4 is negotiated | 
| 756 |  |  |  |  |  |  | during outgoing connection. For received connections, this will be changed | 
| 757 |  |  |  |  |  |  | to TRUE (on the listening connection) whenever the appropriate OPEN capability | 
| 758 |  |  |  |  |  |  | is received. Note that the B must be true for this to | 
| 759 |  |  |  |  |  |  | be sent. This defaults to FALSE. | 
| 760 |  |  |  |  |  |  |  | 
| 761 |  |  |  |  |  |  | =head2 OpaqueData | 
| 762 |  |  |  |  |  |  |  | 
| 763 |  |  |  |  |  |  | This parameter is an optional scalar that will be kept as part of the | 
| 764 |  |  |  |  |  |  | C and can be queried by the callback routines when they | 
| 765 |  |  |  |  |  |  | receive a peer hashref - see B. This allows extra data to be | 
| 766 |  |  |  |  |  |  | stored with the peer. The contents of this are completely ignored by | 
| 767 |  |  |  |  |  |  | C. This defaults to I. | 
| 768 |  |  |  |  |  |  |  | 
| 769 |  |  |  |  |  |  | =head2 OpenCallback | 
| 770 |  |  |  |  |  |  |  | 
| 771 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 772 |  |  |  |  |  |  | peer receives an OPEN message. It takes a subroutine reference. See | 
| 773 |  |  |  |  |  |  | L<"CALLBACK FUNCTIONS"> later in this manual for further details of | 
| 774 |  |  |  |  |  |  | the conventions of callback invocation. | 
| 775 |  |  |  |  |  |  |  | 
| 776 |  |  |  |  |  |  | =head2 KeepaliveCallback | 
| 777 |  |  |  |  |  |  |  | 
| 778 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 779 |  |  |  |  |  |  | peer receives a KEEPALIVE message. It takes a subroutine reference. | 
| 780 |  |  |  |  |  |  | See L<"CALLBACK FUNCTIONS"> later in this manual for further details | 
| 781 |  |  |  |  |  |  | of the conventions of callback invocation. | 
| 782 |  |  |  |  |  |  |  | 
| 783 |  |  |  |  |  |  | =head2 UpdateCallback | 
| 784 |  |  |  |  |  |  |  | 
| 785 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 786 |  |  |  |  |  |  | peer receives an UPDATE message. It takes a subroutine reference. See | 
| 787 |  |  |  |  |  |  | L<"CALLBACK FUNCTIONS"> later in this manual for further details of | 
| 788 |  |  |  |  |  |  | the conventions of callback invocation. | 
| 789 |  |  |  |  |  |  |  | 
| 790 |  |  |  |  |  |  | =head2 RefreshCallback | 
| 791 |  |  |  |  |  |  |  | 
| 792 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 793 |  |  |  |  |  |  | peer receives a REFRESH message. It takes a subroutine reference. See | 
| 794 |  |  |  |  |  |  | L<"CALLBACK FUNCTIONS"> later in this manual for further details of | 
| 795 |  |  |  |  |  |  | the conventions of callback invocation. | 
| 796 |  |  |  |  |  |  |  | 
| 797 |  |  |  |  |  |  | =head2 NotificationCallback | 
| 798 |  |  |  |  |  |  |  | 
| 799 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 800 |  |  |  |  |  |  | peer receives a NOTIFICATION message. It takes a subroutine reference. | 
| 801 |  |  |  |  |  |  | See L<"CALLBACK FUNCTIONS"> later in this manual for further details | 
| 802 |  |  |  |  |  |  | of the conventions of callback invocation. | 
| 803 |  |  |  |  |  |  |  | 
| 804 |  |  |  |  |  |  | =head2 ErrorCallback | 
| 805 |  |  |  |  |  |  |  | 
| 806 |  |  |  |  |  |  | This parameter sets the callback function which is invoked when the | 
| 807 |  |  |  |  |  |  | peer encounters an error and must send a NOTIFICATION message to its | 
| 808 |  |  |  |  |  |  | peer. It takes a subroutine reference. See L<"CALLBACK FUNCTIONS"> | 
| 809 |  |  |  |  |  |  | later in this manual for further details of the conventions of callback | 
| 810 |  |  |  |  |  |  | invocation. | 
| 811 |  |  |  |  |  |  |  | 
| 812 |  |  |  |  |  |  | I - fetch the existing C object from the "object string". | 
| 813 |  |  |  |  |  |  |  | 
| 814 |  |  |  |  |  |  | This "reconstructor" returns a previously constructed object from the | 
| 815 |  |  |  |  |  |  | perl generated string-context scalar of the object, e.g. | 
| 816 |  |  |  |  |  |  | I. | 
| 817 |  |  |  |  |  |  |  | 
| 818 |  |  |  |  |  |  | =head1 ACCESSOR METHODS | 
| 819 |  |  |  |  |  |  |  | 
| 820 |  |  |  |  |  |  | I - start the BGP peering session with the peer | 
| 821 |  |  |  |  |  |  |  | 
| 822 |  |  |  |  |  |  | $peer->start(); | 
| 823 |  |  |  |  |  |  |  | 
| 824 |  |  |  |  |  |  | This method initiates the BGP peering session with the peer by | 
| 825 |  |  |  |  |  |  | internally emitting the BGP Start event, which causes the peer | 
| 826 |  |  |  |  |  |  | to initiate a transport-layer connection to its peer (unless | 
| 827 |  |  |  |  |  |  | the B parameter was set to a true value in the | 
| 828 |  |  |  |  |  |  | constructor) and listen for a connection from the peer (unless | 
| 829 |  |  |  |  |  |  | the B parameter is set to a false value). | 
| 830 |  |  |  |  |  |  |  | 
| 831 |  |  |  |  |  |  | I - cease the BGP peering session with the peer | 
| 832 |  |  |  |  |  |  |  | 
| 833 |  |  |  |  |  |  | $peer->stop(); | 
| 834 |  |  |  |  |  |  |  | 
| 835 |  |  |  |  |  |  | This method immediately ceases the peering session with the | 
| 836 |  |  |  |  |  |  | peer by sending it a NOTIFICATION message with Error Code | 
| 837 |  |  |  |  |  |  | Cease, closing the transport-layer connection, and entering | 
| 838 |  |  |  |  |  |  | the Idle state. | 
| 839 |  |  |  |  |  |  |  | 
| 840 |  |  |  |  |  |  | I - send a BGP UPDATE message to the peer | 
| 841 |  |  |  |  |  |  |  | 
| 842 |  |  |  |  |  |  | $peer->update($update); | 
| 843 |  |  |  |  |  |  |  | 
| 844 |  |  |  |  |  |  | This method sends the peer an UPDATE message. It takes a reference | 
| 845 |  |  |  |  |  |  | to a L object. See the L | 
| 846 |  |  |  |  |  |  | manual page for details on setting UPDATE attributes. | 
| 847 |  |  |  |  |  |  |  | 
| 848 |  |  |  |  |  |  | I - send a BGP REFRESH message to the peer | 
| 849 |  |  |  |  |  |  |  | 
| 850 |  |  |  |  |  |  | $peer->refresh($refresh); | 
| 851 |  |  |  |  |  |  |  | 
| 852 |  |  |  |  |  |  | This method sends the peer a REFRESH message. It takes a reference | 
| 853 |  |  |  |  |  |  | to a L object. If no argument is provided, a default | 
| 854 |  |  |  |  |  |  | L object is constructed. See the L | 
| 855 |  |  |  |  |  |  | manual page for details on setting REFRESH attributes. | 
| 856 |  |  |  |  |  |  |  | 
| 857 |  |  |  |  |  |  | I | 
| 858 |  |  |  |  |  |  |  | 
| 859 |  |  |  |  |  |  | I | 
| 860 |  |  |  |  |  |  |  | 
| 861 |  |  |  |  |  |  | I | 
| 862 |  |  |  |  |  |  |  | 
| 863 |  |  |  |  |  |  | I | 
| 864 |  |  |  |  |  |  |  | 
| 865 |  |  |  |  |  |  | I | 
| 866 |  |  |  |  |  |  |  | 
| 867 |  |  |  |  |  |  | I | 
| 868 |  |  |  |  |  |  |  | 
| 869 |  |  |  |  |  |  | I | 
| 870 |  |  |  |  |  |  |  | 
| 871 |  |  |  |  |  |  | I | 
| 872 |  |  |  |  |  |  |  | 
| 873 |  |  |  |  |  |  | I | 
| 874 |  |  |  |  |  |  |  | 
| 875 |  |  |  |  |  |  | I | 
| 876 |  |  |  |  |  |  |  | 
| 877 |  |  |  |  |  |  | These are accessor methods for the corresponding constructor named parameters. | 
| 878 |  |  |  |  |  |  | They retrieve the values set when the object was created, but the values cannot | 
| 879 |  |  |  |  |  |  | be changed after object construction. Hence, they take no arguments. | 
| 880 |  |  |  |  |  |  |  | 
| 881 |  |  |  |  |  |  | I | 
| 882 |  |  |  |  |  |  |  | 
| 883 |  |  |  |  |  |  | $peer->opaque_data(); | 
| 884 |  |  |  |  |  |  | $peer->opaque_data($new_ref); | 
| 885 |  |  |  |  |  |  |  | 
| 886 |  |  |  |  |  |  | This method can be used to both query (no argument) or set (with an argument) | 
| 887 |  |  |  |  |  |  | the opaque data held with the peer object. The method returns the old opaque data | 
| 888 |  |  |  |  |  |  | scalar (which is the current value if not provided). | 
| 889 |  |  |  |  |  |  |  | 
| 890 |  |  |  |  |  |  | I | 
| 891 |  |  |  |  |  |  |  | 
| 892 |  |  |  |  |  |  | This accessor method returns true if the peer has a established transport | 
| 893 |  |  |  |  |  |  | connection - e.g. the peering is up. | 
| 894 |  |  |  |  |  |  |  | 
| 895 |  |  |  |  |  |  | I | 
| 896 |  |  |  |  |  |  |  | 
| 897 |  |  |  |  |  |  | This accessor method returns a true value if connected to a peer that supports | 
| 898 |  |  |  |  |  |  | refresh messages - otherwise a false value. | 
| 899 |  |  |  |  |  |  |  | 
| 900 |  |  |  |  |  |  | I | 
| 901 |  |  |  |  |  |  |  | 
| 902 |  |  |  |  |  |  | This accessor method returns a print friendly string with the local and remote | 
| 903 |  |  |  |  |  |  | IP and AS numbers. | 
| 904 |  |  |  |  |  |  |  | 
| 905 |  |  |  |  |  |  | I | 
| 906 |  |  |  |  |  |  |  | 
| 907 |  |  |  |  |  |  | I | 
| 908 |  |  |  |  |  |  |  | 
| 909 |  |  |  |  |  |  | I | 
| 910 |  |  |  |  |  |  |  | 
| 911 |  |  |  |  |  |  | I | 
| 912 |  |  |  |  |  |  |  | 
| 913 |  |  |  |  |  |  | I | 
| 914 |  |  |  |  |  |  |  | 
| 915 |  |  |  |  |  |  | I | 
| 916 |  |  |  |  |  |  |  | 
| 917 |  |  |  |  |  |  | I | 
| 918 |  |  |  |  |  |  |  | 
| 919 |  |  |  |  |  |  | I | 
| 920 |  |  |  |  |  |  |  | 
| 921 |  |  |  |  |  |  | These methods set the callback functions which are invoked whenever the | 
| 922 |  |  |  |  |  |  | peer receives the corresponding BGP message type from its peer, or, in the | 
| 923 |  |  |  |  |  |  | case of I, transitions to the relevant state. They | 
| 924 |  |  |  |  |  |  | can be set in the constructor as well as with these methods. These methods | 
| 925 |  |  |  |  |  |  | each take one argument, which is the subroutine reference to be invoked. | 
| 926 |  |  |  |  |  |  | A callback function can be removed by calling the corresponding one of these | 
| 927 |  |  |  |  |  |  | methods and passing it the perl I value. For callback definition and | 
| 928 |  |  |  |  |  |  | invocation conventions see L<"CALLBACK FUNCTIONS"> later in this manual. | 
| 929 |  |  |  |  |  |  |  | 
| 930 |  |  |  |  |  |  | I - add a program defined timer callback function | 
| 931 |  |  |  |  |  |  |  | 
| 932 |  |  |  |  |  |  | $peer->add_timer(\&my_minute_timer, 60); | 
| 933 |  |  |  |  |  |  |  | 
| 934 |  |  |  |  |  |  | This method sets a program defined timer which invokes the specified callback | 
| 935 |  |  |  |  |  |  | function when the timer expires. It takes two arguments: the first is a code | 
| 936 |  |  |  |  |  |  | reference to the subroutine to be invoked when the timer expires, and the | 
| 937 |  |  |  |  |  |  | second is the timer interval, in seconds. The program may set as many timers | 
| 938 |  |  |  |  |  |  | as needed, and multiple timer callbacks may share the same interval. Program | 
| 939 |  |  |  |  |  |  | timers add an asynchronous means for user code to gain control of the program | 
| 940 |  |  |  |  |  |  | control flow - without them user code would only be invoked whenever BGP | 
| 941 |  |  |  |  |  |  | events exposed by the module occur. They may be used to perform any necessary | 
| 942 |  |  |  |  |  |  | action - for example, sending UPDATEs, starting or stopping the peering | 
| 943 |  |  |  |  |  |  | session, house-keeping, etc. | 
| 944 |  |  |  |  |  |  |  | 
| 945 |  |  |  |  |  |  | I - remove a program defined timer callback function | 
| 946 |  |  |  |  |  |  |  | 
| 947 |  |  |  |  |  |  | $peer->remove_timer(\&my_minute_timer); | 
| 948 |  |  |  |  |  |  |  | 
| 949 |  |  |  |  |  |  | This method removes a program defined timer callback which has been previously | 
| 950 |  |  |  |  |  |  | set with the I method. It takes a single argument: a reference | 
| 951 |  |  |  |  |  |  | to the subroutine previously added. | 
| 952 |  |  |  |  |  |  |  | 
| 953 |  |  |  |  |  |  | =head1 CALLBACK FUNCTIONS | 
| 954 |  |  |  |  |  |  |  | 
| 955 |  |  |  |  |  |  | Whenever a C object receives one of the BGP protocol messages - | 
| 956 |  |  |  |  |  |  | OPEN, KEEPALIVE, UPDATE, REFRESH, or NOTIFICATION - from its peer, or whenever it | 
| 957 |  |  |  |  |  |  | encounters an error condition and must send a NOTIFICATION message to its peer, | 
| 958 |  |  |  |  |  |  | the peer object will invoke a program defined callback function corresponding | 
| 959 |  |  |  |  |  |  | to the event type, if one has been provided, to inform the application about | 
| 960 |  |  |  |  |  |  | the event. These callback functions are installed as described in the preceding | 
| 961 |  |  |  |  |  |  | section of the manual. Whenever any callback function is invoked, it is passed | 
| 962 |  |  |  |  |  |  | one or more arguments, depending on the BGP message type associated with the | 
| 963 |  |  |  |  |  |  | callback. The first argument passed to all of the callbacks is a reference | 
| 964 |  |  |  |  |  |  | to the C object which the application may use to identify | 
| 965 |  |  |  |  |  |  | which peer has signalled the event and to take appropriate action. For OPEN | 
| 966 |  |  |  |  |  |  | and KEEPALIVE callbacks, this is the only argument passed. It is very unlikely | 
| 967 |  |  |  |  |  |  | that applications will be interested in OPEN and KEEPALIVE events, since the | 
| 968 |  |  |  |  |  |  | C module handles all details of OPEN and KEEPALIVE message processing | 
| 969 |  |  |  |  |  |  | in order to establish and maintain BGP sessions. Callback handling for these | 
| 970 |  |  |  |  |  |  | messages is mainly included for the sake of completeness. For UPDATE and | 
| 971 |  |  |  |  |  |  | NOTIFICATION messages, however, most applications will install callback handlers. | 
| 972 |  |  |  |  |  |  | Whenever an UPDATE, REFRESH, NOTIFICATION, or error handler is called, the object | 
| 973 |  |  |  |  |  |  | will pass a second argument. In the first two cases, this is a L | 
| 974 |  |  |  |  |  |  | or L object respectivly encapsulating the information contained | 
| 975 |  |  |  |  |  |  | in the UPDATE or REFRESH message, while in the latter two cases it is a | 
| 976 |  |  |  |  |  |  | L object encapsulating the information in the | 
| 977 |  |  |  |  |  |  | NOTIFICATION message sent or received. | 
| 978 |  |  |  |  |  |  |  | 
| 979 |  |  |  |  |  |  | The RESET and ESTABLISHED callbacks are special, since they are used whenever an | 
| 980 |  |  |  |  |  |  | established BGP session is reset, even though no message has been recieved or sent. | 
| 981 |  |  |  |  |  |  | The REFRESH callback is also special, since it is also called without a REFRESH | 
| 982 |  |  |  |  |  |  | object whenever a BGP session is established. The two callbacks can be used to | 
| 983 |  |  |  |  |  |  | clear and retransmit a RIB from/to the peer in question. | 
| 984 |  |  |  |  |  |  |  | 
| 985 |  |  |  |  |  |  | Whenever a callback function is to be invoked, the action occuring internally is | 
| 986 |  |  |  |  |  |  | the invocation of one of the following methods, corresponding to the event which | 
| 987 |  |  |  |  |  |  | has occured: | 
| 988 |  |  |  |  |  |  |  | 
| 989 |  |  |  |  |  |  | I | 
| 990 |  |  |  |  |  |  |  | 
| 991 |  |  |  |  |  |  | I | 
| 992 |  |  |  |  |  |  |  | 
| 993 |  |  |  |  |  |  | I | 
| 994 |  |  |  |  |  |  |  | 
| 995 |  |  |  |  |  |  | I | 
| 996 |  |  |  |  |  |  |  | 
| 997 |  |  |  |  |  |  | I | 
| 998 |  |  |  |  |  |  |  | 
| 999 |  |  |  |  |  |  | I | 
| 1000 |  |  |  |  |  |  |  | 
| 1001 |  |  |  |  |  |  | I | 
| 1002 |  |  |  |  |  |  |  | 
| 1003 |  |  |  |  |  |  | I | 
| 1004 |  |  |  |  |  |  |  | 
| 1005 |  |  |  |  |  |  | Internally, each of these methods just checks to see whether a program defined | 
| 1006 |  |  |  |  |  |  | callback function has been set and calls it if so, passing it arguments as | 
| 1007 |  |  |  |  |  |  | described above. As an alternative to providing subroutine references to the | 
| 1008 |  |  |  |  |  |  | constructor or through the I, I, | 
| 1009 |  |  |  |  |  |  | I, I, I, | 
| 1010 |  |  |  |  |  |  | I, I, and I | 
| 1011 |  |  |  |  |  |  | methods, an application may effect a similar result by sub-classing the | 
| 1012 |  |  |  |  |  |  | C module and overridding the defintions of the above methods | 
| 1013 |  |  |  |  |  |  | to perform whatever actions would have been executed by ordinary callback functions. | 
| 1014 |  |  |  |  |  |  | The overridden methods are passed the same arguments as the callback functions. | 
| 1015 |  |  |  |  |  |  | This method might offer an advantage in organizing code according to different | 
| 1016 |  |  |  |  |  |  | derived classes which apply specifc routing policies. | 
| 1017 |  |  |  |  |  |  |  | 
| 1018 |  |  |  |  |  |  | =head1 ERROR HANDLING | 
| 1019 |  |  |  |  |  |  |  | 
| 1020 |  |  |  |  |  |  | There are two possibilities for error handling callbacks to be invoked. The first | 
| 1021 |  |  |  |  |  |  | case occurs when the peer receives a NOTIFICATION messages from its peer. The | 
| 1022 |  |  |  |  |  |  | second case occurs when the peer detects an error condition while processing an | 
| 1023 |  |  |  |  |  |  | incoming BGP message or when some other protocol covenant is violated - for | 
| 1024 |  |  |  |  |  |  | example if a KEEPALIVE or UPDATE message is not received before the peer's | 
| 1025 |  |  |  |  |  |  | Keepalive timer expires. In this case, the peer responds by sending a NOTIFICATION | 
| 1026 |  |  |  |  |  |  | message to its peer. In the former case the I method | 
| 1027 |  |  |  |  |  |  | is invoked as described above to handle the error, while in the latter the | 
| 1028 |  |  |  |  |  |  | I method is invoked to inform the application that it has | 
| 1029 |  |  |  |  |  |  | encountered an error. Both methods are passed a L | 
| 1030 |  |  |  |  |  |  | object encapsulating the details of the error. In both cases, the transport-layer | 
| 1031 |  |  |  |  |  |  | connection and BGP session are closed and the peer transitions to the Idle state. | 
| 1032 |  |  |  |  |  |  | The error handler callbacks can examine the cause of the error and take appropriate | 
| 1033 |  |  |  |  |  |  | action. This could be to attempt to re-establish the session (perhaps after | 
| 1034 |  |  |  |  |  |  | sleeping for some amount of time), or to unregister the peer object from the | 
| 1035 |  |  |  |  |  |  | L object and permanently end the session (for the duration | 
| 1036 |  |  |  |  |  |  | of the application's running time), or to log the event to a file on the host | 
| 1037 |  |  |  |  |  |  | system, or some combination of these or none. | 
| 1038 |  |  |  |  |  |  |  | 
| 1039 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 1040 |  |  |  |  |  |  |  | 
| 1041 |  |  |  |  |  |  | =over | 
| 1042 |  |  |  |  |  |  |  | 
| 1043 |  |  |  |  |  |  | =item L | 
| 1044 |  |  |  |  |  |  |  | 
| 1045 |  |  |  |  |  |  | =item L | 
| 1046 |  |  |  |  |  |  |  | 
| 1047 |  |  |  |  |  |  | =item L | 
| 1048 |  |  |  |  |  |  |  | 
| 1049 |  |  |  |  |  |  | =item L | 
| 1050 |  |  |  |  |  |  |  | 
| 1051 |  |  |  |  |  |  | =item L | 
| 1052 |  |  |  |  |  |  |  | 
| 1053 |  |  |  |  |  |  | =item L | 
| 1054 |  |  |  |  |  |  |  | 
| 1055 |  |  |  |  |  |  | =item L | 
| 1056 |  |  |  |  |  |  |  | 
| 1057 |  |  |  |  |  |  | =back | 
| 1058 |  |  |  |  |  |  |  | 
| 1059 |  |  |  |  |  |  | =head1 AUTHOR | 
| 1060 |  |  |  |  |  |  |  | 
| 1061 |  |  |  |  |  |  | Stephen J. Scheck | 
| 1062 |  |  |  |  |  |  |  | 
| 1063 |  |  |  |  |  |  | =cut | 
| 1064 |  |  |  |  |  |  |  | 
| 1065 |  |  |  |  |  |  | ## End Package Net::BGP::Peer ## | 
| 1066 |  |  |  |  |  |  |  | 
| 1067 |  |  |  |  |  |  | 1; |