RIB.pm

filter: Statementstmt 38.4% 20 / 52 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 6 / 15 Podpod 100% 6 / 6 totaltotal 41.5% 32 / 77 CC 4 SCAR 13.3
CC
4
Cov
36%
handle_update
12.0
__ANON__
6.0
new
2.0
CRAP 3.8
« Policy.pm ↑ Summary
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ## Inheritance and Versioning ##
12  
13 1 $VERSION = '0.04';
14  
15 ## Module Import ##
16  
17 1 ▶use Net::Patricia;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Net::BGP::RIBEntry;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Net::BGP::Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 ## Public Class Methods ##
22  
23 sub new
24 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
25 0 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 0 ▶{
Subroutine add_peer: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($this,$peer,$dir,$policy) = @_;
42 $this->{_table}->climb( sub
43 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 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 0 ▶{
Subroutine reset_peer: not called CC=1 SCAR=6.9
Pod documented
52 0 shift->add_peer(@_); # Just set to undef - same thing!
53 }
54  
55 sub remove_peer
56 0 ▶{
Subroutine remove_peer: not called CC=1 SCAR=6.9
Pod documented
57 0 my ($this,$peer,$dir,$policy) = @_;
58 $this->{_table}->climb( sub
59 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 my $re = shift;
61 0 ▶ return unless defined $re; # While in final cleanup
Branch: 1 branch
BranchTrueFalseTotal
unless defined $re 0 0 0
62 0 $re->remove_peer($peer,$dir);
63 0 $re->handle_changes($this,$policy);
64 0 } );
65 }
66  
67 sub handle_update
68 0 ▶{
Subroutine handle_update: not called CC=3 SCAR=24.8
Pod documented
69 0 my ($this,$peer,$update,$policy) = @_;
70  
71 0 my $nlri_hr = $update->ashash;
72 0 foreach my $prefix (keys %{$nlri_hr})
73 {
74 0 my $entry = $this->{_table}->match_exact_string($prefix);
75 0 ▶ unless (defined($entry))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entry) 0 0 0
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 0 ▶{
Subroutine asstring: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($this) = shift;
88 0 my $res = '';
89 0 ▶ $this->{_table}->climb( sub { $res .= shift; } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
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<Net::BGP::RIBEntry|Net::BGP::RIBEntry> 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<in> or C<out>). 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 <bgp@martin.lorensen.dk>
174  
175 =cut
176  
177 ## End Package Net::BGP::RIBEntry ##
178  
179 1 1;
« Policy.pm ↑ Summary