BGP/Refresh.pm

filter: Statementstmt 75.0% 42 / 56 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 9 totaltotal 61.1% 55 / 90 SCAR 17.5
CC
5
Cov
69%
new
7.3
_decode_message
2.1
AFI_IP6
2.0
CRAP 5.8
« BGP/Notification.pm ↑ Summary BGP/ASPath/AS_SET.pm »
1 #!/usr/bin/perl
2  
3 package Net::BGP::Refresh;
4 5 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @AFI @SAFI );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ## Inheritance and Versioning ##
10  
11 5 @ISA = qw( Exporter );
12 5 $VERSION = '0.07';
13  
14 ## Module Imports ##
15  
16 5 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Net::BGP::Notification qw( :errors );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 ## BGP Protocol Error Code and Subcode Enumerations ##
20  
21  
22 # http://www.iana.org/assignments/address-family-numbers
23 6 ▶sub AFI_IP4 { 1 }
Subroutine AFI_IP4: called CC=1 SCAR=0.0
Pod undocumented
24 0 ▶sub AFI_IP6 { 2 }
Subroutine AFI_IP6: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 # http://www.iana.org/assignments/safi-namespace
27 0 ▶sub SAFI_UNI { 1 }
Subroutine SAFI_UNI: not called CC=1 SCAR=6.9
Pod undocumented
28 0 ▶sub SAFI_MULTI { 2 }
Subroutine SAFI_MULTI: not called CC=1 SCAR=6.9
Pod undocumented
29 6 ▶sub SAFI_BOTH { 3 }
Subroutine SAFI_BOTH: called CC=1 SCAR=0.0
Pod undocumented
30 0 ▶sub SAFI_MPLS { 4 }
Subroutine SAFI_MPLS: not called CC=1 SCAR=6.9
Pod undocumented
31  
32 5 @AFI = qw(
33 AFI_IP4
34 AFI_IP6
35 );
36  
37 5 @SAFI = qw(
38 SAFI_UNI
39 SAFI_MULTI
40 SAFI_BOTH
41 SAFI_MPLS
42 );
43  
44 5 @EXPORT = ();
45 5 @EXPORT_OK = ( @AFI, @SAFI );
46 5 %EXPORT_TAGS = (
47 afi => [ @AFI ],
48 safi => [ @SAFI ],
49 ALL => [ @EXPORT, @EXPORT_OK ]
50 );
51  
52 ## Public Methods ##
53  
54 sub new
55 {
56 6 ▶ my $class = shift();
Subroutine new: called CC=4 SCAR=19.8
Pod undocumented
57 6 my ($arg, $value);
58  
59 6 my $this = {
60 _afi => AFI_IP4,
61 _safi => SAFI_BOTH
62 };
63  
64 6 bless($this, $class);
65  
66 6 ▶ while ( defined($arg = shift()) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($arg = shift())) 0 6 6
67 0 $value = shift();
68  
69 0 ▶ if ( $arg =~ /safi/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg =~ /safi/i) { } 0 0 0
elsif ($arg =~ /afi/i) { } 0 0 0
70 0 $this->{_safi} = $value;
71 }
72 elsif ( $arg =~ /afi/i ) {
73 0 $this->{_afi} = $value;
74 }
75 else {
76 0 die("unrecognized argument $arg\n");
77 }
78 }
79  
80 6 return ( $this );
81 }
82  
83 sub afi
84 {
85 0 ▶ my $this = shift();
Subroutine afi: not called CC=1 SCAR=6.9
Pod undocumented
86 0 return ( $this->{_afi} );
87 }
88  
89 sub safi
90 {
91 0 ▶ my $this = shift();
Subroutine safi: not called CC=1 SCAR=6.9
Pod undocumented
92 0 return ( $this->{_safi} );
93 }
94  
95 ## Private Methods ##
96  
97 sub _new_from_msg
98 {
99 3 ▶ my ($class, $buffer) = @_;
Subroutine _new_from_msg: called CC=1 SCAR=0.0
100  
101 3 my $this = $class->new;
102  
103 3 $this->_decode_message($buffer);
104  
105 3 return $this;
106 }
107  
108 sub _decode_message
109 {
110 3 ▶ my ($this, $buffer) = @_;
Subroutine _decode_message: called CC=2 SCAR=7.4
111  
112 3 ▶ if ( length($buffer) != 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buffer != 4) 0 3 3
113 0 Net::BGP::Notification->throw(
114 ErrorCode => BGP_ERROR_CODE_FINITE_STATE_MACHINE
115 );
116 }
117  
118 3 ($this->{_afi},undef,$this->{_safi}) = unpack('ncc', $buffer);
119  
120 3 return undef;
121 }
122  
123 sub _encode_message
124 {
125 4 ▶ my $this = shift();
Subroutine _encode_message: called CC=1 SCAR=0.0
126  
127 # encode the message
128 4 my $buffer = pack('ncc', $this->{_afi}, 0, $this->{_safi});
129  
130 4 return ( $buffer );
131 }
132  
133 ## POD ##
134  
135 =pod
136  
137 =head1 NAME
138  
139 Net::BGP::Refresh - Class encapsulating BGP-4 REFRESH message
140  
141 =head1 SYNOPSIS
142  
143 use Net::BGP::Refresh;
144  
145 $refresh = Net::BGP::Refresh->new(
146 AFI => $address_family_identifier,
147 SAFI => $subsequent_address_family_identifier
148 );
149  
150 $address_family_identifier = $error->afi();
151 $subsequent_address_family_identifier = $error->safi();
152  
153 $peer->refresh($refresh);
154  
155 =head1 DESCRIPTION
156  
157 This module encapsulates the data contained in a BGP-4 REFRESH message as
158 specifed by RFC2918.
159 It provides a constructor, and accessor methods for each of the fields, AFI
160 and SAFI, of a REFRESH message.
161 To refresh the route table for a given address family, call the peer object's
162 I<refresh()> function with a B<Net::BGP::Refresh> object as argument.
163  
164 =head1 METHODS
165  
166 I<new()> - create a new Net::BGP::Refresh object
167  
168 $error = Net::BGP::Refresh->new(
169 AFI => $address_family_identifier,
170 SAFI => $subsequent_address_family_identifier
171 );
172  
173 This is the constructor for Net::BGP::Refresh objects. It returns a
174 reference to the newly created object. The following named parameters may
175 be passed to the constructor.
176  
177 =head2 AFI
178  
179 This parameter corresponds to the Address Family Identifier field of a REFRESH
180 message. Default is I<AFI_IP4>.
181  
182 =head2 SAFI
183  
184 This parameter corresponds to the Subsequent Address Family Identifier field of
185 a REFRESH message. Default is I<SAFI_BOTH>.
186  
187 I<afi()> - retrieve the value of the Address Family Identifier field
188  
189 $address_family_identifier = $error->afi();
190  
191 I<safi()> - retrieve the value of the Subsequent Address Family Identifier field
192  
193 $subsequent_address_family_identifier = $error->safi();
194  
195 =head1 SEE ALSO
196  
197 B<Net::BGP>, B<Net::BGP::Process>, B<Net::BGP::Peer>,
198 B<Net::BGP::Notification>, B<Net::BGP::Update>
199  
200 =head1 AUTHOR
201  
202 Stephen J. Scheck <code@neurosphere.com>
203  
204 =cut
205  
206 ## End Package Net::BGP::Notification ##
207  
208 5 1;
« BGP/Notification.pm ↑ Summary BGP/ASPath/AS_SET.pm »