line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: RIB.pm,v 1.9 2003/06/02 15:01:17 unimlo Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::BGP::RIB; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1136
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## Inheritance and Versioning ## |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.04'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## Module Import ## |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
2002
|
use Net::Patricia; |
|
1
|
|
|
|
|
14830
|
|
|
1
|
|
|
|
|
57
|
|
18
|
1
|
|
|
1
|
|
10
|
use Net::BGP::RIBEntry; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
19
|
1
|
|
|
1
|
|
7
|
use Net::BGP::Policy; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
440
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
## Public Class Methods ## |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
1
|
|
my $class = shift(); |
26
|
0
|
|
|
|
|
|
my ($arg, $value); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $this = { |
29
|
|
|
|
|
|
|
_table => new Net::Patricia, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
bless($this, $class); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $this; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## Public Object Methods ## |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add_peer |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
0
|
1
|
|
my ($this,$peer,$dir,$policy) = @_; |
42
|
|
|
|
|
|
|
$this->{_table}->climb( sub |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
|
|
my $re = shift; |
45
|
0
|
|
|
|
|
|
$re->add_peer($peer,$dir); |
46
|
0
|
|
|
|
|
|
$re->handle_changes($policy); |
47
|
0
|
|
|
|
|
|
} ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub reset_peer |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
1
|
|
shift->add_peer(@_); # Just set to undef - same thing! |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub remove_peer |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
1
|
|
my ($this,$peer,$dir,$policy) = @_; |
58
|
|
|
|
|
|
|
$this->{_table}->climb( sub |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
0
|
|
|
my $re = shift; |
61
|
0
|
0
|
|
|
|
|
return unless defined $re; # While in final cleanup |
62
|
0
|
|
|
|
|
|
$re->remove_peer($peer,$dir); |
63
|
0
|
|
|
|
|
|
$re->handle_changes($this,$policy); |
64
|
0
|
|
|
|
|
|
} ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub handle_update |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
0
|
1
|
|
my ($this,$peer,$update,$policy) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $nlri_hr = $update->ashash; |
72
|
0
|
|
|
|
|
|
foreach my $prefix (keys %{$nlri_hr}) |
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
|
my $entry = $this->{_table}->match_exact_string($prefix); |
75
|
0
|
0
|
|
|
|
|
unless (defined($entry)) |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
|
$entry = new Net::BGP::RIBEntry(prefix => $prefix); |
78
|
0
|
|
|
|
|
|
$this->{_table}->add_string($prefix,$entry); |
79
|
|
|
|
|
|
|
}; |
80
|
0
|
|
|
|
|
|
$entry->update_in($peer,$nlri_hr->{$prefix}); |
81
|
0
|
|
|
|
|
|
$entry->handle_changes($policy); |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub asstring |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
0
|
1
|
|
my ($this) = shift; |
88
|
0
|
|
|
|
|
|
my $res = ''; |
89
|
0
|
|
|
0
|
|
|
$this->{_table}->climb( sub { $res .= shift; } ); |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $res; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Net::BGP::RIB - Class representing BGP Routing Information Base (RIB) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
use Net::BGP::RIB; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Constructor |
104
|
|
|
|
|
|
|
$rib = new Net::BGP::RIB(); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Accessor Methods |
107
|
|
|
|
|
|
|
$rib->add_peer($peer,$dir,$policy); |
108
|
|
|
|
|
|
|
$rib->reset_peer($peer,$dir,$policy); |
109
|
|
|
|
|
|
|
$rib->remove_peer($peer,$dir,$policy); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$rib->handle_update($peer,$update,$policy) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$string = $entry->asstring; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 DESCRIPTION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This module implement a class representing an entry in a BGP Routing |
119
|
|
|
|
|
|
|
Information Base. It stores individual RIB entries in |
120
|
|
|
|
|
|
|
L objects. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over 4 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item new() - create a new Net::BGP::RIB object |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$rib = new Net::BGP::RIB() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is the constructor for Net::BGP::RIB object. It returns a reference to |
131
|
|
|
|
|
|
|
the newly created object. All arguments are ignored. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 ACCESSOR METHODS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item add_peer() |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item reset_peer() |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item remove_peer() |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
All three methods takes a Net::BGP::Peer object as first argument. The second |
146
|
|
|
|
|
|
|
should be the direction (C or C). The thirds is optional and is the |
147
|
|
|
|
|
|
|
policy, a Net::BGP::Policy object. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
add_peer() adds the peer to the RIB. remove_peer() removes the peer from the |
150
|
|
|
|
|
|
|
RIB while reset_peer() clears information about NLRIs recieved or send to |
151
|
|
|
|
|
|
|
the peer. All three might have the side effect that UPDATE messages are sent |
152
|
|
|
|
|
|
|
to the peer or other peers in the RIB. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item handle_update() |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The handle_update() method handles updates of the RIB. It should have the |
157
|
|
|
|
|
|
|
peer object of the peer that has recieved the UPDATE message as the first |
158
|
|
|
|
|
|
|
argument. The second argument should be the Net::BGP::Update object recieved. |
159
|
|
|
|
|
|
|
The third optional argument is the policy used. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item asstring() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This method returns a print-friendly string describing the RIB. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SEE ALSO |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Net::BGP::RIBEntry, Net::BGP::Router, Net::Policy, Net::BGP::Update |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Martin Lorensen |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
## End Package Net::BGP::RIBEntry ## |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |